vlc | branch: master | Rémi Denis-Courmont <[email protected]> | Wed Jul 24 
22:48:50 2013 +0300| [2392db7de488cfc960278c2aa7888d8e7809b948] | committer: 
Rémi Denis-Courmont

vdpau: fix surface leaks if the picture is not extracted

This can happen in some corner cases such as flushing (luckily the leak
would automatically be resolved when the device instance is released).

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

 modules/hw/vdpau/avcodec.c |   27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/modules/hw/vdpau/avcodec.c b/modules/hw/vdpau/avcodec.c
index d9d04e4..f243240 100644
--- a/modules/hw/vdpau/avcodec.c
+++ b/modules/hw/vdpau/avcodec.c
@@ -81,26 +81,41 @@ static int Lock(vlc_va_t *va, AVFrame *ff)
         return VLC_EGENERIC;
     }
 
+    vlc_vdp_video_field_t *field = vlc_vdp_video_create(sys->vdp, surface);
+    if (unlikely(field == NULL))
+        return VLC_ENOMEM;
+
     ff->data[0] = (void *)sys->vdp; /* must be non-NULL */
     ff->data[3] = (void *)(uintptr_t)surface;
-    ff->opaque = (void *)(uintptr_t)surface;
+    ff->opaque = field;
     return VLC_SUCCESS;
 }
 
 static void Unlock(vlc_va_t *va, AVFrame *ff)
 {
-    (void) va;
+    vlc_vdp_video_field_t *field = ff->opaque;
+
+    assert(field != NULL);
+    field->destroy(field);
+
     ff->data[0] = ff->data[3] = NULL;
     ff->opaque = NULL;
+    (void) va;
 }
 
 static int Copy(vlc_va_t *va, picture_t *pic, AVFrame *ff)
 {
-    vlc_va_sys_t *sys = va->sys;
-    VdpVideoSurface surface = (uintptr_t)ff->opaque;
+    vlc_vdp_video_field_t *field = ff->opaque;
+
+    assert(field != NULL);
+    field = vlc_vdp_video_copy(field);
+    if (unlikely(field == NULL))
+        return VLC_ENOMEM;
 
-    return vlc_vdp_video_attach(sys->vdp, surface, pic)
-        ? VLC_ENOMEM : VLC_SUCCESS;
+    assert(pic->context == NULL);
+    pic->context = field;
+    (void) va;
+    return VLC_SUCCESS;
 }
 
 static int Init(vlc_va_t *va, void **ctxp, vlc_fourcc_t *chromap,

_______________________________________________
vlc-commits mailing list
[email protected]
http://mailman.videolan.org/listinfo/vlc-commits

Reply via email to