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