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

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

#include <videobuffers.h>

Collaboration diagram for VideoBuffers:
Collaboration graph
[legend]

Public Member Functions

 VideoBuffers ()=default
 
virtual ~VideoBuffers ()
 
void Init (uint numdecode, bool extra_for_pause, uint need_free, uint needprebuffer_normal, uint needprebuffer_small, uint keepprebuffer)
 Creates buffers and sets various buffer management parameters. More...
 
bool CreateBuffers (VideoFrameType type, int width, int height, vector< unsigned char * > bufs, vector< YUVInfo > yuvinfo)
 
bool CreateBuffers (VideoFrameType type, int width, int height)
 
void DeleteBuffers (void)
 
void Reset (void)
 Resets the class so that Init may be called again. More...
 
void DiscardFrames (bool next_frame_keyframe)
 Mark all used frames as ready to be reused, this is for seek. More...
 
void ClearAfterSeek (void)
 
void SetPrebuffering (bool normal)
 Sets prebuffering state to normal, or small. More...
 
VideoFrameGetNextFreeFrame (BufferType enqueue_to=kVideoBuffer_limbo)
 Gets a frame from available buffers list. More...
 
void ReleaseFrame (VideoFrame *frame)
 Frame is ready to be for filtering or OSD application. More...
 
void DeLimboFrame (VideoFrame *frame)
 If the frame is still in the limbo state it is added to the available queue. More...
 
void StartDisplayingFrame (void)
 Sets rpos to index of videoframe at head of used queue. More...
 
void DoneDisplayingFrame (VideoFrame *frame)
 Removes frame from used queue and adds it to the available list. More...
 
void DiscardFrame (VideoFrame *frame)
 Frame is ready to be reused by decoder. More...
 
VideoFrameAt (uint i)
 
VideoFrameDequeue (BufferType)
 
VideoFrameHead (BufferType)
 
VideoFrameTail (BufferType)
 
void Requeue (BufferType dst, BufferType src, int num=1)
 
void Enqueue (BufferType, VideoFrame *)
 
void SafeEnqueue (BufferType, VideoFrame *frame)
 
void Remove (BufferType, VideoFrame *)
 
frame_queue_t::iterator begin_lock (BufferType)
 
frame_queue_t::iterator end (BufferType)
 
void end_lock ()
 
uint Size (BufferType type) const
 
bool Contains (BufferType type, VideoFrame *) const
 
VideoFrameGetScratchFrame (void)
 
VideoFrameGetLastDecodedFrame (void)
 
VideoFrameGetLastShownFrame (void)
 
void SetLastShownFrameToScratch (void)
 
uint ValidVideoFrames (void) const
 
uint FreeVideoFrames (void) const
 
bool EnoughFreeFrames (void) const
 
bool EnoughDecodedFrames (void) const
 
bool EnoughPrebufferedFrames (void) const
 
const VideoFrameAt (uint i) const
 
const VideoFrameGetLastDecodedFrame (void) const
 
const VideoFrameGetLastShownFrame (void) const
 
uint Size () const
 
void Clear (uint i)
 
void Clear (void)
 
bool CreateBuffer (int width, int height, uint num, void *data, VideoFrameType fmt)
 
uint AddBuffer (int width, int height, void *data, VideoFrameType fmt)
 
QString GetStatus (int n=-1) const
 

Private Member Functions

frame_queue_tQueue (BufferType type)
 
const frame_queue_tQueue (BufferType type) const
 
VideoFrameGetNextFreeFrameInternal (BufferType enqueue_to)
 

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
 
uchar_vector_t m_allocatedArrays
 
uint m_needFreeFrames {0}
 
uint m_needPrebufferFrames {0}
 
uint m_needPrebufferFramesNormal {0}
 
uint m_needPrebufferFramesSmall {0}
 
uint m_keepPrebufferFrames {0}
 
bool m_createdPauseFrame {false}
 
uint m_rpos {0}
 
uint m_vpos {0}
 
QMutex m_globalLock {QMutex::Recursive}
 

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 61 of file videobuffers.h.

