Valkka  0.17.0
OpenSource Video Management
avthread.h
Go to the documentation of this file.
1 #ifndef AVTHREAD_HEADER_GUARD
2 #define AVTHREAD_HEADER_GUARD
3 /*
4  * avthread.h : FFmpeg decoding thread
5  *
6  * Copyright 2017, 2018 Valkka Security Ltd. and 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 Affero 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 Affero General Public License for more details.
21  *
22  * You should have received a copy of the GNU Affero General Public License
23  * along with this program. If not, see <https://www.gnu.org/licenses/>
24  *
25  */
26 
37 #include "constant.h"
38 #include "frame.h"
39 #include "thread.h"
40 #include "decoder.h"
41 #include "tools.h"
42 #include "framefilter.h"
43 
44 
45 
57 class AVThread : public Thread { // <pyapi>
58 
59 public: // <pyapi>
67  AVThread(const char* name, FrameFilter& outfilter, FrameFifoContext fifo_ctx=FrameFifoContext()); // <pyapi>
68  ~AVThread();
69 
70 protected: // frame input
74  int n_threads;
75 
76 protected:
78  std::vector<Decoder*> decoders;
79  long int mstimetolerance;
81 
82 private: // framefilter for chaining output for outfilter2
83  TimestampFrameFilter2 timefilter;
84  bool use_time_correction;
85 
86 protected:
87  bool is_decoding;
88 
89 protected: // Thread member redefinitions
90  std::deque<AVSignalContext> signal_fifo;
91 
92 public: // redefined virtual functions
93  void run();
94  void preRun();
95  void postRun();
96  void sendSignal(AVSignalContext signal_ctx);
97 
98 protected:
99  FrameFifo &getFifo();
100 
101 protected:
102  void handleSignals();
103 
104 public: // API <pyapi>
110  void setNumberOfThreads(int n_threads); // <pyapi>
111  void setTimeCorrection(bool val); // <pyapi>
112  FifoFrameFilter &getFrameFilter(); // <pyapi>
113  FifoFrameFilter &getBlockingFrameFilter(); // <pyapi>
114  void setTimeTolerance(long int mstol);
115  void decodingOnCall();
116  void decodingOffCall();
117  void requestStopCall();
118 }; // <pyapi>
119 
120 #endif
std::string name
Name of the thread.
Definition: thread.h:121
void sendSignal(AVSignalContext signal_ctx)
Redefined : Thread::SignalContext has been changed to AVThread::SignalContext.
Definition: avthread.cpp:331
FrameFifo infifo
Incoming frames are read from here.
Definition: avthread.h:71
void setNumberOfThreads(int n_threads)
Set number of decoding threads.
Definition: avthread.cpp:366
AbstractFileState state
Seek, play, stop or what.
Definition: avthread.h:80
Describes the stack structure and fifo behaviour for a FrameFifo.
Definition: framefifo.h:45
Constant/default values, version numbers.
bool is_decoding
should currently decode or not
Definition: avthread.h:87
AVThread(const char *name, FrameFilter &outfilter, FrameFifoContext fifo_ctx=FrameFifoContext())
Default constructor.
Definition: avthread.cpp:38
A thread-safe combination of a fifo (first-in-first-out) queue and an associated stack.
Definition: framefifo.h:72
BlockingFifoFrameFilter infilter_block
Incoming frames can also be written here. If stack runs out of frames, writing will block...
Definition: avthread.h:73
void decodingOnCall()
API method: enable decoding // <pyapi>
Definition: avthread.cpp:370
~AVThread()
Default destructor. Calls AVThread::stopCall // <pyapi>
Definition: avthread.cpp:49
void postRun()
Called after the main execution loop exits, but before joining the thread.
Definition: avthread.cpp:302
void decodingOffCall()
API method: pause decoding // <pyapi>
Definition: avthread.cpp:377
Redefinition of characteristic signal contexts (info that goes with the signal) for AVThread thread...
Definition: threadsignal.h:78
Corrects erroneous timestamps (while preserving timestamp distances).
Definition: framefilter.h:337
FrameFilter & outfilter
Outgoing, decoded frames are written here.
Definition: avthread.h:77
Base class for multithreading.
Passes frames to a multiprocessing fifo.
Definition: framefilter.h:585
FifoFrameFilter infilter
Write incoming frames here.
Definition: avthread.h:72
std::deque< AVSignalContext > signal_fifo
Redefinition of signal fifo.
Definition: avthread.h:90
Frame classes.
void requestStopCall()
API method: Like Thread::stopCall() but does not block. // <pyapi>
Definition: avthread.cpp:397
long int mstimetolerance
Drop frames if they are in milliseconds this much late.
Definition: avthread.h:79
A thread consuming frames and feeding them to various encoders.
Definition: avthread.h:57
void run()
Main execution loop is defined here.
Definition: avthread.cpp:64
int n_threads
Number of decoding threads.
Definition: avthread.h:74
FFmpeg decoders.
Definition of FrameFilter and derived classes for various purposes.
A class for multithreading with a signaling system.
Definition: thread.h:90
std::vector< Decoder * > decoders
A vector/list of registered and instantiated decoders.
Definition: avthread.h:78
void preRun()
Called before entering the main execution loop, but after creating the thread.
Definition: avthread.cpp:296
Passes frames to a FrameFifo.
Definition: framefilter.h:560
Auxiliary routines.
AbstractFileState
Describes the state of a stream.
Definition: threadsignal.h:43
The mother class of all frame filters! FrameFilters are used to create "filter chains".
Definition: framefilter.h:46
void setTimeTolerance(long int mstol)
API method: decoder will scrap late frames that are mstol milliseconds late. Call before starting the...
Definition: avthread.cpp:317