[FFmpeg-devel] [PATCH v8 06/15] avcodec/vaapi_encode: extract the init function to base layer

Mark Thompson sw at jkqxz.net
Tue May 14 23:56:04 EEST 2024


On 18/04/2024 09:59, tong1.wu-at-intel.com at ffmpeg.org wrote:
> From: Tong Wu <tong1.wu at intel.com>
> 
> Related parameters are also moved to base layer.
> 
> Signed-off-by: Tong Wu <tong1.wu at intel.com>
> ---
>  libavcodec/hw_base_encode.c     | 33 ++++++++++++++++
>  libavcodec/hw_base_encode.h     | 11 ++++++
>  libavcodec/vaapi_encode.c       | 68 ++++++++++-----------------------
>  libavcodec/vaapi_encode.h       |  6 ---
>  libavcodec/vaapi_encode_av1.c   |  2 +-
>  libavcodec/vaapi_encode_h264.c  |  2 +-
>  libavcodec/vaapi_encode_h265.c  |  2 +-
>  libavcodec/vaapi_encode_mjpeg.c |  6 ++-
>  8 files changed, 72 insertions(+), 58 deletions(-)
> 
> diff --git a/libavcodec/hw_base_encode.c b/libavcodec/hw_base_encode.c
> index 1d9a255f69..14f3ecfc94 100644
> --- a/libavcodec/hw_base_encode.c
> +++ b/libavcodec/hw_base_encode.c
> @@ -598,3 +598,36 @@ end:
>  
>      return 0;
>  }
> +
> +int ff_hw_base_encode_init(AVCodecContext *avctx)
> +{
> +    HWBaseEncodeContext *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;
> +}
> diff --git a/libavcodec/hw_base_encode.h b/libavcodec/hw_base_encode.h
> index b5b676b9a8..f7e385e840 100644
> --- a/libavcodec/hw_base_encode.h
> +++ b/libavcodec/hw_base_encode.h
> @@ -19,6 +19,7 @@
>  #ifndef AVCODEC_HW_BASE_ENCODE_H
>  #define AVCODEC_HW_BASE_ENCODE_H
>  
> +#include "libavutil/hwcontext.h"
>  #include "libavutil/fifo.h"
>  
>  #define MAX_DPB_SIZE 16
> @@ -117,6 +118,14 @@ typedef struct HWBaseEncodeContext {
>      // Hardware-specific hooks.
>      const struct HWEncodePictureOperation *op;
>  
> +    // The hardware device context.
> +    AVBufferRef    *device_ref;
> +    AVHWDeviceContext *device;
> +
> +    // The hardware frame context containing the input frames.
> +    AVBufferRef    *input_frames_ref;
> +    AVHWFramesContext *input_frames;
> +
>      // Current encoding window, in display (input) order.
>      HWBaseEncodePicture *pic_start, *pic_end;
>      // The next picture to use as the previous reference picture in
> @@ -183,6 +192,8 @@ typedef struct HWBaseEncodeContext {
>  
>  int ff_hw_base_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt);
>  
> +int ff_hw_base_encode_init(AVCodecContext *avctx);
> +
>  #define HW_BASE_ENCODE_COMMON_OPTIONS \
>      { "async_depth", "Maximum processing parallelism. " \
>        "Increase this to improve single channel performance.", \

Maybe this patch should be merged with 9/15 to keep the init/close symmetry?  It's not clear that the intermediate makes sense, and it has some churn.

> ...

Thanks,

- Mark


More information about the ffmpeg-devel mailing list