vdr-plugin-softhddevice-drm-gles 1.6.2
videostream.h
Go to the documentation of this file.
1// SPDX-License-Identifier: AGPL-3.0-or-later
2
13#ifndef __VIDEOSTREAM_H
14#define __VIDEOSTREAM_H
15
16#include <atomic>
17#include <functional>
18#include <set>
19#include <string>
20#include <vector>
21
22extern "C" {
23#include <libavcodec/avcodec.h>
24}
25
26#include <vdr/thread.h>
27
28#include "queue.h"
29#include "videofilter.h"
30
31class cDrmBuffer;
32class cSoftHdConfig;
33class cVideoDecoder;
34class cVideoRender;
35
53
57class cVideoStream : public cThread {
58public:
59 virtual ~cVideoStream(void);
60
61 void DecodeInput(void);
62 bool IsInterlaced(void) { return false; };
63
64 void Open(AVCodecID, AVCodecParameters * = nullptr, AVRational = { .num = 1, .den = 90000 });
65 void Exit(void);
67 void FlushDecoder(void);
68 void CloseDecoder(void);
70 void Flush(void);
71
72 // decoding thread
73 void Stop(void);
74 void Halt(void) { m_mutex.lock(); };
75 void Resume(void) { m_mutex.unlock(); };
76
77 // getters and setters
78 cVideoDecoder *Decoder(void) { return m_pDecoder; };
79 void StartDecoder();
80 size_t GetAvPacketsFilled(void) { return m_packets.Size(); };
81 bool IsInputBufferFull(void) { return m_packets.Size() >= VIDEO_PACKET_MAX; };
82 enum AVCodecID GetCodecId(void) { return m_codecId; };
84 bool HasInputPts(void) { return m_inputPts != AV_NOPTS_VALUE; }
86 int64_t GetInputPts(void) { return m_inputPts; };
88 void GetVideoSize(int *, int *, double *);
89 int GetVideoPacketMax(void) { return VIDEO_PACKET_MAX; };
90
91 // Filter
92 void CancelFilterThread(void);
94
97 int HardwareQuirks(void) { return m_hardwareQuirks; };
102
103protected:
104 cVideoStream(cVideoRender *, cQueue<cDrmBuffer> *, cSoftHdConfig *, bool, std::function<void(AVFrame *)>);
105 virtual void Action(void);
106
107private:
111 const char *m_identifier;
112 std::function<void(AVFrame *)> m_frameOutput;
115 std::mutex m_mutex;
116
124
125 constexpr static int VIDEO_PACKET_MAX = 192;
127
130 std::atomic<struct AVRational> m_timebase;
133 volatile bool m_newStream = false;
135
137
138 // h264 parsing
139 std::vector<std::string> m_naluTypesAtStart;
140 int m_numIFrames = 0;
141 int m_logPackets = 0;
143 std::set<int> m_dpbFrames;
148 bool m_isResend = false;
150
151 void RenderFrame(AVFrame *);
152 void CheckForcingFrameDecode(void);
153 void OpenDecoder(void);
155};
156
161public:
162 cMainVideoStream(cVideoRender *render, cQueue<cDrmBuffer> *buf, cSoftHdConfig *config, std::function<void(AVFrame *)> fn)
163 : cVideoStream(render, buf, config, false, fn) {};
164};
165
170public:
171 cPipVideoStream(cVideoRender *render, cQueue<cDrmBuffer> *buf, cSoftHdConfig *config, std::function<void(AVFrame *)> fn)
172 : cVideoStream(render, buf, config, true, fn) {};
173 void SetDeinterlacerDeactivated(bool) override {}; // deinterlacing is permanently disabled
174};
175
178#endif
DRM Buffer.
Definition drmbuffer.h:47
Main Video Stream.
cMainVideoStream(cVideoRender *render, cQueue< cDrmBuffer > *buf, cSoftHdConfig *config, std::function< void(AVFrame *)> fn)
PiP Video Stream.
cPipVideoStream(cVideoRender *render, cQueue< cDrmBuffer > *buf, cSoftHdConfig *config, std::function< void(AVFrame *)> fn)
void SetDeinterlacerDeactivated(bool) override
size_t Size(void)
Get the current size of the queue.
Definition queue.h:124
Plugin Configuration.
Definition config.h:29
Video Decoder.
Definition codec_video.h:32
Video Filter.
Definition videofilter.h:39
Video Renderer.
Video Input Stream.
Definition videostream.h:57
std::mutex m_mutex
mutex for decoding thread control
bool m_interlaced
flag for interlaced stream
int HardwareQuirks(void)
Definition videostream.h:97
int m_dropInvalidPackets
drop P-Frames with invalid references until the given number of I-Frames arrived
std::function< void(AVFrame *)> m_frameOutput
function to output the frame
const char * m_identifier
identifier string for logging
void SetDecoderFallbackToSwNumPkts(int numPackets)
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?
int m_logPackets
parse and log all frames until the number of given I-Frames arrived
bool m_parseH264Dimensions
parse width and height when starting an h264 stream
cVideoDecoder * Decoder(void)
Definition videostream.h:78
bool m_startDecodingWithIFrame
wait for an I-Frame to start h264 decoding
bool m_userDisabledDeinterlacer
set, if the user configured the deinterlace to be disabled
void ResetInputPts(void)
Definition videostream.h:87
volatile bool m_newStream
flag for new stream
void Resume(void)
Definition videostream.h:75
int m_ppsNumRefIdxL1DefaultActiveMinus1
cache NumRefIdxL1DefaultActiveMinuns1 from a previous PPS parsing
enum AVCodecID m_codecId
current codec id
int GetVideoPacketMax(void)
Definition videostream.h:89
bool m_checkFilterThreadNeeded
set, if we have to check, if filter thread is needed at start of playback
bool IsInterlaced(void)
Definition videostream.h:62
int m_log2MaxFrameNumMinus4
cache Log2MaxFrameNumMinus4 from a previous SPS parsing
void SetStartDecodingWithIFrame(bool enable)
Definition videostream.h:99
size_t GetAvPacketsFilled(void)
Definition videostream.h:80
AVCodecParameters * m_pPar
current codec parameters
static constexpr int VIDEO_PACKET_MAX
max number of video packets held in the buffer
int m_decoderFallbackToSwNumPkts
fallback to sw decoder if hw decoder fails after the given number of packets sent
bool m_isResend
track, if we already tried to send the AVPacket to the decoder if so, skip the parsing
cQueue< cDrmBuffer > * m_pDrmBufferQueue
pointer to renderer's DRM buffer queue
void DisableDeint(bool disable)
Definition videostream.h:98
bool IsDeinterlacerDeactivated(void)
Definition videostream.h:96
int m_hardwareQuirks
hardware specific quirks
cVideoDecoder * m_pDecoder
video decoder
cVideoFilter m_videoFilter
pointer to deinterlace/scaling video filter thread
int m_maxFrameNum
= 1 << Log2MaxFrameNumMinus4 + 4
std::vector< std::string > m_naluTypesAtStart
array of strings to log the H.264 frames at stream start
int m_ppsNumRefIdxL0DefaultActiveMinus1
cache NumRefIdxL0DefaultActiveMinuns1 from a previous PPS parsing
cVideoRender * m_pRender
video renderer
int m_trickpkts
how many avpkt does the decoder need in trickspeed mode?
cQueue< AVPacket > m_packets
AVPackets queue.
bool IsInputBufferFull(void)
Definition videostream.h:81
int64_t GetInputPts(void)
Definition videostream.h:86
void ResetFilterThreadNeededCheck()
Definition videostream.h:93
void SetParseH264Dimensions(bool enable)
void Halt(void)
Definition videostream.h:74
virtual void SetDeinterlacerDeactivated(bool deactivate)
Definition videostream.h:95
int m_numIFrames
counter for the arriving I-Frames at H.264 stream start
void ResetTrickSpeedFramesSentCounter(void)
Definition videostream.h:83
enum AVCodecID GetCodecId(void)
Definition videostream.h:82
std::atomic< struct AVRational > m_timebase
current codec timebase
bool HasInputPts(void)
Definition videostream.h:84
std::set< int > m_dpbFrames
private set of reference frames (internal short-time decoded picture buffer)
#define AV_NOPTS_VALUE
Definition misc.h:74
void GetVideoSize(int *, int *, double *)
Get video size and aspect ratio.
bool ParseH264Packet(AVPacket *)
Parse an H.264 packet.
void OpenDecoder(void)
Open the decoder including an H.264 parsing if needed.
HardwareQuirks
Hardware quirks, that are set depending on the hardware used.
Definition videostream.h:44
void Flush(void)
Flushes the video stream by finalizing any pending data.
void StartDecoder()
Start the decoder.
void CheckForcingFrameDecode(void)
Check, if we need to force the decoder to decode the frame (force a decoder drain)
void ClearVdrCoreToDecoderQueue(void)
Clears all video stream data, which is buffered to be decoded.
void DecodeInput(void)
Decodes a reassembled codec packet.
void Stop(void)
Stop the decoding thread.
virtual void Action(void)
Decoding thread loop, which periodically tries to decode input.
void CloseDecoder(void)
Close the decoder.
void Exit(void)
Exit video stream.
virtual ~cVideoStream(void)
void CancelFilterThread(void)
Stop filter thread.
void RenderFrame(AVFrame *)
Render a frame.
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.
int64_t GetInputPtsMs(void)
@ QUIRK_CODEC_FLUSH_WORKAROUND
set, if we have to close and reopen the codec instead of avcodec_flush_buffers (rpi)
Definition videostream.h:46
@ QUIRK_CODEC_SKIP_FIRST_FRAMES
set, if codec should skip first I-Frames
Definition videostream.h:48
@ QUIRK_CODEC_SKIP_NUM_FRAMES
skip QUIRK_CODEC_SKIP_NUM_FRAMES, in case QUIRK_CODEC_SKIP_FIRST_FRAMES is set
Definition videostream.h:49
@ QUIRK_CODEC_DISABLE_MPEG_HW
set, if disable mpeg hardware decoder
Definition videostream.h:50
@ QUIRK_NO_HW_DEINT
set, if no hw deinterlacer available
Definition videostream.h:45
@ QUIRK_CODEC_DISABLE_H264_HW
set, if disable h264 hardware decoder
Definition videostream.h:51
@ QUIRK_CODEC_NEEDS_EXT_INIT
set, if codec needs some infos for init (coded_width and coded_height)
Definition videostream.h:47
Thread-safe Queue.
Deinterlace and Scaling Filters Header File.