From: Tong Wu <tong1...@intel.com>

Signed-off-by: Tong Wu <tong1...@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

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to