Valkka  1.6.1
OpenSource Video Management
decoderthread.h
Go to the documentation of this file.
1 #ifndef decoderthread_HEADER_GUARD
2 #define decoderthread_HEADER_GUARD
3 /*
4  * decoderthread.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 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 
36 #include "constant.h"
37 #include "frame.h"
38 #include "thread.h"
39 #include "decoder.h"
40 #include "tools.h"
41 #include "framefilter.h"
42 
43 class DecoderThread : public Thread { // <pyapi>
44 
45 public: // <pyapi>
53  DecoderThread(const char* name, FrameFilter& outfilter, FrameFifoContext fifo_ctx=FrameFifoContext()); // <pyapi>
54  virtual ~DecoderThread();
55 
56 protected: // frame input
60  int n_threads;
61 
62 protected:
64  std::vector<Decoder*> decoders;
65  long int mstimetolerance;
67  std::vector<SetupFrame> setupframes;
68 
69 private: // framefilter for chaining output for outfilter2
70  TimestampFrameFilter2 timefilter;
71  bool use_time_correction;
72 
73 protected:
74  bool is_decoding;
75 
76 protected: // Thread member redefinitions
77  std::deque<AVSignalContext> signal_fifo;
78 
79 protected:
80  virtual Decoder* chooseAudioDecoder(AVCodecID codec_id);
81  virtual Decoder* chooseVideoDecoder(AVCodecID codec_id);
82  virtual Decoder* fallbackAudioDecoder(AVCodecID codec_id);
86  virtual Decoder* fallbackVideoDecoder(AVCodecID codec_id);
87 
88 public: // redefined virtual functions
89  void run();
90  void preRun();
91  void postRun();
92  void sendSignal(AVSignalContext signal_ctx);
93 
94 protected:
95  FrameFifo &getFifo();
96 
97 protected:
98  void handleSignals();
99 
100 public: // API <pyapi>
106  void setTimeCorrection(bool val); // <pyapi>
107  FifoFrameFilter &getFrameFilter(); // <pyapi>
108  FifoFrameFilter &getBlockingFrameFilter(); // <pyapi>
109  void setTimeTolerance(long int mstol);
110  void setNumberOfThreads(int n_threads); // <pyapi>
111  void decodingOnCall();
112  void decodingOffCall();
113  void requestStopCall();
114 }; // <pyapi>
115 
116 
117 #endif
Passes frames to a multiprocessing fifo.
Definition: framefilter.h:554
Definition: decoderthread.h:43
BlockingFifoFrameFilter infilter_block
Incoming frames can also be written here. If stack runs out of frames, writing will block.
Definition: decoderthread.h:59
AbstractFileState state
Seek, play, stop or what.
Definition: decoderthread.h:66
FrameFilter & outfilter
Outgoing, decoded frames are written here.
Definition: decoderthread.h:63
void decodingOnCall()
API method: enable decoding // <pyapi>
Definition: decoderthread.cpp:427
DecoderThread(const char *name, FrameFilter &outfilter, FrameFifoContext fifo_ctx=FrameFifoContext())
Default constructor.
Definition: decoderthread.cpp:39
bool is_decoding
should currently decode or not
Definition: decoderthread.h:74
virtual Decoder * fallbackVideoDecoder(AVCodecID codec_id)
If the the video decoder obtained from chooseVideoDecoder fails for some reason, provide a fallback v...
Definition: decoderthread.cpp:95
void run()
Main execution loop is defined here.
Definition: decoderthread.cpp:101
void postRun()
Called after the main execution loop exits, but before joining the thread.
Definition: decoderthread.cpp:360
void requestStopCall()
API method: Like Thread::stopCall() but does not block. // <pyapi>
Definition: decoderthread.cpp:454
virtual ~DecoderThread()
Default destructor. Calls AVThread::stopCall // <pyapi>
Definition: decoderthread.cpp:50
std::deque< AVSignalContext > signal_fifo
Redefinition of signal fifo.
Definition: decoderthread.h:77
long int mstimetolerance
Drop frames if they are in milliseconds this much late.
Definition: decoderthread.h:65
void setTimeCorrection(bool val)
Set number of decoding threads.
Definition: decoderthread.cpp:379
FrameFifo infifo
Incoming frames are read from here.
Definition: decoderthread.h:57
void setTimeTolerance(long int mstol)
API method: decoder will scrap late frames that are mstol milliseconds late. Call before starting the...
Definition: decoderthread.cpp:375
virtual Decoder * chooseVideoDecoder(AVCodecID codec_id)
Chooses a video decoder.
Definition: decoderthread.cpp:76
void preRun()
Called before entering the main execution loop, but after creating the thread.
Definition: decoderthread.cpp:354
std::vector< Decoder * > decoders
A vector/list of registered and instantiated decoders.
Definition: decoderthread.h:64
void decodingOffCall()
API method: pause decoding // <pyapi>
Definition: decoderthread.cpp:434
FifoFrameFilter infilter
Write incoming frames here.
Definition: decoderthread.h:58
void sendSignal(AVSignalContext signal_ctx)
Redefined : Thread::SignalContext has been changed to AVThread::SignalContext.
Definition: decoderthread.cpp:389
std::vector< SetupFrame > setupframes
Save decoder(s) setup information.
Definition: decoderthread.h:67
A Virtual class for decoders.
Definition: decoder.h:62
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
A class for multithreading with a signaling system.
Definition: thread.h:87
std::string name
Name of the thread.
Definition: thread.h:116
Corrects erroneous timestamps (while preserving timestamp distances).
Definition: framefilter.h:317
Constant/default values, version numbers.
FFmpeg decoders.
Frame classes.
Definition of FrameFilter and derived classes for various purposes.
AbstractFileState
Describes the state of a stream.
Definition: threadsignal.h:43
Redefinition of characteristic signal contexts (info that goes with the signal) for AVThread thread.
Definition: threadsignal.h:94
Describes the stack structure and fifo behaviour for a FrameFifo.
Definition: framefifo.h:56
Base class for multithreading.
Auxiliary routines.