diff options
author | Tong Wu <tong1.wu@intel.com> | 2024-04-18 10:30:36 +0800 |
---|---|---|
committer | Lynne <dev@lynne.ee> | 2024-07-02 14:15:12 +0200 |
commit | 1242abdcee257f0cfefc7aabf118d23253f37769 (patch) | |
tree | 9722f32c43249fb50de4b263b0b71f2835214f12 /libavcodec/hw_base_encode.c | |
parent | aa82340b0ccdde4955fba41b8de5e45348ecd11d (diff) | |
download | ffmpeg-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.c | 49 |
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; +} |