vdr-plugin-softhddevice-drm-gles 1.6.2
Video Renderer

Video Renderer. More...

Classes

struct  sRect
 
class  cBufferStrategy
 DRM Buffer Getting-Strategy. More...
 
class  cBufferStrategyUseOnce
 DRM Buffer: Get a Buffer to Use Once. More...
 
class  cBufferStrategyReuseHardware
 DRM Buffer: Get a Hardware Buffer to Reuse. More...
 
class  cBufferStrategyReuseSoftware
 DRM Buffer: Get a Software Buffer to Reuse. More...
 
class  cDecodingStrategy
 Strategy to Prepare DRM Buffer for Decoding. More...
 
class  cDecodingStrategySoftware
 Prepare DRM Buffer for Software Decoding. More...
 
class  cDecodingStrategyHardware
 Prepare DRM Buffer for Hardware Decoding. More...
 
class  cVideoRender
 Video Renderer. More...
 

Macros

#define MIN(a, b)   ((a) < (b) ? (a) : (b))
 
#define AV_SYNC_THRESHOLD_AUDIO_BEHIND_VIDEO_MS   35
 threshold in ms, when to duplicate video frames to keep audio and video in sync
 
#define AV_SYNC_THRESHOLD_AUDIO_AHEAD_VIDEO_MS   5
 threshold in ms, when to drop video frames to keep audio and video in sync
 

Enumerations

enum  drmColorSpace { COLORSPACE_BT709_YCC = 2 , COLORSPACE_BT2020_RGB = 9 }
 
enum  drmColorEncoding { COLORENCODING_BT709 = 1 , COLORENCODING_BT2020 = 2 }
 
enum  drmColorRange { COLORRANGE_LIMITED = 0 , COLORRANGE_FULL = 1 }
 

Functions

static sRect ComputeFittedRect (AVFrame *frame, uint64_t dispX, uint64_t dispY, uint64_t dispWidth, uint64_t dispHeight)
 Fits the video frame into a given area.
 
static void ReleaseFrame (__attribute__((unused)) void *opaque, uint8_t *data)
 Callback free primedata if av_buffer is unreferenced.
 
 cVideoRender::cVideoRender (cSoftHdDevice *)
 Create the video renderer.
 
 cVideoRender::~cVideoRender (void)
 Destroy the video renderer.
 
void cVideoRender::ClearDecoderToDisplayQueue (void)
 Clear (empty) the decoder to display queue.
 
void cVideoRender::ClearPipDecoderToDisplayQueue (void)
 Clear (empty) the decoder to display queue.
 
void cVideoRender::SetHdrBlob (struct hdr_output_metadata)
 Create an hdr blob and set it for the connector.
 
void cVideoRender::SetColorSpace (drmColorRange)
 Set kms color space, color encoding and color range.
 
void cVideoRender::RestoreColorSpace ()
 Restore color space, color encoding and color range to BT709 and the original color range.
 
int cVideoRender::SetVideoBuffer (cDrmBuffer *)
 Modesetting for video.
 
int cVideoRender::SetOsdBuffer (drmModeAtomicReqPtr)
 Modesetting for osd.
 
int cVideoRender::SetPipBuffer (cDrmBuffer *)
 Modesetting for pip.
 
int cVideoRender::CommitBuffer (cDrmBuffer *, cDrmBuffer *)
 Commit the frame to the hardware.
 
void cVideoRender::LogDroppedDuped (int64_t, int64_t, int)
 Log A/V sync debug message.
 
int cVideoRender::GetFrameFlags (AVFrame *)
 Get frame flags.
 
void cVideoRender::SetFrameFlags (AVFrame *, int)
 Set frame flags.
 
bool cVideoRender::PageFlip (cDrmBuffer *, cDrmBuffer *)
 Do the pageflip.
 
virtual void cVideoRender::Action (void)
 Thread loop, which tries to display frames and processes events.
 
void cVideoRender::Stop (void)
 Stop the thread.
 
bool cVideoRender::DisplayFrame ()
 Display the frame (video and/or osd)
 
void cVideoRender::DisplayBlackFrame (void)
 
int64_t cVideoRender::PtsToMs (int64_t)
 
