James Almer:
> And rename the existing one to ff_cbs_alloc().
> This will allow for more versatility when setting options in a module, 
> allowing
> them to be taken into account when calling module specific init functions.
> 
> Signed-off-by: James Almer <jamr...@gmail.com>
> ---
>  libavcodec/apv_decode.c          |  6 +++++-
>  libavcodec/apv_parser.c          |  6 +++++-
>  libavcodec/av1_parser.c          |  6 +++++-
>  libavcodec/av1dec.c              | 14 +++++++++++---
>  libavcodec/bsf/av1_frame_merge.c | 16 ++++++++++++++--
>  libavcodec/bsf/av1_frame_split.c |  6 +++++-
>  libavcodec/bsf/dts2pts.c         |  6 +++++-
>  libavcodec/bsf/filter_units.c    |  6 +++++-
>  libavcodec/bsf/trace_headers.c   |  2 +-
>  libavcodec/cbs.c                 | 28 +++++++++++++++++++++++++++-
>  libavcodec/cbs.h                 | 10 ++++++++--
>  libavcodec/cbs_bsf.c             | 12 ++++++++++--
>  libavcodec/cbs_internal.h        |  3 +++
>  libavcodec/d3d12va_encode_hevc.c |  6 +++++-
>  libavcodec/vaapi_encode_av1.c    |  6 +++++-
>  libavcodec/vaapi_encode_h264.c   |  6 +++++-
>  libavcodec/vaapi_encode_h265.c   |  6 +++++-
>  libavcodec/vaapi_encode_mjpeg.c  |  6 +++++-
>  libavcodec/vaapi_encode_mpeg2.c  |  6 +++++-
>  libavcodec/vulkan_encode_h264.c  | 12 ++++++++++--
>  libavcodec/vulkan_encode_h265.c  | 12 ++++++++++--
>  libavcodec/vvc/dec.c             |  6 +++++-
>  libavcodec/vvc_parser.c          |  5 ++++-
>  libavformat/movenccenc.c         |  6 +++++-
>  24 files changed, 168 insertions(+), 30 deletions(-)
> 
> diff --git a/libavcodec/apv_decode.c b/libavcodec/apv_decode.c
> index eb47298e2e..3667933df6 100644
> --- a/libavcodec/apv_decode.c
> +++ b/libavcodec/apv_decode.c
> @@ -119,7 +119,11 @@ static av_cold int apv_decode_init(AVCodecContext *avctx)
>  
>      ff_thread_once(&apv_entropy_once, apv_entropy_build_decode_lut);
>  
> -    err = ff_cbs_init(&apv->cbc, AV_CODEC_ID_APV, avctx);
> +    err = ff_cbs_alloc(&apv->cbc, AV_CODEC_ID_APV, avctx);
> +    if (err < 0)
> +        return err;
> +
> +    err = ff_cbs_init(apv->cbc, NULL);
>      if (err < 0)
>          return err;
>  
> diff --git a/libavcodec/apv_parser.c b/libavcodec/apv_parser.c
> index fdd575339b..e0aa152ca8 100644
> --- a/libavcodec/apv_parser.c
> +++ b/libavcodec/apv_parser.c
> @@ -122,7 +122,11 @@ static av_cold int init(AVCodecParserContext *s)
>      APVParseContext *p = s->priv_data;
>      int ret;
>  
> -    ret = ff_cbs_init(&p->cbc, AV_CODEC_ID_APV, NULL);
> +    ret = ff_cbs_alloc(&p->cbc, AV_CODEC_ID_APV, NULL);
> +    if (ret < 0)
> +        return ret;
> +
> +    ret = ff_cbs_init(p->cbc, NULL);
>      if (ret < 0)
>          return ret;
>  
> diff --git a/libavcodec/av1_parser.c b/libavcodec/av1_parser.c
> index 1792e813f4..77906d0c91 100644
> --- a/libavcodec/av1_parser.c
> +++ b/libavcodec/av1_parser.c
> @@ -190,13 +190,17 @@ static av_cold int av1_parser_init(AVCodecParserContext 
> *ctx)
>      AV1ParseContext *s = ctx->priv_data;
>      int ret;
>  
> -    ret = ff_cbs_init(&s->cbc, AV_CODEC_ID_AV1, NULL);
> +    ret = ff_cbs_alloc(&s->cbc, AV_CODEC_ID_AV1, NULL);
>      if (ret < 0)
>          return ret;
>  
>      s->cbc->decompose_unit_types    = decompose_unit_types;
>      s->cbc->nb_decompose_unit_types = FF_ARRAY_ELEMS(decompose_unit_types);
>  
> +    ret = ff_cbs_init(s->cbc, NULL);
> +    if (ret < 0)
> +        return ret;
> +
>      return 0;
>  }
>  
> diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
> index 8ff1bf394c..3130364534 100644
> --- a/libavcodec/av1dec.c
> +++ b/libavcodec/av1dec.c
> @@ -858,6 +858,7 @@ static av_cold int av1_decode_init(AVCodecContext *avctx)
>  {
>      AV1DecContext *s = avctx->priv_data;
>      AV1RawSequenceHeader *seq;
> +    AVDictionary *options = NULL;
>      const AVPacketSideData *sd;
>      int ret;
>  
> @@ -865,20 +866,27 @@ static av_cold int av1_decode_init(AVCodecContext 
> *avctx)
>      s->pkt = avctx->internal->in_pkt;
>      s->pix_fmt = AV_PIX_FMT_NONE;
>  
> -    ret = ff_cbs_init(&s->cbc, AV_CODEC_ID_AV1, avctx);
> +    ret = ff_cbs_alloc(&s->cbc, AV_CODEC_ID_AV1, avctx);
>      if (ret < 0)
>          return ret;
>  
>      s->cbc->decompose_unit_types    = decompose_unit_types;
>      s->cbc->nb_decompose_unit_types = FF_ARRAY_ELEMS(decompose_unit_types);
>  
> +    ret = av_dict_set_int(&options, "operating_point", s->operating_point, 
> 0);
> +    if (ret < 0)
> +        return ret;
> +
> +    ret = ff_cbs_init(s->cbc, &options);
> +    av_dict_free(&options);
> +    if (ret < 0)
> +        return ret;
> +
>      s->itut_t35_fifo = av_fifo_alloc2(1, sizeof(AV1RawMetadataITUTT35),
>                                        AV_FIFO_FLAG_AUTO_GROW);
>      if (!s->itut_t35_fifo)
>          return AVERROR(ENOMEM);
>  
> -    av_opt_set_int(s->cbc->priv_data, "operating_point", s->operating_point, 
> 0);
> -
>      if (avctx->extradata && avctx->extradata_size) {
>          ret = ff_cbs_read_extradata_from_codec(s->cbc,
>                                                 &s->current_obu,
> diff --git a/libavcodec/bsf/av1_frame_merge.c 
> b/libavcodec/bsf/av1_frame_merge.c
> index 4c54f2167e..530688be49 100644
> --- a/libavcodec/bsf/av1_frame_merge.c
> +++ b/libavcodec/bsf/av1_frame_merge.c
> @@ -133,11 +133,23 @@ static int av1_frame_merge_init(AVBSFContext *bsf)
>      if (!ctx->in || !ctx->pkt)
>          return AVERROR(ENOMEM);
>  
> -    err =  ff_cbs_init(&ctx->input, AV_CODEC_ID_AV1, bsf);
> +    err =  ff_cbs_alloc(&ctx->input, AV_CODEC_ID_AV1, bsf);
>      if (err < 0)
>          return err;
>  
> -    return ff_cbs_init(&ctx->output, AV_CODEC_ID_AV1, bsf);
> +    err =  ff_cbs_alloc(&ctx->output, AV_CODEC_ID_AV1, bsf);
> +    if (err < 0)
> +        return err;
> +
> +    err = ff_cbs_init(ctx->input, NULL);
> +    if (err < 0)
> +        return err;
> +
> +    err = ff_cbs_init(ctx->output, NULL);
> +    if (err < 0)
> +        return err;
> +
> +    return 0;
>  }
>  
>  static void av1_frame_merge_close(AVBSFContext *bsf)
> diff --git a/libavcodec/bsf/av1_frame_split.c 
> b/libavcodec/bsf/av1_frame_split.c
> index 5f6a40316c..a64e9178e7 100644
> --- a/libavcodec/bsf/av1_frame_split.c
> +++ b/libavcodec/bsf/av1_frame_split.c
> @@ -210,7 +210,11 @@ static int av1_frame_split_init(AVBSFContext *ctx)
>      if (!s->buffer_pkt)
>          return AVERROR(ENOMEM);
>  
> -    ret = ff_cbs_init(&s->cbc, AV_CODEC_ID_AV1, ctx);
> +    ret = ff_cbs_alloc(&s->cbc, AV_CODEC_ID_AV1, ctx);
> +    if (ret < 0)
> +        return ret;
> +
> +    ret = ff_cbs_init(s->cbc, NULL);
>      if (ret < 0)
>          return ret;
>  
> diff --git a/libavcodec/bsf/dts2pts.c b/libavcodec/bsf/dts2pts.c
> index 9d31d7dc08..189a9f9678 100644
> --- a/libavcodec/bsf/dts2pts.c
> +++ b/libavcodec/bsf/dts2pts.c
> @@ -402,7 +402,11 @@ static int dts2pts_init(AVBSFContext *ctx)
>      if (!s->node_pool)
>          return AVERROR(ENOMEM);
>  
> -    ret = ff_cbs_init(&s->cbc, ctx->par_in->codec_id, ctx);
> +    ret = ff_cbs_alloc(&s->cbc, ctx->par_in->codec_id, ctx);
> +    if (ret < 0)
> +        return ret;
> +
> +    ret = ff_cbs_init(s->cbc, NULL);
>      if (ret < 0)
>          return ret;
>  
> diff --git a/libavcodec/bsf/filter_units.c b/libavcodec/bsf/filter_units.c
> index 336331733f..0edf2fa472 100644
> --- a/libavcodec/bsf/filter_units.c
> +++ b/libavcodec/bsf/filter_units.c
> @@ -187,7 +187,11 @@ static int filter_units_init(AVBSFContext *bsf)
>          return 0;
>      }
>  
> -    err = ff_cbs_init(&ctx->cbc, bsf->par_in->codec_id, bsf);
> +    err = ff_cbs_alloc(&ctx->cbc, bsf->par_in->codec_id, bsf);
> +    if (err < 0)
> +        return err;
> +
> +    err = ff_cbs_init(ctx->cbc, NULL);
>      if (err < 0)
>          return err;
>  
> diff --git a/libavcodec/bsf/trace_headers.c b/libavcodec/bsf/trace_headers.c
> index 8781f5f100..e885f7a73f 100644
> --- a/libavcodec/bsf/trace_headers.c
> +++ b/libavcodec/bsf/trace_headers.c
> @@ -38,7 +38,7 @@ static int trace_headers_init(AVBSFContext *bsf)
>      TraceHeadersContext *ctx = bsf->priv_data;
>      int err;
>  
> -    err = ff_cbs_init(&ctx->cbc, bsf->par_in->codec_id, bsf);
> +    err = ff_cbs_alloc(&ctx->cbc, bsf->par_in->codec_id, bsf);
>      if (err < 0)
>          return err;
>  
> diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
> index 6b2ebe597d..8c0659f7af 100644
> --- a/libavcodec/cbs.c
> +++ b/libavcodec/cbs.c
> @@ -21,6 +21,7 @@
>  #include "libavutil/avassert.h"
>  #include "libavutil/buffer.h"
>  #include "libavutil/common.h"
> +#include "libavutil/dict.h"
>  #include "libavutil/mem.h"
>  #include "libavutil/opt.h"
>  
> @@ -91,7 +92,7 @@ const enum AVCodecID CBS_FUNC(all_codec_ids)[] = {
>      AV_CODEC_ID_NONE
>  };
>  
> -av_cold int CBS_FUNC(init)(CodedBitstreamContext **ctx_ptr,
> +av_cold int CBS_FUNC(alloc)(CodedBitstreamContext **ctx_ptr,
>                          enum AVCodecID codec_id, void *log_ctx)
>  {
>      CodedBitstreamContext *ctx;
> @@ -137,6 +138,31 @@ av_cold int CBS_FUNC(init)(CodedBitstreamContext 
> **ctx_ptr,
>      return 0;
>  }
>  
> +av_cold int CBS_FUNC(init)(CodedBitstreamContext *ctx, AVDictionary 
> **options)
> +{
> +    int err;
> +
> +    if (!ctx->codec)
> +        return AVERROR(EINVAL);
> +
> +    if (ctx->codec->priv_data_size) {
> +        if (!ctx->priv_data)
> +            return AVERROR(EINVAL);
> +
> +        err = av_opt_set_dict2(ctx->priv_data, options, 0);
> +        if (err < 0)
> +            return err;
> +    }
> +
> +    if (ctx->codec->init) {
> +        err = ctx->codec->init(ctx);
> +        if (err < 0)
> +            return err;
> +    }
> +
> +    return 0;
> +}
> +
>  av_cold void CBS_FUNC(flush)(CodedBitstreamContext *ctx)
>  {
>      if (ctx->codec->flush)
> diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h
> index 67f2ec9e50..5b0e1f5c6b 100644
> --- a/libavcodec/cbs.h
> +++ b/libavcodec/cbs.h
> @@ -176,6 +176,7 @@ typedef struct CodedBitstreamFragment {
>  } CodedBitstreamFragment;
>  
>  
> +struct AVDictionary;
>  struct CodedBitstreamContext;
>  struct GetBitContext;
>  struct PutBitContext;
> @@ -305,11 +306,16 @@ extern const enum AVCodecID CBS_FUNC(all_codec_ids)[];
>  
>  
>  /**
> - * Create and initialise a new context for the given codec.
> + * Create a new context for the given codec.
>   */
> -int CBS_FUNC(init)(CodedBitstreamContext **ctx,
> +int CBS_FUNC(alloc)(CodedBitstreamContext **ctx,
>                  enum AVCodecID codec_id, void *log_ctx);
>  
> +/**
> + * Initialise a context.
> + */
> +int CBS_FUNC(init)(CodedBitstreamContext *ctx, struct AVDictionary 
> **options);
> +
>  /**
>   * Reset all internal state in a context.
>   */
> diff --git a/libavcodec/cbs_bsf.c b/libavcodec/cbs_bsf.c
> index b25285483b..25b9e730d8 100644
> --- a/libavcodec/cbs_bsf.c
> +++ b/libavcodec/cbs_bsf.c
> @@ -115,11 +115,19 @@ int ff_cbs_bsf_generic_init(AVBSFContext *bsf, const 
> CBSBSFType *type)
>  
>      ctx->type = type;
>  
> -    err = ff_cbs_init(&ctx->input, type->codec_id, bsf);
> +    err = ff_cbs_alloc(&ctx->input, type->codec_id, bsf);
>      if (err < 0)
>          return err;
>  
> -    err = ff_cbs_init(&ctx->output, type->codec_id, bsf);
> +    err = ff_cbs_alloc(&ctx->output, type->codec_id, bsf);
> +    if (err < 0)
> +        return err;
> +
> +    err = ff_cbs_init(ctx->input, NULL);
> +    if (err < 0)
> +        return err;
> +
> +    err = ff_cbs_init(ctx->output, NULL);
>      if (err < 0)
>          return err;
>  
> diff --git a/libavcodec/cbs_internal.h b/libavcodec/cbs_internal.h
> index c3265924ba..734269d368 100644
> --- a/libavcodec/cbs_internal.h
> +++ b/libavcodec/cbs_internal.h
> @@ -184,6 +184,9 @@ typedef struct CodedBitstreamType {
>      int (*assemble_fragment)(CodedBitstreamContext *ctx,
>                               CodedBitstreamFragment *frag);
>  
> +    // Initialize the codec internal state.
> +    int (*init)(CodedBitstreamContext *ctx);
> +
>      // Reset the codec internal state.
>      void (*flush)(CodedBitstreamContext *ctx);
>  
> diff --git a/libavcodec/d3d12va_encode_hevc.c 
> b/libavcodec/d3d12va_encode_hevc.c
> index 938ba01f54..5317e2f850 100644
> --- a/libavcodec/d3d12va_encode_hevc.c
> +++ b/libavcodec/d3d12va_encode_hevc.c
> @@ -442,7 +442,11 @@ static int d3d12va_encode_hevc_configure(AVCodecContext 
> *avctx)
>      int fixed_qp_idr, fixed_qp_p, fixed_qp_b;
>      int err;
>  
> -    err = ff_cbs_init(&priv->cbc, AV_CODEC_ID_HEVC, avctx);
> +    err = ff_cbs_alloc(&priv->cbc, AV_CODEC_ID_HEVC, avctx);
> +    if (err < 0)
> +        return err;
> +
> +    err = ff_cbs_init(priv->cbc, NULL);
>      if (err < 0)
>          return err;
>  
> diff --git a/libavcodec/vaapi_encode_av1.c b/libavcodec/vaapi_encode_av1.c
> index f3df5baddc..f80efd006e 100644
> --- a/libavcodec/vaapi_encode_av1.c
> +++ b/libavcodec/vaapi_encode_av1.c
> @@ -128,7 +128,7 @@ static av_cold int 
> vaapi_encode_av1_configure(AVCodecContext *avctx)
>      VAAPIEncodeAV1Context *priv = avctx->priv_data;
>      int ret;
>  
> -    ret = ff_cbs_init(&priv->cbc, AV_CODEC_ID_AV1, avctx);
> +    ret = ff_cbs_alloc(&priv->cbc, AV_CODEC_ID_AV1, avctx);
>      if (ret < 0)
>          return ret;
>      priv->cbc->trace_enable  = 1;
> @@ -136,6 +136,10 @@ static av_cold int 
> vaapi_encode_av1_configure(AVCodecContext *avctx)
>      priv->cbc->trace_context = ctx;
>      priv->cbc->trace_write_callback = vaapi_encode_av1_trace_write_log;
>  
> +    ret = ff_cbs_init(priv->cbc, NULL);
> +    if (ret < 0)
> +        return ret;
> +
>      if (ctx->rc_mode->quality) {
>          priv->q_idx_p = av_clip(ctx->rc_quality, 0, AV1_MAX_QUANT);
>          if (fabs(avctx->i_quant_factor) > 0.0)
> diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
> index 0cd5b0ac50..7c98833944 100644
> --- a/libavcodec/vaapi_encode_h264.c
> +++ b/libavcodec/vaapi_encode_h264.c
> @@ -874,7 +874,11 @@ static av_cold int 
> vaapi_encode_h264_configure(AVCodecContext *avctx)
>      VAAPIEncodeH264Context *priv = avctx->priv_data;
>      int err;
>  
> -    err = ff_cbs_init(&priv->cbc, AV_CODEC_ID_H264, avctx);
> +    err = ff_cbs_alloc(&priv->cbc, AV_CODEC_ID_H264, avctx);
> +    if (err < 0)
> +        return err;
> +
> +    err = ff_cbs_init(priv->cbc, NULL);
>      if (err < 0)
>          return err;
>  
> diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
> index 2acde2296b..0cfe67735b 100644
> --- a/libavcodec/vaapi_encode_h265.c
> +++ b/libavcodec/vaapi_encode_h265.c
> @@ -967,7 +967,11 @@ static av_cold int 
> vaapi_encode_h265_configure(AVCodecContext *avctx)
>      VAAPIEncodeH265Context *priv = avctx->priv_data;
>      int err;
>  
> -    err = ff_cbs_init(&priv->cbc, AV_CODEC_ID_HEVC, avctx);
> +    err = ff_cbs_alloc(&priv->cbc, AV_CODEC_ID_HEVC, avctx);
> +    if (err < 0)
> +        return err;
> +
> +    err = ff_cbs_init(priv->cbc, NULL);
>      if (err < 0)
>          return err;
>  
> diff --git a/libavcodec/vaapi_encode_mjpeg.c b/libavcodec/vaapi_encode_mjpeg.c
> index 2eef5bf090..5a7915cec4 100644
> --- a/libavcodec/vaapi_encode_mjpeg.c
> +++ b/libavcodec/vaapi_encode_mjpeg.c
> @@ -474,7 +474,11 @@ static av_cold int 
> vaapi_encode_mjpeg_configure(AVCodecContext *avctx)
>          ctx->va_packed_headers |=  VA_ENC_PACKED_HEADER_SLICE;
>      }
>  
> -    err = ff_cbs_init(&priv->cbc, AV_CODEC_ID_MJPEG, avctx);
> +    err = ff_cbs_alloc(&priv->cbc, AV_CODEC_ID_MJPEG, avctx);
> +    if (err < 0)
> +        return err;
> +
> +    err = ff_cbs_init(priv->cbc, NULL);
>      if (err < 0)
>          return err;
>  
> diff --git a/libavcodec/vaapi_encode_mpeg2.c b/libavcodec/vaapi_encode_mpeg2.c
> index 94cb3d4fb6..3e0b7f9ed9 100644
> --- a/libavcodec/vaapi_encode_mpeg2.c
> +++ b/libavcodec/vaapi_encode_mpeg2.c
> @@ -519,7 +519,11 @@ static av_cold int 
> vaapi_encode_mpeg2_configure(AVCodecContext *avctx)
>      VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
>      int err;
>  
> -    err = ff_cbs_init(&priv->cbc, AV_CODEC_ID_MPEG2VIDEO, avctx);
> +    err = ff_cbs_alloc(&priv->cbc, AV_CODEC_ID_MPEG2VIDEO, avctx);
> +    if (err < 0)
> +        return err;
> +
> +    err = ff_cbs_init(priv->cbc, NULL);
>      if (err < 0)
>          return err;
>  
> diff --git a/libavcodec/vulkan_encode_h264.c b/libavcodec/vulkan_encode_h264.c
> index f31b6d4069..be3edfe0d7 100644
> --- a/libavcodec/vulkan_encode_h264.c
> +++ b/libavcodec/vulkan_encode_h264.c
> @@ -1057,10 +1057,14 @@ static int parse_feedback_units(AVCodecContext *avctx,
>      CodedBitstreamContext *cbs;
>      CodedBitstreamFragment au = { 0 };
>  
> -    err = ff_cbs_init(&cbs, AV_CODEC_ID_H264, avctx);
> +    err = ff_cbs_alloc(&cbs, AV_CODEC_ID_H264, avctx);
>      if (err < 0)
>          return err;
>  
> +    err = ff_cbs_init(cbs, NULL);
> +    if (err < 0)
> +        goto fail;
> +
>      err = ff_cbs_read(cbs, &au, NULL, data, size);
>      if (err < 0) {
>          av_log(avctx, AV_LOG_ERROR, "Unable to parse feedback units, bad 
> drivers: %s\n",
> @@ -1540,7 +1544,11 @@ static av_cold int 
> vulkan_encode_h264_init(AVCodecContext *avctx)
>      }
>  
>      /* Init CBS */
> -    err = ff_cbs_init(&enc->cbs, AV_CODEC_ID_H264, avctx);
> +    err = ff_cbs_alloc(&enc->cbs, AV_CODEC_ID_H264, avctx);
> +    if (err < 0)
> +        return err;
> +
> +    err = ff_cbs_init(enc->cbs, NULL);
>      if (err < 0)
>          return err;
>  
> diff --git a/libavcodec/vulkan_encode_h265.c b/libavcodec/vulkan_encode_h265.c
> index d81d2de95a..af13edeec4 100644
> --- a/libavcodec/vulkan_encode_h265.c
> +++ b/libavcodec/vulkan_encode_h265.c
> @@ -1210,10 +1210,14 @@ static int parse_feedback_units(AVCodecContext *avctx,
>      CodedBitstreamContext *cbs;
>      CodedBitstreamFragment au = { 0 };
>  
> -    err = ff_cbs_init(&cbs, AV_CODEC_ID_HEVC, avctx);
> +    err = ff_cbs_alloc(&cbs, AV_CODEC_ID_HEVC, avctx);
>      if (err < 0)
>          return err;
>  
> +    err = ff_cbs_init(cbs, NULL);
> +    if (err < 0)
> +        goto fail;
> +
>      err = ff_cbs_read(cbs, &au, NULL, data, size);
>      if (err < 0) {
>          av_log(avctx, AV_LOG_ERROR, "Unable to parse feedback units, bad 
> drivers: %s\n",
> @@ -1677,7 +1681,11 @@ static av_cold int 
> vulkan_encode_h265_init(AVCodecContext *avctx)
>      base_ctx->decode_delay = base_ctx->max_b_depth;
>  
>      /* Init CBS */
> -    err = ff_cbs_init(&enc->cbs, AV_CODEC_ID_HEVC, avctx);
> +    err = ff_cbs_alloc(&enc->cbs, AV_CODEC_ID_HEVC, avctx);
> +    if (err < 0)
> +        return err;
> +
> +    err = ff_cbs_init(enc->cbs, NULL);
>      if (err < 0)
>          return err;
>  
> diff --git a/libavcodec/vvc/dec.c b/libavcodec/vvc/dec.c
> index 49ba47d5d4..662e5edc60 100644
> --- a/libavcodec/vvc/dec.c
> +++ b/libavcodec/vvc/dec.c
> @@ -1120,10 +1120,14 @@ static av_cold int vvc_decode_init(AVCodecContext 
> *avctx)
>  
>      s->avctx = avctx;
>  
> -    ret = ff_cbs_init(&s->cbc, AV_CODEC_ID_VVC, avctx);
> +    ret = ff_cbs_alloc(&s->cbc, AV_CODEC_ID_VVC, avctx);
>      if (ret)
>          return ret;
>  
> +    ret = ff_cbs_init(s->cbc, NULL);
> +    if (ret < 0)
> +        return ret;
> +
>      if (avctx->extradata_size > 0 && avctx->extradata) {
>          ret = ff_cbs_read_extradata_from_codec(s->cbc, &s->current_frame, 
> avctx);
>          if (ret < 0)
> diff --git a/libavcodec/vvc_parser.c b/libavcodec/vvc_parser.c
> index c9c3a3949f..8b3c794dbe 100644
> --- a/libavcodec/vvc_parser.c
> +++ b/libavcodec/vvc_parser.c
> @@ -482,7 +482,10 @@ static av_cold int vvc_parser_init(AVCodecParserContext 
> *s)
>      VVCParserContext *ctx = s->priv_data;
>      int ret;
>  
> -    ret = ff_cbs_init(&ctx->cbc, AV_CODEC_ID_VVC, NULL);
> +    ret = ff_cbs_alloc(&ctx->cbc, AV_CODEC_ID_VVC, NULL);
> +    if (ret < 0)
> +        return ret;
> +    ret = ff_cbs_init(ctx->cbc, NULL);
>      if (ret < 0)
>          return ret;
>      au_detector_init(&ctx->au_detector);
> diff --git a/libavformat/movenccenc.c b/libavformat/movenccenc.c
> index 32094ebd7b..7966a978a8 100644
> --- a/libavformat/movenccenc.c
> +++ b/libavformat/movenccenc.c
> @@ -618,7 +618,11 @@ int ff_mov_cenc_init(MOVMuxCencContext* ctx, uint8_t* 
> encryption_key,
>      ctx->use_subsamples = use_subsamples;
>  
>      if (codec_id == AV_CODEC_ID_AV1) {
> -        ret = ff_lavf_cbs_init(&ctx->cbc, codec_id, NULL);
> +        ret = ff_lavf_cbs_alloc(&ctx->cbc, codec_id, NULL);
> +        if (ret < 0)
> +            return ret;
> +
> +        ret = ff_lavf_cbs_init(ctx->cbc, NULL);
>          if (ret < 0)
>              return ret;
>  

If something like this were ever needed, it should not be implemented
like this; instead ff_cbs_init() should be like avformat_open_input()
and allocate a context if none was provided.

- Andreas

_______________________________________________
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