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
17extern "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
35class MythXDisplay;
37
39{
40 public:
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
49using VDPAUProfile = QPair<MythCodecContext::CodecProfile, VDPAUCodec>;
50using VDPAUProfiles = std::vector<VDPAUProfile>;
51
52class MythVDPAUHelper : public QObject
53{
54 Q_OBJECT
55
56 public:
57 enum VDPMixerFeature : std::uint8_t
58 {
61 VDPMixerSpatial = 0x02
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 VdpDevice m_device { 0 };
105
106 VdpGetProcAddress *m_vdpGetProcAddress { nullptr };
107 VdpGetErrorString *m_vdpGetErrorString { nullptr };
108 VdpGetInformationString *m_vdpGetInformationString { nullptr };
109 VdpDeviceDestroy *m_vdpDeviceDestroy { nullptr };
110 VdpDecoderQueryCapabilities *m_vdpDecoderQueryCapabilities { nullptr };
111 VdpDecoderCreate *m_vdpDecoderCreate { nullptr };
112 VdpDecoderDestroy *m_vdpDecoderDestroy { nullptr };
113 VdpVideoMixerCreate *m_vdpVideoMixerCreate { nullptr };
114 VdpVideoMixerDestroy *m_vdpVideoMixerDestroy { nullptr };
115 VdpVideoMixerRender *m_vdpVideoMixerRender { nullptr };
116 VdpVideoMixerSetAttributeValues *m_vdpVideoMixerSetAttributeValues { nullptr };
117 VdpVideoMixerSetFeatureEnables *m_vdpVideoMixerSetFeatureEnables { nullptr };
118 VdpVideoMixerQueryFeatureSupport *m_vdpVideoMixerQueryFeatureSupport { nullptr };
119 VdpVideoMixerQueryAttributeSupport *m_vdpVideoMixerQueryAttributeSupport { nullptr };
120 VdpOutputSurfaceCreate *m_vdpOutputSurfaceCreate { nullptr };
121 VdpOutputSurfaceDestroy *m_vdpOutputSurfaceDestroy { nullptr };
122 VdpVideoSurfaceGetParameters *m_vdpVideoSurfaceGetParameters { nullptr };
123 VdpPreemptionCallbackRegister *m_vdpPreemptionCallbackRegister { nullptr };
124
125 bool m_createdDevice { false };
126 bool m_valid { false };
127};
128
129#endif // MYTHVDPAUHELPER_H
A simple wrapper around VDPAU functionality.
void DeleteOutputSurface(VdpOutputSurface Surface)
VdpOutputSurface CreateOutputSurface(QSize Size)
VdpVideoMixerDestroy * m_vdpVideoMixerDestroy
VdpVideoMixerSetFeatureEnables * m_vdpVideoMixerSetFeatureEnables
bool HEVCSupported(void)
void MixerRender(VdpVideoMixer Mixer, VdpVideoSurface Source, VdpOutputSurface Dest, FrameScanType Scan, int TopFieldFirst, QVector< AVBufferRef * > &Frames)
bool IsValid(void) const
VdpOutputSurfaceDestroy * m_vdpOutputSurfaceDestroy
static bool CheckH264Decode(AVCodecContext *Context)
VdpVideoMixerCreate * m_vdpVideoMixerCreate
QSize GetSurfaceParameters(VdpVideoSurface Surface, VdpChromaType &Chroma)
VdpDecoderQueryCapabilities * m_vdpDecoderQueryCapabilities
void DeleteMixer(VdpVideoMixer Mixer)
~MythVDPAUHelper(void) override
MythXDisplay * m_display
static bool HaveVDPAU(bool Reinit=false)
VdpDecoderDestroy * m_vdpDecoderDestroy
bool IsFeatureAvailable(uint Feature)
VdpVideoMixerQueryAttributeSupport * m_vdpVideoMixerQueryAttributeSupport
void SetCSCMatrix(VdpVideoMixer Mixer, MythVideoColourSpace *ColourSpace)
static void GetDecoderList(QStringList &Decoders)
VdpGetErrorString * m_vdpGetErrorString
VdpVideoMixerSetAttributeValues * m_vdpVideoMixerSetAttributeValues
VdpVideoMixer CreateMixer(QSize Size, VdpChromaType ChromaType=VDP_CHROMA_TYPE_420, MythDeintType Deinterlacer=DEINT_BASIC)
VdpDeviceDestroy * m_vdpDeviceDestroy
void DisplayPreempted(void)
VdpVideoMixerRender * m_vdpVideoMixerRender
VdpDecoderCreate * m_vdpDecoderCreate
static const VDPAUProfiles & GetProfiles(void)
VdpVideoSurfaceGetParameters * m_vdpVideoSurfaceGetParameters
void SetPreempted(void)
bool H264DecodeCheck(VdpDecoderProfile Profile, AVCodecContext *Context)
VdpVideoMixerQueryFeatureSupport * m_vdpVideoMixerQueryFeatureSupport
bool ProfileCheck(VdpDecoderProfile Profile, uint32_t &Level, uint32_t &Macros, uint32_t &Width, uint32_t &Height)
bool IsAttributeAvailable(uint Attribute)
VdpOutputSurfaceCreate * m_vdpOutputSurfaceCreate
VdpGetProcAddress * m_vdpGetProcAddress
VdpGetInformationString * m_vdpGetInformationString
VdpPreemptionCallbackRegister * m_vdpPreemptionCallbackRegister
MythVideoColourSpace contains a QMatrix4x4 that can convert YCbCr data to RGB.
uint32_t m_maxMacroBlocks
uint32_t m_maxLevel
bool Supported(int Width, int Height, int Level) const
VDPAUCodec(MythCodecContext::CodecProfile Profile, QSize Size, uint32_t Macroblocks, uint32_t Level)
unsigned int uint
Definition: freesurround.h:24
MythDeintType
Definition: mythframe.h:67
@ DEINT_BASIC
Definition: mythframe.h:69
std::vector< VDPAUProfile > VDPAUProfiles
QPair< MythCodecContext::CodecProfile, VDPAUCodec > VDPAUProfile
Definition: surface.h:4
FrameScanType
Definition: videoouttypes.h:95