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 #include "libavcodec/avcodec.h"
30 }
31 
32 class MythXDisplay;
34 
36 {
37  public:
38  VDPAUCodec(MythCodecContext::CodecProfile Profile, QSize Size,
39  uint32_t Macroblocks, uint32_t Level);
40  bool Supported(int Width, int Height, int Level) const;
41  QSize m_maxSize { 0, 0 };
42  uint32_t m_maxMacroBlocks { 0 };
43  uint32_t m_maxLevel { 0 };
44 };
45 
46 using VDPAUProfile = QPair<MythCodecContext::CodecProfile, VDPAUCodec>;
47 using VDPAUProfiles = std::vector<VDPAUProfile>;
48 
49 class MythVDPAUHelper : public QObject
50 {
51  Q_OBJECT
52 
53  public:
55  {
56  VDPMixerNone = 0x00,
59  };
60 
61  Q_DECLARE_FLAGS(VDPMixerFeatures, VDPMixerFeature)
62 
63  static bool HaveVDPAU(bool Reinit = false);
64  static bool CheckH264Decode(AVCodecContext *Context);
65  static const VDPAUProfiles& GetProfiles(void);
66  static void GetDecoderList (QStringList &Decoders);
67 
68  explicit MythVDPAUHelper(AVVDPAUDeviceContext *Context);
69  ~MythVDPAUHelper(void) override;
70 
71  bool IsValid(void) const;
72  void SetPreempted(void);
73  bool IsFeatureAvailable(uint Feature);
74  bool IsAttributeAvailable(uint Attribute);
75  VdpOutputSurface CreateOutputSurface(QSize Size);
76  VdpVideoMixer CreateMixer(QSize Size, VdpChromaType ChromaType = VDP_CHROMA_TYPE_420,
77  MythDeintType Deinterlacer = DEINT_BASIC);
78  void MixerRender(VdpVideoMixer Mixer, VdpVideoSurface Source, VdpOutputSurface Dest,
79  FrameScanType Scan, int TopFieldFirst, QVector<AVBufferRef*>& Frames);
80  void SetCSCMatrix(VdpVideoMixer Mixer, MythVideoColourSpace *ColourSpace);
81  void DeleteOutputSurface(VdpOutputSurface Surface);
82  void DeleteMixer(VdpVideoMixer Mixer);
83  QSize GetSurfaceParameters(VdpVideoSurface Surface, VdpChromaType &Chroma);
84 
85  signals:
86  void DisplayPreempted(void);
87 
88  protected:
89  MythVDPAUHelper(void);
90 
91  bool H264DecodeCheck (VdpDecoderProfile Profile, AVCodecContext *Context);
92  bool HEVCSupported (void);
93  bool ProfileCheck (VdpDecoderProfile Profile, uint32_t &Level,
94  uint32_t &Macros, uint32_t &Width, uint32_t &Height);
95 
96  private:
97  bool InitProcs(void);
98 
99  private:
100  bool m_valid { false };
101  bool m_createdDevice { false };
102  VdpDevice m_device { 0 };
103  MythXDisplay *m_display { nullptr };
104 
105  VdpGetProcAddress *m_vdpGetProcAddress { nullptr };
106  VdpGetErrorString *m_vdpGetErrorString { nullptr };
107  VdpGetInformationString *m_vdpGetInformationString { nullptr };
108  VdpDeviceDestroy *m_vdpDeviceDestroy { nullptr };
109  VdpDecoderQueryCapabilities *m_vdpDecoderQueryCapabilities { nullptr };
110  VdpDecoderCreate *m_vdpDecoderCreate { nullptr };
111  VdpDecoderDestroy *m_vdpDecoderDestroy { nullptr };
112  VdpVideoMixerCreate *m_vdpVideoMixerCreate { nullptr };
113  VdpVideoMixerDestroy *m_vdpVideoMixerDestroy { nullptr };
114  VdpVideoMixerRender *m_vdpVideoMixerRender { nullptr };
115  VdpVideoMixerSetAttributeValues *m_vdpVideoMixerSetAttributeValues { nullptr };
116  VdpVideoMixerSetFeatureEnables *m_vdpVideoMixerSetFeatureEnables { nullptr };
117  VdpVideoMixerQueryFeatureSupport *m_vdpVideoMixerQueryFeatureSupport { nullptr };
118  VdpVideoMixerQueryAttributeSupport *m_vdpVideoMixerQueryAttributeSupport { nullptr };
119  VdpOutputSurfaceCreate *m_vdpOutputSurfaceCreate { nullptr };
120  VdpOutputSurfaceDestroy *m_vdpOutputSurfaceDestroy { nullptr };
121  VdpVideoSurfaceGetParameters *m_vdpVideoSurfaceGetParameters { nullptr };
122  VdpPreemptionCallbackRegister *m_vdpPreemptionCallbackRegister { nullptr };
123 };
124 
125 #endif // MYTHVDPAUHELPER_H
MythVDPAUHelper::GetProfiles
static const VDPAUProfiles & GetProfiles(void)
Definition: mythvdpauhelper.cpp:122
MythVDPAUHelper::m_vdpVideoMixerQueryAttributeSupport
VdpVideoMixerQueryAttributeSupport * m_vdpVideoMixerQueryAttributeSupport
Definition: mythvdpauhelper.h:118
MythVDPAUHelper::~MythVDPAUHelper
~MythVDPAUHelper(void) override
Definition: mythvdpauhelper.cpp:283
MythVDPAUHelper::m_vdpVideoMixerQueryFeatureSupport
VdpVideoMixerQueryFeatureSupport * m_vdpVideoMixerQueryFeatureSupport
Definition: mythvdpauhelper.h:117
MythVDPAUHelper::m_vdpOutputSurfaceDestroy
VdpOutputSurfaceDestroy * m_vdpOutputSurfaceDestroy
Definition: mythvdpauhelper.h:120
MythVDPAUHelper::m_vdpDecoderQueryCapabilities
VdpDecoderQueryCapabilities * m_vdpDecoderQueryCapabilities
Definition: mythvdpauhelper.h:109
VDPAUCodec::m_maxSize
QSize m_maxSize
Definition: mythvdpauhelper.h:41
MythVDPAUHelper::SetCSCMatrix
void SetCSCMatrix(VdpVideoMixer Mixer, MythVideoColourSpace *ColourSpace)
Definition: mythvdpauhelper.cpp:555
VDPAUCodec::m_maxMacroBlocks
uint32_t m_maxMacroBlocks
Definition: mythvdpauhelper.h:42
VDPAUProfiles
std::vector< VDPAUProfile > VDPAUProfiles
Definition: mythvdpauhelper.h:47
VDPAUCodec::m_maxLevel
uint32_t m_maxLevel
Definition: mythvdpauhelper.h:43
MythCodecContext::CodecProfile
CodecProfile
Definition: mythcodeccontext.h:57
MythVDPAUHelper::m_vdpGetErrorString
VdpGetErrorString * m_vdpGetErrorString
Definition: mythvdpauhelper.h:106
MythVDPAUHelper::MythVDPAUHelper
MythVDPAUHelper(void)
Definition: mythvdpauhelper.cpp:260
MythVDPAUHelper::VDPMixerFeature
VDPMixerFeature
Definition: mythvdpauhelper.h:54
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:100
mythframe.h
MythVDPAUHelper::m_vdpVideoMixerDestroy
VdpVideoMixerDestroy * m_vdpVideoMixerDestroy
Definition: mythvdpauhelper.h:113
MythVDPAUHelper::IsFeatureAvailable
bool IsFeatureAvailable(uint Feature)
Definition: mythvdpauhelper.cpp:568
MythVDPAUHelper::IsAttributeAvailable
bool IsAttributeAvailable(uint Attribute)
Definition: mythvdpauhelper.cpp:580
MythVDPAUHelper::CreateOutputSurface
VdpOutputSurface CreateOutputSurface(QSize Size)
Definition: mythvdpauhelper.cpp:410
MythVDPAUHelper::InitProcs
bool InitProcs(void)
Definition: mythvdpauhelper.cpp:292
MythVDPAUHelper::m_createdDevice
bool m_createdDevice
Definition: mythvdpauhelper.h:101
MythVDPAUHelper::VDPMixerNone
@ VDPMixerNone
Definition: mythvdpauhelper.h:56
MythVDPAUHelper::DeleteOutputSurface
void DeleteOutputSurface(VdpOutputSurface Surface)
Definition: mythvdpauhelper.cpp:424
MythVDPAUHelper::VDPMixerTemporal
@ VDPMixerTemporal
Definition: mythvdpauhelper.h:57
MythVDPAUHelper::m_display
MythXDisplay * m_display
Definition: mythvdpauhelper.h:103
MythVDPAUHelper::GetDecoderList
static void GetDecoderList(QStringList &Decoders)
Definition: mythvdpauhelper.cpp:218
Source
Definition: channelsettings.cpp:93
videoouttypes.h
MythVDPAUHelper::DisplayPreempted
void DisplayPreempted(void)
MythVDPAUHelper::SetPreempted
void SetPreempted(void)
Definition: mythvdpauhelper.cpp:326
MythVDPAUHelper
A simple wrapper around VDPAU functionality.
Definition: mythvdpauhelper.h:49
MythVDPAUHelper::m_vdpVideoMixerRender
VdpVideoMixerRender * m_vdpVideoMixerRender
Definition: mythvdpauhelper.h:114
MythVDPAUHelper::DeleteMixer
void DeleteMixer(VdpVideoMixer Mixer)
Definition: mythvdpauhelper.cpp:545
MythVDPAUHelper::GetSurfaceParameters
QSize GetSurfaceParameters(VdpVideoSurface Surface, VdpChromaType &Chroma)
Definition: mythvdpauhelper.cpp:592
MythVDPAUHelper::m_vdpGetProcAddress
VdpGetProcAddress * m_vdpGetProcAddress
Definition: mythvdpauhelper.h:105
MythVDPAUHelper::IsValid
bool IsValid(void) const
Definition: mythvdpauhelper.cpp:321
VDPAUProfile
QPair< MythCodecContext::CodecProfile, VDPAUCodec > VDPAUProfile
Definition: mythvdpauhelper.h:46
uint
unsigned int uint
Definition: compat.h:81
MythVDPAUHelper::m_vdpVideoMixerSetFeatureEnables
VdpVideoMixerSetFeatureEnables * m_vdpVideoMixerSetFeatureEnables
Definition: mythvdpauhelper.h:116
MythVDPAUHelper::CreateMixer
VdpVideoMixer CreateMixer(QSize Size, VdpChromaType ChromaType=VDP_CHROMA_TYPE_420, MythDeintType Deinterlacer=DEINT_BASIC)
Definition: mythvdpauhelper.cpp:434
MythDeintType
MythDeintType
Definition: mythframe.h:67
MythVDPAUHelper::m_vdpGetInformationString
VdpGetInformationString * m_vdpGetInformationString
Definition: mythvdpauhelper.h:107
MythVDPAUHelper::m_vdpDeviceDestroy
VdpDeviceDestroy * m_vdpDeviceDestroy
Definition: mythvdpauhelper.h:108
MythVDPAUHelper::HEVCSupported
bool HEVCSupported(void)
Definition: mythvdpauhelper.cpp:331
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:110
MythXDisplay
Definition: mythxdisplay.h:19
MythVDPAUHelper::m_vdpVideoMixerCreate
VdpVideoMixerCreate * m_vdpVideoMixerCreate
Definition: mythvdpauhelper.h:112
MythVDPAUHelper::H264DecodeCheck
bool H264DecodeCheck(VdpDecoderProfile Profile, AVCodecContext *Context)
Definition: mythvdpauhelper.cpp:390
MythVDPAUHelper::CheckH264Decode
static bool CheckH264Decode(AVCodecContext *Context)
Definition: mythvdpauhelper.cpp:352
MythVDPAUHelper::MixerRender
void MixerRender(VdpVideoMixer Mixer, VdpVideoSurface Source, VdpOutputSurface Dest, FrameScanType Scan, int TopFieldFirst, QVector< AVBufferRef * > &Frames)
Definition: mythvdpauhelper.cpp:489
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:115
VDPAUCodec::Supported
bool Supported(int Width, int Height, int Level) const
Definition: mythvdpauhelper.cpp:40
VDPAUCodec
Definition: mythvdpauhelper.h:35
DEINT_BASIC
@ DEINT_BASIC
Definition: mythframe.h:70
MythVDPAUHelper::VDPMixerSpatial
@ VDPMixerSpatial
Definition: mythvdpauhelper.h:58
MythVDPAUHelper::m_vdpDecoderDestroy
VdpDecoderDestroy * m_vdpDecoderDestroy
Definition: mythvdpauhelper.h:111
MythVDPAUHelper::m_vdpVideoSurfaceGetParameters
VdpVideoSurfaceGetParameters * m_vdpVideoSurfaceGetParameters
Definition: mythvdpauhelper.h:121
MythVDPAUHelper::m_vdpOutputSurfaceCreate
VdpOutputSurfaceCreate * m_vdpOutputSurfaceCreate
Definition: mythvdpauhelper.h:119
MythVDPAUHelper::m_vdpPreemptionCallbackRegister
VdpPreemptionCallbackRegister * m_vdpPreemptionCallbackRegister
Definition: mythvdpauhelper.h:122
MythVDPAUHelper::m_device
VdpDevice m_device
Definition: mythvdpauhelper.h:102
MythVideoColourSpace
MythVideoColourSpace contains a QMatrix4x4 that can convert YCbCr data to RGB.
Definition: mythvideocolourspace.h:18