MythTV  master
mythvdpauhelper.h
Go to the documentation of this file.
1 #ifndef MYTHVDPAUHELPER_H
2 #define MYTHVDPAUHELPER_H
3 
4 #include <vector>
5 
6 // Qt
7 #include <QSize>
8 #include <QMutex>
9 #include <QFlags>
10 
11 // MythTV
12 #include "mythframe.h"
13 #include "mythcodeccontext.h"
14 #include "videoouttypes.h"
15 
16 // FFmpeg
17 extern "C" {
18 #define Cursor XCursor // Prevent conflicts with Qt6.
19 #define pointer Xpointer // Prevent conflicts with Qt6.
20 #if defined(_X11_XLIB_H_) && !defined(Bool)
21 #define Bool int
22 #endif
23 #include "libavutil/hwcontext_vdpau.h"
24 #include "vdpau/vdpau_x11.h"
25 #undef None // X11/X.h defines this. Causes compile failure in Qt6.
26 #undef Cursor
27 #undef pointer
28 #undef Bool // Interferes with cmake moc file compilation
29 #undef True // Interferes with cmake moc file compilation
30 #undef False // Interferes with cmake moc file compilation
31 #undef Always // X11/X.h defines this. Causes compile failure in Qt6.
32 #include "libavcodec/avcodec.h"
33 }
34 
35 class MythXDisplay;
37 
39 {
40  public:
41  VDPAUCodec(MythCodecContext::CodecProfile Profile, QSize Size,
42  uint32_t Macroblocks, uint32_t Level);
43  bool Supported(int Width, int Height, int Level) const;
44  QSize m_maxSize { 0, 0 };
45  uint32_t m_maxMacroBlocks { 0 };
46  uint32_t m_maxLevel { 0 };
47 };
48 
49 using VDPAUProfile = QPair<MythCodecContext::CodecProfile, VDPAUCodec>;
50 using VDPAUProfiles = std::vector<VDPAUProfile>;
51 
52 class MythVDPAUHelper : public QObject
53 {
54  Q_OBJECT
55 
56  public:
58  {
59  VDPMixerNone = 0x00,
62  };
63 
64  Q_DECLARE_FLAGS(VDPMixerFeatures, VDPMixerFeature)
65 
66  static bool HaveVDPAU(bool Reinit = false);
67  static bool CheckH264Decode(AVCodecContext *Context);
68  static const VDPAUProfiles& GetProfiles(void);
69  static void GetDecoderList (QStringList &Decoders);
70 
71  explicit MythVDPAUHelper(AVVDPAUDeviceContext *Context);
72  ~MythVDPAUHelper(void) override;
73 
74  bool IsValid(void) const;
75  void SetPreempted(void);
76  bool IsFeatureAvailable(uint Feature);
77  bool IsAttributeAvailable(uint Attribute);
78  VdpOutputSurface CreateOutputSurface(QSize Size);
79  VdpVideoMixer CreateMixer(QSize Size, VdpChromaType ChromaType = VDP_CHROMA_TYPE_420,
80  MythDeintType Deinterlacer = DEINT_BASIC);
81  void MixerRender(VdpVideoMixer Mixer, VdpVideoSurface Source, VdpOutputSurface Dest,
82  FrameScanType Scan, int TopFieldFirst, QVector<AVBufferRef*>& Frames);
83  void SetCSCMatrix(VdpVideoMixer Mixer, MythVideoColourSpace *ColourSpace);
84  void DeleteOutputSurface(VdpOutputSurface Surface);
85  void DeleteMixer(VdpVideoMixer Mixer);
86  QSize GetSurfaceParameters(VdpVideoSurface Surface, VdpChromaType &Chroma);
87 
88  signals:
89  void DisplayPreempted(void);
90 
91  protected:
92  MythVDPAUHelper(void);
93 
94  bool H264DecodeCheck (VdpDecoderProfile Profile, AVCodecContext *Context);
95  bool HEVCSupported (void);
96  bool ProfileCheck (VdpDecoderProfile Profile, uint32_t &Level,
97  uint32_t &Macros, uint32_t &Width, uint32_t &Height);
98 
99  private:
100  bool InitProcs(void);
101 
102  private:
103  bool m_valid { false };
104  bool m_createdDevice { false };
105  VdpDevice m_device { 0 };
106  MythXDisplay *m_display { nullptr };
107 
108  VdpGetProcAddress *m_vdpGetProcAddress { nullptr };
109  VdpGetErrorString *m_vdpGetErrorString { nullptr };
110  VdpGetInformationString *m_vdpGetInformationString { nullptr };
111  VdpDeviceDestroy *m_vdpDeviceDestroy { nullptr };
112  VdpDecoderQueryCapabilities *m_vdpDecoderQueryCapabilities { nullptr };
113  VdpDecoderCreate *m_vdpDecoderCreate { nullptr };
114  VdpDecoderDestroy *m_vdpDecoderDestroy { nullptr };
115  VdpVideoMixerCreate *m_vdpVideoMixerCreate { nullptr };
116  VdpVideoMixerDestroy *m_vdpVideoMixerDestroy { nullptr };
117  VdpVideoMixerRender *m_vdpVideoMixerRender { nullptr };
118  VdpVideoMixerSetAttributeValues *m_vdpVideoMixerSetAttributeValues { nullptr };
119  VdpVideoMixerSetFeatureEnables *m_vdpVideoMixerSetFeatureEnables { nullptr };
120  VdpVideoMixerQueryFeatureSupport *m_vdpVideoMixerQueryFeatureSupport { nullptr };
121  VdpVideoMixerQueryAttributeSupport *m_vdpVideoMixerQueryAttributeSupport { nullptr };
122  VdpOutputSurfaceCreate *m_vdpOutputSurfaceCreate { nullptr };
123  VdpOutputSurfaceDestroy *m_vdpOutputSurfaceDestroy { nullptr };
124  VdpVideoSurfaceGetParameters *m_vdpVideoSurfaceGetParameters { nullptr };
125  VdpPreemptionCallbackRegister *m_vdpPreemptionCallbackRegister { nullptr };
126 };
127 
128 #endif // MYTHVDPAUHELPER_H
MythVDPAUHelper::GetProfiles
static const VDPAUProfiles & GetProfiles(void)
Definition: mythvdpauhelper.cpp:122
MythVDPAUHelper::m_vdpVideoMixerQueryAttributeSupport
VdpVideoMixerQueryAttributeSupport * m_vdpVideoMixerQueryAttributeSupport
Definition: mythvdpauhelper.h:121
MythVDPAUHelper::~MythVDPAUHelper
~MythVDPAUHelper(void) override
Definition: mythvdpauhelper.cpp:279
MythVDPAUHelper::m_vdpVideoMixerQueryFeatureSupport
VdpVideoMixerQueryFeatureSupport * m_vdpVideoMixerQueryFeatureSupport
Definition: mythvdpauhelper.h:120
MythVDPAUHelper::m_vdpOutputSurfaceDestroy
VdpOutputSurfaceDestroy * m_vdpOutputSurfaceDestroy
Definition: mythvdpauhelper.h:123
MythVDPAUHelper::m_vdpDecoderQueryCapabilities
VdpDecoderQueryCapabilities * m_vdpDecoderQueryCapabilities
Definition: mythvdpauhelper.h:112
VDPAUCodec::m_maxSize
QSize m_maxSize
Definition: mythvdpauhelper.h:44
MythVDPAUHelper::SetCSCMatrix
void SetCSCMatrix(VdpVideoMixer Mixer, MythVideoColourSpace *ColourSpace)
Definition: mythvdpauhelper.cpp:551
VDPAUCodec::m_maxMacroBlocks
uint32_t m_maxMacroBlocks
Definition: mythvdpauhelper.h:45
VDPAUProfiles
std::vector< VDPAUProfile > VDPAUProfiles
Definition: mythvdpauhelper.h:50
VDPAUCodec::m_maxLevel
uint32_t m_maxLevel
Definition: mythvdpauhelper.h:46
MythCodecContext::CodecProfile
CodecProfile
Definition: mythcodeccontext.h:55
MythVDPAUHelper::m_vdpGetErrorString
VdpGetErrorString * m_vdpGetErrorString
Definition: mythvdpauhelper.h:109
MythVDPAUHelper::MythVDPAUHelper
MythVDPAUHelper(void)
Definition: mythvdpauhelper.cpp:256
MythVDPAUHelper::VDPMixerFeature
VDPMixerFeature
Definition: mythvdpauhelper.h:57
Surface
Definition: surface.h:4
FrameScanType
FrameScanType
Definition: videoouttypes.h:94
MythVDPAUHelper::HaveVDPAU
static bool HaveVDPAU(bool Reinit=false)
Definition: mythvdpauhelper.cpp:55
MythVDPAUHelper::m_valid
bool m_valid
Definition: mythvdpauhelper.h:103
mythframe.h
MythVDPAUHelper::m_vdpVideoMixerDestroy
VdpVideoMixerDestroy * m_vdpVideoMixerDestroy
Definition: mythvdpauhelper.h:116
MythVDPAUHelper::IsFeatureAvailable
bool IsFeatureAvailable(uint Feature)
Definition: mythvdpauhelper.cpp:564
MythVDPAUHelper::IsAttributeAvailable
bool IsAttributeAvailable(uint Attribute)
Definition: mythvdpauhelper.cpp:576
MythVDPAUHelper::CreateOutputSurface
VdpOutputSurface CreateOutputSurface(QSize Size)
Definition: mythvdpauhelper.cpp:406
MythVDPAUHelper::InitProcs
bool InitProcs(void)
Definition: mythvdpauhelper.cpp:288
MythVDPAUHelper::m_createdDevice
bool m_createdDevice
Definition: mythvdpauhelper.h:104
MythVDPAUHelper::VDPMixerNone
@ VDPMixerNone
Definition: mythvdpauhelper.h:59
MythVDPAUHelper::DeleteOutputSurface
void DeleteOutputSurface(VdpOutputSurface Surface)
Definition: mythvdpauhelper.cpp:420
MythVDPAUHelper::VDPMixerTemporal
@ VDPMixerTemporal
Definition: mythvdpauhelper.h:60
MythVDPAUHelper::m_display
MythXDisplay * m_display
Definition: mythvdpauhelper.h:106
MythVDPAUHelper::GetDecoderList
static void GetDecoderList(QStringList &Decoders)
Definition: mythvdpauhelper.cpp:214
Source
Definition: channelsettings.cpp:93
videoouttypes.h
MythVDPAUHelper::DisplayPreempted
void DisplayPreempted(void)
MythVDPAUHelper::SetPreempted
void SetPreempted(void)
Definition: mythvdpauhelper.cpp:322
MythVDPAUHelper
A simple wrapper around VDPAU functionality.
Definition: mythvdpauhelper.h:52
MythVDPAUHelper::m_vdpVideoMixerRender
VdpVideoMixerRender * m_vdpVideoMixerRender
Definition: mythvdpauhelper.h:117
MythVDPAUHelper::DeleteMixer
void DeleteMixer(VdpVideoMixer Mixer)
Definition: mythvdpauhelper.cpp:541
MythVDPAUHelper::GetSurfaceParameters
QSize GetSurfaceParameters(VdpVideoSurface Surface, VdpChromaType &Chroma)
Definition: mythvdpauhelper.cpp:588
MythVDPAUHelper::m_vdpGetProcAddress
VdpGetProcAddress * m_vdpGetProcAddress
Definition: mythvdpauhelper.h:108
MythVDPAUHelper::IsValid
bool IsValid(void) const
Definition: mythvdpauhelper.cpp:317
VDPAUProfile
QPair< MythCodecContext::CodecProfile, VDPAUCodec > VDPAUProfile
Definition: mythvdpauhelper.h:49
uint
unsigned int uint
Definition: compat.h:81
MythVDPAUHelper::m_vdpVideoMixerSetFeatureEnables
VdpVideoMixerSetFeatureEnables * m_vdpVideoMixerSetFeatureEnables
Definition: mythvdpauhelper.h:119
MythVDPAUHelper::CreateMixer
VdpVideoMixer CreateMixer(QSize Size, VdpChromaType ChromaType=VDP_CHROMA_TYPE_420, MythDeintType Deinterlacer=DEINT_BASIC)
Definition: mythvdpauhelper.cpp:430
MythDeintType
MythDeintType
Definition: mythframe.h:67
MythVDPAUHelper::m_vdpGetInformationString
VdpGetInformationString * m_vdpGetInformationString
Definition: mythvdpauhelper.h:110
MythVDPAUHelper::m_vdpDeviceDestroy
VdpDeviceDestroy * m_vdpDeviceDestroy
Definition: mythvdpauhelper.h:111
MythVDPAUHelper::HEVCSupported
bool HEVCSupported(void)
Definition: mythvdpauhelper.cpp:327
MythVDPAUHelper::ProfileCheck
bool ProfileCheck(VdpDecoderProfile Profile, uint32_t &Level, uint32_t &Macros, uint32_t &Width, uint32_t &Height)
Definition: mythvdpauhelper.cpp:86
MythVDPAUHelper::m_vdpDecoderCreate
VdpDecoderCreate * m_vdpDecoderCreate
Definition: mythvdpauhelper.h:113
MythXDisplay
Definition: mythxdisplay.h:15
MythVDPAUHelper::m_vdpVideoMixerCreate
VdpVideoMixerCreate * m_vdpVideoMixerCreate
Definition: mythvdpauhelper.h:115
MythVDPAUHelper::H264DecodeCheck
bool H264DecodeCheck(VdpDecoderProfile Profile, AVCodecContext *Context)
Definition: mythvdpauhelper.cpp:386
MythVDPAUHelper::CheckH264Decode
static bool CheckH264Decode(AVCodecContext *Context)
Definition: mythvdpauhelper.cpp:348
MythVDPAUHelper::MixerRender
void MixerRender(VdpVideoMixer Mixer, VdpVideoSurface Source, VdpOutputSurface Dest, FrameScanType Scan, int TopFieldFirst, QVector< AVBufferRef * > &Frames)
Definition: mythvdpauhelper.cpp:485
mythcodeccontext.h
VDPAUCodec::VDPAUCodec
VDPAUCodec(MythCodecContext::CodecProfile Profile, QSize Size, uint32_t Macroblocks, uint32_t Level)
Definition: mythvdpauhelper.cpp:30
MythVDPAUHelper::m_vdpVideoMixerSetAttributeValues
VdpVideoMixerSetAttributeValues * m_vdpVideoMixerSetAttributeValues
Definition: mythvdpauhelper.h:118
VDPAUCodec::Supported
bool Supported(int Width, int Height, int Level) const
Definition: mythvdpauhelper.cpp:40
VDPAUCodec
Definition: mythvdpauhelper.h:38
DEINT_BASIC
@ DEINT_BASIC
Definition: mythframe.h:70
MythVDPAUHelper::VDPMixerSpatial
@ VDPMixerSpatial
Definition: mythvdpauhelper.h:61
MythVDPAUHelper::m_vdpDecoderDestroy
VdpDecoderDestroy * m_vdpDecoderDestroy
Definition: mythvdpauhelper.h:114
MythVDPAUHelper::m_vdpVideoSurfaceGetParameters
VdpVideoSurfaceGetParameters * m_vdpVideoSurfaceGetParameters
Definition: mythvdpauhelper.h:124
MythVDPAUHelper::m_vdpOutputSurfaceCreate
VdpOutputSurfaceCreate * m_vdpOutputSurfaceCreate
Definition: mythvdpauhelper.h:122
MythVDPAUHelper::m_vdpPreemptionCallbackRegister
VdpPreemptionCallbackRegister * m_vdpPreemptionCallbackRegister
Definition: mythvdpauhelper.h:125
MythVDPAUHelper::m_device
VdpDevice m_device
Definition: mythvdpauhelper.h:105
MythVideoColourSpace
MythVideoColourSpace contains a QMatrix4x4 that can convert YCbCr data to RGB.
Definition: mythvideocolourspace.h:18