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 
70  VideoFrame *At(uint FrameNum);
71  VideoFrame *Dequeue(BufferType Type);
72  VideoFrame *Head(BufferType Type);
73  VideoFrame *Tail(BufferType Type);
74  void Requeue(BufferType Dest, BufferType Source, int Count = 1);
75  void Enqueue(BufferType Type, VideoFrame* Frame);
76  void SafeEnqueue(BufferType Type, VideoFrame* Frame);
77  void Remove(BufferType Type, VideoFrame *Frame);
78  frame_queue_t::iterator BeginLock(BufferType Type);
80  void EndLock();
81  uint Size(BufferType Type) const;
82  bool Contains(BufferType Type, VideoFrame* Frame) const;
83 
84  VideoFrame *GetScratchFrame(void);
85  VideoFrame *GetLastDecodedFrame(void);
86  VideoFrame *GetLastShownFrame(void);
87  void SetLastShownFrameToScratch(void);
88 
89  uint ValidVideoFrames(void) const;
90  uint FreeVideoFrames(void) const;
91  bool EnoughFreeFrames(void) const;
92  bool EnoughDecodedFrames(void) const;
93 
94  const VideoFrame *At(uint FrameNum) const;
95  const VideoFrame *GetLastDecodedFrame(void) const;
96  const VideoFrame *GetLastShownFrame(void) const;
97  uint Size(void) const;
98  void Clear(uint FrameNum);
99  void Clear(void);
100  bool CreateBuffer(int Width, int Height, uint Number, void *Data, VideoFrameType Format);
101 
102  QString GetStatus(uint Num = 0) const;
103 
104  private:
105  frame_queue_t *Queue(BufferType Type);
106  const frame_queue_t *Queue(BufferType Type) const;
107  VideoFrame *GetNextFreeFrameInternal(BufferType EnqueueTo);
108  static void ReleaseDecoderResources(VideoFrame *Frame);
109  static void SetDeinterlacingFlags(VideoFrame &Frame, MythDeintType Single,
110  MythDeintType Double, MythCodecID CodecID);
111 
121 
122  uint m_needFreeFrames { 0 };
123  uint m_needPrebufferFrames { 0 };
124  uint m_needPrebufferFramesNormal { 0 };
125  uint m_needPrebufferFramesSmall { 0 };
126  bool m_createdPauseFrame { false };
127  uint m_rpos { 0 };
128  uint m_vpos { 0 };
129  mutable QMutex m_globalLock { QMutex::Recursive };
130 };
131 
132 #endif // __VIDEOBUFFERS_H__
BufferType
Definition: videobuffers.h:27
vbuffer_map_t m_vbufferMap
Definition: videobuffers.h:119
frame_queue_t m_limbo
Definition: videobuffers.h:114
typename deque< VideoFrame * >::iterator iterator
Definition: mythdeque.h:44
MythCodecID
Definition: mythcodecid.h:10
frame_queue_t m_used
Definition: videobuffers.h:113
VideoFrameType
Definition: mythframe.h:23
frame_queue_t m_decode
Definition: videobuffers.h:117
frame_queue_t m_available
Definition: videobuffers.h:112
MythDeintType
Definition: mythframe.h:120
frame_queue_t m_displayed
Definition: videobuffers.h:116
frame_vector_t m_buffers
Definition: videobuffers.h:120
#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:686
vector< VideoFrame > frame_vector_t
Definition: videobuffers.h:21
frame_queue_t m_finished
Definition: videobuffers.h:118
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:115
This class creates tracks the state of the buffers used by various VideoOutput derived classes.
Definition: videobuffers.h:39
#define Clear(a)