vdr-plugin-softhddevice-drm-gles 1.5.9-20e15de
videostream.h
Go to the documentation of this file.
1
21#ifndef __VIDEOSTREAM_H
22#define __VIDEOSTREAM_H
23
24#include <atomic>
25#include <functional>
26#include <string>
27
28extern "C" {
29#include <libavcodec/avcodec.h>
30}
31
32#include "queue.h"
33#include "threads.h"
34
35#define VIDEO_BUFFER_SIZE (512 * 1024)
36#define VIDEO_PACKET_MAX 192
37
38// Hardware quirks, that are set depending on the hardware used
39#define QUIRK_NO_HW_DEINT 1 << 0
40#define QUIRK_CODEC_FLUSH_WORKAROUND 1 << 1
41#define QUIRK_CODEC_NEEDS_EXT_INIT 1 << 2
42#define QUIRK_CODEC_SKIP_FIRST_FRAMES 1 << 3
43#define QUIRK_CODEC_SKIP_NUM_FRAMES 2
44#define QUIRK_CODEC_DISABLE_MPEG_HW 1 << 4
45#define QUIRK_CODEC_DISABLE_H264_HW 1 << 5
46
47class cSoftHdConfig;
48class cVideoDecoder;
49class cVideoRender;
50
55{
56public:
57 virtual ~cVideoStream(void);
58
59 void DecodeInput(void);
60 bool IsInterlaced(void) { return false; };
61
62 void Open(AVCodecID, AVCodecParameters * = nullptr, AVRational = { .num = 1, .den = 90000 });
63 void Exit(void);
65 void FlushDecoder(void);
66 void CloseDecoder(void);
67 bool PushAvPacket(AVPacket *avpkt);
68 void Flush(void);
69
70 // getters and setters
71 cVideoDecoder *Decoder(void) { return m_pDecoder; };
72 void StartDecoder();
73 size_t GetAvPacketsFilled(void) { return m_packets.Size(); };
74 bool IsInputBufferFull(void) { return m_packets.Size() >= VIDEO_PACKET_MAX; };
75 enum AVCodecID GetCodecId(void) { return m_codecId; };
77 bool HasInputPts(void) { return m_inputPts != AV_NOPTS_VALUE; }
78 int64_t GetInputPtsMs(void);
79 int64_t GetInputPts(void) { return m_inputPts; };
81 void GetVideoSize(int *, int *, double *);
82
83 // decoding thread
84 void ExitDecodingThread(void);
87
88 // Filter
89 void CancelFilterThread(void);
91
92 virtual void SetDeinterlacerDeactivated(bool deactivate) { m_deinterlacerDeactivated = deactivate; };
94 int HardwareQuirks(void) { return m_hardwareQuirks; };
95 void DisableDeint(bool disable) { m_userDisabledDeinterlacer = disable; };
97 void SetParseH264Dimensions(bool enable) { m_parseH264Dimensions = enable; };
98 void SetDecoderFallbackToSwNumPkts(int numPackets) { m_decoderFallbackToSwNumPkts = numPackets; };
99
100protected:
101 cVideoStream(cVideoRender *, cQueue<cDrmBuffer> *, cSoftHdConfig *, bool, std::function<void(AVFrame *)>);
102
103private:
108 const char *m_identifier;
109 std::string m_filterThreadName;
111 std::function<void(AVFrame *)> m_frameOutput;
113
121
123
124 enum AVCodecID m_codecId = AV_CODEC_ID_NONE;
125 AVCodecParameters *m_pPar = nullptr;
126 std::atomic<struct AVRational> m_timebase;
129 volatile bool m_newStream = false;
131
134
135 void RenderFrame(AVFrame *);
136 void CheckForcingFrameDecode(void);
137 void OpenDecoder(void);
138};
139
144{
145public:
146 cMainVideoStream(cVideoRender *render, cQueue<cDrmBuffer> *buf, cSoftHdConfig *config, std::function<void(AVFrame *)> fn)
147 : cVideoStream(render, buf, config, false, fn) {};
148};
149
154{
155public:
156 cPipVideoStream(cVideoRender *render, cQueue<cDrmBuffer> *buf, cSoftHdConfig *config, std::function<void(AVFrame *)> fn)
157 : cVideoStream(render, buf, config, true, fn) {};
158 void SetDeinterlacerDeactivated(bool) override {}; // deinterlacing is permanently disabled
159};
160
161#endif
Decoding thread class.
Definition threads.h:46
void Resume(void)
Definition threads.h:51
void Halt(void)
Definition threads.h:50
Filter thread class.
Definition threads.h:100
cMainVideoStream - Main video stream class
cMainVideoStream(cVideoRender *render, cQueue< cDrmBuffer > *buf, cSoftHdConfig *config, std::function< void(AVFrame *)> fn)
cPipVideoStream - Pip video stream class
cPipVideoStream(cVideoRender *render, cQueue< cDrmBuffer > *buf, cSoftHdConfig *config, std::function< void(AVFrame *)> fn)
void SetDeinterlacerDeactivated(bool) override
Thread-safe queue class.
Definition queue.h:36
size_t Size(void)
Get the current size of the queue.
Definition queue.h:128
cVideoDecoder - VideoDecoder class
Definition codec_video.h:33
cVideoRender - Video render class
cVideoStream - Video stream class
Definition videostream.h:55
cDecodingThread * m_pDecodingThread
pointer to decoding thread
bool m_interlaced
flag for interlaced stream
void GetVideoSize(int *, int *, double *)
Get video size and aspect ratio.
void OpenDecoder(void)
Open the decoder including an H.264 parsing if needed.
cFilterThread * m_pFilterThread
pointer to deinterlace filter thread
int HardwareQuirks(void)
Definition videostream.h:94
std::function< void(AVFrame *)> m_frameOutput
function to output the frame
const char * m_identifier
identifier string for logging
void SetDecoderFallbackToSwNumPkts(int numPackets)
Definition videostream.h:98
cSoftHdConfig * m_pConfig
plugin config
int64_t m_inputPts
PTS of the first packet in the input buffer.
bool m_deinterlacerDeactivated
set, if the deinterlacer should be disabled temporarily (trickspeed, stillpicture,...
int m_sentTrickPkts
how many avpkt have been sent to the decoder in trickspeed mode?
std::string m_decodingThreadName
decoding thread name string (persists for object lifetime)
void Flush(void)
Flushes the video stream by finalizing any pending data.
bool m_parseH264Dimensions
parse width and height when starting an h264 stream
void StartDecoder()
Start the decoder.
void DecodingThreadResume(void)
Definition videostream.h:86
cVideoDecoder * Decoder(void)
Definition videostream.h:71
void CheckForcingFrameDecode(void)
Check, if we need to force the decoder to decode the frame (force a decoder drain)
bool m_startDecodingWithIFrame
wait for an I-Frame to start h264 decoding
void ClearVdrCoreToDecoderQueue(void)
Clears all video stream data, which is buffered to be decoded.
bool m_userDisabledDeinterlacer
set, if the user configured the deinterlace to be disabled
void ResetInputPts(void)
Definition videostream.h:80
volatile bool m_newStream
flag for new stream
enum AVCodecID m_codecId
current codec id
bool m_checkFilterThreadNeeded
set, if we have to check, if filter thread is needed at start of playback
bool IsInterlaced(void)
Definition videostream.h:60
void SetStartDecodingWithIFrame(bool enable)
Definition videostream.h:96
size_t GetAvPacketsFilled(void)
Definition videostream.h:73
AVCodecParameters * m_pPar
current codec parameters
int m_decoderFallbackToSwNumPkts
fallback to sw decoder if hw decoder fails after the given number of packets sent
void DecodeInput(void)
Decodes a reassembled codec packet.
cQueue< cDrmBuffer > * m_pDrmBufferQueue
pointer to renderer's DRM buffer queue
void DisableDeint(bool disable)
Definition videostream.h:95
bool IsDeinterlacerDeactivated(void)
Definition videostream.h:93
void CloseDecoder(void)
Close the decoder.
int m_hardwareQuirks
hardware specific quirks
cVideoDecoder * m_pDecoder
video decoder
void Exit(void)
Exit video stream.
virtual ~cVideoStream(void)
cVideoStream destructor
void CancelFilterThread(void)
Stop filter thread.
void DecodingThreadHalt(void)
Definition videostream.h:85
cVideoRender * m_pRender
video renderer
int m_trickpkts
how many avpkt does the decoder need in trickspeed mode?
void RenderFrame(AVFrame *)
Render a frame.
cQueue< AVPacket > m_packets
AVPackets queue.
void ExitDecodingThread(void)
Stop decoding thread.
void FlushDecoder(void)
Flush the decoder.
void Open(AVCodecID, AVCodecParameters *=nullptr, AVRational={ .num=1,.den=90000 })
Open a video codec.
bool PushAvPacket(AVPacket *avpkt)
Pushes a pre-assembled AVPacket directly to the processing queue.
bool IsInputBufferFull(void)
Definition videostream.h:74
int64_t GetInputPts(void)
Definition videostream.h:79
void ResetFilterThreadNeededCheck()
Definition videostream.h:90
int64_t GetInputPtsMs(void)
void SetParseH264Dimensions(bool enable)
Definition videostream.h:97
std::string m_filterThreadName
filter thread name string (persists for object lifetime)
virtual void SetDeinterlacerDeactivated(bool deactivate)
Definition videostream.h:92
void ResetTrickSpeedFramesSentCounter(void)
Definition videostream.h:76
enum AVCodecID GetCodecId(void)
Definition videostream.h:75
std::atomic< struct AVRational > m_timebase
current codec timebase
bool HasInputPts(void)
Definition videostream.h:77
#define AV_NOPTS_VALUE
Definition misc.h:69
Thread-safe queue header file.
Thread classes header file.
#define VIDEO_PACKET_MAX
max number of video packets held in the buffer
Definition videostream.h:36