vdr-plugin-softhddevice-drm-gles 1.6.4-d0291bb
cVideoDecoder Class Reference

Video Decoder. More...

#include <codec_video.h>

Public Member Functions

 cVideoDecoder (const char *)
 Create a new video decoder.
 
int Open (enum AVCodecID, AVCodecParameters *, AVRational, bool, int, int)
 Open the video decoder.
 
void Close (void)
 Close video decoder.
 
int SendPacket (const AVPacket *)
 Send a video packet to be decoded.
 
int ReceiveFrame (AVFrame **)
 Receive a decoded a video frame.
 
void FlushBuffers (void)
 Flush the video decoder buffers.
 
int ReopenCodec (enum AVCodecID, AVCodecParameters *, AVRational, int)
 Reopen the video decoder.
 
AVCodecContextGetContext (void)
 
bool IsHardwareDecoder (void)
 
const charName (void)
 
int GetPacketsSent (void)
 
int GetFramesReceived (void)
 
void SetSkipKeyFramesNum (int num)
 

Private Member Functions

int GetExtraData (const AVPacket *)
 Get extradata from avpkt.
 
bool IsKeyFrame (AVFrame *)
 Check, if this is a key frame.
 

Private Attributes

AVCodecContextm_pVideoCtx = nullptr
 video codec context
 
const charm_identifier
 identifier for logging
 
const charm_pCodecString = "unknown"
 codec (long) name string
 
std::mutex m_mutex
 mutex to lock codec context
 
int m_cntPacketsSent
 number of packets sent to decoder
 
int m_cntFramesReceived
 number of decoded frames received from decoder
 
int m_cntStartKeyFrames
 number of keyframes arrived while starting the coded (needed for amlogic h264 decoder in order to drop some frames in ReceiveFrame() before sending them to the renderer)
 
int m_lastCodedWidth
 save coded width while closing for a directly reopen
 
int m_lastCodedHeight
 save coded height while closing for a directly reopen
 
int m_skipKeyFramesNum = 0
 number of Keyframes (= I-Frames in VDR) to be skipped at stream start (hardware specific quirk)
 
bool m_isHardwareDecoder = false
 true, if this is a hardware decoder
 

Detailed Description

Video Decoder.

FFmpeg based Video Decoder Frontend

Handles:

  • Video packet decoding using FFmpeg

Definition at line 37 of file codec_video.h.

Constructor & Destructor Documentation

◆ cVideoDecoder()

cVideoDecoder::cVideoDecoder ( const char identifier)

Create a new video decoder.

Parameters
identifierstring to identify decoder for video or pip stream (used within logging only)

Definition at line 144 of file codec_video.cpp.

References cSoftHdLogger::LogFFmpegCallback().

Member Function Documentation

◆ Close()

void cVideoDecoder::Close ( void  )

◆ FlushBuffers()

void cVideoDecoder::FlushBuffers ( void  )

Flush the video decoder buffers.

Also reset packet sent/ frame received counter

Definition at line 547 of file codec_video.cpp.

References L_CODEC, LOGDEBUG2, m_cntFramesReceived, m_cntPacketsSent, m_identifier, m_mutex, and m_pVideoCtx.

Referenced by cVideoStream::FlushDecoder().

◆ GetContext()

AVCodecContext * cVideoDecoder::GetContext ( void  )
inline

Definition at line 46 of file codec_video.h.

References m_pVideoCtx.

Referenced by cVideoStream::GetVideoSize(), and cVideoStream::RenderFrame().

◆ GetExtraData()

int cVideoDecoder::GetExtraData ( const AVPacket avpkt)
private

Get extradata from avpkt.

Parameters
avpktvideo packet
Return values
0extradata set
-1something went wrong

Definition at line 321 of file codec_video.cpp.

References LOGERROR, m_identifier, and m_pVideoCtx.

Referenced by SendPacket().

◆ GetFramesReceived()

int cVideoDecoder::GetFramesReceived ( void  )
inline

Definition at line 50 of file codec_video.h.

References m_cntFramesReceived.

