vdr-plugin-softhddevice-drm-gles 1.7.3-98a2ef7
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/remux.h>
27#include <vdr/thread.h>
28
29#include "queue.h"
30#include "videofilter.h"
31
32class cDrmBuffer;
33class cSoftHdConfig;
34class cVideoDecoder;
35class cVideoRender;
36
48class cVideoStream : public cThread {
49public:
50 virtual ~cVideoStream(void);
51
52 void DecodeInput(void);
53 bool IsInterlaced(void) { return false; };
54
55 void Open(AVCodecID, AVCodecParameters * = nullptr, AVRational = { .num = 1, .den = PTSTICKS });
56 void Exit(void);
58 void FlushDecoder(void);
59 void CloseDecoder(void);
61 bool Drain(void);
62
63 // decoding thread
64 void Stop(void);
65 void Halt(void) { m_mutex.lock(); };
66 void Resume(void) { m_mutex.unlock(); };
67
68 // getters and setters
69 cVideoDecoder *Decoder(void) { return m_pDecoder; };
70 void StartDecoder();
71 size_t GetAvPacketsFilled(void) { return m_packets.Size(); };
72 bool IsInputBufferFull(void) { return m_packets.Size() >= VIDEO_PACKET_MAX; };
73 bool BuffersEmpty(void);
74 enum AVCodecID GetCodecId(void) { return m_codecId; };
76 bool HasInputPts(void) { return m_inputPts != AV_NOPTS_VALUE; }
77 int64_t GetInputPtsMs(void) { return m_inputPts * 1000 * av_q2d(m_timebase); };
79 void GetVideoSize(int *, int *, double *);
80 int GetVideoPacketMax(void) { return VIDEO_PACKET_MAX; };
81
82 // Filter
83 void CancelFilterThread(void);
85
90
91protected:
92 cVideoStream(cVideoRender *, int, cQueue<cDrmBuffer> *, cSoftHdConfig *, bool, std::function<void(AVFrame *)>);
93 virtual void Action(void);
94
95private:
99 const char *m_identifier;
100 std::function<void(AVFrame *)> m_frameOutput;
103 std::mutex m_mutex;
104
109 bool m_useDeinterlacer = false;
111
112 constexpr static int VIDEO_PACKET_MAX = 192;
114 constexpr static int AV_SYNC_BORDER_MS = 5000;
115
118 std::atomic<struct AVRational> m_timebase;
121 std::atomic<bool> m_newStream = false;
123 double m_framerate = 0.0;
124
128
129 // h264 parsing
130 std::vector<std::string> m_naluTypesAtStart;
131 int m_numIFrames = 0;
132 int m_logPackets = 0;
134 std::set<int> m_dpbFrames;
139 bool m_isResend = false;
141
142 void SendPacket(AVPacket *);
143 int ReceiveFrame(AVFrame **);
144 void RenderFrame(AVFrame *);
145 void CheckForcingFrameDecode(void);
146 void OpenDecoder(void);
149 int64_t PtsToMs(int64_t pts) { return pts * av_q2d(m_timebase) * 1000; };
150};
151
158public:
160 : cVideoStream(render, hardwareQuirks, buf, config, false, fn) {};
161};
162
169public:
171 : cVideoStream(render, hardwareQuirks, buf, config, true, fn) {};
172 void SetDeinterlacerDeactivated(bool) override {}; // deinterlacing is permanently disabled
173};
174
175#endif
DRM Buffer.
Definition drmbuffer.h:33
Main Video Stream.
cMainVideoStream(cVideoRender *render, int hardwareQuirks, cQueue< cDrmBuffer > *buf, cSoftHdConfig *config, std::function< void(AVFrame *)> fn)
PiP Video Stream.
cPipVideoStream(cVideoRender *render, int hardwareQuirks, 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:121
Plugin Configuration.
Definition config.h:65
Video Decoder.
Definition codec_video.h:37
Video Filter.
Definition videofilter.h:41
Video Renderer.
Video Input Stream.
Definition videostream.h:48
std::mutex m_mutex
mutex for decoding thread control
bool m_interlaced
flag for interlaced stream
void GetVideoSize(int *, int *, double *)
Get video size and aspect ratio.
bool Drain(void)
Drains the video stream by finalizing any pending data.
bool BuffersEmpty(void)
Return true, if the input AVPacket, videofilter and drm output buffer queues are empty.
bool ParseH264Packet(AVPacket *)
Parse an H.264 packet and test, if the packet is a P-Slice with invalid backward references.
void Open(AVCodecID, AVCodecParameters *=nullptr, AVRational={ .num=1,.den=PTSTICKS })
Open a video codec.
void OpenDecoder(void)
Open the decoder including an H.264 parsing if needed.
std::atomic< bool > m_newStream
flag for new stream
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
Definition videostream.h:99
int ReceiveFrame(AVFrame **)
Receive a decoded frame from the decoder.
void SetDecoderFallbackToSwNumPkts(int numPackets)
Definition videostream.h:89
cSoftHdConfig * m_pConfig
plugin config
Definition videostream.h:96
int64_t m_inputPts
PTS of the first packet in the input buffer.
double m_framerate
current stream framerate
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
void StartDecoder()
Start the decoder.
cVideoDecoder * Decoder(void)
Definition videostream.h:69
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.
bool m_userDisabledDeinterlacer
set, if the user configured the deinterlace to be disabled
void ResetInputPts(void)
Definition videostream.h:78
void Resume(void)
Definition videostream.h:66
int m_ppsNumRefIdxL1DefaultActiveMinus1
cache NumRefIdxL1DefaultActiveMinuns1 from a previous PPS parsing
enum AVCodecID m_codecId
current codec id
int GetVideoPacketMax(void)
Definition videostream.h:80
bool m_checkFilterThreadNeeded
set, if we have to check, if filter thread is needed at start of playback
bool IsInterlaced(void)
Definition videostream.h:53
int64_t m_ptsForFramerateDetection
helper PTS to calculate a framerate at stream start
bool m_useDeinterlacer
set, if the deinterlacer is used
int m_log2MaxFrameNumMinus4
cache Log2MaxFrameNumMinus4 from a previous SPS parsing
size_t GetAvPacketsFilled(void)
Definition videostream.h:71
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
void DecodeInput(void)
Decodes a reassembled codec packet.
bool m_isResend
track, if we already tried to send the AVPacket to the decoder if so, skip the parsing
void Stop(void)
Stop the decoding thread.
static constexpr int AV_SYNC_BORDER_MS
absolute max a/v difference which should trigger a decoder flush
cQueue< cDrmBuffer > * m_pDrmBufferQueue
pointer to renderer's DRM buffer queue
void DisableDeint(bool disable)
Definition videostream.h:88
virtual void Action(void)
Decoding thread loop, which periodically tries to decode input.
bool IsDeinterlacerDeactivated(void)
Definition videostream.h:87
void CloseDecoder(void)
Close the decoder.
int m_hardwareQuirks
hardware specific quirks
cVideoDecoder * m_pDecoder
video decoder
Definition videostream.h:97
cVideoFilter m_videoFilter
pointer to deinterlace/scaling video filter thread
int m_maxFrameNum
= 1 << Log2MaxFrameNumMinus4 + 4
void Exit(void)
Exit video stream.
virtual ~cVideoStream(void)
std::vector< std::string > m_naluTypesAtStart
array of strings to log the H.264 frames at stream start
void CancelFilterThread(void)
Stop filter thread.
int m_ppsNumRefIdxL0DefaultActiveMinus1
cache NumRefIdxL0DefaultActiveMinuns1 from a previous PPS parsing
cVideoRender * m_pRender
video renderer
Definition videostream.h:98
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.
int64_t m_lastDecodedPts
PTS of the latest packet, which was sent to the decoder in order to detect stream discontinuity.
void FlushDecoder(void)
Flush the decoder.
bool PushAvPacket(AVPacket *avpkt)
Pushes a pre-assembled AVPacket directly to the processing queue.
bool IsInputBufferFull(void)
Definition videostream.h:72
void ResetFilterThreadNeededCheck()
Definition videostream.h:84
int64_t GetInputPtsMs(void)
Definition videostream.h:77
bool PacketDropNeeded(AVPacket *)
Test if the packet should be dropped and parse it if needed (see cVideoStream::ParseH264())
void Halt(void)
Definition videostream.h:65
virtual void SetDeinterlacerDeactivated(bool deactivate)
Definition videostream.h:86
int64_t PtsToMs(int64_t pts)
int m_numIFrames
counter for the arriving I-Frames at H.264 stream start
void SendPacket(AVPacket *)
Send a packet to the decoder.
void ResetTrickSpeedFramesSentCounter(void)
Definition videostream.h:75
enum AVCodecID GetCodecId(void)
Definition videostream.h:74
std::atomic< struct AVRational > m_timebase
current codec timebase
bool HasInputPts(void)
Definition videostream.h:76
std::set< int > m_dpbFrames
private set of reference frames (internal short-time decoded picture buffer)
#define AV_NOPTS_VALUE
Definition misc.h:76
Thread-safe Queue.
Deinterlace and Scaling Filters Header File.