FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/options.c
Date: 2024-04-20 14:10:07
Exec Total Coverage
Lines: 173 236 73.3%
Functions: 15 20 75.0%
Branches: 95 133 71.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 "avio_internal.h"
22 #include "demux.h"
23 #include "internal.h"
24
25 #include "libavcodec/avcodec.h"
26 #include "libavcodec/codec_par.h"
27
28 #include "libavutil/avassert.h"
29 #include "libavutil/iamf.h"
30 #include "libavutil/internal.h"
31 #include "libavutil/intmath.h"
32 #include "libavutil/mem.h"
33 #include "libavutil/opt.h"
34
35 /**
36 * @file
37 * Options definition for AVFormatContext.
38 */
39
40 FF_DISABLE_DEPRECATION_WARNINGS
41 #include "options_table.h"
42 FF_ENABLE_DEPRECATION_WARNINGS
43
44 2427 static const char* format_to_name(void* ptr)
45 {
46 2427 AVFormatContext* fc = (AVFormatContext*) ptr;
47
2/2
✓ Branch 0 taken 1628 times.
✓ Branch 1 taken 799 times.
2427 if(fc->iformat) return fc->iformat->name;
48
1/2
✓ Branch 0 taken 799 times.
✗ Branch 1 not taken.
799 else if(fc->oformat) return fc->oformat->name;
49 else return fc->av_class->class_name;
50 }
51
52 53210 static void *format_child_next(void *obj, void *prev)
53 {
54 53210 AVFormatContext *s = obj;
55
4/4
✓ Branch 0 taken 21573 times.
✓ Branch 1 taken 31637 times.
✓ Branch 2 taken 21105 times.
✓ Branch 3 taken 468 times.
53210 if (!prev && s->priv_data &&
56
4/4
✓ Branch 0 taken 21103 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2479 times.
✓ Branch 3 taken 18624 times.
21105 ((s->iformat && s->iformat->priv_class) ||
57
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2479 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2481 s->oformat && s->oformat->priv_class))
58 18626 return s->priv_data;
59
6/6
✓ Branch 0 taken 26382 times.
✓ Branch 1 taken 8202 times.
✓ Branch 2 taken 26370 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 13185 times.
✓ Branch 5 taken 13185 times.
34584 if (s->pb && s->pb->av_class && prev != s->pb)
60 13185 return s->pb;
61 21399 return NULL;
62 }
63
64 enum {
65 CHILD_CLASS_ITER_AVIO = 0,
66 CHILD_CLASS_ITER_MUX,
67 CHILD_CLASS_ITER_DEMUX,
68 CHILD_CLASS_ITER_DONE,
69
70 };
71
72 #define ITER_STATE_SHIFT 16
73
74 21644985 static const AVClass *format_child_class_iterate(void **iter)
75 {
76 // we use the low 16 bits of iter as the value to be passed to
77 // av_(de)muxer_iterate()
78 21644985 void *val = (void*)(((uintptr_t)*iter) & ((1 << ITER_STATE_SHIFT) - 1));
79 21644985 unsigned int state = ((uintptr_t)*iter) >> ITER_STATE_SHIFT;
80 21644985 const AVClass *ret = NULL;
81
82
2/2
✓ Branch 0 taken 91447 times.
✓ Branch 1 taken 21553538 times.
21644985 if (state == CHILD_CLASS_ITER_AVIO) {
83 91447 ret = &ff_avio_class;
84 91447 state++;
85 91447 goto finish;
86 }
87
88
2/2
✓ Branch 0 taken 6761513 times.
✓ Branch 1 taken 14792025 times.
21553538 if (state == CHILD_CLASS_ITER_MUX) {
89 const AVOutputFormat *ofmt;
90
91
2/2
✓ Branch 1 taken 16995779 times.
✓ Branch 2 taken 91323 times.
17087102 while ((ofmt = av_muxer_iterate(&val))) {
92 16995779 ret = ofmt->priv_class;
93
2/2
✓ Branch 0 taken 6670190 times.
✓ Branch 1 taken 10325589 times.
16995779 if (ret)
94 6670190 goto finish;
95 }
96
97 91323 val = NULL;
98 91323 state++;
99 }
100
101
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14883348 times.
14883348 if (state == CHILD_CLASS_ITER_DEMUX) {
102 const AVInputFormat *ifmt;
103
104
2/2
✓ Branch 1 taken 32963124 times.
✓ Branch 2 taken 91293 times.
33054417 while ((ifmt = av_demuxer_iterate(&val))) {
105 32963124 ret = ifmt->priv_class;
106
2/2
✓ Branch 0 taken 14792055 times.
✓ Branch 1 taken 18171069 times.
32963124 if (ret)
107 14792055 goto finish;
108 }
109 91293 val = NULL;
110 91293 state++;
111 }
112
113 finish:
114 // make sure none av_(de)muxer_iterate does not set the high bits of val
115
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21644985 times.
21644985 av_assert0(!((uintptr_t)val >> ITER_STATE_SHIFT));
116 21644985 *iter = (void*)((uintptr_t)val | (state << ITER_STATE_SHIFT));
117 21644985 return ret;
118 }
119
120 2427 static AVClassCategory get_category(void *ptr)
121 {
122 2427 AVFormatContext* s = ptr;
123
2/2
✓ Branch 0 taken 1628 times.
✓ Branch 1 taken 799 times.
2427 if(s->iformat) return AV_CLASS_CATEGORY_DEMUXER;
124 799 else return AV_CLASS_CATEGORY_MUXER;
125 }
126
127 static const AVClass av_format_context_class = {
128 .class_name = "AVFormatContext",
129 .item_name = format_to_name,
130 .option = avformat_options,
131 .version = LIBAVUTIL_VERSION_INT,
132 .child_next = format_child_next,
133 .child_class_iterate = format_child_class_iterate,
134 .category = AV_CLASS_CATEGORY_MUXER,
135 .get_category = get_category,
136 };
137
138 94199 static int io_open_default(AVFormatContext *s, AVIOContext **pb,
139 const char *url, int flags, AVDictionary **options)
140 {
141 int loglevel;
142
143
2/2
✓ Branch 0 taken 89759 times.
✓ Branch 1 taken 4440 times.
94199 if (!strcmp(url, s->url) ||
144
4/4
✓ Branch 0 taken 88950 times.
✓ Branch 1 taken 809 times.
✓ Branch 2 taken 62 times.
✓ Branch 3 taken 88888 times.
89759 s->iformat && !strcmp(s->iformat->name, "image2") ||
145
4/4
✓ Branch 0 taken 809 times.
✓ Branch 1 taken 62 times.
✓ Branch 2 taken 663 times.
✓ Branch 3 taken 146 times.
871 s->oformat && !strcmp(s->oformat->name, "image2")
146 ) {
147 93991 loglevel = AV_LOG_DEBUG;
148 } else
149 208 loglevel = AV_LOG_INFO;
150
151
2/2
✓ Branch 0 taken 819 times.
✓ Branch 1 taken 93380 times.
94199 av_log(s, loglevel, "Opening \'%s\' for %s\n", url, flags & AVIO_FLAG_WRITE ? "writing" : "reading");
152
153 94199 return ffio_open_whitelist(pb, url, flags, &s->interrupt_callback, options, s->protocol_whitelist, s->protocol_blacklist);
154 }
155
156 89782 static int io_close2_default(AVFormatContext *s, AVIOContext *pb)
157 {
158 89782 return avio_close(pb);
159 }
160
161 13985 AVFormatContext *avformat_alloc_context(void)
162 {
163 13985 FFFormatContext *const si = av_mallocz(sizeof(*si));
164 AVFormatContext *s;
165
166
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13985 times.
13985 if (!si)
167 return NULL;
168
169 13985 s = &si->pub;
170 13985 s->av_class = &av_format_context_class;
171 13985 s->io_open = io_open_default;
172 13985 s->io_close2= io_close2_default;
173
174 13985 av_opt_set_defaults(s);
175
176 13985 si->pkt = av_packet_alloc();
177 13985 si->parse_pkt = av_packet_alloc();
178
2/4
✓ Branch 0 taken 13985 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 13985 times.
13985 if (!si->pkt || !si->parse_pkt) {
179 avformat_free_context(s);
180 return NULL;
181 }
182
183 #if FF_API_LAVF_SHORTEST
184 13985 si->shortest_end = AV_NOPTS_VALUE;
185 #endif
186
187 13985 return s;
188 }
189
190 #if FF_API_GET_DUR_ESTIMATE_METHOD
191 enum AVDurationEstimationMethod av_fmt_ctx_get_duration_estimation_method(const AVFormatContext* ctx)
192 {
193 return ctx->duration_estimation_method;
194 }
195 #endif
196
197 97111 const AVClass *avformat_get_class(void)
198 {
199 97111 return &av_format_context_class;
200 }
201
202 #define DISPOSITION_OPT(ctx) \
203 { "disposition", NULL, offsetof(ctx, disposition), AV_OPT_TYPE_FLAGS, { .i64 = 0 }, \
204 .flags = AV_OPT_FLAG_ENCODING_PARAM, .unit = "disposition" }, \
205 { "default", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DEFAULT }, .unit = "disposition" }, \
206 { "dub", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DUB }, .unit = "disposition" }, \
207 { "original", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_ORIGINAL }, .unit = "disposition" }, \
208 { "comment", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_COMMENT }, .unit = "disposition" }, \
209 { "lyrics", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_LYRICS }, .unit = "disposition" }, \
210 { "karaoke", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_KARAOKE }, .unit = "disposition" }, \
211 { "forced", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_FORCED }, .unit = "disposition" }, \
212 { "hearing_impaired", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_HEARING_IMPAIRED }, .unit = "disposition" }, \
213 { "visual_impaired", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_VISUAL_IMPAIRED }, .unit = "disposition" }, \
214 { "clean_effects", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_CLEAN_EFFECTS }, .unit = "disposition" }, \
215 { "attached_pic", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_ATTACHED_PIC }, .unit = "disposition" }, \
216 { "timed_thumbnails", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_TIMED_THUMBNAILS }, .unit = "disposition" }, \
217 { "non_diegetic", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_NON_DIEGETIC }, .unit = "disposition" }, \
218 { "captions", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_CAPTIONS }, .unit = "disposition" }, \
219 { "descriptions", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DESCRIPTIONS }, .unit = "disposition" }, \
220 { "metadata", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_METADATA }, .unit = "disposition" }, \
221 { "dependent", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DEPENDENT }, .unit = "disposition" }, \
222 { "still_image", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_STILL_IMAGE }, .unit = "disposition" }
223
224 static const AVOption stream_options[] = {
225 DISPOSITION_OPT(AVStream),
226 { "discard", NULL, offsetof(AVStream, discard), AV_OPT_TYPE_INT, { .i64 = AVDISCARD_DEFAULT }, INT_MIN, INT_MAX,
227 .flags = AV_OPT_FLAG_DECODING_PARAM, .unit = "avdiscard" },
228 { "none", .type = AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_NONE }, .unit = "avdiscard" },
229 { "default", .type = AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_DEFAULT }, .unit = "avdiscard" },
230 { "noref", .type = AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_NONREF }, .unit = "avdiscard" },
231 { "bidir", .type = AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_BIDIR }, .unit = "avdiscard" },
232 { "nointra", .type = AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_NONINTRA }, .unit = "avdiscard" },
233 { "nokey", .type = AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_NONKEY }, .unit = "avdiscard" },
234 { "all", .type = AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_ALL }, .unit = "avdiscard" },
235 { NULL }
236 };
237
238 static const AVClass stream_class = {
239 .class_name = "AVStream",
240 .item_name = av_default_item_name,
241 .version = LIBAVUTIL_VERSION_INT,
242 .option = stream_options,
243 };
244
245 const AVClass *av_stream_get_class(void)
246 {
247 return &stream_class;
248 }
249
250 15083 AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c)
251 {
252 15083 FFFormatContext *const si = ffformatcontext(s);
253 FFStream *sti;
254 AVStream *st;
255 AVStream **streams;
256
257
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15083 times.
15083 if (s->nb_streams >= s->max_streams) {
258 av_log(s, AV_LOG_ERROR, "Number of streams exceeds max_streams parameter"
259 " (%d), see the documentation if you wish to increase it\n",
260 s->max_streams);
261 return NULL;
262 }
263 15083 streams = av_realloc_array(s->streams, s->nb_streams + 1, sizeof(*streams));
264
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15083 times.
15083 if (!streams)
265 return NULL;
266 15083 s->streams = streams;
267
268 15083 sti = av_mallocz(sizeof(*sti));
269
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15083 times.
15083 if (!sti)
270 return NULL;
271 15083 st = &sti->pub;
272
273 15083 st->av_class = &stream_class;
274 15083 st->codecpar = avcodec_parameters_alloc();
275
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15083 times.
15083 if (!st->codecpar)
276 goto fail;
277
278 15083 sti->fmtctx = s;
279
280
2/2
✓ Branch 0 taken 7888 times.
✓ Branch 1 taken 7195 times.
15083 if (s->iformat) {
281 7888 sti->avctx = avcodec_alloc_context3(NULL);
282
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7888 times.
7888 if (!sti->avctx)
283 goto fail;
284
285 7888 sti->info = av_mallocz(sizeof(*sti->info));
286
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7888 times.
7888 if (!sti->info)
287 goto fail;
288
289 #if FF_API_R_FRAME_RATE
290 7888 sti->info->last_dts = AV_NOPTS_VALUE;
291 #endif
292 7888 sti->info->fps_first_dts = AV_NOPTS_VALUE;
293 7888 sti->info->fps_last_dts = AV_NOPTS_VALUE;
294
295 /* default pts setting is MPEG-like */
296 7888 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 7888 sti->cur_dts = RELATIVE_TS_BASE;
302 } else {
303 7195 sti->cur_dts = AV_NOPTS_VALUE;
304 }
305
306 15083 st->index = s->nb_streams;
307 15083 st->start_time = AV_NOPTS_VALUE;
308 15083 st->duration = AV_NOPTS_VALUE;
309 15083 sti->first_dts = AV_NOPTS_VALUE;
310 15083 sti->probe_packets = s->max_probe_packets;
311 15083 sti->pts_wrap_reference = AV_NOPTS_VALUE;
312 15083 sti->pts_wrap_behavior = AV_PTS_WRAP_IGNORE;
313
314 15083 sti->last_IP_pts = AV_NOPTS_VALUE;
315 15083 sti->last_dts_for_order_check = AV_NOPTS_VALUE;
316
2/2
✓ Branch 0 taken 256411 times.
✓ Branch 1 taken 15083 times.
271494 for (int i = 0; i < MAX_REORDER_DELAY + 1; i++)
317 256411 sti->pts_buffer[i] = AV_NOPTS_VALUE;
318
319 15083 st->sample_aspect_ratio = (AVRational) { 0, 1 };
320 15083 sti->transferred_mux_tb = (AVRational) { 0, 1 };;
321
322 #if FF_API_AVSTREAM_SIDE_DATA
323 15083 sti->inject_global_side_data = si->inject_global_side_data;
324 #endif
325
326 15083 sti->need_context_update = 1;
327
328 15083 s->streams[s->nb_streams++] = st;
329 15083 return st;
330 fail:
331 ff_free_stream(&st);
332 return NULL;
333 }
334
335 #define FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM
336 #define OFFSET(x) offsetof(AVStreamGroupTileGrid, x)
337 static const AVOption tile_grid_options[] = {
338 { "grid_size", "size of the output canvas", OFFSET(coded_width),
339 AV_OPT_TYPE_IMAGE_SIZE, { .str = NULL }, 0, INT_MAX, FLAGS },
340 { "output_size", "size of valid pixels in output image meant for presentation", OFFSET(width),
341 AV_OPT_TYPE_IMAGE_SIZE, { .str = NULL }, 0, INT_MAX, FLAGS },
342 { "background_color", "set a background color for unused pixels",
343 OFFSET(background), AV_OPT_TYPE_COLOR, { .str = "black"}, 0, 0, FLAGS },
344 { "horizontal_offset", NULL, OFFSET(horizontal_offset), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS },
345 { "vertical_offset", NULL, OFFSET(vertical_offset), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS },
346 { NULL },
347 };
348 #undef FLAGS
349 #undef OFFSET
350
351 static const AVClass tile_grid_class = {
352 .class_name = "AVStreamGroupTileGrid",
353 .version = LIBAVUTIL_VERSION_INT,
354 .option = tile_grid_options,
355 };
356
357 112 static void *stream_group_child_next(void *obj, void *prev)
358 {
359 112 AVStreamGroup *stg = obj;
360
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 48 times.
112 if (!prev) {
361
2/4
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
64 switch(stg->type) {
362 32 case AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT:
363 32 return stg->params.iamf_audio_element;
364 32 case AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION:
365 32 return stg->params.iamf_mix_presentation;
366 case AV_STREAM_GROUP_PARAMS_TILE_GRID:
367 return stg->params.tile_grid;
368 default:
369 break;
370 }
371 }
372 48 return NULL;
373 }
374
375 static const AVClass *stream_group_child_iterate(void **opaque)
376 {
377 uintptr_t i = (uintptr_t)*opaque;
378 const AVClass *ret = NULL;
379
380 switch(i) {
381 case AV_STREAM_GROUP_PARAMS_NONE:
382 i++;
383 // fall-through
384 case AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT:
385 ret = av_iamf_audio_element_get_class();
386 break;
387 case AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION:
388 ret = av_iamf_mix_presentation_get_class();
389 break;
390 case AV_STREAM_GROUP_PARAMS_TILE_GRID:
391 ret = &tile_grid_class;
392 break;
393 default:
394 break;
395 }
396
397 if (ret)
398 *opaque = (void*)(i + 1);
399 return ret;
400 }
401
402 static const AVOption stream_group_options[] = {
403 DISPOSITION_OPT(AVStreamGroup),
404 {"id", "Set group id", offsetof(AVStreamGroup, id), AV_OPT_TYPE_INT64, {.i64 = 0}, 0, INT64_MAX, AV_OPT_FLAG_ENCODING_PARAM },
405 { NULL }
406 };
407
408 static const AVClass stream_group_class = {
409 .class_name = "AVStreamGroup",
410 .item_name = av_default_item_name,
411 .version = LIBAVUTIL_VERSION_INT,
412 .option = stream_group_options,
413 .child_next = stream_group_child_next,
414 .child_class_iterate = stream_group_child_iterate,
415 };
416
417 const AVClass *av_stream_group_get_class(void)
418 {
419 return &stream_group_class;
420 }
421
422 54 AVStreamGroup *avformat_stream_group_create(AVFormatContext *s,
423 enum AVStreamGroupParamsType type,
424 AVDictionary **options)
425 {
426 AVStreamGroup **stream_groups;
427 AVStreamGroup *stg;
428 FFStreamGroup *stgi;
429
430 54 stream_groups = av_realloc_array(s->stream_groups, s->nb_stream_groups + 1,
431 sizeof(*stream_groups));
432
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 54 times.
54 if (!stream_groups)
433 return NULL;
434 54 s->stream_groups = stream_groups;
435
436 54 stgi = av_mallocz(sizeof(*stgi));
437
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 54 times.
54 if (!stgi)
438 return NULL;
439 54 stg = &stgi->pub;
440
441 54 stg->av_class = &stream_group_class;
442 54 av_opt_set_defaults(stg);
443 54 stg->type = type;
444
3/4
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
54 switch (type) {
445 24 case AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT:
446 24 stg->params.iamf_audio_element = av_iamf_audio_element_alloc();
447
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if (!stg->params.iamf_audio_element)
448 goto fail;
449 24 break;
450 24 case AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION:
451 24 stg->params.iamf_mix_presentation = av_iamf_mix_presentation_alloc();
452
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if (!stg->params.iamf_mix_presentation)
453 goto fail;
454 24 break;
455 6 case AV_STREAM_GROUP_PARAMS_TILE_GRID:
456 6 stg->params.tile_grid = av_mallocz(sizeof(*stg->params.tile_grid));
457
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (!stg->params.tile_grid)
458 goto fail;
459 6 stg->params.tile_grid->av_class = &tile_grid_class;
460 6 av_opt_set_defaults(stg->params.tile_grid);
461 6 break;
462 default:
463 goto fail;
464 }
465
466
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 38 times.
54 if (options) {
467
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
16 if (av_opt_set_dict2(stg, options, AV_OPT_SEARCH_CHILDREN))
468 goto fail;
469 }
470
471 54 stgi->fmtctx = s;
472 54 stg->index = s->nb_stream_groups;
473
474 54 s->stream_groups[s->nb_stream_groups++] = stg;
475
476 54 return stg;
477 fail:
478 ff_free_stream_group(&stg);
479 return NULL;
480 }
481
482 230 static int stream_group_add_stream(AVStreamGroup *stg, AVStream *st)
483 {
484 230 AVStream **streams = av_realloc_array(stg->streams, stg->nb_streams + 1,
485 sizeof(*stg->streams));
486
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 230 times.
230 if (!streams)
487 return AVERROR(ENOMEM);
488
489 230 stg->streams = streams;
490 230 stg->streams[stg->nb_streams++] = st;
491
492 230 return 0;
493 }
494
495 236 int avformat_stream_group_add_stream(AVStreamGroup *stg, AVStream *st)
496 {
497 236 const FFStreamGroup *stgi = cffstreamgroup(stg);
498 236 const FFStream *sti = cffstream(st);
499
500
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 236 times.
236 if (stgi->fmtctx != sti->fmtctx)
501 return AVERROR(EINVAL);
502
503
2/2
✓ Branch 0 taken 524 times.
✓ Branch 1 taken 230 times.
754 for (int i = 0; i < stg->nb_streams; i++)
504
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 518 times.
524 if (stg->streams[i]->index == st->index)
505 6 return AVERROR(EEXIST);
506
507 230 return stream_group_add_stream(stg, st);
508 }
509
510 102600 static int option_is_disposition(const AVOption *opt)
511 {
512 196840 return opt->type == AV_OPT_TYPE_CONST &&
513
5/6
✓ Branch 0 taken 94240 times.
✓ Branch 1 taken 8360 times.
✓ Branch 2 taken 94240 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 76950 times.
✓ Branch 5 taken 17290 times.
102600 opt->unit && !strcmp(opt->unit, "disposition");
514 }
515
516 int av_disposition_from_string(const char *disp)
517 {
518 for (const AVOption *opt = stream_options; opt->name; opt++)
519 if (option_is_disposition(opt) && !strcmp(disp, opt->name))
520 return opt->default_val.i64;
521 return AVERROR(EINVAL);
522 }
523
524 6080 const char *av_disposition_to_string(int disposition)
525 {
526 int val;
527
528
2/2
✓ Branch 0 taken 190 times.
✓ Branch 1 taken 5890 times.
6080 if (disposition <= 0)
529 190 return NULL;
530
531 5890 val = 1 << ff_ctz(disposition);
532
2/2
✓ Branch 0 taken 102600 times.
✓ Branch 1 taken 2470 times.
105070 for (const AVOption *opt = stream_options; opt->name; opt++)
533
4/4
✓ Branch 1 taken 76950 times.
✓ Branch 2 taken 25650 times.
✓ Branch 3 taken 3420 times.
✓ Branch 4 taken 73530 times.
102600 if (option_is_disposition(opt) && opt->default_val.i64 == val)
534 3420 return opt->name;
535
536 2470 return NULL;
537 }
538