diff mbox series

[FFmpeg-devel,v7,01/12] avcodec/vaapi_encode: move pic->input_surface initialization to encode_alloc

Message ID 20240314081456.379-1-tong1.wu@intel.com
State New
Headers show
Series [FFmpeg-devel,v7,01/12] avcodec/vaapi_encode: move pic->input_surface initialization to encode_alloc | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Wu, Tong1 March 14, 2024, 8:14 a.m. UTC
From: Tong Wu <tong1.wu@intel.com>

When allocating the VAAPIEncodePicture, pic->input_surface can be
initialized right in the place. This movement simplifies the send_frame
logic and is the preparation for moving vaapi_encode_send_frame to the base layer.

Signed-off-by: Tong Wu <tong1.wu@intel.com>
---
 libavcodec/vaapi_encode.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 808b79c0c7..bd29dbf0b4 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -878,7 +878,8 @@  static int vaapi_encode_discard(AVCodecContext *avctx,
     return 0;
 }
 
-static VAAPIEncodePicture *vaapi_encode_alloc(AVCodecContext *avctx)
+static VAAPIEncodePicture *vaapi_encode_alloc(AVCodecContext *avctx,
+                                              const AVFrame *frame)
 {
     VAAPIEncodeContext *ctx = avctx->priv_data;
     VAAPIEncodePicture *pic;
@@ -895,7 +896,7 @@  static VAAPIEncodePicture *vaapi_encode_alloc(AVCodecContext *avctx)
         }
     }
 
-    pic->input_surface = VA_INVALID_ID;
+    pic->input_surface = (VASurfaceID)(uintptr_t)frame->data[3];
     pic->recon_surface = VA_INVALID_ID;
     pic->output_buffer = VA_INVALID_ID;
 
@@ -1331,7 +1332,7 @@  static int vaapi_encode_send_frame(AVCodecContext *avctx, AVFrame *frame)
         if (err < 0)
             return err;
 
-        pic = vaapi_encode_alloc(avctx);
+        pic = vaapi_encode_alloc(avctx, frame);
         if (!pic)
             return AVERROR(ENOMEM);
 
@@ -1344,7 +1345,6 @@  static int vaapi_encode_send_frame(AVCodecContext *avctx, AVFrame *frame)
         if (ctx->input_order == 0 || frame->pict_type == AV_PICTURE_TYPE_I)
             pic->force_idr = 1;
 
-        pic->input_surface = (VASurfaceID)(uintptr_t)frame->data[3];
         pic->pts = frame->pts;
         pic->duration = frame->duration;