FFmpeg
Loading...
Searching...
No Matches
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
25static 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 %zu), %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
46
47int main(void)
48{
49 FrameSideDataSet set = { 0 };
50
52 av_frame_side_data_new(&set.sd, &set.nb_sd,
54 sizeof(int64_t), 0));
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
73 &set.sd, &set.nb_sd, AV_FRAME_DATA_SPHERICAL,
74 sizeof(int64_t), 0));
75
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}
#define entry
int32_t
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
long long int64_t
Definition coverity.c:34
__device__ int printf(const char *,...)
double value
Definition eval.c:102
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 side_data.c:204
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 side_data.c:139
#define AV_FRAME_SIDE_DATA_FLAG_REPLACE
Don't add a new entry if another of the same type exists.
Definition frame.h:1098
#define AV_FRAME_SIDE_DATA_FLAG_UNIQUE
Remove existing entries before adding new ones.
Definition frame.h:1093
const char * av_frame_side_data_name(enum AVFrameSideDataType type)
Definition side_data.c:76
@ AV_FRAME_DATA_SPHERICAL
The data represents the AVSphericalMapping structure defined in libavutil/spherical....
Definition frame.h:131
@ AV_FRAME_DATA_CONTENT_LIGHT_LEVEL
Content light level (based on CTA-861.3).
Definition frame.h:137
@ AV_FRAME_DATA_SEI_UNREGISTERED
User data unregistered metadata associated with a video frame.
Definition frame.h:178
common internal API header
int main(void)
static void print_entries(const AVFrameSideData **sd, const int nb_sd)
Structure to hold side data for an AVFrame.
Definition frame.h:327
uint8_t * data
Definition frame.h:329
AVFrameSideData ** sd
static void set(uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f, double v)
Definition swresample.c:55