It's only used by encoders, so move it to prevent wrong usage.
Unified · Split
| @@ -865,3 +865,34 @@ AVCodecInternal *ff_encode_internal_alloc(void) · 864 unmodified lines | |||
| 865 | { | 865 | { |
| 866 | return av_mallocz(sizeof(EncodeContext)); | 866 | return av_mallocz(sizeof(EncodeContext)); |
| 867 | } | 867 | } |
| 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 | } | ||
| @@ -73,6 +73,11 @@ int ff_encode_reordered_opaque(AVCodecContext *avctx, · 72 unmodified lines | |||
| 73 | int ff_encode_encode_cb(AVCodecContext *avctx, AVPacket *avpkt, | 73 | int ff_encode_encode_cb(AVCodecContext *avctx, AVPacket *avpkt, |
| 74 | AVFrame *frame, int *got_packet); | 74 | AVFrame *frame, int *got_packet); |
| 75 | 75 | ||
| 76 | /** | ||
| 77 | * Add a CPB properties side data to an encoding context. | ||
| 78 | */ | ||
| 79 | AVCPBProperties *ff_encode_add_cpb_side_data(AVCodecContext *avctx); | ||
| 80 | |||
| 76 | /** | 81 | /** |
| 77 | * Rescale from sample rate to AVCodecContext.time_base. | 82 | * Rescale from sample rate to AVCodecContext.time_base. |
| 78 | */ | 83 | */ |
| @@ -180,11 +180,6 @@ int avpriv_h264_has_num_reorder_frames(AVCodecContext *avctx); · 179 unmodified lines | |||
| 180 | 180 | ||
| 181 | int avpriv_codec_get_cap_skip_frame_fill_param(const AVCodec *codec); | 181 | int avpriv_codec_get_cap_skip_frame_fill_param(const AVCodec *codec); |
| 182 | 182 | ||
| 183 | /** | ||
| 184 | * Add a CPB properties side data to an encoding context. | ||
| 185 | */ | ||
| 186 | AVCPBProperties *ff_add_cpb_side_data(AVCodecContext *avctx); | ||
| 187 | |||
| 188 | /** | 183 | /** |
| 189 | * Check AVFrame for S12M timecode side data and allocate and fill TC SEI message with timecode info | 184 | * Check AVFrame for S12M timecode side data and allocate and fill TC SEI message with timecode info |
| 190 | * | 185 | * |
| @@ -1018,7 +1018,7 @@ static av_cold int aom_init(AVCodecContext *avctx, · 1017 unmodified lines | |||
| 1018 | if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) | 1018 | if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) |
| 1019 | ctx->rawimg.bit_depth = enccfg.g_bit_depth; | 1019 | ctx->rawimg.bit_depth = enccfg.g_bit_depth; |
| 1020 | 1020 | ||
| 1021 | cpb_props = ff_add_cpb_side_data(avctx); | 1021 | cpb_props = ff_encode_add_cpb_side_data(avctx); |
| 1022 | if (!cpb_props) | 1022 | if (!cpb_props) |
| 1023 | return AVERROR(ENOMEM); | 1023 | return AVERROR(ENOMEM); |
| 1024 | 1024 | ||
| @@ -353,7 +353,7 @@ FF_ENABLE_DEPRECATION_WARNINGS · 352 unmodified lines | |||
| 353 | memcpy(avctx->extradata, fbi.sLayerInfo[0].pBsBuf, size); | 353 | memcpy(avctx->extradata, fbi.sLayerInfo[0].pBsBuf, size); |
| 354 | } | 354 | } |
| 355 | 355 | ||
| 356 | props = ff_add_cpb_side_data(avctx); | 356 | props = ff_encode_add_cpb_side_data(avctx); |
| 357 | if (!props) | 357 | if (!props) |
| 358 | return AVERROR(ENOMEM); | 358 | return AVERROR(ENOMEM); |
| 359 | props->max_bitrate = param.iMaxBitrate; | 359 | props->max_bitrate = param.iMaxBitrate; |
| @@ -325,7 +325,7 @@ FF_ENABLE_DEPRECATION_WARNINGS · 324 unmodified lines | |||
| 325 | FFMAX(avctx->bit_rate, avctx->rc_max_rate) / 1000LL; | 325 | FFMAX(avctx->bit_rate, avctx->rc_max_rate) / 1000LL; |
| 326 | 326 | ||
| 327 | if (avctx->bit_rate || avctx->rc_max_rate || avctx->rc_buffer_size) { | 327 | 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); |
| 329 | if (!cpb_props) | 329 | if (!cpb_props) |
| 330 | return AVERROR(ENOMEM); | 330 | return AVERROR(ENOMEM); |
| 331 | 331 | ||
| @@ -1273,7 +1273,7 @@ static av_cold int vpx_init(AVCodecContext *avctx, · 1272 unmodified lines | |||
| 1273 | ctx->rawimg.bit_depth = enccfg.g_bit_depth; | 1273 | ctx->rawimg.bit_depth = enccfg.g_bit_depth; |
| 1274 | #endif | 1274 | #endif |
| 1275 | 1275 | ||
| 1276 | cpb_props = ff_add_cpb_side_data(avctx); | 1276 | cpb_props = ff_encode_add_cpb_side_data(avctx); |
| 1277 | if (!cpb_props) | 1277 | if (!cpb_props) |
| 1278 | return AVERROR(ENOMEM); | 1278 | return AVERROR(ENOMEM); |
| 1279 | 1279 | ||
| @@ -1230,7 +1230,7 @@ FF_ENABLE_DEPRECATION_WARNINGS · 1229 unmodified lines | |||
| 1230 | avctx->extradata_size = p - avctx->extradata; | 1230 | avctx->extradata_size = p - avctx->extradata; |
| 1231 | } | 1231 | } |
| 1232 | 1232 | ||
| 1233 | cpb_props = ff_add_cpb_side_data(avctx); | 1233 | cpb_props = ff_encode_add_cpb_side_data(avctx); |
| 1234 | if (!cpb_props) | 1234 | if (!cpb_props) |
| 1235 | return AVERROR(ENOMEM); | 1235 | return AVERROR(ENOMEM); |
| 1236 | cpb_props->buffer_size = x4->params.rc.i_vbv_buffer_size * 1000; | 1236 | cpb_props->buffer_size = x4->params.rc.i_vbv_buffer_size * 1000; |
| @@ -395,7 +395,7 @@ FF_ENABLE_DEPRECATION_WARNINGS · 394 unmodified lines | |||
| 395 | ctx->params->rc.vbvBufferSize = avctx->rc_buffer_size / 1000; | 395 | ctx->params->rc.vbvBufferSize = avctx->rc_buffer_size / 1000; |
| 396 | ctx->params->rc.vbvMaxBitrate = avctx->rc_max_rate / 1000; | 396 | ctx->params->rc.vbvMaxBitrate = avctx->rc_max_rate / 1000; |
| 397 | 397 | ||
| 398 | cpb_props = ff_add_cpb_side_data(avctx); | 398 | cpb_props = ff_encode_add_cpb_side_data(avctx); |
| 399 | if (!cpb_props) | 399 | if (!cpb_props) |
| 400 | return AVERROR(ENOMEM); | 400 | return AVERROR(ENOMEM); |
| 401 | cpb_props->buffer_size = ctx->params->rc.vbvBufferSize * 1000; | 401 | cpb_props->buffer_size = ctx->params->rc.vbvBufferSize * 1000; |
| @@ -973,7 +973,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) · 972 unmodified lines | |||
| 973 | } | 973 | } |
| 974 | } | 974 | } |
| 975 | 975 | ||
| 976 | cpb_props = ff_add_cpb_side_data(avctx); | 976 | cpb_props = ff_encode_add_cpb_side_data(avctx); |
| 977 | if (!cpb_props) | 977 | if (!cpb_props) |
| 978 | return AVERROR(ENOMEM); | 978 | return AVERROR(ENOMEM); |
| 979 | cpb_props->max_bitrate = avctx->rc_max_rate; | 979 | cpb_props->max_bitrate = avctx->rc_max_rate; |
| @@ -1666,7 +1666,7 @@ FF_ENABLE_DEPRECATION_WARNINGS · 1665 unmodified lines | |||
| 1666 | if (ctx->encode_config.rcParams.averageBitRate > 0) | 1666 | if (ctx->encode_config.rcParams.averageBitRate > 0) |
| 1667 | avctx->bit_rate = ctx->encode_config.rcParams.averageBitRate; | 1667 | avctx->bit_rate = ctx->encode_config.rcParams.averageBitRate; |
| 1668 | 1668 | ||
| 1669 | cpb_props = ff_add_cpb_side_data(avctx); | 1669 | cpb_props = ff_encode_add_cpb_side_data(avctx); |
| 1670 | if (!cpb_props) | 1670 | if (!cpb_props) |
| 1671 | return AVERROR(ENOMEM); | 1671 | return AVERROR(ENOMEM); |
| 1672 | cpb_props->max_bitrate = ctx->encode_config.rcParams.maxBitRate; | 1672 | cpb_props->max_bitrate = ctx->encode_config.rcParams.maxBitRate; |
| @@ -1504,7 +1504,7 @@ static int qsv_retrieve_enc_params(AVCodecContext *avctx, QSVEncContext *q) · 1503 unmodified lines | |||
| 1504 | } | 1504 | } |
| 1505 | memset(avctx->extradata + avctx->extradata_size, 0, AV_INPUT_BUFFER_PADDING_SIZE); | 1505 | memset(avctx->extradata + avctx->extradata_size, 0, AV_INPUT_BUFFER_PADDING_SIZE); |
| 1506 | 1506 | ||
| 1507 | cpb_props = ff_add_cpb_side_data(avctx); | 1507 | cpb_props = ff_encode_add_cpb_side_data(avctx); |
| 1508 | if (!cpb_props) | 1508 | if (!cpb_props) |
| 1509 | return AVERROR(ENOMEM); | 1509 | return AVERROR(ENOMEM); |
| 1510 | cpb_props->max_bitrate = avctx->rc_max_rate; | 1510 | cpb_props->max_bitrate = avctx->rc_max_rate; |
| @@ -1018,37 +1018,6 @@ AVCPBProperties *av_cpb_properties_alloc(size_t *size) · 1017 unmodified lines | |||
| 1018 | return props; | 1018 | return props; |
| 1019 | } | 1019 | } |
| 1020 | 1020 | ||
| 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 | |||
| 1052 | static unsigned bcd2uint(uint8_t bcd) | 1021 | static unsigned bcd2uint(uint8_t bcd) |
| 1053 | { | 1022 | { |
| 1054 | unsigned low = bcd & 0xf; | 1023 | unsigned low = bcd & 0xf; |