[FFmpeg-devel] [PATCH 15/17] avcodec/utils: move ff_add_cpb_side_data() to encoder code

James Almer jamrial at gmail.com
Mon Sep 4 18:04:08 EEST 2023


It's only used by encoders, so move it to prevent wrong usage.

Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavcodec/encode.c         | 23 +++++++++++++++++++++++
 libavcodec/encode.h         |  5 +++++
 libavcodec/internal.h       |  5 -----
 libavcodec/libaomenc.c      |  2 +-
 libavcodec/libopenh264enc.c |  2 +-
 libavcodec/libsvtav1.c      |  2 +-
 libavcodec/libvpxenc.c      |  2 +-
 libavcodec/libx264.c        |  2 +-
 libavcodec/libx265.c        |  2 +-
 libavcodec/mpegvideo_enc.c  |  2 +-
 libavcodec/nvenc.c          |  2 +-
 libavcodec/qsvenc.c         |  2 +-
 libavcodec/utils.c          | 23 -----------------------
 13 files changed, 37 insertions(+), 37 deletions(-)

diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index b92593770c..417ce954aa 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -865,3 +865,26 @@ AVCodecInternal *ff_encode_internal_alloc(void)
 {
     return av_mallocz(sizeof(EncodeContext));
 }
+
+AVCPBProperties *ff_encode_add_cpb_side_data(AVCodecContext *avctx)
+{
+    AVPacketSideData *sd;
+    AVCPBProperties  *props;
+    size_t size;
+
+    av_assert0(av_codec_is_encoder(avctx->codec));
+
+    sd = av_packet_side_data_set_get(&avctx->packet_side_data, AV_PKT_DATA_CPB_PROPERTIES);
+    if (sd)
+        return (AVCPBProperties *)sd->data;
+
+    props = av_cpb_properties_alloc(&size);
+    if (!props)
+        return NULL;
+
+    if (!av_packet_side_data_set_add(&avctx->packet_side_data, AV_PKT_DATA_CPB_PROPERTIES,
+                                     (uint8_t *)props, size, 0))
+        av_freep(&props);
+
+    return props;
+}
diff --git a/libavcodec/encode.h b/libavcodec/encode.h
index dfaab7c976..e019cd7702 100644
--- a/libavcodec/encode.h
+++ b/libavcodec/encode.h
@@ -73,6 +73,11 @@ int ff_encode_reordered_opaque(AVCodecContext *avctx,
 int ff_encode_encode_cb(AVCodecContext *avctx, AVPacket *avpkt,
                         AVFrame *frame, int *got_packet);
 
+/**
+ * Add a CPB properties side data to an encoding context.
+ */
+AVCPBProperties *ff_encode_add_cpb_side_data(AVCodecContext *avctx);
+
 /**
  * Rescale from sample rate to AVCodecContext.time_base.
  */
diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index a67cf713ca..83e0bc3fb2 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -180,11 +180,6 @@ int avpriv_h264_has_num_reorder_frames(AVCodecContext *avctx);
 
 int avpriv_codec_get_cap_skip_frame_fill_param(const AVCodec *codec);
 
-/**
- * Add a CPB properties side data to an encoding context.
- */
-AVCPBProperties *ff_add_cpb_side_data(AVCodecContext *avctx);
-
 /**
  * Check AVFrame for S12M timecode side data and allocate and fill TC SEI message with timecode info
  *
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index f29cb0784a..53a1159b75 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -1018,7 +1018,7 @@ static av_cold int aom_init(AVCodecContext *avctx,
     if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH)
         ctx->rawimg.bit_depth = enccfg.g_bit_depth;
 
-    cpb_props = ff_add_cpb_side_data(avctx);
+    cpb_props = ff_encode_add_cpb_side_data(avctx);
     if (!cpb_props)
         return AVERROR(ENOMEM);
 
diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
index 5b59af6f94..433accba22 100644
--- a/libavcodec/libopenh264enc.c
+++ b/libavcodec/libopenh264enc.c
@@ -353,7 +353,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
         memcpy(avctx->extradata, fbi.sLayerInfo[0].pBsBuf, size);
     }
 
-    props = ff_add_cpb_side_data(avctx);
+    props = ff_encode_add_cpb_side_data(avctx);
     if (!props)
         return AVERROR(ENOMEM);
     props->max_bitrate = param.iMaxBitrate;
diff --git a/libavcodec/libsvtav1.c b/libavcodec/libsvtav1.c
index f2b73361d8..a8b3b62b96 100644
--- a/libavcodec/libsvtav1.c
+++ b/libavcodec/libsvtav1.c
@@ -325,7 +325,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
                             FFMAX(avctx->bit_rate, avctx->rc_max_rate) / 1000LL;
 
     if (avctx->bit_rate || avctx->rc_max_rate || avctx->rc_buffer_size) {
-        AVCPBProperties *cpb_props = ff_add_cpb_side_data(avctx);
+        AVCPBProperties *cpb_props = ff_encode_add_cpb_side_data(avctx);
         if (!cpb_props)
             return AVERROR(ENOMEM);
 
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 7a545527a9..0f6f4e785c 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -1273,7 +1273,7 @@ static av_cold int vpx_init(AVCodecContext *avctx,
         ctx->rawimg.bit_depth = enccfg.g_bit_depth;
 #endif
 
-    cpb_props = ff_add_cpb_side_data(avctx);
+    cpb_props = ff_encode_add_cpb_side_data(avctx);
     if (!cpb_props)
         return AVERROR(ENOMEM);
 
diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index ce849d6c9a..131d1c7fc9 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -1231,7 +1231,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
         avctx->extradata_size = p - avctx->extradata;
     }
 
-    cpb_props = ff_add_cpb_side_data(avctx);
+    cpb_props = ff_encode_add_cpb_side_data(avctx);
     if (!cpb_props)
         return AVERROR(ENOMEM);
     cpb_props->buffer_size = x4->params.rc.i_vbv_buffer_size * 1000;
diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
index 873b3021ee..447e6da25f 100644
--- a/libavcodec/libx265.c
+++ b/libavcodec/libx265.c
@@ -395,7 +395,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
     ctx->params->rc.vbvBufferSize = avctx->rc_buffer_size / 1000;
     ctx->params->rc.vbvMaxBitrate = avctx->rc_max_rate    / 1000;
 
-    cpb_props = ff_add_cpb_side_data(avctx);
+    cpb_props = ff_encode_add_cpb_side_data(avctx);
     if (!cpb_props)
         return AVERROR(ENOMEM);
     cpb_props->buffer_size = ctx->params->rc.vbvBufferSize * 1000;
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 69e3152c82..5bf4b06a11 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -973,7 +973,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
         }
     }
 
-    cpb_props = ff_add_cpb_side_data(avctx);
+    cpb_props = ff_encode_add_cpb_side_data(avctx);
     if (!cpb_props)
         return AVERROR(ENOMEM);
     cpb_props->max_bitrate = avctx->rc_max_rate;
diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index 1e83ea9734..4249ff7188 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -1666,7 +1666,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
     if (ctx->encode_config.rcParams.averageBitRate > 0)
         avctx->bit_rate = ctx->encode_config.rcParams.averageBitRate;
 
-    cpb_props = ff_add_cpb_side_data(avctx);
+    cpb_props = ff_encode_add_cpb_side_data(avctx);
     if (!cpb_props)
         return AVERROR(ENOMEM);
     cpb_props->max_bitrate = ctx->encode_config.rcParams.maxBitRate;
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index b3b7475b0f..ac7364f61f 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -1504,7 +1504,7 @@ static int qsv_retrieve_enc_params(AVCodecContext *avctx, QSVEncContext *q)
     }
     memset(avctx->extradata + avctx->extradata_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
 
-    cpb_props = ff_add_cpb_side_data(avctx);
+    cpb_props = ff_encode_add_cpb_side_data(avctx);
     if (!cpb_props)
         return AVERROR(ENOMEM);
     cpb_props->max_bitrate = avctx->rc_max_rate;
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 90e573890f..d54e050848 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -1018,29 +1018,6 @@ AVCPBProperties *av_cpb_properties_alloc(size_t *size)
     return props;
 }
 
-AVCPBProperties *ff_add_cpb_side_data(AVCodecContext *avctx)
-{
-    AVPacketSideData *sd;
-    AVCPBProperties  *props;
-    size_t size;
-
-    av_assert0(av_codec_is_encoder(avctx->codec));
-
-    sd = av_packet_side_data_set_get(&avctx->packet_side_data, AV_PKT_DATA_CPB_PROPERTIES);
-    if (sd)
-        return (AVCPBProperties *)sd->data;
-
-    props = av_cpb_properties_alloc(&size);
-    if (!props)
-        return NULL;
-
-    if (!av_packet_side_data_set_add(&avctx->packet_side_data, AV_PKT_DATA_CPB_PROPERTIES,
-                                     (uint8_t *)props, size, 0))
-        av_freep(&props);
-
-    return props;
-}
-
 static unsigned bcd2uint(uint8_t bcd)
 {
     unsigned low  = bcd & 0xf;
-- 
2.42.0



More information about the ffmpeg-devel mailing list