diff options
author | James Almer <jamrial@gmail.com> | 2023-07-16 17:57:26 -0300 |
---|---|---|
committer | James Almer <jamrial@gmail.com> | 2023-10-06 10:03:57 -0300 |
commit | 5432d2aacad5fa7420fe2d9369ed061d521e92d6 (patch) | |
tree | 9c1bf0307108a16ed652261d590042e5944e288d /libavformat/demux.c | |
parent | 21d7cc6fa9a26e94965fa71b25655d07568450fe (diff) | |
download | ffmpeg-5432d2aacad5fa7420fe2d9369ed061d521e92d6.tar.gz |
avformat/avformat: use the side data from AVStream.codecpar
Deprecate AVStream.side_data and its helpers in favor of the AVStream's
codecpar.coded_side_data.
This will considerably simplify the propagation of global side data to decoders
and from encoders. Instead of having to do it inside packets, it will be
available during init().
Global and frame specific side data will therefore be distinct.
Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavformat/demux.c')
-rw-r--r-- | libavformat/demux.c | 53 |
1 files changed, 33 insertions, 20 deletions
diff --git a/libavformat/demux.c b/libavformat/demux.c index 45cdb8e1b7..6f640b92b1 100644 --- a/libavformat/demux.c +++ b/libavformat/demux.c @@ -1409,9 +1409,10 @@ FF_ENABLE_DEPRECATION_WARNINGS sti->skip_samples = 0; } +#if FF_API_AVSTREAM_SIDE_DATA if (sti->inject_global_side_data) { - for (int i = 0; i < st->nb_side_data; i++) { - const AVPacketSideData *const src_sd = &st->side_data[i]; + for (int i = 0; i < st->codecpar->nb_coded_side_data; i++) { + const AVPacketSideData *const src_sd = &st->codecpar->coded_side_data[i]; uint8_t *dst_data; if (av_packet_get_side_data(pkt, src_sd->type, NULL)) @@ -1427,6 +1428,7 @@ FF_ENABLE_DEPRECATION_WARNINGS } sti->inject_global_side_data = 0; } +#endif } if (!si->metafree) { @@ -2431,19 +2433,6 @@ static int extract_extradata(FFFormatContext *si, AVStream *st, const AVPacket * return 0; } -static int add_coded_side_data(AVStream *st, AVCodecContext *avctx) -{ - for (int i = 0; i < avctx->nb_coded_side_data; i++) { - const AVPacketSideData *const sd_src = &avctx->coded_side_data[i]; - uint8_t *dst_data; - dst_data = av_stream_new_side_data(st, sd_src->type, sd_src->size); - if (!dst_data) - return AVERROR(ENOMEM); - memcpy(dst_data, sd_src->data, sd_src->size); - } - return 0; -} - int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) { FFFormatContext *const si = ffformatcontext(ic); @@ -2971,9 +2960,6 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) ret = avcodec_parameters_from_context(st->codecpar, sti->avctx); if (ret < 0) goto find_stream_info_err; - ret = add_coded_side_data(st, sti->avctx); - if (ret < 0) - goto find_stream_info_err; if (sti->avctx->rc_buffer_size > 0 || sti->avctx->rc_max_rate > 0 || sti->avctx->rc_min_rate) { @@ -2986,14 +2972,41 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) props->min_bitrate = sti->avctx->rc_min_rate; if (sti->avctx->rc_max_rate > 0) props->max_bitrate = sti->avctx->rc_max_rate; - if (av_stream_add_side_data(st, AV_PKT_DATA_CPB_PROPERTIES, - (uint8_t *)props, cpb_size)) + if (!av_packet_side_data_add(&st->codecpar->coded_side_data, + &st->codecpar->nb_coded_side_data, + AV_PKT_DATA_CPB_PROPERTIES, + (uint8_t *)props, cpb_size, 0)) av_free(props); } } } sti->avctx_inited = 0; +#if FF_API_AVSTREAM_SIDE_DATA +FF_DISABLE_DEPRECATION_WARNINGS + if (st->codecpar->nb_coded_side_data > 0) { + av_assert0(!st->side_data && !st->nb_side_data); + st->side_data = av_calloc(st->codecpar->nb_coded_side_data, sizeof(*st->side_data)); + if (!st->side_data) { + ret = AVERROR(ENOMEM); + goto find_stream_info_err; + } + + for (int j = 0; j < st->codecpar->nb_coded_side_data; j++) { + uint8_t *data = av_memdup(st->codecpar->coded_side_data[j].data, + st->codecpar->coded_side_data[j].size); + if (!data) { + ret = AVERROR(ENOMEM); + goto find_stream_info_err; + } + st->side_data[j].type = st->codecpar->coded_side_data[j].type; + st->side_data[j].size = st->codecpar->coded_side_data[j].size; + st->side_data[j].data = data; + st->nb_side_data++; + } + } +FF_ENABLE_DEPRECATION_WARNINGS +#endif } find_stream_info_err: |