Message ID | 20230411212052.159889-8-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-04-11 23:20:47) > --- > libavutil/frame.c | 21 +++++++++++++++++++++ > libavutil/frame.h | 11 +++++++++++ > 2 files changed, 32 insertions(+) > > diff --git a/libavutil/frame.c b/libavutil/frame.c > index 3386cda627..ec4e44a11f 100644 > --- a/libavutil/frame.c > +++ b/libavutil/frame.c > @@ -720,6 +720,27 @@ AVFrameSideData *av_new_side_data_to_set(AVFrameSideDataSet *set, > return ret; > } > > +int av_extend_side_data_set(AVFrameSideDataSet *dst, > + const AVFrameSideDataSet src) > +{ > + for (int i = 0; i < src.nb_side_data; i++) { > + const AVFrameSideData *sd_src = src.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; > +} > + > AVFrameSideData *av_get_side_data_from_set(const AVFrameSideDataSet set, > enum AVFrameSideDataType type) > { > diff --git a/libavutil/frame.h b/libavutil/frame.h > index 8aa50e3ad8..da8ac3237b 100644 > --- a/libavutil/frame.h > +++ b/libavutil/frame.h > @@ -1011,6 +1011,17 @@ AVFrameSideData *av_new_side_data_to_set(AVFrameSideDataSet *set, > enum AVFrameSideDataType type, > size_t size); > > +/** > + * Add multiple side data entries to a set in one go. > + * > + * @param dst a set to which the side data should be added > + * @param src a set from which the side data should be copied from > + * > + * @return negative error code on failure, >=0 on success. > + */ > +int av_extend_side_data_set(AVFrameSideDataSet *dst, > + const AVFrameSideDataSet src); There's a question of what to do in case of duplicates, so I think a flags argument to resolve it might be useful. More generally we might want to add flagging for side data type indicating for which duplicates make sense.
diff --git a/libavutil/frame.c b/libavutil/frame.c index 3386cda627..ec4e44a11f 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -720,6 +720,27 @@ AVFrameSideData *av_new_side_data_to_set(AVFrameSideDataSet *set, return ret; } +int av_extend_side_data_set(AVFrameSideDataSet *dst, + const AVFrameSideDataSet src) +{ + for (int i = 0; i < src.nb_side_data; i++) { + const AVFrameSideData *sd_src = src.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; +} + AVFrameSideData *av_get_side_data_from_set(const AVFrameSideDataSet set, enum AVFrameSideDataType type) { diff --git a/libavutil/frame.h b/libavutil/frame.h index 8aa50e3ad8..da8ac3237b 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -1011,6 +1011,17 @@ AVFrameSideData *av_new_side_data_to_set(AVFrameSideDataSet *set, enum AVFrameSideDataType type, size_t size); +/** + * Add multiple side data entries to a set in one go. + * + * @param dst a set to which the side data should be added + * @param src a set from which the side data should be copied from + * + * @return negative error code on failure, >=0 on success. + */ +int av_extend_side_data_set(AVFrameSideDataSet *dst, + const AVFrameSideDataSet src); + /** * @param set a set to which the side data should be added * @param type type of the added side data