[FFmpeg-devel] [PATCH 07/10] avcodec/hevcdec: check for DOVI configuration record in AVCodecContext side data

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Mon Sep 11 20:58:55 EEST 2023


James Almer:
> Signed-off-by: James Almer <jamrial at gmail.com>
> ---
>  libavcodec/avcodec.h  |  2 +-
>  libavcodec/hevcdec.c  | 15 ++++++++++++++-
>  libavcodec/internal.h |  3 +++
>  libavcodec/utils.c    | 10 ++++++++++
>  4 files changed, 28 insertions(+), 2 deletions(-)
> 
> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> index 1f477209b0..b875076ba5 100644
> --- a/libavcodec/avcodec.h
> +++ b/libavcodec/avcodec.h
> @@ -1893,7 +1893,7 @@ typedef struct AVCodecContext {
>      /**
>       * Additional data associated with the entire coded stream.
>       *
> -     * - decoding: unused
> +     * - decoding: set by user
>       * - encoding: may be set by libavcodec after avcodec_open2().
>       */
>      AVPacketSideData *coded_side_data;
> diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
> index df40c91ba6..162b832800 100644
> --- a/libavcodec/hevcdec.c
> +++ b/libavcodec/hevcdec.c
> @@ -3337,8 +3337,15 @@ static int hevc_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
>      }
>  
>      sd = av_packet_get_side_data(avpkt, AV_PKT_DATA_DOVI_CONF, &sd_size);
> -    if (sd && sd_size > 0)
> +    if (sd && sd_size > 0) {
> +        int old = s->dovi_ctx.dv_profile;
> +
>          ff_dovi_update_cfg(&s->dovi_ctx, (AVDOVIDecoderConfigurationRecord *) sd);
> +        if (old)
> +            av_log(avctx, AV_LOG_DEBUG,
> +                   "New DOVI configuration record from input packet (profile %d -> %u).\n",
> +                   old, s->dovi_ctx.dv_profile);
> +    }
>  
>      s->ref = NULL;
>      ret    = decode_nal_units(s, avpkt->data, avpkt->size);
> @@ -3641,12 +3648,18 @@ static av_cold int hevc_decode_init(AVCodecContext *avctx)
>      atomic_init(&s->wpp_err, 0);
>  
>      if (!avctx->internal->is_copy) {
> +        const AVPacketSideData *sd;
> +
>          if (avctx->extradata_size > 0 && avctx->extradata) {
>              ret = hevc_decode_extradata(s, avctx->extradata, avctx->extradata_size, 1);
>              if (ret < 0) {
>                  return ret;
>              }
>          }
> +
> +        sd = ff_get_coded_side_data(avctx, AV_PKT_DATA_DOVI_CONF);
> +        if (sd && sd->size > 0)
> +            ff_dovi_update_cfg(&s->dovi_ctx, (AVDOVIDecoderConfigurationRecord *) sd->data);
>      }
>  
>      return 0;
> diff --git a/libavcodec/internal.h b/libavcodec/internal.h
> index 83e0bc3fb2..517d96fb97 100644
> --- a/libavcodec/internal.h
> +++ b/libavcodec/internal.h
> @@ -202,4 +202,7 @@ int ff_alloc_timecode_sei(const AVFrame *frame, AVRational rate, size_t prefix_l
>   */
>  int64_t ff_guess_coded_bitrate(AVCodecContext *avctx);
>  
> +AVPacketSideData *ff_get_coded_side_data(const AVCodecContext *avctx,
> +                                         enum AVPacketSideDataType type);

Why is this not in decode.h? An encoder has little reason to inquire
whether side data exists (given that if it exists, it has added it).

> +
>  #endif /* AVCODEC_INTERNAL_H */
> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> index d54e050848..4fbd591bf1 100644
> --- a/libavcodec/utils.c
> +++ b/libavcodec/utils.c
> @@ -1111,3 +1111,13 @@ int64_t ff_guess_coded_bitrate(AVCodecContext *avctx)
>  
>      return bitrate;
>  }
> +
> +AVPacketSideData *ff_get_coded_side_data(const AVCodecContext *avctx,
> +                                         enum AVPacketSideDataType type)
> +{
> +    for (int i = 0; i < avctx->nb_coded_side_data; i++)
> +        if (avctx->coded_side_data[i].type == type)
> +            return &avctx->coded_side_data[i];
> +
> +    return NULL;
> +}



More information about the ffmpeg-devel mailing list