]> git.sesse.net Git - ffmpeg/commitdiff
vaapi_encode: Allocate picture-private data in generic code
authorMark Thompson <sw@jkqxz.net>
Thu, 20 Dec 2018 20:39:55 +0000 (20:39 +0000)
committerMark Thompson <sw@jkqxz.net>
Wed, 23 Jan 2019 23:04:11 +0000 (23:04 +0000)
libavcodec/vaapi_encode.c
libavcodec/vaapi_encode.h

index eda8a362992b94ee5f6a28fb03a8f837311ff1fe..d8bedbe1623f45f9c6ea9fb6d2e63631a8a74148 100644 (file)
@@ -570,14 +570,23 @@ static int vaapi_encode_discard(AVCodecContext *avctx,
     return 0;
 }
 
-static VAAPIEncodePicture *vaapi_encode_alloc(void)
+static VAAPIEncodePicture *vaapi_encode_alloc(AVCodecContext *avctx)
 {
+    VAAPIEncodeContext *ctx = avctx->priv_data;
     VAAPIEncodePicture *pic;
 
     pic = av_mallocz(sizeof(*pic));
     if (!pic)
         return NULL;
 
+    if (ctx->codec->picture_priv_data_size > 0) {
+        pic->priv_data = av_mallocz(ctx->codec->picture_priv_data_size);
+        if (!pic->priv_data) {
+            av_freep(&pic);
+            return NULL;
+        }
+    }
+
     pic->input_surface = VA_INVALID_ID;
     pic->recon_surface = VA_INVALID_ID;
     pic->output_buffer = VA_INVALID_ID;
@@ -710,7 +719,7 @@ static int vaapi_encode_get_next(AVCodecContext *avctx,
         }
     }
 
-    pic = vaapi_encode_alloc();
+    pic = vaapi_encode_alloc(avctx);
     if (!pic)
         return AVERROR(ENOMEM);
 
@@ -739,7 +748,7 @@ static int vaapi_encode_get_next(AVCodecContext *avctx,
 
         for (i = 0; i < ctx->b_per_p &&
              ctx->gop_counter < ctx->gop_size; i++) {
-            pic = vaapi_encode_alloc();
+            pic = vaapi_encode_alloc(avctx);
             if (!pic)
                 goto fail;
 
index 965fe65c0b63aa30b5cf2f820117135f88a963db..6204c5171f01b215da346439e16659b352d1b4cb 100644 (file)
@@ -268,6 +268,10 @@ typedef struct VAAPIEncodeType {
     // add any necessary global parameters).
     int (*configure)(AVCodecContext *avctx);
 
+    // The size of any private data structure associated with each
+    // picture (can be zero if not required).
+    size_t picture_priv_data_size;
+
     // The size of the parameter structures:
     // sizeof(VAEnc{type}ParameterBuffer{codec}).
     size_t sequence_params_size;