int cVideoRender::DrmHandleEvent (void)
 Wrapper for drmHandleEvent()
 
bool cVideoRender::CanHandleHdr (void)
 
void cVideoRender::OsdClear (void)
 Clear the OSD (draw an empty/ transparent OSD)
 
void cVideoRender::OsdDrawARGB (int, int, int, int, int, const uint8_t *, int, int)
 Draw an OSD ARGB image.
 
bool cVideoRender::IsOutputBufferFull (void)
 Check, if the main render output buffer is full.
 
void cVideoRender::PushMainFrame (AVFrame *)
 Push a main frame into the render ringbuffer.
 
void cVideoRender::PushPipFrame (AVFrame *)
 Push a PiP frame into the render ringbuffer.
 
void cVideoRender::PushFrame (AVFrame *, bool, std::atomic< cBufferStrategy * > &, std::atomic< cDecodingStrategy * > &, cQueue< cDrmBuffer > *, cDrmBufferPool *)
 Push the frame into the render ringbuffer.
 
int64_t cVideoRender::GetOutputPtsMs (void)
 Get the output PTS in milliseconds.
 
void cVideoRender::ResetFrameCounter (void)
 Send start condition to video thread.
 
void cVideoRender::Reset ()
 Reset the renderer.
 
void cVideoRender::SetTrickSpeed (double, bool, bool)
 Set the trickspeed parameters.
 
int cVideoRender::GetFramePresentationCount (int64_t)
 Get the number of times the current frame shall be presented in trickspeed mode.
 
int cVideoRender::TriggerGrab (void)
 Trigger a screen grab.
 
void cVideoRender::CreateGrabBuffers (bool)
 Copy current video, osd and pip buffers to dedicated grabbing buffers.
 
void cVideoRender::ClearGrabBuffers (void)
 Clear the grab drm buffers.
 
void cVideoRender::GetStats (int *, int *, int *)
 Get some rendering statistics.
 
void cVideoRender::SetScreenSize (int, int, double)
 Wrapper to set the screen size in the device.
 
void cVideoRender::Init (void)
 Initialize the renderer.
 
void cVideoRender::Exit (void)
 Exit and cleanup the renderer.
 
void cVideoRender::SetVideoOutputPosition (const cRect &)
 Set size and position of the video on the screen.
 
void cVideoRender::ProcessEvents (void)
 Process queued events and forward to event receiver.
 
void cVideoRender::SetPipSize (bool)
 Set the size and position of the pip window.
 
cDrmBuffercBufferStrategyUseOnce::GetBuffer (cDrmBufferPool *, AVDRMFrameDescriptor *) override
 
cDrmBuffercBufferStrategyReuseHardware::GetBuffer (cDrmBufferPool *, AVDRMFrameDescriptor *) override
 
cDrmBuffercBufferStrategyReuseSoftware::GetBuffer (cDrmBufferPool *, AVDRMFrameDescriptor *) override
 
AVFramecDecodingStrategySoftware::PrepareDrmBuffer (cDrmBuffer *, int, AVFrame *) override
 
AVFramecDecodingStrategyHardware::PrepareDrmBuffer (cDrmBuffer *, int, AVFrame *) override
 

Detailed Description

Video Renderer.

Macro Definition Documentation

◆ AV_SYNC_THRESHOLD_AUDIO_AHEAD_VIDEO_MS

#define AV_SYNC_THRESHOLD_AUDIO_AHEAD_VIDEO_MS   5

threshold in ms, when to drop video frames to keep audio and video in sync

Definition at line 60 of file videorender.h.

◆ AV_SYNC_THRESHOLD_AUDIO_BEHIND_VIDEO_MS

#define AV_SYNC_THRESHOLD_AUDIO_BEHIND_VIDEO_MS   35

threshold in ms, when to duplicate video frames to keep audio and video in sync

Definition at line 59 of file videorender.h.

◆ MIN

#define MIN (   a,
 
)    ((a) < (b) ? (a) : (b))

Definition at line 873 of file videorender.cpp.

Enumeration Type Documentation

◆ drmColorEncoding

Enumerator
COLORENCODING_BT709 
COLORENCODING_BT2020 

Definition at line 67 of file videorender.h.

◆ drmColorRange

