diff mbox

[FFmpeg-devel,v3,36/41] vaapi_encode: Allocate picture-private data in generic code

Message ID 20180822234514.10571-37-sw@jkqxz.net
State Accepted
Commit 26ce3a43a35fe3a43c895945252aa22c6b46ffb7
Headers show

Commit Message

Mark Thompson Aug. 22, 2018, 11:45 p.m. UTC
---
 libavcodec/vaapi_encode.c | 15 ++++++++++++---
 libavcodec/vaapi_encode.h |  4 ++++
 2 files changed, 16 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 2c34cdce2c..a6981d69fa 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -526,14 +526,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;
@@ -666,7 +675,7 @@  static int vaapi_encode_get_next(AVCodecContext *avctx,
         }
     }
 
-    pic = vaapi_encode_alloc();
+    pic = vaapi_encode_alloc(avctx);
     if (!pic)
         return AVERROR(ENOMEM);
 
@@ -695,7 +704,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;
 
diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h
index 091889f9ae..33bdd16403 100644
--- a/libavcodec/vaapi_encode.h
+++ b/libavcodec/vaapi_encode.h
@@ -244,6 +244,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;