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"
24 
25 static void print_clls(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, %s",
32 
34  putchar('\n');
35  continue;
36  }
37 
38  printf(": MaxCLL: %u\n",
39  ((AVContentLightMetadata *)entry->data)->MaxCLL);
40  }
41 }
42 
43 typedef struct FrameSideDataSet {
45  int nb_sd;
47 
48 int main(void)
49 {
50  FrameSideDataSet set = { 0 };
51 
52  av_assert0(
53  av_frame_side_data_new(&set.sd, &set.nb_sd,
55  0, 0));
56 
57  // test entries in the middle
58  for (int value = 1; value < 4; value++) {
61  sizeof(AVContentLightMetadata), 0);
62 
63  av_assert0(sd);
64 
65  ((AVContentLightMetadata *)sd->data)->MaxCLL = value;
66  }
67 
68  av_assert0(
70  &set.sd, &set.nb_sd, AV_FRAME_DATA_SPHERICAL, 0, 0));
71 
72  // test entries at the end
73  for (int value = 1; value < 4; value++) {
76  sizeof(AVContentLightMetadata), 0);
77 
78  av_assert0(sd);
79 
80  ((AVContentLightMetadata *)sd->data)->MaxCLL = value + 3;
81  }
82 
83  puts("Initial addition results with duplicates:");
84  print_clls((const AVFrameSideData **)set.sd, set.nb_sd);
85 
86  {
89  sizeof(AVContentLightMetadata),
91 
92  av_assert0(sd);
93 
94  ((AVContentLightMetadata *)sd->data)->MaxCLL = 1337;
95  }
96 
97  puts("\nFinal state after a single 'no-duplicates' addition:");
98  print_clls((const AVFrameSideData **)set.sd, set.nb_sd);
99 
100  av_frame_side_data_free(&set.sd, &set.nb_sd);
101 
102  return 0;
103 }
entry
#define entry
Definition: aom_film_grain_template.c:66
AVContentLightMetadata
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
Definition: mastering_display_metadata.h:98
FrameSideDataSet::sd
AVFrameSideData ** sd
Definition: side_data_array.c:44
AV_FRAME_SIDE_DATA_FLAG_UNIQUE
#define AV_FRAME_SIDE_DATA_FLAG_UNIQUE
Definition: frame.h:1006
set
static void set(uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f, double v)
Definition: swresample.c:59
print_clls
static void print_clls(const AVFrameSideData **sd, const int nb_sd)
Definition: side_data_array.c:25
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_DATA_AMBIENT_VIEWING_ENVIRONMENT
@ AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT
Ambient viewing environment metadata, as defined by H.274.
Definition: frame.h:220
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:45
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:255
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:81
frame.c
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
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:777
main
int main(void)
Definition: side_data_array.c:48
mastering_display_metadata.h
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:909
FrameSideDataSet
Definition: side_data_array.c:43