Referenced by cVideoStream::DecodeInput().

◆ GetPacketsSent()

int cVideoDecoder::GetPacketsSent ( void  )
inline

Definition at line 49 of file codec_video.h.

References m_cntPacketsSent.

Referenced by cVideoStream::DecodeInput().

◆ IsHardwareDecoder()

bool cVideoDecoder::IsHardwareDecoder ( void  )
inline

◆ IsKeyFrame()

bool cVideoDecoder::IsKeyFrame ( AVFrame frame)
private

Check, if this is a key frame.

Parameters
frameAVFrame
Returns
true, if this frame is a key frame

Definition at line 566 of file codec_video.cpp.

Referenced by ReceiveFrame().

◆ Name()

const char * cVideoDecoder::Name ( void  )
inline

Definition at line 48 of file codec_video.h.

References m_pCodecString.

Referenced by cVideoStream::OpenDecoder().

◆ Open()

int cVideoDecoder::Open ( enum AVCodecID  codecId,
AVCodecParameters par,
AVRational  timebase,
bool  forceSoftwareDecoder,
int  width,
int  height 
)

Open the video decoder.

Parameters
codecIdvideo codec id
parcodec parameters
timebasetimebase
forceSoftwareDecoderforce software decoding
widthforce width (only for H264 and if par is not set)
heightforce height (only for H264 and if par is not set)
Return values
0decoder successfully opend
-1opening the decoder failed

Definition at line 167 of file codec_video.cpp.

References av_err2str, FindHWConfig(), FindHWDecoder(), FindSWDecoder(), GetFormat(), L_CODEC, LOGDEBUG2, LOGERROR, LOGINFO, m_cntFramesReceived, m_cntPacketsSent, m_cntStartKeyFrames, m_identifier, m_isHardwareDecoder, m_mutex, m_pCodecString, m_pVideoCtx, and Open().

Referenced by Open(), cVideoStream::OpenDecoder(), and ReopenCodec().

◆ ReceiveFrame()

int cVideoDecoder::ReceiveFrame ( AVFrame **  frame)

Receive a decoded a video frame.

Parameters
[out]framedecoded AVFrame
instanceinstance name for logging
Return values
0received frame
AVERROR(EAGAIN)get no frame, send avpkt again
AVERROR_EOFEOF, needs flushing
AVERROR(EINVAL)get no frame, something went wrong
retreturn other ffmpeg error

Definition at line 457 of file codec_video.cpp.

References av_err2str, isInterlacedFrame(), IsKeyFrame(), L_CODEC, L_PACKET, LOGDEBUG2, LOGFATAL, m_cntFramesReceived, m_cntPacketsSent, m_cntStartKeyFrames, m_identifier, m_mutex, m_pVideoCtx, m_skipKeyFramesNum, and Timestamp2String().

Referenced by cVideoStream::DecodeInput().

◆ ReopenCodec()

int cVideoDecoder::ReopenCodec ( enum AVCodecID  codecId,
AVCodecParameters par,
AVRational  timebase,
int  forceSoftwareDecoding 
)

Reopen the video decoder.

Parameters
codecIdvideo codec id
parcodec parameters
timebasetimebase
forceSoftwareDecodingforce software decoding
Return values
0success
-1reopen decoder failed
Todo:
This is just a temporary implementation RPi's ffmpeg decoder is broken. In order to get the same result if we want to flush the decoder, we need to close and reopen it. This function is only needed, if some decoder can't flush correctly. Once this is fixed in ffmpeg, we can drop this function. remove, once ffmpeg is fixed

Definition at line 529 of file codec_video.cpp.

References Close(), L_CODEC, LOGDEBUG2, m_cntFramesReceived, m_cntPacketsSent, m_cntStartKeyFrames, m_identifier, m_lastCodedHeight, m_lastCodedWidth, m_pVideoCtx, and Open().

Referenced by cVideoStream::DecodeInput(), and cVideoStream::FlushDecoder().

◆ SendPacket()

int cVideoDecoder::SendPacket ( const AVPacket avpkt)