Enumerator
COLORRANGE_LIMITED 
COLORRANGE_FULL 

Definition at line 72 of file videorender.h.

◆ drmColorSpace

Enumerator
COLORSPACE_BT709_YCC 
COLORSPACE_BT2020_RGB 

Definition at line 62 of file videorender.h.

Function Documentation

◆ Action()

void cVideoRender::Action ( void  )
protectedvirtual

Thread loop, which tries to display frames and processes events.

Definition at line 626 of file videorender.cpp.

References cVideoRender::DisplayFrame(), LOGDEBUG, cVideoRender::m_mutex, and cVideoRender::ProcessEvents().

◆ CanHandleHdr()

bool cVideoRender::CanHandleHdr ( void  )

Definition at line 821 of file videorender.cpp.

References cDrmDevice::CanHandleHdr(), and cVideoRender::m_pDrmDevice.

Referenced by cHdrMetadata::Build().

◆ ClearDecoderToDisplayQueue()

◆ ClearGrabBuffers()

void cVideoRender::ClearGrabBuffers ( void  )

◆ ClearPipDecoderToDisplayQueue()

void cVideoRender::ClearPipDecoderToDisplayQueue ( void  )

◆ CommitBuffer()

int cVideoRender::CommitBuffer ( cDrmBuffer buf,
cDrmBuffer pip 
)
private

◆ ComputeFittedRect()

static sRect ComputeFittedRect ( AVFrame frame,
uint64_t  dispX,
uint64_t  dispY,
uint64_t  dispWidth,
uint64_t  dispHeight 
)
static

Fits the video frame into a given area.

Parameters
frameAVFrame with frame dimensions and aspect ratio information
dispXx offset of video area
dispYy offset of video area
dispWidthwidth of video area
dispHeightheight of video area
Returns
the new computed video area or the given area if no frame was given

Definition at line 138 of file videorender.cpp.

Referenced by cVideoRender::SetPipBuffer(), and cVideoRender::SetVideoBuffer().

◆ CreateGrabBuffers()

void cVideoRender::CreateGrabBuffers ( bool  grabPip)
private

◆ cVideoRender()

◆ DisplayBlackFrame()

◆ DisplayFrame()

bool cVideoRender::DisplayFrame ( )

Display the frame (video and/or osd)

Returns
true if it shall be scheduled immediately again

Definition at line 663 of file videorender.cpp.

References AV_NOPTS_VALUE, AV_SYNC_THRESHOLD_AUDIO_AHEAD_VIDEO_MS, AV_SYNC_THRESHOLD_AUDIO_BEHIND_VIDEO_MS, cVideoRender::CreateGrabBuffers(), cSoftHdAudio::DropSamplesOlderThanPtsMs(), cDrmBuffer::frame, cVideoStream::GetAvPacketsFilled(), cSoftHdAudio::GetAvResyncBorderMs(), cSoftHdDevice::GetChannelSwitchFirstPacketTime(), cSoftHdDevice::GetChannelSwitchStartTime(), cVideoRender::GetFramePresentationCount(), cSoftHdAudio::GetHardwareOutputPtsMs(), cSoftHdDevice::GetVideoAudioDelayMs(), cSoftHdDevice::IsBufferingThresholdReached(), cDrmBuffer::IsDirty(), cQueue< T >::IsEmpty(), cSoftHdAudio::IsPaused(), cVideoRender::IsStillpicture(), cVideoRender::IsTrickSpeed(), cSoftHdDevice::IsVideoOnlyPlayback(), L_AV_SYNC, LOGDEBUG, LOGDEBUG2, cVideoRender::LogDroppedDuped(), cVideoRender::m_displayOneFrameThenPause, cVideoRender::m_drmBufferQueue, cVideoRender::m_eventQueue, cVideoRender::m_framePresentationCounter, cVideoRender::m_lastFrameWasDropped, cVideoRender::m_pAudio, cVideoRender::m_pBufOsd, cVideoRender::m_pCurrentlyDisplayed, cVideoRender::m_pCurrentlyPipDisplayed, cVideoRender::m_pDevice, cVideoRender::m_pipDrmBufferQueue, cVideoRender::m_resumeAudioScheduled, cVideoRender::m_schedulePlaybackStartAtPtsMs, cVideoRender::m_scheduleResyncAtPtsMs, cVideoRender::m_startCounter, cVideoRender::m_timebase, cVideoRender::m_videoIsScaled, cVideoRender::m_videoPlaybackPaused, cVideoRender::m_videoPlaybackPauseScheduledAt, cVideoRender::PageFlip(), cQueue< T >::Pop(), cDrmBuffer::PresentationFinished(), cVideoRender::PtsToMs(), cSoftHdAudio::SetPaused(), Timestamp2String(), VIDEO, and cSoftHdDevice::VideoStream().

