FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/options.c
Date: 2026-05-02 03:33:10
Exec Total Coverage
Lines: 182 248 73.4%
Functions: 16 19 84.2%
Branches: 100 142 70.4%

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 2699 static const char* format_to_name(void* ptr)
47 {
48 2699 AVFormatContext* fc = (AVFormatContext*) ptr;
49
2/2
✓ Branch 0 taken 1621 times.
✓ Branch 1 taken 1078 times.
2699 if (fc->name) return fc->name;
50
2/2
✓ Branch 0 taken 88 times.
✓ Branch 1 taken 990 times.
1078 else if(fc->iformat) return fc->iformat->name;
51
1/2
✓ Branch 0 taken 990 times.
✗ Branch 1 not taken.
990 else if(fc->oformat) return fc->oformat->name;
52 else return fc->av_class->class_name;
53 }
54
55 58186 static void *format_child_next(void *obj, void *prev)
56 {
57 58186 AVFormatContext *s = obj;
58
4/4
✓ Branch 0 taken 23798 times.
✓ Branch 1 taken 34388 times.
✓ Branch 2 taken 23315 times.
✓ Branch 3 taken 483 times.
58186 if (!prev && s->priv_data &&
59
4/4
✓ Branch 0 taken 23313 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2670 times.
✓ Branch 3 taken 20643 times.
23315 ((s->iformat && s->iformat->priv_class) ||
60
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2670 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2672 s->oformat && s->oformat->priv_class))
61 20645 return s->priv_data;
62
6/6
✓ Branch 0 taken 28016 times.
✓ Branch 1 taken 9525 times.
✓ Branch 2 taken 28002 times.
✓ Branch 3 taken 14 times.
✓ Branch 4 taken 14001 times.
✓ Branch 5 taken 14001 times.
37541 if (s->pb && s->pb->av_class && prev != s->pb)
63 14001 return s->pb;
64 23540 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 29165227 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 29165227 void *val = (void*)(((uintptr_t)*iter) & ((1 << ITER_STATE_SHIFT) - 1));
82 29165227 unsigned int state = ((uintptr_t)*iter) >> ITER_STATE_SHIFT;
83 29165227 const AVClass *ret = NULL;
84
85
2/2
✓ Branch 0 taken 120198 times.
✓ Branch 1 taken 29045029 times.
29165227 if (state == CHILD_CLASS_ITER_AVIO) {
86 120198 ret = &ff_avio_class;
87 120198 state++;
88 120198 goto finish;
89 }
90
91
2/2
✓ Branch 0 taken 9126401 times.
✓ Branch 1 taken 19918628 times.
29045029 if (state == CHILD_CLASS_ITER_MUX) {
92 const AVOutputFormat *ofmt;
93
94
2/2
✓ Branch 1 taken 22576861 times.
✓ Branch 2 taken 120014 times.
22696875 while ((ofmt = av_muxer_iterate(&val))) {
95 22576861 ret = ofmt->priv_class;
96
2/2
✓ Branch 0 taken 9006387 times.
✓ Branch 1 taken 13570474 times.
22576861 if (ret)
97 9006387 goto finish;
98 }
99
100 120014 val = NULL;
101 120014 state++;
102 }
103
104
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20038642 times.
20038642 if (state == CHILD_CLASS_ITER_DEMUX) {
105 const AVInputFormat *ifmt;
106
107
2/2
✓ Branch 1 taken 43797748 times.
✓ Branch 2 taken 119972 times.
43917720 while ((ifmt = av_demuxer_iterate(&val))) {
108 43797748 ret = ifmt->priv_class;
109
2/2
✓ Branch 0 taken 19918670 times.
✓ Branch 1 taken 23879078 times.
43797748 if (ret)
110 19918670 goto finish;
111 }
112 119972 val = NULL;
113 119972 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 29165227 times.
29165227 av_assert0(!((uintptr_t)val >> ITER_STATE_SHIFT));
119 29165227 *iter = (void*)((uintptr_t)val | (state << ITER_STATE_SHIFT));
120 29165227 return ret;
121 }
122
123 2699 static AVClassCategory get_category(void *ptr)
124 {
125 2699 AVFormatContext* s = ptr;
126
2/2
✓ Branch 0 taken 1709 times.
✓ Branch 1 taken 990 times.
2699 if(s->iformat) return AV_CLASS_CATEGORY_DEMUXER;
127 990 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 107923 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 103186 times.
✓ Branch 1 taken 4737 times.
107923 if (!strcmp(url, s->url) ||
147
4/4
✓ Branch 0 taken 102327 times.
✓ Branch 1 taken 859 times.
✓ Branch 2 taken 68 times.
✓ Branch 3 taken 102259 times.
103186 s->iformat && !strcmp(s->iformat->name, "image2") ||
148
4/4
✓ Branch 0 taken 859 times.
✓ Branch 1 taken 68 times.
✓ Branch 2 taken 663 times.
✓ Branch 3 taken 196 times.
927 s->oformat && !strcmp(s->oformat->name, "image2")
149 ) {
150 107659 loglevel = AV_LOG_DEBUG;
151 } else
152 264 loglevel = AV_LOG_INFO;
153
154
2/2
✓ Branch 0 taken 873 times.
✓ Branch 1 taken 107050 times.
107923 av_log(s, loglevel, "Opening \'%s\' for %s\n", url, flags & AVIO_FLAG_WRITE ? "writing" : "reading");
155
156 107923 return ffio_open_whitelist(pb, url, flags, &s->interrupt_callback, options, s->protocol_whitelist, s->protocol_blacklist);
157 }
158
159 107921 static int io_close2_default(AVFormatContext *s, AVIOContext *pb)
160 {
161 107921 return avio_close(pb);
162 }
163
164 16545 AVFormatContext *avformat_alloc_context(void)
165 {
166 FormatContextInternal *fci;
167 FFFormatContext *si;
168 AVFormatContext *s;
169
170 16545 fci = av_mallocz(sizeof(*fci));
171
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16545 times.
16545 if (!fci)
172 return NULL;
173
174 16545 si = &fci->fc;
175 16545 s = &si->pub;
176 16545 s->av_class = &av_format_context_class;
177 16545 s->io_open = io_open_default;
178 16545 s->io_close2= io_close2_default;
179
180 16545 av_opt_set_defaults(s);
181
182 16545 si->pkt = av_packet_alloc();
183 16545 si->parse_pkt = av_packet_alloc();
184
2/4
✓ Branch 0 taken 16545 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 16545 times.
16545 if (!si->pkt || !si->parse_pkt) {
185 avformat_free_context(s);
186 return NULL;
187 }
188
189 16545 return s;
190 }
191
192 135241 const AVClass *avformat_get_class(void)
193 {
194 135241 return &av_format_context_class;
195 }
196
197 #define DISPOSITION_OPT(ctx) \
198 { "disposition", NULL, offsetof(ctx, disposition), AV_OPT_TYPE_FLAGS, { .i64 = 0 }, \
199 .flags = AV_OPT_FLAG_ENCODING_PARAM, .unit = "disposition" }, \
200 { "default", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DEFAULT }, .unit = "disposition" }, \
201 { "dub", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DUB }, .unit = "disposition" }, \
202 { "original", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_ORIGINAL }, .unit = "disposition" }, \
203 { "comment", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_COMMENT }, .unit = "disposition" }, \
204 { "lyrics", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_LYRICS }, .unit = "disposition" }, \
205 { "karaoke", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_KARAOKE }, .unit = "disposition" }, \
206 { "forced", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_FORCED }, .unit = "disposition" }, \
207 { "hearing_impaired", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_HEARING_IMPAIRED }, .unit = "disposition" }, \
208 { "visual_impaired", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_VISUAL_IMPAIRED }, .unit = "disposition" }, \
209 { "clean_effects", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_CLEAN_EFFECTS }, .unit = "disposition" }, \
210 { "attached_pic", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_ATTACHED_PIC }, .unit = "disposition" }, \
211 { "timed_thumbnails", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_TIMED_THUMBNAILS }, .unit = "disposition" }, \
212 { "non_diegetic", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_NON_DIEGETIC }, .unit = "disposition" }, \
213 { "captions", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_CAPTIONS }, .unit = "disposition" }, \
214 { "descriptions", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DESCRIPTIONS }, .unit = "disposition" }, \
215 { "metadata", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_METADATA }, .unit = "disposition" }, \
216 { "dependent", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DEPENDENT }, .unit = "disposition" }, \
217 { "still_image", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_STILL_IMAGE }, .unit = "disposition" }, \
218 { "multilayer", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_MULTILAYER }, .unit = "disposition" }
219
220 static const AVOption stream_options[] = {
221 DISPOSITION_OPT(AVStream),
222 { "discard", NULL, offsetof(AVStream, discard), AV_OPT_TYPE_INT, { .i64 = AVDISCARD_DEFAULT }, INT_MIN, INT_MAX,
223 .flags = AV_OPT_FLAG_DECODING_PARAM, .unit = "avdiscard" },
224 { "none", .type = AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_NONE }, .unit = "avdiscard" },
225 { "default", .type = AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_DEFAULT }, .unit = "avdiscard" },
226 { "noref", .type = AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_NONREF }, .unit = "avdiscard" },
227 { "bidir", .type = AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_BIDIR }, .unit = "avdiscard" },
228 { "nointra", .type = AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_NONINTRA }, .unit = "avdiscard" },
229 { "nokey", .type = AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_NONKEY }, .unit = "avdiscard" },
230 { "all", .type = AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_ALL }, .unit = "avdiscard" },
231 { NULL }
232 };
233
234 static const AVClass stream_class = {
235 .class_name = "AVStream",
236 .item_name = av_default_item_name,
237 .version = LIBAVUTIL_VERSION_INT,
238 .option = stream_options,
239 };
240
241 1 const AVClass *av_stream_get_class(void)
242 {
243 1 return &stream_class;
244 }
245
246 17971 AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c)
247 {
248 FFStream *sti;
249 AVStream *st;
250 AVStream **streams;
251
252
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17971 times.
17971 if (s->nb_streams >= s->max_streams) {
253 av_log(s, AV_LOG_ERROR, "Number of streams exceeds max_streams parameter"
254 " (%d), see the documentation if you wish to increase it\n",
255 s->max_streams);
256 return NULL;
257 }
258 17971 streams = av_realloc_array(s->streams, s->nb_streams + 1, sizeof(*streams));
259
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17971 times.
17971 if (!streams)
260 return NULL;
261 17971 s->streams = streams;
262
263 17971 sti = av_mallocz(sizeof(*sti));
264
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17971 times.
17971 if (!sti)
265 return NULL;
266 17971 st = &sti->pub;
267
268 17971 st->av_class = &stream_class;
269 17971 st->codecpar = avcodec_parameters_alloc();
270
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17971 times.
17971 if (!st->codecpar)
271 goto fail;
272
273 17971 sti->fmtctx = s;
274
275 17971 sti->parse_pkt = av_packet_alloc();
276
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17971 times.
17971 if (!sti->parse_pkt)
277 goto fail;
278
279
2/2
✓ Branch 0 taken 8786 times.
✓ Branch 1 taken 9185 times.
17971 if (s->iformat) {
280 8786 sti->avctx = avcodec_alloc_context3(NULL);
281
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8786 times.
8786 if (!sti->avctx)
282 goto fail;
283
284 8786 sti->info = av_mallocz(sizeof(*sti->info));
285
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8786 times.
8786 if (!sti->info)
286 goto fail;
287
288 #if FF_API_R_FRAME_RATE
289 8786 sti->info->last_dts = AV_NOPTS_VALUE;
290 #endif
291 8786 sti->info->fps_first_dts = AV_NOPTS_VALUE;
292 8786 sti->info->fps_last_dts = AV_NOPTS_VALUE;
293
294 /* default pts setting is MPEG-like */
295 8786 avpriv_set_pts_info(st, 33, 1, 90000);
296 /* we set the current DTS to 0 so that formats without any timestamps
297 * but durations get some timestamps, formats with some unknown
298 * timestamps have their first few packets buffered and the
299 * timestamps corrected before they are returned to the user */
300 8786 sti->cur_dts = RELATIVE_TS_BASE;
301 } else {
302 9185 sti->cur_dts = AV_NOPTS_VALUE;
303 }
304
305 17971 st->index = s->nb_streams;
306 17971 st->start_time = AV_NOPTS_VALUE;
307 17971 st->duration = AV_NOPTS_VALUE;
308 17971 sti->first_dts = AV_NOPTS_VALUE;
309 17971 sti->probe_packets = s->max_probe_packets;
310 17971 sti->pts_wrap_reference = AV_NOPTS_VALUE;
311 17971 sti->pts_wrap_behavior = AV_PTS_WRAP_IGNORE;
312
313 17971 sti->last_IP_pts = AV_NOPTS_VALUE;
314 17971 sti->last_dts_for_order_check = AV_NOPTS_VALUE;
315
2/2
✓ Branch 0 taken 305507 times.
✓ Branch 1 taken 17971 times.
323478 for (int i = 0; i < MAX_REORDER_DELAY + 1; i++)
316 305507 sti->pts_buffer[i] = AV_NOPTS_VALUE;
317
318 17971 st->sample_aspect_ratio = (AVRational) { 0, 1 };
319 #if FF_API_INTERNAL_TIMING
320 17971 sti->transferred_mux_tb = (AVRational) { 0, 1 };;
321 #endif
322
323 17971 sti->need_context_update = 1;
324
325 17971 s->streams[s->nb_streams++] = st;
326 17971 return st;
327 fail:
328 ff_free_stream(&st);
329 return NULL;
330 }
331
332 #define FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM
333 #define OFFSET(x) offsetof(AVStreamGroupTileGrid, x)
334 static const AVOption tile_grid_options[] = {
335 { "grid_size", "size of the output canvas", OFFSET(coded_width),
336 AV_OPT_TYPE_IMAGE_SIZE, { .str = NULL }, 0, INT_MAX, FLAGS },
337 { "output_size", "size of valid pixels in output image meant for presentation", OFFSET(width),
338 AV_OPT_TYPE_IMAGE_SIZE, { .str = NULL }, 0, INT_MAX, FLAGS },
339 { "background_color", "set a background color for unused pixels",
340 OFFSET(background), AV_OPT_TYPE_COLOR, { .str = "black"}, 0, 0, FLAGS },
341 { "horizontal_offset", NULL, OFFSET(horizontal_offset), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS },
342 { "vertical_offset", NULL, OFFSET(vertical_offset), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS },
343 { NULL },
344 };
345 #undef OFFSET
346
347 static const AVClass tile_grid_class = {
348 .class_name = "AVStreamGroupTileGrid",
349 .version = LIBAVUTIL_VERSION_INT,
350 .option = tile_grid_options,
351 };
352
353 #define OFFSET(x) offsetof(AVStreamGroupLCEVC, x)
354 static const AVOption lcevc_options[] = {
355 { "lcevc_index", "Index of the LCEVC stream within the group", OFFSET(lcevc_index),
356 AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS },
357 { "video_size", "size of video after LCEVC enhancement has been applied", OFFSET(width),
358 AV_OPT_TYPE_IMAGE_SIZE, { .str = NULL }, 0, INT_MAX, FLAGS },
359 { NULL },
360 };
361 #undef OFFSET
362
363 static const AVClass lcevc_class = {
364 .class_name = "AVStreamGroupLCEVC",
365 .version = LIBAVUTIL_VERSION_INT,
366 .option = lcevc_options,
367 };
368
369 204 static void *stream_group_child_next(void *obj, void *prev)
370 {
371 204 AVStreamGroup *stg = obj;
372
2/2
✓ Branch 0 taken 115 times.
✓ Branch 1 taken 89 times.
204 if (!prev) {
373
2/5
✓ Branch 0 taken 59 times.
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
115 switch(stg->type) {
374 59 case AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT:
375 59 return stg->params.iamf_audio_element;
376 56 case AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION:
377 56 return stg->params.iamf_mix_presentation;
378 case AV_STREAM_GROUP_PARAMS_TILE_GRID:
379 return stg->params.tile_grid;
380 case AV_STREAM_GROUP_PARAMS_LCEVC:
381 return stg->params.lcevc;
382 default:
383 break;
384 }
385 }
386 89 return NULL;
387 }
388
389 #undef FLAGS
390
391 static const AVClass *stream_group_child_iterate(void **opaque)
392 {
393 uintptr_t i = (uintptr_t)*opaque;
394 const AVClass *ret = NULL;
395
396 switch(i) {
397 case AV_STREAM_GROUP_PARAMS_NONE:
398 i++;
399 av_fallthrough;
400 case AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT:
401 ret = av_iamf_audio_element_get_class();
402 break;
403 case AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION:
404 ret = av_iamf_mix_presentation_get_class();
405 break;
406 case AV_STREAM_GROUP_PARAMS_TILE_GRID:
407 ret = &tile_grid_class;
408 break;
409 case AV_STREAM_GROUP_PARAMS_LCEVC:
410 ret = &lcevc_class;
411 break;
412 default:
413 break;
414 }
415
416 if (ret)
417 *opaque = (void*)(i + 1);
418 return ret;
419 }
420
421 static const AVOption stream_group_options[] = {
422 DISPOSITION_OPT(AVStreamGroup),
423 {"id", "Set group id", offsetof(AVStreamGroup, id), AV_OPT_TYPE_INT64, {.i64 = 0}, 0, INT64_MAX, AV_OPT_FLAG_ENCODING_PARAM },
424 { NULL }
425 };
426
427 static const AVClass stream_group_class = {
428 .class_name = "AVStreamGroup",
429 .item_name = av_default_item_name,
430 .version = LIBAVUTIL_VERSION_INT,
431 .option = stream_group_options,
432 .child_next = stream_group_child_next,
433 .child_class_iterate = stream_group_child_iterate,
434 };
435
436 const AVClass *av_stream_group_get_class(void)
437 {
438 return &stream_group_class;
439 }
440
441 116 AVStreamGroup *avformat_stream_group_create(AVFormatContext *s,
442 enum AVStreamGroupParamsType type,
443 AVDictionary **options)
444 {
445 AVStreamGroup **stream_groups;
446 AVStreamGroup *stg;
447 FFStreamGroup *stgi;
448
449 116 stream_groups = av_realloc_array(s->stream_groups, s->nb_stream_groups + 1,
450 sizeof(*stream_groups));
451
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 116 times.
116 if (!stream_groups)
452 return NULL;
453 116 s->stream_groups = stream_groups;
454
455 116 stgi = av_mallocz(sizeof(*stgi));
456
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 116 times.
116 if (!stgi)
457 return NULL;
458 116 stg = &stgi->pub;
459
460 116 stg->av_class = &stream_group_class;
461 116 av_opt_set_defaults(stg);
462 116 stg->type = type;
463
4/5
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 49 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
116 switch (type) {
464 52 case AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT:
465 52 stg->params.iamf_audio_element = av_iamf_audio_element_alloc();
466
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 52 times.
52 if (!stg->params.iamf_audio_element)
467 goto fail;
468 52 break;
469 49 case AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION:
470 49 stg->params.iamf_mix_presentation = av_iamf_mix_presentation_alloc();
471
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 49 times.
49 if (!stg->params.iamf_mix_presentation)
472 goto fail;
473 49 break;
474 9 case AV_STREAM_GROUP_PARAMS_TILE_GRID:
475 9 stg->params.tile_grid = av_mallocz(sizeof(*stg->params.tile_grid));
476
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (!stg->params.tile_grid)
477 goto fail;
478 9 stg->params.tile_grid->av_class = &tile_grid_class;
479 9 av_opt_set_defaults(stg->params.tile_grid);
480 9 break;
481 6 case AV_STREAM_GROUP_PARAMS_LCEVC:
482 6 stg->params.lcevc = av_mallocz(sizeof(*stg->params.lcevc));
483
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (!stg->params.lcevc)
484 goto fail;
485 6 stg->params.lcevc->av_class = &lcevc_class;
486 6 av_opt_set_defaults(stg->params.lcevc);
487 6 break;
488 default:
489 goto fail;
490 }
491
492
2/2
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 89 times.
116 if (options) {
493
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 27 times.
27 if (av_opt_set_dict2(stg, options, AV_OPT_SEARCH_CHILDREN))
494 goto fail;
495 }
496
497 116 stgi->fmtctx = s;
498 116 stg->index = s->nb_stream_groups;
499
500 116 s->stream_groups[s->nb_stream_groups++] = stg;
501
502 116 return stg;
503 fail:
504 ff_free_stream_group(&stg);
505 return NULL;
506 }
507
508 507 static int stream_group_add_stream(AVStreamGroup *stg, AVStream *st)
509 {
510 507 AVStream **streams = av_realloc_array(stg->streams, stg->nb_streams + 1,
511 sizeof(*stg->streams));
512
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 507 times.
507 if (!streams)
513 return AVERROR(ENOMEM);
514
515 507 stg->streams = streams;
516 507 stg->streams[stg->nb_streams++] = st;
517
518 507 return 0;
519 }
520
521 513 int avformat_stream_group_add_stream(AVStreamGroup *stg, AVStream *st)
522 {
523 513 const FFStreamGroup *stgi = cffstreamgroup(stg);
524 513 const FFStream *sti = cffstream(st);
525
526
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 513 times.
513 if (stgi->fmtctx != sti->fmtctx)
527 return AVERROR(EINVAL);
528
529
2/2
✓ Branch 0 taken 1172 times.
✓ Branch 1 taken 507 times.
1679 for (int i = 0; i < stg->nb_streams; i++)
530
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1166 times.
1172 if (stg->streams[i]->index == st->index)
531 6 return AVERROR(EEXIST);
532
533 507 return stream_group_add_stream(stg, st);
534 }
535
536 158595 static int option_is_disposition(const AVOption *opt)
537 {
538 304677 return opt->type == AV_OPT_TYPE_CONST &&
539
5/6
✓ Branch 0 taken 146082 times.
✓ Branch 1 taken 12513 times.
✓ Branch 2 taken 146082 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 121638 times.
✓ Branch 5 taken 24444 times.
158595 opt->unit && !strcmp(opt->unit, "disposition");
540 }
541
542 int av_disposition_from_string(const char *disp)
543 {
544 for (const AVOption *opt = stream_options; opt->name; opt++)
545 if (option_is_disposition(opt) && !strcmp(disp, opt->name))
546 return opt->default_val.i64;
547 return AVERROR(EINVAL);
548 }
549
550 9312 const char *av_disposition_to_string(int disposition)
551 {
552 int val;
553
554
2/2
✓ Branch 0 taken 291 times.
✓ Branch 1 taken 9021 times.
9312 if (disposition <= 0)
555 291 return NULL;
556
557 9021 val = 1 << ff_ctz(disposition);
558
2/2
✓ Branch 0 taken 158595 times.
✓ Branch 1 taken 3492 times.
162087 for (const AVOption *opt = stream_options; opt->name; opt++)
559
4/4
✓ Branch 1 taken 121638 times.
✓ Branch 2 taken 36957 times.
✓ Branch 3 taken 5529 times.
✓ Branch 4 taken 116109 times.
158595 if (option_is_disposition(opt) && opt->default_val.i64 == val)
560 5529 return opt->name;
561
562 3492 return NULL;
563 }
564