Valkka  1.6.1
OpenSource Video Management
valkkafsreader.h
Go to the documentation of this file.
1 #ifndef valkkafsreader_HEADER_GUARD
2 #define valkkafsreader_HEADER_GUARD
3 /*
4  * valkkafsreader.h :
5  *
6  * (c) Copyright 2017-2024 Sampsa Riikonen
7  *
8  * Authors: Sampsa Riikonen <sampsa.riikonen@iki.fi>
9  *
10  * This file is part of the Valkka library.
11  *
12  * Valkka is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License as
14  * published by the Free Software Foundation, either version 3 of the
15  * License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * along with this program. If not, see <https://www.gnu.org/licenses/>
24  *
25  */
26 
36 #include "common.h"
37 #include "thread.h"
38 #include "framefifo.h"
39 #include "framefilter.h"
40 #include "valkkafs.h"
41 #include "rawrite.h"
42 
55 class ValkkaFSReaderThread : public Thread { // <pyapi>
56 
57 public: // <pyapi>
58  ValkkaFSReaderThread(const char *name, ValkkaFS &valkkafs, FrameFilter &outfilter, FrameFifoContext fifo_ctx=FrameFifoContext(10), bool o_direct = false); // <pyapi>
59  ~ValkkaFSReaderThread(); // <pyapi>
60 
61 protected:
62  ValkkaFS &valkkafs;
63  FrameFilter &outfilter;
64  std::map<IdNumber, SlotNumber> id_to_slot;
65  // std::fstream filestream;
66  RawReader raw_reader;
67 
68 protected: // frame input
71 
72 protected: // Thread member redefinitions
73  std::deque<ValkkaFSReaderSignalContext> signal_fifo;
74 
75 public: // redefined virtual functions
76  void run();
77  void preRun();
78  void postRun();
79  void sendSignal(ValkkaFSReaderSignalContext signal_ctx);
80 
81 protected:
82  void handleSignal(ValkkaFSReaderSignalContext &signal_ctx);
83  void handleSignals();
84 
85 protected:
86  void setSlotId(SlotNumber slot, IdNumber id);
87  void unSetSlotId(IdNumber id);
88  void clearSlotId();
89  void reportSlotId();
90  void pullBlocks(std::list<std::size_t> block_list);
91 
92 // API
93 public: // <pyapi>
94  FifoFrameFilter &getFrameFilter(); // <pyapi>
96  void setSlotIdCall(SlotNumber slot, IdNumber id); // <pyapi>
98  void unSetSlotIdCall(IdNumber id); // <pyapi>
100  void clearSlotIdCall(); // <pyapi>
102  void reportSlotIdCall(); // <pyapi>
103  void pullBlocksCall(std::list<std::size_t> block_list);
105  void pullBlocksPyCall(PyObject *pylist); // <pyapi>
106  void requestStopCall(); // <pyapi>
107 }; // <pyapi>
108 
109 
110 
111 
112 #endif
Passes frames to a FrameFifo.
Definition: framefilter.h:530
A thread-safe combination of a fifo (first-in-first-out) queue and an associated stack.
Definition: framefifo.h:83
The mother class of all frame filters! FrameFilters are used to create "filter chains".
Definition: framefilter.h:44
Definition: rawrite.h:96
A class for multithreading with a signaling system.
Definition: thread.h:87
std::string name
Name of the thread.
Definition: thread.h:116
ValkkaFS reader thread.
Definition: valkkafsreader.h:55
void sendSignal(ValkkaFSReaderSignalContext signal_ctx)
Insert a signal into the signal_fifo.
Definition: valkkafsreader.cpp:122
void handleSignals()
Call ValkkaFSReaderThread::handleSignal for every signal in the signal_fifo.
Definition: valkkafsreader.cpp:127
void pullBlocksPyCall(PyObject *pylist)
Request blocks with python list.
Definition: valkkafsreader.cpp:311
std::deque< ValkkaFSReaderSignalContext > signal_fifo
Redefinition of signal fifo.
Definition: valkkafsreader.h:73
void setSlotIdCall(SlotNumber slot, IdNumber id)
Set a id number => slot mapping.
Definition: valkkafsreader.cpp:234
void preRun()
Called before entering the main execution loop, but after creating the thread.
Definition: valkkafsreader.cpp:85
void reportSlotIdCall()
Print id number => slot mappings.
Definition: valkkafsreader.cpp:282
void postRun()
Called after the main execution loop exits, but before joining the thread.
Definition: valkkafsreader.cpp:88
void handleSignal(ValkkaFSReaderSignalContext &signal_ctx)
Handle an individual signal. Signal can originate from the frame fifo or from the signal_fifo deque.
Definition: valkkafsreader.cpp:91
FifoFrameFilter infilter
Write incoming frames here. Only for SignalFrames.
Definition: valkkafsreader.h:70
void run()
Main execution loop is defined here.
Definition: valkkafsreader.cpp:46
void requestStopCall()
API method: stops the thread.
Definition: valkkafsreader.cpp:340
void clearSlotIdCall()
Clear all id number => slot mappings.
Definition: valkkafsreader.cpp:268
void unSetSlotIdCall(IdNumber id)
Clear a id number => slot mapping.
Definition: valkkafsreader.cpp:252
FrameFifo infifo
Incoming frames are read from here. The stream is "stateless", so you have to add SetupFrames (for ex...
Definition: valkkafsreader.h:69
Book-keeping for ValkkaFS.
Definition: valkkafs.h:78
List of common header files.
Thread safe system of fifo and a stack.
Definition of FrameFilter and derived classes for various purposes.
Write directly to files and devices with POSIX O_DIRECT.
Describes the stack structure and fifo behaviour for a FrameFifo.
Definition: framefifo.h:56
Encapsulate data sent in the ValkkaFSReaderSignal.
Definition: threadsignal.h:220
Base class for multithreading.