MythTV  master
mythframe.h
Go to the documentation of this file.
1 #ifndef MYTHFRAME_H
2 #define MYTHFRAME_H
3 
4 // Qt
5 #include <QRect>
6 
7 // MythTV
8 #include "mythtvexp.h"
9 #include "mythaverror.h"
10 
11 // Std
12 #include <array>
13 #include <vector>
14 
15 #define MYTH_WIDTH_ALIGNMENT 64
16 #define MYTH_HEIGHT_ALIGNMENT 16
17 
19 {
20  FMT_NONE = -1,
21  // YV12 and variants
22  FMT_YV12 = 0,
28  // RGB variants
34  // YUV422P and variants
41  // YUV444P and variants
48  // Packed YUV
50  // NV12 and variants
54  // hardware formats
63 };
64 
66 {
67  DEINT_NONE = 0x0000,
68  DEINT_BASIC = 0x0001,
69  DEINT_MEDIUM = 0x0002,
70  DEINT_HIGH = 0x0004,
71  DEINT_CPU = 0x0010,
72  DEINT_SHADER = 0x0020,
73  DEINT_DRIVER = 0x0040,
74  DEINT_ALL = 0x0077
75 };
76 
77 inline MythDeintType operator| (MythDeintType a, MythDeintType b) { return static_cast<MythDeintType>(static_cast<int>(a) | static_cast<int>(b)); }
78 inline MythDeintType operator& (MythDeintType a, MythDeintType b) { return static_cast<MythDeintType>(static_cast<int>(a) & static_cast<int>(b)); }
79 inline MythDeintType operator~ (MythDeintType a) { return static_cast<MythDeintType>(~(static_cast<int>(a))); }
80 
81 using VideoFrameTypes = std::vector<VideoFrameType>;
82 using FramePitches = std::array<int,3>;
83 using FrameOffsets = std::array<int,3>;
84 
86 {
87  public:
88  static inline const VideoFrameTypes kDefaultRenderFormats { FMT_YV12 };
89 
90  MythVideoFrame() = default;
91  MythVideoFrame(VideoFrameType Type, int Width, int Height, const VideoFrameTypes* RenderFormats = nullptr);
92  MythVideoFrame(VideoFrameType Type, uint8_t* Buffer, size_t BufferSize,
93  int Width, int Height, const VideoFrameTypes* RenderFormats = nullptr,
94  int Alignment = MYTH_WIDTH_ALIGNMENT);
95  ~MythVideoFrame();
96 
97  void Init(VideoFrameType Type, int Width, int Height, const VideoFrameTypes* RenderFormats = nullptr);
98  void Init(VideoFrameType Type, uint8_t* Buffer, size_t BufferSize,
99  int Width, int Height, const VideoFrameTypes* RenderFormats = nullptr, int Alignment = MYTH_WIDTH_ALIGNMENT);
100  void ClearMetadata();
101  void ClearBufferToBlank();
102  bool CopyFrame(MythVideoFrame* From);
103  MythDeintType GetSingleRateOption(MythDeintType Type, MythDeintType Override = DEINT_NONE) const;
104  MythDeintType GetDoubleRateOption(MythDeintType Type, MythDeintType Override = DEINT_NONE) const;
105 
106  static void CopyPlane(uint8_t* To, int ToPitch, const uint8_t* From, int FromPitch,
107  int PlaneWidth, int PlaneHeight);
108  static QString FormatDescription(VideoFrameType Type);
109  static uint8_t* GetAlignedBuffer(size_t Size);
110  static uint8_t* CreateBuffer(VideoFrameType Type, int Width, int Height);
111  static size_t GetBufferSize(VideoFrameType Type, int Width, int Height, int Aligned = MYTH_WIDTH_ALIGNMENT);
112  static QString DeinterlacerPref(MythDeintType Deint);
113  static QString DeinterlacerName(MythDeintType Deint, bool DoubleRate, VideoFrameType Format = FMT_NONE);
114  static MythDeintType ParseDeinterlacer(const QString& Deinterlacer);
115 
117  uint8_t* m_buffer { nullptr };
118  int m_width { 0 };
119  int m_height { 0 };
120  int m_bitsPerPixel { 0 };
121  size_t m_bufferSize { 0 };
122 
123  // everthing below is considered metadata by ClearMetadata
124  float m_aspect { -1.0F };
125  double m_frameRate { -1.0 };
126  long long m_frameNumber { 0 };
127  uint64_t m_frameCounter { 0 };
128  long long m_timecode { 0 };
129  int64_t m_displayTimecode { 0 };
130  std::array<uint8_t*,4> m_priv { nullptr };
131  int m_interlaced { 0 };
132  bool m_topFieldFirst { true };
133  bool m_interlacedReverse { false };
134  bool m_newGOP { false };
135  bool m_repeatPic { false };
136  bool m_forceKey { false };
137  bool m_dummy { false };
138  bool m_pauseFrame { false };
139  FramePitches m_pitches { 0 };
140  FrameOffsets m_offsets { 0 };
141  int m_pixFmt { 0 };
142  int m_swPixFmt { 0 };
143  bool m_directRendering { true };
144  const VideoFrameTypes* m_renderFormats { &kDefaultRenderFormats };
145  int m_colorspace { 1 };
146  int m_colorrange { 1 };
147  int m_colorprimaries { 1 };
148  int m_colortransfer { 1 };
149  int m_chromalocation { 1 };
150  bool m_colorshifted { false };
151  bool m_alreadyDeinterlaced { false };
152  int m_rotation { 0 };
153  uint m_stereo3D { 0 };
154  MythDeintType m_deinterlaceSingle { DEINT_NONE };
155  MythDeintType m_deinterlaceDouble { DEINT_NONE };
156  MythDeintType m_deinterlaceAllowed { DEINT_NONE };
157  MythDeintType m_deinterlaceInuse { DEINT_NONE };
158  bool m_deinterlaceInuse2x { false };
159 
160  // Presentation details for 'pure' direct rendering methods (e.g. DRM)
161  // Experimental and may be removed.
162  QRect m_srcRect;
163  QRect m_dstRect;
164 
165  static inline int BitsPerPixel(VideoFrameType Type)
166  {
167  switch (Type)
168  {
169  case FMT_BGRA:
170  case FMT_RGBA32:
171  case FMT_ARGB32:
172  case FMT_RGB32:
173  case FMT_YUV422P9:
174  case FMT_YUV422P10:
175  case FMT_YUV422P12:
176  case FMT_YUV422P14:
177  case FMT_YUV422P16: return 32;
178  case FMT_RGB24: return 24;
179  case FMT_YUV422P:
180  case FMT_YUY2: return 16;
181  case FMT_YV12:
182  case FMT_NV12: return 12;
183  case FMT_YUV444P:
184  case FMT_P010:
185  case FMT_P016:
186  case FMT_YUV420P9:
187  case FMT_YUV420P10:
188  case FMT_YUV420P12:
189  case FMT_YUV420P14:
190  case FMT_YUV420P16: return 24;
191  case FMT_YUV444P9:
192  case FMT_YUV444P10:
193  case FMT_YUV444P12:
194  case FMT_YUV444P14:
195  case FMT_YUV444P16: return 48;
196  case FMT_NONE:
197  case FMT_VDPAU:
198  case FMT_VAAPI:
199  case FMT_DXVA2:
200  case FMT_MMAL:
201  case FMT_MEDIACODEC:
202  case FMT_NVDEC:
203  case FMT_DRMPRIME:
204  case FMT_VTB: break;
205  }
206  return 8;
207  }
208 
209  static inline uint GetNumPlanes(VideoFrameType Type)
210  {
211  switch (Type)
212  {
213  case FMT_YV12:
214  case FMT_YUV420P9:
215  case FMT_YUV420P10:
216  case FMT_YUV420P12:
217  case FMT_YUV420P14:
218  case FMT_YUV420P16:
219  case FMT_YUV422P:
220  case FMT_YUV422P9:
221  case FMT_YUV422P10:
222  case FMT_YUV422P12:
223  case FMT_YUV422P14:
224  case FMT_YUV422P16:
225  case FMT_YUV444P:
226  case FMT_YUV444P9:
227  case FMT_YUV444P10:
228  case FMT_YUV444P12:
229  case FMT_YUV444P14:
230  case FMT_YUV444P16: return 3;
231  case FMT_P010:
232  case FMT_P016:
233  case FMT_NV12: return 2;
234  case FMT_YUY2:
235  case FMT_BGRA:
236  case FMT_ARGB32:
237  case FMT_RGB24:
238  case FMT_RGB32:
239  case FMT_RGBA32: return 1;
240  case FMT_NONE:
241  case FMT_VDPAU:
242  case FMT_VAAPI:
243  case FMT_DXVA2:
244  case FMT_MEDIACODEC:
245  case FMT_NVDEC:
246  case FMT_MMAL:
247  case FMT_DRMPRIME:
248  case FMT_VTB: return 0;
249  }
250  return 0;
251  }
252 
253  static inline int GetHeightForPlane(VideoFrameType Type, int Height, uint Plane)
254  {
255  switch (Type)
256  {
257  case FMT_YV12:
258  case FMT_YUV420P9:
259  case FMT_YUV420P10:
260  case FMT_YUV420P12:
261  case FMT_YUV420P14:
262  case FMT_YUV420P16:
263  if (Plane == 0) return Height;
264  if (Plane < 3) return Height >> 1;
265  break;
266  case FMT_YUV422P:
267  case FMT_YUV422P9:
268  case FMT_YUV422P10:
269  case FMT_YUV422P12:
270  case FMT_YUV422P14:
271  case FMT_YUV422P16:
272  case FMT_YUV444P:
273  case FMT_YUV444P9:
274  case FMT_YUV444P10:
275  case FMT_YUV444P12:
276  case FMT_YUV444P14:
277  case FMT_YUV444P16:
278  if (Plane < 3) return Height;
279  break;
280  case FMT_NV12:
281  case FMT_P010:
282  case FMT_P016:
283  if (Plane == 0) return Height;
284  if (Plane < 2) return Height >> 1;
285  break;
286  case FMT_YUY2:
287  case FMT_RGB24:
288  case FMT_ARGB32:
289  case FMT_RGBA32:
290  case FMT_BGRA:
291  case FMT_RGB32:
292  if (Plane == 0) return Height;
293  break;
294  default: break; // None and hardware formats
295  }
296  return 0;
297  }
298 
299  static inline int GetPitchForPlane(VideoFrameType Type, int Width, uint Plane)
300  {
301  switch (Type)
302  {
303  case FMT_YV12:
304  case FMT_YUV422P:
305  if (Plane == 0) return Width;
306  if (Plane < 3) return (Width + 1) >> 1;
307  break;
308  case FMT_YUV420P9:
309  case FMT_YUV420P10:
310  case FMT_YUV420P12:
311  case FMT_YUV420P14:
312  case FMT_YUV420P16:
313  case FMT_YUV422P9:
314  case FMT_YUV422P10:
315  case FMT_YUV422P12:
316  case FMT_YUV422P14:
317  case FMT_YUV422P16:
318  if (Plane == 0) return Width << 1;
319  if (Plane < 3) return Width;
320  break;
321  case FMT_YUV444P:
322  case FMT_YUV444P9:
323  case FMT_YUV444P10:
324  case FMT_YUV444P12:
325  case FMT_YUV444P14:
326  case FMT_YUV444P16:
327  if (Plane < 3) return Width;
328  break;
329  case FMT_NV12:
330  if (Plane < 2) return Width;
331  break;
332  case FMT_P010:
333  case FMT_P016:
334  if (Plane < 2) return Width << 1;
335  break;
336  case FMT_YUY2:
337  case FMT_RGB24:
338  case FMT_ARGB32:
339  case FMT_RGBA32:
340  case FMT_BGRA:
341  case FMT_RGB32:
342  if (Plane == 0) return (MythVideoFrame::BitsPerPixel(Type) * Width) >> 3;
343  break;
344  default: break; // None and hardware formats
345  }
346  return 0;
347  }
348 
349  static inline int GetWidthForPlane(VideoFrameType Type, int Width, uint Plane)
350  {
351  switch (Type)
352  {
353  case FMT_YV12:
354  case FMT_YUV420P9:
355  case FMT_YUV420P10:
356  case FMT_YUV420P12:
357  case FMT_YUV420P14:
358  case FMT_YUV420P16:
359  case FMT_YUV422P:
360  case FMT_YUV422P9:
361  case FMT_YUV422P10:
362  case FMT_YUV422P12:
363  case FMT_YUV422P14:
364  case FMT_YUV422P16:
365  if (Plane == 0) return Width;
366  if (Plane < 3) return (Width + 1) >> 1;
367  break;
368  case FMT_YUV444P:
369  case FMT_YUV444P9:
370  case FMT_YUV444P10:
371  case FMT_YUV444P12:
372  case FMT_YUV444P14:
373  case FMT_YUV444P16:
374  if (Plane < 3) return Width;
375  break;
376  case FMT_NV12:
377  case FMT_P010:
378  case FMT_P016:
379  if (Plane < 2) return Width;
380  break;
381  case FMT_YUY2:
382  case FMT_RGB24:
383  case FMT_ARGB32:
384  case FMT_RGBA32:
385  case FMT_BGRA:
386  case FMT_RGB32:
387  if (Plane == 0) return Width;
388  break;
389  default: break; // None and hardware formats
390  }
391  return 0;
392  }
393 
394  static inline int ColorDepth(int Format)
395  {
396  switch (Format)
397  {
398  case FMT_YUV420P9:
399  case FMT_YUV422P9:
400  case FMT_YUV444P9: return 9;
401  case FMT_P010:
402  case FMT_YUV420P10:
403  case FMT_YUV422P10:
404  case FMT_YUV444P10: return 10;
405  case FMT_YUV420P12:
406  case FMT_YUV422P12:
407  case FMT_YUV444P12: return 12;
408  case FMT_YUV420P14:
409  case FMT_YUV422P14:
410  case FMT_YUV444P14: return 14;
411  case FMT_P016:
412  case FMT_YUV420P16:
413  case FMT_YUV422P16:
414  case FMT_YUV444P16: return 16;
415  default: break;
416  }
417  return 8;
418  }
419 
420  static inline bool HardwareFormat(VideoFrameType Type)
421  {
422  return (Type == FMT_VDPAU) || (Type == FMT_VAAPI) ||
423  (Type == FMT_DXVA2) || (Type == FMT_MMAL) ||
424  (Type == FMT_MEDIACODEC) || (Type == FMT_VTB) ||
425  (Type == FMT_NVDEC) || (Type == FMT_DRMPRIME);
426  }
427 
428  static inline bool HardwareFramesFormat(VideoFrameType Type)
429  {
430  return (Type == FMT_VDPAU) || (Type == FMT_VAAPI) || (Type == FMT_NVDEC);
431  }
432 
433  static inline bool FormatIs420(VideoFrameType Type)
434  {
435  return (Type == FMT_YV12) || (Type == FMT_YUV420P9) || (Type == FMT_YUV420P10) ||
436  (Type == FMT_YUV420P12) || (Type == FMT_YUV420P14) || (Type == FMT_YUV420P16);
437  }
438 
439  static inline bool FormatIs422(VideoFrameType Type)
440  {
441  return (Type == FMT_YUV422P) || (Type == FMT_YUV422P9) || (Type == FMT_YUV422P10) ||
442  (Type == FMT_YUV422P12) || (Type == FMT_YUV422P14) || (Type == FMT_YUV422P16);
443  }
444 
445  static inline bool FormatIs444(VideoFrameType Type)
446  {
447  return (Type == FMT_YUV444P) || (Type == FMT_YUV444P9) || (Type == FMT_YUV444P10) ||
448  (Type == FMT_YUV444P12) || (Type == FMT_YUV444P14) || (Type == FMT_YUV444P16);
449  }
450 
451  static inline bool FormatIsNV12(VideoFrameType Type)
452  {
453  return (Type == FMT_NV12) || (Type == FMT_P010) || (Type == FMT_P016);
454  }
455 
456  static inline bool PackedFormat(VideoFrameType Type)
457  {
458  return Type == FMT_YUY2;
459  }
460 
461  static inline bool YUVFormat(VideoFrameType Type)
462  {
463  return FormatIs420(Type) || FormatIs422(Type) || FormatIs444(Type) ||
464  FormatIsNV12(Type) || PackedFormat(Type);
465  }
466 
467  static inline bool FormatIsRGB(VideoFrameType Type)
468  {
469  return (FMT_RGB24 == Type) || (FMT_BGRA == Type) || (FMT_RGB32 == Type) ||
470  (FMT_ARGB32 == Type) || (FMT_RGBA32 == Type);
471  }
472 
473  private:
474  static MythDeintType GetDeinterlacer(MythDeintType Option);
475 };
476 
477 #endif
FMT_MEDIACODEC
@ FMT_MEDIACODEC
Definition: mythframe.h:59
DEINT_DRIVER
@ DEINT_DRIVER
Definition: mythframe.h:73
DEINT_MEDIUM
@ DEINT_MEDIUM
Definition: mythframe.h:69
FMT_YUV420P10
@ FMT_YUV420P10
Definition: mythframe.h:24
MythVideoFrame::GetPitchForPlane
static int GetPitchForPlane(VideoFrameType Type, int Width, uint Plane)
Definition: mythframe.h:299
FMT_YUV420P16
@ FMT_YUV420P16
Definition: mythframe.h:27
FMT_VTB
@ FMT_VTB
Definition: mythframe.h:60
DEINT_SHADER
@ DEINT_SHADER
Definition: mythframe.h:72
FMT_YUV420P14
@ FMT_YUV420P14
Definition: mythframe.h:26
MythVideoFrame::PackedFormat
static bool PackedFormat(VideoFrameType Type)
Definition: mythframe.h:456
MythVideoFrame::HardwareFramesFormat
static bool HardwareFramesFormat(VideoFrameType Type)
Definition: mythframe.h:428
FMT_DRMPRIME
@ FMT_DRMPRIME
Definition: mythframe.h:62
FMT_YUV444P10
@ FMT_YUV444P10
Definition: mythframe.h:44
FMT_YUV422P14
@ FMT_YUV422P14
Definition: mythframe.h:39
mythtvexp.h
operator|
MythDeintType operator|(MythDeintType a, MythDeintType b)
Definition: mythframe.h:77
FMT_P010
@ FMT_P010
Definition: mythframe.h:52
MythVideoFrame::FormatIsRGB
static bool FormatIsRGB(VideoFrameType Type)
Definition: mythframe.h:467
DEINT_NONE
@ DEINT_NONE
Definition: mythframe.h:67
operator~
MythDeintType operator~(MythDeintType a)
Definition: mythframe.h:79
FramePitches
std::array< int, 3 > FramePitches
Definition: mythframe.h:82
MythDate::Format
Format
Definition: mythdate.h:12
FMT_YUV422P
@ FMT_YUV422P
Definition: mythframe.h:35
MythVideoFrame::HardwareFormat
static bool HardwareFormat(VideoFrameType Type)
Definition: mythframe.h:420
DEINT_ALL
@ DEINT_ALL
Definition: mythframe.h:74
FrameOffsets
std::array< int, 3 > FrameOffsets
Definition: mythframe.h:83
MythVideoFrame::FormatIs422
static bool FormatIs422(VideoFrameType Type)
Definition: mythframe.h:439
FMT_YUV444P14
@ FMT_YUV444P14
Definition: mythframe.h:46
FMT_YUV444P
@ FMT_YUV444P
Definition: mythframe.h:42
FMT_NONE
@ FMT_NONE
Definition: mythframe.h:20
DEINT_CPU
@ DEINT_CPU
Definition: mythframe.h:71
MythVideoFrame::BitsPerPixel
static int BitsPerPixel(VideoFrameType Type)
Definition: mythframe.h:165
MythVideoFrame::YUVFormat
static bool YUVFormat(VideoFrameType Type)
Definition: mythframe.h:461
FMT_YUV444P9
@ FMT_YUV444P9
Definition: mythframe.h:43
FMT_YV12
@ FMT_YV12
Definition: mythframe.h:22
FMT_YUV422P10
@ FMT_YUV422P10
Definition: mythframe.h:37
FMT_YUV444P16
@ FMT_YUV444P16
Definition: mythframe.h:47
VideoFrameTypes
std::vector< VideoFrameType > VideoFrameTypes
Definition: mythframe.h:81
FMT_BGRA
@ FMT_BGRA
Definition: mythframe.h:30
FMT_YUV420P12
@ FMT_YUV420P12
Definition: mythframe.h:25
MYTH_WIDTH_ALIGNMENT
#define MYTH_WIDTH_ALIGNMENT
Definition: mythframe.h:15
MythVideoFrame::ColorDepth
static int ColorDepth(int Format)
Definition: mythframe.h:394
MythVideoFrame::GetWidthForPlane
static int GetWidthForPlane(VideoFrameType Type, int Width, uint Plane)
Definition: mythframe.h:349
uint
unsigned int uint
Definition: compat.h:141
operator&
MythDeintType operator&(MythDeintType a, MythDeintType b)
Definition: mythframe.h:78
FMT_YUV444P12
@ FMT_YUV444P12
Definition: mythframe.h:45
MythVideoFrame::FormatIs444
static bool FormatIs444(VideoFrameType Type)
Definition: mythframe.h:445
FMT_ARGB32
@ FMT_ARGB32
Definition: mythframe.h:32
MTV_PUBLIC
#define MTV_PUBLIC
Definition: mythtvexp.h:15
FMT_NVDEC
@ FMT_NVDEC
Definition: mythframe.h:61
MythVideoFrame::FormatIs420
static bool FormatIs420(VideoFrameType Type)
Definition: mythframe.h:433
MythVideoFrame::GetHeightForPlane
static int GetHeightForPlane(VideoFrameType Type, int Height, uint Plane)
Definition: mythframe.h:253
FMT_YUV422P9
@ FMT_YUV422P9
Definition: mythframe.h:36
MythDeintType
MythDeintType
Definition: mythframe.h:65
Buffer
Definition: MythExternControl.h:36
FMT_YUV420P9
@ FMT_YUV420P9
Definition: mythframe.h:23
FMT_VDPAU
@ FMT_VDPAU
Definition: mythframe.h:55
FMT_YUV422P16
@ FMT_YUV422P16
Definition: mythframe.h:40
FMT_YUY2
@ FMT_YUY2
Definition: mythframe.h:49
FMT_DXVA2
@ FMT_DXVA2
Definition: mythframe.h:57
FMT_RGB24
@ FMT_RGB24
Definition: mythframe.h:29
FMT_YUV422P12
@ FMT_YUV422P12
Definition: mythframe.h:38
DEINT_HIGH
@ DEINT_HIGH
Definition: mythframe.h:70
MythVideoFrame::GetNumPlanes
static uint GetNumPlanes(VideoFrameType Type)
Definition: mythframe.h:209
MythVideoFrame::m_dstRect
QRect m_dstRect
Definition: mythframe.h:163
MythVideoFrame::m_srcRect
QRect m_srcRect
Definition: mythframe.h:162
FMT_RGB32
@ FMT_RGB32
endian dependent format, ARGB or BGRA
Definition: mythframe.h:31
FMT_MMAL
@ FMT_MMAL
Definition: mythframe.h:58
VideoFrameType
VideoFrameType
Definition: mythframe.h:18
FMT_VAAPI
@ FMT_VAAPI
Definition: mythframe.h:56
MythVideoFrame
Definition: mythframe.h:85
FMT_NV12
@ FMT_NV12
Definition: mythframe.h:51
DEINT_BASIC
@ DEINT_BASIC
Definition: mythframe.h:68
FMT_P016
@ FMT_P016
Definition: mythframe.h:53
MythVideoFrame::FormatIsNV12
static bool FormatIsNV12(VideoFrameType Type)
Definition: mythframe.h:451
mythaverror.h
FMT_RGBA32
@ FMT_RGBA32
Definition: mythframe.h:33