Commit 7d3fc2a7 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

vaapi: protect potentially concurrent access to the surfaces table

parent b6dbbeaa
...@@ -80,6 +80,7 @@ struct vlc_va_sys_t ...@@ -80,6 +80,7 @@ struct vlc_va_sys_t
int i_version_minor; int i_version_minor;
/* */ /* */
vlc_mutex_t lock;
int i_surface_count; int i_surface_count;
unsigned int i_surface_order; unsigned int i_surface_order;
int i_surface_width; int i_surface_width;
...@@ -207,6 +208,8 @@ static int Open( vlc_va_t *va, int i_codec_id ) ...@@ -207,6 +208,8 @@ static int Open( vlc_va_t *va, int i_codec_id )
sys->b_supports_derive = false; sys->b_supports_derive = false;
vlc_mutex_init(&sys->lock);
if( asprintf( &va->description, "VA API version %d.%d", if( asprintf( &va->description, "VA API version %d.%d",
sys->i_version_major, sys->i_version_minor ) < 0 ) sys->i_version_major, sys->i_version_minor ) < 0 )
va->description = NULL; va->description = NULL;
...@@ -215,6 +218,7 @@ static int Open( vlc_va_t *va, int i_codec_id ) ...@@ -215,6 +218,7 @@ static int Open( vlc_va_t *va, int i_codec_id )
return VLC_SUCCESS; return VLC_SUCCESS;
error: error:
#warning Leaks!
return VLC_EGENERIC; return VLC_EGENERIC;
} }
...@@ -248,7 +252,9 @@ static void DestroySurfaces( vlc_va_sys_t *sys ) ...@@ -248,7 +252,9 @@ static void DestroySurfaces( vlc_va_sys_t *sys )
sys->p_surface = NULL; sys->p_surface = NULL;
sys->i_surface_width = 0; sys->i_surface_width = 0;
sys->i_surface_height = 0; sys->i_surface_height = 0;
vlc_mutex_destroy(&sys->lock);
} }
static int CreateSurfaces( vlc_va_sys_t *sys, void **pp_hw_ctx, vlc_fourcc_t *pi_chroma, static int CreateSurfaces( vlc_va_sys_t *sys, void **pp_hw_ctx, vlc_fourcc_t *pi_chroma,
int i_width, int i_height ) int i_width, int i_height )
{ {
...@@ -469,12 +475,14 @@ static int Extract( vlc_va_t *va, picture_t *p_picture, AVFrame *p_ff ) ...@@ -469,12 +475,14 @@ static int Extract( vlc_va_t *va, picture_t *p_picture, AVFrame *p_ff )
return VLC_SUCCESS; return VLC_SUCCESS;
} }
static int Get( vlc_va_t *va, AVFrame *p_ff ) static int Get( vlc_va_t *va, AVFrame *p_ff )
{ {
vlc_va_sys_t *sys = va->sys; vlc_va_sys_t *sys = va->sys;
int i_old; int i_old;
int i; int i;
vlc_mutex_lock( &sys->lock );
/* Grab an unused surface, in case none are, try the oldest /* Grab an unused surface, in case none are, try the oldest
* XXX using the oldest is a workaround in case a problem happens with ffmpeg */ * XXX using the oldest is a workaround in case a problem happens with ffmpeg */
for( i = 0, i_old = 0; i < sys->i_surface_count; i++ ) for( i = 0, i_old = 0; i < sys->i_surface_count; i++ )
...@@ -489,6 +497,7 @@ static int Get( vlc_va_t *va, AVFrame *p_ff ) ...@@ -489,6 +497,7 @@ static int Get( vlc_va_t *va, AVFrame *p_ff )
} }
if( i >= sys->i_surface_count ) if( i >= sys->i_surface_count )
i = i_old; i = i_old;
vlc_mutex_unlock( &sys->lock );
vlc_va_surface_t *p_surface = &sys->p_surface[i]; vlc_va_surface_t *p_surface = &sys->p_surface[i];
...@@ -506,12 +515,14 @@ static int Get( vlc_va_t *va, AVFrame *p_ff ) ...@@ -506,12 +515,14 @@ static int Get( vlc_va_t *va, AVFrame *p_ff )
} }
return VLC_SUCCESS; return VLC_SUCCESS;
} }
static void Release( vlc_va_t *va, AVFrame *p_ff ) static void Release( vlc_va_t *va, AVFrame *p_ff )
{ {
vlc_va_sys_t *sys = va->sys; vlc_va_sys_t *sys = va->sys;
VASurfaceID i_surface_id = (VASurfaceID)(uintptr_t)p_ff->data[3]; VASurfaceID i_surface_id = (VASurfaceID)(uintptr_t)p_ff->data[3];
vlc_mutex_lock( &sys->lock );
for( int i = 0; i < sys->i_surface_count; i++ ) for( int i = 0; i < sys->i_surface_count; i++ )
{ {
vlc_va_surface_t *p_surface = &sys->p_surface[i]; vlc_va_surface_t *p_surface = &sys->p_surface[i];
...@@ -519,6 +530,7 @@ static void Release( vlc_va_t *va, AVFrame *p_ff ) ...@@ -519,6 +530,7 @@ static void Release( vlc_va_t *va, AVFrame *p_ff )
if( p_surface->i_id == i_surface_id ) if( p_surface->i_id == i_surface_id )
p_surface->i_refcount--; p_surface->i_refcount--;
} }
vlc_mutex_unlock( &sys->lock );
} }
static void Close( vlc_va_sys_t *sys ) static void Close( vlc_va_sys_t *sys )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment