avcodec/utils: move ff_add_cpb_side_data() to encoder code
It's only used by encoders, so move it to prevent wrong usage. Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
parent
3744ada3b8
commit
0231df505d
@ -865,3 +865,34 @@ AVCodecInternal *ff_encode_internal_alloc(void)
|
|||||||
{
|
{
|
||||||
return av_mallocz(sizeof(EncodeContext));
|
return av_mallocz(sizeof(EncodeContext));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AVCPBProperties *ff_encode_add_cpb_side_data(AVCodecContext *avctx)
|
||||||
|
{
|
||||||
|
AVPacketSideData *tmp;
|
||||||
|
AVCPBProperties *props;
|
||||||
|
size_t size;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < avctx->nb_coded_side_data; i++)
|
||||||
|
if (avctx->coded_side_data[i].type == AV_PKT_DATA_CPB_PROPERTIES)
|
||||||
|
return (AVCPBProperties *)avctx->coded_side_data[i].data;
|
||||||
|
|
||||||
|
props = av_cpb_properties_alloc(&size);
|
||||||
|
if (!props)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
tmp = av_realloc_array(avctx->coded_side_data, avctx->nb_coded_side_data + 1, sizeof(*tmp));
|
||||||
|
if (!tmp) {
|
||||||
|
av_freep(&props);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
avctx->coded_side_data = tmp;
|
||||||
|
avctx->nb_coded_side_data++;
|
||||||
|
|
||||||
|
avctx->coded_side_data[avctx->nb_coded_side_data - 1].type = AV_PKT_DATA_CPB_PROPERTIES;
|
||||||
|
avctx->coded_side_data[avctx->nb_coded_side_data - 1].data = (uint8_t*)props;
|
||||||
|
avctx->coded_side_data[avctx->nb_coded_side_data - 1].size = size;
|
||||||
|
|
||||||
|
return props;
|
||||||
|
}
|
||||||
|
@ -73,6 +73,11 @@ int ff_encode_reordered_opaque(AVCodecContext *avctx,
|
|||||||
int ff_encode_encode_cb(AVCodecContext *avctx, AVPacket *avpkt,
|
int ff_encode_encode_cb(AVCodecContext *avctx, AVPacket *avpkt,
|
||||||
AVFrame *frame, int *got_packet);
|
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.
|
* Rescale from sample rate to AVCodecContext.time_base.
|
||||||
*/
|
*/
|
||||||
|
@ -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);
|
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
|
* Check AVFrame for S12M timecode side data and allocate and fill TC SEI message with timecode info
|
||||||
*
|
*
|
||||||
|
@ -1018,7 +1018,7 @@ static av_cold int aom_init(AVCodecContext *avctx,
|
|||||||
if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH)
|
if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH)
|
||||||
ctx->rawimg.bit_depth = enccfg.g_bit_depth;
|
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)
|
if (!cpb_props)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
|
|
||||||
|
@ -353,7 +353,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
|
|||||||
memcpy(avctx->extradata, fbi.sLayerInfo[0].pBsBuf, size);
|
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)
|
if (!props)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
props->max_bitrate = param.iMaxBitrate;
|
props->max_bitrate = param.iMaxBitrate;
|
||||||
|
@ -325,7 +325,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
|
|||||||
FFMAX(avctx->bit_rate, avctx->rc_max_rate) / 1000LL;
|
FFMAX(avctx->bit_rate, avctx->rc_max_rate) / 1000LL;
|
||||||
|
|
||||||
if (avctx->bit_rate || avctx->rc_max_rate || avctx->rc_buffer_size) {
|
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)
|
if (!cpb_props)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
|
|
||||||
|
@ -1273,7 +1273,7 @@ static av_cold int vpx_init(AVCodecContext *avctx,
|
|||||||
ctx->rawimg.bit_depth = enccfg.g_bit_depth;
|
ctx->rawimg.bit_depth = enccfg.g_bit_depth;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
cpb_props = ff_add_cpb_side_data(avctx);
|
cpb_props = ff_encode_add_cpb_side_data(avctx);
|
||||||
if (!cpb_props)
|
if (!cpb_props)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
|
|
||||||
|
@ -1230,7 +1230,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
|
|||||||
avctx->extradata_size = p - avctx->extradata;
|
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)
|
if (!cpb_props)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
cpb_props->buffer_size = x4->params.rc.i_vbv_buffer_size * 1000;
|
cpb_props->buffer_size = x4->params.rc.i_vbv_buffer_size * 1000;
|
||||||
|
@ -395,7 +395,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
|
|||||||
ctx->params->rc.vbvBufferSize = avctx->rc_buffer_size / 1000;
|
ctx->params->rc.vbvBufferSize = avctx->rc_buffer_size / 1000;
|
||||||
ctx->params->rc.vbvMaxBitrate = avctx->rc_max_rate / 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)
|
if (!cpb_props)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
cpb_props->buffer_size = ctx->params->rc.vbvBufferSize * 1000;
|
cpb_props->buffer_size = ctx->params->rc.vbvBufferSize * 1000;
|
||||||
|
@ -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)
|
if (!cpb_props)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
cpb_props->max_bitrate = avctx->rc_max_rate;
|
cpb_props->max_bitrate = avctx->rc_max_rate;
|
||||||
|
@ -1666,7 +1666,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
|
|||||||
if (ctx->encode_config.rcParams.averageBitRate > 0)
|
if (ctx->encode_config.rcParams.averageBitRate > 0)
|
||||||
avctx->bit_rate = ctx->encode_config.rcParams.averageBitRate;
|
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)
|
if (!cpb_props)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
cpb_props->max_bitrate = ctx->encode_config.rcParams.maxBitRate;
|
cpb_props->max_bitrate = ctx->encode_config.rcParams.maxBitRate;
|
||||||
|
@ -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);
|
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)
|
if (!cpb_props)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
cpb_props->max_bitrate = avctx->rc_max_rate;
|
cpb_props->max_bitrate = avctx->rc_max_rate;
|
||||||
|
@ -1018,37 +1018,6 @@ AVCPBProperties *av_cpb_properties_alloc(size_t *size)
|
|||||||
return props;
|
return props;
|
||||||
}
|
}
|
||||||
|
|
||||||
AVCPBProperties *ff_add_cpb_side_data(AVCodecContext *avctx)
|
|
||||||
{
|
|
||||||
AVPacketSideData *tmp;
|
|
||||||
AVCPBProperties *props;
|
|
||||||
size_t size;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < avctx->nb_coded_side_data; i++)
|
|
||||||
if (avctx->coded_side_data[i].type == AV_PKT_DATA_CPB_PROPERTIES)
|
|
||||||
return (AVCPBProperties *)avctx->coded_side_data[i].data;
|
|
||||||
|
|
||||||
props = av_cpb_properties_alloc(&size);
|
|
||||||
if (!props)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
tmp = av_realloc_array(avctx->coded_side_data, avctx->nb_coded_side_data + 1, sizeof(*tmp));
|
|
||||||
if (!tmp) {
|
|
||||||
av_freep(&props);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
avctx->coded_side_data = tmp;
|
|
||||||
avctx->nb_coded_side_data++;
|
|
||||||
|
|
||||||
avctx->coded_side_data[avctx->nb_coded_side_data - 1].type = AV_PKT_DATA_CPB_PROPERTIES;
|
|
||||||
avctx->coded_side_data[avctx->nb_coded_side_data - 1].data = (uint8_t*)props;
|
|
||||||
avctx->coded_side_data[avctx->nb_coded_side_data - 1].size = size;
|
|
||||||
|
|
||||||
return props;
|
|
||||||
}
|
|
||||||
|
|
||||||
static unsigned bcd2uint(uint8_t bcd)
|
static unsigned bcd2uint(uint8_t bcd)
|
||||||
{
|
{
|
||||||
unsigned low = bcd & 0xf;
|
unsigned low = bcd & 0xf;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user