Go to the documentation of this file.
11 #include "libmythbase/mythconfig.h"
20 #include "libavcodec/avcodec.h"
42 auto* ref =
reinterpret_cast<AVBufferRef*
>(
Frame->m_priv[0]);
44 Discards.push_back(ref);
49 ref =
reinterpret_cast<AVBufferRef*
>(
Frame->m_priv[1]);
51 Discards.push_back(ref);
52 Frame->m_priv[1] =
nullptr;
57 static inline void DoDiscard(
const std::vector<AVBufferRef *> &Discards)
59 for (
auto * it : Discards)
138 uint refs =
static_cast<uint>(MaxReferenceFrames);
177 uint NeedPrebufferNormal,
uint NeedPrebufferSmall)
185 m_buffers.reserve(std::max(NumDecode, 128U));
187 for (
uint i = 0; i < NumDecode; i++)
195 for (
uint i = 0; i < NumDecode; i++)
221 Frame.m_deinterlaceSingle = Single;
222 Frame.m_deinterlaceDouble = Double;
227 Frame.m_deinterlaceAllowed = kSoftware | kShader | kDriver;
229 Frame.m_deinterlaceAllowed = kSoftware | kShader;
233 Frame.m_deinterlaceAllowed = kShader;
237 Frame.m_deinterlaceAllowed = kShader;
241 Frame.m_deinterlaceAllowed = kShader;
245 Frame.m_deinterlaceAllowed = kShader | kDriver;
249 Frame.m_deinterlaceAllowed = kDriver;
253 Frame.m_deinterlaceAllowed = kDriver;
257 Frame.m_deinterlaceAllowed = kSoftware | kShader;
305 LOG(VB_PLAYBACK, LOG_NOTICE,
306 QString(
"GetNextFreeFrame() served a busy frame %1. Dropping. %2")
322 for (
uint tries = 1;
true; tries++)
330 LOG(VB_GENERAL, LOG_ERR, QString(
"GetNextFreeFrame: "
331 "available:%1 used:%2 limbo:%3 pause:%4 displayed:%5 decode:%6 finished:%7")
335 LOG(VB_GENERAL, LOG_ERR,
336 QString(
"GetNextFreeFrame() unable to "
337 "lock frame %1 times. Discarding Frames.")
345 LOG(VB_PLAYBACK, LOG_NOTICE,
346 QString(
"GetNextFreeFrame() TryLock has "
347 "spun %1 times, this is a lot.").arg(tries));
368 if (
Frame->m_directRendering)
380 std::vector<AVBufferRef*> discards;
420 std::vector<AVBufferRef*> discards;
431 for (
auto & it : ula)
453 std::vector<AVBufferRef*> discards;
463 std::vector<AVBufferRef*> discards;
486 std::vector<AVBufferRef*> refs;
489 LOG(VB_PLAYBACK, LOG_INFO, QString(
"DiscardAndRecreate: %1").arg(
GetStatus()));
508 for (
auto & discard : discards)
521 LOG(VB_GENERAL, LOG_INFO,
522 QString(
"VideoBuffers::DiscardFrames(): %1 (%2) not "
523 "in available, pause, or displayed %3")
579 LOG(VB_PLAYBACK, LOG_INFO, QString(
"DiscardAndRecreate: %1").arg(
GetStatus()));
655 return queue->
head();
666 return queue->
tail();
681 Frame->m_pauseFrame =
true;
726 return queue->begin();
747 return queue->size();
811 std::vector<AVBufferRef*> refs;
813 LOG(VB_PLAYBACK, LOG_INFO, QString(
"VideoBuffers::DiscardFrames(%1): %2")
814 .arg(NextFrameIsKeyFrame).arg(
GetStatus()));
816 if (!NextFrameIsKeyFrame)
819 for (
auto & it : ula)
824 LOG(VB_PLAYBACK, LOG_INFO,
825 QString(
"VideoBuffers::DiscardFrames(%1): %2 -- done")
826 .arg(NextFrameIsKeyFrame).arg(
GetStatus()));
843 for (it = discards.begin(); it != discards.end(); ++it)
861 LOG(VB_GENERAL, LOG_DEBUG,
862 QString(
"VideoBuffers::DiscardFrames(): %1 (%2) not "
863 "in available, pause, or displayed %3")
880 LOG(VB_PLAYBACK, LOG_INFO,
881 QString(
"VideoBuffers::DiscardFrames(%1): %2 -- done")
882 .arg(NextFrameIsKeyFrame).arg(
GetStatus()));
898 std::vector<AVBufferRef*> discards;
942 uint NeedFree,
uint NeedprebufferNormal,
943 uint NeedPrebufferSmall,
int MaxReferenceFrames)
946 Init(
GetNumBuffers(Type, MaxReferenceFrames), NeedFree, NeedprebufferNormal, NeedPrebufferSmall);
960 LOG(VB_PLAYBACK, LOG_INFO, QString(
"Created %1 empty %2 (%3x%4) video buffers")
974 if (!success && (Width < 1 || Height < 1))
977 LOG(VB_PLAYBACK, LOG_INFO, QString(
"Created %1 %2 (%3x%4) video buffers")
983 int Width,
int Height)
990 LOG(VB_GENERAL, LOG_ERR,
"Cannot re-initialise a hardware buffer");
996 LOG(VB_PLAYBACK, LOG_INFO, QString(
"Reallocating frame %1 %2x%3->%4 %5x%6")
1003 Frame->ClearBufferToBlank();
1028 for (
uint i = 0; i < Num; i++)
1030 unsigned long long mask = 1ULL << i;
1033 tmp += (x & mask) ?
"a" :
"A";
1035 tmp += (x & mask) ?
"u" :
"U";
1037 tmp += (x & mask) ?
"d" :
"D";
1039 tmp += (x & mask) ?
"l" :
"L";
1041 tmp += (x & mask) ?
"p" :
"P";
1043 tmp += (x & mask) ?
"f" :
"F";
1044 if (0 ==
tmp.length())
1046 else if (1 ==
tmp.length())
1049 str +=
"(" +
tmp +
")";
1055 for (
uint i = 0; i < Num; i++)
1066 const std::array<const QString,DBG_STR_ARR_SIZE>
dbg_str_arr
1068 "A ",
" B ",
" C ",
" D ",
1069 " E ",
" F ",
" G ",
" H",
1070 "a ",
" b ",
" c ",
" d ",
1071 " e ",
" f ",
" g ",
" h",
1072 "0 ",
" 1 ",
" 2 ",
" 3 ",
1073 " 4 ",
" 5 ",
" 6 ",
" 7",
1074 "I ",
" J ",
" K ",
" L ",
1075 " M ",
" N ",
" O ",
" P",
1076 "i ",
" j ",
" k ",
" l ",
1077 " m ",
" n ",
" o ",
" p",
1081 "A",
"B",
"C",
"D",
"E",
"F",
"G",
"H",
1082 "a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
1083 "0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
1084 "I",
"J",
"K",
"L",
"M",
"N",
"O",
"P",
1085 "i",
"j",
"k",
"l",
"m",
"n",
"o",
"p",
1112 unsigned long long bitmap = 0;
1113 for (
auto *it : Queue)
1116 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 enqueue(T d)
Adds item to the back of the list. O(1).
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