[FFmpeg-devel] [PATCH v7 10/14] avcodec: add helper for configuring AVCodecContext's frame side data
Jan Ekström
jeebjp at gmail.com
Thu Feb 29 18:42:57 EET 2024
This allows API clients that wish to configure multiple entries
at a time to do so without writing the looping code themselves.
---
libavcodec/avcodec.c | 30 ++++++++++++++++++++++++++++++
libavcodec/avcodec.h | 20 ++++++++++++++++++++
2 files changed, 50 insertions(+)
diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index a13b781996..d3ec41b280 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -720,3 +720,33 @@ 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 AVFrameSideData **sd, const int nb_sd,
+ unsigned int flags)
+{
+ if (!avctx)
+ return AVERROR(EINVAL);
+
+ if (!sd) {
+ av_frame_side_data_free(
+ &avctx->frame_side_data, &avctx->nb_frame_side_data);
+ return 0;
+ }
+
+ if (nb_sd > 0 && nb_sd == avctx->nb_frame_side_data &&
+ sd == (const AVFrameSideData **)avctx->frame_side_data)
+ return AVERROR(EINVAL);
+
+ for (int i = 0; i < nb_sd; i++) {
+ int ret = av_frame_side_data_from_sd(
+ &avctx->frame_side_data, &avctx->nb_frame_side_data, sd[i], flags);
+ if (ret < 0) {
+ av_frame_side_data_free(
+ &avctx->frame_side_data, &avctx->nb_frame_side_data);
+ return ret;
+ }
+ }
+
+ return 0;
+}
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 411f4caad3..3b5ca9c0ef 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3162,6 +3162,26 @@ void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size);
*/
int avcodec_is_open(AVCodecContext *s);
+/**
+ * Add multiple side data entries to an AVCodecContext set in one go, for
+ * example from an AVFrame.
+ *
+ * In case the function fails to add a side data entry, it will clear the
+ * whole side data set.
+ *
+ * @param avctx context to which the side data should be added
+ * @param sd array of side data to use as input.
+ * if null, clears out the side data for this context.
+ * @param nb_sd integer containing the number of entries in the array.
+ * @param flags Some combination of AV_FRAME_SIDE_DATA_SET_FLAG_* flags, or 0.
+ *
+ * @return negative error code on failure, >=0 on success.
+ *
+ * @see av_frame_side_data_set_new_entry regarding the flags.
+ */
+int avcodec_configure_side_data(AVCodecContext *avctx,
+ const AVFrameSideData **sd, const int nb_sd,
+ unsigned int flags);
/**
* @}
*/
--
2.44.0
More information about the ffmpeg-devel
mailing list