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
kVideoBuffer_avail
@ kVideoBuffer_avail
Definition: videobuffers.h:29
VideoBuffers::VideoBuffers
VideoBuffers()=default
VideoBuffers::m_available
frame_queue_t m_available
Definition: videobuffers.h:113
kVideoBuffer_decode
@ kVideoBuffer_decode
Definition: videobuffers.h:35
VideoBuffers
This class creates tracks the state of the buffers used by various VideoOutput derived classes.
Definition: videobuffers.h:40
mythtvexp.h
Frame
Definition: zmdefines.h:94
VideoBuffers::m_limbo
frame_queue_t m_limbo
Definition: videobuffers.h:115
MythDate::Format
Format
Definition: mythdate.h:13
mythframe.h
kVideoBuffer_finished
@ kVideoBuffer_finished
Definition: videobuffers.h:34
VideoFrame
Definition: mythframe.h:135
mythdeque.h
VideoBuffers::m_pause
frame_queue_t m_pause
Definition: videobuffers.h:116
VideoBuffers::m_buffers
frame_vector_t m_buffers
Definition: videobuffers.h:121
MythCodecID
MythCodecID
Definition: mythcodecid.h:11
Decoder
Definition: decoder.h:66
VideoBuffers::m_displayed
frame_queue_t m_displayed
Definition: videobuffers.h:117
Source
Definition: channelsettings.cpp:69
VideoBuffers::m_vbufferMap
vbuffer_map_t m_vbufferMap
Definition: videobuffers.h:120
VideoBuffers::m_finished
frame_queue_t m_finished
Definition: videobuffers.h:119
mythcodecid.h
kVideoBuffer_all
@ kVideoBuffer_all
Definition: videobuffers.h:36
uint
unsigned int uint
Definition: compat.h:140
Enqueue
#define Enqueue(a, b, c)
Definition: audiooutputopensles.cpp:48
vbuffer_map_t
map< const VideoFrame *, uint > vbuffer_map_t
Definition: videobuffers.h:22
MTV_PUBLIC
#define MTV_PUBLIC
Definition: mythtvexp.h:15
DebugString
const QString & DebugString(const VideoFrame *Frame, bool Short=false)
Definition: videobuffers.cpp:1205
kVideoBuffer_limbo
@ kVideoBuffer_limbo
Definition: videobuffers.h:30
kVideoBuffer_pause
@ kVideoBuffer_pause
Definition: videobuffers.h:32
kVideoBuffer_displayed
@ kVideoBuffer_displayed
Definition: videobuffers.h:33
MythDeintType
MythDeintType
Definition: mythframe.h:116
VideoBuffers::m_used
frame_queue_t m_used
Definition: videobuffers.h:114
kVideoBuffer_used
@ kVideoBuffer_used
Definition: videobuffers.h:31
Clear
#define Clear(a)
Definition: audiooutputopensles.cpp:49
MythDeque< VideoFrame * >
CreateBuffer
static unsigned char * CreateBuffer(VideoFrameType Type, int Width, int Height)
Definition: mythframe.h:693
VideoFrameType
VideoFrameType
Definition: mythframe.h:19
frame_vector_t
vector< VideoFrame > frame_vector_t
Definition: videobuffers.h:21
VideoBuffers::m_decode
frame_queue_t m_decode
Definition: videobuffers.h:118
BufferType
BufferType
Definition: videobuffers.h:28
MythDeque< VideoFrame * >::iterator
typename deque< VideoFrame * >::iterator iterator
Definition: mythdeque.h:44