FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/options.c
Date: 2026-10-14 08:57:35
Exec Total Coverage
Lines: 219 298 73.5%
Functions: 18 21 85.7%
Branches: 114 167 68.3%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
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 #include "avformat.h"
21 #include "avformat_internal.h"
22 #include "avio_internal.h"
23 #include "demux.h"
24 #include "internal.h"
25
26 #include "libavcodec/avcodec.h"
27 #include "libavcodec/codec_par.h"
28
29 #include "libavutil/attributes.h"
30 #include "libavutil/avassert.h"
31 #include "libavutil/iamf.h"
32 #include "libavutil/internal.h"
33 #include "libavutil/intmath.h"
34 #include "libavutil/mem.h"
35 #include "libavutil/opt.h"
36
37 /**
38 * @file
39 * Options definition for AVFormatContext.
40 */
41
42 FF_DISABLE_DEPRECATION_WARNINGS
43 #include "options_table.h"
44 FF_ENABLE_DEPRECATION_WARNINGS
45
46 2919 static const char* format_to_name(void* ptr)
47 {
48 2919 AVFormatContext* fc = (AVFormatContext*) ptr;
49
2/2
✓ Branch 0 taken 1681 times.
✓ Branch 1 taken 1238 times.
2919 if (fc->name) return fc->name;
50
2/2
✓ Branch 0 taken 185 times.
✓ Branch 1 taken 1053 times.
1238 else if(fc->iformat) return fc->iformat->name;
51
2/2
✓ Branch 0 taken 1052 times.
✓ Branch 1 taken 1 times.
1053 else if(fc->oformat) return fc->oformat->name;
52 1 else return fc->av_class->class_name;
53 }
54
55 61554 static void *format_child_next(void *obj, void *prev)
56 {
57 61554 AVFormatContext *s = obj;
58
4/4
✓ Branch 0 taken 25095 times.
✓ Branch 1 taken 36459 times.
✓ Branch 2 taken 24541 times.
✓ Branch 3 taken 554 times.
61554 if (!prev && s->priv_data &&
59
4/4
✓ Branch 0 taken 24539 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2989 times.
✓ Branch 3 taken 21550 times.
24541 ((s->iformat && s->iformat->priv_class) ||
60
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2989 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2991 s->oformat && s->oformat->priv_class))
61 21552 return s->priv_data;
62
6/6
✓ Branch 0 taken 30396 times.
✓ Branch 1 taken 9606 times.
✓ Branch 2 taken 30374 times.
✓ Branch 3 taken 22 times.
✓ Branch 4 taken 15187 times.
✓ Branch 5 taken 15187 times.
40002 if (s->pb && s->pb->av_class && prev != s->pb)
63 15187 return s->pb;
64 24815 return NULL;
65 }
66
67 enum {
68 CHILD_CLASS_ITER_AVIO = 0,
69 CHILD_CLASS_ITER_MUX,
70 CHILD_CLASS_ITER_DEMUX,
71 CHILD_CLASS_ITER_DONE,
72
73 };
74
75 #define ITER_STATE_SHIFT 16
76
77 30613039 static const AVClass *format_child_class_iterate(void **iter)
78 {
79 // we use the low 16 bits of iter as the value to be passed to
80 // av_(de)muxer_iterate()
81 30613039 void *val = (void*)(((uintptr_t)*iter) & ((1 << ITER_STATE_SHIFT) - 1));
82 30613039 unsigned int state = ((uintptr_t)*iter) >> ITER_STATE_SHIFT;
83 30613039 const AVClass *ret = NULL;
84
85
2/2
✓ Branch 0 taken 124173 times.
✓ Branch 1 taken 30488866 times.
30613039 if (state == CHILD_CLASS_ITER_AVIO) {
86 124173 ret = &ff_avio_class;
87 124173 state++;
88 124173 goto finish;
89 }
90
91
2/2
✓ Branch 0 taken 9673101 times.
✓ Branch 1 taken 20815765 times.
30488866 if (state == CHILD_CLASS_ITER_MUX) {
92 const AVOutputFormat *ofmt;
93
94
2/2
✓ Branch 1 taken 23812169 times.
✓ Branch 2 taken 123931 times.
23936100 while ((ofmt = av_muxer_iterate(&val))) {
95 23812169 ret = ofmt->priv_class;
96
2/2
✓ Branch 0 taken 9549170 times.
✓ Branch 1 taken 14262999 times.
23812169 if (ret)
97 9549170 goto finish;
98 }
99
100 123931 val = NULL;
101 123931 state++;
102 }
103
104
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20939696 times.
20939696 if (state == CHILD_CLASS_ITER_DEMUX) {
105 const AVInputFormat *ifmt;
106
107
2/2
✓ Branch 1 taken 45845126 times.
✓ Branch 2 taken 123882 times.
45969008 while ((ifmt = av_demuxer_iterate(&val))) {
108 45845126 ret = ifmt->priv_class;
109
2/2
✓ Branch 0 taken 20815814 times.
✓ Branch 1 taken 25029312 times.
45845126 if (ret)
110 20815814 goto finish;
111 }
112 123882 val = NULL;
113 123882 state++;
114 }
115
116 ✗ finish:
117 // make sure none av_(de)muxer_iterate does not set the high bits of val
118
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30613039 times.
30613039 av_assert0(!((uintptr_t)val >> ITER_STATE_SHIFT));
119 30613039 *iter = (void*)((uintptr_t)val | (state << ITER_STATE_SHIFT));
120 30613039 return ret;
121 }
122
123 2919 static AVClassCategory get_category(void *ptr)
124 {
125 2919 AVFormatContext* s = ptr;
126
2/2
✓ Branch 0 taken 1866 times.
✓ Branch 1 taken 1053 times.
2919 if(s->iformat) return AV_CLASS_CATEGORY_DEMUXER;
127 1053 else return AV_CLASS_CATEGORY_MUXER;
128 }
129
130 static const AVClass av_format_context_class = {
131 .class_name = "AVFormatContext",
132 .item_name = format_to_name,
133 .option = avformat_options,
134 .version = LIBAVUTIL_VERSION_INT,
135 .child_next = format_child_next,
136 .child_class_iterate = format_child_class_iterate,
137 .category = AV_CLASS_CATEGORY_MUXER,
138 .get_category = get_category,
139 };
140
141 108097 static int io_open_default(AVFormatContext *s, AVIOContext **pb,
142 const char *url, int flags, AVDictionary **options)
143 {
144 int loglevel;
145
146
2/2
✓ Branch 0 taken 102957 times.
✓ Branch 1 taken 5140 times.
108097 if (!strcmp(url, s->url) ||
147
4/4
✓ Branch 0 taken 102056 times.
✓ Branch 1 taken 901 times.
✓ Branch 2 taken 124 times.
✓ Branch 3 taken 101932 times.
102957 s->iformat && !strcmp(s->iformat->name, "image2") ||
148
4/4
✓ Branch 0 taken 901 times.
✓ Branch 1 taken 124 times.
✓ Branch 2 taken 666 times.
✓ Branch 3 taken 235 times.
1025 s->oformat && !strcmp(s->oformat->name, "image2")
149 ) {
150 107738 loglevel = AV_LOG_DEBUG;
151 } else
152 359 loglevel = AV_LOG_INFO;
153
154
2/2
✓ Branch 0 taken 916 times.
✓ Branch 1 taken 107181 times.
108097 av_log(s, loglevel, "Opening \'%s\' for %s\n", url, flags & AVIO_FLAG_WRITE ? "writing" : "reading");
155
156 216194 return ffio_open_whitelist2(pb, url, flags, &s->interrupt_callback, options,
157 108097 s->protocol_whitelist, s->protocol_blacklist, s);
158 }
159
160 108095 static int io_close2_default(AVFormatContext *s, AVIOContext *pb)
161 {
162 108095 return avio_close(pb);
163 }
164
165 17365 AVFormatContext *avformat_alloc_context(void)
166 {
167 FormatContextInternal *fci;
168 FFFormatContext *si;
169 AVFormatContext *s;
170
171 17365 fci = av_mallocz(sizeof(*fci));
172
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17365 times.
17365 if (!fci)
173 ✗ return NULL;
174
175 17365 si = &fci->fc;
176 17365 s = &si->pub;
177 17365 s->av_class = &av_format_context_class;
178 17365 s->io_open = io_open_default;
179 17365 s->io_close2= io_close2_default;
180
181 17365 av_opt_set_defaults(s);
182
183 17365 si->pkt = av_packet_alloc();
184 17365 si->parse_pkt = av_packet_alloc();
185
2/4
✓ Branch 0 taken 17365 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 17365 times.
17365 if (!si->pkt || !si->parse_pkt) {
186 ✗ avformat_free_context(s);
187 ✗ return NULL;
188 }
189
190 17365 return s;
191 }
192
193 139801 const AVClass *avformat_get_class(void)
194 {
195 139801 return &av_format_context_class;
196 }
197
198 #define DISPOSITION_OPT(ctx) \
199 { "disposition", NULL, offsetof(ctx, disposition), AV_OPT_TYPE_FLAGS, { .i64 = 0 }, \
200 .flags = AV_OPT_FLAG_ENCODING_PARAM, .unit = "disposition" }, \
201 { "default", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DEFAULT }, .unit = "disposition" }, \
202 { "dub", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DUB }, .unit = "disposition" }, \
203 { "original", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_ORIGINAL }, .unit = "disposition" }, \
204 { "comment", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_COMMENT }, .unit = "disposition" }, \
205 { "lyrics", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_LYRICS }, .unit = "disposition" }, \
206 { "karaoke", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_KARAOKE }, .unit = "disposition" }, \
207 { "forced", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_FORCED }, .unit = "disposition" }, \
208 { "hearing_impaired", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_HEARING_IMPAIRED }, .unit = "disposition" }, \
209 { "visual_impaired", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_VISUAL_IMPAIRED }, .unit = "disposition" }, \
210 { "clean_effects", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_CLEAN_EFFECTS }, .unit = "disposition" }, \
211 { "attached_pic", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_ATTACHED_PIC }, .unit = "disposition" }, \
212 { "timed_thumbnails", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_TIMED_THUMBNAILS }, .unit = "disposition" }, \
213 { "non_diegetic", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_NON_DIEGETIC }, .unit = "disposition" }, \
214 { "captions", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_CAPTIONS }, .unit = "disposition" }, \
215 { "descriptions", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DESCRIPTIONS }, .unit = "disposition" }, \
216 { "metadata", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_METADATA }, .unit = "disposition" }, \
217 { "dependent", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DEPENDENT }, .unit = "disposition" }, \
218 { "still_image", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_STILL_IMAGE }, .unit = "disposition" }, \
219 { "multilayer", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_MULTILAYER }, .unit = "disposition" }
220
221 static const AVOption stream_options[] = {
222 DISPOSITION_OPT(AVStream),
223 { "discard", NULL, offsetof(AVStream, discard), AV_OPT_TYPE_INT, { .i64 = AVDISCARD_DEFAULT }, INT_MIN, INT_MAX,
224 .flags = AV_OPT_FLAG_DECODING_PARAM, .unit = "avdiscard" },
225 { "none", .type = AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_NONE }, .unit = "avdiscard" },
226 { "default", .type = AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_DEFAULT }, .unit = "avdiscard" },
227 { "noref", .type = AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_NONREF }, .unit = "avdiscard" },
228 { "bidir", .type = AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_BIDIR }, .unit = "avdiscard" },
229 { "nointra", .type = AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_NONINTRA }, .unit = "avdiscard" },
230 { "nokey", .type = AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_NONKEY }, .unit = "avdiscard" },
231 { "all", .type = AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_ALL }, .unit = "avdiscard" },
232 { NULL }
233 };
234
235 static const AVClass stream_class = {
236 .class_name = "AVStream",
237 .item_name = av_default_item_name,
238 .version = LIBAVUTIL_VERSION_INT,
239 .option = stream_options,
240 };
241
242 1 const AVClass *av_stream_get_class(void)
243 {
244 1 return &stream_class;
245 }
246
247 19352 AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c)
248 {
249 FFStream *sti;
250 AVStream *st;
251 AVStream **streams;
252
253
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19352 times.
19352 if (s->nb_streams >= s->max_streams) {
254 ✗ av_log(s, AV_LOG_ERROR, "Number of streams exceeds max_streams parameter"
255 " (%d), see the documentation if you wish to increase it\n",
256 s->max_streams);
257 ✗ return NULL;
258 }
259 19352 streams = av_realloc_array(s->streams, s->nb_streams + 1, sizeof(*streams));
260
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19352 times.
19352 if (!streams)
261 ✗ return NULL;
262 19352 s->streams = streams;
263
264 19352 sti = av_mallocz(sizeof(*sti));
265
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19352 times.
19352 if (!sti)
266 ✗ return NULL;
267 19352 st = &sti->pub;
268
269 19352 st->av_class = &stream_class;
270 19352 st->codecpar = avcodec_parameters_alloc();
271
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19352 times.
19352 if (!st->codecpar)
272 ✗ goto fail;
273
274 19352 sti->fmtctx = s;
275
276 19352 sti->parse_pkt = av_packet_alloc();
277
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19352 times.
19352 if (!sti->parse_pkt)
278 ✗ goto fail;
279
280
2/2
✓ Branch 0 taken 9555 times.
✓ Branch 1 taken 9797 times.
19352 if (s->iformat) {
281 9555 sti->avctx = avcodec_alloc_context3(NULL);
282
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9555 times.
9555 if (!sti->avctx)
283 ✗ goto fail;
284
285 9555 sti->info = av_mallocz(sizeof(*sti->info));
286
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9555 times.
9555 if (!sti->info)
287 ✗ goto fail;
288
289 #if FF_API_R_FRAME_RATE
290 9555 sti->info->last_dts = AV_NOPTS_VALUE;
291 #endif
292 9555 sti->info->fps_first_dts = AV_NOPTS_VALUE;
293 9555 sti->info->fps_last_dts = AV_NOPTS_VALUE;
294
295 /* default pts setting is MPEG-like */
296 9555 avpriv_set_pts_info(st, 33, 1, 90000);
297 /* we set the current DTS to 0 so that formats without any timestamps
298 * but durations get some timestamps, formats with some unknown
299 * timestamps have their first few packets buffered and the
300 * timestamps corrected before they are returned to the user */
301 9555 sti->cur_dts = RELATIVE_TS_BASE;
302 } else {
303 9797 sti->cur_dts = AV_NOPTS_VALUE;
304 }
305
306 19352 st->index = s->nb_streams;
307 19352 st->start_time = AV_NOPTS_VALUE;
308 19352 st->duration = AV_NOPTS_VALUE;
309 19352 sti->first_dts = AV_NOPTS_VALUE;
310 19352 sti->probe_packets = s->max_probe_packets;
311 19352 sti->pts_wrap_reference = AV_NOPTS_VALUE;
312 19352 sti->pts_wrap_behavior = AV_PTS_WRAP_IGNORE;
313
314 19352 sti->last_IP_pts = AV_NOPTS_VALUE;
315 19352 sti->last_dts_for_order_check = AV_NOPTS_VALUE;
316
2/2
✓ Branch 0 taken 328984 times.
✓ Branch 1 taken 19352 times.
348336 for (int i = 0; i < MAX_REORDER_DELAY + 1; i++)
317 328984 sti->pts_buffer[i] = AV_NOPTS_VALUE;
318
319 19352 st->sample_aspect_ratio = (AVRational) { 0, 1 };
320
321 19352 sti->need_context_update = 1;
322
323 19352 s->streams[s->nb_streams++] = st;
324 19352 return st;
325 ✗ fail:
326 ✗ ff_free_stream(&st);
327 ✗ return NULL;
328 }
329
330 #define FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM
331 #define OFFSET(x) offsetof(AVStreamGroupTileGrid, x)
332 static const AVOption tile_grid_options[] = {
333 { "grid_size", "size of the output canvas", OFFSET(coded_width),
334 AV_OPT_TYPE_IMAGE_SIZE, { .str = NULL }, 0, INT_MAX, FLAGS },
335 { "output_size", "size of valid pixels in output image meant for presentation", OFFSET(width),
336 AV_OPT_TYPE_IMAGE_SIZE, { .str = NULL }, 0, INT_MAX, FLAGS },
337 { "background_color", "set a background color for unused pixels",
338 OFFSET(background), AV_OPT_TYPE_COLOR, { .str = "black"}, 0, 0, FLAGS },
339 { "horizontal_offset", NULL, OFFSET(horizontal_offset), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS },
340 { "vertical_offset", NULL, OFFSET(vertical_offset), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS },
341 { NULL },
342 };
343 #undef OFFSET
344
345 static const AVClass tile_grid_class = {
346 .class_name = "AVStreamGroupTileGrid",
347 .version = LIBAVUTIL_VERSION_INT,
348 .option = tile_grid_options,
349 };
350
351 #define OFFSET(x) offsetof(AVStreamGroupTREF, x)
352 static const AVOption tref_options[] = {
353 { "metadata_index", "Index of the data stream within the group", OFFSET(metadata_index),
354 AV_OPT_TYPE_UINT, { .i64 = 0 }, 0, UINT_MAX, FLAGS },
355 { NULL },
356 };
357 #undef OFFSET
358
359 static const AVClass tref_class = {
360 .class_name = "AVStreamGroupTREF",
361 .version = LIBAVUTIL_VERSION_INT,
362 .option = tref_options,
363 };
364
365 #if FF_API_LCEVC_STRUCT
366 FF_DISABLE_DEPRECATION_WARNINGS
367 #endif
368 #define OFFSET(x) offsetof(AVStreamGroupLayeredVideo, x)
369 static const AVOption layered_video_options[] = {
370 #if FF_API_LCEVC_STRUCT
371 { "lcevc_index", "Index of the LCEVC stream within the group", OFFSET(lcevc_index),
372 AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS | AV_OPT_FLAG_DEPRECATED },
373 #endif
374 { "el_index", "Index of the enhancement layer stream within the group", OFFSET(el_index),
375 AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS },
376 { "video_size", "size of the final layered video presentation", OFFSET(width),
377 AV_OPT_TYPE_IMAGE_SIZE, { .str = NULL }, 0, INT_MAX, FLAGS },
378 { NULL },
379 };
380 #if FF_API_LCEVC_STRUCT
381 FF_ENABLE_DEPRECATION_WARNINGS
382 #endif
383 #undef OFFSET
384
385 static const AVClass layered_video_class = {
386 .class_name = "AVStreamGroupLayeredVideo",
387 .version = LIBAVUTIL_VERSION_INT,
388 .option = layered_video_options,
389 };
390
391 231 static void *stream_group_child_next(void *obj, void *prev)
392 {
393 231 AVStreamGroup *stg = obj;
394
2/2
✓ Branch 0 taken 130 times.
✓ Branch 1 taken 101 times.
231 if (!prev) {
395
3/6
✓ Branch 0 taken 65 times.
✓ Branch 1 taken 62 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
130 switch(stg->type) {
396 65 case AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT:
397 65 return stg->params.iamf_audio_element;
398 62 case AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION:
399 62 return stg->params.iamf_mix_presentation;
400 ✗ case AV_STREAM_GROUP_PARAMS_TILE_GRID:
401 ✗ return stg->params.tile_grid;
402 ✗ case AV_STREAM_GROUP_PARAMS_TREF:
403 ✗ return stg->params.tref;
404 3 case AV_STREAM_GROUP_PARAMS_LCEVC:
405 case AV_STREAM_GROUP_PARAMS_DOLBY_VISION:
406 case AV_STREAM_GROUP_PARAMS_GAIN_MAP:
407 3 return stg->params.layered_video;
408 ✗ default:
409 ✗ break;
410 }
411 }
412 101 return NULL;
413 }
414
415 #undef FLAGS
416
417 ✗ static const AVClass *stream_group_child_iterate(void **opaque)
418 {
419 ✗ uintptr_t i = (uintptr_t)*opaque;
420 ✗ const AVClass *ret = NULL;
421
422 ✗ switch(i) {
423 ✗ case AV_STREAM_GROUP_PARAMS_NONE:
424 ✗ i++;
425 av_fallthrough;
426 ✗ case AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT:
427 ✗ ret = av_iamf_audio_element_get_class();
428 ✗ break;
429 ✗ case AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION:
430 ✗ ret = av_iamf_mix_presentation_get_class();
431 ✗ break;
432 ✗ case AV_STREAM_GROUP_PARAMS_TILE_GRID:
433 ✗ ret = &tile_grid_class;
434 ✗ break;
435 ✗ case AV_STREAM_GROUP_PARAMS_TREF:
436 ✗ ret = &tref_class;
437 ✗ break;
438 ✗ case AV_STREAM_GROUP_PARAMS_LCEVC:
439 case AV_STREAM_GROUP_PARAMS_DOLBY_VISION:
440 case AV_STREAM_GROUP_PARAMS_GAIN_MAP:
441 ✗ ret = &layered_video_class;
442 ✗ break;
443 ✗ default:
444 ✗ break;
445 }
446
447 ✗ if (ret)
448 ✗ *opaque = (void*)(i + 1);
449 ✗ return ret;
450 }
451
452 static const AVOption stream_group_options[] = {
453 DISPOSITION_OPT(AVStreamGroup),
454 {"id", "Set group id", offsetof(AVStreamGroup, id), AV_OPT_TYPE_INT64, {.i64 = 0}, 0, INT64_MAX, AV_OPT_FLAG_ENCODING_PARAM },
455 { NULL }
456 };
457
458 static const AVClass stream_group_class = {
459 .class_name = "AVStreamGroup",
460 .item_name = av_default_item_name,
461 .version = LIBAVUTIL_VERSION_INT,
462 .option = stream_group_options,
463 .child_next = stream_group_child_next,
464 .child_class_iterate = stream_group_child_iterate,
465 };
466
467 ✗ const AVClass *av_stream_group_get_class(void)
468 {
469 ✗ return &stream_group_class;
470 }
471
472 174 AVStreamGroup *avformat_stream_group_create(AVFormatContext *s,
473 enum AVStreamGroupParamsType type,
474 AVDictionary **options)
475 {
476 AVStreamGroup **stream_groups;
477 AVStreamGroup *stg;
478 FFStreamGroup *stgi;
479
480 174 stream_groups = av_realloc_array(s->stream_groups, s->nb_stream_groups + 1,
481 sizeof(*stream_groups));
482
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 174 times.
174 if (!stream_groups)
483 ✗ return NULL;
484 174 s->stream_groups = stream_groups;
485
486 174 stgi = av_mallocz(sizeof(*stgi));
487
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 174 times.
174 if (!stgi)
488 ✗ return NULL;
489 174 stg = &stgi->pub;
490
491 174 stg->av_class = &stream_group_class;
492 174 av_opt_set_defaults(stg);
493
5/6
✓ Branch 0 taken 58 times.
✓ Branch 1 taken 55 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 39 times.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
174 switch (type) {
494 58 case AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT:
495 58 stg->params.iamf_audio_element = av_iamf_audio_element_alloc();
496
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 58 times.
58 if (!stg->params.iamf_audio_element)
497 ✗ goto fail;
498 58 break;
499 55 case AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION:
500 55 stg->params.iamf_mix_presentation = av_iamf_mix_presentation_alloc();
501
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if (!stg->params.iamf_mix_presentation)
502 ✗ goto fail;
503 55 break;
504 11 case AV_STREAM_GROUP_PARAMS_TILE_GRID:
505 11 stg->params.tile_grid = av_mallocz(sizeof(*stg->params.tile_grid));
506
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (!stg->params.tile_grid)
507 ✗ goto fail;
508 11 stg->params.tile_grid->av_class = &tile_grid_class;
509 11 av_opt_set_defaults(stg->params.tile_grid);
510 11 break;
511 39 case AV_STREAM_GROUP_PARAMS_TREF:
512 39 stg->params.tref = av_mallocz(sizeof(*stg->params.tref));
513
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 39 times.
39 if (!stg->params.tref)
514 ✗ goto fail;
515 39 stg->params.tref->av_class = &tref_class;
516 39 av_opt_set_defaults(stg->params.tref);
517 39 break;
518 11 case AV_STREAM_GROUP_PARAMS_LCEVC:
519 case AV_STREAM_GROUP_PARAMS_DOLBY_VISION:
520 case AV_STREAM_GROUP_PARAMS_GAIN_MAP:
521 11 stg->params.layered_video = av_mallocz(sizeof(*stg->params.layered_video));
522
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (!stg->params.layered_video)
523 ✗ goto fail;
524 11 stg->params.layered_video->av_class = &layered_video_class;
525 11 av_opt_set_defaults(stg->params.layered_video);
526 11 break;
527 ✗ default:
528 ✗ goto fail;
529 }
530 174 stg->type = type;
531
532
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 144 times.
174 if (options) {
533
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
30 if (av_opt_set_dict2(stg, options, AV_OPT_SEARCH_CHILDREN))
534 ✗ goto fail;
535 }
536
537 174 stgi->fmtctx = s;
538 174 stg->index = s->nb_stream_groups;
539
540 174 s->stream_groups[s->nb_stream_groups++] = stg;
541
542 174 return stg;
543 ✗ fail:
544 ✗ ff_free_stream_group(&stg);
545 ✗ return NULL;
546 }
547
548 794 static int stream_group_add_stream(AVStreamGroup *stg, AVStream *st)
549 {
550 #if FF_API_STREAM_GROUP_ENTRIES
551 FF_DISABLE_DEPRECATION_WARNINGS
552 794 AVStream **streams = av_realloc_array(stg->streams, stg->nb_streams + 1,
553 sizeof(*stg->streams));
554
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 794 times.
794 if (!streams)
555 ✗ return AVERROR(ENOMEM);
556
557 794 stg->streams = streams;
558 FF_ENABLE_DEPRECATION_WARNINGS
559 #endif
560
561 794 AVStreamGroupEntry **entries = av_realloc_array(stg->entries, stg->nb_entries + 1,
562 sizeof(*stg->entries));
563
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 794 times.
794 if (!entries)
564 ✗ return AVERROR(ENOMEM);
565
566 794 stg->entries = entries;
567 794 stg->entries[stg->nb_entries] = av_mallocz(sizeof(*stg->entries[stg->nb_entries]));
568
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 794 times.
794 if (!stg->entries[stg->nb_entries])
569 ✗ return AVERROR(ENOMEM);
570
571 794 stg->entries[stg->nb_entries]->type = AV_STREAM_GROUP_ENTRY_STREAM;
572 794 stg->entries[stg->nb_entries++]->stream = st;
573
574 #if FF_API_STREAM_GROUP_ENTRIES
575 FF_DISABLE_DEPRECATION_WARNINGS
576
2/2
✓ Branch 0 taken 792 times.
✓ Branch 1 taken 2 times.
794 if (stg->nb_streams == (stg->nb_entries - 1))
577 792 stg->streams[stg->nb_streams++] = st;
578 else
579 2 stg->nb_streams = 0;
580 FF_ENABLE_DEPRECATION_WARNINGS
581 #endif
582
583 794 return 0;
584 }
585
586 800 int avformat_stream_group_add_stream(AVStreamGroup *stg, AVStream *st)
587 {
588 800 const FFStreamGroup *stgi = cffstreamgroup(stg);
589 800 const FFStream *sti = cffstream(st);
590
591
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 800 times.
800 if (stgi->fmtctx != sti->fmtctx)
592 ✗ return AVERROR(EINVAL);
593
594
2/2
✓ Branch 0 taken 2670 times.
✓ Branch 1 taken 794 times.
3464 for (int i = 0; i < stg->nb_entries; i++) {
595 2670 const AVStreamGroupEntry *entry = stg->entries[i];
596
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2668 times.
2670 if (entry->type != AV_STREAM_GROUP_ENTRY_STREAM)
597 2 continue;
598
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2662 times.
2668 if (entry->stream->index == st->index)
599 6 return AVERROR(EEXIST);
600 }
601
602 794 return stream_group_add_stream(stg, st);
603 }
604
605 2 static int stream_group_add_stream_group(AVStreamGroup *stg, AVStreamGroup *group)
606 {
607 2 AVStreamGroupEntry **entries = av_realloc_array(stg->entries, stg->nb_entries + 1,
608 sizeof(*stg->entries));
609
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!entries)
610 ✗ return AVERROR(ENOMEM);
611
612 2 stg->entries = entries;
613 2 stg->entries[stg->nb_entries] = av_mallocz(sizeof(*stg->entries[stg->nb_entries]));
614
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!stg->entries[stg->nb_entries])
615 ✗ return AVERROR(ENOMEM);
616
617 2 stg->entries[stg->nb_entries]->type = AV_STREAM_GROUP_ENTRY_STREAM_GROUP;
618 2 stg->entries[stg->nb_entries++]->stream_group = group;
619 #if FF_API_STREAM_GROUP_ENTRIES
620 FF_DISABLE_DEPRECATION_WARNINGS
621 2 stg->nb_streams = 0;
622 FF_ENABLE_DEPRECATION_WARNINGS
623 #endif
624
625 2 return 0;
626 }
627
628 2 int avformat_stream_group_add_stream_group(AVStreamGroup *stg, AVStreamGroup *group)
629 {
630 2 const FFStreamGroup *stgi = cffstreamgroup(stg);
631 2 const FFStreamGroup *groupi = cffstreamgroup(group);
632
633
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (stgi->fmtctx != groupi->fmtctx)
634 ✗ return AVERROR(EINVAL);
635
636
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 for (int i = 0; i < stg->nb_entries; i++) {
637 ✗ const AVStreamGroupEntry *entry = stg->entries[i];
638 ✗ if (entry->type != AV_STREAM_GROUP_ENTRY_STREAM_GROUP)
639 ✗ continue;
640 ✗ if (entry->stream_group->index == group->index)
641 ✗ return AVERROR(EEXIST);
642 }
643
644 2 return stream_group_add_stream_group(stg, group);
645 }
646
647 166770 static int option_is_disposition(const AVOption *opt)
648 {
649 320382 return opt->type == AV_OPT_TYPE_CONST &&
650
5/6
✓ Branch 0 taken 153612 times.
✓ Branch 1 taken 13158 times.
✓ Branch 2 taken 153612 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 127908 times.
✓ Branch 5 taken 25704 times.
166770 opt->unit && !strcmp(opt->unit, "disposition");
651 }
652
653 ✗ int av_disposition_from_string(const char *disp)
654 {
655 ✗ for (const AVOption *opt = stream_options; opt->name; opt++)
656 ✗ if (option_is_disposition(opt) && !strcmp(disp, opt->name))
657 ✗ return opt->default_val.i64;
658 ✗ return AVERROR(EINVAL);
659 }
660
661 9792 const char *av_disposition_to_string(int disposition)
662 {
663 int val;
664
665
2/2
✓ Branch 0 taken 306 times.
✓ Branch 1 taken 9486 times.
9792 if (disposition <= 0)
666 306 return NULL;
667
668 9486 val = 1 << ff_ctz(disposition);
669
2/2
✓ Branch 0 taken 166770 times.
✓ Branch 1 taken 3672 times.
170442 for (const AVOption *opt = stream_options; opt->name; opt++)
670
4/4
✓ Branch 1 taken 127908 times.
✓ Branch 2 taken 38862 times.
✓ Branch 3 taken 5814 times.
✓ Branch 4 taken 122094 times.
166770 if (option_is_disposition(opt) && opt->default_val.i64 == val)
671 5814 return opt->name;
672
673 3672 return NULL;
674 }
675