[vlc-devel] [PATCH] avcodec: allocate more hardware surfaces for threaded decoding

Felix Abecassis felix.abecassis at gmail.com
Wed Mar 5 11:48:13 CET 2014


Merged, thanks for the help.

2014-03-04 21:43 GMT+01:00 Rémi Denis-Courmont <remi at remlab.net>:
> From: Felix Abecassis <felix.abecassis at gmail.com>
>
> 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: Rémi Denis-Courmont <remi at remlab.net>
> ---
>  modules/codec/avcodec/dxva2.c | 6 +++++-
>  modules/codec/avcodec/vaapi.c | 8 ++++----
>  2 files changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/modules/codec/avcodec/dxva2.c b/modules/codec/avcodec/dxva2.c
> index 1298a5f..f3a1524 100644
> --- a/modules/codec/avcodec/dxva2.c
> +++ b/modules/codec/avcodec/dxva2.c
> @@ -283,6 +283,8 @@ struct vlc_va_sys_t
>      int          surface_height;
>      vlc_fourcc_t surface_chroma;
>
> +    int          thread_count;
> +
>      vlc_va_surface_t 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,
>          goto error;
>      }
>
> +    va->thread_count = ctx->thread_count;
> +
>      /* TODO print the hardware name/vendor for debugging purposes */
>      external->description = DxDescribe(va);
>      external->pix_fmt = PIX_FMT_DXVA2_VLD;
> @@ -859,7 +863,7 @@ static int DxCreateVideoDecoder(vlc_va_dxva2_t *va,
>      int surface_count;
>      switch (codec_id) {
>      case AV_CODEC_ID_H264:
> -        surface_count = 16 + 1;
> +        surface_count = 16 + va->thread_count + 2;
>          break;
>      default:
>          surface_count = 2 + 1;
> diff --git a/modules/codec/avcodec/vaapi.c b/modules/codec/avcodec/vaapi.c
> index 139d781..14fc83d 100644
> --- a/modules/codec/avcodec/vaapi.c
> +++ b/modules/codec/avcodec/vaapi.c
> @@ -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) );
>      if ( unlikely(sys == NULL) )
> @@ -129,8 +129,8 @@ static int Open( vlc_va_t *va, int i_codec_id )
>          break;
>      case AV_CODEC_ID_H264:
>          i_profile = VAProfileH264High;
> -        i_surface_count = 16+1;
> -        break;
> +        i_surface_count = 16 + i_thread_count + 2;
> +        break;;
>      default:
>          return VLC_EGENERIC;
>      }
> @@ -552,7 +552,7 @@ static int Create( vlc_va_t *p_va, AVCodecContext *ctx,
>
>      (void) fmt;
>
> -    int err = Open( p_va, ctx->codec_id );
> +    int err = Open( p_va, ctx->codec_id, ctx->thread_count );
>      if( err )
>          return err;
>
> --
> 1.9.0
>
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel



-- 
Félix Abecassis
http://felix.abecassis.me



More information about the vlc-devel mailing list