- hr = IDirectXVideoDecoder_BeginFrame(ctx->decoder,
- ff_dxva2_get_surface(frame),
- NULL);
- if (hr == E_PENDING)
- av_usleep(2000);
- } while (hr == E_PENDING && ++runs < 50);
+#if CONFIG_D3D11VA
+ if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) {
+ if (D3D11VA_CONTEXT(ctx)->context_mutex != INVALID_HANDLE_VALUE)
+ WaitForSingleObjectEx(D3D11VA_CONTEXT(ctx)->context_mutex, INFINITE, FALSE);
+ hr = ID3D11VideoContext_DecoderBeginFrame(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder,
+ ff_dxva2_get_surface(frame),
+ 0, NULL);
+ }
+#endif
+#if CONFIG_DXVA2
+ if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD)
+ hr = IDirectXVideoDecoder_BeginFrame(DXVA2_CONTEXT(ctx)->decoder,
+ ff_dxva2_get_surface(frame),
+ NULL);
+#endif
+ if (hr != E_PENDING || ++runs > 50)
+ break;
+#if CONFIG_D3D11VA
+ if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD)
+ if (D3D11VA_CONTEXT(ctx)->context_mutex != INVALID_HANDLE_VALUE)
+ ReleaseMutex(D3D11VA_CONTEXT(ctx)->context_mutex);
+#endif
+ av_usleep(2000);
+ } while(1);