Constructor & Destructor Documentation

◆ VideoBuffers()

VideoBuffers::VideoBuffers ( )
default

◆ ~VideoBuffers()

VideoBuffers::~VideoBuffers ( )
virtual

Definition at line 137 of file videobuffers.cpp.

Member Function Documentation

◆ Init()

void VideoBuffers::Init ( uint  numdecode,
bool  extra_for_pause,
uint  need_free,
uint  needprebuffer_normal,
uint  needprebuffer_small,
uint  keepprebuffer 
)

Creates buffers and sets various buffer management parameters.

This normally creates numdecode buffers, but it creates one more buffer if extra_for_pause is true. Only numdecode buffers are added to available and hence into the buffer management handled by VideoBuffers. The availability of any scratch frame must be managed by the video output class itself.

Parameters
numdecodenumber of buffers to allocate for normal use
extra_for_pauseallocate an extra buffer, a scratch a frame for pause
need_freemaximum number of buffers needed in display and pause
needprebuffer_normalnumber buffers you can put in used or limbo normally
needprebuffer_smallnumber of buffers you can put in used or limbo after SetPrebuffering(false) has been called.
keepprebuffernumber of buffers in used or limbo that are considered enough for decent playback.

Definition at line 163 of file videobuffers.cpp.

Referenced by VideoOutputOpenGLVAAPI::CreateBuffers(), VideoOutputOpenGL::CreateBuffers(), VideoOutputD3D::CreateBuffers(), VideoOutputNull::Init(), VideoOutputOMX::Init(), VideoOutputNullVAAPI::InitBuffers(), VideoOutputNullVDPAU::InitBuffers(), VideoOutputVDPAU::InitBuffers(), VideoOutputNullVDPAU::InitShadowBuffers(), and VideoOutputXv::InitVideoBuffers().

◆ CreateBuffers() [1/2]

bool VideoBuffers::CreateBuffers ( VideoFrameType  type,
int  width,
int  height,
vector< unsigned char * >  bufs,
vector< YUVInfo yuvinfo 
)

◆ CreateBuffers() [2/2]

bool VideoBuffers::CreateBuffers ( VideoFrameType  type,
int  width,
int  height 
)

Definition at line 716 of file videobuffers.cpp.

◆ DeleteBuffers()

void VideoBuffers::DeleteBuffers ( void  )

◆ Reset()

void VideoBuffers::Reset ( void  )

◆ DiscardFrames()

void VideoBuffers::DiscardFrames ( bool  next_frame_keyframe)

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

Definition at line 620 of file videobuffers.cpp.

Referenced by VideoOutputNullVDPAU::DiscardFrames(), VideoOutputVDPAU::DiscardFrames(), VideoOutputXv::DiscardFrames(), GetNextFreeFrame(), and VideoOutputD3D::TearDown().

◆ ClearAfterSeek()

void VideoBuffers::ClearAfterSeek ( void  )

Definition at line 688 of file videobuffers.cpp.

◆ SetPrebuffering()

void VideoBuffers::SetPrebuffering ( bool  normal)

Sets prebuffering state to normal, or small.

Definition at line 231 of file videobuffers.cpp.

◆ GetNextFreeFrame()

VideoFrame * VideoBuffers::GetNextFreeFrame ( BufferType  enqueue_to = kVideoBuffer_limbo)

Gets a frame from available buffers list.

Parameters
enqueue_toput new frame in some state other than limbo.

Definition at line 273 of file videobuffers.cpp.

◆ ReleaseFrame()

