| 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 | 2813 | static const char* format_to_name(void* ptr) | |
| 47 | { | ||
| 48 | 2813 | AVFormatContext* fc = (AVFormatContext*) ptr; | |
| 49 |
2/2✓ Branch 0 taken 1624 times.
✓ Branch 1 taken 1189 times.
|
2813 | if (fc->name) return fc->name; |
| 50 |
2/2✓ Branch 0 taken 171 times.
✓ Branch 1 taken 1018 times.
|
1189 | else if(fc->iformat) return fc->iformat->name; |
| 51 |
2/2✓ Branch 0 taken 1017 times.
✓ Branch 1 taken 1 times.
|
1018 | else if(fc->oformat) return fc->oformat->name; |
| 52 | 1 | else return fc->av_class->class_name; | |
| 53 | } | ||
| 54 | |||
| 55 | 60228 | static void *format_child_next(void *obj, void *prev) | |
| 56 | { | ||
| 57 | 60228 | AVFormatContext *s = obj; | |
| 58 |
4/4✓ Branch 0 taken 24580 times.
✓ Branch 1 taken 35648 times.
✓ Branch 2 taken 24089 times.
✓ Branch 3 taken 491 times.
|
60228 | if (!prev && s->priv_data && |
| 59 |
4/4✓ Branch 0 taken 24087 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2885 times.
✓ Branch 3 taken 21202 times.
|
24089 | ((s->iformat && s->iformat->priv_class) || |
| 60 |
3/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2885 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2887 | s->oformat && s->oformat->priv_class)) |
| 61 | 21204 | return s->priv_data; | |
| 62 |
6/6✓ Branch 0 taken 29433 times.
✓ Branch 1 taken 9591 times.
✓ Branch 2 taken 29416 times.
✓ Branch 3 taken 17 times.
✓ Branch 4 taken 14708 times.
✓ Branch 5 taken 14708 times.
|
39024 | if (s->pb && s->pb->av_class && prev != s->pb) |
| 63 | 14708 | return s->pb; | |
| 64 | 24316 | 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 | 29815551 | 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 | 29815551 | void *val = (void*)(((uintptr_t)*iter) & ((1 << ITER_STATE_SHIFT) - 1)); | |
| 82 | 29815551 | unsigned int state = ((uintptr_t)*iter) >> ITER_STATE_SHIFT; | |
| 83 | 29815551 | const AVClass *ret = NULL; | |
| 84 | |||
| 85 |
2/2✓ Branch 0 taken 121899 times.
✓ Branch 1 taken 29693652 times.
|
29815551 | if (state == CHILD_CLASS_ITER_AVIO) { |
| 86 | 121899 | ret = &ff_avio_class; | |
| 87 | 121899 | state++; | |
| 88 | 121899 | goto finish; | |
| 89 | } | ||
| 90 | |||
| 91 |
2/2✓ Branch 0 taken 9375962 times.
✓ Branch 1 taken 20317690 times.
|
29693652 | if (state == CHILD_CLASS_ITER_MUX) { |
| 92 | const AVOutputFormat *ofmt; | ||
| 93 | |||
| 94 |
2/2✓ Branch 1 taken 23014904 times.
✓ Branch 2 taken 121688 times.
|
23136592 | while ((ofmt = av_muxer_iterate(&val))) { |
| 95 | 23014904 | ret = ofmt->priv_class; | |
| 96 |
2/2✓ Branch 0 taken 9254274 times.
✓ Branch 1 taken 13760630 times.
|
23014904 | if (ret) |
| 97 | 9254274 | goto finish; | |
| 98 | } | ||
| 99 | |||
| 100 | 121688 | val = NULL; | |
| 101 | 121688 | state++; | |
| 102 | } | ||
| 103 | |||
| 104 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20439378 times.
|
20439378 | if (state == CHILD_CLASS_ITER_DEMUX) { |
| 105 | const AVInputFormat *ifmt; | ||
| 106 | |||
| 107 |
2/2✓ Branch 1 taken 44651068 times.
✓ Branch 2 taken 121642 times.
|
44772710 | while ((ifmt = av_demuxer_iterate(&val))) { |
| 108 | 44651068 | ret = ifmt->priv_class; | |
| 109 |
2/2✓ Branch 0 taken 20317736 times.
✓ Branch 1 taken 24333332 times.
|
44651068 | if (ret) |
| 110 | 20317736 | goto finish; | |
| 111 | } | ||
| 112 | 121642 | val = NULL; | |
| 113 | 121642 | 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 29815551 times.
|
29815551 | av_assert0(!((uintptr_t)val >> ITER_STATE_SHIFT)); |
| 119 | 29815551 | *iter = (void*)((uintptr_t)val | (state << ITER_STATE_SHIFT)); | |
| 120 | 29815551 | return ret; | |
| 121 | } | ||
| 122 | |||
| 123 | 2813 | static AVClassCategory get_category(void *ptr) | |
| 124 | { | ||
| 125 | 2813 | AVFormatContext* s = ptr; | |
| 126 |
2/2✓ Branch 0 taken 1795 times.
✓ Branch 1 taken 1018 times.
|
2813 | if(s->iformat) return AV_CLASS_CATEGORY_DEMUXER; |
| 127 | 1018 | 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 | 108435 | 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 103461 times.
✓ Branch 1 taken 4974 times.
|
108435 | if (!strcmp(url, s->url) || |
| 147 |
4/4✓ Branch 0 taken 102571 times.
✓ Branch 1 taken 890 times.
✓ Branch 2 taken 112 times.
✓ Branch 3 taken 102459 times.
|
103461 | s->iformat && !strcmp(s->iformat->name, "image2") || |
| 148 |
4/4✓ Branch 0 taken 890 times.
✓ Branch 1 taken 112 times.
✓ Branch 2 taken 666 times.
✓ Branch 3 taken 224 times.
|
1002 | s->oformat && !strcmp(s->oformat->name, "image2") |
| 149 | ) { | ||
| 150 | 108099 | loglevel = AV_LOG_DEBUG; | |
| 151 | } else | ||
| 152 | 336 | loglevel = AV_LOG_INFO; | |
| 153 | |||
| 154 |
2/2✓ Branch 0 taken 904 times.
✓ Branch 1 taken 107531 times.
|
108435 | av_log(s, loglevel, "Opening \'%s\' for %s\n", url, flags & AVIO_FLAG_WRITE ? "writing" : "reading"); |
| 155 | |||
| 156 | 216870 | return ffio_open_whitelist2(pb, url, flags, &s->interrupt_callback, options, | |
| 157 | 108435 | s->protocol_whitelist, s->protocol_blacklist, s); | |
| 158 | } | ||
| 159 | |||
| 160 | 108434 | static int io_close2_default(AVFormatContext *s, AVIOContext *pb) | |
| 161 | { | ||
| 162 | 108434 | return avio_close(pb); | |
| 163 | } | ||
| 164 | |||
| 165 | 17021 | AVFormatContext *avformat_alloc_context(void) | |
| 166 | { | ||
| 167 | FormatContextInternal *fci; | ||
| 168 | FFFormatContext *si; | ||
| 169 | AVFormatContext *s; | ||
| 170 | |||
| 171 | 17021 | fci = av_mallocz(sizeof(*fci)); | |
| 172 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 17021 times.
|
17021 | if (!fci) |
| 173 | ✗ | return NULL; | |
| 174 | |||
| 175 | 17021 | si = &fci->fc; | |
| 176 | 17021 | s = &si->pub; | |
| 177 | 17021 | s->av_class = &av_format_context_class; | |
| 178 | 17021 | s->io_open = io_open_default; | |
| 179 | 17021 | s->io_close2= io_close2_default; | |
| 180 | |||
| 181 | 17021 | av_opt_set_defaults(s); | |
| 182 | |||
| 183 | 17021 | si->pkt = av_packet_alloc(); | |
| 184 | 17021 | si->parse_pkt = av_packet_alloc(); | |
| 185 |
2/4✓ Branch 0 taken 17021 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 17021 times.
|
17021 | if (!si->pkt || !si->parse_pkt) { |
| 186 | ✗ | avformat_free_context(s); | |
| 187 | ✗ | return NULL; | |
| 188 | } | ||
| 189 | |||
| 190 | 17021 | return s; | |
| 191 | } | ||
| 192 | |||
| 193 | 137253 | const AVClass *avformat_get_class(void) | |
| 194 | { | ||
| 195 | 137253 | return &av_format_context_class; | |
| 196 | } | ||
| 197 | |||
| 198 | #define DISPOSITION_OPT(ctx) \ | ||
| 199 | { "disposition", NULL, offsetof(ctx, disposition), AV_OPT_TYPE_FLAGS, { .i64 = 0 }, \ | ||
| 200 | .flags = AV_OPT_FLAG_ENCODING_PARAM, .unit = "disposition" }, \ | ||
| 201 | { "default", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DEFAULT }, .unit = "disposition" }, \ | ||
| 202 | { "dub", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DUB }, .unit = "disposition" }, \ | ||
| 203 | { "original", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_ORIGINAL }, .unit = "disposition" }, \ | ||
| 204 | { "comment", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_COMMENT }, .unit = "disposition" }, \ | ||
| 205 | { "lyrics", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_LYRICS }, .unit = "disposition" }, \ | ||
| 206 | { "karaoke", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_KARAOKE }, .unit = "disposition" }, \ | ||
| 207 | { "forced", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_FORCED }, .unit = "disposition" }, \ | ||
| 208 | { "hearing_impaired", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_HEARING_IMPAIRED }, .unit = "disposition" }, \ | ||
| 209 | { "visual_impaired", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_VISUAL_IMPAIRED }, .unit = "disposition" }, \ | ||
| 210 | { "clean_effects", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_CLEAN_EFFECTS }, .unit = "disposition" }, \ | ||
| 211 | { "attached_pic", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_ATTACHED_PIC }, .unit = "disposition" }, \ | ||
| 212 | { "timed_thumbnails", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_TIMED_THUMBNAILS }, .unit = "disposition" }, \ | ||
| 213 | { "non_diegetic", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_NON_DIEGETIC }, .unit = "disposition" }, \ | ||
| 214 | { "captions", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_CAPTIONS }, .unit = "disposition" }, \ | ||
| 215 | { "descriptions", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DESCRIPTIONS }, .unit = "disposition" }, \ | ||
| 216 | { "metadata", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_METADATA }, .unit = "disposition" }, \ | ||
| 217 | { "dependent", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DEPENDENT }, .unit = "disposition" }, \ | ||
| 218 | { "still_image", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_STILL_IMAGE }, .unit = "disposition" }, \ | ||
| 219 | { "multilayer", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_MULTILAYER }, .unit = "disposition" } | ||
| 220 | |||
| 221 | static const AVOption stream_options[] = { | ||
| 222 | DISPOSITION_OPT(AVStream), | ||
| 223 | { "discard", NULL, offsetof(AVStream, discard), AV_OPT_TYPE_INT, { .i64 = AVDISCARD_DEFAULT }, INT_MIN, INT_MAX, | ||
| 224 | .flags = AV_OPT_FLAG_DECODING_PARAM, .unit = "avdiscard" }, | ||
| 225 | { "none", .type = AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_NONE }, .unit = "avdiscard" }, | ||
| 226 | { "default", .type = AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_DEFAULT }, .unit = "avdiscard" }, | ||
| 227 | { "noref", .type = AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_NONREF }, .unit = "avdiscard" }, | ||
| 228 | { "bidir", .type = AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_BIDIR }, .unit = "avdiscard" }, | ||
| 229 | { "nointra", .type = AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_NONINTRA }, .unit = "avdiscard" }, | ||
| 230 | { "nokey", .type = AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_NONKEY }, .unit = "avdiscard" }, | ||
| 231 | { "all", .type = AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_ALL }, .unit = "avdiscard" }, | ||
| 232 | { NULL } | ||
| 233 | }; | ||
| 234 | |||
| 235 | static const AVClass stream_class = { | ||
| 236 | .class_name = "AVStream", | ||
| 237 | .item_name = av_default_item_name, | ||
| 238 | .version = LIBAVUTIL_VERSION_INT, | ||
| 239 | .option = stream_options, | ||
| 240 | }; | ||
| 241 | |||
| 242 | 1 | const AVClass *av_stream_get_class(void) | |
| 243 | { | ||
| 244 | 1 | return &stream_class; | |
| 245 | } | ||
| 246 | |||
| 247 | 18447 | AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c) | |
| 248 | { | ||
| 249 | FFStream *sti; | ||
| 250 | AVStream *st; | ||
| 251 | AVStream **streams; | ||
| 252 | |||
| 253 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18447 times.
|
18447 | if (s->nb_streams >= s->max_streams) { |
| 254 | ✗ | av_log(s, AV_LOG_ERROR, "Number of streams exceeds max_streams parameter" | |
| 255 | " (%d), see the documentation if you wish to increase it\n", | ||
| 256 | s->max_streams); | ||
| 257 | ✗ | return NULL; | |
| 258 | } | ||
| 259 | 18447 | streams = av_realloc_array(s->streams, s->nb_streams + 1, sizeof(*streams)); | |
| 260 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18447 times.
|
18447 | if (!streams) |
| 261 | ✗ | return NULL; | |
| 262 | 18447 | s->streams = streams; | |
| 263 | |||
| 264 | 18447 | sti = av_mallocz(sizeof(*sti)); | |
| 265 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18447 times.
|
18447 | if (!sti) |
| 266 | ✗ | return NULL; | |
| 267 | 18447 | st = &sti->pub; | |
| 268 | |||
| 269 | 18447 | st->av_class = &stream_class; | |
| 270 | 18447 | st->codecpar = avcodec_parameters_alloc(); | |
| 271 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18447 times.
|
18447 | if (!st->codecpar) |
| 272 | ✗ | goto fail; | |
| 273 | |||
| 274 | 18447 | sti->fmtctx = s; | |
| 275 | |||
| 276 | 18447 | sti->parse_pkt = av_packet_alloc(); | |
| 277 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18447 times.
|
18447 | if (!sti->parse_pkt) |
| 278 | ✗ | goto fail; | |
| 279 | |||
| 280 |
2/2✓ Branch 0 taken 9068 times.
✓ Branch 1 taken 9379 times.
|
18447 | if (s->iformat) { |
| 281 | 9068 | sti->avctx = avcodec_alloc_context3(NULL); | |
| 282 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9068 times.
|
9068 | if (!sti->avctx) |
| 283 | ✗ | goto fail; | |
| 284 | |||
| 285 | 9068 | sti->info = av_mallocz(sizeof(*sti->info)); | |
| 286 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9068 times.
|
9068 | if (!sti->info) |
| 287 | ✗ | goto fail; | |
| 288 | |||
| 289 | #if FF_API_R_FRAME_RATE | ||
| 290 | 9068 | sti->info->last_dts = AV_NOPTS_VALUE; | |
| 291 | #endif | ||
| 292 | 9068 | sti->info->fps_first_dts = AV_NOPTS_VALUE; | |
| 293 | 9068 | sti->info->fps_last_dts = AV_NOPTS_VALUE; | |
| 294 | |||
| 295 | /* default pts setting is MPEG-like */ | ||
| 296 | 9068 | 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 | 9068 | sti->cur_dts = RELATIVE_TS_BASE; | |
| 302 | } else { | ||
| 303 | 9379 | sti->cur_dts = AV_NOPTS_VALUE; | |
| 304 | } | ||
| 305 | |||
| 306 | 18447 | st->index = s->nb_streams; | |
| 307 | 18447 | st->start_time = AV_NOPTS_VALUE; | |
| 308 | 18447 | st->duration = AV_NOPTS_VALUE; | |
| 309 | 18447 | sti->first_dts = AV_NOPTS_VALUE; | |
| 310 | 18447 | sti->probe_packets = s->max_probe_packets; | |
| 311 | 18447 | sti->pts_wrap_reference = AV_NOPTS_VALUE; | |
| 312 | 18447 | sti->pts_wrap_behavior = AV_PTS_WRAP_IGNORE; | |
| 313 | |||
| 314 | 18447 | sti->last_IP_pts = AV_NOPTS_VALUE; | |
| 315 | 18447 | sti->last_dts_for_order_check = AV_NOPTS_VALUE; | |
| 316 |
2/2✓ Branch 0 taken 313599 times.
✓ Branch 1 taken 18447 times.
|
332046 | for (int i = 0; i < MAX_REORDER_DELAY + 1; i++) |
| 317 | 313599 | sti->pts_buffer[i] = AV_NOPTS_VALUE; | |
| 318 | |||
| 319 | 18447 | st->sample_aspect_ratio = (AVRational) { 0, 1 }; | |
| 320 | |||
| 321 | 18447 | sti->need_context_update = 1; | |
| 322 | |||
| 323 | 18447 | s->streams[s->nb_streams++] = st; | |
| 324 | 18447 | return st; | |
| 325 | ✗ | fail: | |
| 326 | ✗ | ff_free_stream(&st); | |
| 327 | ✗ | return NULL; | |
| 328 | } | ||
| 329 | |||
| 330 | #define FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM | ||
| 331 | #define OFFSET(x) offsetof(AVStreamGroupTileGrid, x) | ||
| 332 | static const AVOption tile_grid_options[] = { | ||
| 333 | { "grid_size", "size of the output canvas", OFFSET(coded_width), | ||
| 334 | AV_OPT_TYPE_IMAGE_SIZE, { .str = NULL }, 0, INT_MAX, FLAGS }, | ||
| 335 | { "output_size", "size of valid pixels in output image meant for presentation", OFFSET(width), | ||
| 336 | AV_OPT_TYPE_IMAGE_SIZE, { .str = NULL }, 0, INT_MAX, FLAGS }, | ||
| 337 | { "background_color", "set a background color for unused pixels", | ||
| 338 | OFFSET(background), AV_OPT_TYPE_COLOR, { .str = "black"}, 0, 0, FLAGS }, | ||
| 339 | { "horizontal_offset", NULL, OFFSET(horizontal_offset), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS }, | ||
| 340 | { "vertical_offset", NULL, OFFSET(vertical_offset), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS }, | ||
| 341 | { NULL }, | ||
| 342 | }; | ||
| 343 | #undef OFFSET | ||
| 344 | |||
| 345 | static const AVClass tile_grid_class = { | ||
| 346 | .class_name = "AVStreamGroupTileGrid", | ||
| 347 | .version = LIBAVUTIL_VERSION_INT, | ||
| 348 | .option = tile_grid_options, | ||
| 349 | }; | ||
| 350 | |||
| 351 | #define OFFSET(x) offsetof(AVStreamGroupTREF, x) | ||
| 352 | static const AVOption tref_options[] = { | ||
| 353 | { "metadata_index", "Index of the data stream within the group", OFFSET(metadata_index), | ||
| 354 | AV_OPT_TYPE_UINT, { .i64 = 0 }, 0, UINT_MAX, FLAGS }, | ||
| 355 | { NULL }, | ||
| 356 | }; | ||
| 357 | #undef OFFSET | ||
| 358 | |||
| 359 | static const AVClass tref_class = { | ||
| 360 | .class_name = "AVStreamGroupTREF", | ||
| 361 | .version = LIBAVUTIL_VERSION_INT, | ||
| 362 | .option = tref_options, | ||
| 363 | }; | ||
| 364 | |||
| 365 | #if FF_API_LCEVC_STRUCT | ||
| 366 | FF_DISABLE_DEPRECATION_WARNINGS | ||
| 367 | #endif | ||
| 368 | #define OFFSET(x) offsetof(AVStreamGroupLayeredVideo, x) | ||
| 369 | static const AVOption layered_video_options[] = { | ||
| 370 | #if FF_API_LCEVC_STRUCT | ||
| 371 | { "lcevc_index", "Index of the LCEVC stream within the group", OFFSET(lcevc_index), | ||
| 372 | AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS | AV_OPT_FLAG_DEPRECATED }, | ||
| 373 | #endif | ||
| 374 | { "el_index", "Index of the enhancement layer stream within the group", OFFSET(el_index), | ||
| 375 | AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS }, | ||
| 376 | { "video_size", "size of the final layered video presentation", OFFSET(width), | ||
| 377 | AV_OPT_TYPE_IMAGE_SIZE, { .str = NULL }, 0, INT_MAX, FLAGS }, | ||
| 378 | { NULL }, | ||
| 379 | }; | ||
| 380 | #if FF_API_LCEVC_STRUCT | ||
| 381 | FF_ENABLE_DEPRECATION_WARNINGS | ||
| 382 | #endif | ||
| 383 | #undef OFFSET | ||
| 384 | |||
| 385 | static const AVClass layered_video_class = { | ||
| 386 | .class_name = "AVStreamGroupLayeredVideo", | ||
| 387 | .version = LIBAVUTIL_VERSION_INT, | ||
| 388 | .option = layered_video_options, | ||
| 389 | }; | ||
| 390 | |||
| 391 | 204 | static void *stream_group_child_next(void *obj, void *prev) | |
| 392 | { | ||
| 393 | 204 | AVStreamGroup *stg = obj; | |
| 394 |
2/2✓ Branch 0 taken 115 times.
✓ Branch 1 taken 89 times.
|
204 | if (!prev) { |
| 395 |
2/6✓ Branch 0 taken 59 times.
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
115 | switch(stg->type) { |
| 396 | 59 | case AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT: | |
| 397 | 59 | return stg->params.iamf_audio_element; | |
| 398 | 56 | case AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION: | |
| 399 | 56 | return stg->params.iamf_mix_presentation; | |
| 400 | ✗ | case AV_STREAM_GROUP_PARAMS_TILE_GRID: | |
| 401 | ✗ | return stg->params.tile_grid; | |
| 402 | ✗ | case AV_STREAM_GROUP_PARAMS_TREF: | |
| 403 | ✗ | return stg->params.tref; | |
| 404 | ✗ | case AV_STREAM_GROUP_PARAMS_LCEVC: | |
| 405 | case AV_STREAM_GROUP_PARAMS_DOLBY_VISION: | ||
| 406 | ✗ | return stg->params.layered_video; | |
| 407 | ✗ | default: | |
| 408 | ✗ | break; | |
| 409 | } | ||
| 410 | } | ||
| 411 | 89 | return NULL; | |
| 412 | } | ||
| 413 | |||
| 414 | #undef FLAGS | ||
| 415 | |||
| 416 | ✗ | static const AVClass *stream_group_child_iterate(void **opaque) | |
| 417 | { | ||
| 418 | ✗ | uintptr_t i = (uintptr_t)*opaque; | |
| 419 | ✗ | const AVClass *ret = NULL; | |
| 420 | |||
| 421 | ✗ | switch(i) { | |
| 422 | ✗ | case AV_STREAM_GROUP_PARAMS_NONE: | |
| 423 | ✗ | i++; | |
| 424 | av_fallthrough; | ||
| 425 | ✗ | case AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT: | |
| 426 | ✗ | ret = av_iamf_audio_element_get_class(); | |
| 427 | ✗ | break; | |
| 428 | ✗ | case AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION: | |
| 429 | ✗ | ret = av_iamf_mix_presentation_get_class(); | |
| 430 | ✗ | break; | |
| 431 | ✗ | case AV_STREAM_GROUP_PARAMS_TILE_GRID: | |
| 432 | ✗ | ret = &tile_grid_class; | |
| 433 | ✗ | break; | |
| 434 | ✗ | case AV_STREAM_GROUP_PARAMS_TREF: | |
| 435 | ✗ | ret = &tref_class; | |
| 436 | ✗ | break; | |
| 437 | ✗ | case AV_STREAM_GROUP_PARAMS_LCEVC: | |
| 438 | case AV_STREAM_GROUP_PARAMS_DOLBY_VISION: | ||
| 439 | ✗ | ret = &layered_video_class; | |
| 440 | ✗ | break; | |
| 441 | ✗ | default: | |
| 442 | ✗ | break; | |
| 443 | } | ||
| 444 | |||
| 445 | ✗ | if (ret) | |
| 446 | ✗ | *opaque = (void*)(i + 1); | |
| 447 | ✗ | return ret; | |
| 448 | } | ||
| 449 | |||
| 450 | static const AVOption stream_group_options[] = { | ||
| 451 | DISPOSITION_OPT(AVStreamGroup), | ||
| 452 | {"id", "Set group id", offsetof(AVStreamGroup, id), AV_OPT_TYPE_INT64, {.i64 = 0}, 0, INT64_MAX, AV_OPT_FLAG_ENCODING_PARAM }, | ||
| 453 | { NULL } | ||
| 454 | }; | ||
| 455 | |||
| 456 | static const AVClass stream_group_class = { | ||
| 457 | .class_name = "AVStreamGroup", | ||
| 458 | .item_name = av_default_item_name, | ||
| 459 | .version = LIBAVUTIL_VERSION_INT, | ||
| 460 | .option = stream_group_options, | ||
| 461 | .child_next = stream_group_child_next, | ||
| 462 | .child_class_iterate = stream_group_child_iterate, | ||
| 463 | }; | ||
| 464 | |||
| 465 | ✗ | const AVClass *av_stream_group_get_class(void) | |
| 466 | { | ||
| 467 | ✗ | return &stream_group_class; | |
| 468 | } | ||
| 469 | |||
| 470 | 148 | AVStreamGroup *avformat_stream_group_create(AVFormatContext *s, | |
| 471 | enum AVStreamGroupParamsType type, | ||
| 472 | AVDictionary **options) | ||
| 473 | { | ||
| 474 | AVStreamGroup **stream_groups; | ||
| 475 | AVStreamGroup *stg; | ||
| 476 | FFStreamGroup *stgi; | ||
| 477 | |||
| 478 | 148 | stream_groups = av_realloc_array(s->stream_groups, s->nb_stream_groups + 1, | |
| 479 | sizeof(*stream_groups)); | ||
| 480 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 148 times.
|
148 | if (!stream_groups) |
| 481 | ✗ | return NULL; | |
| 482 | 148 | s->stream_groups = stream_groups; | |
| 483 | |||
| 484 | 148 | stgi = av_mallocz(sizeof(*stgi)); | |
| 485 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 148 times.
|
148 | if (!stgi) |
| 486 | ✗ | return NULL; | |
| 487 | 148 | stg = &stgi->pub; | |
| 488 | |||
| 489 | 148 | stg->av_class = &stream_group_class; | |
| 490 | 148 | av_opt_set_defaults(stg); | |
| 491 | 148 | stg->type = type; | |
| 492 |
5/6✓ Branch 0 taken 52 times.
✓ Branch 1 taken 49 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 30 times.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
|
148 | switch (type) { |
| 493 | 52 | case AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT: | |
| 494 | 52 | stg->params.iamf_audio_element = av_iamf_audio_element_alloc(); | |
| 495 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 52 times.
|
52 | if (!stg->params.iamf_audio_element) |
| 496 | ✗ | goto fail; | |
| 497 | 52 | break; | |
| 498 | 49 | case AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION: | |
| 499 | 49 | stg->params.iamf_mix_presentation = av_iamf_mix_presentation_alloc(); | |
| 500 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 49 times.
|
49 | if (!stg->params.iamf_mix_presentation) |
| 501 | ✗ | goto fail; | |
| 502 | 49 | break; | |
| 503 | 9 | case AV_STREAM_GROUP_PARAMS_TILE_GRID: | |
| 504 | 9 | stg->params.tile_grid = av_mallocz(sizeof(*stg->params.tile_grid)); | |
| 505 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | if (!stg->params.tile_grid) |
| 506 | ✗ | goto fail; | |
| 507 | 9 | stg->params.tile_grid->av_class = &tile_grid_class; | |
| 508 | 9 | av_opt_set_defaults(stg->params.tile_grid); | |
| 509 | 9 | break; | |
| 510 | 30 | case AV_STREAM_GROUP_PARAMS_TREF: | |
| 511 | 30 | stg->params.tref = av_mallocz(sizeof(*stg->params.tref)); | |
| 512 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
|
30 | if (!stg->params.tref) |
| 513 | ✗ | goto fail; | |
| 514 | 30 | stg->params.tref->av_class = &tref_class; | |
| 515 | 30 | av_opt_set_defaults(stg->params.tref); | |
| 516 | 30 | break; | |
| 517 | 8 | case AV_STREAM_GROUP_PARAMS_LCEVC: | |
| 518 | case AV_STREAM_GROUP_PARAMS_DOLBY_VISION: | ||
| 519 | 8 | stg->params.layered_video = av_mallocz(sizeof(*stg->params.layered_video)); | |
| 520 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
|
8 | if (!stg->params.layered_video) |
| 521 | ✗ | goto fail; | |
| 522 | 8 | stg->params.layered_video->av_class = &layered_video_class; | |
| 523 | 8 | av_opt_set_defaults(stg->params.layered_video); | |
| 524 | 8 | break; | |
| 525 | ✗ | default: | |
| 526 | ✗ | goto fail; | |
| 527 | } | ||
| 528 | |||
| 529 |
2/2✓ Branch 0 taken 27 times.
✓ Branch 1 taken 121 times.
|
148 | if (options) { |
| 530 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 27 times.
|
27 | if (av_opt_set_dict2(stg, options, AV_OPT_SEARCH_CHILDREN)) |
| 531 | ✗ | goto fail; | |
| 532 | } | ||
| 533 | |||
| 534 | 148 | stgi->fmtctx = s; | |
| 535 | 148 | stg->index = s->nb_stream_groups; | |
| 536 | |||
| 537 | 148 | s->stream_groups[s->nb_stream_groups++] = stg; | |
| 538 | |||
| 539 | 148 | return stg; | |
| 540 | ✗ | fail: | |
| 541 | ✗ | ff_free_stream_group(&stg); | |
| 542 | ✗ | return NULL; | |
| 543 | } | ||
| 544 | |||
| 545 | 572 | static int stream_group_add_stream(AVStreamGroup *stg, AVStream *st) | |
| 546 | { | ||
| 547 | 572 | AVStream **streams = av_realloc_array(stg->streams, stg->nb_streams + 1, | |
| 548 | sizeof(*stg->streams)); | ||
| 549 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 572 times.
|
572 | if (!streams) |
| 550 | ✗ | return AVERROR(ENOMEM); | |
| 551 | |||
| 552 | 572 | stg->streams = streams; | |
| 553 | 572 | stg->streams[stg->nb_streams++] = st; | |
| 554 | |||
| 555 | 572 | return 0; | |
| 556 | } | ||
| 557 | |||
| 558 | 578 | int avformat_stream_group_add_stream(AVStreamGroup *stg, AVStream *st) | |
| 559 | { | ||
| 560 | 578 | const FFStreamGroup *stgi = cffstreamgroup(stg); | |
| 561 | 578 | const FFStream *sti = cffstream(st); | |
| 562 | |||
| 563 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 578 times.
|
578 | if (stgi->fmtctx != sti->fmtctx) |
| 564 | ✗ | return AVERROR(EINVAL); | |
| 565 | |||
| 566 |
2/2✓ Branch 0 taken 1206 times.
✓ Branch 1 taken 572 times.
|
1778 | for (int i = 0; i < stg->nb_streams; i++) |
| 567 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1200 times.
|
1206 | if (stg->streams[i]->index == st->index) |
| 568 | 6 | return AVERROR(EEXIST); | |
| 569 | |||
| 570 | 572 | return stream_group_add_stream(stg, st); | |
| 571 | } | ||
| 572 | |||
| 573 | 161865 | static int option_is_disposition(const AVOption *opt) | |
| 574 | { | ||
| 575 | 310959 | return opt->type == AV_OPT_TYPE_CONST && | |
| 576 |
5/6✓ Branch 0 taken 149094 times.
✓ Branch 1 taken 12771 times.
✓ Branch 2 taken 149094 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 124146 times.
✓ Branch 5 taken 24948 times.
|
161865 | opt->unit && !strcmp(opt->unit, "disposition"); |
| 577 | } | ||
| 578 | |||
| 579 | ✗ | int av_disposition_from_string(const char *disp) | |
| 580 | { | ||
| 581 | ✗ | for (const AVOption *opt = stream_options; opt->name; opt++) | |
| 582 | ✗ | if (option_is_disposition(opt) && !strcmp(disp, opt->name)) | |
| 583 | ✗ | return opt->default_val.i64; | |
| 584 | ✗ | return AVERROR(EINVAL); | |
| 585 | } | ||
| 586 | |||
| 587 | 9504 | const char *av_disposition_to_string(int disposition) | |
| 588 | { | ||
| 589 | int val; | ||
| 590 | |||
| 591 |
2/2✓ Branch 0 taken 297 times.
✓ Branch 1 taken 9207 times.
|
9504 | if (disposition <= 0) |
| 592 | 297 | return NULL; | |
| 593 | |||
| 594 | 9207 | val = 1 << ff_ctz(disposition); | |
| 595 |
2/2✓ Branch 0 taken 161865 times.
✓ Branch 1 taken 3564 times.
|
165429 | for (const AVOption *opt = stream_options; opt->name; opt++) |
| 596 |
4/4✓ Branch 1 taken 124146 times.
✓ Branch 2 taken 37719 times.
✓ Branch 3 taken 5643 times.
✓ Branch 4 taken 118503 times.
|
161865 | if (option_is_disposition(opt) && opt->default_val.i64 == val) |
| 597 | 5643 | return opt->name; | |
| 598 | |||
| 599 | 3564 | return NULL; | |
| 600 | } | ||
| 601 |