MythTV  master
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
VideoBuffers Class Reference

#include <videobuffers.h>

Collaboration diagram for VideoBuffers:
Collaboration graph
[legend]

Public Member Functions

 VideoBuffers ()=default
 
 ~VideoBuffers ()=default
 
void Init (uint NumDecode, uint NeedFree, uint NeedprebufferNormal, uint NeedPrebufferSmall)
 Creates buffers and sets various buffer management parameters. More...
 
bool CreateBuffers (VideoFrameType Type, const VideoFrameTypes *RenderFormats, QSize Size, uint NeedFree, uint NeedprebufferNormal, uint NeedPrebufferSmall, int MaxReferenceFrames=16)
 
bool CreateBuffers (VideoFrameType Type, int Width, int Height, const VideoFrameTypes *RenderFormats)
 
void SetDeinterlacing (MythDeintType Single, MythDeintType Double, MythCodecID CodecID)
 
void Reset (void)
 
void DiscardFrames (bool NextFrameIsKeyFrame)
 
void ClearAfterSeek (void)
 Clear used frames after seeking. More...
 
void SetPrebuffering (bool Normal)
 
MythVideoFrameGetNextFreeFrame (BufferType EnqueueTo=kVideoBuffer_limbo)
 Gets a frame from available buffers list. More...
 
void ReleaseFrame (MythVideoFrame *Frame)
 
void DeLimboFrame (MythVideoFrame *Frame)
 
void StartDisplayingFrame (void)
 
void DoneDisplayingFrame (MythVideoFrame *Frame)
 
void DiscardFrame (MythVideoFrame *Frame)
 
void DiscardPauseFrames (void)
 
bool DiscardAndRecreate (MythCodecID CodecID, QSize VideoDim, int References)
 Discard all buffers and recreate. More...
 
MythVideoFrameAt (uint FrameNum)
 
MythVideoFrameDequeue (BufferType Type)
 
MythVideoFrameHead (BufferType Type)
 
MythVideoFrameTail (BufferType Type)
 
void Enqueue (BufferType Type, MythVideoFrame *Frame)
 
void SafeEnqueue (BufferType Type, MythVideoFrame *Frame)
 
void Remove (BufferType Type, MythVideoFrame *Frame)
 
frame_queue_t::iterator BeginLock (BufferType Type)
 Lock the video buffers. More...
 
frame_queue_t::iterator End (BufferType Type)
 
void EndLock ()
 
uint Size (BufferType Type) const
 
bool Contains (BufferType Type, MythVideoFrame *Frame) const
 
MythVideoFrameGetLastDecodedFrame (void)
 
MythVideoFrameGetLastShownFrame (void)
 
uint ValidVideoFrames (void) const
 
uint FreeVideoFrames (void) const
 
bool EnoughFreeFrames (void) const
 
bool EnoughDecodedFrames (void) const
 
const MythVideoFrameAt (uint FrameNum) const
 
const MythVideoFrameGetLastDecodedFrame (void) const
 
const MythVideoFrameGetLastShownFrame (void) const
 
uint Size (void) const
 
QString GetStatus (uint Num=0) const
 

Static Public Member Functions

static uint GetNumBuffers (int PixelFormat, int MaxReferenceFrames=16, bool Decoder=false)
 
static bool ReinitBuffer (MythVideoFrame *Frame, VideoFrameType Type, MythCodecID CodecID, int Width, int Height)
 

Private Member Functions

frame_queue_tQueue (BufferType Type)
 
const frame_queue_tQueue (BufferType Type) const
 
MythVideoFrameGetNextFreeFrameInternal (BufferType EnqueueTo)
 

Static Private Member Functions

static void SetDeinterlacingFlags (MythVideoFrame &Frame, MythDeintType Single, MythDeintType Double, MythCodecID CodecID)
 Set the appropriate flags for single and double rate deinterlacing. More...
 

Private Attributes

frame_queue_t m_available
 
frame_queue_t m_used
 
frame_queue_t m_limbo
 
frame_queue_t m_pause
 
frame_queue_t m_displayed
 
frame_queue_t m_decode
 
frame_queue_t m_finished
 
vbuffer_map_t m_vbufferMap
 
frame_vector_t m_buffers
 
const VideoFrameTypesm_renderFormats { nullptr }
 
uint m_needFreeFrames { 0 }
 
