MythTV  master
videobuffers.h
Go to the documentation of this file.
1 #ifndef VIDEOBUFFERS_H
2 #define VIDEOBUFFERS_H
3 
4 // Qt
5 #include <QSize>
6 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
7 #include <QMutex>
8 #else
9 #include <QRecursiveMutex>
10 #endif
11 #include <QString>
12 
13 // MythTV
14 #include "mythtvexp.h"
15 #include "mythframe.h"
16 #include "mythdeque.h"
17 #include "mythcodecid.h"
18 
19 // Std
20 #include <vector>
21 #include <map>
22 
24 using frame_vector_t = std::vector<MythVideoFrame>;
25 using vbuffer_map_t = std::map<const MythVideoFrame*, uint>;
26 
27 const QString& DebugString(const MythVideoFrame *Frame, bool Short = false);
28 const QString& DebugString(uint FrameNum, bool Short = false);
29 
31 {
32  kVideoBuffer_avail = 0x00000001,
33  kVideoBuffer_limbo = 0x00000002,
34  kVideoBuffer_used = 0x00000004,
35  kVideoBuffer_pause = 0x00000008,
36  kVideoBuffer_displayed = 0x00000010,
37  kVideoBuffer_finished = 0x00000020,
38  kVideoBuffer_decode = 0x00000040,
39  kVideoBuffer_all = 0x0000003F,
40 };
41 
43 {
44  public:
45  VideoBuffers() = default;
46  ~VideoBuffers() = default;
47 
48  static uint GetNumBuffers(int PixelFormat, int MaxReferenceFrames = 16, bool Decoder = false);
49  void Init(uint NumDecode,
50  uint NeedFree, uint NeedprebufferNormal,
51  uint NeedPrebufferSmall);
52  bool CreateBuffers(VideoFrameType Type, const VideoFrameTypes* RenderFormats, QSize Size,
53  uint NeedFree, uint NeedprebufferNormal,
54  uint NeedPrebufferSmall, int MaxReferenceFrames = 16);
55  bool CreateBuffers(VideoFrameType Type, int Width, int Height, const VideoFrameTypes* RenderFormats);
56  static bool ReinitBuffer(MythVideoFrame *Frame, VideoFrameType Type, MythCodecID CodecID, int Width, int Height);
57  void SetDeinterlacing(MythDeintType Single, MythDeintType Double, MythCodecID CodecID);
58 
59  void Reset(void);
60  void DiscardFrames(bool NextFrameIsKeyFrame);
61  void ClearAfterSeek(void);
62 
63  void SetPrebuffering(bool Normal);
64  MythVideoFrame *GetNextFreeFrame(BufferType EnqueueTo = kVideoBuffer_limbo);
65  void ReleaseFrame(MythVideoFrame *Frame);
66  void DeLimboFrame(MythVideoFrame *Frame);
67  void StartDisplayingFrame(void);
68  void DoneDisplayingFrame(MythVideoFrame *Frame);
69  void DiscardFrame(MythVideoFrame *Frame);
70  void DiscardPauseFrames(void);
71  bool DiscardAndRecreate(MythCodecID CodecID, QSize VideoDim, int References);
72 
73  MythVideoFrame *At(uint FrameNum);
74  MythVideoFrame *Dequeue(BufferType Type);
75  MythVideoFrame *Head(BufferType Type);
76  MythVideoFrame *Tail(BufferType Type);
78  void SafeEnqueue(BufferType Type, MythVideoFrame* Frame);
79  void Remove(BufferType Type, MythVideoFrame *Frame);
80  frame_queue_t::iterator BeginLock(BufferType Type);
82  void EndLock();
83  uint Size(BufferType Type) const;
84  bool Contains(BufferType Type, MythVideoFrame* Frame) const;
85  MythVideoFrame *GetLastDecodedFrame(void);
86  MythVideoFrame *GetLastShownFrame(void);
87 
88  uint ValidVideoFrames(void) const;
89  uint FreeVideoFrames(void) const;
90  bool EnoughFreeFrames(void) const;
91  bool EnoughDecodedFrames(void) const;
92 
93  const MythVideoFrame *At(uint FrameNum) const;
94  const MythVideoFrame *GetLastDecodedFrame(void) const;
95  const MythVideoFrame *GetLastShownFrame(void) const;
96  uint Size(void) const;
97 
98  QString GetStatus(uint Num = 0) const;
99 
100  private:
101  frame_queue_t *Queue(BufferType Type);
102  const frame_queue_t *Queue(BufferType Type) const;
103  MythVideoFrame *GetNextFreeFrameInternal(BufferType EnqueueTo);
104  static void SetDeinterlacingFlags(MythVideoFrame &Frame, MythDeintType Single,
105  MythDeintType Double, MythCodecID CodecID);
106 
116  const VideoFrameTypes* m_renderFormats { nullptr };
117 
118  uint m_needFreeFrames { 0 };
119  uint m_needPrebufferFrames { 0 };
120  uint m_needPrebufferFramesNormal { 0 };
121  uint m_needPrebufferFramesSmall { 0 };
122  uint m_rpos { 0 };
123  uint m_vpos { 0 };
124 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
125  mutable QMutex m_globalLock { QMutex::Recursive };
126 #else
127  mutable QRecursiveMutex m_globalLock;
128 #endif
129 };
130 
131 #endif // VIDEOBUFFERS_H
kVideoBuffer_avail
@ kVideoBuffer_avail
Definition: videobuffers.h:32
DebugString
const QString & DebugString(const MythVideoFrame *Frame, bool Short=false)
Definition: videobuffers.cpp:1097
VideoBuffers::m_available
frame_queue_t m_available
Definition: videobuffers.h:107
kVideoBuffer_decode
@ kVideoBuffer_decode
Definition: videobuffers.h:38
VideoBuffers
Definition: videobuffers.h:42
VideoBuffers::m_globalLock
QRecursiveMutex m_globalLock
Definition: videobuffers.h:127
mythtvexp.h
Frame
Definition: zmdefines.h:93
VideoBuffers::m_limbo
frame_queue_t m_limbo
Definition: videobuffers.h:109
mythframe.h
kVideoBuffer_finished
@ kVideoBuffer_finished
Definition: videobuffers.h:37
mythdeque.h
VideoBuffers::m_pause
frame_queue_t m_pause
Definition: videobuffers.h:110
VideoBuffers::m_buffers
frame_vector_t m_buffers
Definition: videobuffers.h:115
MythCodecID
MythCodecID
Definition: mythcodecid.h:10
Decoder
Definition: decoder.h:70
VideoBuffers::m_displayed
frame_queue_t m_displayed
Definition: videobuffers.h:111
VideoBuffers::m_vbufferMap
vbuffer_map_t m_vbufferMap
Definition: videobuffers.h:114
VideoFrameTypes
std::vector< VideoFrameType > VideoFrameTypes
Definition: mythframe.h:83
VideoBuffers::m_finished
frame_queue_t m_finished
Definition: videobuffers.h:113
vbuffer_map_t
std::map< const MythVideoFrame *, uint > vbuffer_map_t
Definition: videobuffers.h:25
mythcodecid.h
kVideoBuffer_all
@ kVideoBuffer_all
Definition: videobuffers.h:39
uint
unsigned int uint
Definition: compat.h:140
Enqueue
#define Enqueue(a, b, c)
Definition: audiooutputopensles.cpp:46
MTV_PUBLIC
#define MTV_PUBLIC
Definition: mythtvexp.h:15
kVideoBuffer_limbo
@ kVideoBuffer_limbo
Definition: videobuffers.h:33
kVideoBuffer_pause
@ kVideoBuffer_pause
Definition: videobuffers.h:35
kVideoBuffer_displayed
@ kVideoBuffer_displayed
Definition: videobuffers.h:36
MythDeintType
MythDeintType
Definition: mythframe.h:67
VideoBuffers::m_used
frame_queue_t m_used
Definition: videobuffers.h:108
kVideoBuffer_used
@ kVideoBuffer_used
Definition: videobuffers.h:34
MythDeque< MythVideoFrame * >
frame_vector_t
std::vector< MythVideoFrame > frame_vector_t
Definition: videobuffers.h:24
VideoFrameType
VideoFrameType
Definition: mythframe.h:20
MythVideoFrame
Definition: mythframe.h:88
VideoBuffers::m_decode
frame_queue_t m_decode
Definition: videobuffers.h:112
BufferType
BufferType
Definition: videobuffers.h:30
MythDeque< MythVideoFrame * >::iterator
typename deque< MythVideoFrame * >::iterator iterator
Definition: mythdeque.h:44