2 * Copyright (c) 2023 Jan Ekström <jeebjp@gmail.com>
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "libavutil/frame.c"
23 #include "libavutil/internal.h"
25 static void print_entries(const AVFrameSideData
**sd
, const int nb_sd
)
27 for (int i
= 0; i
< nb_sd
; i
++) {
28 const AVFrameSideData
*entry
= sd
[i
];
30 printf("sd %d (size %"SIZE_SPECIFIER
"), %s",
31 i
, entry
->size
, av_frame_side_data_name(entry
->type
));
33 if (entry
->type
!= AV_FRAME_DATA_SEI_UNREGISTERED
) {
38 printf(": %d\n", *(int32_t *)entry
->data
);
42 typedef struct FrameSideDataSet
{
49 FrameSideDataSet set
= { 0 };
52 av_frame_side_data_new(&set
.sd
, &set
.nb_sd
,
53 AV_FRAME_DATA_CONTENT_LIGHT_LEVEL
,
56 av_frame_side_data_new(&set
.sd
, &set
.nb_sd
,
57 AV_FRAME_DATA_CONTENT_LIGHT_LEVEL
,
58 sizeof(int32_t), AV_FRAME_SIDE_DATA_FLAG_REPLACE
));
60 // test entries in the middle
61 for (int value
= 1; value
< 4; value
++) {
62 AVFrameSideData
*sd
= av_frame_side_data_new(
63 &set
.sd
, &set
.nb_sd
, AV_FRAME_DATA_SEI_UNREGISTERED
,
68 *(int32_t *)sd
->data
= value
;
72 av_frame_side_data_new(
73 &set
.sd
, &set
.nb_sd
, AV_FRAME_DATA_SPHERICAL
,
77 av_frame_side_data_new(
78 &set
.sd
, &set
.nb_sd
, AV_FRAME_DATA_SPHERICAL
,
79 sizeof(int32_t), AV_FRAME_SIDE_DATA_FLAG_REPLACE
));
81 // test entries at the end
82 for (int value
= 1; value
< 4; value
++) {
83 AVFrameSideData
*sd
= av_frame_side_data_new(
84 &set
.sd
, &set
.nb_sd
, AV_FRAME_DATA_SEI_UNREGISTERED
,
89 *(int32_t *)sd
->data
= value
+ 3;
92 puts("Initial addition results with duplicates:");
93 print_entries((const AVFrameSideData
**)set
.sd
, set
.nb_sd
);
96 AVFrameSideData
*sd
= av_frame_side_data_new(
97 &set
.sd
, &set
.nb_sd
, AV_FRAME_DATA_SEI_UNREGISTERED
,
98 sizeof(int32_t), AV_FRAME_SIDE_DATA_FLAG_UNIQUE
);
102 *(int32_t *)sd
->data
= 1337;
105 puts("\nFinal state after a single 'no-duplicates' addition:");
106 print_entries((const AVFrameSideData
**)set
.sd
, set
.nb_sd
);
108 av_frame_side_data_free(&set
.sd
, &set
.nb_sd
);