uint m_needPrebufferFrames { 0 }
 
uint m_needPrebufferFramesNormal { 0 }
 
uint m_needPrebufferFramesSmall { 0 }
 
uint m_rpos { 0 }
 
uint m_vpos { 0 }
 
QRecursiveMutex m_globalLock
 

Detailed Description

This class creates tracks the state of the buffers used by various VideoOutput derived classes.

The states available for a buffer are: available, limbo, used, process, and displayed.

The two most important states are available and used. Used is implemented as a FIFO, and is used to buffer frames ready for display. A decoder may decode frames out of order but must add them to the used queue in order. The available buffers are buffers that are ready to be used by the decoder.

Generally a buffer leaves the available state via GetNextFreeFrame(bool,bool,BufferType) and enters the limbo state. It then leaves the limbo state via ReleaseFrame(VideoFrame*) and enters the used state. Then it leaves the used state via DoneDisplayingFrame() and enters the available state.

At any point, DiscardFrame(VideoFrame*) can be called to remove the frame from the current state and add it to the available list.

However, there are two additional states available, these are currently used by VideoOutputXv for XvMC support. These are the process and displayed state. The process state simply indicates that the frame has been picked up in the VideoOutput::ProcessFrame() call, but VideoOutput::Show() has not yet used the frame. This is needed because a frame other than a used frame is being held by VideoOutput and we don't want to lose it if the stream is reset. The displayed state indicates that DoneDisplayingFrame() has been called for the frame, but it cannot yet be added to available because it is still being displayed. VideoOutputXv calls DiscardFrame(VideoFrame*) on the frames no longer being displayed at the end of the next DoneDisplayingFrame(), finally adding them to available.

The only method that returns with a lock held on the VideoBuffers object itself, preventing anyone else from using the VideoBuffers class, inluding to unlocking frames, is the begin_lock(BufferType). This method is to be used with extreme caution, in particular one should not attempt to acquire any locks before end_lock() is called.

There are also frame inheritence tracking functions, these are used by VideoOutputXv to avoid throwing away displayed frames too early. See videoout_xv.cpp for their use.

released = used + finished + displayed + pause total = available + limbo + released released_and_in_use_by_decoder = decode

available - frames not in use by decoder or display limbo - frames in use by decoder but not released for display decode - frames in use by decoder and released for display used - frames released for display but not displayed or paused displayed - frames displayed but still used as a reference frame pause - frames used for pause finished - frames that are finished displaying but still in use by decoder

NOTE: All queues are mutually exclusive except "decode" which tracks frames that have been released but still in use by the decoder. If a frame has finished being processed/displayed but is still in use by the decoder (in the decode queue) then it is placed in the finished queue until the decoder is no longer using it (not in the decode queue).

See also
VideoOutput

Definition at line 38 of file videobuffers.h.

Constructor & Destructor Documentation

◆ VideoBuffers()

VideoBuffers::VideoBuffers ( )
default

◆ ~VideoBuffers()

VideoBuffers::~VideoBuffers ( )
default

Member Function Documentation

◆ GetNumBuffers()

uint VideoBuffers::GetNumBuffers ( int  PixelFormat,
int  MaxReferenceFrames = 16,
bool  Decoder = false 
)
static

◆ Init()

void VideoBuffers::Init ( uint  NumDecode,
uint  NeedFree,
uint  NeedPrebufferNormal,
uint  NeedPrebufferSmall 
)

Creates buffers and sets various buffer management parameters.

Parameters
NumDecodenumber of buffers to allocate for normal use
NeedFreemaximum number of buffers needed in display and pause
NeedPrebufferNormalnumber buffers you can put in used or limbo normally
NeedPrebufferSmallnumber of buffers you can put in used or limbo after SetPrebuffering(false) has been called.

Definition at line 176 of file videobuffers.cpp.

Referenced by CreateBuffers(), VideoOutputD3D::CreateBuffers(), MythVideoOutputGPU::CreateBuffers(), DiscardAndRecreate(), and MythVideoOutputNull::Init().

◆ CreateBuffers() [1/2]

bool VideoBuffers::CreateBuffers ( VideoFrameType  Type,
const VideoFrameTypes RenderFormats,
QSize  Size,
uint  NeedFree,
uint  NeedprebufferNormal,
uint  NeedPrebufferSmall,
int  MaxReferenceFrames = 16 
)

