FFmpeg
side_data_array.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023 Jan Ekström <jeebjp@gmail.com>
3  *
4  * This file is part of FFmpeg.
5  *
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.
10  *
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.
15  *
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
19  */
20 
21 #include <stdio.h>
22 #include "libavutil/frame.c"
23 #include "libavutil/internal.h"
24 
25 static void print_entries(const AVFrameSideData **sd, const int nb_sd)
26 {
27  for (int i = 0; i < nb_sd; i++) {
28  const AVFrameSideData *entry = sd[i];
29 
30  printf("sd %d (size %"SIZE_SPECIFIER"), %s",
31  i, entry->size, av_frame_side_data_name(entry->type));
32 
34  putchar('\n');
35  continue;
36  }
37 
38  printf(": %d\n", *(int32_t *)entry->data);
39  }
40 }
41 
42 typedef struct FrameSideDataSet {
44  int nb_sd;
46 
47 int main(void)
48 {
49  FrameSideDataSet set = { 0 };
50 
51  av_assert0(
52  av_frame_side_data_new(&set.sd, &set.nb_sd,
54  sizeof(int64_t), 0));
55  av_assert0(
56  av_frame_side_data_new(&set.sd, &set.nb_sd,
59 
60  // test entries in the middle
61  for (int value = 1; value < 4; value++) {
64  sizeof(int32_t), 0);
65 
66  av_assert0(sd);
67 
68  *(int32_t *)sd->data = value;
69  }
70 
71  av_assert0(
73  &set.sd, &set.nb_sd, AV_FRAME_DATA_SPHERICAL,
74  sizeof(int64_t), 0));
75 
76  av_assert0(
78  &set.sd, &set.nb_sd, AV_FRAME_DATA_SPHERICAL,
80 
81  // test entries at the end
82  for (int value = 1; value < 4; value++) {
85  sizeof(int32_t), 0);
86 
87  av_assert0(sd);
88 
89  *(int32_t *)sd->data = value + 3;
90  }
91 
92  puts("Initial addition results with duplicates:");
93  print_entries((const AVFrameSideData **)set.sd, set.nb_sd);
94 
95  {
99 
100  av_assert0(sd);
101 
102  *(int32_t *)sd->data = 1337;
103  }
104 
105  puts("\nFinal state after a single 'no-duplicates' addition:");
106  print_entries((const AVFrameSideData **)set.sd, set.nb_sd);
107 
108  av_frame_side_data_free(&set.sd, &set.nb_sd);
109 
110  return 0;
111 }
entry
#define entry
Definition: aom_film_grain_template.c:66
FrameSideDataSet::sd
AVFrameSideData ** sd
Definition: side_data_array.c:43
AV_FRAME_SIDE_DATA_FLAG_UNIQUE
#define AV_FRAME_SIDE_DATA_FLAG_UNIQUE
Remove existing entries before adding new ones.
Definition: frame.h:1045
set
static void set(uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f, double v)
Definition: swresample.c:59
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
AV_FRAME_DATA_SPHERICAL
@ AV_FRAME_DATA_SPHERICAL
The data represents the AVSphericalMapping structure defined in libavutil/spherical....
Definition: frame.h:131
AV_FRAME_SIDE_DATA_FLAG_REPLACE
#define AV_FRAME_SIDE_DATA_FLAG_REPLACE
Don't add a new entry if another of the same type exists.
Definition: frame.h:1050
AV_FRAME_DATA_SEI_UNREGISTERED
@ AV_FRAME_DATA_SEI_UNREGISTERED
User data unregistered metadata associated with a video frame.
Definition: frame.h:178
AVFrameSideData::data
uint8_t * data
Definition: frame.h:252
printf
printf("static const uint8_t my_array[100] = {\n")
FrameSideDataSet::nb_sd
int nb_sd
Definition: side_data_array.c:44
AV_FRAME_DATA_CONTENT_LIGHT_LEVEL
@ AV_FRAME_DATA_CONTENT_LIGHT_LEVEL
Content light level (based on CTA-861.3).
Definition: frame.h:137
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
av_frame_side_data_free
void av_frame_side_data_free(AVFrameSideData ***sd, int *nb_sd)
Free all side data entries and their contents, then zeroes out the values which the pointers are poin...
Definition: frame.c:111
frame.c
internal.h
value
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
Definition: writing_filters.txt:86
SIZE_SPECIFIER
#define SIZE_SPECIFIER
Definition: internal.h:129
av_frame_side_data_new
AVFrameSideData * av_frame_side_data_new(AVFrameSideData ***sd, int *nb_sd, enum AVFrameSideDataType type, size_t size, unsigned int flags)
Add new side data entry to an array.
Definition: frame.c:821
main
int main(void)
Definition: side_data_array.c:47
AVFrameSideData
Structure to hold side data for an AVFrame.
Definition: frame.h:250
av_frame_side_data_name
const char * av_frame_side_data_name(enum AVFrameSideDataType type)
Definition: frame.c:1026
int32_t
int32_t
Definition: audioconvert.c:56
print_entries
static void print_entries(const AVFrameSideData **sd, const int nb_sd)
Definition: side_data_array.c:25
FrameSideDataSet
Definition: side_data_array.c:42