dxva2: Retry IDirectXVideoDecoder_BeginFrame()
authorSam Lantinga <slouken@libsdl.org>
Thu, 9 Jan 2014 19:59:54 +0000 (19:59 +0000)
committerLuca Barbato <lu_zero@gentoo.org>
Tue, 21 Jan 2014 11:46:28 +0000 (12:46 +0100)
If the function returns E_PENDING retry for a fixed number of times.

Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
libavcodec/dxva2.c

index bc43cae..b6efa15 100644 (file)
@@ -87,12 +87,19 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, Picture *pic,
     unsigned               buffer_count = 0;
     DXVA2_DecodeBufferDesc buffer[4];
     DXVA2_DecodeExecuteParams exec = { 0 };
-    int      result;
-
-    if (FAILED(IDirectXVideoDecoder_BeginFrame(ctx->decoder,
-                                               ff_dxva2_get_surface(pic),
-                                               NULL))) {
-        av_log(avctx, AV_LOG_ERROR, "Failed to begin frame\n");
+    int result, runs = 0;
+    HRESULT hr;
+
+    do {
+        hr = IDirectXVideoDecoder_BeginFrame(ctx->decoder,
+                                             ff_dxva2_get_surface(pic),
+                                             NULL);
+        if (hr == E_PENDING)
+            av_usleep(2000);
+    } while (hr == E_PENDING && ++runs < 50);
+
+    if (FAILED(hr)) {
+        av_log(avctx, AV_LOG_ERROR, "Failed to begin frame: 0x%x\n", hr);
         return -1;
     }