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 | 2428 | static const char* format_to_name(void* ptr) | |
45 | { | ||
46 | 2428 | AVFormatContext* fc = (AVFormatContext*) ptr; | |
47 |
2/2✓ Branch 0 taken 1629 times.
✓ Branch 1 taken 799 times.
|
2428 | 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 | 53236 | static void *format_child_next(void *obj, void *prev) | |
53 | { | ||
54 | 53236 | AVFormatContext *s = obj; | |
55 |
4/4✓ Branch 0 taken 21586 times.
✓ Branch 1 taken 31650 times.
✓ Branch 2 taken 21118 times.
✓ Branch 3 taken 468 times.
|
53236 | if (!prev && s->priv_data && |
56 |
4/4✓ Branch 0 taken 21116 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2492 times.
✓ Branch 3 taken 18624 times.
|
21118 | ((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 | 18626 | return s->priv_data; | |
59 |
6/6✓ Branch 0 taken 26408 times.
✓ Branch 1 taken 8202 times.
✓ Branch 2 taken 26396 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 13198 times.
✓ Branch 5 taken 13198 times.
|
34610 | if (s->pb && s->pb->av_class && prev != s->pb) |
60 | 13198 | return s->pb; | |
61 | 21412 | 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 | 21658494 | 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 | 21658494 | void *val = (void*)(((uintptr_t)*iter) & ((1 << ITER_STATE_SHIFT) - 1)); | |
79 | 21658494 | unsigned int state = ((uintptr_t)*iter) >> ITER_STATE_SHIFT; | |
80 | 21658494 | const AVClass *ret = NULL; | |
81 | |||
82 |
2/2✓ Branch 0 taken 91504 times.
✓ Branch 1 taken 21566990 times.
|
21658494 | if (state == CHILD_CLASS_ITER_AVIO) { |
83 | 91504 | ret = &ff_avio_class; | |
84 | 91504 | state++; | |
85 | 91504 | goto finish; | |
86 | } | ||
87 | |||
88 |
2/2✓ Branch 0 taken 6765731 times.
✓ Branch 1 taken 14801259 times.
|
21566990 | if (state == CHILD_CLASS_ITER_MUX) { |
89 | const AVOutputFormat *ofmt; | ||
90 | |||
91 |
2/2✓ Branch 1 taken 17006381 times.
✓ Branch 2 taken 91380 times.
|
17097761 | while ((ofmt = av_muxer_iterate(&val))) { |
92 | 17006381 | ret = ofmt->priv_class; | |
93 |
2/2✓ Branch 0 taken 6674351 times.
✓ Branch 1 taken 10332030 times.
|
17006381 | if (ret) |
94 | 6674351 | goto finish; | |
95 | } | ||
96 | |||
97 | 91380 | val = NULL; | |
98 | 91380 | state++; | |
99 | } | ||
100 | |||
101 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 14892639 times.
|
14892639 | if (state == CHILD_CLASS_ITER_DEMUX) { |
102 | const AVInputFormat *ifmt; | ||
103 | |||
104 |
2/2✓ Branch 1 taken 32983701 times.
✓ Branch 2 taken 91350 times.
|
33075051 | while ((ifmt = av_demuxer_iterate(&val))) { |
105 | 32983701 | ret = ifmt->priv_class; | |
106 |
2/2✓ Branch 0 taken 14801289 times.
✓ Branch 1 taken 18182412 times.
|
32983701 | if (ret) |
107 | 14801289 | goto finish; | |
108 | } | ||
109 | 91350 | val = NULL; | |
110 | 91350 | 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 21658494 times.
|
21658494 | av_assert0(!((uintptr_t)val >> ITER_STATE_SHIFT)); |
116 | 21658494 | *iter = (void*)((uintptr_t)val | (state << ITER_STATE_SHIFT)); | |
117 | 21658494 | return ret; | |
118 | } | ||
119 | |||
120 | 2428 | static AVClassCategory get_category(void *ptr) | |
121 | { | ||
122 | 2428 | AVFormatContext* s = ptr; | |
123 |
2/2✓ Branch 0 taken 1629 times.
✓ Branch 1 taken 799 times.
|
2428 | 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 | 94210 | 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 89765 times.
✓ Branch 1 taken 4445 times.
|
94210 | if (!strcmp(url, s->url) || |
144 |
4/4✓ Branch 0 taken 88956 times.
✓ Branch 1 taken 809 times.
✓ Branch 2 taken 62 times.
✓ Branch 3 taken 88894 times.
|
89765 | 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 | 94002 | loglevel = AV_LOG_DEBUG; | |
148 | } else | ||
149 | 208 | loglevel = AV_LOG_INFO; | |
150 | |||
151 |
2/2✓ Branch 0 taken 819 times.
✓ Branch 1 taken 93391 times.
|
94210 | av_log(s, loglevel, "Opening \'%s\' for %s\n", url, flags & AVIO_FLAG_WRITE ? "writing" : "reading"); |
152 | |||
153 | 94210 | return ffio_open_whitelist(pb, url, flags, &s->interrupt_callback, options, s->protocol_whitelist, s->protocol_blacklist); | |
154 | } | ||
155 | |||
156 | 89788 | static int io_close2_default(AVFormatContext *s, AVIOContext *pb) | |
157 | { | ||
158 | 89788 | return avio_close(pb); | |
159 | } | ||
160 | |||
161 | 13993 | AVFormatContext *avformat_alloc_context(void) | |
162 | { | ||
163 | 13993 | FFFormatContext *const si = av_mallocz(sizeof(*si)); | |
164 | AVFormatContext *s; | ||
165 | |||
166 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 13993 times.
|
13993 | if (!si) |
167 | ✗ | return NULL; | |
168 | |||
169 | 13993 | s = &si->pub; | |
170 | 13993 | s->av_class = &av_format_context_class; | |
171 | 13993 | s->io_open = io_open_default; | |
172 | 13993 | s->io_close2= io_close2_default; | |
173 | |||
174 | 13993 | av_opt_set_defaults(s); | |
175 | |||
176 | 13993 | si->pkt = av_packet_alloc(); | |
177 | 13993 | si->parse_pkt = av_packet_alloc(); | |
178 |
2/4✓ Branch 0 taken 13993 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 13993 times.
|
13993 | if (!si->pkt || !si->parse_pkt) { |
179 | ✗ | avformat_free_context(s); | |
180 | ✗ | return NULL; | |
181 | } | ||
182 | |||
183 | #if FF_API_LAVF_SHORTEST | ||
184 | 13993 | si->shortest_end = AV_NOPTS_VALUE; | |
185 | #endif | ||
186 | |||
187 | 13993 | 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 | 97162 | const AVClass *avformat_get_class(void) | |
198 | { | ||
199 | 97162 | 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 | 15115 | AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c) | |
251 | { | ||
252 | 15115 | 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 15115 times.
|
15115 | 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 | 15115 | streams = av_realloc_array(s->streams, s->nb_streams + 1, sizeof(*streams)); | |
264 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15115 times.
|
15115 | if (!streams) |
265 | ✗ | return NULL; | |
266 | 15115 | s->streams = streams; | |
267 | |||
268 | 15115 | sti = av_mallocz(sizeof(*sti)); | |
269 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15115 times.
|
15115 | if (!sti) |
270 | ✗ | return NULL; | |
271 | 15115 | st = &sti->pub; | |
272 | |||
273 | 15115 | st->av_class = &stream_class; | |
274 | 15115 | st->codecpar = avcodec_parameters_alloc(); | |
275 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15115 times.
|
15115 | if (!st->codecpar) |
276 | ✗ | goto fail; | |
277 | |||
278 | 15115 | sti->fmtctx = s; | |
279 | |||
280 |
2/2✓ Branch 0 taken 7908 times.
✓ Branch 1 taken 7207 times.
|
15115 | if (s->iformat) { |
281 | 7908 | sti->avctx = avcodec_alloc_context3(NULL); | |
282 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7908 times.
|
7908 | if (!sti->avctx) |
283 | ✗ | goto fail; | |
284 | |||
285 | 7908 | sti->info = av_mallocz(sizeof(*sti->info)); | |
286 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7908 times.
|
7908 | if (!sti->info) |
287 | ✗ | goto fail; | |
288 | |||
289 | #if FF_API_R_FRAME_RATE | ||
290 | 7908 | sti->info->last_dts = AV_NOPTS_VALUE; | |
291 | #endif | ||
292 | 7908 | sti->info->fps_first_dts = AV_NOPTS_VALUE; | |
293 | 7908 | sti->info->fps_last_dts = AV_NOPTS_VALUE; | |
294 | |||
295 | /* default pts setting is MPEG-like */ | ||
296 | 7908 | 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 | 7908 | sti->cur_dts = RELATIVE_TS_BASE; | |
302 | } else { | ||
303 | 7207 | sti->cur_dts = AV_NOPTS_VALUE; | |
304 | } | ||
305 | |||
306 | 15115 | st->index = s->nb_streams; | |
307 | 15115 | st->start_time = AV_NOPTS_VALUE; | |
308 | 15115 | st->duration = AV_NOPTS_VALUE; | |
309 | 15115 | sti->first_dts = AV_NOPTS_VALUE; | |
310 | 15115 | sti->probe_packets = s->max_probe_packets; | |
311 | 15115 | sti->pts_wrap_reference = AV_NOPTS_VALUE; | |
312 | 15115 | sti->pts_wrap_behavior = AV_PTS_WRAP_IGNORE; | |
313 | |||
314 | 15115 | sti->last_IP_pts = AV_NOPTS_VALUE; | |
315 | 15115 | sti->last_dts_for_order_check = AV_NOPTS_VALUE; | |
316 |
2/2✓ Branch 0 taken 256955 times.
✓ Branch 1 taken 15115 times.
|
272070 | for (int i = 0; i < MAX_REORDER_DELAY + 1; i++) |
317 | 256955 | sti->pts_buffer[i] = AV_NOPTS_VALUE; | |
318 | |||
319 | 15115 | st->sample_aspect_ratio = (AVRational) { 0, 1 }; | |
320 | 15115 | sti->transferred_mux_tb = (AVRational) { 0, 1 };; | |
321 | |||
322 | #if FF_API_AVSTREAM_SIDE_DATA | ||
323 | 15115 | sti->inject_global_side_data = si->inject_global_side_data; | |
324 | #endif | ||
325 | |||
326 | 15115 | sti->need_context_update = 1; | |
327 | |||
328 | 15115 | s->streams[s->nb_streams++] = st; | |
329 | 15115 | 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 | 133 | static void *stream_group_child_next(void *obj, void *prev) | |
358 | { | ||
359 | 133 | AVStreamGroup *stg = obj; | |
360 |
2/2✓ Branch 0 taken 75 times.
✓ Branch 1 taken 58 times.
|
133 | if (!prev) { |
361 |
2/4✓ Branch 0 taken 37 times.
✓ Branch 1 taken 38 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
75 | switch(stg->type) { |
362 | 37 | case AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT: | |
363 | 37 | return stg->params.iamf_audio_element; | |
364 | 38 | case AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION: | |
365 | 38 | 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 | 58 | 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 | 66 | 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 | 66 | 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 66 times.
|
66 | if (!stream_groups) |
433 | ✗ | return NULL; | |
434 | 66 | s->stream_groups = stream_groups; | |
435 | |||
436 | 66 | stgi = av_mallocz(sizeof(*stgi)); | |
437 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
|
66 | if (!stgi) |
438 | ✗ | return NULL; | |
439 | 66 | stg = &stgi->pub; | |
440 | |||
441 | 66 | stg->av_class = &stream_group_class; | |
442 | 66 | av_opt_set_defaults(stg); | |
443 | 66 | stg->type = type; | |
444 |
3/4✓ Branch 0 taken 30 times.
✓ Branch 1 taken 30 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
66 | switch (type) { |
445 | 30 | case AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT: | |
446 | 30 | stg->params.iamf_audio_element = av_iamf_audio_element_alloc(); | |
447 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
|
30 | if (!stg->params.iamf_audio_element) |
448 | ✗ | goto fail; | |
449 | 30 | break; | |
450 | 30 | case AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION: | |
451 | 30 | stg->params.iamf_mix_presentation = av_iamf_mix_presentation_alloc(); | |
452 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
|
30 | if (!stg->params.iamf_mix_presentation) |
453 | ✗ | goto fail; | |
454 | 30 | 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 18 times.
✓ Branch 1 taken 48 times.
|
66 | if (options) { |
467 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
|
18 | if (av_opt_set_dict2(stg, options, AV_OPT_SEARCH_CHILDREN)) |
468 | ✗ | goto fail; | |
469 | } | ||
470 | |||
471 | 66 | stgi->fmtctx = s; | |
472 | 66 | stg->index = s->nb_stream_groups; | |
473 | |||
474 | 66 | s->stream_groups[s->nb_stream_groups++] = stg; | |
475 | |||
476 | 66 | return stg; | |
477 | ✗ | fail: | |
478 | ✗ | ff_free_stream_group(&stg); | |
479 | ✗ | return NULL; | |
480 | } | ||
481 | |||
482 | 278 | static int stream_group_add_stream(AVStreamGroup *stg, AVStream *st) | |
483 | { | ||
484 | 278 | 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 278 times.
|
278 | if (!streams) |
487 | ✗ | return AVERROR(ENOMEM); | |
488 | |||
489 | 278 | stg->streams = streams; | |
490 | 278 | stg->streams[stg->nb_streams++] = st; | |
491 | |||
492 | 278 | return 0; | |
493 | } | ||
494 | |||
495 | 284 | int avformat_stream_group_add_stream(AVStreamGroup *stg, AVStream *st) | |
496 | { | ||
497 | 284 | const FFStreamGroup *stgi = cffstreamgroup(stg); | |
498 | 284 | const FFStream *sti = cffstream(st); | |
499 | |||
500 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 284 times.
|
284 | if (stgi->fmtctx != sti->fmtctx) |
501 | ✗ | return AVERROR(EINVAL); | |
502 | |||
503 |
2/2✓ Branch 0 taken 596 times.
✓ Branch 1 taken 278 times.
|
874 | for (int i = 0; i < stg->nb_streams; i++) |
504 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 590 times.
|
596 | if (stg->streams[i]->index == st->index) |
505 | 6 | return AVERROR(EEXIST); | |
506 | |||
507 | 278 | return stream_group_add_stream(stg, st); | |
508 | } | ||
509 | |||
510 | 111240 | static int option_is_disposition(const AVOption *opt) | |
511 | { | ||
512 | 213416 | return opt->type == AV_OPT_TYPE_CONST && | |
513 |
5/6✓ Branch 0 taken 102176 times.
✓ Branch 1 taken 9064 times.
✓ Branch 2 taken 102176 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 83430 times.
✓ Branch 5 taken 18746 times.
|
111240 | 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 | 6592 | const char *av_disposition_to_string(int disposition) | |
525 | { | ||
526 | int val; | ||
527 | |||
528 |
2/2✓ Branch 0 taken 206 times.
✓ Branch 1 taken 6386 times.
|
6592 | if (disposition <= 0) |
529 | 206 | return NULL; | |
530 | |||
531 | 6386 | val = 1 << ff_ctz(disposition); | |
532 |
2/2✓ Branch 0 taken 111240 times.
✓ Branch 1 taken 2678 times.
|
113918 | for (const AVOption *opt = stream_options; opt->name; opt++) |
533 |
4/4✓ Branch 1 taken 83430 times.
✓ Branch 2 taken 27810 times.
✓ Branch 3 taken 3708 times.
✓ Branch 4 taken 79722 times.
|
111240 | if (option_is_disposition(opt) && opt->default_val.i64 == val) |
534 | 3708 | return opt->name; | |
535 | |||
536 | 2678 | return NULL; | |
537 | } | ||
538 |