Referenced by cVideoRender::Action().

◆ DrmHandleEvent()

int cVideoRender::DrmHandleEvent ( void  )

Wrapper for drmHandleEvent()

Definition at line 816 of file videorender.cpp.

References cDrmDevice::HandleEvent(), and cVideoRender::m_pDrmDevice.

◆ Exit()

◆ GetBuffer() [1/3]

cDrmBuffer * cBufferStrategyUseOnce::GetBuffer ( cDrmBufferPool pool,
AVDRMFrameDescriptor  
)
overridevirtual

Implements cBufferStrategy.

Definition at line 1403 of file videorender.cpp.

◆ GetBuffer() [2/3]

cDrmBuffer * cBufferStrategyReuseHardware::GetBuffer ( cDrmBufferPool pool,
AVDRMFrameDescriptor primedata 
)
overridevirtual

Implements cBufferStrategy.

Definition at line 1416 of file videorender.cpp.

◆ GetBuffer() [3/3]

cDrmBuffer * cBufferStrategyReuseSoftware::GetBuffer ( cDrmBufferPool pool,
AVDRMFrameDescriptor  
)
overridevirtual

Implements cBufferStrategy.

Definition at line 1426 of file videorender.cpp.

◆ GetFrameFlags()

int cVideoRender::GetFrameFlags ( AVFrame frame)
private

Get frame flags.

Parameters
frameAVFrame
Returns
FRAME_FLAG_TRICKSPEED or FRAME_FLAG_STILLPICTURE

Definition at line 557 of file videorender.cpp.

◆ GetFramePresentationCount()

int cVideoRender::GetFramePresentationCount ( int64_t  interFrameGapMs)
private

Get the number of times the current frame shall be presented in trickspeed mode.

This is calculated based on the inter-frame gap (distance between each I-frame VDR sends us during trickspeed), the refresh rate of the output device, and the trickspeed speed.

Parameters
interFrameGapMsinter-frame gap in ms
Return values
numberof times the current frame shall be presented

Definition at line 1089 of file videorender.cpp.

References cVideoRender::IsTrickSpeed(), cVideoRender::m_refreshRateHz, and cVideoRender::m_trickspeedFactor.

Referenced by cVideoRender::DisplayFrame().

◆ GetOutputPtsMs()

int64_t cVideoRender::GetOutputPtsMs ( void  )

Get the output PTS in milliseconds.

Returns the presentation timestamp of the next frame to be displayed.

Returns
PTS in milliseconds

Definition at line 1032 of file videorender.cpp.

References AV_NOPTS_VALUE, cVideoRender::GetVideoClock(), cVideoRender::m_timebase, and cVideoRender::m_timebaseMutex.

Referenced by cSoftHdDevice::GetFirstAudioPtsMsToPlay(), cSoftHdDevice::GetFirstVideoPtsMsToPlay(), cSoftHdDevice::IsBufferingThresholdReached(), and cSoftHdDevice::OnEventReceived().

◆ GetStats()

void cVideoRender::GetStats ( int duped,
int dropped,
int counter 
)

Get some rendering statistics.

Parameters
[out]dupednumber of duplicated frames
[out]droppednumber of dropped frames
[out]counternumber of decoded frames

Definition at line 1182 of file videorender.cpp.

References cVideoRender::m_framesDropped, cVideoRender::m_framesDuped, and cVideoRender::m_startCounter.

Referenced by cSoftHdDevice::GetStats().

◆ Init()

◆ IsOutputBufferFull()

bool cVideoRender::IsOutputBufferFull ( void  )

Check, if the main render output buffer is full.

Return values
truerender output buffer is full