◆ CreateBuffers() [2/2]

bool VideoBuffers::CreateBuffers ( VideoFrameType  Type,
int  Width,
int  Height,
const VideoFrameTypes RenderFormats 
)

Definition at line 950 of file videobuffers.cpp.

◆ ReinitBuffer()

bool VideoBuffers::ReinitBuffer ( MythVideoFrame Frame,
VideoFrameType  Type,
MythCodecID  CodecID,
int  Width,
int  Height 
)
static

◆ SetDeinterlacing()

void VideoBuffers::SetDeinterlacing ( MythDeintType  Single,
MythDeintType  Double,
MythCodecID  CodecID 
)

◆ Reset()

void VideoBuffers::Reset ( void  )

Resets the class so that Init may be called again.

Definition at line 265 of file videobuffers.cpp.

Referenced by MythVideoOutputGPU::DestroyBuffers(), DiscardAndRecreate(), Init(), and VideoOutputD3D::TearDown().

◆ DiscardFrames()

void VideoBuffers::DiscardFrames ( bool  NextFrameIsKeyFrame)

Mark all used frames as ready to be reused, this is for seek.

Definition at line 809 of file videobuffers.cpp.

Referenced by MythVideoOutput::DiscardFrames(), GetNextFreeFrame(), and VideoOutputD3D::TearDown().

◆ ClearAfterSeek()

void VideoBuffers::ClearAfterSeek ( void  )

Clear used frames after seeking.

Note
The use of this function after seeking is a little dubious as the decoder is often not paused. In extreme cases every video buffer has already been requested by the decoder by the time this function is called. Should probably be repurposed as ClearBeforeSeek...

Definition at line 896 of file videobuffers.cpp.

Referenced by MythVideoOutput::ClearAfterSeek().

◆ SetPrebuffering()

void VideoBuffers::SetPrebuffering ( bool  normal)

Sets prebuffering state to normal, or small.

Definition at line 282 of file videobuffers.cpp.

Referenced by MythVideoOutput::SetPrebuffering().

◆ GetNextFreeFrame()

MythVideoFrame * VideoBuffers::GetNextFreeFrame ( BufferType  EnqueueTo = kVideoBuffer_limbo)

Gets a frame from available buffers list.

Parameters
EnqueueToPut new frame in some state other than limbo.

Definition at line 320 of file videobuffers.cpp.

Referenced by MythVideoOutput::GetNextFreeFrame().

◆ ReleaseFrame()

void VideoBuffers::ReleaseFrame ( MythVideoFrame Frame)

Frame is ready to be for filtering or OSD application. Removes frame from limbo and adds it to used queue.

Parameters
frameFrame to move to used.

Definition at line 361 of file videobuffers.cpp.

Referenced by MythVideoOutput::ReleaseFrame().

◆ DeLimboFrame()

void VideoBuffers::DeLimboFrame ( MythVideoFrame Frame)

If the frame is still in the limbo state it is added to the available queue.

Parameters
frameFrame to move to used.

Definition at line 378 of file videobuffers.cpp.

Referenced by MythVideoOutput::DeLimboFrame().

◆ StartDisplayingFrame()

void VideoBuffers::StartDisplayingFrame ( void  )

Sets rpos to index of videoframe at head of used queue.

Definition at line 408 of file videobuffers.cpp.

Referenced by MythVideoOutput::StartDisplayingFrame().

◆ DoneDisplayingFrame()

void VideoBuffers::DoneDisplayingFrame ( MythVideoFrame Frame)

Removes frame from used queue and adds it to the available list.

Definition at line 418 of file videobuffers.cpp.

Referenced by MythVideoOutputGPU::DoneDisplayingFrame(), and MythVideoOutput::DoneDisplayingFrame().

◆ DiscardFrame()

void VideoBuffers::DiscardFrame ( MythVideoFrame Frame)

Frame is ready to be reused by decoder. Add frame to available list, remove from any other list.

Definition at line 451 of file videobuffers.cpp.

Referenced by MythVideoOutput::DiscardFrame().

◆ DiscardPauseFrames()

void VideoBuffers::DiscardPauseFrames ( void  )

Definition at line 461 of file videobuffers.cpp.

Referenced by MythVideoOutputGPU::DiscardFrames().

