Commit 47a9e86e authored by Felix Abecassis's avatar Felix Abecassis

avcodec: allocate more hardware surfaces for threaded decoding

The number of threads impacts the number of surfaces that should be
allocated by the HW acceleration backend. If not enough surfaces are
allocated, the VAAPI and DXVA modules returned the oldest surface
currently in used. This technique can cause many visual glitches with
some samples. The number of allocated surfaces now scales with the
number of threads used by avcodec.

Fix #9887
Signed-off-by: default avatarRémi Denis-Courmont <remi@remlab.net>
parent e31fb2a4
...@@ -283,6 +283,8 @@ struct vlc_va_sys_t ...@@ -283,6 +283,8 @@ struct vlc_va_sys_t
int surface_height; int surface_height;
vlc_fourcc_t surface_chroma; vlc_fourcc_t surface_chroma;
int thread_count;
vlc_va_surface_t surface[VA_DXVA2_MAX_SURFACE_COUNT]; vlc_va_surface_t surface[VA_DXVA2_MAX_SURFACE_COUNT];
LPDIRECT3DSURFACE9 hw_surface[VA_DXVA2_MAX_SURFACE_COUNT]; LPDIRECT3DSURFACE9 hw_surface[VA_DXVA2_MAX_SURFACE_COUNT];
}; };
...@@ -541,6 +543,8 @@ static int Open(vlc_va_t *external, AVCodecContext *ctx, ...@@ -541,6 +543,8 @@ static int Open(vlc_va_t *external, AVCodecContext *ctx,
goto error; goto error;
} }
va->thread_count = ctx->thread_count;
/* TODO print the hardware name/vendor for debugging purposes */ /* TODO print the hardware name/vendor for debugging purposes */
external->description = DxDescribe(va); external->description = DxDescribe(va);
external->pix_fmt = PIX_FMT_DXVA2_VLD; external->pix_fmt = PIX_FMT_DXVA2_VLD;
...@@ -859,7 +863,7 @@ static int DxCreateVideoDecoder(vlc_va_dxva2_t *va, ...@@ -859,7 +863,7 @@ static int DxCreateVideoDecoder(vlc_va_dxva2_t *va,
int surface_count; int surface_count;
switch (codec_id) { switch (codec_id) {
case AV_CODEC_ID_H264: case AV_CODEC_ID_H264:
surface_count = 16 + 1; surface_count = 16 + va->thread_count + 2;
break; break;
default: default:
surface_count = 2 + 1; surface_count = 2 + 1;
......
...@@ -96,7 +96,7 @@ struct vlc_va_sys_t ...@@ -96,7 +96,7 @@ struct vlc_va_sys_t
}; };
/* */ /* */
static int Open( vlc_va_t *va, int i_codec_id ) static int Open( vlc_va_t *va, int i_codec_id, int i_thread_count )
{ {
vlc_va_sys_t *sys = calloc( 1, sizeof(*sys) ); vlc_va_sys_t *sys = calloc( 1, sizeof(*sys) );
if ( unlikely(sys == NULL) ) if ( unlikely(sys == NULL) )
...@@ -129,8 +129,8 @@ static int Open( vlc_va_t *va, int i_codec_id ) ...@@ -129,8 +129,8 @@ static int Open( vlc_va_t *va, int i_codec_id )
break; break;
case AV_CODEC_ID_H264: case AV_CODEC_ID_H264:
i_profile = VAProfileH264High; i_profile = VAProfileH264High;
i_surface_count = 16+1; i_surface_count = 16 + i_thread_count + 2;
break; break;;
default: default:
return VLC_EGENERIC; return VLC_EGENERIC;
} }
...@@ -552,7 +552,7 @@ static int Create( vlc_va_t *p_va, AVCodecContext *ctx, ...@@ -552,7 +552,7 @@ static int Create( vlc_va_t *p_va, AVCodecContext *ctx,
(void) fmt; (void) fmt;
int err = Open( p_va, ctx->codec_id ); int err = Open( p_va, ctx->codec_id, ctx->thread_count );
if( err ) if( err )
return err; return err;
......
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