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 #include <QMutex>
7 #include <QString>
8 
9 // MythTV
10 #include "mythtvexp.h"
11 #include "mythframe.h"
12 #include "mythdeque.h"
13 #include "mythcodecid.h"
14 
15 // Std
16 #include <vector>
17 #include <map>
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 
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 QMutex m_globalLock { QMutex::Recursive };
121 };
122 
123 #endif // VIDEOBUFFERS_H
kVideoBuffer_avail
@ kVideoBuffer_avail
Definition: videobuffers.h:28
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:103
kVideoBuffer_decode
@ kVideoBuffer_decode
Definition: videobuffers.h:34
VideoBuffers
Definition: videobuffers.h:38
mythtvexp.h
Frame
Definition: zmdefines.h:93
VideoBuffers::m_limbo
frame_queue_t m_limbo
Definition: videobuffers.h:105
mythframe.h
kVideoBuffer_finished
@ kVideoBuffer_finished
Definition: videobuffers.h:33
mythdeque.h
VideoBuffers::m_pause
frame_queue_t m_pause
Definition: videobuffers.h:106
VideoBuffers::m_buffers
frame_vector_t m_buffers
Definition: videobuffers.h:111
MythCodecID
MythCodecID
Definition: mythcodecid.h:10
Decoder
Definition: decoder.h:65
VideoBuffers::m_displayed
frame_queue_t m_displayed
Definition: videobuffers.h:107
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
mythcodecid.h
kVideoBuffer_all
@ kVideoBuffer_all
Definition: videobuffers.h:35
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:29
kVideoBuffer_pause
@ kVideoBuffer_pause
Definition: videobuffers.h:31
kVideoBuffer_displayed
@ kVideoBuffer_displayed
Definition: videobuffers.h:32
MythDeintType
MythDeintType
Definition: mythframe.h:67
VideoBuffers::m_used
frame_queue_t m_used
Definition: videobuffers.h:104
kVideoBuffer_used
@ kVideoBuffer_used
Definition: videobuffers.h:30
MythDeque< MythVideoFrame * >
frame_vector_t
std::vector< MythVideoFrame > frame_vector_t
Definition: videobuffers.h:20
VideoFrameType
VideoFrameType
Definition: mythframe.h:20
MythVideoFrame
Definition: mythframe.h:88
VideoBuffers::m_decode
frame_queue_t m_decode
Definition: videobuffers.h:108
BufferType
BufferType
Definition: videobuffers.h:26
MythDeque< MythVideoFrame * >::iterator
typename deque< MythVideoFrame * >::iterator iterator
Definition: mythdeque.h:44