[vlc-commits] directx_va: always use the oldest decoding buffer

Steve Lhomme git at videolan.org
Sun Aug 21 18:20:35 CEST 2016


vlc | branch: master | Steve Lhomme <robUx4 at videolabs.io> | Fri Aug 12 10:29:05 2016 +0200| [35e63080bcfc7c45078435eb9d23474824d7ecc2] | committer: Jean-Baptiste Kempf

directx_va: always use the oldest decoding buffer

Direct3D calls are pipelined and surface copies are not guaranteed to finish
after the call so reusing a surface that was requested to be copied produces
glitches in some cases. We use the surface that has been use the longest to
avoid this issue.

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=35e63080bcfc7c45078435eb9d23474824d7ecc2
---

 modules/codec/avcodec/directx_va.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/modules/codec/avcodec/directx_va.c b/modules/codec/avcodec/directx_va.c
index 5b8a894..3c12e0c 100644
--- a/modules/codec/avcodec/directx_va.c
+++ b/modules/codec/avcodec/directx_va.c
@@ -384,20 +384,24 @@ int directx_va_Get(vlc_va_t *va, directx_sys_t *dx_sys, picture_t *pic, uint8_t
 
     vlc_mutex_lock( &dx_sys->surface_lock );
 
-    /* Grab an unused surface, in case none are, try the oldest
-     * XXX using the oldest is a workaround in case a problem happens with libavcodec */
-    int i, old;
-    for (i = 0, old = 0; i < dx_sys->surface_count; i++) {
-        vlc_va_surface_t *surface = &dx_sys->surface[i];
-
-        if (!surface->refcount)
-            break;
+    /* Grab the oldest unused surface, in case none are, use the oldest used one
+     * XXX using the used one is a workaround in case a problem happens with libavcodec */
+    int i, old = -1, old_used = -1;
 
-        if (surface->order < dx_sys->surface[old].order)
+    for (i = 0; i < dx_sys->surface_count; i++) {
+        vlc_va_surface_t *surface = &dx_sys->surface[i];
+        if ((old == -1 || surface->order < dx_sys->surface[old].order) && !surface->refcount)
             old = i;
+        if (old_used == -1 || surface->order < dx_sys->surface[old_used].order)
+            old_used = i;
     }
-    if (i >= dx_sys->surface_count)
+    if (old >= 0)
         i = old;
+    else if (old_used >= 0)
+    {
+        msg_Warn(va, "couldn't find a free decoding buffer, using index %d", old_used);
+        i = old_used;
+    }
 
     vlc_va_surface_t *surface = &dx_sys->surface[i];
 



More information about the vlc-commits mailing list