You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

548 lines
18KB

  1. /*
  2. * This file is part of Libav.
  3. *
  4. * Libav is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * Libav is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with Libav; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include <windows.h>
  19. #ifdef _WIN32_WINNT
  20. #undef _WIN32_WINNT
  21. #endif
  22. #define _WIN32_WINNT 0x0600
  23. #define DXVA2API_USE_BITFIELDS
  24. #define COBJMACROS
  25. #include <stdint.h>
  26. #include <d3d9.h>
  27. #include <dxva2api.h>
  28. #include "avconv.h"
  29. #include "libavcodec/dxva2.h"
  30. #include "libavutil/avassert.h"
  31. #include "libavutil/buffer.h"
  32. #include "libavutil/frame.h"
  33. #include "libavutil/imgutils.h"
  34. #include "libavutil/pixfmt.h"
  35. #include "libavutil/hwcontext.h"
  36. #include "libavutil/hwcontext_dxva2.h"
  37. /* define all the GUIDs used directly here,
  38. to avoid problems with inconsistent dxva2api.h versions in mingw-w64 and different MSVC version */
  39. #include <initguid.h>
  40. DEFINE_GUID(IID_IDirectXVideoDecoderService, 0xfc51a551,0xd5e7,0x11d9,0xaf,0x55,0x00,0x05,0x4e,0x43,0xff,0x02);
  41. DEFINE_GUID(DXVA2_ModeMPEG2_VLD, 0xee27417f, 0x5e28,0x4e65,0xbe,0xea,0x1d,0x26,0xb5,0x08,0xad,0xc9);
  42. DEFINE_GUID(DXVA2_ModeMPEG2and1_VLD, 0x86695f12, 0x340e,0x4f04,0x9f,0xd3,0x92,0x53,0xdd,0x32,0x74,0x60);
  43. DEFINE_GUID(DXVA2_ModeH264_E, 0x1b81be68, 0xa0c7,0x11d3,0xb9,0x84,0x00,0xc0,0x4f,0x2e,0x73,0xc5);
  44. DEFINE_GUID(DXVA2_ModeH264_F, 0x1b81be69, 0xa0c7,0x11d3,0xb9,0x84,0x00,0xc0,0x4f,0x2e,0x73,0xc5);
  45. DEFINE_GUID(DXVADDI_Intel_ModeH264_E, 0x604F8E68, 0x4951,0x4C54,0x88,0xFE,0xAB,0xD2,0x5C,0x15,0xB3,0xD6);
  46. DEFINE_GUID(DXVA2_ModeVC1_D, 0x1b81beA3, 0xa0c7,0x11d3,0xb9,0x84,0x00,0xc0,0x4f,0x2e,0x73,0xc5);
  47. DEFINE_GUID(DXVA2_ModeVC1_D2010, 0x1b81beA4, 0xa0c7,0x11d3,0xb9,0x84,0x00,0xc0,0x4f,0x2e,0x73,0xc5);
  48. DEFINE_GUID(DXVA2_ModeHEVC_VLD_Main, 0x5b11d51b, 0x2f4c,0x4452,0xbc,0xc3,0x09,0xf2,0xa1,0x16,0x0c,0xc0);
  49. DEFINE_GUID(DXVA2_NoEncrypt, 0x1b81beD0, 0xa0c7,0x11d3,0xb9,0x84,0x00,0xc0,0x4f,0x2e,0x73,0xc5);
  50. DEFINE_GUID(GUID_NULL, 0x00000000, 0x0000,0x0000,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00);
  51. typedef IDirect3D9* WINAPI pDirect3DCreate9(UINT);
  52. typedef HRESULT WINAPI pCreateDeviceManager9(UINT *, IDirect3DDeviceManager9 **);
  53. typedef struct dxva2_mode {
  54. const GUID *guid;
  55. enum AVCodecID codec;
  56. } dxva2_mode;
  57. static const dxva2_mode dxva2_modes[] = {
  58. /* MPEG-2 */
  59. { &DXVA2_ModeMPEG2_VLD, AV_CODEC_ID_MPEG2VIDEO },
  60. { &DXVA2_ModeMPEG2and1_VLD, AV_CODEC_ID_MPEG2VIDEO },
  61. /* H.264 */
  62. { &DXVA2_ModeH264_F, AV_CODEC_ID_H264 },
  63. { &DXVA2_ModeH264_E, AV_CODEC_ID_H264 },
  64. /* Intel specific H.264 mode */
  65. { &DXVADDI_Intel_ModeH264_E, AV_CODEC_ID_H264 },
  66. /* VC-1 / WMV3 */
  67. { &DXVA2_ModeVC1_D2010, AV_CODEC_ID_VC1 },
  68. { &DXVA2_ModeVC1_D2010, AV_CODEC_ID_WMV3 },
  69. { &DXVA2_ModeVC1_D, AV_CODEC_ID_VC1 },
  70. { &DXVA2_ModeVC1_D, AV_CODEC_ID_WMV3 },
  71. /* HEVC/H.265 */
  72. { &DXVA2_ModeHEVC_VLD_Main, AV_CODEC_ID_HEVC },
  73. { NULL, 0 },
  74. };
  75. typedef struct DXVA2DevicePriv {
  76. HMODULE d3dlib;
  77. HMODULE dxva2lib;
  78. HANDLE deviceHandle;
  79. IDirect3D9 *d3d9;
  80. IDirect3DDevice9 *d3d9device;
  81. } DXVA2DevicePriv;
  82. typedef struct DXVA2Context {
  83. IDirectXVideoDecoder *decoder;
  84. GUID decoder_guid;
  85. DXVA2_ConfigPictureDecode decoder_config;
  86. IDirectXVideoDecoderService *decoder_service;
  87. AVFrame *tmp_frame;
  88. AVBufferRef *hw_device_ctx;
  89. AVBufferRef *hw_frames_ctx;
  90. } DXVA2Context;
  91. static void dxva2_device_uninit(AVHWDeviceContext *ctx)
  92. {
  93. AVDXVA2DeviceContext *hwctx = ctx->hwctx;
  94. DXVA2DevicePriv *priv = ctx->user_opaque;
  95. if (hwctx->devmgr && priv->deviceHandle != INVALID_HANDLE_VALUE)
  96. IDirect3DDeviceManager9_CloseDeviceHandle(hwctx->devmgr, priv->deviceHandle);
  97. if (hwctx->devmgr)
  98. IDirect3DDeviceManager9_Release(hwctx->devmgr);
  99. if (priv->d3d9device)
  100. IDirect3DDevice9_Release(priv->d3d9device);
  101. if (priv->d3d9)
  102. IDirect3D9_Release(priv->d3d9);
  103. if (priv->d3dlib)
  104. FreeLibrary(priv->d3dlib);
  105. if (priv->dxva2lib)
  106. FreeLibrary(priv->dxva2lib);
  107. av_freep(&ctx->user_opaque);
  108. }
  109. static void dxva2_uninit(AVCodecContext *s)
  110. {
  111. InputStream *ist = s->opaque;
  112. DXVA2Context *ctx = ist->hwaccel_ctx;
  113. ist->hwaccel_uninit = NULL;
  114. ist->hwaccel_get_buffer = NULL;
  115. ist->hwaccel_retrieve_data = NULL;
  116. if (ctx->decoder_service)
  117. IDirectXVideoDecoderService_Release(ctx->decoder_service);
  118. av_buffer_unref(&ctx->hw_frames_ctx);
  119. av_buffer_unref(&ctx->hw_device_ctx);
  120. av_frame_free(&ctx->tmp_frame);
  121. av_freep(&ist->hwaccel_ctx);
  122. av_freep(&s->hwaccel_context);
  123. }
  124. static int dxva2_get_buffer(AVCodecContext *s, AVFrame *frame, int flags)
  125. {
  126. InputStream *ist = s->opaque;
  127. DXVA2Context *ctx = ist->hwaccel_ctx;
  128. return av_hwframe_get_buffer(ctx->hw_frames_ctx, frame, 0);
  129. }
  130. static int dxva2_retrieve_data(AVCodecContext *s, AVFrame *frame)
  131. {
  132. InputStream *ist = s->opaque;
  133. DXVA2Context *ctx = ist->hwaccel_ctx;
  134. int ret;
  135. ret = av_hwframe_transfer_data(ctx->tmp_frame, frame, 0);
  136. if (ret < 0)
  137. return ret;
  138. ret = av_frame_copy_props(ctx->tmp_frame, frame);
  139. if (ret < 0) {
  140. av_frame_unref(ctx->tmp_frame);
  141. return ret;
  142. }
  143. av_frame_unref(frame);
  144. av_frame_move_ref(frame, ctx->tmp_frame);
  145. return 0;
  146. }
  147. static int dxva2_alloc(AVCodecContext *s)
  148. {
  149. InputStream *ist = s->opaque;
  150. int loglevel = (ist->hwaccel_id == HWACCEL_AUTO) ? AV_LOG_VERBOSE : AV_LOG_ERROR;
  151. DXVA2Context *ctx;
  152. pDirect3DCreate9 *createD3D = NULL;
  153. pCreateDeviceManager9 *createDeviceManager = NULL;
  154. HRESULT hr;
  155. D3DPRESENT_PARAMETERS d3dpp = {0};
  156. D3DDISPLAYMODE d3ddm;
  157. unsigned resetToken = 0;
  158. UINT adapter = D3DADAPTER_DEFAULT;
  159. AVHWDeviceContext *device_ctx;
  160. AVDXVA2DeviceContext *device_hwctx;
  161. DXVA2DevicePriv *device_priv;
  162. int ret;
  163. ctx = av_mallocz(sizeof(*ctx));
  164. if (!ctx)
  165. return AVERROR(ENOMEM);
  166. ist->hwaccel_ctx = ctx;
  167. ist->hwaccel_uninit = dxva2_uninit;
  168. ist->hwaccel_get_buffer = dxva2_get_buffer;
  169. ist->hwaccel_retrieve_data = dxva2_retrieve_data;
  170. ctx->hw_device_ctx = av_hwdevice_ctx_alloc(AV_HWDEVICE_TYPE_DXVA2);
  171. if (!ctx->hw_device_ctx)
  172. goto fail;
  173. device_ctx = (AVHWDeviceContext*)ctx->hw_device_ctx->data;
  174. device_hwctx = device_ctx->hwctx;
  175. device_priv = av_mallocz(sizeof(*device_priv));
  176. if (!device_priv)
  177. goto fail;
  178. device_ctx->user_opaque = device_priv;
  179. device_ctx->free = dxva2_device_uninit;
  180. device_priv->deviceHandle = INVALID_HANDLE_VALUE;
  181. device_priv->d3dlib = LoadLibrary("d3d9.dll");
  182. if (!device_priv->d3dlib) {
  183. av_log(NULL, loglevel, "Failed to load D3D9 library\n");
  184. goto fail;
  185. }
  186. device_priv->dxva2lib = LoadLibrary("dxva2.dll");
  187. if (!device_priv->dxva2lib) {
  188. av_log(NULL, loglevel, "Failed to load DXVA2 library\n");
  189. goto fail;
  190. }
  191. createD3D = (pDirect3DCreate9 *)GetProcAddress(device_priv->d3dlib, "Direct3DCreate9");
  192. if (!createD3D) {
  193. av_log(NULL, loglevel, "Failed to locate Direct3DCreate9\n");
  194. goto fail;
  195. }
  196. createDeviceManager = (pCreateDeviceManager9 *)GetProcAddress(device_priv->dxva2lib, "DXVA2CreateDirect3DDeviceManager9");
  197. if (!createDeviceManager) {
  198. av_log(NULL, loglevel, "Failed to locate DXVA2CreateDirect3DDeviceManager9\n");
  199. goto fail;
  200. }
  201. device_priv->d3d9 = createD3D(D3D_SDK_VERSION);
  202. if (!device_priv->d3d9) {
  203. av_log(NULL, loglevel, "Failed to create IDirect3D object\n");
  204. goto fail;
  205. }
  206. if (ist->hwaccel_device) {
  207. adapter = atoi(ist->hwaccel_device);
  208. av_log(NULL, AV_LOG_INFO, "Using HWAccel device %d\n", adapter);
  209. }
  210. IDirect3D9_GetAdapterDisplayMode(device_priv->d3d9, adapter, &d3ddm);
  211. d3dpp.Windowed = TRUE;
  212. d3dpp.BackBufferWidth = 640;
  213. d3dpp.BackBufferHeight = 480;
  214. d3dpp.BackBufferCount = 0;
  215. d3dpp.BackBufferFormat = d3ddm.Format;
  216. d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
  217. d3dpp.Flags = D3DPRESENTFLAG_VIDEO;
  218. hr = IDirect3D9_CreateDevice(device_priv->d3d9, adapter, D3DDEVTYPE_HAL, GetShellWindow(),
  219. D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED | D3DCREATE_FPU_PRESERVE,
  220. &d3dpp, &device_priv->d3d9device);
  221. if (FAILED(hr)) {
  222. av_log(NULL, loglevel, "Failed to create Direct3D device\n");
  223. goto fail;
  224. }
  225. hr = createDeviceManager(&resetToken, &device_hwctx->devmgr);
  226. if (FAILED(hr)) {
  227. av_log(NULL, loglevel, "Failed to create Direct3D device manager\n");
  228. goto fail;
  229. }
  230. hr = IDirect3DDeviceManager9_ResetDevice(device_hwctx->devmgr, device_priv->d3d9device, resetToken);
  231. if (FAILED(hr)) {
  232. av_log(NULL, loglevel, "Failed to bind Direct3D device to device manager\n");
  233. goto fail;
  234. }
  235. hr = IDirect3DDeviceManager9_OpenDeviceHandle(device_hwctx->devmgr, &device_priv->deviceHandle);
  236. if (FAILED(hr)) {
  237. av_log(NULL, loglevel, "Failed to open device handle\n");
  238. goto fail;
  239. }
  240. hr = IDirect3DDeviceManager9_GetVideoService(device_hwctx->devmgr, device_priv->deviceHandle, &IID_IDirectXVideoDecoderService, (void **)&ctx->decoder_service);
  241. if (FAILED(hr)) {
  242. av_log(NULL, loglevel, "Failed to create IDirectXVideoDecoderService\n");
  243. goto fail;
  244. }
  245. ret = av_hwdevice_ctx_init(ctx->hw_device_ctx);
  246. if (ret < 0) {
  247. av_log(NULL, loglevel, "Failed to initialize the HW device context\n");
  248. goto fail;
  249. }
  250. ctx->tmp_frame = av_frame_alloc();
  251. if (!ctx->tmp_frame)
  252. goto fail;
  253. s->hwaccel_context = av_mallocz(sizeof(struct dxva_context));
  254. if (!s->hwaccel_context)
  255. goto fail;
  256. return 0;
  257. fail:
  258. dxva2_uninit(s);
  259. return AVERROR(EINVAL);
  260. }
  261. static int dxva2_get_decoder_configuration(AVCodecContext *s, const GUID *device_guid,
  262. const DXVA2_VideoDesc *desc,
  263. DXVA2_ConfigPictureDecode *config)
  264. {
  265. InputStream *ist = s->opaque;
  266. int loglevel = (ist->hwaccel_id == HWACCEL_AUTO) ? AV_LOG_VERBOSE : AV_LOG_ERROR;
  267. DXVA2Context *ctx = ist->hwaccel_ctx;
  268. unsigned cfg_count = 0, best_score = 0;
  269. DXVA2_ConfigPictureDecode *cfg_list = NULL;
  270. DXVA2_ConfigPictureDecode best_cfg = {{0}};
  271. HRESULT hr;
  272. int i;
  273. hr = IDirectXVideoDecoderService_GetDecoderConfigurations(ctx->decoder_service, device_guid, desc, NULL, &cfg_count, &cfg_list);
  274. if (FAILED(hr)) {
  275. av_log(NULL, loglevel, "Unable to retrieve decoder configurations\n");
  276. return AVERROR(EINVAL);
  277. }
  278. for (i = 0; i < cfg_count; i++) {
  279. DXVA2_ConfigPictureDecode *cfg = &cfg_list[i];
  280. unsigned score;
  281. if (cfg->ConfigBitstreamRaw == 1)
  282. score = 1;
  283. else if (s->codec_id == AV_CODEC_ID_H264 && cfg->ConfigBitstreamRaw == 2)
  284. score = 2;
  285. else
  286. continue;
  287. if (IsEqualGUID(&cfg->guidConfigBitstreamEncryption, &DXVA2_NoEncrypt))
  288. score += 16;
  289. if (score > best_score) {
  290. best_score = score;
  291. best_cfg = *cfg;
  292. }
  293. }
  294. CoTaskMemFree(cfg_list);
  295. if (!best_score) {
  296. av_log(NULL, loglevel, "No valid decoder configuration available\n");
  297. return AVERROR(EINVAL);
  298. }
  299. *config = best_cfg;
  300. return 0;
  301. }
  302. static int dxva2_create_decoder(AVCodecContext *s)
  303. {
  304. InputStream *ist = s->opaque;
  305. int loglevel = (ist->hwaccel_id == HWACCEL_AUTO) ? AV_LOG_VERBOSE : AV_LOG_ERROR;
  306. DXVA2Context *ctx = ist->hwaccel_ctx;
  307. struct dxva_context *dxva_ctx = s->hwaccel_context;
  308. GUID *guid_list = NULL;
  309. unsigned guid_count = 0, i, j;
  310. GUID device_guid = GUID_NULL;
  311. D3DFORMAT target_format = 0;
  312. DXVA2_VideoDesc desc = { 0 };
  313. DXVA2_ConfigPictureDecode config;
  314. HRESULT hr;
  315. int surface_alignment, num_surfaces;
  316. int ret;
  317. AVDXVA2FramesContext *frames_hwctx;
  318. AVHWFramesContext *frames_ctx;
  319. hr = IDirectXVideoDecoderService_GetDecoderDeviceGuids(ctx->decoder_service, &guid_count, &guid_list);
  320. if (FAILED(hr)) {
  321. av_log(NULL, loglevel, "Failed to retrieve decoder device GUIDs\n");
  322. goto fail;
  323. }
  324. for (i = 0; dxva2_modes[i].guid; i++) {
  325. D3DFORMAT *target_list = NULL;
  326. unsigned target_count = 0;
  327. const dxva2_mode *mode = &dxva2_modes[i];
  328. if (mode->codec != s->codec_id)
  329. continue;
  330. for (j = 0; j < guid_count; j++) {
  331. if (IsEqualGUID(mode->guid, &guid_list[j]))
  332. break;
  333. }
  334. if (j == guid_count)
  335. continue;
  336. hr = IDirectXVideoDecoderService_GetDecoderRenderTargets(ctx->decoder_service, mode->guid, &target_count, &target_list);
  337. if (FAILED(hr)) {
  338. continue;
  339. }
  340. for (j = 0; j < target_count; j++) {
  341. const D3DFORMAT format = target_list[j];
  342. if (format == MKTAG('N','V','1','2')) {
  343. target_format = format;
  344. break;
  345. }
  346. }
  347. CoTaskMemFree(target_list);
  348. if (target_format) {
  349. device_guid = *mode->guid;
  350. break;
  351. }
  352. }
  353. CoTaskMemFree(guid_list);
  354. if (IsEqualGUID(&device_guid, &GUID_NULL)) {
  355. av_log(NULL, loglevel, "No decoder device for codec found\n");
  356. goto fail;
  357. }
  358. desc.SampleWidth = s->coded_width;
  359. desc.SampleHeight = s->coded_height;
  360. desc.Format = target_format;
  361. ret = dxva2_get_decoder_configuration(s, &device_guid, &desc, &config);
  362. if (ret < 0) {
  363. goto fail;
  364. }
  365. /* decoding MPEG-2 requires additional alignment on some Intel GPUs,
  366. but it causes issues for H.264 on certain AMD GPUs..... */
  367. if (s->codec_id == AV_CODEC_ID_MPEG2VIDEO)
  368. surface_alignment = 32;
  369. /* the HEVC DXVA2 spec asks for 128 pixel aligned surfaces to ensure
  370. all coding features have enough room to work with */
  371. else if (s->codec_id == AV_CODEC_ID_HEVC)
  372. surface_alignment = 128;
  373. else
  374. surface_alignment = 16;
  375. /* 4 base work surfaces */
  376. num_surfaces = 4;
  377. /* add surfaces based on number of possible refs */
  378. if (s->codec_id == AV_CODEC_ID_H264 || s->codec_id == AV_CODEC_ID_HEVC)
  379. num_surfaces += 16;
  380. else
  381. num_surfaces += 2;
  382. /* add extra surfaces for frame threading */
  383. if (s->active_thread_type & FF_THREAD_FRAME)
  384. num_surfaces += s->thread_count;
  385. ctx->hw_frames_ctx = av_hwframe_ctx_alloc(ctx->hw_device_ctx);
  386. if (!ctx->hw_frames_ctx)
  387. goto fail;
  388. frames_ctx = (AVHWFramesContext*)ctx->hw_frames_ctx->data;
  389. frames_hwctx = frames_ctx->hwctx;
  390. frames_ctx->format = AV_PIX_FMT_DXVA2_VLD;
  391. frames_ctx->sw_format = AV_PIX_FMT_NV12;
  392. frames_ctx->width = FFALIGN(s->coded_width, surface_alignment);
  393. frames_ctx->height = FFALIGN(s->coded_height, surface_alignment);
  394. frames_ctx->initial_pool_size = num_surfaces;
  395. frames_hwctx->surface_type = DXVA2_VideoDecoderRenderTarget;
  396. ret = av_hwframe_ctx_init(ctx->hw_frames_ctx);
  397. if (ret < 0) {
  398. av_log(NULL, loglevel, "Failed to initialize the HW frames context\n");
  399. goto fail;
  400. }
  401. hr = IDirectXVideoDecoderService_CreateVideoDecoder(ctx->decoder_service, &device_guid,
  402. &desc, &config, frames_hwctx->surfaces,
  403. frames_hwctx->nb_surfaces, &frames_hwctx->decoder_to_release);
  404. if (FAILED(hr)) {
  405. av_log(NULL, loglevel, "Failed to create DXVA2 video decoder\n");
  406. goto fail;
  407. }
  408. ctx->decoder_guid = device_guid;
  409. ctx->decoder_config = config;
  410. dxva_ctx->cfg = &ctx->decoder_config;
  411. dxva_ctx->decoder = frames_hwctx->decoder_to_release;
  412. dxva_ctx->surface = frames_hwctx->surfaces;
  413. dxva_ctx->surface_count = frames_hwctx->nb_surfaces;
  414. if (IsEqualGUID(&ctx->decoder_guid, &DXVADDI_Intel_ModeH264_E))
  415. dxva_ctx->workaround |= FF_DXVA2_WORKAROUND_INTEL_CLEARVIDEO;
  416. return 0;
  417. fail:
  418. av_buffer_unref(&ctx->hw_frames_ctx);
  419. return AVERROR(EINVAL);
  420. }
  421. int dxva2_init(AVCodecContext *s)
  422. {
  423. InputStream *ist = s->opaque;
  424. int loglevel = (ist->hwaccel_id == HWACCEL_AUTO) ? AV_LOG_VERBOSE : AV_LOG_ERROR;
  425. DXVA2Context *ctx;
  426. int ret;
  427. if (!ist->hwaccel_ctx) {
  428. ret = dxva2_alloc(s);
  429. if (ret < 0)
  430. return ret;
  431. }
  432. ctx = ist->hwaccel_ctx;
  433. if (s->codec_id == AV_CODEC_ID_H264 &&
  434. (s->profile & ~FF_PROFILE_H264_CONSTRAINED) > FF_PROFILE_H264_HIGH) {
  435. av_log(NULL, loglevel, "Unsupported H.264 profile for DXVA2 HWAccel: %d\n", s->profile);
  436. return AVERROR(EINVAL);
  437. }
  438. av_buffer_unref(&ctx->hw_frames_ctx);
  439. ret = dxva2_create_decoder(s);
  440. if (ret < 0) {
  441. av_log(NULL, loglevel, "Error creating the DXVA2 decoder\n");
  442. return ret;
  443. }
  444. return 0;
  445. }