Definition at line 954 of file videorender.cpp.

References cQueue< T >::IsFull(), and cVideoRender::m_drmBufferQueue.

Referenced by cSoftHdDevice::IsBufferingThresholdReached().

◆ LogDroppedDuped()

void cVideoRender::LogDroppedDuped ( int64_t  audioPtsMs,
int64_t  videoPtsMs,
int  audioBehindVideoByMs 
)
private

◆ OsdClear()

◆ OsdDrawARGB()

void cVideoRender::OsdDrawARGB ( int  xi,
int  yi,
int  width,
int  height,
int  pitch,
const uint8_t argb,
int  x,
int  y 
)

Draw an OSD ARGB image.

Parameters
xix-coordinate in argb image
yiy-coordinate in argb image
heightheight in pixel in argb image
widthwidth in pixel in argb image
pitchpitch of argb image
argb32bit ARGB image data
xx-coordinate on screen of argb image
yy-coordinate on screen of argb image

Definition at line 887 of file videorender.cpp.

References EGL_CHECK, cDrmDevice::EglDisplay(), cDrmDevice::EglSurface(), cDrmDevice::GbmSurface(), cDrmDevice::GetBufFromBo(), L_OPENGL, L_OSD, LOGDEBUG2, LOGERROR, cVideoRender::m_bo, cVideoRender::m_disableOglOsd, cVideoRender::m_osdShown, cVideoRender::m_pBufOsd, cVideoRender::m_pDrmDevice, cVideoRender::m_pNextBo, cVideoRender::m_pOldBo, cDrmBuffer::MarkDirty(), MIN, cDrmBuffer::Pitch(), and cDrmBuffer::Plane().

Referenced by cSoftHdDevice::OsdDrawARGB().

◆ PageFlip()

bool cVideoRender::PageFlip ( cDrmBuffer buf,
cDrmBuffer pipBuf 
)
private

Do the pageflip.

Parameters
bufdrm buffer
pipBufdrm pip buffer
Returns
true if page flip was done

Definition at line 593 of file videorender.cpp.

References AV_NOPTS_VALUE, cVideoRender::CommitBuffer(), cDrmDevice::HandleEvent(), L_PACKET, LOGDEBUG2, LOGERROR, cVideoRender::m_pDrmDevice, cVideoRender::SetVideoClock(), and Timestamp2String().

Referenced by cVideoRender::DisplayBlackFrame(), and cVideoRender::DisplayFrame().

◆ PrepareDrmBuffer() [1/2]

AVFrame * cDecodingStrategySoftware::PrepareDrmBuffer ( cDrmBuffer buf,
int  drmDeviceFd,
AVFrame inframe 
)
overridevirtual

Implements cDecodingStrategy.

Definition at line 1439 of file videorender.cpp.

References LOGFATAL, and ReleaseFrame().

◆ PrepareDrmBuffer() [2/2]

AVFrame * cDecodingStrategyHardware::PrepareDrmBuffer ( cDrmBuffer buf,
int  drmDeviceFd,
AVFrame frame 
)
overridevirtual

Implements cDecodingStrategy.

Definition at line 1478 of file videorender.cpp.

◆ ProcessEvents()

void cVideoRender::ProcessEvents ( void  )

Process queued events and forward to event receiver.

Definition at line 1374 of file videorender.cpp.

References cVideoRender::m_eventQueue, cVideoRender::m_pEventReceiver, and IEventReceiver::OnEventReceived().

Referenced by cVideoRender::Action().

◆ PtsToMs()

int64_t cVideoRender::PtsToMs ( int64_t  pts)
private

Definition at line 806 of file videorender.cpp.

References cVideoRender::m_timebase, and cVideoRender::m_timebaseMutex.

Referenced by cVideoRender::DisplayFrame().

◆ PushFrame()

void cVideoRender::PushFrame ( AVFrame frame,
bool  trickspeed,
std::atomic< cBufferStrategy * > &  bufferReuseStrategy,
std::atomic< cDecodingStrategy * > &  decodingStrategy,
cQueue< cDrmBuffer > *  drmBufferQueue,
cDrmBufferPool drmBufferPool 
)
private

◆ PushMainFrame()

void cVideoRender::PushMainFrame ( AVFrame frame)