void VideoBuffers::ReleaseFrame ( VideoFrame 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 315 of file videobuffers.cpp.

◆ DeLimboFrame()

void VideoBuffers::DeLimboFrame ( VideoFrame 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 332 of file videobuffers.cpp.

◆ StartDisplayingFrame()

void VideoBuffers::StartDisplayingFrame ( void  )

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

Definition at line 352 of file videobuffers.cpp.

◆ DoneDisplayingFrame()

void VideoBuffers::DoneDisplayingFrame ( VideoFrame frame)

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

Definition at line 362 of file videobuffers.cpp.

Referenced by VideoOutputNullVDPAU::DiscardFrame(), and VideoOutputVDPAU::DiscardFrame().

◆ DiscardFrame()

void VideoBuffers::DiscardFrame ( VideoFrame frame)

Frame is ready to be reused by decoder.

Add frame to available list, remove from any other list.

Definition at line 389 of file videobuffers.cpp.

Referenced by VideoOutputNullVAAPI::DiscardFrame(), VideoOutputXv::DiscardFrame(), and DiscardFrames().

◆ At() [1/2]

VideoFrame* VideoBuffers::At ( uint  i)
inline

◆ Dequeue()

VideoFrame * VideoBuffers::Dequeue ( BufferType  type)

◆ Head()

VideoFrame * VideoBuffers::Head ( BufferType  type)

◆ Tail()

VideoFrame * VideoBuffers::Tail ( BufferType  type)

Definition at line 470 of file videobuffers.cpp.

Referenced by VideoOutputOMX::UpdatePauseFrame().

◆ Requeue()

void VideoBuffers::Requeue ( BufferType  dst,
BufferType  src,
int  num = 1 
)

Definition at line 523 of file videobuffers.cpp.

◆ Enqueue()

void VideoBuffers::Enqueue ( BufferType  type,
VideoFrame frame 
)

◆ SafeEnqueue()

void VideoBuffers::SafeEnqueue ( BufferType  dst,
VideoFrame frame 
)

◆ Remove()

void VideoBuffers::Remove ( BufferType  type,
VideoFrame frame 
)

Definition at line 500 of file videobuffers.cpp.

Referenced by DiscardFrames(), DoneDisplayingFrame(), and SafeEnqueue().

◆ begin_lock()

frame_queue_t::iterator VideoBuffers::begin_lock ( BufferType  type)

◆ end()

frame_queue_t::iterator VideoBuffers::end ( BufferType  type)

◆ end_lock()

void VideoBuffers::end_lock ( )
inline

◆ Size() [1/2]

uint VideoBuffers::Size ( BufferType  type) const

◆ Contains()

bool VideoBuffers::Contains ( BufferType  type,
VideoFrame frame 
) const

◆ GetScratchFrame()

VideoFrame * VideoBuffers::GetScratchFrame ( void  )

◆ GetLastDecodedFrame() [1/2]

VideoFrame* VideoBuffers::GetLastDecodedFrame ( void  )
inline

◆ GetLastShownFrame() [1/2]

VideoFrame* VideoBuffers::GetLastShownFrame ( void  )
inline

◆ SetLastShownFrameToScratch()

void VideoBuffers::SetLastShownFrameToScratch ( void  )

◆ ValidVideoFrames()

uint VideoBuffers::ValidVideoFrames ( void  ) const
inline

Definition at line 109 of file videobuffers.h.

◆ FreeVideoFrames()

uint VideoBuffers::FreeVideoFrames ( void  ) const
inline

Definition at line 110 of file videobuffers.h.

◆ EnoughFreeFrames()

bool VideoBuffers::EnoughFreeFrames ( void  ) const
inline

Definition at line 111 of file videobuffers.h.

◆ EnoughDecodedFrames()

bool VideoBuffers::EnoughDecodedFrames ( void  ) const
inline

Definition at line 113 of file videobuffers.h.

◆ EnoughPrebufferedFrames()

bool VideoBuffers::EnoughPrebufferedFrames ( void  ) const
inline

Definition at line 115 of file videobuffers.h.

◆ At() [2/2]

const VideoFrame* VideoBuffers::At ( uint  i) const
inline

Definition at line 118 of file videobuffers.h.

◆ GetLastDecodedFrame() [2/2]

const VideoFrame* VideoBuffers::GetLastDecodedFrame ( void  ) const
inline

Definition at line 119 of file videobuffers.h.

◆ GetLastShownFrame() [2/2]

const VideoFrame* VideoBuffers::GetLastShownFrame ( void  ) const
inline

Definition at line 120 of file videobuffers.h.

◆ Size() [2/2]

uint VideoBuffers::Size ( void  ) const
inline

◆ Clear() [1/2]

void VideoBuffers::Clear ( uint  i)

Definition at line 868 of file videobuffers.cpp.

Referenced by VideoOutputNull::InputChanged().

◆ Clear() [2/2]

void VideoBuffers::Clear ( void  )

Definition at line 873 of file videobuffers.cpp.

Referenced by CreateBuffers().

◆ CreateBuffer()

bool VideoBuffers::CreateBuffer ( int  width,
int  height,
uint  num,
void *  data,
VideoFrameType  fmt 
)

◆ AddBuffer()

uint VideoBuffers::AddBuffer ( int  width,
int  height,
void *  data,
VideoFrameType  fmt 
)

◆ GetStatus()

QString VideoBuffers::GetStatus ( int  n = -1) const

◆ Queue() [1/2]

frame_queue_t * VideoBuffers::Queue ( BufferType  type)
private

Definition at line 395 of file videobuffers.cpp.

Referenced by begin_lock(), Contains(), Dequeue(), end(), Enqueue(), Head(), Size(), and Tail().

◆ Queue() [2/2]

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

Definition at line 419 of file videobuffers.cpp.

◆ GetNextFreeFrameInternal()

VideoFrame * VideoBuffers::GetNextFreeFrameInternal ( BufferType  enqueue_to)
private

Definition at line 238 of file videobuffers.cpp.

Referenced by GetNextFreeFrame().

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

Definition at line 140 of file videobuffers.h.

Referenced by DiscardFrames(), GetNextFreeFrame(), GetStatus(), Queue(), Remove(), and Reset().

◆ m_displayed

frame_queue_t VideoBuffers::m_displayed
private

Definition at line 141 of file videobuffers.h.

Referenced by DiscardFrames(), GetNextFreeFrame(), GetStatus(), Queue(), Remove(), and Reset().

◆ 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

◆ m_buffers

frame_vector_t VideoBuffers::m_buffers
private

Definition at line 145 of file videobuffers.h.

Referenced by AddBuffer(), CreateBuffer(), CreateBuffers(), DeleteBuffers(), Init(), and Reset().

◆ m_allocatedArrays

uchar_vector_t VideoBuffers::m_allocatedArrays
private

Definition at line 146 of file videobuffers.h.

Referenced by AddBuffer(), CreateBuffers(), and DeleteBuffers().

◆ m_needFreeFrames

uint VideoBuffers::m_needFreeFrames {0}
private

Definition at line 148 of file videobuffers.h.

Referenced by Init().

◆ m_needPrebufferFrames

uint VideoBuffers::m_needPrebufferFrames {0}
private

Definition at line 149 of file videobuffers.h.

Referenced by Init(), and SetPrebuffering().

◆ m_needPrebufferFramesNormal

uint VideoBuffers::m_needPrebufferFramesNormal {0}
private

Definition at line 150 of file videobuffers.h.

Referenced by Init(), and SetPrebuffering().

◆ m_needPrebufferFramesSmall

uint VideoBuffers::m_needPrebufferFramesSmall {0}
private

Definition at line 151 of file videobuffers.h.

Referenced by Init(), and SetPrebuffering().

◆ m_keepPrebufferFrames

uint VideoBuffers::m_keepPrebufferFrames {0}
private

Definition at line 152 of file videobuffers.h.

Referenced by Init().

◆ m_createdPauseFrame

bool VideoBuffers::m_createdPauseFrame {false}
private

Definition at line 153 of file videobuffers.h.

Referenced by GetScratchFrame(), Init(), and SetLastShownFrameToScratch().

◆ m_rpos

uint VideoBuffers::m_rpos {0}
private

◆ m_vpos

uint VideoBuffers::m_vpos {0}
private

Definition at line 155 of file videobuffers.h.

Referenced by ClearAfterSeek(), and ReleaseFrame().

◆ m_globalLock

QMutex VideoBuffers::m_globalLock {QMutex::Recursive}
mutableprivate

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