MythTV
master
|
#include <libmythtv/videobuffers.h>
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_t * | Queue (BufferType Type) |
const frame_queue_t * | Queue (BufferType Type) const |
MythVideoFrame * | GetNextFreeFrameInternal (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 VideoFrameTypes * | m_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 |
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).
Definition at line 38 of file videobuffers.h.
|
default |
|
default |
|
static |
Definition at line 136 of file videobuffers.cpp.
Referenced by CreateBuffers(), VideoOutputD3D::CreateBuffers(), MythVideoOutputGPU::CreateBuffers(), DiscardAndRecreate(), MythVideoOutputNull::Init(), MythVAAPIContext::InitialiseContext(), and MythVAAPIContext::InitialiseContext2().
void VideoBuffers::Init | ( | uint | NumDecode, |
uint | NeedFree, | ||
uint | NeedPrebufferNormal, | ||
uint | NeedPrebufferSmall | ||
) |
Creates buffers and sets various buffer management parameters.
NumDecode | number of buffers to allocate for normal use |
NeedFree | maximum number of buffers needed in display and pause |
NeedPrebufferNormal | number buffers you can put in used or limbo normally |
NeedPrebufferSmall | number 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().
bool VideoBuffers::CreateBuffers | ( | VideoFrameType | Type, |
const VideoFrameTypes * | RenderFormats, | ||
QSize | Size, | ||
uint | NeedFree, | ||
uint | NeedprebufferNormal, | ||
uint | NeedPrebufferSmall, | ||
int | MaxReferenceFrames = 16 |
||
) |
Definition at line 941 of file videobuffers.cpp.
Referenced by MythVideoOutputGPU::CreateBuffers(), DiscardAndRecreate(), MythVideoOutputNull::Init(), VideoOutputD3D::InitBuffers(), and MythVideoOutputNull::InputChanged().
bool VideoBuffers::CreateBuffers | ( | VideoFrameType | Type, |
int | Width, | ||
int | Height, | ||
const VideoFrameTypes * | RenderFormats | ||
) |
Definition at line 950 of file videobuffers.cpp.
|
static |
Definition at line 982 of file videobuffers.cpp.
Referenced by get_avf_buffer(), MythMMALContext::GetBuffer(), MythV4L2M2MContext::GetBuffer(), and MythCodecContext::RetrieveHWFrame().
void VideoBuffers::SetDeinterlacing | ( | MythDeintType | Single, |
MythDeintType | Double, | ||
MythCodecID | CodecID | ||
) |
Definition at line 200 of file videobuffers.cpp.
Referenced by Init(), MythVideoOutputNull::SetDeinterlacing(), and MythVideoOutput::SetDeinterlacing().
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().
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().
void VideoBuffers::ClearAfterSeek | ( | void | ) |
Clear used frames after seeking.
Definition at line 896 of file videobuffers.cpp.
Referenced by MythVideoOutput::ClearAfterSeek().
void VideoBuffers::SetPrebuffering | ( | bool | normal | ) |
Sets prebuffering state to normal, or small.
Definition at line 282 of file videobuffers.cpp.
Referenced by MythVideoOutput::SetPrebuffering().
MythVideoFrame * VideoBuffers::GetNextFreeFrame | ( | BufferType | EnqueueTo = kVideoBuffer_limbo | ) |
Gets a frame from available buffers list.
EnqueueTo | Put new frame in some state other than limbo. |
Definition at line 320 of file videobuffers.cpp.
Referenced by MythVideoOutput::GetNextFreeFrame().
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.
frame | Frame to move to used. |
Definition at line 361 of file videobuffers.cpp.
Referenced by MythVideoOutput::ReleaseFrame().
void VideoBuffers::DeLimboFrame | ( | MythVideoFrame * | Frame | ) |
If the frame is still in the limbo state it is added to the available queue.
frame | Frame to move to used. |
Definition at line 378 of file videobuffers.cpp.
Referenced by MythVideoOutput::DeLimboFrame().
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().
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().
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().
void VideoBuffers::DiscardPauseFrames | ( | void | ) |
Definition at line 461 of file videobuffers.cpp.
Referenced by MythVideoOutputGPU::DiscardFrames().
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().
MythVideoFrame * VideoBuffers::At | ( | uint | FrameNum | ) |
Definition at line 629 of file videobuffers.cpp.
Referenced by ClearAfterSeek(), DiscardAndRecreate(), DiscardFrames(), GetLastDecodedFrame(), GetLastShownFrame(), and Init().
MythVideoFrame * VideoBuffers::Dequeue | ( | BufferType | Type | ) |
Definition at line 639 of file videobuffers.cpp.
Referenced by MythVideoOutputGPU::DoneDisplayingFrame(), and MythVideoOutputGPU::UpdatePauseFrame().
MythVideoFrame * VideoBuffers::Head | ( | BufferType | Type | ) |
Definition at line 648 of file videobuffers.cpp.
Referenced by VideoOutputD3D::UpdatePauseFrame(), and MythVideoOutputGPU::UpdatePauseFrame().
MythVideoFrame * VideoBuffers::Tail | ( | BufferType | Type | ) |
Definition at line 659 of file videobuffers.cpp.
Referenced by DiscardAndRecreate(), DiscardPauseFrames(), and MythVideoOutputGPU::RenderFrame().
void VideoBuffers::Enqueue | ( | BufferType | Type, |
MythVideoFrame * | Frame | ||
) |
Definition at line 670 of file videobuffers.cpp.
Referenced by MythVideoOutputGPU::DoneDisplayingFrame(), DoneDisplayingFrame(), Init(), and SafeEnqueue().
void VideoBuffers::SafeEnqueue | ( | BufferType | Type, |
MythVideoFrame * | Frame | ||
) |
Definition at line 707 of file videobuffers.cpp.
Referenced by DeLimboFrame(), DiscardAndRecreate(), DiscardFrame(), DiscardFrames(), DiscardPauseFrames(), and GetNextFreeFrameInternal().
void VideoBuffers::Remove | ( | BufferType | Type, |
MythVideoFrame * | Frame | ||
) |
Definition at line 685 of file videobuffers.cpp.
Referenced by DiscardAndRecreate(), DiscardFrames(), MythVideoOutputGPU::DoneDisplayingFrame(), DoneDisplayingFrame(), and SafeEnqueue().
frame_queue_t::iterator VideoBuffers::BeginLock | ( | BufferType | Type | ) |
Lock the video buffers.
Definition at line 721 of file videobuffers.cpp.
Referenced by MythVideoOutputGPU::DoneDisplayingFrame(), and MythVideoOutputGPU::UpdatePauseFrame().
frame_queue_t::iterator VideoBuffers::End | ( | BufferType | Type | ) |
Definition at line 735 of file videobuffers.cpp.
void VideoBuffers::EndLock | ( | ) |
Definition at line 730 of file videobuffers.cpp.
Referenced by MythVideoOutputGPU::DoneDisplayingFrame(), and MythVideoOutputGPU::UpdatePauseFrame().
uint VideoBuffers::Size | ( | BufferType | Type | ) | const |
Definition at line 742 of file videobuffers.cpp.
Referenced by MythVideoOutputGPU::DoneDisplayingFrame(), and MythVideoOutputGPU::RenderFrame().
bool VideoBuffers::Contains | ( | BufferType | Type, |
MythVideoFrame * | Frame | ||
) | const |
Definition at line 751 of file videobuffers.cpp.
Referenced by MythVideoOutputGPU::DoneDisplayingFrame().
MythVideoFrame * VideoBuffers::GetLastDecodedFrame | ( | void | ) |
Definition at line 760 of file videobuffers.cpp.
Referenced by MythVideoOutput::GetLastDecodedFrame().
MythVideoFrame * VideoBuffers::GetLastShownFrame | ( | void | ) |
Definition at line 765 of file videobuffers.cpp.
Referenced by MythVideoOutput::GetLastShownFrame().
uint VideoBuffers::ValidVideoFrames | ( | void | ) | const |
Definition at line 770 of file videobuffers.cpp.
Referenced by MythVideoOutput::ValidVideoFrames().
uint VideoBuffers::FreeVideoFrames | ( | void | ) | const |
Definition at line 775 of file videobuffers.cpp.
Referenced by MythVideoOutput::FreeVideoFrames().
bool VideoBuffers::EnoughFreeFrames | ( | void | ) | const |
Definition at line 780 of file videobuffers.cpp.
Referenced by MythVideoOutput::EnoughFreeFrames().
bool VideoBuffers::EnoughDecodedFrames | ( | void | ) | const |
Definition at line 785 of file videobuffers.cpp.
Referenced by MythVideoOutput::EnoughDecodedFrames().
const MythVideoFrame * VideoBuffers::At | ( | uint | FrameNum | ) | const |
Definition at line 634 of file videobuffers.cpp.
const MythVideoFrame * VideoBuffers::GetLastDecodedFrame | ( | void | ) | const |
Definition at line 790 of file videobuffers.cpp.
const MythVideoFrame * VideoBuffers::GetLastShownFrame | ( | void | ) | const |
Definition at line 795 of file videobuffers.cpp.
uint VideoBuffers::Size | ( | void | ) | const |
Definition at line 800 of file videobuffers.cpp.
Referenced by ClearAfterSeek(), CreateBuffers(), DiscardAndRecreate(), DiscardFrames(), DiscardPauseFrames(), EnoughDecodedFrames(), EnoughFreeFrames(), FreeVideoFrames(), GetStatus(), and ValidVideoFrames().
QString VideoBuffers::GetStatus | ( | uint | Num = 0 | ) | const |
Definition at line 1012 of file videobuffers.cpp.
Referenced by DiscardAndRecreate(), MythVideoOutputGPU::DiscardFrames(), DiscardFrames(), MythVideoOutput::GetFrameStatus(), and GetNextFreeFrameInternal().
|
private |
Definition at line 587 of file videobuffers.cpp.
Referenced by BeginLock(), Contains(), Dequeue(), End(), Enqueue(), Head(), Size(), and Tail().
|
private |
Definition at line 608 of file videobuffers.cpp.
|
private |
Definition at line 288 of file videobuffers.cpp.
Referenced by GetNextFreeFrame().
|
staticprivate |
Set the appropriate flags for single and double rate deinterlacing.
Definition at line 215 of file videobuffers.cpp.
Referenced by ReinitBuffer(), and SetDeinterlacing().
|
private |
Definition at line 103 of file videobuffers.h.
Referenced by BeginLock(), ClearAfterSeek(), DiscardAndRecreate(), DiscardFrames(), End(), GetNextFreeFrame(), GetNextFreeFrameInternal(), GetStatus(), Queue(), Remove(), and Reset().
|
private |
Definition at line 104 of file videobuffers.h.
Referenced by ClearAfterSeek(), DiscardAndRecreate(), DiscardFrames(), DoneDisplayingFrame(), GetNextFreeFrame(), GetNextFreeFrameInternal(), GetStatus(), Queue(), ReleaseFrame(), Remove(), Reset(), and StartDisplayingFrame().
|
private |
Definition at line 105 of file videobuffers.h.
Referenced by DeLimboFrame(), DiscardAndRecreate(), DiscardFrames(), GetNextFreeFrame(), GetStatus(), Queue(), ReleaseFrame(), Remove(), and Reset().
|
private |
Definition at line 106 of file videobuffers.h.
Referenced by DiscardAndRecreate(), DiscardFrames(), GetNextFreeFrame(), GetStatus(), Queue(), Remove(), and Reset().
|
private |
Definition at line 107 of file videobuffers.h.
Referenced by DiscardAndRecreate(), DiscardFrames(), GetNextFreeFrame(), GetStatus(), Queue(), Remove(), and Reset().
|
private |
Definition at line 108 of file videobuffers.h.
Referenced by ClearAfterSeek(), DeLimboFrame(), DiscardAndRecreate(), DiscardFrames(), DoneDisplayingFrame(), GetNextFreeFrame(), GetNextFreeFrameInternal(), GetStatus(), Queue(), ReleaseFrame(), Remove(), and Reset().
|
private |
Definition at line 109 of file videobuffers.h.
Referenced by DiscardAndRecreate(), DiscardFrames(), DoneDisplayingFrame(), GetNextFreeFrame(), GetStatus(), Queue(), Remove(), and Reset().
|
private |
Definition at line 110 of file videobuffers.h.
Referenced by ClearAfterSeek(), Init(), ReleaseFrame(), Reset(), and StartDisplayingFrame().
|
private |
Definition at line 111 of file videobuffers.h.
Referenced by At(), CreateBuffers(), Init(), SetDeinterlacing(), and Size().
|
private |
Definition at line 112 of file videobuffers.h.
Referenced by CreateBuffers(), and DiscardAndRecreate().
|
private |
Definition at line 114 of file videobuffers.h.
Referenced by EnoughFreeFrames(), and Init().
|
private |
Definition at line 115 of file videobuffers.h.
Referenced by EnoughDecodedFrames(), Init(), and SetPrebuffering().
|
private |
Definition at line 116 of file videobuffers.h.
Referenced by Init(), and SetPrebuffering().
|
private |
Definition at line 117 of file videobuffers.h.
Referenced by Init(), and SetPrebuffering().
|
private |
Definition at line 118 of file videobuffers.h.
Referenced by ClearAfterSeek(), GetLastShownFrame(), and StartDisplayingFrame().
|
private |
Definition at line 119 of file videobuffers.h.
Referenced by ClearAfterSeek(), GetLastDecodedFrame(), and ReleaseFrame().
|
mutableprivate |
Definition at line 120 of file videobuffers.h.
Referenced by BeginLock(), ClearAfterSeek(), Contains(), DeLimboFrame(), Dequeue(), DiscardAndRecreate(), DiscardFrame(), DiscardFrames(), DiscardPauseFrames(), DoneDisplayingFrame(), End(), EndLock(), Enqueue(), GetNextFreeFrameInternal(), GetStatus(), Head(), Init(), Queue(), ReleaseFrame(), Remove(), Reset(), SafeEnqueue(), SetDeinterlacing(), SetPrebuffering(), Size(), StartDisplayingFrame(), and Tail().