Store them in private data instead.
---
 libavcodec/vaapi.c          | 125 ++++++++++++++++++++++++--------------------
 libavcodec/vaapi.h          |  17 ++++++
 libavcodec/vaapi_h264.c     |  14 ++---
 libavcodec/vaapi_internal.h |  76 ++++++++++++++++++++++++---
 libavcodec/vaapi_mpeg2.c    |  10 ++--
 libavcodec/vaapi_mpeg4.c    |  11 ++--
 libavcodec/vaapi_vc1.c      |  11 ++--
 libavcodec/version.h        |   3 ++
 8 files changed, 185 insertions(+), 82 deletions(-)

diff --git a/libavcodec/vaapi.c b/libavcodec/vaapi.c
index d00be2f..befc681 100644
--- a/libavcodec/vaapi.c
+++ b/libavcodec/vaapi.c
@@ -42,22 +42,24 @@ static void destroy_buffers(VADisplay display, VABufferID 
*buffers, unsigned int
     }
 }
 
-int ff_vaapi_render_picture(struct vaapi_context *vactx, VASurfaceID surface)
+int ff_vaapi_render_picture(AVCodecContext *avctx, struct vaapi_context *vactx,
+                            VASurfaceID surface)
 {
+    VAAPIContext *s = avctx->internal->hwaccel_priv_data;
     VABufferID va_buffers[3];
     unsigned int n_va_buffers = 0;
 
-    vaUnmapBuffer(vactx->display, vactx->pic_param_buf_id);
-    va_buffers[n_va_buffers++] = vactx->pic_param_buf_id;
+    vaUnmapBuffer(vactx->display, s->pic_param_buf_id);
+    va_buffers[n_va_buffers++] = s->pic_param_buf_id;
 
-    if (vactx->iq_matrix_buf_id) {
-        vaUnmapBuffer(vactx->display, vactx->iq_matrix_buf_id);
-        va_buffers[n_va_buffers++] = vactx->iq_matrix_buf_id;
+    if (s->iq_matrix_buf_id) {
+        vaUnmapBuffer(vactx->display, s->iq_matrix_buf_id);
+        va_buffers[n_va_buffers++] = s->iq_matrix_buf_id;
     }
 
-    if (vactx->bitplane_buf_id) {
-        vaUnmapBuffer(vactx->display, vactx->bitplane_buf_id);
-        va_buffers[n_va_buffers++] = vactx->bitplane_buf_id;
+    if (s->bitplane_buf_id) {
+        vaUnmapBuffer(vactx->display, s->bitplane_buf_id);
+        va_buffers[n_va_buffers++] = s->bitplane_buf_id;
     }
 
     if (vaBeginPicture(vactx->display, vactx->context_id,
@@ -69,8 +71,8 @@ int ff_vaapi_render_picture(struct vaapi_context *vactx, 
VASurfaceID surface)
         return -1;
 
     if (vaRenderPicture(vactx->display, vactx->context_id,
-                        vactx->slice_buf_ids,
-                        vactx->n_slice_buf_ids) != VA_STATUS_SUCCESS)
+                        s->slice_buf_ids,
+                        s->n_slice_buf_ids) != VA_STATUS_SUCCESS)
         return -1;
 
     if (vaEndPicture(vactx->display, vactx->context_id) != VA_STATUS_SUCCESS)
@@ -79,43 +81,44 @@ int ff_vaapi_render_picture(struct vaapi_context *vactx, 
VASurfaceID surface)
     return 0;
 }
 
-int ff_vaapi_commit_slices(struct vaapi_context *vactx)
+int ff_vaapi_commit_slices(AVCodecContext *avctx, struct vaapi_context *vactx)
 {
+    VAAPIContext *s = avctx->internal->hwaccel_priv_data;
     VABufferID *slice_buf_ids;
     VABufferID slice_param_buf_id, slice_data_buf_id;
 
-    if (vactx->slice_count == 0)
+    if (s->slice_count == 0)
         return 0;
 
     slice_buf_ids =
-        av_fast_realloc(vactx->slice_buf_ids,
-                        &vactx->slice_buf_ids_alloc,
-                        (vactx->n_slice_buf_ids + 2) * 
sizeof(slice_buf_ids[0]));
+        av_fast_realloc(s->slice_buf_ids,
+                        &s->slice_buf_ids_alloc,
+                        (s->n_slice_buf_ids + 2) * sizeof(slice_buf_ids[0]));
     if (!slice_buf_ids)
         return -1;
-    vactx->slice_buf_ids = slice_buf_ids;
+    s->slice_buf_ids = slice_buf_ids;
 
     slice_param_buf_id = 0;
     if (vaCreateBuffer(vactx->display, vactx->context_id,
                        VASliceParameterBufferType,
-                       vactx->slice_param_size,
-                       vactx->slice_count, vactx->slice_params,
+                       s->slice_param_size,
+                       s->slice_count, s->slice_params,
                        &slice_param_buf_id) != VA_STATUS_SUCCESS)
         return -1;
-    vactx->slice_count = 0;
+    s->slice_count = 0;
 
     slice_data_buf_id = 0;
     if (vaCreateBuffer(vactx->display, vactx->context_id,
                        VASliceDataBufferType,
-                       vactx->slice_data_size,
-                       1, (void *)vactx->slice_data,
+                       s->slice_data_size,
+                       1, (void *)s->slice_data,
                        &slice_data_buf_id) != VA_STATUS_SUCCESS)
         return -1;
-    vactx->slice_data = NULL;
-    vactx->slice_data_size = 0;
+    s->slice_data = NULL;
+    s->slice_data_size = 0;
 
-    slice_buf_ids[vactx->n_slice_buf_ids++] = slice_param_buf_id;
-    slice_buf_ids[vactx->n_slice_buf_ids++] = slice_data_buf_id;
+    slice_buf_ids[s->n_slice_buf_ids++] = slice_param_buf_id;
+    slice_buf_ids[s->n_slice_buf_ids++] = slice_data_buf_id;
     return 0;
 }
 
@@ -131,68 +134,74 @@ static void *alloc_buffer(struct vaapi_context *vactx, 
int type, unsigned int si
     return data;
 }
 
-void *ff_vaapi_alloc_pic_param(struct vaapi_context *vactx, unsigned int size)
+void *ff_vaapi_alloc_pic_param(AVCodecContext *avctx, struct vaapi_context 
*vactx, unsigned int size)
 {
-    return alloc_buffer(vactx, VAPictureParameterBufferType, size, 
&vactx->pic_param_buf_id);
+    VAAPIContext *s = avctx->internal->hwaccel_priv_data;
+    return alloc_buffer(vactx, VAPictureParameterBufferType, size, 
&s->pic_param_buf_id);
 }
 
-void *ff_vaapi_alloc_iq_matrix(struct vaapi_context *vactx, unsigned int size)
+void *ff_vaapi_alloc_iq_matrix(AVCodecContext *avctx, struct vaapi_context 
*vactx, unsigned int size)
 {
-    return alloc_buffer(vactx, VAIQMatrixBufferType, size, 
&vactx->iq_matrix_buf_id);
+    VAAPIContext *s = avctx->internal->hwaccel_priv_data;
+    return alloc_buffer(vactx, VAIQMatrixBufferType, size, 
&s->iq_matrix_buf_id);
 }
 
-uint8_t *ff_vaapi_alloc_bitplane(struct vaapi_context *vactx, uint32_t size)
+uint8_t *ff_vaapi_alloc_bitplane(AVCodecContext *avctx, struct vaapi_context 
*vactx, uint32_t size)
 {
-    return alloc_buffer(vactx, VABitPlaneBufferType, size, 
&vactx->bitplane_buf_id);
+    VAAPIContext *s = avctx->internal->hwaccel_priv_data;
+    return alloc_buffer(vactx, VABitPlaneBufferType, size, 
&s->bitplane_buf_id);
 }
 
-VASliceParameterBufferBase *ff_vaapi_alloc_slice(struct vaapi_context *vactx, 
const uint8_t *buffer, uint32_t size)
+VASliceParameterBufferBase *ff_vaapi_alloc_slice(AVCodecContext *avctx, struct 
vaapi_context *vactx,
+                                                 const uint8_t *buffer, 
uint32_t size)
 {
+    VAAPIContext *s = avctx->internal->hwaccel_priv_data;
     uint8_t *slice_params;
     VASliceParameterBufferBase *slice_param;
 
-    if (!vactx->slice_data)
-        vactx->slice_data = buffer;
-    if (vactx->slice_data + vactx->slice_data_size != buffer) {
-        if (ff_vaapi_commit_slices(vactx) < 0)
+    if (!s->slice_data)
+        s->slice_data = buffer;
+    if (s->slice_data + s->slice_data_size != buffer) {
+        if (ff_vaapi_commit_slices(avctx, vactx) < 0)
             return NULL;
-        vactx->slice_data = buffer;
+        s->slice_data = buffer;
     }
 
     slice_params =
-        av_fast_realloc(vactx->slice_params,
-                        &vactx->slice_params_alloc,
-                        (vactx->slice_count + 1) * vactx->slice_param_size);
+        av_fast_realloc(s->slice_params,
+                        &s->slice_params_alloc,
+                        (s->slice_count + 1) * s->slice_param_size);
     if (!slice_params)
         return NULL;
-    vactx->slice_params = slice_params;
+    s->slice_params = slice_params;
 
-    slice_param = (VASliceParameterBufferBase *)(slice_params + 
vactx->slice_count * vactx->slice_param_size);
+    slice_param = (VASliceParameterBufferBase *)(slice_params + s->slice_count 
* s->slice_param_size);
     slice_param->slice_data_size   = size;
-    slice_param->slice_data_offset = vactx->slice_data_size;
+    slice_param->slice_data_offset = s->slice_data_size;
     slice_param->slice_data_flag   = VA_SLICE_DATA_FLAG_ALL;
 
-    vactx->slice_count++;
-    vactx->slice_data_size += size;
+    s->slice_count++;
+    s->slice_data_size += size;
     return slice_param;
 }
 
 void ff_vaapi_common_end_frame(AVCodecContext *avctx)
 {
+    VAAPIContext *s = avctx->internal->hwaccel_priv_data;
     struct vaapi_context * const vactx = avctx->hwaccel_context;
 
     ff_dlog(avctx, "ff_vaapi_common_end_frame()\n");
 
-    destroy_buffers(vactx->display, &vactx->pic_param_buf_id, 1);
-    destroy_buffers(vactx->display, &vactx->iq_matrix_buf_id, 1);
-    destroy_buffers(vactx->display, &vactx->bitplane_buf_id, 1);
-    destroy_buffers(vactx->display, vactx->slice_buf_ids, 
vactx->n_slice_buf_ids);
-    av_freep(&vactx->slice_buf_ids);
-    av_freep(&vactx->slice_params);
-    vactx->n_slice_buf_ids     = 0;
-    vactx->slice_buf_ids_alloc = 0;
-    vactx->slice_count         = 0;
-    vactx->slice_params_alloc  = 0;
+    destroy_buffers(vactx->display, &s->pic_param_buf_id, 1);
+    destroy_buffers(vactx->display, &s->iq_matrix_buf_id, 1);
+    destroy_buffers(vactx->display, &s->bitplane_buf_id, 1);
+    destroy_buffers(vactx->display, s->slice_buf_ids, s->n_slice_buf_ids);
+    av_freep(&s->slice_buf_ids);
+    av_freep(&s->slice_params);
+    s->n_slice_buf_ids     = 0;
+    s->slice_buf_ids_alloc = 0;
+    s->slice_count         = 0;
+    s->slice_params_alloc  = 0;
 }
 
 #if CONFIG_H263_VAAPI_HWACCEL  || CONFIG_MPEG1_VAAPI_HWACCEL || \
@@ -204,11 +213,11 @@ int ff_vaapi_mpeg_end_frame(AVCodecContext *avctx)
     MpegEncContext *s = avctx->priv_data;
     int ret;
 
-    ret = ff_vaapi_commit_slices(vactx);
+    ret = ff_vaapi_commit_slices(avctx, vactx);
     if (ret < 0)
         goto finish;
 
-    ret = ff_vaapi_render_picture(vactx,
+    ret = ff_vaapi_render_picture(avctx, vactx,
                                   
ff_vaapi_get_surface_id(s->current_picture_ptr->f));
     if (ret < 0)
         goto finish;
diff --git a/libavcodec/vaapi.h b/libavcodec/vaapi.h
index 39e8825..ea206a5 100644
--- a/libavcodec/vaapi.h
+++ b/libavcodec/vaapi.h
@@ -32,6 +32,9 @@
 
 #include <stdint.h>
 
+#include "version.h"
+#include "libavutil/attributes.h"
+
 /**
  * @defgroup lavc_codec_hwaccel_vaapi VA API Decoding
  * @ingroup lavc_codec_hwaccel
@@ -72,12 +75,14 @@ struct vaapi_context {
      */
     uint32_t context_id;
 
+#if FF_API_VAAPI_PRIVATE
     /**
      * VAPictureParameterBuffer ID
      *
      * - encoding: unused
      * - decoding: Set by libavcodec
      */
+    attribute_deprecated
     uint32_t pic_param_buf_id;
 
     /**
@@ -86,6 +91,7 @@ struct vaapi_context {
      * - encoding: unused
      * - decoding: Set by libavcodec
      */
+    attribute_deprecated
     uint32_t iq_matrix_buf_id;
 
     /**
@@ -94,6 +100,7 @@ struct vaapi_context {
      * - encoding: unused
      * - decoding: Set by libavcodec
      */
+    attribute_deprecated
     uint32_t bitplane_buf_id;
 
     /**
@@ -102,6 +109,7 @@ struct vaapi_context {
      * - encoding: unused
      * - decoding: Set by libavcodec
      */
+    attribute_deprecated
     uint32_t *slice_buf_ids;
 
     /**
@@ -110,6 +118,7 @@ struct vaapi_context {
      * - encoding: unused
      * - decoding: Set by libavcodec
      */
+    attribute_deprecated
     unsigned int n_slice_buf_ids;
 
     /**
@@ -118,6 +127,7 @@ struct vaapi_context {
      * - encoding: unused
      * - decoding: Set by libavcodec
      */
+    attribute_deprecated
     unsigned int slice_buf_ids_alloc;
 
     /**
@@ -126,6 +136,7 @@ struct vaapi_context {
      * - encoding: unused
      * - decoding: Set by libavcodec
      */
+    attribute_deprecated
     void *slice_params;
 
     /**
@@ -134,6 +145,7 @@ struct vaapi_context {
      * - encoding: unused
      * - decoding: Set by libavcodec
      */
+    attribute_deprecated
     unsigned int slice_param_size;
 
     /**
@@ -142,6 +154,7 @@ struct vaapi_context {
      * - encoding: unused
      * - decoding: Set by libavcodec
      */
+    attribute_deprecated
     unsigned int slice_params_alloc;
 
     /**
@@ -150,6 +163,7 @@ struct vaapi_context {
      * - encoding: unused
      * - decoding: Set by libavcodec
      */
+    attribute_deprecated
     unsigned int slice_count;
 
     /**
@@ -157,6 +171,7 @@ struct vaapi_context {
      * - encoding: unused
      * - decoding: Set by libavcodec
      */
+    attribute_deprecated
     const uint8_t *slice_data;
 
     /**
@@ -165,7 +180,9 @@ struct vaapi_context {
      * - encoding: unused
      * - decoding: Set by libavcodec
      */
+    attribute_deprecated
     uint32_t slice_data_size;
+#endif
 };
 
 /* @} */
diff --git a/libavcodec/vaapi_h264.c b/libavcodec/vaapi_h264.c
index 82a49f6..ec1c677 100644
--- a/libavcodec/vaapi_h264.c
+++ b/libavcodec/vaapi_h264.c
@@ -225,6 +225,7 @@ static int vaapi_h264_start_frame(AVCodecContext          
*avctx,
                                   av_unused const uint8_t *buffer,
                                   av_unused uint32_t       size)
 {
+    VAAPIContext *s = avctx->internal->hwaccel_priv_data;
     H264Context * const h = avctx->priv_data;
     struct vaapi_context * const vactx = avctx->hwaccel_context;
     VAPictureParameterBufferH264 *pic_param;
@@ -232,10 +233,10 @@ static int vaapi_h264_start_frame(AVCodecContext          
*avctx,
 
     ff_dlog(avctx, "vaapi_h264_start_frame()\n");
 
-    vactx->slice_param_size = sizeof(VASliceParameterBufferH264);
+    s->slice_param_size = sizeof(VASliceParameterBufferH264);
 
     /* Fill in VAPictureParameterBufferH264. */
-    pic_param = ff_vaapi_alloc_pic_param(vactx, 
sizeof(VAPictureParameterBufferH264));
+    pic_param = ff_vaapi_alloc_pic_param(avctx, vactx, 
sizeof(VAPictureParameterBufferH264));
     if (!pic_param)
         return -1;
     fill_vaapi_pic(&pic_param->CurrPic, h->cur_pic_ptr, h->picture_structure);
@@ -279,7 +280,7 @@ static int vaapi_h264_start_frame(AVCodecContext          
*avctx,
     pic_param->frame_num                                        = h->frame_num;
 
     /* Fill in VAIQMatrixBufferH264. */
-    iq_matrix = ff_vaapi_alloc_iq_matrix(vactx, sizeof(VAIQMatrixBufferH264));
+    iq_matrix = ff_vaapi_alloc_iq_matrix(avctx, vactx, 
sizeof(VAIQMatrixBufferH264));
     if (!iq_matrix)
         return -1;
     memcpy(iq_matrix->ScalingList4x4, h->pps.scaling_matrix4, 
sizeof(iq_matrix->ScalingList4x4));
@@ -297,11 +298,11 @@ static int vaapi_h264_end_frame(AVCodecContext *avctx)
     int ret;
 
     ff_dlog(avctx, "vaapi_h264_end_frame()\n");
-    ret = ff_vaapi_commit_slices(vactx);
+    ret = ff_vaapi_commit_slices(avctx, vactx);
     if (ret < 0)
         goto finish;
 
-    ret = ff_vaapi_render_picture(vactx, 
ff_vaapi_get_surface_id(h->cur_pic_ptr->f));
+    ret = ff_vaapi_render_picture(avctx, vactx, 
ff_vaapi_get_surface_id(h->cur_pic_ptr->f));
     if (ret < 0)
         goto finish;
 
@@ -325,7 +326,7 @@ static int vaapi_h264_decode_slice(AVCodecContext *avctx,
             buffer, size);
 
     /* Fill in VASliceParameterBufferH264. */
-    slice_param = (VASliceParameterBufferH264 
*)ff_vaapi_alloc_slice(avctx->hwaccel_context, buffer, size);
+    slice_param = (VASliceParameterBufferH264 *)ff_vaapi_alloc_slice(avctx, 
avctx->hwaccel_context, buffer, size);
     if (!slice_param)
         return -1;
     slice_param->slice_data_bit_offset          = get_bits_count(&sl->gb) + 8; 
/* bit buffer started beyond nal_unit_type */
@@ -362,4 +363,5 @@ AVHWAccel ff_h264_vaapi_hwaccel = {
     .start_frame    = vaapi_h264_start_frame,
     .end_frame      = vaapi_h264_end_frame,
     .decode_slice   = vaapi_h264_decode_slice,
+    .priv_data_size = sizeof(VAAPIContext),
 };
diff --git a/libavcodec/vaapi_internal.h b/libavcodec/vaapi_internal.h
index 5e2a6ca..953b1c2 100644
--- a/libavcodec/vaapi_internal.h
+++ b/libavcodec/vaapi_internal.h
@@ -34,6 +34,68 @@
  * @{
  */
 
+typedef struct VAAPIContext {
+    /**
+     * VAPictureParameterBuffer ID
+     */
+    uint32_t pic_param_buf_id;
+
+    /**
+     * VAIQMatrixBuffer ID
+     */
+    uint32_t iq_matrix_buf_id;
+
+    /**
+     * VABitPlaneBuffer ID (for VC-1 decoding)
+     */
+    uint32_t bitplane_buf_id;
+
+    /**
+     * Slice parameter/data buffer IDs
+     */
+    uint32_t *slice_buf_ids;
+
+    /**
+     * Number of effective slice buffer IDs to send to the HW
+     */
+    unsigned int n_slice_buf_ids;
+
+    /**
+     * Size of pre-allocated slice_buf_ids
+     */
+    unsigned int slice_buf_ids_alloc;
+
+    /**
+     * Pointer to VASliceParameterBuffers
+     */
+    void *slice_params;
+
+    /**
+     * Size of a VASliceParameterBuffer element
+     */
+    unsigned int slice_param_size;
+
+    /**
+     * Size of pre-allocated slice_params
+     */
+    unsigned int slice_params_alloc;
+
+    /**
+     * Number of slices currently filled in
+     */
+    unsigned int slice_count;
+
+    /**
+     * Pointer to slice data buffer base
+     */
+    const uint8_t *slice_data;
+
+    /**
+     * Current size of slice data
+     */
+    uint32_t slice_data_size;
+} VAAPIContext;
+
 /** Extract VASurfaceID from an AVFrame */
 static inline VASurfaceID ff_vaapi_get_surface_id(AVFrame *pic)
 {
@@ -44,13 +106,14 @@ static inline VASurfaceID ff_vaapi_get_surface_id(AVFrame 
*pic)
 void ff_vaapi_common_end_frame(AVCodecContext *avctx);
 
 /** Allocate a new picture parameter buffer */
-void *ff_vaapi_alloc_pic_param(struct vaapi_context *vactx, unsigned int size);
+void *ff_vaapi_alloc_pic_param(AVCodecContext *avctx, struct vaapi_context 
*vactx,
+                               unsigned int size);
 
 /** Allocate a new IQ matrix buffer */
-void *ff_vaapi_alloc_iq_matrix(struct vaapi_context *vactx, unsigned int size);
+void *ff_vaapi_alloc_iq_matrix(AVCodecContext *avctx, struct vaapi_context 
*vactx, unsigned int size);
 
 /** Allocate a new bit-plane buffer */
-uint8_t *ff_vaapi_alloc_bitplane(struct vaapi_context *vactx, uint32_t size);
+uint8_t *ff_vaapi_alloc_bitplane(AVCodecContext *avctx, struct vaapi_context 
*vactx, uint32_t size);
 
 /**
  * Allocate a new slice descriptor for the input slice.
@@ -60,11 +123,12 @@ uint8_t *ff_vaapi_alloc_bitplane(struct vaapi_context 
*vactx, uint32_t size);
  * @param size the size of the slice in bytes
  * @return the newly allocated slice parameter
  */
-VASliceParameterBufferBase *ff_vaapi_alloc_slice(struct vaapi_context *vactx, 
const uint8_t *buffer, uint32_t size);
+VASliceParameterBufferBase *ff_vaapi_alloc_slice(AVCodecContext *avctx, struct 
vaapi_context *vactx,
+                                                 const uint8_t *buffer, 
uint32_t size);
 
 int ff_vaapi_mpeg_end_frame(AVCodecContext *avctx);
-int ff_vaapi_commit_slices(struct vaapi_context *vactx);
-int ff_vaapi_render_picture(struct vaapi_context *vactx, VASurfaceID surface);
+int ff_vaapi_commit_slices(AVCodecContext *avctx, struct vaapi_context *vactx);
+int ff_vaapi_render_picture(AVCodecContext *avctx, struct vaapi_context 
*vactx, VASurfaceID surface);
 
 /* @} */
 
diff --git a/libavcodec/vaapi_mpeg2.c b/libavcodec/vaapi_mpeg2.c
index 7d0e205..b5da9ba 100644
--- a/libavcodec/vaapi_mpeg2.c
+++ b/libavcodec/vaapi_mpeg2.c
@@ -40,6 +40,7 @@ static inline int mpeg2_get_is_frame_start(MpegEncContext *s)
 
 static int vaapi_mpeg2_start_frame(AVCodecContext *avctx, av_unused const 
uint8_t *buffer, av_unused uint32_t size)
 {
+    VAAPIContext *ctx = avctx->internal->hwaccel_priv_data;
     struct MpegEncContext * const s = avctx->priv_data;
     struct vaapi_context * const vactx = avctx->hwaccel_context;
     VAPictureParameterBufferMPEG2 *pic_param;
@@ -48,10 +49,10 @@ static int vaapi_mpeg2_start_frame(AVCodecContext *avctx, 
av_unused const uint8_
 
     ff_dlog(avctx, "vaapi_mpeg2_start_frame()\n");
 
-    vactx->slice_param_size = sizeof(VASliceParameterBufferMPEG2);
+    ctx->slice_param_size = sizeof(VASliceParameterBufferMPEG2);
 
     /* Fill in VAPictureParameterBufferMPEG2 */
-    pic_param = ff_vaapi_alloc_pic_param(vactx, 
sizeof(VAPictureParameterBufferMPEG2));
+    pic_param = ff_vaapi_alloc_pic_param(avctx, vactx, 
sizeof(VAPictureParameterBufferMPEG2));
     if (!pic_param)
         return -1;
     pic_param->horizontal_size                                  = s->width;
@@ -83,7 +84,7 @@ static int vaapi_mpeg2_start_frame(AVCodecContext *avctx, 
av_unused const uint8_
     }
 
     /* Fill in VAIQMatrixBufferMPEG2 */
-    iq_matrix = ff_vaapi_alloc_iq_matrix(vactx, sizeof(VAIQMatrixBufferMPEG2));
+    iq_matrix = ff_vaapi_alloc_iq_matrix(avctx, vactx, 
sizeof(VAIQMatrixBufferMPEG2));
     if (!iq_matrix)
         return -1;
     iq_matrix->load_intra_quantiser_matrix              = 1;
@@ -124,7 +125,7 @@ static int vaapi_mpeg2_decode_slice(AVCodecContext *avctx, 
const uint8_t *buffer
     macroblock_offset = get_bits_count(&gb);
 
     /* Fill in VASliceParameterBufferMPEG2 */
-    slice_param = (VASliceParameterBufferMPEG2 
*)ff_vaapi_alloc_slice(avctx->hwaccel_context, buffer, size);
+    slice_param = (VASliceParameterBufferMPEG2 *)ff_vaapi_alloc_slice(avctx, 
avctx->hwaccel_context, buffer, size);
     if (!slice_param)
         return -1;
     slice_param->macroblock_offset              = macroblock_offset;
@@ -143,4 +144,5 @@ AVHWAccel ff_mpeg2_vaapi_hwaccel = {
     .start_frame    = vaapi_mpeg2_start_frame,
     .end_frame      = ff_vaapi_mpeg_end_frame,
     .decode_slice   = vaapi_mpeg2_decode_slice,
+    .priv_data_size = sizeof(VAAPIContext),
 };
diff --git a/libavcodec/vaapi_mpeg4.c b/libavcodec/vaapi_mpeg4.c
index 1b9053c..b0e86c9 100644
--- a/libavcodec/vaapi_mpeg4.c
+++ b/libavcodec/vaapi_mpeg4.c
@@ -44,6 +44,7 @@ static int mpeg4_get_intra_dc_vlc_thr(Mpeg4DecContext *s)
 
 static int vaapi_mpeg4_start_frame(AVCodecContext *avctx, av_unused const 
uint8_t *buffer, av_unused uint32_t size)
 {
+    VAAPIContext *va = avctx->internal->hwaccel_priv_data;
     Mpeg4DecContext *ctx = avctx->priv_data;
     MpegEncContext * const s = &ctx->m;
     struct vaapi_context * const vactx = avctx->hwaccel_context;
@@ -53,10 +54,10 @@ static int vaapi_mpeg4_start_frame(AVCodecContext *avctx, 
av_unused const uint8_
 
     ff_dlog(avctx, "vaapi_mpeg4_start_frame()\n");
 
-    vactx->slice_param_size = sizeof(VASliceParameterBufferMPEG4);
+    va->slice_param_size = sizeof(VASliceParameterBufferMPEG4);
 
     /* Fill in VAPictureParameterBufferMPEG4 */
-    pic_param = ff_vaapi_alloc_pic_param(vactx, 
sizeof(VAPictureParameterBufferMPEG4));
+    pic_param = ff_vaapi_alloc_pic_param(avctx, vactx, 
sizeof(VAPictureParameterBufferMPEG4));
     if (!pic_param)
         return -1;
     pic_param->vop_width                                = s->width;
@@ -104,7 +105,7 @@ static int vaapi_mpeg4_start_frame(AVCodecContext *avctx, 
av_unused const uint8_
     /* Fill in VAIQMatrixBufferMPEG4 */
     /* Only the first inverse quantisation method uses the weighting matrices 
*/
     if (pic_param->vol_fields.bits.quant_type) {
-        iq_matrix = ff_vaapi_alloc_iq_matrix(vactx, 
sizeof(VAIQMatrixBufferMPEG4));
+        iq_matrix = ff_vaapi_alloc_iq_matrix(avctx, vactx, 
sizeof(VAIQMatrixBufferMPEG4));
         if (!iq_matrix)
             return -1;
         iq_matrix->load_intra_quant_mat         = 1;
@@ -135,7 +136,7 @@ static int vaapi_mpeg4_decode_slice(AVCodecContext *avctx, 
const uint8_t *buffer
         size = s->gb.buffer_end - buffer;
 
     /* Fill in VASliceParameterBufferMPEG4 */
-    slice_param = (VASliceParameterBufferMPEG4 
*)ff_vaapi_alloc_slice(avctx->hwaccel_context, buffer, size);
+    slice_param = (VASliceParameterBufferMPEG4 *)ff_vaapi_alloc_slice(avctx, 
avctx->hwaccel_context, buffer, size);
     if (!slice_param)
         return -1;
     slice_param->macroblock_offset      = get_bits_count(&s->gb) % 8;
@@ -157,6 +158,7 @@ AVHWAccel ff_mpeg4_vaapi_hwaccel = {
     .start_frame    = vaapi_mpeg4_start_frame,
     .end_frame      = ff_vaapi_mpeg_end_frame,
     .decode_slice   = vaapi_mpeg4_decode_slice,
+    .priv_data_size = sizeof(VAAPIContext),
 };
 #endif
 
@@ -169,5 +171,6 @@ AVHWAccel ff_h263_vaapi_hwaccel = {
     .start_frame    = vaapi_mpeg4_start_frame,
     .end_frame      = ff_vaapi_mpeg_end_frame,
     .decode_slice   = vaapi_mpeg4_decode_slice,
+    .priv_data_size = sizeof(VAAPIContext),
 };
 #endif
diff --git a/libavcodec/vaapi_vc1.c b/libavcodec/vaapi_vc1.c
index fe01c52..bca928b 100644
--- a/libavcodec/vaapi_vc1.c
+++ b/libavcodec/vaapi_vc1.c
@@ -146,6 +146,7 @@ static inline void vc1_pack_bitplanes(uint8_t *bitplane, 
int n, const uint8_t *f
 
 static int vaapi_vc1_start_frame(AVCodecContext *avctx, av_unused const 
uint8_t *buffer, av_unused uint32_t size)
 {
+    VAAPIContext *ctx = avctx->internal->hwaccel_priv_data;
     VC1Context * const v = avctx->priv_data;
     MpegEncContext * const s = &v->s;
     struct vaapi_context * const vactx = avctx->hwaccel_context;
@@ -153,10 +154,10 @@ static int vaapi_vc1_start_frame(AVCodecContext *avctx, 
av_unused const uint8_t
 
     ff_dlog(avctx, "vaapi_vc1_start_frame()\n");
 
-    vactx->slice_param_size = sizeof(VASliceParameterBufferVC1);
+    ctx->slice_param_size = sizeof(VASliceParameterBufferVC1);
 
     /* Fill in VAPictureParameterBufferVC1 */
-    pic_param = ff_vaapi_alloc_pic_param(vactx, 
sizeof(VAPictureParameterBufferVC1));
+    pic_param = ff_vaapi_alloc_pic_param(avctx, vactx, 
sizeof(VAPictureParameterBufferVC1));
     if (!pic_param)
         return -1;
     pic_param->forward_reference_picture                            = 
VA_INVALID_ID;
@@ -297,7 +298,7 @@ static int vaapi_vc1_start_frame(AVCodecContext *avctx, 
av_unused const uint8_t
             break;
         }
 
-        bitplane = ff_vaapi_alloc_bitplane(vactx, (s->mb_width * s->mb_height 
+ 1) / 2);
+        bitplane = ff_vaapi_alloc_bitplane(avctx, vactx, (s->mb_width * 
s->mb_height + 1) / 2);
         if (!bitplane)
             return -1;
 
@@ -326,7 +327,7 @@ static int vaapi_vc1_decode_slice(AVCodecContext *avctx, 
const uint8_t *buffer,
     }
 
     /* Fill in VASliceParameterBufferVC1 */
-    slice_param = (VASliceParameterBufferVC1 
*)ff_vaapi_alloc_slice(avctx->hwaccel_context, buffer, size);
+    slice_param = (VASliceParameterBufferVC1 *)ff_vaapi_alloc_slice(avctx, 
avctx->hwaccel_context, buffer, size);
     if (!slice_param)
         return -1;
     slice_param->macroblock_offset       = get_bits_count(&s->gb);
@@ -343,6 +344,7 @@ AVHWAccel ff_wmv3_vaapi_hwaccel = {
     .start_frame    = vaapi_vc1_start_frame,
     .end_frame      = ff_vaapi_mpeg_end_frame,
     .decode_slice   = vaapi_vc1_decode_slice,
+    .priv_data_size = sizeof(VAAPIContext),
 };
 #endif
 
@@ -354,4 +356,5 @@ AVHWAccel ff_vc1_vaapi_hwaccel = {
     .start_frame    = vaapi_vc1_start_frame,
     .end_frame      = ff_vaapi_mpeg_end_frame,
     .decode_slice   = vaapi_vc1_decode_slice,
+    .priv_data_size = sizeof(VAAPIContext),
 };
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 303c112..4b092f7 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -192,5 +192,8 @@
 #ifndef FF_API_NVENC_OLD_NAME
 #define FF_API_NVENC_OLD_NAME    (LIBAVCODEC_VERSION_MAJOR < 59)
 #endif
+#ifndef FF_API_VAAPI_PRIVATE
+#define FF_API_VAAPI_PRIVATE     (LIBAVCODEC_VERSION_MAJOR < 59)
+#endif
 
 #endif /* AVCODEC_VERSION_H */
-- 
2.0.0

_______________________________________________
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to