@@ -248,7 +248,7 @@ int enc_open(void *opaque, const AVFrame *frame)
ret = avcodec_configure_side_data(
enc_ctx,
(const AVFrameSideData **)frame->side_data, frame->nb_side_data,
- AV_FRAME_SIDE_DATA_SET_FLAG_NO_DUPLICATES);
+ AV_FRAME_SIDE_DATA_FLAG_UNIQUE);
if (ret < 0) {
av_log(NULL, AV_LOG_ERROR, "failed to configure video encoder: %s!\n",
av_err2str(ret));
@@ -705,7 +705,7 @@ int avcodec_configure_side_data(AVCodecContext *avctx,
return AVERROR(EINVAL);
for (int i = 0; i < nb_sd; i++) {
- int ret = av_frame_side_data_from_sd(
+ 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(
@@ -3076,7 +3076,7 @@ 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
+ * 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
@@ -3090,11 +3090,12 @@ int avcodec_is_open(AVCodecContext *s);
*
* @return negative error code on failure, >=0 on success.
*
- * @see av_frame_side_data_set_new_entry regarding the flags.
+ * @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);
+
/**
* @}
*/
@@ -771,7 +771,7 @@ AVFrameSideData *av_frame_side_data_new(AVFrameSideData ***sd, int *nb_sd,
AVBufferRef *buf = av_buffer_alloc(size);
AVFrameSideData *ret = NULL;
- if (flags & AV_FRAME_SIDE_DATA_SET_FLAG_NO_DUPLICATES)
+ if (flags & AV_FRAME_SIDE_DATA_FLAG_UNIQUE)
remove_side_data(sd, nb_sd, type);
ret = add_side_data_to_set_from_buf(sd, nb_sd, type, buf);
@@ -781,45 +781,43 @@ AVFrameSideData *av_frame_side_data_new(AVFrameSideData ***sd, int *nb_sd,
return ret;
}
-AVFrameSideData *av_frame_side_data_from_buf(AVFrameSideData ***sd, int *nb_sd,
- enum AVFrameSideDataType type,
- const AVBufferRef *buf,
- unsigned int flags)
+AVFrameSideData *av_frame_side_data_add(AVFrameSideData ***sd, int *nb_sd,
+ enum AVFrameSideDataType type,
+ const AVBufferRef *buf,
+ unsigned int flags)
{
+ AVBufferRef *new_buf = NULL;
+ AVFrameSideData *sd_dst = NULL;
+
if (!sd || !buf || !nb_sd || (*nb_sd && !*sd))
return NULL;
- if (flags & AV_FRAME_SIDE_DATA_SET_FLAG_NO_DUPLICATES)
- remove_side_data(sd, nb_sd, type);
-
- {
- AVBufferRef *new_buf = av_buffer_ref(buf);
- AVFrameSideData *sd_dst = NULL;
-
- if (flags & AV_FRAME_SIDE_DATA_SET_FLAG_NO_DUPLICATES)
- remove_side_data(sd, nb_sd, type);
+ new_buf = av_buffer_ref(buf);
+ if (!buf)
+ return NULL;
- sd_dst = add_side_data_to_set_from_buf(sd, nb_sd, type, new_buf);
- if (!sd_dst) {
- av_buffer_unref(&new_buf);
- return NULL;
- }
+ if (flags & AV_FRAME_SIDE_DATA_FLAG_UNIQUE)
+ remove_side_data(sd, nb_sd, type);
- return sd_dst;
+ sd_dst = add_side_data_to_set_from_buf(sd, nb_sd, type, new_buf);
+ if (!sd_dst) {
+ av_buffer_unref(&new_buf);
+ return NULL;
}
+
+ return sd_dst;
}
-int av_frame_side_data_from_sd(AVFrameSideData ***sd, int *nb_sd,
- const AVFrameSideData *src,
- unsigned int flags)
+int av_frame_side_data_clone(AVFrameSideData ***sd, int *nb_sd,
+ const AVFrameSideData *src, unsigned int flags)
{
AVFrameSideData *sd_dst = NULL;
- int ret = AVERROR_BUG;
+ int ret = AVERROR_BUG;
+
if (!src)
return AVERROR(EINVAL);
- sd_dst =
- av_frame_side_data_from_buf(sd, nb_sd, src->type, src->buf, flags);
+ sd_dst = av_frame_side_data_add(sd, nb_sd, src->type, src->buf, flags);
if (!sd_dst)
return AVERROR(ENOMEM);
@@ -990,7 +990,7 @@ const char *av_frame_side_data_name(enum AVFrameSideDataType type);
/**
* Free all side data entries and their contents, then zeroes out the
- * struct values.
+ * values which the pointers are pointing to.
*
* @param sd pointer to array of side data to free. Will be set to NULL
* upon return.
@@ -999,68 +999,71 @@ const char *av_frame_side_data_name(enum AVFrameSideDataType type);
*/
void av_frame_side_data_free(AVFrameSideData ***sd, int *nb_sd);
-#define AV_FRAME_SIDE_DATA_SET_FLAG_NO_DUPLICATES (1 << 0)
+#define AV_FRAME_SIDE_DATA_FLAG_UNIQUE (1 << 0)
/**
- * Add a new side data entry to a set.
+ * Add new side data entry to an array.
*
- * @param sd pointer to array of side data to which to add another entry.
+ * @param sd pointer to array of side data to which to add another entry,
+ * or to NULL in order to start a new array.
* @param nb_sd pointer to an integer containing the number of entries in
* the array.
* @param type type of the added side data
* @param size size of the side data
- * @param flags Some combination of AV_FRAME_SIDE_DATA_SET_FLAG_* flags, or 0.
+ * @param flags Some combination of AV_FRAME_SIDE_DATA_FLAG_* flags, or 0.
*
* @return newly added side data on success, NULL on error. In case of
- * AV_FRAME_SIDE_DATA_SET_FLAG_NO_DUPLICATES being set, entries
- * of matching AVFrameSideDataType will be removed before the
- * addition is attempted.
+ * AV_FRAME_SIDE_DATA_FLAG_UNIQUE being set, entries of matching
+ * AVFrameSideDataType will be removed before the addition is
+ * attempted.
*/
AVFrameSideData *av_frame_side_data_new(AVFrameSideData ***sd, int *nb_sd,
enum AVFrameSideDataType type,
size_t size, unsigned int flags);
/**
- * Add a new side data entry to a set from an existing AVBufferRef.
+ * Add a new side data entry to an array from an existing AVBufferRef.
*
- * @param sd pointer to array of side data to which to add another entry.
+ * @param sd pointer to array of side data to which to add another entry,
+ * or to NULL in order to start a new array.
* @param nb_sd pointer to an integer containing the number of entries in
* the array.
* @param type type of the added side data
* @param buf AVBufferRef for which a new reference will be made
- * @param flags Some combination of AV_FRAME_SIDE_DATA_SET_FLAG_* flags, or 0.
+ * @param flags Some combination of AV_FRAME_SIDE_DATA_FLAG_* flags, or 0.
*
* @return newly added side data on success, NULL on error. In case of
- * AV_FRAME_SIDE_DATA_SET_FLAG_NO_DUPLICATES being set, entries
- * of matching AVFrameSideDataType will be removed before the
- * addition is attempted.
+ * AV_FRAME_SIDE_DATA_FLAG_UNIQUE being set, entries of matching
+ * AVFrameSideDataType will be removed before the addition is
+ * attempted.
*/
-AVFrameSideData *av_frame_side_data_from_buf(AVFrameSideData ***sd, int *nb_sd,
- enum AVFrameSideDataType type,
- const AVBufferRef *buf,
- unsigned int flags);
+AVFrameSideData *av_frame_side_data_add(AVFrameSideData ***sd, int *nb_sd,
+ enum AVFrameSideDataType type,
+ const AVBufferRef *buf,
+ unsigned int flags);
/**
- * Add a new side data entry to a set based on existing side data, taking
+ * Add a new side data entry to an array based on existing side data, taking
* a reference towards the contained AVBufferRef.
*
- * @param sd pointer to array of side data to which to add another entry.
+ * @param sd pointer to array of side data to which to add another entry,
+ * or to NULL in order to start a new array.
* @param nb_sd pointer to an integer containing the number of entries in
* the array.
- * @param src side data which should be added to the set
- * @param flags Some combination of AV_FRAME_SIDE_DATA_SET_FLAG_* flags, or 0.
+ * @param src side data to be cloned, with a new reference utilized
+ * for the buffer.
+ * @param flags Some combination of AV_FRAME_SIDE_DATA_FLAG_* flags, or 0.
*
* @return negative error code on failure, >=0 on success. In case of
- * AV_FRAME_SIDE_DATA_SET_FLAG_NO_DUPLICATES being set, entries
- * of matching AVFrameSideDataType will be removed before the
- * addition is attempted.
+ * AV_FRAME_SIDE_DATA_FLAG_UNIQUE being set, entries of matching
+ * AVFrameSideDataType will be removed before the addition is
+ * attempted.
*/
-int av_frame_side_data_from_sd(AVFrameSideData ***sd, int *nb_sd,
- const AVFrameSideData *src,
- unsigned int flags);
+int av_frame_side_data_clone(AVFrameSideData ***sd, int *nb_sd,
+ const AVFrameSideData *src, unsigned int flags);
/**
- * Get a side data entry of a specific type from a set.
+ * Get a side data entry of a specific type from an array.
*
* @param sd array of side data.
* @param nb_sd integer containing the number of entries in the array.
@@ -87,7 +87,7 @@ int main(void)
AVFrameSideData *sd = av_frame_side_data_new(
&set.sd, &set.nb_sd, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL,
sizeof(AVContentLightMetadata),
- AV_FRAME_SIDE_DATA_SET_FLAG_NO_DUPLICATES);
+ AV_FRAME_SIDE_DATA_FLAG_UNIQUE);
av_assert0(sd);