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 | 2538 | static const char* format_to_name(void* ptr) | |
45 | { | ||
46 | 2538 | AVFormatContext* fc = (AVFormatContext*) ptr; | |
47 |
2/2✓ Branch 0 taken 1631 times.
✓ Branch 1 taken 907 times.
|
2538 | if(fc->iformat) return fc->iformat->name; |
48 |
1/2✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
|
907 | else if(fc->oformat) return fc->oformat->name; |
49 | ✗ | else return fc->av_class->class_name; | |
50 | } | ||
51 | |||
52 | 53404 | static void *format_child_next(void *obj, void *prev) | |
53 | { | ||
54 | 53404 | AVFormatContext *s = obj; | |
55 |
4/4✓ Branch 0 taken 21646 times.
✓ Branch 1 taken 31758 times.
✓ Branch 2 taken 21178 times.
✓ Branch 3 taken 468 times.
|
53404 | if (!prev && s->priv_data && |
56 |
4/4✓ Branch 0 taken 21176 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2492 times.
✓ Branch 3 taken 18684 times.
|
21178 | ((s->iformat && s->iformat->priv_class) || |
57 |
3/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2492 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2494 | s->oformat && s->oformat->priv_class)) |
58 | 18686 | return s->priv_data; | |
59 |
6/6✓ Branch 0 taken 26504 times.
✓ Branch 1 taken 8214 times.
✓ Branch 2 taken 26492 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 13246 times.
✓ Branch 5 taken 13246 times.
|
34718 | if (s->pb && s->pb->av_class && prev != s->pb) |
60 | 13246 | return s->pb; | |
61 | 21472 | 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 | 21523657 | 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 | 21523657 | void *val = (void*)(((uintptr_t)*iter) & ((1 << ITER_STATE_SHIFT) - 1)); | |
79 | 21523657 | unsigned int state = ((uintptr_t)*iter) >> ITER_STATE_SHIFT; | |
80 | 21523657 | const AVClass *ret = NULL; | |
81 | |||
82 |
2/2✓ Branch 0 taken 90936 times.
✓ Branch 1 taken 21432721 times.
|
21523657 | if (state == CHILD_CLASS_ITER_AVIO) { |
83 | 90936 | ret = &ff_avio_class; | |
84 | 90936 | state++; | |
85 | 90936 | goto finish; | |
86 | } | ||
87 | |||
88 |
2/2✓ Branch 0 taken 6723640 times.
✓ Branch 1 taken 14709081 times.
|
21432721 | if (state == CHILD_CLASS_ITER_MUX) { |
89 | const AVOutputFormat *ofmt; | ||
90 | |||
91 |
2/2✓ Branch 1 taken 16900590 times.
✓ Branch 2 taken 90811 times.
|
16991401 | while ((ofmt = av_muxer_iterate(&val))) { |
92 | 16900590 | ret = ofmt->priv_class; | |
93 |
2/2✓ Branch 0 taken 6632829 times.
✓ Branch 1 taken 10267761 times.
|
16900590 | if (ret) |
94 | 6632829 | goto finish; | |
95 | } | ||
96 | |||
97 | 90811 | val = NULL; | |
98 | 90811 | state++; | |
99 | } | ||
100 | |||
101 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 14799892 times.
|
14799892 | if (state == CHILD_CLASS_ITER_DEMUX) { |
102 | const AVInputFormat *ifmt; | ||
103 | |||
104 |
2/2✓ Branch 1 taken 32778292 times.
✓ Branch 2 taken 90781 times.
|
32869073 | while ((ifmt = av_demuxer_iterate(&val))) { |
105 | 32778292 | ret = ifmt->priv_class; | |
106 |
2/2✓ Branch 0 taken 14709111 times.
✓ Branch 1 taken 18069181 times.
|
32778292 | if (ret) |
107 | 14709111 | goto finish; | |
108 | } | ||
109 | 90781 | val = NULL; | |
110 | 90781 | 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 21523657 times.
|
21523657 | av_assert0(!((uintptr_t)val >> ITER_STATE_SHIFT)); |
116 | 21523657 | *iter = (void*)((uintptr_t)val | (state << ITER_STATE_SHIFT)); | |
117 | 21523657 | return ret; | |
118 | } | ||
119 | |||
120 | 2538 | static AVClassCategory get_category(void *ptr) | |
121 | { | ||
122 | 2538 | AVFormatContext* s = ptr; | |
123 |
2/2✓ Branch 0 taken 1631 times.
✓ Branch 1 taken 907 times.
|
2538 | if(s->iformat) return AV_CLASS_CATEGORY_DEMUXER; |
124 | 907 | 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 | 94416 | 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 89955 times.
✓ Branch 1 taken 4461 times.
|
94416 | if (!strcmp(url, s->url) || |
144 |
4/4✓ Branch 0 taken 89146 times.
✓ Branch 1 taken 809 times.
✓ Branch 2 taken 62 times.
✓ Branch 3 taken 89084 times.
|
89955 | 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 | 94208 | loglevel = AV_LOG_DEBUG; | |
148 | } else | ||
149 | 208 | loglevel = AV_LOG_INFO; | |
150 | |||
151 |
2/2✓ Branch 0 taken 819 times.
✓ Branch 1 taken 93597 times.
|
94416 | av_log(s, loglevel, "Opening \'%s\' for %s\n", url, flags & AVIO_FLAG_WRITE ? "writing" : "reading"); |
152 | |||
153 | 94416 | return ffio_open_whitelist(pb, url, flags, &s->interrupt_callback, options, s->protocol_whitelist, s->protocol_blacklist); | |
154 | } | ||
155 | |||
156 | 89978 | static int io_close2_default(AVFormatContext *s, AVIOContext *pb) | |
157 | { | ||
158 | 89978 | return avio_close(pb); | |
159 | } | ||
160 | |||
161 | 14032 | AVFormatContext *avformat_alloc_context(void) | |
162 | { | ||
163 | 14032 | FFFormatContext *const si = av_mallocz(sizeof(*si)); | |
164 | AVFormatContext *s; | ||
165 | |||
166 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 14032 times.
|
14032 | if (!si) |
167 | ✗ | return NULL; | |
168 | |||
169 | 14032 | s = &si->pub; | |
170 | 14032 | s->av_class = &av_format_context_class; | |
171 | 14032 | s->io_open = io_open_default; | |
172 | 14032 | s->io_close2= io_close2_default; | |
173 | |||
174 | 14032 | av_opt_set_defaults(s); | |
175 | |||
176 | 14032 | si->pkt = av_packet_alloc(); | |
177 | 14032 | si->parse_pkt = av_packet_alloc(); | |
178 |
2/4✓ Branch 0 taken 14032 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 14032 times.
|
14032 | if (!si->pkt || !si->parse_pkt) { |
179 | ✗ | avformat_free_context(s); | |
180 | ✗ | return NULL; | |
181 | } | ||
182 | |||
183 | #if FF_API_LAVF_SHORTEST | ||
184 | 14032 | si->shortest_end = AV_NOPTS_VALUE; | |
185 | #endif | ||
186 | |||
187 | 14032 | 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 | 103719 | const AVClass *avformat_get_class(void) | |
198 | { | ||
199 | 103719 | 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 | { "multilayer", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_MULTILAYER }, .unit = "disposition" } | ||
224 | |||
225 | static const AVOption stream_options[] = { | ||
226 | DISPOSITION_OPT(AVStream), | ||
227 | { "discard", NULL, offsetof(AVStream, discard), AV_OPT_TYPE_INT, { .i64 = AVDISCARD_DEFAULT }, INT_MIN, INT_MAX, | ||
228 | .flags = AV_OPT_FLAG_DECODING_PARAM, .unit = "avdiscard" }, | ||
229 | { "none", .type = AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_NONE }, .unit = "avdiscard" }, | ||
230 | { "default", .type = AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_DEFAULT }, .unit = "avdiscard" }, | ||
231 | { "noref", .type = AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_NONREF }, .unit = "avdiscard" }, | ||
232 | { "bidir", .type = AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_BIDIR }, .unit = "avdiscard" }, | ||
233 | { "nointra", .type = AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_NONINTRA }, .unit = "avdiscard" }, | ||
234 | { "nokey", .type = AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_NONKEY }, .unit = "avdiscard" }, | ||
235 | { "all", .type = AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_ALL }, .unit = "avdiscard" }, | ||
236 | { NULL } | ||
237 | }; | ||
238 | |||
239 | static const AVClass stream_class = { | ||
240 | .class_name = "AVStream", | ||
241 | .item_name = av_default_item_name, | ||
242 | .version = LIBAVUTIL_VERSION_INT, | ||
243 | .option = stream_options, | ||
244 | }; | ||
245 | |||
246 | ✗ | const AVClass *av_stream_get_class(void) | |
247 | { | ||
248 | ✗ | return &stream_class; | |
249 | } | ||
250 | |||
251 | 15158 | AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c) | |
252 | { | ||
253 | 15158 | FFFormatContext *const si = ffformatcontext(s); | |
254 | FFStream *sti; | ||
255 | AVStream *st; | ||
256 | AVStream **streams; | ||
257 | |||
258 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15158 times.
|
15158 | if (s->nb_streams >= s->max_streams) { |
259 | ✗ | av_log(s, AV_LOG_ERROR, "Number of streams exceeds max_streams parameter" | |
260 | " (%d), see the documentation if you wish to increase it\n", | ||
261 | s->max_streams); | ||
262 | ✗ | return NULL; | |
263 | } | ||
264 | 15158 | streams = av_realloc_array(s->streams, s->nb_streams + 1, sizeof(*streams)); | |
265 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15158 times.
|
15158 | if (!streams) |
266 | ✗ | return NULL; | |
267 | 15158 | s->streams = streams; | |
268 | |||
269 | 15158 | sti = av_mallocz(sizeof(*sti)); | |
270 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15158 times.
|
15158 | if (!sti) |
271 | ✗ | return NULL; | |
272 | 15158 | st = &sti->pub; | |
273 | |||
274 | 15158 | st->av_class = &stream_class; | |
275 | 15158 | st->codecpar = avcodec_parameters_alloc(); | |
276 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15158 times.
|
15158 | if (!st->codecpar) |
277 | ✗ | goto fail; | |
278 | |||
279 | 15158 | sti->fmtctx = s; | |
280 | |||
281 |
2/2✓ Branch 0 taken 7930 times.
✓ Branch 1 taken 7228 times.
|
15158 | if (s->iformat) { |
282 | 7930 | sti->avctx = avcodec_alloc_context3(NULL); | |
283 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7930 times.
|
7930 | if (!sti->avctx) |
284 | ✗ | goto fail; | |
285 | |||
286 | 7930 | sti->info = av_mallocz(sizeof(*sti->info)); | |
287 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7930 times.
|
7930 | if (!sti->info) |
288 | ✗ | goto fail; | |
289 | |||
290 | #if FF_API_R_FRAME_RATE | ||
291 | 7930 | sti->info->last_dts = AV_NOPTS_VALUE; | |
292 | #endif | ||
293 | 7930 | sti->info->fps_first_dts = AV_NOPTS_VALUE; | |
294 | 7930 | sti->info->fps_last_dts = AV_NOPTS_VALUE; | |
295 | |||
296 | /* default pts setting is MPEG-like */ | ||
297 | 7930 | avpriv_set_pts_info(st, 33, 1, 90000); | |
298 | /* we set the current DTS to 0 so that formats without any timestamps | ||
299 | * but durations get some timestamps, formats with some unknown | ||
300 | * timestamps have their first few packets buffered and the | ||
301 | * timestamps corrected before they are returned to the user */ | ||
302 | 7930 | sti->cur_dts = RELATIVE_TS_BASE; | |
303 | } else { | ||
304 | 7228 | sti->cur_dts = AV_NOPTS_VALUE; | |
305 | } | ||
306 | |||
307 | 15158 | st->index = s->nb_streams; | |
308 | 15158 | st->start_time = AV_NOPTS_VALUE; | |
309 | 15158 | st->duration = AV_NOPTS_VALUE; | |
310 | 15158 | sti->first_dts = AV_NOPTS_VALUE; | |
311 | 15158 | sti->probe_packets = s->max_probe_packets; | |
312 | 15158 | sti->pts_wrap_reference = AV_NOPTS_VALUE; | |
313 | 15158 | sti->pts_wrap_behavior = AV_PTS_WRAP_IGNORE; | |
314 | |||
315 | 15158 | sti->last_IP_pts = AV_NOPTS_VALUE; | |
316 | 15158 | sti->last_dts_for_order_check = AV_NOPTS_VALUE; | |
317 |
2/2✓ Branch 0 taken 257686 times.
✓ Branch 1 taken 15158 times.
|
272844 | for (int i = 0; i < MAX_REORDER_DELAY + 1; i++) |
318 | 257686 | sti->pts_buffer[i] = AV_NOPTS_VALUE; | |
319 | |||
320 | 15158 | st->sample_aspect_ratio = (AVRational) { 0, 1 }; | |
321 | #if FF_API_INTERNAL_TIMING | ||
322 | 15158 | sti->transferred_mux_tb = (AVRational) { 0, 1 };; | |
323 | #endif | ||
324 | |||
325 | #if FF_API_AVSTREAM_SIDE_DATA | ||
326 | 15158 | sti->inject_global_side_data = si->inject_global_side_data; | |
327 | #endif | ||
328 | |||
329 | 15158 | sti->need_context_update = 1; | |
330 | |||
331 | 15158 | s->streams[s->nb_streams++] = st; | |
332 | 15158 | return st; | |
333 | ✗ | fail: | |
334 | ✗ | ff_free_stream(&st); | |
335 | ✗ | return NULL; | |
336 | } | ||
337 | |||
338 | #define FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM | ||
339 | #define OFFSET(x) offsetof(AVStreamGroupTileGrid, x) | ||
340 | static const AVOption tile_grid_options[] = { | ||
341 | { "grid_size", "size of the output canvas", OFFSET(coded_width), | ||
342 | AV_OPT_TYPE_IMAGE_SIZE, { .str = NULL }, 0, INT_MAX, FLAGS }, | ||
343 | { "output_size", "size of valid pixels in output image meant for presentation", OFFSET(width), | ||
344 | AV_OPT_TYPE_IMAGE_SIZE, { .str = NULL }, 0, INT_MAX, FLAGS }, | ||
345 | { "background_color", "set a background color for unused pixels", | ||
346 | OFFSET(background), AV_OPT_TYPE_COLOR, { .str = "black"}, 0, 0, FLAGS }, | ||
347 | { "horizontal_offset", NULL, OFFSET(horizontal_offset), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS }, | ||
348 | { "vertical_offset", NULL, OFFSET(vertical_offset), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS }, | ||
349 | { NULL }, | ||
350 | }; | ||
351 | #undef FLAGS | ||
352 | #undef OFFSET | ||
353 | |||
354 | static const AVClass tile_grid_class = { | ||
355 | .class_name = "AVStreamGroupTileGrid", | ||
356 | .version = LIBAVUTIL_VERSION_INT, | ||
357 | .option = tile_grid_options, | ||
358 | }; | ||
359 | |||
360 | 133 | static void *stream_group_child_next(void *obj, void *prev) | |
361 | { | ||
362 | 133 | AVStreamGroup *stg = obj; | |
363 |
2/2✓ Branch 0 taken 75 times.
✓ Branch 1 taken 58 times.
|
133 | if (!prev) { |
364 |
2/4✓ Branch 0 taken 37 times.
✓ Branch 1 taken 38 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
75 | switch(stg->type) { |
365 | 37 | case AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT: | |
366 | 37 | return stg->params.iamf_audio_element; | |
367 | 38 | case AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION: | |
368 | 38 | return stg->params.iamf_mix_presentation; | |
369 | ✗ | case AV_STREAM_GROUP_PARAMS_TILE_GRID: | |
370 | ✗ | return stg->params.tile_grid; | |
371 | ✗ | default: | |
372 | ✗ | break; | |
373 | } | ||
374 | } | ||
375 | 58 | return NULL; | |
376 | } | ||
377 | |||
378 | ✗ | static const AVClass *stream_group_child_iterate(void **opaque) | |
379 | { | ||
380 | ✗ | uintptr_t i = (uintptr_t)*opaque; | |
381 | ✗ | const AVClass *ret = NULL; | |
382 | |||
383 | ✗ | switch(i) { | |
384 | ✗ | case AV_STREAM_GROUP_PARAMS_NONE: | |
385 | ✗ | i++; | |
386 | // fall-through | ||
387 | ✗ | case AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT: | |
388 | ✗ | ret = av_iamf_audio_element_get_class(); | |
389 | ✗ | break; | |
390 | ✗ | case AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION: | |
391 | ✗ | ret = av_iamf_mix_presentation_get_class(); | |
392 | ✗ | break; | |
393 | ✗ | case AV_STREAM_GROUP_PARAMS_TILE_GRID: | |
394 | ✗ | ret = &tile_grid_class; | |
395 | ✗ | break; | |
396 | ✗ | default: | |
397 | ✗ | break; | |
398 | } | ||
399 | |||
400 | ✗ | if (ret) | |
401 | ✗ | *opaque = (void*)(i + 1); | |
402 | ✗ | return ret; | |
403 | } | ||
404 | |||
405 | static const AVOption stream_group_options[] = { | ||
406 | DISPOSITION_OPT(AVStreamGroup), | ||
407 | {"id", "Set group id", offsetof(AVStreamGroup, id), AV_OPT_TYPE_INT64, {.i64 = 0}, 0, INT64_MAX, AV_OPT_FLAG_ENCODING_PARAM }, | ||
408 | { NULL } | ||
409 | }; | ||
410 | |||
411 | static const AVClass stream_group_class = { | ||
412 | .class_name = "AVStreamGroup", | ||
413 | .item_name = av_default_item_name, | ||
414 | .version = LIBAVUTIL_VERSION_INT, | ||
415 | .option = stream_group_options, | ||
416 | .child_next = stream_group_child_next, | ||
417 | .child_class_iterate = stream_group_child_iterate, | ||
418 | }; | ||
419 | |||
420 | ✗ | const AVClass *av_stream_group_get_class(void) | |
421 | { | ||
422 | ✗ | return &stream_group_class; | |
423 | } | ||
424 | |||
425 | 66 | AVStreamGroup *avformat_stream_group_create(AVFormatContext *s, | |
426 | enum AVStreamGroupParamsType type, | ||
427 | AVDictionary **options) | ||
428 | { | ||
429 | AVStreamGroup **stream_groups; | ||
430 | AVStreamGroup *stg; | ||
431 | FFStreamGroup *stgi; | ||
432 | |||
433 | 66 | stream_groups = av_realloc_array(s->stream_groups, s->nb_stream_groups + 1, | |
434 | sizeof(*stream_groups)); | ||
435 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
|
66 | if (!stream_groups) |
436 | ✗ | return NULL; | |
437 | 66 | s->stream_groups = stream_groups; | |
438 | |||
439 | 66 | stgi = av_mallocz(sizeof(*stgi)); | |
440 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
|
66 | if (!stgi) |
441 | ✗ | return NULL; | |
442 | 66 | stg = &stgi->pub; | |
443 | |||
444 | 66 | stg->av_class = &stream_group_class; | |
445 | 66 | av_opt_set_defaults(stg); | |
446 | 66 | stg->type = type; | |
447 |
3/4✓ Branch 0 taken 30 times.
✓ Branch 1 taken 30 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
66 | switch (type) { |
448 | 30 | case AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT: | |
449 | 30 | stg->params.iamf_audio_element = av_iamf_audio_element_alloc(); | |
450 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
|
30 | if (!stg->params.iamf_audio_element) |
451 | ✗ | goto fail; | |
452 | 30 | break; | |
453 | 30 | case AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION: | |
454 | 30 | stg->params.iamf_mix_presentation = av_iamf_mix_presentation_alloc(); | |
455 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
|
30 | if (!stg->params.iamf_mix_presentation) |
456 | ✗ | goto fail; | |
457 | 30 | break; | |
458 | 6 | case AV_STREAM_GROUP_PARAMS_TILE_GRID: | |
459 | 6 | stg->params.tile_grid = av_mallocz(sizeof(*stg->params.tile_grid)); | |
460 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | if (!stg->params.tile_grid) |
461 | ✗ | goto fail; | |
462 | 6 | stg->params.tile_grid->av_class = &tile_grid_class; | |
463 | 6 | av_opt_set_defaults(stg->params.tile_grid); | |
464 | 6 | break; | |
465 | ✗ | default: | |
466 | ✗ | goto fail; | |
467 | } | ||
468 | |||
469 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 48 times.
|
66 | if (options) { |
470 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
|
18 | if (av_opt_set_dict2(stg, options, AV_OPT_SEARCH_CHILDREN)) |
471 | ✗ | goto fail; | |
472 | } | ||
473 | |||
474 | 66 | stgi->fmtctx = s; | |
475 | 66 | stg->index = s->nb_stream_groups; | |
476 | |||
477 | 66 | s->stream_groups[s->nb_stream_groups++] = stg; | |
478 | |||
479 | 66 | return stg; | |
480 | ✗ | fail: | |
481 | ✗ | ff_free_stream_group(&stg); | |
482 | ✗ | return NULL; | |
483 | } | ||
484 | |||
485 | 278 | static int stream_group_add_stream(AVStreamGroup *stg, AVStream *st) | |
486 | { | ||
487 | 278 | AVStream **streams = av_realloc_array(stg->streams, stg->nb_streams + 1, | |
488 | sizeof(*stg->streams)); | ||
489 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 278 times.
|
278 | if (!streams) |
490 | ✗ | return AVERROR(ENOMEM); | |
491 | |||
492 | 278 | stg->streams = streams; | |
493 | 278 | stg->streams[stg->nb_streams++] = st; | |
494 | |||
495 | 278 | return 0; | |
496 | } | ||
497 | |||
498 | 284 | int avformat_stream_group_add_stream(AVStreamGroup *stg, AVStream *st) | |
499 | { | ||
500 | 284 | const FFStreamGroup *stgi = cffstreamgroup(stg); | |
501 | 284 | const FFStream *sti = cffstream(st); | |
502 | |||
503 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 284 times.
|
284 | if (stgi->fmtctx != sti->fmtctx) |
504 | ✗ | return AVERROR(EINVAL); | |
505 | |||
506 |
2/2✓ Branch 0 taken 596 times.
✓ Branch 1 taken 278 times.
|
874 | for (int i = 0; i < stg->nb_streams; i++) |
507 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 590 times.
|
596 | if (stg->streams[i]->index == st->index) |
508 | 6 | return AVERROR(EEXIST); | |
509 | |||
510 | 278 | return stream_group_add_stream(stg, st); | |
511 | } | ||
512 | |||
513 | 112270 | static int option_is_disposition(const AVOption *opt) | |
514 | { | ||
515 | 215682 | return opt->type == AV_OPT_TYPE_CONST && | |
516 |
5/6✓ Branch 0 taken 103412 times.
✓ Branch 1 taken 8858 times.
✓ Branch 2 taken 103412 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 86108 times.
✓ Branch 5 taken 17304 times.
|
112270 | opt->unit && !strcmp(opt->unit, "disposition"); |
517 | } | ||
518 | |||
519 | ✗ | int av_disposition_from_string(const char *disp) | |
520 | { | ||
521 | ✗ | for (const AVOption *opt = stream_options; opt->name; opt++) | |
522 | ✗ | if (option_is_disposition(opt) && !strcmp(disp, opt->name)) | |
523 | ✗ | return opt->default_val.i64; | |
524 | ✗ | return AVERROR(EINVAL); | |
525 | } | ||
526 | |||
527 | 6592 | const char *av_disposition_to_string(int disposition) | |
528 | { | ||
529 | int val; | ||
530 | |||
531 |
2/2✓ Branch 0 taken 206 times.
✓ Branch 1 taken 6386 times.
|
6592 | if (disposition <= 0) |
532 | 206 | return NULL; | |
533 | |||
534 | 6386 | val = 1 << ff_ctz(disposition); | |
535 |
2/2✓ Branch 0 taken 112270 times.
✓ Branch 1 taken 2472 times.
|
114742 | for (const AVOption *opt = stream_options; opt->name; opt++) |
536 |
4/4✓ Branch 1 taken 86108 times.
✓ Branch 2 taken 26162 times.
✓ Branch 3 taken 3914 times.
✓ Branch 4 taken 82194 times.
|
112270 | if (option_is_disposition(opt) && opt->default_val.i64 == val) |
537 | 3914 | return opt->name; | |
538 | |||
539 | 2472 | return NULL; | |
540 | } | ||
541 |