◆ DiscardAndRecreate()

bool VideoBuffers::DiscardAndRecreate ( MythCodecID  CodecID,
QSize  VideoDim,
int  References 
)

Discard all buffers and recreate.

This is used to 'atomically' recreate VideoBuffers that may use hardware buffer references. It is only used by MythVideoOutputOpenGL (other MythVideoOutput classes currently do not support hardware frames).

Definition at line 483 of file videobuffers.cpp.

Referenced by MythVideoOutputGPU::InputChanged().

◆ At() [1/2]

MythVideoFrame * VideoBuffers::At ( uint  FrameNum)

◆ Dequeue()

MythVideoFrame * VideoBuffers::Dequeue ( BufferType  Type)

◆ Head()

MythVideoFrame * VideoBuffers::Head ( BufferType  Type)

◆ Tail()

MythVideoFrame * VideoBuffers::Tail ( BufferType  Type)

◆ Enqueue()

void VideoBuffers::Enqueue ( BufferType  Type,
MythVideoFrame Frame 
)

◆ SafeEnqueue()

void VideoBuffers::SafeEnqueue ( BufferType  Type,
MythVideoFrame Frame 
)

◆ Remove()

void VideoBuffers::Remove ( BufferType  Type,
MythVideoFrame Frame 
)

◆ BeginLock()

frame_queue_t::iterator VideoBuffers::BeginLock ( BufferType  Type)

Lock the video buffers.

Note
Use with caution. Holding this lock while releasing hardware buffers will almost certainly lead to deadlocks.

Definition at line 721 of file videobuffers.cpp.

Referenced by MythVideoOutputGPU::DoneDisplayingFrame(), and MythVideoOutputGPU::UpdatePauseFrame().

◆ End()

frame_queue_t::iterator VideoBuffers::End ( BufferType  Type)

Definition at line 735 of file videobuffers.cpp.

◆ EndLock()

void VideoBuffers::EndLock ( )

◆ Size() [1/2]

uint VideoBuffers::Size ( BufferType  Type) const

◆ Contains()

bool VideoBuffers::Contains ( BufferType  Type,
MythVideoFrame Frame 
) const

Definition at line 751 of file videobuffers.cpp.

Referenced by MythVideoOutputGPU::DoneDisplayingFrame().

◆ GetLastDecodedFrame() [1/2]

MythVideoFrame * VideoBuffers::GetLastDecodedFrame ( void  )

Definition at line 760 of file videobuffers.cpp.

Referenced by MythVideoOutput::GetLastDecodedFrame().

◆ GetLastShownFrame() [1/2]

MythVideoFrame * VideoBuffers::GetLastShownFrame ( void  )

Definition at line 765 of file videobuffers.cpp.

Referenced by MythVideoOutput::GetLastShownFrame().

◆ ValidVideoFrames()

uint VideoBuffers::ValidVideoFrames ( void  ) const

Definition at line 770 of file videobuffers.cpp.

Referenced by MythVideoOutput::ValidVideoFrames().

◆ FreeVideoFrames()

uint VideoBuffers::FreeVideoFrames ( void  ) const

Definition at line 775 of file videobuffers.cpp.

Referenced by MythVideoOutput::FreeVideoFrames().

◆ EnoughFreeFrames()

bool VideoBuffers::EnoughFreeFrames ( void  ) const

Definition at line 780 of file videobuffers.cpp.

Referenced by MythVideoOutput::EnoughFreeFrames().

◆ EnoughDecodedFrames()

bool VideoBuffers::EnoughDecodedFrames ( void  ) const

Definition at line 785 of file videobuffers.cpp.

Referenced by MythVideoOutput::EnoughDecodedFrames().

◆ At() [2/2]

const MythVideoFrame * VideoBuffers::At ( uint  FrameNum) const

Definition at line 634 of file videobuffers.cpp.

◆ GetLastDecodedFrame() [2/2]

const MythVideoFrame * VideoBuffers::GetLastDecodedFrame ( void  ) const

Definition at line 790 of file videobuffers.cpp.

◆ GetLastShownFrame() [2/2]

const MythVideoFrame * VideoBuffers::GetLastShownFrame ( void  ) const

Definition at line 795 of file videobuffers.cpp.

◆ Size() [2/2]

uint VideoBuffers::Size ( void  ) const

