aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/hw_base_encode.c
diff options
context:
space:
mode:
authorTong Wu <tong1.wu@intel.com>2024-04-18 10:30:36 +0800
committerLynne <dev@lynne.ee>2024-07-02 14:15:12 +0200
commit1242abdcee257f0cfefc7aabf118d23253f37769 (patch)
tree9722f32c43249fb50de4b263b0b71f2835214f12 /libavcodec/hw_base_encode.c
parentaa82340b0ccdde4955fba41b8de5e45348ecd11d (diff)
downloadffmpeg-1242abdcee257f0cfefc7aabf118d23253f37769.tar.gz
avcodec/vaapi_encode: extract the init and close function to base layer
Related parameters such as device context, frame context are also moved to base layer. Signed-off-by: Tong Wu <tong1.wu@intel.com>
Diffstat (limited to 'libavcodec/hw_base_encode.c')
-rw-r--r--libavcodec/hw_base_encode.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/libavcodec/hw_base_encode.c b/libavcodec/hw_base_encode.c
index 16afaa37be..c4789380b6 100644
--- a/libavcodec/hw_base_encode.c
+++ b/libavcodec/hw_base_encode.c
@@ -592,3 +592,52 @@ end:
return 0;
}
+
+int ff_hw_base_encode_init(AVCodecContext *avctx)
+{
+ FFHWBaseEncodeContext *ctx = avctx->priv_data;
+
+ ctx->frame = av_frame_alloc();
+ if (!ctx->frame)
+ return AVERROR(ENOMEM);
+
+ if (!avctx->hw_frames_ctx) {
+ av_log(avctx, AV_LOG_ERROR, "A hardware frames reference is "
+ "required to associate the encoding device.\n");
+ return AVERROR(EINVAL);
+ }
+
+ ctx->input_frames_ref = av_buffer_ref(avctx->hw_frames_ctx);
+ if (!ctx->input_frames_ref)
+ return AVERROR(ENOMEM);
+
+ ctx->input_frames = (AVHWFramesContext *)ctx->input_frames_ref->data;
+
+ ctx->device_ref = av_buffer_ref(ctx->input_frames->device_ref);
+ if (!ctx->device_ref)
+ return AVERROR(ENOMEM);
+
+ ctx->device = (AVHWDeviceContext *)ctx->device_ref->data;
+
+ ctx->tail_pkt = av_packet_alloc();
+ if (!ctx->tail_pkt)
+ return AVERROR(ENOMEM);
+
+ return 0;
+}
+
+int ff_hw_base_encode_close(AVCodecContext *avctx)
+{
+ FFHWBaseEncodeContext *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;
+}