[vlc-devel] [PATCH] DxVA2: improve the algorithm to look for the oldest buffer

Steve Lhomme robux4 at videolabs.io
Thu Apr 2 16:36:02 CEST 2015


On Thu, Apr 2, 2015 at 4:23 PM, Steve Lhomme <robux4 at videolabs.io> wrote:
> --
> Before it was using the oldest of the buffers already used. With this algo we use all the buffers and reuse them as later as possible.
> ---
>  modules/codec/avcodec/dxva2.c | 32 ++++++++++++++++----------------
>  1 file changed, 16 insertions(+), 16 deletions(-)
>
> diff --git a/modules/codec/avcodec/dxva2.c b/modules/codec/avcodec/dxva2.c
> index 76a1ebb..f87c325 100644
> --- a/modules/codec/avcodec/dxva2.c
> +++ b/modules/codec/avcodec/dxva2.c
> @@ -475,25 +475,23 @@ static int Get(vlc_va_t *va, void **opaque, uint8_t **data)
>
>      /* 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;
> -    for (i = 0, old = 0; i < sys->surface_count; i++) {
> +    unsigned i;
> +    vlc_va_surface_t *oldest = NULL;
> +    for (i = 0; i < sys->surface_count; i++) {
>          vlc_va_surface_t *surface = &sys->surface[i];
>
> -        if (!surface->refcount)
> -            break;
> -
> -        if (surface->order < sys->surface[old].order)
> -            old = i;
> +        if (!surface->refcount && (!oldest || surface->order < oldest->order))
> +            oldest = surface;
> +    }
> +    if ( oldest == NULL )
> +    {
> +        msg_Warn(va, "no free d3d surface found" );
> +        oldest = &sys->surface[0];
>      }
> -    if (i >= sys->surface_count)
> -        i = old;
> -
> -    vlc_va_surface_t *surface = &sys->surface[i];
>
> -    surface->refcount = 1;
> -    surface->order = sys->surface_order++;
> -    *data = (void *)surface->d3d;
> -    *opaque = surface;
> +    oldest->refcount = 1;
> +    *data = (void *)oldest->d3d;
> +    *opaque = oldest;
>
>      vlc_mutex_unlock( &sys->surface_lock );
>
> @@ -507,6 +505,7 @@ static void Release(void *opaque, uint8_t *data)
>      vlc_mutex_lock( &surface->sys->surface_lock );
>
>      surface->refcount--;
> +    surface->order = surface->sys->surface_order++;

This is the key part. The "age" is determined by when it was released,
not it was acquired.

>      (void) data;
>
>      vlc_mutex_unlock( &surface->sys->surface_lock );
> @@ -941,9 +940,10 @@ static int DxCreateVideoDecoder(vlc_va_t *va,
>          vlc_va_surface_t *surface = &sys->surface[i];
>          surface->d3d = sys->hw_surface[i];
>          surface->refcount = 0;
> -        surface->order = 0;
> +        surface->order = i;
>          surface->sys = sys;
>      }
> +    sys->surface_order = sys->surface_count;
>      msg_Dbg(va, "IDirectXVideoAccelerationService_CreateSurface succeed with %d surfaces (%dx%d)",
>              sys->surface_count, fmt->i_width, fmt->i_height);
>
> --
> 2.3.0
>
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel



More information about the vlc-devel mailing list