23#include <libavcodec/avcodec.h>
24#include <libavformat/avformat.h>
25#include <libavutil/timestamp.h>
28#include <vdr/thread.h>
119 LOGDEBUG2(
L_DRM,
"videostream: %s: bcm2837 (Raspberry Pi 2 Model B v1.2/ 3 Model B, Raspberry Pi 3 Compute Module 3) found",
__FUNCTION__);
158 : cThread(
isPipStream ?
"shd PIP decode" :
"shd main decode"),
165 m_videoFilter(render, m_pDrmBufferQueue,
isPipStream ?
"shd PIP filter" :
"shd main filter",
frameOutput),
166 m_userDisabledDeinterlacer(config->ConfigDisableDeint),
168 m_startDecodingWithIFrame(config->ConfigDecoderNeedsIFrame),
169 m_parseH264Dimensions(config->ConfigParseH264Dimensions)
405 if (
mod.idc != 0 &&
mod.idc != 1)
414 int diff =
mod.abs_diff_pic_num_minus1 + 1;
418 }
else if (
mod.idc == 1) {
567 LOGDEBUG(
"videostream: decoding thread started");
577 LOGDEBUG(
"videostream: decoding thread stopped");
588 LOGDEBUG(
"videostream: stopping decoding thread");
T * Pop(void)
Pop an element from the back of the queue.
bool IsEmpty(void)
Check if the queue is empty.
bool IsFull(void)
Check if the queue is full.
bool Push(T *element)
Push an element to the front of the queue.
size_t Size(void)
Get the current size of the queue.
T * Peek(void)
Get a reference to the back element.
int ConfigParseH264StreamStart
log frames at stream start up to the given number of I-Frames
int ConfigDecoderFallbackToSwNumPkts
maximum number of packets sent before fallback to sw decoder
const char * CurrentDecoderType
current decoder type: "hardware" or "software"
const char * CurrentDecoderName
current decoder name
bool ConfigDecoderFallbackToSw
fallback to software decoder if the hardware decoder fails
int ConfigDropInvalidH264PFrames
drop P-Frames with invalid references on stream start up to the given number of I-Frames
AVCodecContext * GetContext(void)
bool IsHardwareDecoder(void)
int GetFramesReceived(void)
int GetNumFramesToFilter(void)
bool IsInputBufferFull(void)
bool IsForwardTrickspeed(void)
std::mutex m_mutex
mutex for decoding thread control
bool m_interlaced
flag for interlaced 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
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
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
volatile bool m_newStream
flag for new stream
int m_ppsNumRefIdxL1DefaultActiveMinus1
cache NumRefIdxL1DefaultActiveMinuns1 from a previous PPS parsing
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
int m_log2MaxFrameNumMinus4
cache Log2MaxFrameNumMinus4 from a previous SPS parsing
AVCodecParameters * m_pPar
current codec parameters
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
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.
virtual void SetDeinterlacerDeactivated(bool deactivate)
int m_numIFrames
counter for the arriving I-Frames at H.264 stream start
std::atomic< struct AVRational > m_timebase
current codec timebase
std::set< int > m_dpbFrames
private set of reference frames (internal short-time decoded picture buffer)
Video Decoder Header File.
Plugin Configuration Header File.
void SetDecoderNeedsMaxPackets(int)
int GetDecoderNeedsMaxPackets(void)
void InitAndStart(const AVCodecContext *, AVFrame *, bool)
Init and start the video filter thread.
void Stop(void)
Stops the filter thread and does a cleanup.
void PushFrame(AVFrame *)
Puts a frame in the buffer to be filtered.
#define LOGDEBUG2
log to LOG_DEBUG and add a prefix
#define LOGDEBUG
log to LOG_DEBUG
#define LOGERROR
log to LOG_ERR
#define LOGWARNING
log to LOG_WARN
#define LOGFATAL
log to LOG_ERR and abort
static bool isInterlacedFrame(AVFrame *frame)
Check, if this is an interlaced frame.
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.
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.
static size_t ReadLineFromFile(char *buf, size_t size, const char *file)
Helper function to read a line from a given file.
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.
static int ReadHWPlatform(void)
Helper function to find out which platform we are on.
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)
cVideoStream(cVideoRender *, cQueue< cDrmBuffer > *, cSoftHdConfig *, bool, std::function< void(AVFrame *)>)
Create a video stream.
@ QUIRK_CODEC_FLUSH_WORKAROUND
set, if we have to close and reopen the codec instead of avcodec_flush_buffers (rpi)
@ QUIRK_CODEC_SKIP_FIRST_FRAMES
set, if codec should skip first I-Frames
@ QUIRK_NO_HW_DEINT
set, if no hw deinterlacer available
@ QUIRK_CODEC_NEEDS_EXT_INIT
set, if codec needs some infos for init (coded_width and coded_height)
int ReopenCodec(enum AVCodecID, AVCodecParameters *, AVRational, int)
Reopen the video decoder.
int SendPacket(const AVPacket *)
Send a video packet to be decoded.
int Open(enum AVCodecID, AVCodecParameters *, AVRational, bool, int, int)
Open the video decoder.
void FlushBuffers(void)
Flush the video decoder buffers.
int ReceiveFrame(AVFrame **)
Receive a decoded a video frame.
void Close(void)
Close video decoder.
H.264 Parser Header File.
Deinterlace and Scaling Filters Header File.
Video Renderer (Display) Header File.
Video Input Stream Header File.