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 using namespace std;
19 
21 using frame_vector_t = vector<VideoFrame>;
22 using vbuffer_map_t = map<const VideoFrame*, uint>;
23 
24 const QString& DebugString(const VideoFrame *Frame, bool Short = false);
25 const QString& DebugString(uint FrameNum, bool Short = false);
26 
28 {
29  kVideoBuffer_avail = 0x00000001,
30  kVideoBuffer_limbo = 0x00000002,
31  kVideoBuffer_used = 0x00000004,
32  kVideoBuffer_pause = 0x00000008,
33  kVideoBuffer_displayed = 0x00000010,
34  kVideoBuffer_finished = 0x00000020,
35  kVideoBuffer_decode = 0x00000040,
36  kVideoBuffer_all = 0x0000003F,
37 };
38 
40 {
41  public:
42  VideoBuffers() = default;
43  virtual ~VideoBuffers();
44 
45  static uint GetNumBuffers(int PixelFormat, int MaxReferenceFrames = 16, bool Decoder = false);
46  void Init(uint NumDecode, bool ExtraForPause,
47  uint NeedFree, uint NeedprebufferNormal,
48  uint NeedPrebufferSmall);
49  bool CreateBuffers(VideoFrameType Type, QSize Size, bool ExtraForPause,
50  uint NeedFree, uint NeedprebufferNormal,
51  uint NeedPrebufferSmall, int MaxReferenceFrames = 16);
52  bool CreateBuffers(VideoFrameType Type, int Width, int Height);
53  static bool ReinitBuffer(VideoFrame *Frame, VideoFrameType Type, MythCodecID CodecID, int Width, int Height);
54  void DeleteBuffers(void);
55  void SetDeinterlacing(MythDeintType Single, MythDeintType Double, MythCodecID CodecID);
56 
57  void Reset(void);
58  void DiscardFrames(bool NextFrameIsKeyFrame);
59  void ClearAfterSeek(void);
60 
61  void SetPrebuffering(bool Normal);
62 
63  VideoFrame *GetNextFreeFrame(BufferType EnqueueTo = kVideoBuffer_limbo);
64  void ReleaseFrame(VideoFrame *Frame);
65  void DeLimboFrame(VideoFrame *Frame);
66  void StartDisplayingFrame(void);
67  void DoneDisplayingFrame(VideoFrame *Frame);
68  void DiscardFrame(VideoFrame *Frame);
69  void DiscardPauseFrames(void);
70  bool DiscardAndRecreate(MythCodecID CodecID, QSize VideoDim, int References);
71 
72  VideoFrame *At(uint FrameNum);
73  VideoFrame *Dequeue(BufferType Type);
74  VideoFrame *Head(BufferType Type);
75  VideoFrame *Tail(BufferType Type);
76  void Requeue(BufferType Dest, BufferType Source, int Count = 1);
77  void Enqueue(BufferType Type, VideoFrame* Frame);
78  void SafeEnqueue(BufferType Type, VideoFrame* Frame);
79  void Remove(BufferType Type, VideoFrame *Frame);
80  frame_queue_t::iterator BeginLock(BufferType Type);
82  void EndLock();
83  uint Size(BufferType Type) const;
84  bool Contains(BufferType Type, VideoFrame* Frame) const;
85 
86  VideoFrame *GetScratchFrame(void);
87  VideoFrame *GetLastDecodedFrame(void);
88  VideoFrame *GetLastShownFrame(void);
89  void SetLastShownFrameToScratch(void);
90 
91  uint ValidVideoFrames(void) const;
92  uint FreeVideoFrames(void) const;
93  bool EnoughFreeFrames(void) const;
94  bool EnoughDecodedFrames(void) const;
95 
96  const VideoFrame *At(uint FrameNum) const;
97  const VideoFrame *GetLastDecodedFrame(void) const;
98  const VideoFrame *GetLastShownFrame(void) const;
99  uint Size(void) const;
100  void Clear(uint FrameNum);
101  void Clear(void);
102  bool CreateBuffer(int Width, int Height, uint Number, void *Data, VideoFrameType Format);
103 
104  QString GetStatus(uint Num = 0) const;
105 
106  private:
107  frame_queue_t *Queue(BufferType Type);
108  const frame_queue_t *Queue(BufferType Type) const;
109  VideoFrame *GetNextFreeFrameInternal(BufferType EnqueueTo);
110  static void SetDeinterlacingFlags(VideoFrame &Frame, MythDeintType Single,
111  MythDeintType Double, MythCodecID CodecID);
112 
122 
123  uint m_needFreeFrames { 0 };
124  uint m_needPrebufferFrames { 0 };
125  uint m_needPrebufferFramesNormal { 0 };
126  uint m_needPrebufferFramesSmall { 0 };
127  bool m_createdPauseFrame { false };
128  uint m_rpos { 0 };
129  uint m_vpos { 0 };
130  mutable QMutex m_globalLock { QMutex::Recursive };
131 };
132 
133 #endif // VIDEOBUFFERS_H
BufferType
Definition: videobuffers.h:27
vbuffer_map_t m_vbufferMap
Definition: videobuffers.h:120
frame_queue_t m_limbo
Definition: videobuffers.h:115
typename deque< VideoFrame * >::iterator iterator
Definition: mythdeque.h:44
MythCodecID
Definition: mythcodecid.h:10
frame_queue_t m_used
Definition: videobuffers.h:114
VideoFrameType
Definition: mythframe.h:23
frame_queue_t m_decode
Definition: videobuffers.h:118
frame_queue_t m_available
Definition: videobuffers.h:113
MythDeintType
Definition: mythframe.h:120
frame_queue_t m_displayed
Definition: videobuffers.h:117
frame_vector_t m_buffers
Definition: videobuffers.h:121
#define MTV_PUBLIC
Definition: mythtvexp.h:15
unsigned int uint
Definition: compat.h:140
static unsigned char * CreateBuffer(VideoFrameType Type, int Width, int Height)
Definition: mythframe.h:688
vector< VideoFrame > frame_vector_t
Definition: videobuffers.h:21
frame_queue_t m_finished
Definition: videobuffers.h:119
map< const VideoFrame *, uint > vbuffer_map_t
Definition: videobuffers.h:22
#define Enqueue(a, b, c)
const QString & DebugString(const VideoFrame *Frame, bool Short=false)
frame_queue_t m_pause
Definition: videobuffers.h:116
This class creates tracks the state of the buffers used by various VideoOutput derived classes.
Definition: videobuffers.h:39
#define Clear(a)