Go to the documentation of this file.
10 #include "libmythbase/mythconfig.h"
19 #include "libavcodec/avcodec.h"
41 auto* ref =
reinterpret_cast<AVBufferRef*
>(
Frame->m_priv[0]);
43 Discards.push_back(ref);
48 ref =
reinterpret_cast<AVBufferRef*
>(
Frame->m_priv[1]);
50 Discards.push_back(ref);
51 Frame->m_priv[1] =
nullptr;
56 static inline void DoDiscard(
const std::vector<AVBufferRef *> &Discards)
58 for (
auto * it : Discards)
137 uint refs =
static_cast<uint>(MaxReferenceFrames);
176 uint NeedPrebufferNormal,
uint NeedPrebufferSmall)
184 m_buffers.reserve(std::max(NumDecode, 128U));
186 for (
uint i = 0; i < NumDecode; i++)
194 for (
uint i = 0; i < NumDecode; i++)
220 Frame.m_deinterlaceSingle = Single;
221 Frame.m_deinterlaceDouble = Double;
226 Frame.m_deinterlaceAllowed = kSoftware | kShader | kDriver;
228 Frame.m_deinterlaceAllowed = kSoftware | kShader;
232 Frame.m_deinterlaceAllowed = kShader;
236 Frame.m_deinterlaceAllowed = kShader;
240 Frame.m_deinterlaceAllowed = kShader;
244 Frame.m_deinterlaceAllowed = kShader | kDriver;
248 Frame.m_deinterlaceAllowed = kDriver;
252 Frame.m_deinterlaceAllowed = kDriver;
256 Frame.m_deinterlaceAllowed = kSoftware | kShader;
304 LOG(VB_PLAYBACK, LOG_NOTICE,
305 QString(
"GetNextFreeFrame() served a busy frame %1. Dropping. %2")
321 for (
uint tries = 1;
true; tries++)
329 LOG(VB_GENERAL, LOG_ERR, QString(
"GetNextFreeFrame: "
330 "available:%1 used:%2 limbo:%3 pause:%4 displayed:%5 decode:%6 finished:%7")
334 LOG(VB_GENERAL, LOG_ERR,
335 QString(
"GetNextFreeFrame() unable to "
336 "lock frame %1 times. Discarding Frames.")
344 LOG(VB_PLAYBACK, LOG_NOTICE,
345 QString(
"GetNextFreeFrame() TryLock has "
346 "spun %1 times, this is a lot.").arg(tries));
367 if (
Frame->m_directRendering)
379 std::vector<AVBufferRef*> discards;
419 std::vector<AVBufferRef*> discards;
430 for (
auto & it : ula)
452 std::vector<AVBufferRef*> discards;
462 std::vector<AVBufferRef*> discards;
485 std::vector<AVBufferRef*> refs;
488 LOG(VB_PLAYBACK, LOG_INFO, QString(
"DiscardAndRecreate: %1").arg(
GetStatus()));
507 for (
auto & discard : discards)
520 LOG(VB_GENERAL, LOG_INFO,
521 QString(
"VideoBuffers::DiscardFrames(): %1 (%2) not "
522 "in available, pause, or displayed %3")
578 LOG(VB_PLAYBACK, LOG_INFO, QString(
"DiscardAndRecreate: %1").arg(
GetStatus()));
654 return queue->
head();
665 return queue->
tail();
680 Frame->m_pauseFrame =
true;
725 return queue->begin();
746 return queue->size();
810 std::vector<AVBufferRef*> refs;
812 LOG(VB_PLAYBACK, LOG_INFO, QString(
"VideoBuffers::DiscardFrames(%1): %2")
813 .arg(NextFrameIsKeyFrame).arg(
GetStatus()));
815 if (!NextFrameIsKeyFrame)
818 for (
auto & it : ula)
823 LOG(VB_PLAYBACK, LOG_INFO,
824 QString(
"VideoBuffers::DiscardFrames(%1): %2 -- done")
825 .arg(NextFrameIsKeyFrame).arg(
GetStatus()));
842 for (it = discards.begin(); it != discards.end(); ++it)
860 LOG(VB_GENERAL, LOG_DEBUG,
861 QString(
"VideoBuffers::DiscardFrames(): %1 (%2) not "
862 "in available, pause, or displayed %3")
879 LOG(VB_PLAYBACK, LOG_INFO,
880 QString(
"VideoBuffers::DiscardFrames(%1): %2 -- done")
881 .arg(NextFrameIsKeyFrame).arg(
GetStatus()));
897 std::vector<AVBufferRef*> discards;
941 uint NeedFree,
uint NeedprebufferNormal,
942 uint NeedPrebufferSmall,
int MaxReferenceFrames)
945 Init(
GetNumBuffers(Type, MaxReferenceFrames), NeedFree, NeedprebufferNormal, NeedPrebufferSmall);
959 LOG(VB_PLAYBACK, LOG_INFO, QString(
"Created %1 empty %2 (%3x%4) video buffers")
973 if (!success && (Width < 1 || Height < 1))
976 LOG(VB_PLAYBACK, LOG_INFO, QString(
"Created %1 %2 (%3x%4) video buffers")
982 int Width,
int Height)
989 LOG(VB_GENERAL, LOG_ERR,
"Cannot re-initialise a hardware buffer");
995 LOG(VB_PLAYBACK, LOG_INFO, QString(
"Reallocating frame %1 %2x%3->%4 %5x%6")
1002 Frame->ClearBufferToBlank();
1027 for (
uint i = 0; i < Num; i++)
1029 unsigned long long mask = 1ULL << i;
1032 tmp += (x & mask) ?
"a" :
"A";
1034 tmp += (x & mask) ?
"u" :
"U";
1036 tmp += (x & mask) ?
"d" :
"D";
1038 tmp += (x & mask) ?
"l" :
"L";
1040 tmp += (x & mask) ?
"p" :
"P";
1042 tmp += (x & mask) ?
"f" :
"F";
1043 if (0 ==
tmp.length())
1045 else if (1 ==
tmp.length())
1048 str +=
"(" +
tmp +
")";
1054 for (
uint i = 0; i < Num; i++)
1065 const std::array<const QString,DBG_STR_ARR_SIZE>
dbg_str_arr
1067 "A ",
" B ",
" C ",
" D ",
1068 " E ",
" F ",
" G ",
" H",
1069 "a ",
" b ",
" c ",
" d ",
1070 " e ",
" f ",
" g ",
" h",
1071 "0 ",
" 1 ",
" 2 ",
" 3 ",
1072 " 4 ",
" 5 ",
" 6 ",
" 7",
1073 "I ",
" J ",
" K ",
" L ",
1074 " M ",
" N ",
" O ",
" P",
1075 "i ",
" j ",
" k ",
" l ",
1076 " m ",
" n ",
" o ",
" p",
1080 "A",
"B",
"C",
"D",
"E",
"F",
"G",
"H",
1081 "a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
1082 "0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
1083 "I",
"J",
"K",
"L",
"M",
"N",
"O",
"P",
1084 "i",
"j",
"k",
"l",
"m",
"n",
"o",
"p",
1111 unsigned long long bitmap = 0;
1112 for (
auto *it : Queue)
1115 bitmap |= 1ULL << shift;
void remove(T const item)
Removes any item from list. O(n).
uint ValidVideoFrames(void) const
static int DebugNum(const MythVideoFrame *Frame)
void ReleaseFrame(MythVideoFrame *Frame)
MythVideoFrame * Head(BufferType Type)
static bool codec_is_v4l2(MythCodecID id)
MythVideoFrame * Tail(BufferType Type)
frame_queue_t m_available
uint m_needPrebufferFrames
static bool HardwareFramesFormat(VideoFrameType Type)
static bool codec_is_nvdec(MythCodecID id)
void Remove(BufferType Type, MythVideoFrame *Frame)
MythVideoFrame * GetNextFreeFrame(BufferType EnqueueTo=kVideoBuffer_limbo)
Gets a frame from available buffers list.
uint m_needPrebufferFramesNormal
QRecursiveMutex m_globalLock
bool EnoughDecodedFrames(void) const
static bool codec_is_vaapi(MythCodecID id)
static bool codec_is_vtb(MythCodecID id)
void SetDeinterlacing(MythDeintType Single, MythDeintType Double, MythCodecID CodecID)
bool DiscardAndRecreate(MythCodecID CodecID, QSize VideoDim, int References)
Discard all buffers and recreate.
static bool codec_is_vaapi_dec(MythCodecID id)
MythVideoFrame * Dequeue(BufferType Type)
frame_queue_t::iterator End(BufferType Type)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
static void SetDeinterlacingFlags(MythVideoFrame &Frame, MythDeintType Single, MythDeintType Double, MythCodecID CodecID)
Set the appropriate flags for single and double rate deinterlacing.
static bool HardwareFormat(VideoFrameType Type)
static constexpr size_t DBG_STR_ARR_SIZE
T tail()
Returns item at tail of list. O(1).
std::map< const MythVideoFrame *, int > dbg_str
bool CreateBuffers(VideoFrameType Type, const VideoFrameTypes *RenderFormats, QSize Size, uint NeedFree, uint NeedprebufferNormal, uint NeedPrebufferSmall, int MaxReferenceFrames=16)
MythVideoFrame * GetNextFreeFrameInternal(BufferType EnqueueTo)
frame_queue_t m_displayed
static constexpr uint16_t TRY_LOCK_SPINS
typename std::deque< MythVideoFrame * >::iterator iterator
vbuffer_map_t m_vbufferMap
bool Contains(BufferType Type, MythVideoFrame *Frame) const
std::chrono::milliseconds m_timecode
std::vector< VideoFrameType > VideoFrameTypes
bool EnoughFreeFrames(void) const
const std::array< const std::string, 8 > formats
frame_queue_t * Queue(BufferType Type)
static bool codec_is_nvdec_dec(MythCodecID id)
void StartDisplayingFrame(void)
static void ReleaseDecoderResources(MythVideoFrame *Frame, std::vector< AVBufferRef * > &Discards)
Store AVBufferRef's for later disposal.
const std::array< const QString, DBG_STR_ARR_SIZE > dbg_str_arr
static constexpr std::chrono::milliseconds TRY_LOCK_SPIN_WAIT
frame_queue_t::iterator BeginLock(BufferType Type)
Lock the video buffers.
void DiscardPauseFrames(void)
MythVideoFrame * GetLastShownFrame(void)
void DiscardFrame(MythVideoFrame *Frame)
static QString FormatDescription(VideoFrameType Type)
static constexpr uint16_t TRY_LOCK_SPINS_BEFORE_WARNING
void Enqueue(BufferType Type, MythVideoFrame *Frame)
static bool codec_is_mmal(MythCodecID id)
MythVideoFrame * GetLastDecodedFrame(void)
void SetPrebuffering(bool Normal)
void ClearAfterSeek(void)
Clear used frames after seeking.
void DoneDisplayingFrame(MythVideoFrame *Frame)
static bool codec_is_mediacodec(MythCodecID id)
T head()
Returns item at head of list. O(1).
void SafeEnqueue(BufferType Type, MythVideoFrame *Frame)
static void DoDiscard(const std::vector< AVBufferRef * > &Discards)
uint FreeVideoFrames(void) const
const QString & DebugString(const MythVideoFrame *Frame, bool Short)
static bool ReinitBuffer(MythVideoFrame *Frame, VideoFrameType Type, MythCodecID CodecID, int Width, int Height)
static bool codec_is_drmprime(MythCodecID id)
static bool codec_is_vdpau(MythCodecID id)
bool contains(T const &item) const
Returns true if item is in list. O(n).
static unsigned long long to_bitmap(const frame_queue_t &Queue, int Num)
static const iso6937table * d
void DiscardFrames(bool NextFrameIsKeyFrame)
void DeLimboFrame(MythVideoFrame *Frame)
static bool codec_is_copyback(MythCodecID id)
T dequeue()
Removes item from front of list and returns a copy. O(1).
const std::array< const QString, DBG_STR_ARR_SIZE > dbg_str_arr_short
MythVideoFrame * At(uint FrameNum)
void Init(uint NumDecode, uint NeedFree, uint NeedprebufferNormal, uint NeedPrebufferSmall)
Creates buffers and sets various buffer management parameters.
QString GetStatus(uint Num=0) const
size_type count() const
Returns size of list. O(1).
static uint GetNumBuffers(int PixelFormat, int MaxReferenceFrames=16, bool Decoder=false)
uint m_needPrebufferFramesSmall
const VideoFrameTypes * m_renderFormats
void enqueue(const T &d)
Adds item to the back of the list. O(1).