VideoBuffers Class Reference

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

#include <videobuffers.h>

List of all members.

Public Member Functions

 VideoBuffers ()
virtual ~VideoBuffers ()
void Init (uint numdecode, bool extra_for_pause, uint need_free, uint needprebuffer_normal, uint needprebuffer_small, uint keepprebuffer)
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.
void DiscardFrames (bool next_frame_keyframe)
 Mark all used frames as ready to be reused, this is for seek.
void ClearAfterSeek (void)
void SetPrebuffering (bool normal)
 Sets prebuffering state to normal, or small.
VideoFrameGetNextFreeFrame (BufferType enqueue_to=kVideoBuffer_limbo)
void ReleaseFrame (VideoFrame *frame)
 Frame is ready to be for filtering or OSD application.
void DeLimboFrame (VideoFrame *frame)
 If the frame is still in the limbo state it is added to the available queue.
void StartDisplayingFrame (void)
 Sets rpos to index of videoframe at head of used queue.
void DoneDisplayingFrame (VideoFrame *frame)
 Removes frame from used queue and adds it to the available list.
void DiscardFrame (VideoFrame *frame)
 Frame is ready to be reused by decoder.
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 available
frame_queue_t used
frame_queue_t limbo
frame_queue_t pause
frame_queue_t displayed
frame_queue_t decode
frame_queue_t finished
vbuffer_map_t vbufferMap
frame_vector_t buffers
uchar_vector_t allocated_arrays
uint needfreeframes
uint needprebufferframes
uint needprebufferframes_normal
uint needprebufferframes_small
uint keepprebufferframes
bool createdpauseframe
uint rpos
uint vpos
QMutex global_lock

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 (  ) 

Definition at line 121 of file videobuffers.cpp.

VideoBuffers::~VideoBuffers (  )  [virtual]

Definition at line 129 of file videobuffers.cpp.


Member Function Documentation

void VideoBuffers::Init ( uint  numdecode,
bool  extra_for_pause,
uint  need_free,
uint  needprebuffer_normal,
uint  needprebuffer_small,
uint  keepprebuffer 
)
bool VideoBuffers::CreateBuffers ( VideoFrameType  type,
int  width,
int  height,
vector< unsigned char * >  bufs,
vector< YUVInfo yuvinfo 
)
bool VideoBuffers::CreateBuffers ( VideoFrameType  type,
int  width,
int  height 
)

Definition at line 704 of file videobuffers.cpp.

void VideoBuffers::DeleteBuffers ( void   ) 
void VideoBuffers::Reset ( void   ) 
void VideoBuffers::DiscardFrames ( bool  next_frame_keyframe  ) 
void VideoBuffers::ClearAfterSeek ( void   ) 

Definition at line 676 of file videobuffers.cpp.

Referenced by VideoOutput::ClearAfterSeek().

void VideoBuffers::SetPrebuffering ( bool  normal  ) 

Sets prebuffering state to normal, or small.

Definition at line 227 of file videobuffers.cpp.

Referenced by VideoOutput::SetPrebuffering().

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

Definition at line 269 of file videobuffers.cpp.

Referenced by VideoOutput::GetNextFreeFrame().

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:
frame Frame to move to used.

Definition at line 306 of file videobuffers.cpp.

Referenced by VideoOutput::ReleaseFrame().

void VideoBuffers::DeLimboFrame ( VideoFrame frame  ) 

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

Parameters:
frame Frame to move to used.

Definition at line 321 of file videobuffers.cpp.

Referenced by VideoOutput::DeLimboFrame().

void VideoBuffers::StartDisplayingFrame ( void   ) 

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

Definition at line 341 of file videobuffers.cpp.

Referenced by VideoOutput::StartDisplayingFrame().

void VideoBuffers::DoneDisplayingFrame ( VideoFrame frame  ) 

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

Definition at line 351 of file videobuffers.cpp.

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

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 378 of file videobuffers.cpp.

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

VideoFrame* VideoBuffers::at ( uint  i  )  [inline]
VideoFrame * VideoBuffers::dequeue ( BufferType  type  ) 

Definition at line 432 of file videobuffers.cpp.

Referenced by requeue().

VideoFrame * VideoBuffers::head ( BufferType  type  ) 
VideoFrame * VideoBuffers::tail ( BufferType  type  ) 

Definition at line 459 of file videobuffers.cpp.

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

Definition at line 514 of file videobuffers.cpp.

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

Definition at line 474 of file videobuffers.cpp.

Referenced by AddBuffer(), DoneDisplayingFrame(), Init(), requeue(), and safeEnqueue().

void VideoBuffers::safeEnqueue ( BufferType  dst,
VideoFrame frame 
)
void VideoBuffers::remove ( BufferType  type,
VideoFrame frame 
)

