[FFmpeg-devel] [PATCH v8 10/14] avcodec: add helper for configuring AVCodecContext's frame side data
Jan Ekström
jeebjp at gmail.com
Mon Mar 11 22:58:33 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 | 21 +++++++++++++++++++++
2 files changed, 51 insertions(+)
diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index a9a87bb58c..0ced87b946 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -686,3 +686,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_clone(
+ &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 432a3fd153..6de4dc0f7b 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3075,6 +3075,27 @@ 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's array 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_new 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