Send a video packet to be decoded.

Parameters
avpktvideo packet
Return values
0packet was sent
AVERROR(EAGAIN)packet was not accepted, first receive frame and send packet again
AVERROR(EINVAL)invalid input or missing m_pVideoCtx
retother ffmpeg error

Definition at line 407 of file codec_video.cpp.

References av_err2str, GetExtraData(), L_CODEC, L_PACKET, LOGDEBUG2, m_cntPacketsSent, m_identifier, m_mutex, m_pVideoCtx, and Timestamp2String().

Referenced by cVideoStream::CheckForcingFrameDecode(), and cVideoStream::DecodeInput().

◆ SetSkipKeyFramesNum()

void cVideoDecoder::SetSkipKeyFramesNum ( int  num)
inline

Definition at line 51 of file codec_video.h.

References m_skipKeyFramesNum.

Referenced by cVideoStream::StartDecoder().

Member Data Documentation

◆ m_cntFramesReceived

int cVideoDecoder::m_cntFramesReceived
private

number of decoded frames received from decoder

Definition at line 59 of file codec_video.h.

Referenced by Close(), FlushBuffers(), GetFramesReceived(), Open(), ReceiveFrame(), and ReopenCodec().

◆ m_cntPacketsSent

int cVideoDecoder::m_cntPacketsSent
private

number of packets sent to decoder

Definition at line 58 of file codec_video.h.

Referenced by Close(), FlushBuffers(), GetPacketsSent(), Open(), ReceiveFrame(), ReopenCodec(), and SendPacket().

◆ m_cntStartKeyFrames

int cVideoDecoder::m_cntStartKeyFrames
private

number of keyframes arrived while starting the coded (needed for amlogic h264 decoder in order to drop some frames in ReceiveFrame() before sending them to the renderer)

Definition at line 60 of file codec_video.h.

Referenced by Open(), ReceiveFrame(), and ReopenCodec().

◆ m_identifier

const char* cVideoDecoder::m_identifier
private

identifier for logging

Definition at line 55 of file codec_video.h.

Referenced by Close(), FlushBuffers(), GetExtraData(), Open(), ReceiveFrame(), ReopenCodec(), and SendPacket().

◆ m_isHardwareDecoder

bool cVideoDecoder::m_isHardwareDecoder = false
private

true, if this is a hardware decoder

Definition at line 66 of file codec_video.h.

Referenced by IsHardwareDecoder(), and Open().

◆ m_lastCodedHeight

int cVideoDecoder::m_lastCodedHeight
private

save coded height while closing for a directly reopen

Definition at line 64 of file codec_video.h.

Referenced by Close(), and ReopenCodec().

◆ m_lastCodedWidth

int cVideoDecoder::m_lastCodedWidth
private

save coded width while closing for a directly reopen

Definition at line 63 of file codec_video.h.

Referenced by Close(), and ReopenCodec().

◆ m_mutex

std::mutex cVideoDecoder::m_mutex
private

mutex to lock codec context

Definition at line 57 of file codec_video.h.

Referenced by Close(), FlushBuffers(), Open(), ReceiveFrame(), and SendPacket().

◆ m_pCodecString

const char* cVideoDecoder::m_pCodecString = "unknown"
private

codec (long) name string

Definition at line 56 of file codec_video.h.

Referenced by Name(), and Open().

◆ m_pVideoCtx

AVCodecContext* cVideoDecoder::m_pVideoCtx = nullptr
private

video codec context

Definition at line 54 of file codec_video.h.

Referenced by Close(), FlushBuffers(), GetContext(), GetExtraData(), Open(), ReceiveFrame(), ReopenCodec(), and SendPacket().

◆ m_skipKeyFramesNum

int cVideoDecoder::m_skipKeyFramesNum = 0
private

number of Keyframes (= I-Frames in VDR) to be skipped at stream start (hardware specific quirk)

Definition at line 65 of file codec_video.h.

Referenced by ReceiveFrame(), and SetSkipKeyFramesNum().


The documentation for this class was generated from the following files: