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