VideoBuffers Class Reference

#include <videobuffers.h>

List of all members.


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 can not 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.

Frame locking is also available, the locks are reqursive QMutex locks. If more than one frame lock is needed the LockFrames should generally be called with all the needed locks in the list, and no locks currently held. This function will spin until all the locks can be held at once, avoiding deadlocks from mismatched locking order.

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.

See also:
VideoOutput

Definition at line 60 of file videobuffers.h.


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 enable_frame_locking=false)
 Creates buffers and sets various buffer management parameters.
bool CreateBuffers (int width, int height, vector< unsigned char * > bufs, vector< YUVInfo > yuvinfo)
bool CreateBuffers (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 (bool with_lock, bool allow_unsafe, BufferType enqueue_to=kVideoBuffer_limbo)
 Gets a frame from available buffers list.
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 (void)
 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)
const VideoFrameGetScratchFrame () const
VideoFrameGetLastDecodedFrame (void)
VideoFrameGetLastShownFrame (void)
void SetLastShownFrameToScratch ()
bool WaitForAvailable (uint w)
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
uint allocSize () const
void LockFrame (const VideoFrame *, const char *owner)
void LockFrames (vector< const VideoFrame * > &, const char *owner)
bool TryLockFrame (const VideoFrame *, const char *owner)
void UnlockFrame (const VideoFrame *, const char *owner)
void UnlockFrames (vector< const VideoFrame * > &, const char *owner)
void AddInheritence (const VideoFrame *frame)
void RemoveInheritence (const VideoFrame *frame)
frame_queue_t Children (const VideoFrame *frame)
bool HasChildren (const VideoFrame *frame)
void Clear (uint i, int fourcc)
void Clear (int fourcc)
VideoFramePastFrame (const VideoFrame *frame)
VideoFrameFutureFrame (const VideoFrame *frame)
VideoFrameGetOSDFrame (const VideoFrame *frame)
void SetOSDFrame (VideoFrame *frame, VideoFrame *osd)
VideoFrameGetOSDParent (const VideoFrame *osd)
bool CreateBuffers (int width, int height, Display *disp, void *xvmc_ctx, void *xvmc_surf_info, vector< void * > surfs)
QString GetStatus (int n=-1) const

Private Member Functions

frame_queue_tqueue (BufferType type)
const frame_queue_tqueue (BufferType type) const
VideoFrameGetNextFreeFrameInternal (bool with_lock, bool allow_unsafe, 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
vbuffer_map_t vbufferMap
frame_vector_t buffers
uchar_vector_t allocated_structs
uchar_vector_t allocated_arrays
frame_map_t parents
frame_map_t children
QWaitCondition available_wait
uint numbuffers
uint needfreeframes
uint needprebufferframes
uint needprebufferframes_normal
uint needprebufferframes_small
uint keepprebufferframes
bool need_extra_for_pause
uint rpos
uint vpos
QMutex global_lock
bool use_frame_locks
QMutex frame_lock
frame_lock_map_t frame_locks
surf_to_frame_map_t xvmc_surf_to_frame
frame_to_frame_map_t xvmc_osd_parent

Constructor & Destructor Documentation

VideoBuffers::VideoBuffers (  ) 

Definition at line 112 of file videobuffers.cpp.

VideoBuffers::~VideoBuffers (  )  [virtual]

Definition at line 121 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  enable_frame_locking = false 
)

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:
numdecode number of buffers to allocate for normal use
extra_for_pause allocate an extra buffer, a scratch a frame for pause
need_free maximum number of buffers needed in display and pause
needprebuffer_normal number buffers you can put in used or limbo normally
needprebuffer_small number of buffers you can put in used or limbo after SetPrebuffering(false) has been called.
keepprebuffer number of buffers in used or limbo that are considered enough for decent playback.
enable_frame_locking if true, the frames will be locked with a mutex, this makes XvMC decoding safe, but adds some CPU overhead. It is normally left off.

Definition at line 150 of file videobuffers.cpp.

Referenced by CreateBuffers(), VideoOutputQuartz::Init(), VideoOutputNull::Init(), VideoOutputDX::Init(), VideoOutputDirectfb::Init(), VideoOutputD3D::Init(), and VideoOutputXv::InitVideoBuffers().

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

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

Definition at line 1106 of file videobuffers.cpp.

void VideoBuffers::DeleteBuffers ( void   ) 

void VideoBuffers::Reset ( void   ) 

Resets the class so that Init may be called again.

Definition at line 192 of file videobuffers.cpp.

Referenced by CreateBuffers(), Init(), and VideoOutputXv::InitVideoBuffers().

