@@ -247,10 +247,7 @@ int enc_open(void *opaque, const AVFrame *frame)
ret = avcodec_configure_side_data(
enc_ctx,
- &(const AVFrameSideDataSet){
- .sd = frame->side_data,
- .nb_sd = frame->nb_side_data
- },
+ (const AVFrameSideData **)frame->side_data, frame->nb_side_data,
AV_FRAME_SIDE_DATA_SET_FLAG_NO_DUPLICATES);
if (ret < 0) {
av_log(NULL, AV_LOG_ERROR, "failed to configure video encoder: %s!\n",
@@ -722,26 +722,28 @@ int attribute_align_arg avcodec_receive_frame(AVCodecContext *avctx, AVFrame *fr
}
int avcodec_configure_side_data(AVCodecContext *avctx,
- const AVFrameSideDataSet *set,
+ const AVFrameSideData **sd, const int nb_sd,
unsigned int flags)
{
if (!avctx)
return AVERROR(EINVAL);
- if (!set) {
- av_frame_side_data_set_uninit(&avctx->frame_sd_set);
+ if (!sd) {
+ av_frame_side_data_free(
+ &avctx->frame_side_data, &avctx->nb_frame_side_data);
return 0;
}
- if (set->nb_sd > 0 && set->nb_sd == avctx->frame_sd_set.nb_sd &&
- set->sd == avctx->frame_sd_set.sd)
+ 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 < set->nb_sd; i++) {
- int ret = av_frame_side_data_set_entry_from_sd(
- &avctx->frame_sd_set, set->sd[i], flags);
+ 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_set_uninit(&avctx->frame_sd_set);
+ av_frame_side_data_free(
+ &avctx->frame_side_data, &avctx->nb_frame_side_data);
return ret;
}
}
@@ -2126,7 +2126,8 @@ typedef struct AVCodecContext {
* - encoding: set by user
* - decoding: unused
*/
- AVFrameSideDataSet frame_sd_set;
+ AVFrameSideData **frame_side_data;
+ int nb_frame_side_data;
} AVCodecContext;
/**
@@ -3169,8 +3170,9 @@ int avcodec_is_open(AVCodecContext *s);
* whole side data set.
*
* @param avctx context to which the side data should be added
- * @param set a set from which the side data should be added from.
- * if null, clears out the side data for this context.
+ * @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.
@@ -3178,9 +3180,8 @@ int avcodec_is_open(AVCodecContext *s);
* @see av_frame_side_data_set_new_entry regarding the flags.
*/
int avcodec_configure_side_data(AVCodecContext *avctx,
- const AVFrameSideDataSet *set,
+ const AVFrameSideData **sd, const int nb_sd,
unsigned int flags);
-
/**
* @}
*/
@@ -189,13 +189,14 @@ static void handle_mdcv(struct EbSvtAv1MasteringDisplayInfo *dst,
static void handle_side_data(AVCodecContext *avctx,
EbSvtAv1EncConfiguration *param)
{
- const AVFrameSideDataSet set = avctx->frame_sd_set;
const AVFrameSideData *cll_sd =
- av_frame_side_data_set_get_entry(
- set, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL);
+ av_frame_side_data_get(
+ (const AVFrameSideData **)avctx->frame_side_data,
+ avctx->nb_frame_side_data, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL);
const AVFrameSideData *mdcv_sd =
- av_frame_side_data_set_get_entry(
- set, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA);
+ av_frame_side_data_get(
+ (const AVFrameSideData **)avctx->frame_side_data,
+ avctx->nb_frame_side_data, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA);
if (cll_sd) {
const AVContentLightMetadata *cll =
@@ -923,13 +923,14 @@ static void handle_mdcv(x264_param_t *params,
static void handle_side_data(AVCodecContext *avctx, x264_param_t *params)
{
#if CONFIG_LIBX264_HDR10
- const AVFrameSideDataSet set = avctx->frame_sd_set;
const AVFrameSideData *cll_sd =
- av_frame_side_data_set_get_entry(
- set, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL);
+ av_frame_side_data_get(
+ (const AVFrameSideData **)avctx->frame_side_data,
+ avctx->nb_frame_side_data, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL);
const AVFrameSideData *mdcv_sd =
- av_frame_side_data_set_get_entry(
- set, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA);
+ av_frame_side_data_get(
+ (const AVFrameSideData **)avctx->frame_side_data,
+ avctx->nb_frame_side_data, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA);
if (cll_sd) {
const AVContentLightMetadata *cll =
@@ -232,13 +232,14 @@ end:
static int handle_side_data(AVCodecContext *avctx, const x265_api *api,
x265_param *params)
{
- const AVFrameSideDataSet set = avctx->frame_sd_set;
const AVFrameSideData *cll_sd =
- av_frame_side_data_set_get_entry(
- set, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL);
+ av_frame_side_data_get(
+ (const AVFrameSideData **)avctx->frame_side_data,
+ avctx->nb_frame_side_data, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL);
const AVFrameSideData *mdcv_sd =
- av_frame_side_data_set_get_entry(
- set, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA);
+ av_frame_side_data_get(
+ (const AVFrameSideData **)avctx->frame_side_data,
+ avctx->nb_frame_side_data, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA);
if (cll_sd) {
const AVContentLightMetadata *cll =
@@ -181,7 +181,8 @@ void avcodec_free_context(AVCodecContext **pavctx)
av_freep(&avctx->inter_matrix);
av_freep(&avctx->rc_override);
av_channel_layout_uninit(&avctx->ch_layout);
- av_frame_side_data_set_uninit(&avctx->frame_sd_set);
+ av_frame_side_data_free(
+ &avctx->frame_side_data, &avctx->nb_frame_side_data);
av_freep(pavctx);
}
@@ -90,9 +90,9 @@ static void frame_side_data_wipe(AVFrame *frame)
wipe_side_data(&frame->side_data, &frame->nb_side_data);
}
-void av_frame_side_data_set_uninit(AVFrameSideDataSet *set)
+void av_frame_side_data_free(AVFrameSideData ***sd, int *nb_sd)
{
- wipe_side_data(&set->sd, &set->nb_sd);
+ wipe_side_data(sd, nb_sd);
}
static void remove_side_data(AVFrameSideData ***sd, int *nb_side_data,
@@ -110,19 +110,18 @@ static void remove_side_data(AVFrameSideData ***sd, int *nb_side_data,
}
}
-static void remove_side_data_by_entry(AVFrameSideData ***sd,
- int *nb_side_data,
+static void remove_side_data_by_entry(AVFrameSideData ***sd, int *nb_sd,
const AVFrameSideData *target)
{
- for (int i = *nb_side_data - 1; i >= 0; i--) {
+ for (int i = *nb_sd - 1; i >= 0; i--) {
AVFrameSideData *entry = ((*sd)[i]);
if (entry != target)
continue;
free_side_data(&entry);
- ((*sd)[i]) = ((*sd)[*nb_side_data - 1]);
- (*nb_side_data)--;
+ ((*sd)[i]) = ((*sd)[*nb_sd - 1]);
+ (*nb_sd)--;
return;
}
@@ -820,7 +819,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
return NULL;
}
-static AVFrameSideData *add_side_data_to_set_from_buf(AVFrameSideDataSet *set,
+static AVFrameSideData *add_side_data_to_set_from_buf(AVFrameSideData ***sd,
+ int *nb_sd,
enum AVFrameSideDataType type,
AVBufferRef *buf)
{
@@ -829,13 +829,13 @@ static AVFrameSideData *add_side_data_to_set_from_buf(AVFrameSideDataSet *set,
if (!buf)
return NULL;
- if (set->nb_sd > INT_MAX / sizeof(*set->sd) - 1)
+ if (*nb_sd > INT_MAX / sizeof(*sd) - 1)
return NULL;
- tmp = av_realloc(set->sd, (set->nb_sd + 1) * sizeof(*set->sd));
+ tmp = av_realloc(*sd, (*nb_sd + 1) * sizeof(*sd));
if (!tmp)
return NULL;
- set->sd = tmp;
+ *sd = tmp;
ret = av_mallocz(sizeof(*ret));
if (!ret)
@@ -846,7 +846,7 @@ static AVFrameSideData *add_side_data_to_set_from_buf(AVFrameSideDataSet *set,
ret->size = buf->size;
ret->type = type;
- set->sd[set->nb_sd++] = ret;
+ (*sd)[(*nb_sd)++] = ret;
return ret;
}
@@ -855,16 +855,9 @@ AVFrameSideData *av_frame_new_side_data_from_buf(AVFrame *frame,
enum AVFrameSideDataType type,
AVBufferRef *buf)
{
- AVFrameSideDataSet set = {
- .sd = frame->side_data,
- .nb_sd = frame->nb_side_data,
- };
- AVFrameSideData *ret = add_side_data_to_set_from_buf(&set, type, buf);
-
- frame->side_data = set.sd;
- frame->nb_side_data = set.nb_sd;
-
- return ret;
+ return
+ add_side_data_to_set_from_buf(&frame->side_data, &frame->nb_side_data,
+ type, buf);
}
AVFrameSideData *av_frame_new_side_data(AVFrame *frame,
@@ -879,29 +872,28 @@ AVFrameSideData *av_frame_new_side_data(AVFrame *frame,
return ret;
}
-AVFrameSideData *av_frame_side_data_set_new_entry(AVFrameSideDataSet *set,
- enum AVFrameSideDataType type,
- size_t size,
- unsigned int flags)
+AVFrameSideData *av_frame_side_data_new(AVFrameSideData ***sd, int *nb_sd,
+ enum AVFrameSideDataType type,
+ size_t size, unsigned int flags)
{
AVBufferRef *buf = av_buffer_alloc(size);
AVFrameSideData *ret = NULL;
if (flags & AV_FRAME_SIDE_DATA_SET_FLAG_NO_DUPLICATES)
- remove_side_data(&set->sd, &set->nb_sd, type);
+ remove_side_data(sd, nb_sd, type);
- ret = add_side_data_to_set_from_buf(set, type, buf);
+ ret = add_side_data_to_set_from_buf(sd, nb_sd, type, buf);
if (!ret)
av_buffer_unref(&buf);
return ret;
}
-int av_frame_side_data_set_entry_from_sd(AVFrameSideDataSet *dst,
- const AVFrameSideData *src,
- unsigned int flags)
+int av_frame_side_data_from_sd(AVFrameSideData ***sd, int *nb_sd,
+ const AVFrameSideData *src,
+ unsigned int flags)
{
- if (!dst || !src)
+ if (!sd || !src || !nb_sd || (*nb_sd && !*sd))
return AVERROR(EINVAL);
{
@@ -909,9 +901,9 @@ int av_frame_side_data_set_entry_from_sd(AVFrameSideDataSet *dst,
AVFrameSideData *sd_dst = NULL;
if (flags & AV_FRAME_SIDE_DATA_SET_FLAG_NO_DUPLICATES)
- remove_side_data(&dst->sd, &dst->nb_sd, src->type);
+ remove_side_data(sd, nb_sd, src->type);
- sd_dst = add_side_data_to_set_from_buf(dst, src->type, buf);
+ sd_dst = add_side_data_to_set_from_buf(sd, nb_sd, src->type, buf);
if (!sd_dst) {
av_buffer_unref(&buf);
return AVERROR(ENOMEM);
@@ -920,7 +912,7 @@ int av_frame_side_data_set_entry_from_sd(AVFrameSideDataSet *dst,
{
int ret = av_dict_copy(&sd_dst->metadata, src->metadata, 0);
if (ret < 0) {
- remove_side_data_by_entry(&dst->sd, &dst->nb_sd, sd_dst);
+ remove_side_data_by_entry(sd, nb_sd, sd_dst);
return ret;
}
}
@@ -929,12 +921,13 @@ int av_frame_side_data_set_entry_from_sd(AVFrameSideDataSet *dst,
}
}
-AVFrameSideData *av_frame_side_data_set_get_entry(const AVFrameSideDataSet set,
- enum AVFrameSideDataType type)
+const AVFrameSideData *av_frame_side_data_get(const AVFrameSideData **sd,
+ const int nb_sd,
+ enum AVFrameSideDataType type)
{
- for (int i = 0; i < set.nb_sd; i++) {
- if (set.sd[i]->type == type)
- return set.sd[i];
+ for (int i = 0; i < nb_sd; i++) {
+ if (sd[i]->type == type)
+ return sd[i];
}
return NULL;
}
@@ -942,11 +935,8 @@ AVFrameSideData *av_frame_side_data_set_get_entry(const AVFrameSideDataSet set,
AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,
enum AVFrameSideDataType type)
{
- return av_frame_side_data_set_get_entry(
- (const AVFrameSideDataSet){
- .sd = frame->side_data,
- .nb_sd = frame->nb_side_data
- },
+ return (AVFrameSideData *)av_frame_side_data_get(
+ (const AVFrameSideData **)frame->side_data, frame->nb_side_data,
type
);
}
@@ -251,14 +251,6 @@ typedef struct AVFrameSideData {
AVBufferRef *buf;
} AVFrameSideData;
-/**
- * Structure to hold a set of AVFrameSideData
- */
-typedef struct AVFrameSideDataSet {
- AVFrameSideData **sd;
- int nb_sd;
-} AVFrameSideDataSet;
-
/**
* Structure describing a single Region Of Interest.
*
@@ -1061,18 +1053,23 @@ const char *av_frame_side_data_name(enum AVFrameSideDataType type);
* Free all side data entries and their contents, then zeroes out the
* struct values.
*
- * @param set the set which should be uninitialized
+ * @param sd pointer to array of side data to free. Will be set to NULL
+ * upon return.
+ * @param nb_sd pointer to an integer containing the number of entries in
+ * the array. Will be set to 0 upon return.
*/
-void av_frame_side_data_set_uninit(AVFrameSideDataSet *set);
+void av_frame_side_data_free(AVFrameSideData ***sd, int *nb_sd);
#define AV_FRAME_SIDE_DATA_SET_FLAG_NO_DUPLICATES (1 << 0)
/**
* Add a new side data entry to a set.
*
- * @param set a set to which the side data should be added
- * @param type type of the added side data
- * @param size size of the side data
+ * @param sd pointer to array of side data to which to add another entry.
+ * @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.
*
* @return newly added side data on success, NULL on error. In case of
@@ -1080,16 +1077,18 @@ void av_frame_side_data_set_uninit(AVFrameSideDataSet *set);
* of matching AVFrameSideDataType will be removed before the
* addition is attempted.
*/
-AVFrameSideData *av_frame_side_data_set_new_entry(AVFrameSideDataSet *set,
- enum AVFrameSideDataType type,
- size_t size,
- unsigned int flags);
+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 based on existing side data.
+ * Add a new side data entry to a set based on existing side data, taking
+ * a reference towards the contained AVBufferRef.
*
- * @param dst a set to which the side data should be added
- * @param src side data which should be added to the set
+ * @param sd pointer to array of side data to which to add another entry.
+ * @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.
*
* @return negative error code on failure, >=0 on success. In case of
@@ -1097,21 +1096,23 @@ AVFrameSideData *av_frame_side_data_set_new_entry(AVFrameSideDataSet *set,
* of matching AVFrameSideDataType will be removed before the
* addition is attempted.
*/
-int av_frame_side_data_set_entry_from_sd(AVFrameSideDataSet *dst,
- const AVFrameSideData *src,
- unsigned int flags);
+int av_frame_side_data_from_sd(AVFrameSideData ***sd, int *nb_sd,
+ const AVFrameSideData *src,
+ unsigned int flags);
/**
* Get a side data entry of a specific type from a set.
*
- * @param set the set from which side data should be queried from
- * @param type type of side data to be queried
+ * @param sd array of side data.
+ * @param nb_sd integer containing the number of entries in the array.
+ * @param type type of side data to be queried
*
* @return a pointer to the side data of a given type on success, NULL if there
* is no side data with such type in this set.
*/
-AVFrameSideData *av_frame_side_data_set_get_entry(const AVFrameSideDataSet set,
- enum AVFrameSideDataType type);
+const AVFrameSideData *av_frame_side_data_get(const AVFrameSideData **sd,
+ const int nb_sd,
+ enum AVFrameSideDataType type);
/**
* @}
@@ -22,36 +22,42 @@
#include "libavutil/frame.c"
#include "libavutil/mastering_display_metadata.h"
-static void print_clls(const AVFrameSideDataSet set)
+static void print_clls(const AVFrameSideData **sd, const int nb_sd)
{
- for (int i = 0; i < set.nb_sd; i++) {
- AVFrameSideData *sd = set.sd[i];
+ for (int i = 0; i < nb_sd; i++) {
+ const AVFrameSideData *entry = sd[i];
printf("sd %d, %s",
- i, av_frame_side_data_name(sd->type));
+ i, av_frame_side_data_name(entry->type));
- if (sd->type != AV_FRAME_DATA_CONTENT_LIGHT_LEVEL) {
+ if (entry->type != AV_FRAME_DATA_CONTENT_LIGHT_LEVEL) {
putchar('\n');
continue;
}
printf(": MaxCLL: %u\n",
- ((AVContentLightMetadata *)sd->data)->MaxCLL);
+ ((AVContentLightMetadata *)entry->data)->MaxCLL);
}
}
+typedef struct FrameSideDataSet {
+ AVFrameSideData **sd;
+ int nb_sd;
+} FrameSideDataSet;
+
int main(void)
{
- AVFrameSideDataSet set = { 0 };
+ FrameSideDataSet set = { 0 };
av_assert0(
- av_frame_side_data_set_new_entry(
- &set, AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT, 0, 0));
+ av_frame_side_data_new(&set.sd, &set.nb_sd,
+ AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT,
+ 0, 0));
// test entries in the middle
for (int value = 1; value < 4; value++) {
- AVFrameSideData *sd = av_frame_side_data_set_new_entry(
- &set, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL,
+ AVFrameSideData *sd = av_frame_side_data_new(
+ &set.sd, &set.nb_sd, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL,
sizeof(AVContentLightMetadata), 0);
av_assert0(sd);
@@ -60,13 +66,13 @@ int main(void)
}
av_assert0(
- av_frame_side_data_set_new_entry(
- &set, AV_FRAME_DATA_SPHERICAL, 0, 0));
+ av_frame_side_data_new(
+ &set.sd, &set.nb_sd, AV_FRAME_DATA_SPHERICAL, 0, 0));
// test entries at the end
for (int value = 1; value < 4; value++) {
- AVFrameSideData *sd = av_frame_side_data_set_new_entry(
- &set, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL,
+ AVFrameSideData *sd = av_frame_side_data_new(
+ &set.sd, &set.nb_sd, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL,
sizeof(AVContentLightMetadata), 0);
av_assert0(sd);
@@ -75,11 +81,11 @@ int main(void)
}
puts("Initial addition results with duplicates:");
- print_clls(set);
+ print_clls((const AVFrameSideData **)set.sd, set.nb_sd);
{
- AVFrameSideData *sd = av_frame_side_data_set_new_entry(
- &set, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL,
+ 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);
@@ -89,9 +95,9 @@ int main(void)
}
puts("\nFinal state after a single 'no-duplicates' addition:");
- print_clls(set);
+ print_clls((const AVFrameSideData **)set.sd, set.nb_sd);
- av_frame_side_data_set_uninit(&set);
+ av_frame_side_data_free(&set.sd, &set.nb_sd);
return 0;
}