[FFmpeg-devel] [PATCH v2 3/3] vaapi: fix usage of invalid buffer ids.

wm4 nfxjfg at googlemail.com
Wed Aug 19 11:56:55 CEST 2015


On Wed, 19 Aug 2015 11:03:06 +0200
Gwenole Beauchesne <gb.devel at gmail.com> wrote:

> Invalid buffer ids are defined by VA_INVALID_ID. Use that through out
> vaapi_*.c support files now that we have private data initialized and
> managed by libavcodec. Previously, the only requirement for the public
> vaapi_context struct was to be zero-initialized.
> 
> This fixes support for 3rdparty VA drivers that strictly conform to
> the API whereby an invalid buffer id is VA_INVALID_ID and the first
> valid buffer id can actually be zero.
> 
> Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne at intel.com>
> ---
>  libavcodec/vaapi.c | 20 ++++++++++++--------
>  1 file changed, 12 insertions(+), 8 deletions(-)
> 
> diff --git a/libavcodec/vaapi.c b/libavcodec/vaapi.c
> index 5dc43e1..d5f8fa2 100644
> --- a/libavcodec/vaapi.c
> +++ b/libavcodec/vaapi.c
> @@ -35,9 +35,9 @@ static void destroy_buffers(VADisplay display, VABufferID *buffers, unsigned int
>  {
>      unsigned int i;
>      for (i = 0; i < n_buffers; i++) {
> -        if (buffers[i]) {
> +        if (buffers[i] != VA_INVALID_ID) {
>              vaDestroyBuffer(display, buffers[i]);
> -            buffers[i] = 0;
> +            buffers[i] = VA_INVALID_ID;
>          }
>      }
>  }
> @@ -55,6 +55,10 @@ int ff_vaapi_context_init(AVCodecContext *avctx)
>      vactx->display              = user_vactx->display;
>      vactx->config_id            = user_vactx->config_id;
>      vactx->context_id           = user_vactx->context_id;
> +
> +    vactx->pic_param_buf_id     = VA_INVALID_ID;
> +    vactx->iq_matrix_buf_id     = VA_INVALID_ID;
> +    vactx->bitplane_buf_id      = VA_INVALID_ID;
>      return 0;
>  }
>  
> @@ -68,18 +72,18 @@ int ff_vaapi_render_picture(FFVAContext *vactx, VASurfaceID surface)
>      VABufferID va_buffers[3];
>      unsigned int n_va_buffers = 0;
>  
> -    if (!vactx->pic_param_buf_id)
> +    if (vactx->pic_param_buf_id == VA_INVALID_ID)
>          return 0;
>  
>      vaUnmapBuffer(vactx->display, vactx->pic_param_buf_id);
>      va_buffers[n_va_buffers++] = vactx->pic_param_buf_id;
>  
> -    if (vactx->iq_matrix_buf_id) {
> +    if (vactx->iq_matrix_buf_id != VA_INVALID_ID) {
>          vaUnmapBuffer(vactx->display, vactx->iq_matrix_buf_id);
>          va_buffers[n_va_buffers++] = vactx->iq_matrix_buf_id;
>      }
>  
> -    if (vactx->bitplane_buf_id) {
> +    if (vactx->bitplane_buf_id != VA_INVALID_ID) {
>          vaUnmapBuffer(vactx->display, vactx->bitplane_buf_id);
>          va_buffers[n_va_buffers++] = vactx->bitplane_buf_id;
>      }
> @@ -119,7 +123,7 @@ int ff_vaapi_commit_slices(FFVAContext *vactx)
>          return -1;
>      vactx->slice_buf_ids = slice_buf_ids;
>  
> -    slice_param_buf_id = 0;
> +    slice_param_buf_id = VA_INVALID_ID;
>      if (vaCreateBuffer(vactx->display, vactx->context_id,
>                         VASliceParameterBufferType,
>                         vactx->slice_param_size,
> @@ -128,7 +132,7 @@ int ff_vaapi_commit_slices(FFVAContext *vactx)
>          return -1;
>      vactx->slice_count = 0;
>  
> -    slice_data_buf_id = 0;
> +    slice_data_buf_id = VA_INVALID_ID;
>      if (vaCreateBuffer(vactx->display, vactx->context_id,
>                         VASliceDataBufferType,
>                         vactx->slice_data_size,
> @@ -147,7 +151,7 @@ static void *alloc_buffer(FFVAContext *vactx, int type, unsigned int size, uint3
>  {
>      void *data = NULL;
>  
> -    *buf_id = 0;
> +    *buf_id = VA_INVALID_ID;
>      if (vaCreateBuffer(vactx->display, vactx->context_id,
>                         type, size, 1, NULL, buf_id) == VA_STATUS_SUCCESS)
>          vaMapBuffer(vactx->display, *buf_id, &data);

All 3 patches look good, and I'd say they can be merged now.


More information about the ffmpeg-devel mailing list