void VideoBuffers::DiscardFrames ( bool  next_frame_keyframe  ) 

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

Definition at line 653 of file videobuffers.cpp.

Referenced by VideoOutput::DiscardFrames(), VideoOutputXv::DiscardFrames(), GetNextFreeFrame(), and VideoOutputNull::InputChanged().

void VideoBuffers::ClearAfterSeek ( void   ) 

Definition at line 731 of file videobuffers.cpp.

Referenced by VideoOutput::ClearAfterSeek().

void VideoBuffers::SetPrebuffering ( bool  normal  ) 

Sets prebuffering state to normal, or small.

Definition at line 222 of file videobuffers.cpp.

Referenced by VideoOutput::SetPrebuffering().

VideoFrame * VideoBuffers::GetNextFreeFrame ( bool  with_lock,
bool  allow_unsafe,
BufferType  enqueue_to = kVideoBuffer_limbo 
)

Gets a frame from available buffers list.

Parameters:
with_lock locks the frame, so that UnlockFrame() must be called before anyone else can use it.
allow_unsafe allows busy buffers to be used if no available buffers exist. Historic, should never be used.
enqueue_to put new frame in some state other than limbo.

Definition at line 298 of file videobuffers.cpp.

Referenced by VideoOutput::GetNextFreeFrame(), VideoOutputXv::GetNextFreeFrame(), and VideoOutputXv::ProcessFrameXvMC().

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 338 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 353 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 374 of file videobuffers.cpp.

Referenced by VideoOutput::StartDisplayingFrame().

void VideoBuffers::DoneDisplayingFrame ( void   ) 

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

Definition at line 384 of file videobuffers.cpp.

Referenced by VideoOutput::DoneDisplayingFrame(), and VideoOutputXv::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 402 of file videobuffers.cpp.

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

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

VideoFrame * VideoBuffers::dequeue ( BufferType  type  ) 

VideoFrame * VideoBuffers::head ( BufferType  type  ) 

VideoFrame * VideoBuffers::tail ( BufferType  type  ) 

Definition at line 499 of file videobuffers.cpp.

Referenced by VideoOutputXv::UpdatePauseFrame().

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

Definition at line 555 of file videobuffers.cpp.

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

Definition at line 514 of file videobuffers.cpp.

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

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

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

Definition at line 534 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

Definition at line 614 of file videobuffers.cpp.

Referenced by VideoOutputXv::CheckFrameStates().

VideoFrame * VideoBuffers::GetScratchFrame ( void   ) 

const VideoFrame * VideoBuffers::GetScratchFrame ( void   )  const

Definition at line 637 of file videobuffers.cpp.

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

Definition at line 107 of file videobuffers.h.

Referenced by VideoOutput::GetLastDecodedFrame().

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

Definition at line 108 of file videobuffers.h.

Referenced by VideoOutput::GetLastShownFrame().

void VideoBuffers::SetLastShownFrameToScratch (  )  [inline]

bool VideoBuffers::WaitForAvailable ( uint  w  )  [inline]

Definition at line 110 of file videobuffers.h.

Referenced by VideoOutput::WaitForAvailable().

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

Definition at line 112 of file videobuffers.h.

Referenced by VideoOutput::ValidVideoFrames().

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

Definition at line 113 of file videobuffers.h.

Referenced by VideoOutput::FreeVideoFrames().

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

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

Definition at line 116 of file videobuffers.h.

Referenced by VideoOutput::EnoughDecodedFrames().

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

Definition at line 118 of file videobuffers.h.

Referenced by VideoOutput::EnoughPrebufferedFrames().

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

Definition at line 121 of file videobuffers.h.

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

Definition at line 122 of file videobuffers.h.

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

Definition at line 123 of file videobuffers.h.

uint VideoBuffers::size (  )  const [inline]

uint VideoBuffers::allocSize (  )  const [inline]

void VideoBuffers::LockFrame ( const VideoFrame frame,
const char *  owner 
)

void VideoBuffers::LockFrames ( vector< const VideoFrame * > &  vec,
const char *  owner 
)

Definition at line 792 of file videobuffers.cpp.

Referenced by VideoOutputXv::DrawSlice(), and VideoOutputXv::ProcessFrameMem().

bool VideoBuffers::TryLockFrame ( const VideoFrame frame,
const char *  owner 
)

void VideoBuffers::UnlockFrame ( const VideoFrame frame,
const char *  owner 
)

void VideoBuffers::UnlockFrames ( vector< const VideoFrame * > &  vec,
const char *  owner 
)

