[FFmpeg-devel] [PATCH v7 05/12] avcodec/vaapi_encode: extract a close function for base layer

tong1.wu at intel.com tong1.wu at intel.com
Thu Mar 14 10:14:48 EET 2024


From: Tong Wu <tong1.wu at intel.com>

Signed-off-by: Tong Wu <tong1.wu at intel.com>
---
 libavcodec/hw_base_encode.c | 16 ++++++++++++++++
 libavcodec/hw_base_encode.h |  2 ++
 libavcodec/vaapi_encode.c   |  8 +-------
 3 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/libavcodec/hw_base_encode.c b/libavcodec/hw_base_encode.c
index 71ead512c0..754f990ed0 100644
--- a/libavcodec/hw_base_encode.c
+++ b/libavcodec/hw_base_encode.c
@@ -630,3 +630,19 @@ int ff_hw_base_encode_init(AVCodecContext *avctx)
 
     return 0;
 }
+
+int ff_hw_base_encode_close(AVCodecContext *avctx)
+{
+    HWBaseEncodeContext *ctx = avctx->priv_data;
+
+    av_fifo_freep2(&ctx->encode_fifo);
+
+    av_frame_free(&ctx->frame);
+    av_packet_free(&ctx->tail_pkt);
+
+    av_buffer_unref(&ctx->device_ref);
+    av_buffer_unref(&ctx->input_frames_ref);
+    av_buffer_unref(&ctx->recon_frames_ref);
+
+    return 0;
+}
diff --git a/libavcodec/hw_base_encode.h b/libavcodec/hw_base_encode.h
index c9c8fb43c9..436767b706 100644
--- a/libavcodec/hw_base_encode.h
+++ b/libavcodec/hw_base_encode.h
@@ -228,6 +228,8 @@ int ff_hw_base_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt);
 
 int ff_hw_base_encode_init(AVCodecContext *avctx);
 
+int ff_hw_base_encode_close(AVCodecContext *avctx);
+
 #define HW_BASE_ENCODE_COMMON_OPTIONS \
     { "idr_interval", \
       "Distance (in I-frames) between key frames", \
diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 887543734b..ffac27a08f 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -2412,16 +2412,10 @@ av_cold int ff_vaapi_encode_close(AVCodecContext *avctx)
         ctx->va_config = VA_INVALID_ID;
     }
 
-    av_frame_free(&base_ctx->frame);
-    av_packet_free(&base_ctx->tail_pkt);
-
     av_freep(&ctx->codec_sequence_params);
     av_freep(&ctx->codec_picture_params);
-    av_fifo_freep2(&base_ctx->encode_fifo);
 
-    av_buffer_unref(&base_ctx->recon_frames_ref);
-    av_buffer_unref(&base_ctx->input_frames_ref);
-    av_buffer_unref(&base_ctx->device_ref);
+    ff_hw_base_encode_close(avctx);
 
     return 0;
 }
-- 
2.41.0.windows.1



More information about the ffmpeg-devel mailing list