History

avcodec/utils: move ff_add_cpb_side_data() to encoder code

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

James Almer committed 3 years ago

Commit 0231df51 parent 3744ada13 files · +45 −45Browse files

Showing the changes to libavcodec (13 of 13 files). Show all

Unified · Split

13 files
  1. libavcodec/encode.c +31 −0
  2. libavcodec/encode.h +5 −0
  3. libavcodec/internal.h +0 −5
  4. libavcodec/libaomenc.c +1 −1
  5. libavcodec/libopenh264enc.c +1 −1
  6. libavcodec/libsvtav1.c +1 −1
  7. libavcodec/libvpxenc.c +1 −1
  8. libavcodec/libx264.c +1 −1
  9. libavcodec/libx265.c +1 −1
  10. libavcodec/mpegvideo_enc.c +1 −1
  11. libavcodec/nvenc.c +1 −1
  12. libavcodec/qsvenc.c +1 −1
  13. libavcodec/utils.c +0 −31
libavcodec/encode.c+31−0
@@ -865,3 +865,34 @@ AVCodecInternal *ff_encode_internal_alloc(void) · 864 unmodified lines
865865 {
866866 return av_mallocz(sizeof(EncodeContext));
867867 }
868+
869+AVCPBProperties *ff_encode_add_cpb_side_data(AVCodecContext *avctx)
870+{
871+ AVPacketSideData *tmp;
872+ AVCPBProperties *props;
873+ size_t size;
874+ int i;
875+
876+ for (i = 0; i < avctx->nb_coded_side_data; i++)
877+ if (avctx->coded_side_data[i].type == AV_PKT_DATA_CPB_PROPERTIES)
878+ return (AVCPBProperties *)avctx->coded_side_data[i].data;
879+
880+ props = av_cpb_properties_alloc(&size);
881+ if (!props)
882+ return NULL;
883+
884+ tmp = av_realloc_array(avctx->coded_side_data, avctx->nb_coded_side_data + 1, sizeof(*tmp));
885+ if (!tmp) {
886+ av_freep(&props);
887+ return NULL;
888+ }
889+
890+ avctx->coded_side_data = tmp;
891+ avctx->nb_coded_side_data++;
892+
893+ avctx->coded_side_data[avctx->nb_coded_side_data - 1].type = AV_PKT_DATA_CPB_PROPERTIES;
894+ avctx->coded_side_data[avctx->nb_coded_side_data - 1].data = (uint8_t*)props;
895+ avctx->coded_side_data[avctx->nb_coded_side_data - 1].size = size;
896+
897+ return props;
898+}
libavcodec/encode.h+5−0
@@ -73,6 +73,11 @@ int ff_encode_reordered_opaque(AVCodecContext *avctx, · 72 unmodified lines
7373 int ff_encode_encode_cb(AVCodecContext *avctx, AVPacket *avpkt,
7474 AVFrame *frame, int *got_packet);
7575
76+/**
77+ * Add a CPB properties side data to an encoding context.
78+ */
79+AVCPBProperties *ff_encode_add_cpb_side_data(AVCodecContext *avctx);
80+
7681 /**
7782 * Rescale from sample rate to AVCodecContext.time_base.
7883 */
libavcodec/internal.h+0−5
@@ -180,11 +180,6 @@ int avpriv_h264_has_num_reorder_frames(AVCodecContext *avctx); · 179 unmodified lines
180180
181181 int avpriv_codec_get_cap_skip_frame_fill_param(const AVCodec *codec);
182182
183−/**
184− * Add a CPB properties side data to an encoding context.
185− */
186−AVCPBProperties *ff_add_cpb_side_data(AVCodecContext *avctx);
187−
188183 /**
189184 * Check AVFrame for S12M timecode side data and allocate and fill TC SEI message with timecode info
190185 *
libavcodec/libaomenc.c+1−1
@@ -1018,7 +1018,7 @@ static av_cold int aom_init(AVCodecContext *avctx, · 1017 unmodified lines
10181018 if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH)
10191019 ctx->rawimg.bit_depth = enccfg.g_bit_depth;
10201020
1021− cpb_props = ff_add_cpb_side_data(avctx);
1021+ cpb_props = ff_encode_add_cpb_side_data(avctx);
10221022 if (!cpb_props)
10231023 return AVERROR(ENOMEM);
10241024
libavcodec/libopenh264enc.c+1−1
@@ -353,7 +353,7 @@ FF_ENABLE_DEPRECATION_WARNINGS · 352 unmodified lines
353353 memcpy(avctx->extradata, fbi.sLayerInfo[0].pBsBuf, size);
354354 }
355355
356− props = ff_add_cpb_side_data(avctx);
356+ props = ff_encode_add_cpb_side_data(avctx);
357357 if (!props)
358358 return AVERROR(ENOMEM);
359359 props->max_bitrate = param.iMaxBitrate;
libavcodec/libsvtav1.c+1−1
@@ -325,7 +325,7 @@ FF_ENABLE_DEPRECATION_WARNINGS · 324 unmodified lines
325325 FFMAX(avctx->bit_rate, avctx->rc_max_rate) / 1000LL;
326326
327327 if (avctx->bit_rate || avctx->rc_max_rate || avctx->rc_buffer_size) {
328− AVCPBProperties *cpb_props = ff_add_cpb_side_data(avctx);
328+ AVCPBProperties *cpb_props = ff_encode_add_cpb_side_data(avctx);
329329 if (!cpb_props)
330330 return AVERROR(ENOMEM);
331331
libavcodec/libvpxenc.c+1−1
@@ -1273,7 +1273,7 @@ static av_cold int vpx_init(AVCodecContext *avctx, · 1272 unmodified lines
12731273 ctx->rawimg.bit_depth = enccfg.g_bit_depth;
12741274 #endif
12751275
1276− cpb_props = ff_add_cpb_side_data(avctx);
1276+ cpb_props = ff_encode_add_cpb_side_data(avctx);
12771277 if (!cpb_props)
12781278 return AVERROR(ENOMEM);
12791279
libavcodec/libx264.c+1−1
@@ -1230,7 +1230,7 @@ FF_ENABLE_DEPRECATION_WARNINGS · 1229 unmodified lines
12301230 avctx->extradata_size = p - avctx->extradata;
12311231 }
12321232
1233− cpb_props = ff_add_cpb_side_data(avctx);
1233+ cpb_props = ff_encode_add_cpb_side_data(avctx);
12341234 if (!cpb_props)
12351235 return AVERROR(ENOMEM);
12361236 cpb_props->buffer_size = x4->params.rc.i_vbv_buffer_size * 1000;
libavcodec/libx265.c+1−1
@@ -395,7 +395,7 @@ FF_ENABLE_DEPRECATION_WARNINGS · 394 unmodified lines
395395 ctx->params->rc.vbvBufferSize = avctx->rc_buffer_size / 1000;
396396 ctx->params->rc.vbvMaxBitrate = avctx->rc_max_rate / 1000;
397397
398− cpb_props = ff_add_cpb_side_data(avctx);
398+ cpb_props = ff_encode_add_cpb_side_data(avctx);
399399 if (!cpb_props)
400400 return AVERROR(ENOMEM);
401401 cpb_props->buffer_size = ctx->params->rc.vbvBufferSize * 1000;
libavcodec/mpegvideo_enc.c+1−1
@@ -973,7 +973,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) · 972 unmodified lines
973973 }
974974 }
975975
976− cpb_props = ff_add_cpb_side_data(avctx);
976+ cpb_props = ff_encode_add_cpb_side_data(avctx);
977977 if (!cpb_props)
978978 return AVERROR(ENOMEM);
979979 cpb_props->max_bitrate = avctx->rc_max_rate;
libavcodec/nvenc.c+1−1
@@ -1666,7 +1666,7 @@ FF_ENABLE_DEPRECATION_WARNINGS · 1665 unmodified lines
16661666 if (ctx->encode_config.rcParams.averageBitRate > 0)
16671667 avctx->bit_rate = ctx->encode_config.rcParams.averageBitRate;
16681668
1669− cpb_props = ff_add_cpb_side_data(avctx);
1669+ cpb_props = ff_encode_add_cpb_side_data(avctx);
16701670 if (!cpb_props)
16711671 return AVERROR(ENOMEM);
16721672 cpb_props->max_bitrate = ctx->encode_config.rcParams.maxBitRate;
libavcodec/qsvenc.c+1−1
@@ -1504,7 +1504,7 @@ static int qsv_retrieve_enc_params(AVCodecContext *avctx, QSVEncContext *q) · 1503 unmodified lines
15041504 }
15051505 memset(avctx->extradata + avctx->extradata_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
15061506
1507− cpb_props = ff_add_cpb_side_data(avctx);
1507+ cpb_props = ff_encode_add_cpb_side_data(avctx);
15081508 if (!cpb_props)
15091509 return AVERROR(ENOMEM);
15101510 cpb_props->max_bitrate = avctx->rc_max_rate;
libavcodec/utils.c+0−31
@@ -1018,37 +1018,6 @@ AVCPBProperties *av_cpb_properties_alloc(size_t *size) · 1017 unmodified lines
10181018 return props;
10191019 }
10201020
1021−AVCPBProperties *ff_add_cpb_side_data(AVCodecContext *avctx)
1022−{
1023− AVPacketSideData *tmp;
1024− AVCPBProperties *props;
1025− size_t size;
1026− int i;
1027−
1028− for (i = 0; i < avctx->nb_coded_side_data; i++)
1029− if (avctx->coded_side_data[i].type == AV_PKT_DATA_CPB_PROPERTIES)
1030− return (AVCPBProperties *)avctx->coded_side_data[i].data;
1031−
1032− props = av_cpb_properties_alloc(&size);
1033− if (!props)
1034− return NULL;
1035−
1036− tmp = av_realloc_array(avctx->coded_side_data, avctx->nb_coded_side_data + 1, sizeof(*tmp));
1037− if (!tmp) {
1038− av_freep(&props);
1039− return NULL;
1040− }
1041−
1042− avctx->coded_side_data = tmp;
1043− avctx->nb_coded_side_data++;
1044−
1045− avctx->coded_side_data[avctx->nb_coded_side_data - 1].type = AV_PKT_DATA_CPB_PROPERTIES;
1046− avctx->coded_side_data[avctx->nb_coded_side_data - 1].data = (uint8_t*)props;
1047− avctx->coded_side_data[avctx->nb_coded_side_data - 1].size = size;
1048−
1049− return props;
1050−}
1051−
10521021 static unsigned bcd2uint(uint8_t bcd)
10531022 {
10541023 unsigned low = bcd & 0xf;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t