[vlc-commits] DXVA2: lock the buffer pool when getting/releasing a buffer

Steve Lhomme git at videolan.org
Mon Apr 27 14:05:58 CEST 2015


vlc | branch: master | Steve Lhomme <robUx4 at videolabs.io> | Thu Apr 23 05:12:12 2015 +0000| [9a23705530416d30a948c7646c9d9d1ccd866377] | committer: Jean-Baptiste Kempf

DXVA2: lock the buffer pool when getting/releasing a buffer

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

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

 modules/codec/avcodec/dxva2.c |   15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/modules/codec/avcodec/dxva2.c b/modules/codec/avcodec/dxva2.c
index 9fed97b..cbdda7f 100644
--- a/modules/codec/avcodec/dxva2.c
+++ b/modules/codec/avcodec/dxva2.c
@@ -311,6 +311,7 @@ typedef struct {
     LPDIRECT3DSURFACE9 d3d;
     int                refcount;
     unsigned int       order;
+    vlc_mutex_t        *p_lock;
 } vlc_va_surface_t;
 
 #define VA_DXVA2_MAX_SURFACE_COUNT (64)
@@ -320,6 +321,8 @@ struct vlc_va_sys_t
     int          width;
     int          height;
 
+    vlc_mutex_t     surface_lock;
+
     /* DLL */
     HINSTANCE             hd3d9_dll;
     HINSTANCE             hdxva2_dll;
@@ -507,6 +510,8 @@ static int Get(vlc_va_t *va, picture_t *pic, uint8_t **data)
         return VLC_EGENERIC;
     }
 
+    vlc_mutex_lock( &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 */
     unsigned i, old;
@@ -528,6 +533,9 @@ static int Get(vlc_va_t *va, picture_t *pic, uint8_t **data)
     surface->order = sys->surface_order++;
     *data = (void *)surface->d3d;
     pic->context = surface;
+
+    vlc_mutex_unlock( &sys->surface_lock );
+
     return VLC_SUCCESS;
 }
 
@@ -535,11 +543,14 @@ static void Release(void *opaque, uint8_t *data)
 {
     picture_t *pic = opaque;
     vlc_va_surface_t *surface = pic->context;
+    vlc_mutex_lock( surface->p_lock );
 
     surface->refcount--;
     pic->context = NULL;
     picture_Release(pic);
     (void) data;
+
+    vlc_mutex_unlock( surface->p_lock );
 }
 
 static void Close(vlc_va_t *va, AVCodecContext *ctx)
@@ -557,6 +568,7 @@ static void Close(vlc_va_t *va, AVCodecContext *ctx)
         FreeLibrary(sys->hdxva2_dll);
     if (sys->hd3d9_dll)
         FreeLibrary(sys->hd3d9_dll);
+    vlc_mutex_destroy( &sys->surface_lock );
 
     free((char *)va->description);
     free(sys);
@@ -575,6 +587,8 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,
     va->sys = sys;
     sys->codec_id = ctx->codec_id;
 
+    vlc_mutex_init( &sys->surface_lock );
+
     /* Load dll*/
     sys->hd3d9_dll = LoadLibrary(TEXT("D3D9.DLL"));
     if (!sys->hd3d9_dll) {
@@ -1018,6 +1032,7 @@ static int DxCreateVideoDecoder(vlc_va_t *va, int codec_id,
         surface->d3d = sys->hw_surface[i];
         surface->refcount = 0;
         surface->order = 0;
+        surface->p_lock = &sys->surface_lock;
     }
     msg_Dbg(va, "IDirectXVideoAccelerationService_CreateSurface succeed with %d surfaces (%dx%d)",
             sys->surface_count, fmt->i_width, fmt->i_height);



More information about the vlc-commits mailing list