◆ GetStatus()

QString VideoBuffers::GetStatus ( uint  Num = 0) const

◆ Queue() [1/2]

frame_queue_t * VideoBuffers::Queue ( BufferType  Type)
private

Definition at line 587 of file videobuffers.cpp.

Referenced by BeginLock(), Contains(), Dequeue(), End(), Enqueue(), Head(), Size(), and Tail().

◆ Queue() [2/2]

const frame_queue_t * VideoBuffers::Queue ( BufferType  Type) const
private

Definition at line 608 of file videobuffers.cpp.

◆ GetNextFreeFrameInternal()

MythVideoFrame * VideoBuffers::GetNextFreeFrameInternal ( BufferType  EnqueueTo)
private

Definition at line 288 of file videobuffers.cpp.

Referenced by GetNextFreeFrame().

◆ SetDeinterlacingFlags()

void VideoBuffers::SetDeinterlacingFlags ( MythVideoFrame Frame,
MythDeintType  Single,
MythDeintType  Double,
MythCodecID  CodecID 
)
staticprivate

Set the appropriate flags for single and double rate deinterlacing.

Note
Double rate support is determined by the VideoOutput class and must be set appropriately
Driver deinterlacers are only available for hardware frames with the exception of NVDEC and VTB which can use shaders.
Shader and CPU deinterlacers are disabled for hardware frames (except for shaders with NVDEC and VTB)
Todo:
Handling of decoder deinterlacing with NVDEC

Definition at line 215 of file videobuffers.cpp.

Referenced by ReinitBuffer(), and SetDeinterlacing().

Member Data Documentation

◆ m_available

frame_queue_t VideoBuffers::m_available
private

◆ m_used

frame_queue_t VideoBuffers::m_used
private

◆ m_limbo

frame_queue_t VideoBuffers::m_limbo
private

◆ m_pause

frame_queue_t VideoBuffers::m_pause
private

◆ m_displayed

frame_queue_t VideoBuffers::m_displayed
private

◆ m_decode

frame_queue_t VideoBuffers::m_decode
private

◆ m_finished

frame_queue_t VideoBuffers::m_finished
private

◆ m_vbufferMap

vbuffer_map_t VideoBuffers::m_vbufferMap
private

Definition at line 110 of file videobuffers.h.

Referenced by ClearAfterSeek(), Init(), ReleaseFrame(), Reset(), and StartDisplayingFrame().

◆ m_buffers

frame_vector_t VideoBuffers::m_buffers
private

Definition at line 111 of file videobuffers.h.

Referenced by At(), CreateBuffers(), Init(), SetDeinterlacing(), and Size().

◆ m_renderFormats

const VideoFrameTypes* VideoBuffers::m_renderFormats { nullptr }
private

Definition at line 112 of file videobuffers.h.

Referenced by CreateBuffers(), and DiscardAndRecreate().

◆ m_needFreeFrames

uint VideoBuffers::m_needFreeFrames { 0 }
private

Definition at line 114 of file videobuffers.h.

Referenced by EnoughFreeFrames(), and Init().

◆ m_needPrebufferFrames

uint VideoBuffers::m_needPrebufferFrames { 0 }
private

Definition at line 115 of file videobuffers.h.

Referenced by EnoughDecodedFrames(), Init(), and SetPrebuffering().

◆ m_needPrebufferFramesNormal

uint VideoBuffers::m_needPrebufferFramesNormal { 0 }
private

Definition at line 116 of file videobuffers.h.

Referenced by Init(), and SetPrebuffering().

◆ m_needPrebufferFramesSmall

uint VideoBuffers::m_needPrebufferFramesSmall { 0 }
private

Definition at line 117 of file videobuffers.h.

Referenced by Init(), and SetPrebuffering().

◆ m_rpos

uint VideoBuffers::m_rpos { 0 }
private

Definition at line 118 of file videobuffers.h.

Referenced by ClearAfterSeek(), GetLastShownFrame(), and StartDisplayingFrame().

◆ m_vpos

uint VideoBuffers::m_vpos { 0 }
private

Definition at line 119 of file videobuffers.h.

Referenced by ClearAfterSeek(), GetLastDecodedFrame(), and ReleaseFrame().

◆ m_globalLock

QRecursiveMutex VideoBuffers::m_globalLock
mutableprivate

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