Definition at line 888 of file videobuffers.cpp.

Referenced by VideoOutputXv::DrawSlice(), and VideoOutputXv::ProcessFrameMem().

void VideoBuffers::AddInheritence ( const VideoFrame frame  ) 

Definition at line 903 of file videobuffers.cpp.

Referenced by VideoOutputXv::DrawSlice().

void VideoBuffers::RemoveInheritence ( const VideoFrame frame  ) 

frame_queue_t VideoBuffers::Children ( const VideoFrame frame  ) 

Definition at line 991 of file videobuffers.cpp.

Referenced by VideoOutputXv::CheckFrameStates().

bool VideoBuffers::HasChildren ( const VideoFrame frame  ) 

void VideoBuffers::Clear ( uint  i,
int  fourcc 
)

void VideoBuffers::Clear ( int  fourcc  ) 

Definition at line 1318 of file videobuffers.cpp.

VideoFrame * VideoBuffers::PastFrame ( const VideoFrame frame  ) 

Definition at line 1030 of file videobuffers.cpp.

Referenced by AddInheritence(), and VideoOutputXv::DrawSlice().

VideoFrame * VideoBuffers::FutureFrame ( const VideoFrame frame  ) 

Definition at line 1041 of file videobuffers.cpp.

Referenced by AddInheritence(), and VideoOutputXv::DrawSlice().

VideoFrame * VideoBuffers::GetOSDFrame ( const VideoFrame frame  ) 

void VideoBuffers::SetOSDFrame ( VideoFrame frame,
VideoFrame osd 
)

VideoFrame * VideoBuffers::GetOSDParent ( const VideoFrame osd  ) 

bool VideoBuffers::CreateBuffers ( int  width,
int  height,
Display *  disp,
void *  xvmc_ctx,
void *  xvmc_surf_info,
vector< void * >  surfs 
)

Definition at line 1161 of file videobuffers.cpp.

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

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

Definition at line 428 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 450 of file videobuffers.cpp.

VideoFrame * VideoBuffers::GetNextFreeFrameInternal ( bool  with_lock,
bool  allow_unsafe,
BufferType  enqueue_to 
) [private]

Definition at line 229 of file videobuffers.cpp.

Referenced by GetNextFreeFrame().


Member Data Documentation

Definition at line 161 of file videobuffers.h.

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

Definition at line 161 of file videobuffers.h.

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

Definition at line 162 of file videobuffers.h.

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

Definition at line 163 of file videobuffers.h.

Definition at line 164 of file videobuffers.h.

Referenced by CreateBuffers(), and DeleteBuffers().

Definition at line 165 of file videobuffers.h.

Referenced by CreateBuffers(), and DeleteBuffers().

Definition at line 166 of file videobuffers.h.

Referenced by AddInheritence(), RemoveInheritence(), and Reset().

Definition at line 167 of file videobuffers.h.

Referenced by AddInheritence(), Children(), HasChildren(), RemoveInheritence(), and Reset().

QWaitCondition VideoBuffers::available_wait [private]

Definition at line 171 of file videobuffers.h.

Referenced by GetStatus(), Init(), and size().

Definition at line 172 of file videobuffers.h.

Referenced by CreateBuffers(), EnoughFreeFrames(), and Init().

Definition at line 173 of file videobuffers.h.

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

Definition at line 174 of file videobuffers.h.

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

Definition at line 175 of file videobuffers.h.

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

Definition at line 175 of file videobuffers.h.

Referenced by CreateBuffers(), EnoughPrebufferedFrames(), and Init().

Definition at line 177 of file videobuffers.h.

Referenced by GetScratchFrame(), and Init().

Definition at line 180 of file videobuffers.h.

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

QMutex VideoBuffers::global_lock [mutable, private]

Definition at line 184 of file videobuffers.h.

Referenced by Init(), LockFrame(), LockFrames(), TryLockFrame(), UnlockFrame(), and UnlockFrames().

QMutex VideoBuffers::frame_lock [private]

Definition at line 185 of file videobuffers.h.

Referenced by LockFrame(), TryLockFrame(), and UnlockFrame().

Definition at line 186 of file videobuffers.h.

Referenced by LockFrame(), TryLockFrame(), and UnlockFrame().

Definition at line 189 of file videobuffers.h.

Referenced by CreateBuffers(), DeleteBuffers(), FutureFrame(), and PastFrame().

Definition at line 190 of file videobuffers.h.

Referenced by GetOSDParent(), and SetOSDFrame().


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

Generated on Sat Dec 18 05:16:13 2010 for MythTV by  doxygen 1.5.5