Message ID | 20230320233408.134255-11-jeebjp@gmail.com |
---|---|
State | New |
Headers | show |
Series | encoder AVCodecContext configuration side data | expand |
Context | Check | Description |
---|---|---|
andriy/make_x86 | success | Make finished |
andriy/make_fate_x86 | success | Make fate finished |
Quoting Jan Ekström (2023-03-21 00:34:04) > diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h > index 30f1d312f4..8f535a0cc8 100644 > --- a/libavcodec/avcodec.h > +++ b/libavcodec/avcodec.h > @@ -3223,6 +3223,18 @@ void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size); > */ > int avcodec_is_open(AVCodecContext *s); > > +/** > + * Configure a side data set to an encoder AVCodecContext. With multiple > + * calls new side data gets added in addition to the existing set of side data. I have no idea what does "configure" mean in this context and what effect will this actually have.
On Fri, Mar 24, 2023 at 12:49 PM Anton Khirnov <anton@khirnov.net> wrote: > > Quoting Jan Ekström (2023-03-21 00:34:04) > > diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h > > index 30f1d312f4..8f535a0cc8 100644 > > --- a/libavcodec/avcodec.h > > +++ b/libavcodec/avcodec.h > > @@ -3223,6 +3223,18 @@ void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size); > > */ > > int avcodec_is_open(AVCodecContext *s); > > > > +/** > > + * Configure a side data set to an encoder AVCodecContext. With multiple > > + * calls new side data gets added in addition to the existing set of side data. > > I have no idea what does "configure" mean in this context and what > effect will this actually have. > It becomes available to any encoder which utilizes it for configuration of itself, basically. Jan
diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c index 3faabe77d1..9ffff28d70 100644 --- a/libavcodec/avcodec.c +++ b/libavcodec/avcodec.c @@ -29,6 +29,7 @@ #include "libavutil/bprint.h" #include "libavutil/channel_layout.h" #include "libavutil/fifo.h" +#include "libavutil/frame.h" #include "libavutil/imgutils.h" #include "libavutil/mem.h" #include "libavutil/opt.h" @@ -719,3 +720,32 @@ int attribute_align_arg avcodec_receive_frame(AVCodecContext *avctx, AVFrame *fr return ff_decode_receive_frame(avctx, frame); return ff_encode_receive_frame(avctx, frame); } + +int avcodec_configure_side_data(AVCodecContext *avctx, + const AVFrameSideDataSet set) +{ + if (!avctx || !avctx->internal || !av_codec_is_encoder(avctx->codec)) + return AVERROR(EINVAL); + + { + AVCodecInternal *avci = avctx->internal; + AVFrameSideDataSet *dst = &avci->side_data_set; + + for (int i = 0; i < set.nb_side_data; i++) { + const AVFrameSideData *sd_src = set.side_data[i]; + AVFrameSideData *sd_dst = + av_new_side_data_to_set(dst, sd_src->type, + sd_src->size); + if (!sd_dst) { + av_side_data_set_wipe(dst); + return AVERROR(ENOMEM); + } + + memcpy(sd_dst->data, sd_src->data, sd_src->size); + + av_dict_copy(&sd_dst->metadata, sd_src->metadata, 0); + } + + return 0; + } +} diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 30f1d312f4..8f535a0cc8 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -3223,6 +3223,18 @@ void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size); */ int avcodec_is_open(AVCodecContext *s); +/** + * Configure a side data set to an encoder AVCodecContext. With multiple + * calls new side data gets added in addition to the existing set of side data. + * + * @param avctx codec context to which to add side data + * @param set set of side data to add + * +* @return negative error code on failure, >=0 on success. + */ +int avcodec_configure_side_data(AVCodecContext *avctx, + const AVFrameSideDataSet set); + /** * @} */