◆ PushPipFrame()

void cVideoRender::PushPipFrame ( AVFrame frame)

◆ ReleaseFrame()

static void ReleaseFrame ( __attribute__((unused)) void opaque,
uint8_t data 
)
static

Callback free primedata if av_buffer is unreferenced.

Definition at line 942 of file videorender.cpp.

Referenced by cDecodingStrategySoftware::PrepareDrmBuffer().

◆ Reset()

◆ ResetFrameCounter()

void cVideoRender::ResetFrameCounter ( void  )

Send start condition to video thread.

Definition at line 1045 of file videorender.cpp.

References cVideoRender::IsTrickSpeed(), LOGDEBUG, and cVideoRender::m_startCounter.

Referenced by cSoftHdDevice::OnEventReceived(), and cSoftHdDevice::OnLeavingState().

◆ RestoreColorSpace()

◆ SetColorSpace()

◆ SetFrameFlags()

void cVideoRender::SetFrameFlags ( AVFrame frame,
int  flags 
)
private

Set frame flags.

Parameters
frameAVFrame
flagsFRAME_FLAG_TRICKSPEED and/or FRAME_FLAG_STILLPICTURE

Definition at line 572 of file videorender.cpp.

References LOGFATAL.

◆ SetHdrBlob()

void cVideoRender::SetHdrBlob ( struct hdr_output_metadata  hdrData)
private

◆ SetOsdBuffer()

◆ SetPipBuffer()

int cVideoRender::SetPipBuffer ( cDrmBuffer buf)
private

◆ SetPipSize()

◆ SetScreenSize()

void cVideoRender::SetScreenSize ( int  width,
int  height,
double  refreshRateHz 
)

Wrapper to set the screen size in the device.

Parameters
widthscreen width
heightscreen height
refreshRateHzscreen refresh rate in Hz

Definition at line 1200 of file videorender.cpp.

References cVideoRender::m_pDevice, cVideoRender::m_refreshRateHz, and cSoftHdDevice::SetScreenSize().

Referenced by cDrmDevice::Init().

◆ SetTrickSpeed()

void cVideoRender::SetTrickSpeed ( double  speed,
bool  active,
bool  forward 
)

Set the trickspeed parameters.

Parameters
speedtrick speed value from VDR (0 = normal)
activetrue if trickspeed is active
forwardtrue if forward trick speed, false if backward

Definition at line 1073 of file videorender.cpp.

References L_TRICK, LOGDEBUG2, cVideoRender::m_forwardTrickspeed, cVideoRender::m_framePresentationCounter, cVideoRender::m_trickspeed, and cVideoRender::m_trickspeedFactor.

Referenced by cSoftHdDevice::OnEventReceived(), and cSoftHdDevice::OnLeavingState().

◆ SetVideoBuffer()

int cVideoRender::SetVideoBuffer ( cDrmBuffer buf)
private

◆ SetVideoOutputPosition()

void cVideoRender::SetVideoOutputPosition ( const cRect rect)

Set size and position of the video on the screen.

Parameters
recta cRect, where the video should be rendered in

Definition at line 1359 of file videorender.cpp.

References LOGDEBUG, cVideoRender::m_videoIsScaled, and cVideoRender::m_videoRect.

Referenced by cSoftHdDevice::ScaleVideo().

◆ Stop()

void cVideoRender::Stop ( void  )

Stop the thread.

Definition at line 649 of file videorender.cpp.

References LOGDEBUG.

Referenced by cVideoRender::Exit(), and cVideoRender::~cVideoRender().

◆ TriggerGrab()

int cVideoRender::TriggerGrab ( void  )

Trigger a screen grab.

Return values
0on success, grab was triggered
1on timeout, grab was not triggered

Definition at line 1112 of file videorender.cpp.

References LOGWARNING, cVideoRender::m_grabCond, and cVideoRender::m_startgrab.

Referenced by cSoftHdGrab::Start().

◆ ~cVideoRender()

cVideoRender::~cVideoRender ( void  )

Destroy the video renderer.

Definition at line 88 of file videorender.cpp.

References L_DRM, LOGDEBUG2, cVideoRender::m_pDrmDevice, and cVideoRender::Stop().