9static inline QString
toString(
const GUID& guid)
11 return QString(
"%1-%2-%3-%4%5-%6%7%8%9%10%11")
12 .arg(guid.Data1, 8, 16, QLatin1Char(
'0'))
13 .arg(guid.Data2, 4, 16, QLatin1Char(
'0'))
14 .arg(guid.Data3, 4, 16, QLatin1Char(
'0'))
15 .arg(guid.Data4[0], 2, 16, QLatin1Char(
'0'))
16 .arg(guid.Data4[1], 2, 16, QLatin1Char(
'0'))
17 .arg(guid.Data4[2], 2, 16, QLatin1Char(
'0'))
18 .arg(guid.Data4[3], 2, 16, QLatin1Char(
'0'))
19 .arg(guid.Data4[4], 2, 16, QLatin1Char(
'0'))
20 .arg(guid.Data4[5], 2, 16, QLatin1Char(
'0'))
21 .arg(guid.Data4[6], 2, 16, QLatin1Char(
'0'))
22 .arg(guid.Data4[7], 2, 16, QLatin1Char(
'0')).toUpper();
25#define LOC QString("DXVA2: ")
26#define ERR QString("DXVA2 Error: ")
28#define DXVA2_ModeWMV8_PostProc DXVA2_ModeWMV8_A
29#define DXVA2_ModeWMV8_MoComp DXVA2_ModeWMV8_B
31#define DXVA2_ModeWMV9_PostProc DXVA2_ModeWMV9_A
32#define DXVA2_ModeWMV9_MoComp DXVA2_ModeWMV9_B
33#define DXVA2_ModeWMV9_IDCT DXVA2_ModeWMV9_C
35#define DXVA2_ModeVC1_PostProc DXVA2_ModeVC1_A
36#define DXVA2_ModeVC1_MoComp DXVA2_ModeVC1_B
37#define DXVA2_ModeVC1_IDCT DXVA2_ModeVC1_C
38#define DXVA2_ModeVC1_VLD DXVA2_ModeVC1_D
40#define DXVA2_ModeH264_MoComp_NoFGT DXVA2_ModeH264_A
41#define DXVA2_ModeH264_MoComp_FGT DXVA2_ModeH264_B
42#define DXVA2_ModeH264_IDCT_NoFGT DXVA2_ModeH264_C
43#define DXVA2_ModeH264_IDCT_FGT DXVA2_ModeH264_D
44#define DXVA2_ModeH264_VLD_NoFGT DXVA2_ModeH264_E
45#define DXVA2_ModeH264_VLD_FGT DXVA2_ModeH264_F
47DEFINE_GUID(DXVA2_Intel_ModeH264_A, 0x604F8E64, 0x4951, 0x4c54, 0x88,0xFE,0xAB,0xD2,0x5C,0x15,0xB3,0xD6);
48DEFINE_GUID(DXVA2_Intel_ModeH264_C, 0x604F8E66, 0x4951, 0x4c54, 0x88,0xFE,0xAB,0xD2,0x5C,0x15,0xB3,0xD6);
49DEFINE_GUID(DXVA2_Intel_ModeH264_E, 0x604F8E68, 0x4951, 0x4c54, 0x88,0xFE,0xAB,0xD2,0x5C,0x15,0xB3,0xD6);
50DEFINE_GUID(DXVA2_Intel_ModeVC1_E , 0xBCC5DB6D, 0xA2B6, 0x4AF0, 0xAC,0xE4,0xAD,0xB1,0xF7,0x87,0xBC,0x89);
61 {
"MPEG2 MoComp", &DXVA2_ModeMPEG2_MoComp,
kCodec_NONE},
66 {
"H.264 IDCT, FGT", &DXVA2_ModeH264_D,
kCodec_NONE},
67 {
"H.264 IDCT, no FGT", &DXVA2_ModeH264_C,
kCodec_NONE},
68 {
"H.264 MoComp, FGT", &DXVA2_ModeH264_B,
kCodec_NONE},
69 {
"H.264 MoComp, no FGT", &DXVA2_ModeH264_A,
kCodec_NONE},
72 {
"WMV8 post processing", &DXVA2_ModeWMV8_A,
kCodec_NONE},
76 {
"WMV9 post processing", &DXVA2_ModeWMV9_A,
kCodec_NONE},
82 {
"VC-1 post processing", &DXVA2_ModeVC1_A,
kCodec_NONE},
85 {
"Intel H.264 IDCT, no FGT", &DXVA2_Intel_ModeH264_C,
kCodec_NONE},
86 {
"Intel H.264 MoComp, no FGT", &DXVA2_Intel_ModeH264_A,
kCodec_NONE},
92#define CREATE_CHECK(arg1, arg2) \
97 LOG(VB_GENERAL, LOG_ERR, LOC + (arg2)); \
102 : m_codec_id(codec_id), m_width(width), m_height(height)
104 memset(&
m_format, 0,
sizeof(DXVA2_VideoDesc));
105 memset(&
m_context, 0,
sizeof(dxva_context));
106 memset(&
m_config, 0,
sizeof(DXVA2_ConfigPictureDecode));
109 m_context.surface =
new IDirect3DSurface9*[num_bufs];
110 for (
uint i = 0; i < num_bufs; i++)
144 if (!create_video_service)
150 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Failed to get device manager.");
157 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Failed to get device handle.");
163 IID_IDirectXVideoDecoderService,
167 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Failed to get video service.");
171 LOG(VB_PLAYBACK, LOG_INFO,
LOC +
"Created DXVA2 video service.");
180 IDirectXVideoDecoderService_Release(
m_service);
190 LOG(VB_PLAYBACK, LOG_INFO,
LOC + QString(
"Looking for support for %1")
195 IDirectXVideoDecoderService_GetDecoderDeviceGuids(
199 !mode->
name.isEmpty() &&
m_format.Format == D3DFMT_UNKNOWN;
204 for (
uint j = 0; j < input_count; j++)
206 if (IsEqualGUID(input_list[j], *mode->guid))
208 LOG(VB_PLAYBACK, LOG_INFO,
LOC + QString(
"Testing %1")
216 return m_format.Format != D3DFMT_UNKNOWN;
223 uint output_count = 0;
224 D3DFORMAT *output_list =
nullptr;
225 IDirectXVideoDecoderService_GetDecoderRenderTargets(
226 m_service, guid, &output_count, &output_list);
227 for(
uint i = 0; i < output_count; i++)
229 if(output_list[i] == MAKEFOURCC(
'Y',
'V',
'1',
'2') ||
230 output_list[i] == MAKEFOURCC(
'N',
'V',
'1',
'2'))
244 m_format.InputSampleFreq.Numerator = 0;
245 m_format.InputSampleFreq.Denominator = 0;
247 m_format.UABProtectionLevel =
false;
257 DXVA2_ConfigPictureDecode *cfg_list =
nullptr;
258 IDirectXVideoDecoderService_GetDecoderConfigurations(
261 DXVA2_ConfigPictureDecode config = {};
263 for (
uint i = 0; i < cfg_count; i++)
266 if (config.ConfigBitstreamRaw == 0 &&
267 cfg_list[i].ConfigBitstreamRaw != 0)
269 config = cfg_list[i];
272 if (config.ConfigBitstreamRaw != bitstream &&
273 cfg_list[i].ConfigBitstreamRaw == bitstream)
275 config = cfg_list[i];
279 if(!config.ConfigBitstreamRaw)
283 LOG(VB_PLAYBACK, LOG_INFO,
LOC + QString(
"Found bitstream type %1")
284 .arg(
m_context.cfg->ConfigBitstreamRaw));
293 HRESULT hr = IDirectXVideoDecoderService_CreateSurface(
296 D3DPOOL_DEFAULT, 0, DXVA2_VideoDecoderRenderTarget,
302 LOG(VB_PLAYBACK, LOG_INFO,
LOC + QString(
"Created %1 decoder surfaces.")
327 HRESULT hr = IDirectXVideoDecoderService_CreateVideoDecoder(
329 const_cast<DXVA2_ConfigPictureDecode*
>(
m_context.cfg),
335 LOG(VB_PLAYBACK, LOG_INFO,
LOC +
336 QString(
"Created decoder: %1->%2x%3 (%4 surfaces)")
345 IDirectXVideoDecoder_Release(
m_context.decoder);
bool Init(MythRenderD3D9 *render)
DXVA2_ConfigPictureDecode m_config
DXVA2Decoder(uint num_bufs, MythCodecID codec_id, uint width, uint height)
bool CreateSurfaces(void)
void DestroySurfaces(void)
IDirectXVideoDecoderService * m_service
bool GetInputOutput(void)
struct dxva_context m_context
void DestroyDecoder(void)
void * GetSurface(uint num)
void DestroyVideoService(void)
bool GetDecoderConfig(void)
bool TestTarget(const GUID &guid)
bool CreateVideoService(MythRenderD3D9 *render)
IDirect3DDeviceManager9 * m_deviceManager
static void * ResolveAddress(const char *lib, const char *proc)
IDirect3DDeviceManager9 * GetDeviceManager(void)
HRESULT(__stdcall *)(IDirect3DDevice9 *pDD, REFIID riid, void **ppService) DXVA2CreateVideoServicePtr
static QString toString(const GUID &guid)
#define CREATE_CHECK(arg1, arg2)
static const dxva2_mode dxva2_modes[]
DEFINE_GUID(DXVA2_Intel_ModeH264_A, 0x604F8E64, 0x4951, 0x4c54, 0x88, 0xFE, 0xAB, 0xD2, 0x5C, 0x15, 0xB3, 0xD6)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)