Definition at line 491 of file videobuffers.cpp.

frame_queue_t::iterator VideoBuffers::begin_lock ( BufferType  type  ) 
frame_queue_t::iterator VideoBuffers::end ( BufferType  type  ) 
void VideoBuffers::end_lock (  )  [inline]
uint VideoBuffers::size ( BufferType  type  )  const
bool VideoBuffers::contains ( BufferType  type,
VideoFrame frame 
) const
VideoFrame * VideoBuffers::GetScratchFrame ( void   ) 
VideoFrame* VideoBuffers::GetLastDecodedFrame ( void   )  [inline]
VideoFrame* VideoBuffers::GetLastShownFrame ( void   )  [inline]
void VideoBuffers::SetLastShownFrameToScratch ( void   ) 
uint VideoBuffers::ValidVideoFrames ( void   )  const [inline]

Definition at line 109 of file videobuffers.h.

Referenced by VideoOutput::ValidVideoFrames().

uint VideoBuffers::FreeVideoFrames ( void   )  const [inline]

Definition at line 110 of file videobuffers.h.

Referenced by VideoOutput::FreeVideoFrames().

bool VideoBuffers::EnoughFreeFrames ( void   )  const [inline]

Definition at line 111 of file videobuffers.h.

Referenced by VideoOutput::EnoughFreeFrames().

bool VideoBuffers::EnoughDecodedFrames ( void   )  const [inline]

Definition at line 113 of file videobuffers.h.

Referenced by VideoOutput::EnoughDecodedFrames().

bool VideoBuffers::EnoughPrebufferedFrames ( void   )  const [inline]

Definition at line 115 of file videobuffers.h.

Referenced by VideoOutput::EnoughPrebufferedFrames().

const VideoFrame* VideoBuffers::at ( uint  i  )  const [inline]

Definition at line 118 of file videobuffers.h.

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

Definition at line 119 of file videobuffers.h.

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

Definition at line 120 of file videobuffers.h.

uint VideoBuffers::Size ( void   )  const [inline]
void VideoBuffers::Clear ( uint  i  ) 

Definition at line 853 of file videobuffers.cpp.

Referenced by VideoOutputNull::InputChanged().

void VideoBuffers::Clear ( void   ) 

Definition at line 858 of file videobuffers.cpp.

Referenced by CreateBuffers().

bool VideoBuffers::CreateBuffer ( int  width,
int  height,
uint  num,
void *  data,
VideoFrameType  fmt 
)
uint VideoBuffers::AddBuffer ( int  width,
int  height,
void *  data,
VideoFrameType  fmt 
)
QString VideoBuffers::GetStatus ( int  n = -1  )  const
frame_queue_t * VideoBuffers::queue ( BufferType  type  )  [private]

Definition at line 384 of file videobuffers.cpp.

Referenced by begin_lock(), contains(), dequeue(), end(), enqueue(), head(), size(), and tail().

const frame_queue_t * VideoBuffers::queue ( BufferType  type  )  const [private]

Definition at line 408 of file videobuffers.cpp.

VideoFrame * VideoBuffers::GetNextFreeFrameInternal ( BufferType  enqueue_to  )  [private]

Definition at line 234 of file videobuffers.cpp.

Referenced by GetNextFreeFrame().


Member Data Documentation

Definition at line 137 of file videobuffers.h.

Referenced by DeLimboFrame(), DiscardFrames(), GetStatus(), queue(), ReleaseFrame(), remove(), and Reset().

Definition at line 137 of file videobuffers.h.

Referenced by DiscardFrames(), GetStatus(), queue(), remove(), and Reset().

Definition at line 137 of file videobuffers.h.

Referenced by DiscardFrames(), DoneDisplayingFrame(), GetStatus(), queue(), remove(), and Reset().

Definition at line 139 of file videobuffers.h.

Definition at line 140 of file videobuffers.h.

Referenced by CreateBuffers(), and DeleteBuffers().

Definition at line 142 of file videobuffers.h.

Referenced by EnoughFreeFrames(), and Init().

Definition at line 143 of file videobuffers.h.

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

Definition at line 144 of file videobuffers.h.

Referenced by Init(), and SetPrebuffering().

Definition at line 145 of file videobuffers.h.

Referenced by Init(), and SetPrebuffering().

Definition at line 145 of file videobuffers.h.

Referenced by EnoughPrebufferedFrames(), and Init().

Definition at line 147 of file videobuffers.h.

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

Definition at line 150 of file videobuffers.h.

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

QMutex VideoBuffers::global_lock [mutable, private]

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends
Generated on Mon May 28 06:42:32 2012 for MythTV by  doxygen 1.6.3