| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Core demuxing component | ||
| 3 | * Copyright (c) 2000, 2001, 2002 Fabrice Bellard | ||
| 4 | * | ||
| 5 | * This file is part of FFmpeg. | ||
| 6 | * | ||
| 7 | * FFmpeg is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with FFmpeg; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | #include <stdint.h> | ||
| 23 | |||
| 24 | #include "config_components.h" | ||
| 25 | |||
| 26 | #include "libavutil/avassert.h" | ||
| 27 | #include "libavutil/avstring.h" | ||
| 28 | #include "libavutil/dict.h" | ||
| 29 | #include "libavutil/internal.h" | ||
| 30 | #include "libavutil/intreadwrite.h" | ||
| 31 | #include "libavutil/mathematics.h" | ||
| 32 | #include "libavutil/mem.h" | ||
| 33 | #include "libavutil/opt.h" | ||
| 34 | #include "libavutil/pixfmt.h" | ||
| 35 | #include "libavutil/time.h" | ||
| 36 | #include "libavutil/timestamp.h" | ||
| 37 | |||
| 38 | #include "libavcodec/avcodec.h" | ||
| 39 | #include "libavcodec/bsf.h" | ||
| 40 | #include "libavcodec/codec_desc.h" | ||
| 41 | #include "libavcodec/internal.h" | ||
| 42 | #include "packet_internal.h" | ||
| 43 | #include "libavcodec/raw.h" | ||
| 44 | |||
| 45 | #include "avformat.h" | ||
| 46 | #include "avformat_internal.h" | ||
| 47 | #include "avio_internal.h" | ||
| 48 | #include "demux.h" | ||
| 49 | #include "id3v2.h" | ||
| 50 | #include "internal.h" | ||
| 51 | #include "url.h" | ||
| 52 | |||
| 53 | 2622917 | static int64_t wrap_timestamp(const AVStream *st, int64_t timestamp) | |
| 54 | { | ||
| 55 | 2622917 | const FFStream *const sti = cffstream(st); | |
| 56 |
4/4✓ Branch 0 taken 165449 times.
✓ Branch 1 taken 2457468 times.
✓ Branch 2 taken 160433 times.
✓ Branch 3 taken 5016 times.
|
2622917 | if (sti->pts_wrap_behavior != AV_PTS_WRAP_IGNORE && st->pts_wrap_bits < 64 && |
| 57 |
4/4✓ Branch 0 taken 159127 times.
✓ Branch 1 taken 1306 times.
✓ Branch 2 taken 96969 times.
✓ Branch 3 taken 62158 times.
|
160433 | sti->pts_wrap_reference != AV_NOPTS_VALUE && timestamp != AV_NOPTS_VALUE) { |
| 58 |
2/2✓ Branch 0 taken 96765 times.
✓ Branch 1 taken 204 times.
|
96969 | if (sti->pts_wrap_behavior == AV_PTS_WRAP_ADD_OFFSET && |
| 59 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 96765 times.
|
96765 | timestamp < sti->pts_wrap_reference) |
| 60 | ✗ | return timestamp + (1ULL << st->pts_wrap_bits); | |
| 61 |
2/2✓ Branch 0 taken 204 times.
✓ Branch 1 taken 96765 times.
|
96969 | else if (sti->pts_wrap_behavior == AV_PTS_WRAP_SUB_OFFSET && |
| 62 |
2/2✓ Branch 0 taken 50 times.
✓ Branch 1 taken 154 times.
|
204 | timestamp >= sti->pts_wrap_reference) |
| 63 | 50 | return timestamp - (1ULL << st->pts_wrap_bits); | |
| 64 | } | ||
| 65 | 2622867 | return timestamp; | |
| 66 | } | ||
| 67 | |||
| 68 | 355679 | int64_t ff_wrap_timestamp(const AVStream *st, int64_t timestamp) | |
| 69 | { | ||
| 70 | 355679 | return wrap_timestamp(st, timestamp); | |
| 71 | } | ||
| 72 | |||
| 73 | 10546 | static const AVCodec *find_probe_decoder(AVFormatContext *s, const AVStream *st, enum AVCodecID codec_id) | |
| 74 | { | ||
| 75 | const AVCodec *codec; | ||
| 76 | |||
| 77 | #if CONFIG_H264_DECODER | ||
| 78 | /* Other parts of the code assume this decoder to be used for h264, | ||
| 79 | * so force it if possible. */ | ||
| 80 |
2/2✓ Branch 0 taken 367 times.
✓ Branch 1 taken 10179 times.
|
10546 | if (codec_id == AV_CODEC_ID_H264) |
| 81 | 367 | return avcodec_find_decoder_by_name("h264"); | |
| 82 | #endif | ||
| 83 | |||
| 84 | 10179 | codec = ff_find_decoder(s, st, codec_id); | |
| 85 |
2/2✓ Branch 0 taken 212 times.
✓ Branch 1 taken 9967 times.
|
10179 | if (!codec) |
| 86 | 212 | return NULL; | |
| 87 | |||
| 88 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9967 times.
|
9967 | if (codec->capabilities & AV_CODEC_CAP_AVOID_PROBING) { |
| 89 | ✗ | const AVCodec *probe_codec = NULL; | |
| 90 | ✗ | void *iter = NULL; | |
| 91 | ✗ | while ((probe_codec = av_codec_iterate(&iter))) { | |
| 92 | ✗ | if (probe_codec->id == codec->id && | |
| 93 | ✗ | av_codec_is_decoder(probe_codec) && | |
| 94 | ✗ | !(probe_codec->capabilities & (AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_EXPERIMENTAL))) { | |
| 95 | ✗ | return probe_codec; | |
| 96 | } | ||
| 97 | } | ||
| 98 | } | ||
| 99 | |||
| 100 | 9967 | return codec; | |
| 101 | } | ||
| 102 | |||
| 103 | 3372 | static int set_codec_from_probe_data(AVFormatContext *s, AVStream *st, | |
| 104 | AVProbeData *pd) | ||
| 105 | { | ||
| 106 | static const struct { | ||
| 107 | const char *name; | ||
| 108 | enum AVCodecID id; | ||
| 109 | enum AVMediaType type; | ||
| 110 | } fmt_id_type[] = { | ||
| 111 | { "aac", AV_CODEC_ID_AAC, AVMEDIA_TYPE_AUDIO }, | ||
| 112 | { "ac3", AV_CODEC_ID_AC3, AVMEDIA_TYPE_AUDIO }, | ||
| 113 | { "aptx", AV_CODEC_ID_APTX, AVMEDIA_TYPE_AUDIO }, | ||
| 114 | { "av1", AV_CODEC_ID_AV1, AVMEDIA_TYPE_VIDEO }, | ||
| 115 | { "dts", AV_CODEC_ID_DTS, AVMEDIA_TYPE_AUDIO }, | ||
| 116 | { "dvbsub", AV_CODEC_ID_DVB_SUBTITLE, AVMEDIA_TYPE_SUBTITLE }, | ||
| 117 | { "dvbtxt", AV_CODEC_ID_DVB_TELETEXT, AVMEDIA_TYPE_SUBTITLE }, | ||
| 118 | { "eac3", AV_CODEC_ID_EAC3, AVMEDIA_TYPE_AUDIO }, | ||
| 119 | { "h264", AV_CODEC_ID_H264, AVMEDIA_TYPE_VIDEO }, | ||
| 120 | { "hevc", AV_CODEC_ID_HEVC, AVMEDIA_TYPE_VIDEO }, | ||
| 121 | { "loas", AV_CODEC_ID_AAC_LATM, AVMEDIA_TYPE_AUDIO }, | ||
| 122 | { "m4v", AV_CODEC_ID_MPEG4, AVMEDIA_TYPE_VIDEO }, | ||
| 123 | { "mjpeg_2000", AV_CODEC_ID_JPEG2000, AVMEDIA_TYPE_VIDEO }, | ||
| 124 | { "mp3", AV_CODEC_ID_MP3, AVMEDIA_TYPE_AUDIO }, | ||
| 125 | { "mpegvideo", AV_CODEC_ID_MPEG2VIDEO, AVMEDIA_TYPE_VIDEO }, | ||
| 126 | { "truehd", AV_CODEC_ID_TRUEHD, AVMEDIA_TYPE_AUDIO }, | ||
| 127 | { "evc", AV_CODEC_ID_EVC, AVMEDIA_TYPE_VIDEO }, | ||
| 128 | { "vvc", AV_CODEC_ID_VVC, AVMEDIA_TYPE_VIDEO }, | ||
| 129 | { 0 } | ||
| 130 | }; | ||
| 131 | int score; | ||
| 132 | 3372 | const AVInputFormat *fmt = av_probe_input_format3(pd, 1, &score); | |
| 133 | 3372 | FFStream *const sti = ffstream(st); | |
| 134 | |||
| 135 |
2/2✓ Branch 0 taken 1184 times.
✓ Branch 1 taken 2188 times.
|
3372 | if (fmt) { |
| 136 | 1184 | av_log(s, AV_LOG_DEBUG, | |
| 137 | "Probe with size=%d, packets=%d detected %s with score=%d\n", | ||
| 138 | 1184 | pd->buf_size, s->max_probe_packets - sti->probe_packets, | |
| 139 | 1184 | fmt->name, score); | |
| 140 |
2/2✓ Branch 0 taken 21144 times.
✓ Branch 1 taken 1159 times.
|
22303 | for (int i = 0; fmt_id_type[i].name; i++) { |
| 141 |
2/2✓ Branch 0 taken 31 times.
✓ Branch 1 taken 21113 times.
|
21144 | if (!strcmp(fmt->name, fmt_id_type[i].name)) { |
| 142 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 18 times.
|
31 | if (fmt_id_type[i].type != AVMEDIA_TYPE_AUDIO && |
| 143 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
|
13 | st->codecpar->sample_rate) |
| 144 | ✗ | continue; | |
| 145 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 21 times.
|
31 | if (sti->request_probe > score && |
| 146 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 4 times.
|
10 | st->codecpar->codec_id != fmt_id_type[i].id) |
| 147 | 6 | continue; | |
| 148 | 25 | st->codecpar->codec_id = fmt_id_type[i].id; | |
| 149 | 25 | st->codecpar->codec_type = fmt_id_type[i].type; | |
| 150 | 25 | sti->need_context_update = 1; | |
| 151 | 25 | return score; | |
| 152 | } | ||
| 153 | } | ||
| 154 | } | ||
| 155 | 3347 | return 0; | |
| 156 | } | ||
| 157 | |||
| 158 | 8257 | static int init_input(AVFormatContext *s, const char *filename, | |
| 159 | AVDictionary **options) | ||
| 160 | { | ||
| 161 | int ret; | ||
| 162 | 8257 | AVProbeData pd = { filename, NULL, 0 }; | |
| 163 | 8257 | int score = AVPROBE_SCORE_RETRY; | |
| 164 | |||
| 165 |
2/2✓ Branch 0 taken 17 times.
✓ Branch 1 taken 8240 times.
|
8257 | if (s->pb) { |
| 166 | 17 | s->flags |= AVFMT_FLAG_CUSTOM_IO; | |
| 167 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
|
17 | if (!s->iformat) |
| 168 | ✗ | return av_probe_input_buffer2(s->pb, &s->iformat, filename, | |
| 169 | ✗ | s, 0, s->format_probesize); | |
| 170 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
|
17 | else if (s->iformat->flags & AVFMT_NOFILE) |
| 171 | ✗ | av_log(s, AV_LOG_WARNING, "Custom AVIOContext makes no sense and " | |
| 172 | "will be ignored with AVFMT_NOFILE format.\n"); | ||
| 173 | 17 | return 0; | |
| 174 | } | ||
| 175 | |||
| 176 |
4/4✓ Branch 0 taken 3966 times.
✓ Branch 1 taken 4274 times.
✓ Branch 2 taken 968 times.
✓ Branch 3 taken 2998 times.
|
8240 | if ((s->iformat && s->iformat->flags & AVFMT_NOFILE) || |
| 177 |
4/4✓ Branch 0 taken 4274 times.
✓ Branch 1 taken 968 times.
✓ Branch 3 taken 199 times.
✓ Branch 4 taken 4075 times.
|
5242 | (!s->iformat && (s->iformat = av_probe_input_format2(&pd, 0, &score)))) |
| 178 | 3197 | return score; | |
| 179 | |||
| 180 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 5043 times.
|
5043 | if ((ret = s->io_open(s, &s->pb, filename, AVIO_FLAG_READ | s->avio_flags, options)) < 0) |
| 181 | ✗ | return ret; | |
| 182 | |||
| 183 |
2/2✓ Branch 0 taken 968 times.
✓ Branch 1 taken 4075 times.
|
5043 | if (s->iformat) |
| 184 | 968 | return 0; | |
| 185 | 4075 | return av_probe_input_buffer2(s->pb, &s->iformat, filename, | |
| 186 | 4075 | s, 0, s->format_probesize); | |
| 187 | } | ||
| 188 | |||
| 189 | static int codec_close(FFStream *sti); | ||
| 190 | |||
| 191 | 218256 | static int update_stream_avctx(AVFormatContext *s) | |
| 192 | { | ||
| 193 | int ret; | ||
| 194 |
2/2✓ Branch 0 taken 262507 times.
✓ Branch 1 taken 218256 times.
|
480763 | for (unsigned i = 0; i < s->nb_streams; i++) { |
| 195 | 262507 | AVStream *const st = s->streams[i]; | |
| 196 | 262507 | FFStream *const sti = ffstream(st); | |
| 197 | |||
| 198 |
2/2✓ Branch 0 taken 253490 times.
✓ Branch 1 taken 9017 times.
|
262507 | if (!sti->need_context_update) |
| 199 | 253490 | continue; | |
| 200 | |||
| 201 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 2 taken 9015 times.
|
9017 | if (avcodec_is_open(sti->avctx)) { |
| 202 | 2 | av_log(s, AV_LOG_DEBUG, "Demuxer context update while decoder is open, closing and trying to re-open\n"); | |
| 203 | 2 | ret = codec_close(sti); | |
| 204 | 2 | sti->info->found_decoder = 0; | |
| 205 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (ret < 0) |
| 206 | ✗ | return ret; | |
| 207 | } | ||
| 208 | |||
| 209 | /* close parser, because it depends on the codec */ | ||
| 210 |
3/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9015 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
9017 | if (sti->parser && sti->avctx->codec_id != st->codecpar->codec_id) { |
| 211 | ✗ | av_parser_close(sti->parser); | |
| 212 | ✗ | sti->parser = NULL; | |
| 213 | } | ||
| 214 | |||
| 215 | /* update internal codec context, for the parser */ | ||
| 216 | 9017 | ret = avcodec_parameters_to_context(sti->avctx, st->codecpar); | |
| 217 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9017 times.
|
9017 | if (ret < 0) |
| 218 | ✗ | return ret; | |
| 219 | |||
| 220 | 9017 | sti->codec_desc = avcodec_descriptor_get(sti->avctx->codec_id); | |
| 221 | |||
| 222 | 9017 | sti->need_context_update = 0; | |
| 223 | } | ||
| 224 | 218256 | return 0; | |
| 225 | } | ||
| 226 | |||
| 227 | 5060 | static av_always_inline int is_id3v2_format(const AVInputFormat *fmt) { | |
| 228 | 5060 | return ffifmt(fmt)->flags_internal & FF_INFMT_FLAG_ID3V2_AUTO; | |
| 229 | } | ||
| 230 | |||
| 231 | 8257 | int avformat_open_input(AVFormatContext **ps, const char *filename, | |
| 232 | const AVInputFormat *fmt, AVDictionary **options) | ||
| 233 | { | ||
| 234 | FormatContextInternal *fci; | ||
| 235 | 8257 | AVFormatContext *s = *ps; | |
| 236 | FFFormatContext *si; | ||
| 237 | 8257 | AVDictionary *tmp = NULL; | |
| 238 | 8257 | ID3v2ExtraMeta *id3v2_extra_meta = NULL; | |
| 239 | 8257 | int ret = 0; | |
| 240 | |||
| 241 |
3/4✓ Branch 0 taken 29 times.
✓ Branch 1 taken 8228 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 29 times.
|
8257 | if (!s && !(s = avformat_alloc_context())) |
| 242 | ✗ | return AVERROR(ENOMEM); | |
| 243 | 8257 | fci = ff_fc_internal(s); | |
| 244 | 8257 | si = &fci->fc; | |
| 245 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8257 times.
|
8257 | if (!s->av_class) { |
| 246 | ✗ | av_log(NULL, AV_LOG_ERROR, "Input context has not been properly allocated by avformat_alloc_context() and is not NULL either\n"); | |
| 247 | ✗ | return AVERROR(EINVAL); | |
| 248 | } | ||
| 249 |
2/2✓ Branch 0 taken 3983 times.
✓ Branch 1 taken 4274 times.
|
8257 | if (fmt) |
| 250 | 3983 | s->iformat = fmt; | |
| 251 | |||
| 252 |
2/2✓ Branch 0 taken 8241 times.
✓ Branch 1 taken 16 times.
|
8257 | if (options) |
| 253 | 8241 | av_dict_copy(&tmp, *options, 0); | |
| 254 | |||
| 255 |
2/2✓ Branch 0 taken 17 times.
✓ Branch 1 taken 8240 times.
|
8257 | if (s->pb) // must be before any goto fail |
| 256 | 17 | s->flags |= AVFMT_FLAG_CUSTOM_IO; | |
| 257 | |||
| 258 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 8257 times.
|
8257 | if ((ret = av_opt_set_dict(s, &tmp)) < 0) |
| 259 | ✗ | goto fail; | |
| 260 | |||
| 261 |
2/4✓ Branch 0 taken 8257 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 8257 times.
|
8257 | if (!(s->url = av_strdup(filename ? filename : ""))) { |
| 262 | ✗ | ret = AVERROR(ENOMEM); | |
| 263 | ✗ | goto fail; | |
| 264 | } | ||
| 265 | |||
| 266 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 8257 times.
|
8257 | if ((ret = init_input(s, filename, &tmp)) < 0) |
| 267 | ✗ | goto fail; | |
| 268 | 8257 | s->probe_score = ret; | |
| 269 | |||
| 270 |
6/6✓ Branch 0 taken 8169 times.
✓ Branch 1 taken 88 times.
✓ Branch 2 taken 4972 times.
✓ Branch 3 taken 3197 times.
✓ Branch 4 taken 4971 times.
✓ Branch 5 taken 1 times.
|
8257 | if (!s->protocol_whitelist && s->pb && s->pb->protocol_whitelist) { |
| 271 | 4971 | s->protocol_whitelist = av_strdup(s->pb->protocol_whitelist); | |
| 272 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4971 times.
|
4971 | if (!s->protocol_whitelist) { |
| 273 | ✗ | ret = AVERROR(ENOMEM); | |
| 274 | ✗ | goto fail; | |
| 275 | } | ||
| 276 | } | ||
| 277 | |||
| 278 |
4/6✓ Branch 0 taken 8257 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5060 times.
✓ Branch 3 taken 3197 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 5060 times.
|
8257 | if (!s->protocol_blacklist && s->pb && s->pb->protocol_blacklist) { |
| 279 | ✗ | s->protocol_blacklist = av_strdup(s->pb->protocol_blacklist); | |
| 280 | ✗ | if (!s->protocol_blacklist) { | |
| 281 | ✗ | ret = AVERROR(ENOMEM); | |
| 282 | ✗ | goto fail; | |
| 283 | } | ||
| 284 | } | ||
| 285 | |||
| 286 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 8257 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
8257 | if (s->format_whitelist && av_match_list(s->iformat->name, s->format_whitelist, ',') <= 0) { |
| 287 | ✗ | av_log(s, AV_LOG_ERROR, "Format not on whitelist \'%s\'\n", s->format_whitelist); | |
| 288 | ✗ | ret = AVERROR(EINVAL); | |
| 289 | ✗ | goto fail; | |
| 290 | } | ||
| 291 | |||
| 292 | 8257 | avio_skip(s->pb, s->skip_initial_bytes); | |
| 293 | |||
| 294 | /* Check filename in case an image number is expected. */ | ||
| 295 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8257 times.
|
8257 | if (s->iformat->flags & AVFMT_NEEDNUMBER) { |
| 296 | ✗ | if (!av_filename_number_test(filename)) { | |
| 297 | ✗ | ret = AVERROR(EINVAL); | |
| 298 | ✗ | goto fail; | |
| 299 | } | ||
| 300 | } | ||
| 301 | |||
| 302 | 8257 | s->duration = s->start_time = AV_NOPTS_VALUE; | |
| 303 | |||
| 304 | /* Allocate private data. */ | ||
| 305 |
2/2✓ Branch 1 taken 8074 times.
✓ Branch 2 taken 183 times.
|
8257 | if (ffifmt(s->iformat)->priv_data_size > 0) { |
| 306 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 8074 times.
|
8074 | if (!(s->priv_data = av_mallocz(ffifmt(s->iformat)->priv_data_size))) { |
| 307 | ✗ | ret = AVERROR(ENOMEM); | |
| 308 | ✗ | goto fail; | |
| 309 | } | ||
| 310 |
2/2✓ Branch 0 taken 7097 times.
✓ Branch 1 taken 977 times.
|
8074 | if (s->iformat->priv_class) { |
| 311 | 7097 | *(const AVClass **) s->priv_data = s->iformat->priv_class; | |
| 312 | 7097 | av_opt_set_defaults(s->priv_data); | |
| 313 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 7097 times.
|
7097 | if ((ret = av_opt_set_dict(s->priv_data, &tmp)) < 0) |
| 314 | ✗ | goto fail; | |
| 315 | } | ||
| 316 | } | ||
| 317 | |||
| 318 | /* e.g. AVFMT_NOFILE formats will not have an AVIOContext */ | ||
| 319 |
4/4✓ Branch 0 taken 5060 times.
✓ Branch 1 taken 3197 times.
✓ Branch 3 taken 791 times.
✓ Branch 4 taken 4269 times.
|
8257 | if (s->pb && is_id3v2_format(s->iformat)) |
| 320 | 791 | ff_id3v2_read_dict(s, s->pb, &si->id3v2_meta, ID3v2_DEFAULT_MAGIC, &id3v2_extra_meta); | |
| 321 | |||
| 322 |
1/2✓ Branch 1 taken 8257 times.
✗ Branch 2 not taken.
|
8257 | if (ffifmt(s->iformat)->read_header) |
| 323 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 3 taken 8256 times.
|
8257 | if ((ret = ffifmt(s->iformat)->read_header(s)) < 0) { |
| 324 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (ffifmt(s->iformat)->flags_internal & FF_INFMT_FLAG_INIT_CLEANUP) |
| 325 | ✗ | goto close; | |
| 326 | 1 | goto fail; | |
| 327 | } | ||
| 328 | |||
| 329 |
2/2✓ Branch 0 taken 6690 times.
✓ Branch 1 taken 1566 times.
|
8256 | if (!s->metadata) { |
| 330 | 6690 | s->metadata = si->id3v2_meta; | |
| 331 | 6690 | si->id3v2_meta = NULL; | |
| 332 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1566 times.
|
1566 | } else if (si->id3v2_meta) { |
| 333 | ✗ | av_log(s, AV_LOG_WARNING, "Discarding ID3 tags because more suitable tags were found.\n"); | |
| 334 | ✗ | av_dict_free(&si->id3v2_meta); | |
| 335 | } | ||
| 336 | |||
| 337 |
2/2✓ Branch 0 taken 31 times.
✓ Branch 1 taken 8225 times.
|
8256 | if (id3v2_extra_meta) { |
| 338 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 31 times.
|
31 | if ((ret = ff_id3v2_parse_apic(s, id3v2_extra_meta)) < 0) |
| 339 | ✗ | goto close; | |
| 340 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 31 times.
|
31 | if ((ret = ff_id3v2_parse_chapters(s, id3v2_extra_meta)) < 0) |
| 341 | ✗ | goto close; | |
| 342 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 31 times.
|
31 | if ((ret = ff_id3v2_parse_priv(s, id3v2_extra_meta)) < 0) |
| 343 | ✗ | goto close; | |
| 344 | 31 | ff_id3v2_free_extra_meta(&id3v2_extra_meta); | |
| 345 | } | ||
| 346 | |||
| 347 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 8256 times.
|
8256 | if ((ret = avformat_queue_attached_pictures(s)) < 0) |
| 348 | ✗ | goto close; | |
| 349 | |||
| 350 |
4/4✓ Branch 0 taken 5059 times.
✓ Branch 1 taken 3197 times.
✓ Branch 2 taken 4524 times.
✓ Branch 3 taken 535 times.
|
8256 | if (s->pb && !si->data_offset) |
| 351 | 4524 | si->data_offset = avio_tell(s->pb); | |
| 352 | |||
| 353 | 8256 | fci->raw_packet_buffer_size = 0; | |
| 354 | |||
| 355 | 8256 | update_stream_avctx(s); | |
| 356 | |||
| 357 |
2/2✓ Branch 0 taken 8240 times.
✓ Branch 1 taken 16 times.
|
8256 | if (options) { |
| 358 | 8240 | av_dict_free(options); | |
| 359 | 8240 | *options = tmp; | |
| 360 | } | ||
| 361 | 8256 | *ps = s; | |
| 362 | 8256 | return 0; | |
| 363 | |||
| 364 | ✗ | close: | |
| 365 | ✗ | if (ffifmt(s->iformat)->read_close) | |
| 366 | ✗ | ffifmt(s->iformat)->read_close(s); | |
| 367 | ✗ | fail: | |
| 368 | 1 | ff_id3v2_free_extra_meta(&id3v2_extra_meta); | |
| 369 | 1 | av_dict_free(&tmp); | |
| 370 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | if (s->pb && !(s->flags & AVFMT_FLAG_CUSTOM_IO)) |
| 371 | 1 | ff_format_io_close(s, &s->pb); | |
| 372 | 1 | avformat_free_context(s); | |
| 373 | 1 | *ps = NULL; | |
| 374 | 1 | return ret; | |
| 375 | } | ||
| 376 | |||
| 377 | 8258 | void avformat_close_input(AVFormatContext **ps) | |
| 378 | { | ||
| 379 | AVFormatContext *s; | ||
| 380 | AVIOContext *pb; | ||
| 381 | |||
| 382 |
3/4✓ Branch 0 taken 8258 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 8256 times.
|
8258 | if (!ps || !*ps) |
| 383 | 2 | return; | |
| 384 | |||
| 385 | 8256 | s = *ps; | |
| 386 | 8256 | pb = s->pb; | |
| 387 | |||
| 388 |
5/6✓ Branch 0 taken 8256 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5107 times.
✓ Branch 3 taken 3149 times.
✓ Branch 4 taken 5032 times.
✓ Branch 5 taken 75 times.
|
8256 | if ((s->iformat && strcmp(s->iformat->name, "image2") && s->iformat->flags & AVFMT_NOFILE) || |
| 389 |
2/2✓ Branch 0 taken 17 times.
✓ Branch 1 taken 8164 times.
|
8181 | (s->flags & AVFMT_FLAG_CUSTOM_IO)) |
| 390 | 92 | pb = NULL; | |
| 391 | |||
| 392 |
1/2✓ Branch 0 taken 8256 times.
✗ Branch 1 not taken.
|
8256 | if (s->iformat) |
| 393 |
2/2✓ Branch 1 taken 5340 times.
✓ Branch 2 taken 2916 times.
|
8256 | if (ffifmt(s->iformat)->read_close) |
| 394 | 5340 | ffifmt(s->iformat)->read_close(s); | |
| 395 | |||
| 396 | 8256 | ff_format_io_close(s, &pb); | |
| 397 | 8256 | avformat_free_context(s); | |
| 398 | |||
| 399 | 8256 | *ps = NULL; | |
| 400 | } | ||
| 401 | |||
| 402 | 1136990 | static void force_codec_ids(AVFormatContext *s, AVStream *st) | |
| 403 | { | ||
| 404 |
5/5✓ Branch 0 taken 756414 times.
✓ Branch 1 taken 376928 times.
✓ Branch 2 taken 3450 times.
✓ Branch 3 taken 196 times.
✓ Branch 4 taken 2 times.
|
1136990 | switch (st->codecpar->codec_type) { |
| 405 | 756414 | case AVMEDIA_TYPE_VIDEO: | |
| 406 |
2/2✓ Branch 0 taken 118517 times.
✓ Branch 1 taken 637897 times.
|
756414 | if (s->video_codec_id) |
| 407 | 118517 | st->codecpar->codec_id = s->video_codec_id; | |
| 408 | 756414 | break; | |
| 409 | 376928 | case AVMEDIA_TYPE_AUDIO: | |
| 410 |
2/2✓ Branch 0 taken 4619 times.
✓ Branch 1 taken 372309 times.
|
376928 | if (s->audio_codec_id) |
| 411 | 4619 | st->codecpar->codec_id = s->audio_codec_id; | |
| 412 | 376928 | break; | |
| 413 | 3450 | case AVMEDIA_TYPE_SUBTITLE: | |
| 414 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3450 times.
|
3450 | if (s->subtitle_codec_id) |
| 415 | ✗ | st->codecpar->codec_id = s->subtitle_codec_id; | |
| 416 | 3450 | break; | |
| 417 | 196 | case AVMEDIA_TYPE_DATA: | |
| 418 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 196 times.
|
196 | if (s->data_codec_id) |
| 419 | ✗ | st->codecpar->codec_id = s->data_codec_id; | |
| 420 | 196 | break; | |
| 421 | } | ||
| 422 | 1136990 | } | |
| 423 | |||
| 424 | 23900 | static int probe_codec(AVFormatContext *s, AVStream *st, const AVPacket *pkt) | |
| 425 | { | ||
| 426 | 23900 | FormatContextInternal *const fci = ff_fc_internal(s); | |
| 427 | 23900 | FFStream *const sti = ffstream(st); | |
| 428 | |||
| 429 |
2/2✓ Branch 0 taken 17657 times.
✓ Branch 1 taken 6243 times.
|
23900 | if (sti->request_probe > 0) { |
| 430 | 17657 | AVProbeData *const pd = &sti->probe_data; | |
| 431 | int end; | ||
| 432 | 17657 | av_log(s, AV_LOG_DEBUG, "probing stream %d pp:%d\n", st->index, sti->probe_packets); | |
| 433 | 17657 | --sti->probe_packets; | |
| 434 | |||
| 435 |
2/2✓ Branch 0 taken 17640 times.
✓ Branch 1 taken 17 times.
|
17657 | if (pkt) { |
| 436 | 17640 | uint8_t *new_buf = av_realloc(pd->buf, pd->buf_size+pkt->size+AVPROBE_PADDING_SIZE); | |
| 437 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 17640 times.
|
17640 | if (!new_buf) { |
| 438 | ✗ | av_log(s, AV_LOG_WARNING, | |
| 439 | "Failed to reallocate probe buffer for stream %d\n", | ||
| 440 | st->index); | ||
| 441 | ✗ | goto no_packet; | |
| 442 | } | ||
| 443 | 17640 | pd->buf = new_buf; | |
| 444 | 17640 | memcpy(pd->buf + pd->buf_size, pkt->data, pkt->size); | |
| 445 | 17640 | pd->buf_size += pkt->size; | |
| 446 | 17640 | memset(pd->buf + pd->buf_size, 0, AVPROBE_PADDING_SIZE); | |
| 447 | } else { | ||
| 448 | 17 | no_packet: | |
| 449 | 17 | sti->probe_packets = 0; | |
| 450 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
|
17 | if (!pd->buf_size) { |
| 451 | ✗ | av_log(s, AV_LOG_WARNING, | |
| 452 | "nothing to probe for stream %d\n", st->index); | ||
| 453 | } | ||
| 454 | } | ||
| 455 | |||
| 456 |
1/2✓ Branch 0 taken 17657 times.
✗ Branch 1 not taken.
|
35314 | end = fci->raw_packet_buffer_size >= s->probesize || |
| 457 |
2/2✓ Branch 0 taken 554 times.
✓ Branch 1 taken 17103 times.
|
17657 | sti->probe_packets <= 0; |
| 458 | |||
| 459 |
4/4✓ Branch 0 taken 17103 times.
✓ Branch 1 taken 554 times.
✓ Branch 2 taken 2818 times.
✓ Branch 3 taken 14285 times.
|
17657 | if (end || av_log2(pd->buf_size) != av_log2(pd->buf_size - pkt->size)) { |
| 460 | 3372 | int score = set_codec_from_probe_data(s, st, pd); | |
| 461 |
4/4✓ Branch 0 taken 3364 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 3343 times.
✓ Branch 3 taken 21 times.
|
3372 | if ( (st->codecpar->codec_id != AV_CODEC_ID_NONE && score > AVPROBE_SCORE_STREAM_RETRY) |
| 462 |
2/2✓ Branch 0 taken 554 times.
✓ Branch 1 taken 2797 times.
|
3351 | || end) { |
| 463 | 575 | pd->buf_size = 0; | |
| 464 | 575 | av_freep(&pd->buf); | |
| 465 | 575 | sti->request_probe = -1; | |
| 466 |
1/2✓ Branch 0 taken 575 times.
✗ Branch 1 not taken.
|
575 | if (st->codecpar->codec_id != AV_CODEC_ID_NONE) { |
| 467 | 575 | av_log(s, AV_LOG_DEBUG, "probed stream %d\n", st->index); | |
| 468 | } else | ||
| 469 | ✗ | av_log(s, AV_LOG_WARNING, "probed stream %d failed\n", st->index); | |
| 470 | } | ||
| 471 | 3372 | force_codec_ids(s, st); | |
| 472 | } | ||
| 473 | } | ||
| 474 | 23900 | return 0; | |
| 475 | } | ||
| 476 | |||
| 477 | 1133618 | static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_index, AVPacket *pkt) | |
| 478 | { | ||
| 479 | 1133618 | FFStream *const sti = ffstream(st); | |
| 480 | 1133618 | int64_t ref = pkt->dts; | |
| 481 | int pts_wrap_behavior; | ||
| 482 | int64_t pts_wrap_reference; | ||
| 483 | AVProgram *first_program; | ||
| 484 | |||
| 485 |
2/2✓ Branch 0 taken 925691 times.
✓ Branch 1 taken 207927 times.
|
1133618 | if (ref == AV_NOPTS_VALUE) |
| 486 | 925691 | ref = pkt->pts; | |
| 487 |
7/8✓ Branch 0 taken 1059470 times.
✓ Branch 1 taken 74148 times.
✓ Branch 2 taken 58867 times.
✓ Branch 3 taken 1000603 times.
✓ Branch 4 taken 1002 times.
✓ Branch 5 taken 57865 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1002 times.
|
1133618 | if (sti->pts_wrap_reference != AV_NOPTS_VALUE || st->pts_wrap_bits >= 63 || ref == AV_NOPTS_VALUE || !s->correct_ts_overflow) |
| 488 | 1132616 | return 0; | |
| 489 | 1002 | ref &= (1LL << st->pts_wrap_bits)-1; | |
| 490 | |||
| 491 | // reference time stamp should be 60 s before first time stamp | ||
| 492 | 1002 | pts_wrap_reference = ref - av_rescale(60, st->time_base.den, st->time_base.num); | |
| 493 | // if first time stamp is not more than 1/8 and 60s before the wrap point, subtract rather than add wrap offset | ||
| 494 | 2005 | pts_wrap_behavior = (ref < (1LL << st->pts_wrap_bits) - (1LL << st->pts_wrap_bits-3)) || | |
| 495 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | (ref < (1LL << st->pts_wrap_bits) - av_rescale(60, st->time_base.den, st->time_base.num)) ? |
| 496 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1001 times.
|
1003 | AV_PTS_WRAP_ADD_OFFSET : AV_PTS_WRAP_SUB_OFFSET; |
| 497 | |||
| 498 | 1002 | first_program = av_find_program_from_stream(s, NULL, stream_index); | |
| 499 | |||
| 500 |
2/2✓ Branch 0 taken 215 times.
✓ Branch 1 taken 787 times.
|
1002 | if (!first_program) { |
| 501 | 215 | int default_stream_index = av_find_default_stream_index(s); | |
| 502 | 215 | FFStream *const default_sti = ffstream(s->streams[default_stream_index]); | |
| 503 |
2/2✓ Branch 0 taken 204 times.
✓ Branch 1 taken 11 times.
|
215 | if (default_sti->pts_wrap_reference == AV_NOPTS_VALUE) { |
| 504 |
2/2✓ Branch 0 taken 397 times.
✓ Branch 1 taken 204 times.
|
601 | for (unsigned i = 0; i < s->nb_streams; i++) { |
| 505 | 397 | FFStream *const sti = ffstream(s->streams[i]); | |
| 506 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 397 times.
|
397 | if (av_find_program_from_stream(s, NULL, i)) |
| 507 | ✗ | continue; | |
| 508 | 397 | sti->pts_wrap_reference = pts_wrap_reference; | |
| 509 | 397 | sti->pts_wrap_behavior = pts_wrap_behavior; | |
| 510 | } | ||
| 511 | } else { | ||
| 512 | 11 | sti->pts_wrap_reference = default_sti->pts_wrap_reference; | |
| 513 | 11 | sti->pts_wrap_behavior = default_sti->pts_wrap_behavior; | |
| 514 | } | ||
| 515 | } else { | ||
| 516 | 787 | AVProgram *program = first_program; | |
| 517 |
2/2✓ Branch 0 taken 787 times.
✓ Branch 1 taken 94 times.
|
881 | while (program) { |
| 518 |
2/2✓ Branch 0 taken 693 times.
✓ Branch 1 taken 94 times.
|
787 | if (program->pts_wrap_reference != AV_NOPTS_VALUE) { |
| 519 | 693 | pts_wrap_reference = program->pts_wrap_reference; | |
| 520 | 693 | pts_wrap_behavior = program->pts_wrap_behavior; | |
| 521 | 693 | break; | |
| 522 | } | ||
| 523 | 94 | program = av_find_program_from_stream(s, program, stream_index); | |
| 524 | } | ||
| 525 | |||
| 526 | // update every program with differing pts_wrap_reference | ||
| 527 | 787 | program = first_program; | |
| 528 |
2/2✓ Branch 0 taken 787 times.
✓ Branch 1 taken 787 times.
|
1574 | while (program) { |
| 529 |
2/2✓ Branch 0 taken 94 times.
✓ Branch 1 taken 693 times.
|
787 | if (program->pts_wrap_reference != pts_wrap_reference) { |
| 530 |
2/2✓ Branch 0 taken 143 times.
✓ Branch 1 taken 94 times.
|
237 | for (unsigned i = 0; i < program->nb_stream_indexes; i++) { |
| 531 | 143 | FFStream *const sti = ffstream(s->streams[program->stream_index[i]]); | |
| 532 | 143 | sti->pts_wrap_reference = pts_wrap_reference; | |
| 533 | 143 | sti->pts_wrap_behavior = pts_wrap_behavior; | |
| 534 | } | ||
| 535 | |||
| 536 | 94 | program->pts_wrap_reference = pts_wrap_reference; | |
| 537 | 94 | program->pts_wrap_behavior = pts_wrap_behavior; | |
| 538 | } | ||
| 539 | 787 | program = av_find_program_from_stream(s, program, stream_index); | |
| 540 | } | ||
| 541 | } | ||
| 542 | 1002 | return 1; | |
| 543 | } | ||
| 544 | |||
| 545 | 1133618 | static void update_timestamps(AVFormatContext *s, AVStream *st, AVPacket *pkt) | |
| 546 | { | ||
| 547 | 1133618 | FFStream *const sti = ffstream(st); | |
| 548 | |||
| 549 |
4/4✓ Branch 1 taken 1002 times.
✓ Branch 2 taken 1132616 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1001 times.
|
1133618 | if (update_wrap_reference(s, st, pkt->stream_index, pkt) && sti->pts_wrap_behavior == AV_PTS_WRAP_SUB_OFFSET) { |
| 550 | // correct first time stamps to negative values | ||
| 551 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | if (!is_relative(sti->first_dts)) |
| 552 | 1 | sti->first_dts = wrap_timestamp(st, sti->first_dts); | |
| 553 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | if (!is_relative(st->start_time)) |
| 554 | 1 | st->start_time = wrap_timestamp(st, st->start_time); | |
| 555 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (!is_relative(sti->cur_dts)) |
| 556 | ✗ | sti->cur_dts = wrap_timestamp(st, sti->cur_dts); | |
| 557 | } | ||
| 558 | |||
| 559 | 1133618 | pkt->dts = wrap_timestamp(st, pkt->dts); | |
| 560 | 1133618 | pkt->pts = wrap_timestamp(st, pkt->pts); | |
| 561 | |||
| 562 | 1133618 | force_codec_ids(s, st); | |
| 563 | |||
| 564 | /* TODO: audio: time filter; video: frame reordering (pts != dts) */ | ||
| 565 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1133618 times.
|
1133618 | if (s->use_wallclock_as_timestamps) |
| 566 | ✗ | pkt->dts = pkt->pts = av_rescale_q(av_gettime(), AV_TIME_BASE_Q, st->time_base); | |
| 567 | 1133618 | } | |
| 568 | |||
| 569 | /** | ||
| 570 | * Handle a new packet and either return it directly if possible and | ||
| 571 | * allow_passthrough is true or queue the packet (or drop the packet | ||
| 572 | * if corrupt). | ||
| 573 | * | ||
| 574 | * @return < 0 on error, 0 if the packet was passed through, | ||
| 575 | * 1 if it was queued or dropped | ||
| 576 | */ | ||
| 577 | 1133618 | static int handle_new_packet(AVFormatContext *s, AVPacket *pkt, int allow_passthrough) | |
| 578 | { | ||
| 579 | 1133618 | FormatContextInternal *const fci = ff_fc_internal(s); | |
| 580 | AVStream *st; | ||
| 581 | FFStream *sti; | ||
| 582 | int err; | ||
| 583 | |||
| 584 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1133618 times.
|
1133618 | av_assert0(pkt->stream_index < (unsigned)s->nb_streams && |
| 585 | "Invalid stream index.\n"); | ||
| 586 | |||
| 587 |
2/2✓ Branch 0 taken 206 times.
✓ Branch 1 taken 1133412 times.
|
1133618 | if (pkt->flags & AV_PKT_FLAG_CORRUPT) { |
| 588 | 412 | av_log(s, AV_LOG_WARNING, | |
| 589 | "Packet corrupt (stream = %d, dts = %s)%s.\n", | ||
| 590 | 206 | pkt->stream_index, av_ts2str(pkt->dts), | |
| 591 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 206 times.
|
206 | s->flags & AVFMT_FLAG_DISCARD_CORRUPT ? ", dropping it" : ""); |
| 592 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 206 times.
|
206 | if (s->flags & AVFMT_FLAG_DISCARD_CORRUPT) { |
| 593 | ✗ | av_packet_unref(pkt); | |
| 594 | ✗ | return 1; | |
| 595 | } | ||
| 596 | } | ||
| 597 | |||
| 598 | 1133618 | st = s->streams[pkt->stream_index]; | |
| 599 | 1133618 | sti = ffstream(st); | |
| 600 | |||
| 601 | 1133618 | update_timestamps(s, st, pkt); | |
| 602 | |||
| 603 |
6/6✓ Branch 0 taken 1115978 times.
✓ Branch 1 taken 17640 times.
✓ Branch 2 taken 1109777 times.
✓ Branch 3 taken 6201 times.
✓ Branch 4 taken 1109735 times.
✓ Branch 5 taken 42 times.
|
1133618 | if (sti->request_probe <= 0 && allow_passthrough && !fci->raw_packet_buffer.head) |
| 604 | 1109735 | return 0; | |
| 605 | |||
| 606 | 23883 | err = ff_packet_list_put(&fci->raw_packet_buffer, pkt, NULL, 0); | |
| 607 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 23883 times.
|
23883 | if (err < 0) { |
| 608 | ✗ | av_packet_unref(pkt); | |
| 609 | ✗ | return err; | |
| 610 | } | ||
| 611 | |||
| 612 | 23883 | pkt = &fci->raw_packet_buffer.tail->pkt; | |
| 613 | 23883 | fci->raw_packet_buffer_size += pkt->size; | |
| 614 | |||
| 615 | 23883 | err = probe_codec(s, st, pkt); | |
| 616 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 23883 times.
|
23883 | if (err < 0) |
| 617 | ✗ | return err; | |
| 618 | |||
| 619 | 23883 | return 1; | |
| 620 | } | ||
| 621 | |||
| 622 | 6201 | int ff_buffer_packet(AVFormatContext *s, AVPacket *pkt) | |
| 623 | { | ||
| 624 | 6201 | int err = handle_new_packet(s, pkt, 0); | |
| 625 | |||
| 626 | 6201 | return err < 0 ? err : 0; | |
| 627 | } | ||
| 628 | |||
| 629 | 1140890 | int ff_read_packet(AVFormatContext *s, AVPacket *pkt) | |
| 630 | { | ||
| 631 | 1140890 | FormatContextInternal *const fci = ff_fc_internal(s); | |
| 632 | int err; | ||
| 633 | |||
| 634 | #if FF_API_INIT_PACKET | ||
| 635 | FF_DISABLE_DEPRECATION_WARNINGS | ||
| 636 | 1140890 | pkt->data = NULL; | |
| 637 | 1140890 | pkt->size = 0; | |
| 638 | 1140890 | av_init_packet(pkt); | |
| 639 | FF_ENABLE_DEPRECATION_WARNINGS | ||
| 640 | #else | ||
| 641 | av_packet_unref(pkt); | ||
| 642 | #endif | ||
| 643 | |||
| 644 | 24148 | for (;;) { | |
| 645 | 1165038 | PacketListEntry *pktl = fci->raw_packet_buffer.head; | |
| 646 | |||
| 647 |
2/2✓ Branch 0 taken 41063 times.
✓ Branch 1 taken 1123975 times.
|
1165038 | if (pktl) { |
| 648 | 41063 | AVStream *const st = s->streams[pktl->pkt.stream_index]; | |
| 649 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 41063 times.
|
41063 | if (fci->raw_packet_buffer_size >= s->probesize) |
| 650 | ✗ | if ((err = probe_codec(s, st, NULL)) < 0) | |
| 651 | ✗ | return err; | |
| 652 |
2/2✓ Branch 1 taken 23939 times.
✓ Branch 2 taken 17124 times.
|
41063 | if (ffstream(st)->request_probe <= 0) { |
| 653 | 23939 | ff_packet_list_get(&fci->raw_packet_buffer, pkt); | |
| 654 | 23939 | fci->raw_packet_buffer_size -= pkt->size; | |
| 655 | 23939 | return 0; | |
| 656 | } | ||
| 657 | } | ||
| 658 | |||
| 659 | 1141099 | err = ffifmt(s->iformat)->read_packet(s, pkt); | |
| 660 |
2/2✓ Branch 0 taken 13682 times.
✓ Branch 1 taken 1127417 times.
|
1141099 | if (err < 0) { |
| 661 | 13682 | av_packet_unref(pkt); | |
| 662 | |||
| 663 | /* Some demuxers return FFERROR_REDO when they consume | ||
| 664 | data and discard it (ignored streams, junk, extradata). | ||
| 665 | We must re-call the demuxer to get the real packet. */ | ||
| 666 |
2/2✓ Branch 0 taken 6449 times.
✓ Branch 1 taken 7233 times.
|
13682 | if (err == FFERROR_REDO) |
| 667 | 6449 | continue; | |
| 668 |
3/4✓ Branch 0 taken 17 times.
✓ Branch 1 taken 7216 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 17 times.
|
7233 | if (!pktl || err == AVERROR(EAGAIN)) |
| 669 | 7216 | return err; | |
| 670 |
2/2✓ Branch 0 taken 17 times.
✓ Branch 1 taken 17 times.
|
34 | for (unsigned i = 0; i < s->nb_streams; i++) { |
| 671 | 17 | AVStream *const st = s->streams[i]; | |
| 672 | 17 | FFStream *const sti = ffstream(st); | |
| 673 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
17 | if (sti->probe_packets || sti->request_probe > 0) |
| 674 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
|
17 | if ((err = probe_codec(s, st, NULL)) < 0) |
| 675 | ✗ | return err; | |
| 676 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
|
17 | av_assert0(sti->request_probe <= 0); |
| 677 | } | ||
| 678 | 17 | continue; | |
| 679 | } | ||
| 680 | |||
| 681 | 1127417 | err = av_packet_make_refcounted(pkt); | |
| 682 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1127417 times.
|
1127417 | if (err < 0) { |
| 683 | ✗ | av_packet_unref(pkt); | |
| 684 | ✗ | return err; | |
| 685 | } | ||
| 686 | |||
| 687 | 1127417 | err = handle_new_packet(s, pkt, 1); | |
| 688 |
2/2✓ Branch 0 taken 1109735 times.
✓ Branch 1 taken 17682 times.
|
1127417 | if (err <= 0) /* Error or passthrough */ |
| 689 | 1109735 | return err; | |
| 690 | } | ||
| 691 | } | ||
| 692 | |||
| 693 | /** | ||
| 694 | * Return the frame duration in seconds. Return 0 if not available. | ||
| 695 | */ | ||
| 696 | 334743 | static void compute_frame_duration(AVFormatContext *s, int *pnum, int *pden, | |
| 697 | AVStream *st, AVCodecParserContext *pc, | ||
| 698 | AVPacket *pkt) | ||
| 699 | { | ||
| 700 | 334743 | FFStream *const sti = ffstream(st); | |
| 701 | 334743 | AVRational codec_framerate = sti->avctx->framerate; | |
| 702 | int frame_size, sample_rate; | ||
| 703 | |||
| 704 | 334743 | *pnum = 0; | |
| 705 | 334743 | *pden = 0; | |
| 706 |
3/3✓ Branch 0 taken 228150 times.
✓ Branch 1 taken 105001 times.
✓ Branch 2 taken 1592 times.
|
334743 | switch (st->codecpar->codec_type) { |
| 707 | 228150 | case AVMEDIA_TYPE_VIDEO: | |
| 708 |
6/6✓ Branch 0 taken 196785 times.
✓ Branch 1 taken 31365 times.
✓ Branch 2 taken 43357 times.
✓ Branch 3 taken 153428 times.
✓ Branch 4 taken 31062 times.
✓ Branch 5 taken 12295 times.
|
228150 | if (st->r_frame_rate.num && (!pc || !codec_framerate.num)) { |
| 709 | 184490 | *pnum = st->r_frame_rate.den; | |
| 710 | 184490 | *pden = st->r_frame_rate.num; | |
| 711 |
2/2✓ Branch 0 taken 24665 times.
✓ Branch 1 taken 18995 times.
|
43660 | } else if ((s->iformat->flags & AVFMT_NOTIMESTAMPS) && |
| 712 |
2/2✓ Branch 0 taken 15243 times.
✓ Branch 1 taken 9422 times.
|
24665 | !codec_framerate.num && |
| 713 |
3/4✓ Branch 0 taken 15241 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 15241 times.
✗ Branch 3 not taken.
|
15243 | st->avg_frame_rate.num && st->avg_frame_rate.den) { |
| 714 | 15241 | *pnum = st->avg_frame_rate.den; | |
| 715 | 15241 | *pden = st->avg_frame_rate.num; | |
| 716 |
2/2✓ Branch 0 taken 9172 times.
✓ Branch 1 taken 19247 times.
|
28419 | } else if (st->time_base.num * 1000LL > st->time_base.den) { |
| 717 | 9172 | *pnum = st->time_base.num; | |
| 718 | 9172 | *pden = st->time_base.den; | |
| 719 |
2/2✓ Branch 0 taken 19222 times.
✓ Branch 1 taken 25 times.
|
19247 | } else if (codec_framerate.den * 1000LL > codec_framerate.num) { |
| 720 | 57666 | int ticks_per_frame = (sti->codec_desc && | |
| 721 |
3/4✓ Branch 0 taken 19222 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13315 times.
✓ Branch 3 taken 5907 times.
|
19222 | (sti->codec_desc->props & AV_CODEC_PROP_FIELDS)) ? 2 : 1; |
| 722 | 19222 | av_reduce(pnum, pden, | |
| 723 | 19222 | codec_framerate.den, | |
| 724 | 19222 | codec_framerate.num * (int64_t)ticks_per_frame, | |
| 725 | INT_MAX); | ||
| 726 | |||
| 727 |
4/4✓ Branch 0 taken 17389 times.
✓ Branch 1 taken 1833 times.
✓ Branch 2 taken 12685 times.
✓ Branch 3 taken 4704 times.
|
19222 | if (pc && pc->repeat_pict) { |
| 728 | 12685 | av_reduce(pnum, pden, | |
| 729 | 12685 | (*pnum) * (1LL + pc->repeat_pict), | |
| 730 | 12685 | (*pden), | |
| 731 | INT_MAX); | ||
| 732 | } | ||
| 733 | /* If this codec can be interlaced or progressive then we need | ||
| 734 | * a parser to compute duration of a packet. Thus if we have | ||
| 735 | * no parser in such case leave duration undefined. */ | ||
| 736 |
1/2✓ Branch 0 taken 19222 times.
✗ Branch 1 not taken.
|
19222 | if (sti->codec_desc && |
| 737 |
3/4✓ Branch 0 taken 13315 times.
✓ Branch 1 taken 5907 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 13315 times.
|
19222 | (sti->codec_desc->props & AV_CODEC_PROP_FIELDS) && !pc) |
| 738 | ✗ | *pnum = *pden = 0; | |
| 739 | } | ||
| 740 | 228150 | break; | |
| 741 | 105001 | case AVMEDIA_TYPE_AUDIO: | |
| 742 |
2/2✓ Branch 0 taken 46936 times.
✓ Branch 1 taken 58065 times.
|
105001 | if (sti->avctx_inited) { |
| 743 | 46936 | frame_size = av_get_audio_frame_duration(sti->avctx, pkt->size); | |
| 744 | 46936 | sample_rate = sti->avctx->sample_rate; | |
| 745 | } else { | ||
| 746 | 58065 | frame_size = av_get_audio_frame_duration2(st->codecpar, pkt->size); | |
| 747 | 58065 | sample_rate = st->codecpar->sample_rate; | |
| 748 | } | ||
| 749 |
4/4✓ Branch 0 taken 99567 times.
✓ Branch 1 taken 5434 times.
✓ Branch 2 taken 99562 times.
✓ Branch 3 taken 5 times.
|
105001 | if (frame_size <= 0 || sample_rate <= 0) |
| 750 | break; | ||
| 751 | 99562 | *pnum = frame_size; | |
| 752 | 99562 | *pden = sample_rate; | |
| 753 | 99562 | break; | |
| 754 | 1592 | default: | |
| 755 | 1592 | break; | |
| 756 | } | ||
| 757 | 334743 | } | |
| 758 | |||
| 759 | 804642 | static int has_decode_delay_been_guessed(AVStream *st) | |
| 760 | { | ||
| 761 | 804642 | FFStream *const sti = ffstream(st); | |
| 762 |
2/2✓ Branch 0 taken 786692 times.
✓ Branch 1 taken 17950 times.
|
804642 | if (st->codecpar->codec_id != AV_CODEC_ID_H264) return 1; |
| 763 |
2/2✓ Branch 0 taken 6422 times.
✓ Branch 1 taken 11528 times.
|
17950 | if (!sti->info) // if we have left find_stream_info then nb_decoded_frames won't increase anymore for stream copy |
| 764 | 6422 | return 1; | |
| 765 |
1/6✗ Branch 0 not taken.
✓ Branch 1 taken 11528 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
11528 | av_assert0(sti->avctx->codec_id == AV_CODEC_ID_H264 || (sti->avctx->codec_id == AV_CODEC_ID_NONE && !avcodec_is_open(sti->avctx))); |
| 766 | #if CONFIG_H264_DECODER | ||
| 767 |
4/4✓ Branch 0 taken 7074 times.
✓ Branch 1 taken 4454 times.
✓ Branch 3 taken 6949 times.
✓ Branch 4 taken 125 times.
|
11528 | if (sti->avctx->has_b_frames && avcodec_is_open(sti->avctx) && |
| 768 |
2/2✓ Branch 1 taken 1703 times.
✓ Branch 2 taken 5246 times.
|
6949 | avpriv_h264_has_num_reorder_frames(sti->avctx) == sti->avctx->has_b_frames) |
| 769 | 1703 | return 1; | |
| 770 | #endif | ||
| 771 |
2/2✓ Branch 0 taken 9635 times.
✓ Branch 1 taken 190 times.
|
9825 | if (sti->avctx->has_b_frames < 3) |
| 772 | 9635 | return sti->nb_decoded_frames >= 7; | |
| 773 |
2/2✓ Branch 0 taken 36 times.
✓ Branch 1 taken 154 times.
|
190 | else if (sti->avctx->has_b_frames < 4) |
| 774 | 36 | return sti->nb_decoded_frames >= 18; | |
| 775 | else | ||
| 776 | 154 | return sti->nb_decoded_frames >= 20; | |
| 777 | } | ||
| 778 | |||
| 779 | 37375 | static PacketListEntry *get_next_pkt(AVFormatContext *s, AVStream *st, | |
| 780 | PacketListEntry *pktl) | ||
| 781 | { | ||
| 782 | 37375 | FormatContextInternal *const fci = ff_fc_internal(s); | |
| 783 | 37375 | FFFormatContext *const si = &fci->fc; | |
| 784 |
2/2✓ Branch 0 taken 35253 times.
✓ Branch 1 taken 2122 times.
|
37375 | if (pktl->next) |
| 785 | 35253 | return pktl->next; | |
| 786 |
2/2✓ Branch 0 taken 2090 times.
✓ Branch 1 taken 32 times.
|
2122 | if (pktl == si->packet_buffer.tail) |
| 787 | 2090 | return fci->parse_queue.head; | |
| 788 | 32 | return NULL; | |
| 789 | } | ||
| 790 | |||
| 791 | 595881 | static int64_t select_from_pts_buffer(AVStream *st, int64_t *pts_buffer, int64_t dts) | |
| 792 | { | ||
| 793 | 595881 | FFStream *const sti = ffstream(st); | |
| 794 | 1779853 | int onein_oneout = st->codecpar->codec_id != AV_CODEC_ID_H264 && | |
| 795 |
4/4✓ Branch 0 taken 588091 times.
✓ Branch 1 taken 7790 times.
✓ Branch 2 taken 586459 times.
✓ Branch 3 taken 1632 times.
|
1182340 | st->codecpar->codec_id != AV_CODEC_ID_HEVC && |
| 796 |
2/2✓ Branch 0 taken 586243 times.
✓ Branch 1 taken 216 times.
|
586459 | st->codecpar->codec_id != AV_CODEC_ID_VVC; |
| 797 | |||
| 798 |
2/2✓ Branch 0 taken 9638 times.
✓ Branch 1 taken 586243 times.
|
595881 | if (!onein_oneout) { |
| 799 | 9638 | int delay = sti->avctx->has_b_frames; | |
| 800 | |||
| 801 |
2/2✓ Branch 0 taken 1404 times.
✓ Branch 1 taken 8234 times.
|
9638 | if (dts == AV_NOPTS_VALUE) { |
| 802 | 1404 | int64_t best_score = INT64_MAX; | |
| 803 |
2/2✓ Branch 0 taken 1709 times.
✓ Branch 1 taken 1404 times.
|
3113 | for (int i = 0; i < delay; i++) { |
| 804 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1709 times.
|
1709 | if (sti->pts_reorder_error_count[i]) { |
| 805 | ✗ | int64_t score = sti->pts_reorder_error[i] / sti->pts_reorder_error_count[i]; | |
| 806 | ✗ | if (score < best_score) { | |
| 807 | ✗ | best_score = score; | |
| 808 | ✗ | dts = pts_buffer[i]; | |
| 809 | } | ||
| 810 | } | ||
| 811 | } | ||
| 812 | } else { | ||
| 813 |
2/2✓ Branch 0 taken 14597 times.
✓ Branch 1 taken 8234 times.
|
22831 | for (int i = 0; i < delay; i++) { |
| 814 |
2/2✓ Branch 0 taken 13623 times.
✓ Branch 1 taken 974 times.
|
14597 | if (pts_buffer[i] != AV_NOPTS_VALUE) { |
| 815 | #define ABSDIFF(a,b) (((a) < (b)) ? (b) - (uint64_t)(a) : ((a) - (uint64_t)(b))) | ||
| 816 |
2/2✓ Branch 0 taken 4165 times.
✓ Branch 1 taken 9458 times.
|
13623 | uint64_t diff = ABSDIFF(pts_buffer[i], dts); |
| 817 | |||
| 818 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 13623 times.
|
13623 | if (diff > INT64_MAX - sti->pts_reorder_error[i]) { |
| 819 | ✗ | diff = INT64_MAX; | |
| 820 | } else | ||
| 821 | 13623 | diff += sti->pts_reorder_error[i]; | |
| 822 | |||
| 823 | 13623 | sti->pts_reorder_error[i] = diff; | |
| 824 | 13623 | sti->pts_reorder_error_count[i]++; | |
| 825 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 13620 times.
|
13623 | if (sti->pts_reorder_error_count[i] > 250) { |
| 826 | 3 | sti->pts_reorder_error[i] >>= 1; | |
| 827 | 3 | sti->pts_reorder_error_count[i] >>= 1; | |
| 828 | } | ||
| 829 | } | ||
| 830 | } | ||
| 831 | } | ||
| 832 | } | ||
| 833 | |||
| 834 |
2/2✓ Branch 0 taken 1779 times.
✓ Branch 1 taken 594102 times.
|
595881 | if (dts == AV_NOPTS_VALUE) |
| 835 | 1779 | dts = pts_buffer[0]; | |
| 836 | |||
| 837 | 595881 | return dts; | |
| 838 | } | ||
| 839 | |||
| 840 | /** | ||
| 841 | * Updates the dts of packets of a stream in pkt_buffer, by re-ordering the pts | ||
| 842 | * of the packets in a window. | ||
| 843 | */ | ||
| 844 | 6539 | static void update_dts_from_pts(AVFormatContext *s, int stream_index, | |
| 845 | PacketListEntry *pkt_buffer) | ||
| 846 | { | ||
| 847 | 6539 | AVStream *const st = s->streams[stream_index]; | |
| 848 | 6539 | int delay = ffstream(st)->avctx->has_b_frames; | |
| 849 | |||
| 850 | int64_t pts_buffer[MAX_REORDER_DELAY+1]; | ||
| 851 | |||
| 852 |
2/2✓ Branch 0 taken 111163 times.
✓ Branch 1 taken 6539 times.
|
117702 | for (int i = 0; i < MAX_REORDER_DELAY + 1; i++) |
| 853 | 111163 | pts_buffer[i] = AV_NOPTS_VALUE; | |
| 854 | |||
| 855 |
2/2✓ Branch 1 taken 5722 times.
✓ Branch 2 taken 6539 times.
|
12261 | for (; pkt_buffer; pkt_buffer = get_next_pkt(s, st, pkt_buffer)) { |
| 856 |
2/2✓ Branch 0 taken 5025 times.
✓ Branch 1 taken 697 times.
|
5722 | if (pkt_buffer->pkt.stream_index != stream_index) |
| 857 | 5025 | continue; | |
| 858 | |||
| 859 |
3/4✓ Branch 0 taken 599 times.
✓ Branch 1 taken 98 times.
✓ Branch 2 taken 599 times.
✗ Branch 3 not taken.
|
697 | if (pkt_buffer->pkt.pts != AV_NOPTS_VALUE && delay <= MAX_REORDER_DELAY) { |
| 860 | 599 | pts_buffer[0] = pkt_buffer->pkt.pts; | |
| 861 |
4/4✓ Branch 0 taken 419 times.
✓ Branch 1 taken 434 times.
✓ Branch 2 taken 254 times.
✓ Branch 3 taken 165 times.
|
853 | for (int i = 0; i < delay && pts_buffer[i] > pts_buffer[i + 1]; i++) |
| 862 | 254 | FFSWAP(int64_t, pts_buffer[i], pts_buffer[i + 1]); | |
| 863 | |||
| 864 | 599 | pkt_buffer->pkt.dts = select_from_pts_buffer(st, pts_buffer, pkt_buffer->pkt.dts); | |
| 865 | } | ||
| 866 | } | ||
| 867 | 6539 | } | |
| 868 | |||
| 869 | 638066 | static void update_initial_timestamps(AVFormatContext *s, int stream_index, | |
| 870 | int64_t dts, int64_t pts, AVPacket *pkt) | ||
| 871 | { | ||
| 872 | 638066 | FormatContextInternal *const fci = ff_fc_internal(s); | |
| 873 | 638066 | FFFormatContext *const si = &fci->fc; | |
| 874 | 638066 | AVStream *const st = s->streams[stream_index]; | |
| 875 | 638066 | FFStream *const sti = ffstream(st); | |
| 876 |
2/2✓ Branch 0 taken 191216 times.
✓ Branch 1 taken 446850 times.
|
638066 | PacketListEntry *pktl = si->packet_buffer.head ? si->packet_buffer.head : fci->parse_queue.head; |
| 877 | |||
| 878 | uint64_t shift; | ||
| 879 | |||
| 880 |
4/4✓ Branch 0 taken 229472 times.
✓ Branch 1 taken 408594 times.
✓ Branch 2 taken 6620 times.
✓ Branch 3 taken 222852 times.
|
638066 | if (sti->first_dts != AV_NOPTS_VALUE || |
| 881 | 6620 | dts == AV_NOPTS_VALUE || | |
| 882 |
1/2✓ Branch 0 taken 6620 times.
✗ Branch 1 not taken.
|
6620 | sti->cur_dts == AV_NOPTS_VALUE || |
| 883 |
1/2✓ Branch 0 taken 6620 times.
✗ Branch 1 not taken.
|
6620 | sti->cur_dts < INT_MIN + RELATIVE_TS_BASE || |
| 884 |
2/4✓ Branch 0 taken 6620 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6620 times.
|
13240 | dts < INT_MIN + (sti->cur_dts - RELATIVE_TS_BASE) || |
| 885 | 6620 | is_relative(dts)) | |
| 886 | 631446 | return; | |
| 887 | |||
| 888 | 6620 | sti->first_dts = dts - (sti->cur_dts - RELATIVE_TS_BASE); | |
| 889 | 6620 | sti->cur_dts = dts; | |
| 890 | 6620 | shift = (uint64_t)sti->first_dts - RELATIVE_TS_BASE; | |
| 891 | |||
| 892 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 6620 times.
|
6620 | if (is_relative(pts)) |
| 893 | ✗ | pts += shift; | |
| 894 | |||
| 895 |
2/2✓ Branch 1 taken 5450 times.
✓ Branch 2 taken 6620 times.
|
12070 | for (PacketListEntry *pktl_it = pktl; pktl_it; pktl_it = get_next_pkt(s, st, pktl_it)) { |
| 896 |
2/2✓ Branch 0 taken 4956 times.
✓ Branch 1 taken 494 times.
|
5450 | if (pktl_it->pkt.stream_index != stream_index) |
| 897 | 4956 | continue; | |
| 898 |
2/2✓ Branch 1 taken 207 times.
✓ Branch 2 taken 287 times.
|
494 | if (is_relative(pktl_it->pkt.pts)) |
| 899 | 207 | pktl_it->pkt.pts += shift; | |
| 900 | |||
| 901 |
2/2✓ Branch 1 taken 235 times.
✓ Branch 2 taken 259 times.
|
494 | if (is_relative(pktl_it->pkt.dts)) |
| 902 | 235 | pktl_it->pkt.dts += shift; | |
| 903 | |||
| 904 |
4/4✓ Branch 0 taken 81 times.
✓ Branch 1 taken 413 times.
✓ Branch 2 taken 52 times.
✓ Branch 3 taken 29 times.
|
494 | if (st->start_time == AV_NOPTS_VALUE && pktl_it->pkt.pts != AV_NOPTS_VALUE) { |
| 905 | 52 | st->start_time = pktl_it->pkt.pts; | |
| 906 |
3/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 50 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
52 | if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && st->codecpar->sample_rate) |
| 907 | 2 | st->start_time = av_sat_add64(st->start_time, av_rescale_q(sti->skip_samples, (AVRational){1, st->codecpar->sample_rate}, st->time_base)); | |
| 908 | } | ||
| 909 | } | ||
| 910 | |||
| 911 |
2/2✓ Branch 1 taken 6518 times.
✓ Branch 2 taken 102 times.
|
6620 | if (has_decode_delay_been_guessed(st)) |
| 912 | 6518 | update_dts_from_pts(s, stream_index, pktl); | |
| 913 | |||
| 914 |
2/2✓ Branch 0 taken 1887 times.
✓ Branch 1 taken 4733 times.
|
6620 | if (st->start_time == AV_NOPTS_VALUE) { |
| 915 |
3/4✓ Branch 0 taken 1330 times.
✓ Branch 1 taken 557 times.
✓ Branch 2 taken 1330 times.
✗ Branch 3 not taken.
|
1887 | if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO || !(pkt->flags & AV_PKT_FLAG_DISCARD)) { |
| 916 | 1887 | st->start_time = pts; | |
| 917 | } | ||
| 918 |
4/4✓ Branch 0 taken 557 times.
✓ Branch 1 taken 1330 times.
✓ Branch 2 taken 461 times.
✓ Branch 3 taken 96 times.
|
1887 | if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && st->codecpar->sample_rate) |
| 919 | 461 | st->start_time = av_sat_add64(st->start_time, av_rescale_q(sti->skip_samples, (AVRational){1, st->codecpar->sample_rate}, st->time_base)); | |
| 920 | } | ||
| 921 | } | ||
| 922 | |||
| 923 | 277328 | static void update_initial_durations(AVFormatContext *s, AVStream *st, | |
| 924 | int stream_index, int64_t duration) | ||
| 925 | { | ||
| 926 | 277328 | FormatContextInternal *const fci = ff_fc_internal(s); | |
| 927 | 277328 | FFFormatContext *const si = &fci->fc; | |
| 928 | 277328 | FFStream *const sti = ffstream(st); | |
| 929 |
2/2✓ Branch 0 taken 187958 times.
✓ Branch 1 taken 89370 times.
|
277328 | PacketListEntry *pktl = si->packet_buffer.head ? si->packet_buffer.head : fci->parse_queue.head; |
| 930 | 277328 | int64_t cur_dts = RELATIVE_TS_BASE; | |
| 931 | |||
| 932 |
2/2✓ Branch 0 taken 134827 times.
✓ Branch 1 taken 142501 times.
|
277328 | if (sti->first_dts != AV_NOPTS_VALUE) { |
| 933 |
2/2✓ Branch 0 taken 131042 times.
✓ Branch 1 taken 3785 times.
|
134827 | if (sti->update_initial_durations_done) |
| 934 | 131042 | return; | |
| 935 | 3785 | sti->update_initial_durations_done = 1; | |
| 936 | 3785 | cur_dts = sti->first_dts; | |
| 937 |
1/2✓ Branch 1 taken 5630 times.
✗ Branch 2 not taken.
|
5630 | for (; pktl; pktl = get_next_pkt(s, st, pktl)) { |
| 938 |
2/2✓ Branch 0 taken 3801 times.
✓ Branch 1 taken 1829 times.
|
5630 | if (pktl->pkt.stream_index == stream_index) { |
| 939 |
2/2✓ Branch 0 taken 3667 times.
✓ Branch 1 taken 134 times.
|
3801 | if (pktl->pkt.pts != pktl->pkt.dts || |
| 940 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 3651 times.
|
3667 | pktl->pkt.dts != AV_NOPTS_VALUE || |
| 941 |
1/2✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
16 | pktl->pkt.duration) |
| 942 | break; | ||
| 943 | 16 | cur_dts -= duration; | |
| 944 | } | ||
| 945 | } | ||
| 946 |
3/4✓ Branch 0 taken 3785 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41 times.
✓ Branch 3 taken 3744 times.
|
3785 | if (pktl && pktl->pkt.dts != sti->first_dts) { |
| 947 | 41 | av_log(s, AV_LOG_DEBUG, "first_dts %s not matching first dts %s (pts %s, duration %"PRId64") in the queue\n", | |
| 948 | 41 | av_ts2str(sti->first_dts), av_ts2str(pktl->pkt.dts), av_ts2str(pktl->pkt.pts), pktl->pkt.duration); | |
| 949 | 41 | return; | |
| 950 | } | ||
| 951 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3744 times.
|
3744 | if (!pktl) { |
| 952 | ✗ | av_log(s, AV_LOG_DEBUG, "first_dts %s but no packet with dts in the queue\n", av_ts2str(sti->first_dts)); | |
| 953 | ✗ | return; | |
| 954 | } | ||
| 955 |
2/2✓ Branch 0 taken 3720 times.
✓ Branch 1 taken 24 times.
|
3744 | pktl = si->packet_buffer.head ? si->packet_buffer.head : fci->parse_queue.head; |
| 956 | 3744 | sti->first_dts = cur_dts; | |
| 957 |
2/2✓ Branch 0 taken 116951 times.
✓ Branch 1 taken 25550 times.
|
142501 | } else if (sti->cur_dts != RELATIVE_TS_BASE) |
| 958 | 116951 | return; | |
| 959 | |||
| 960 |
2/2✓ Branch 1 taken 52930 times.
✓ Branch 2 taken 722 times.
|
53652 | for (; pktl; pktl = get_next_pkt(s, st, pktl)) { |
| 961 |
2/2✓ Branch 0 taken 24173 times.
✓ Branch 1 taken 28757 times.
|
52930 | if (pktl->pkt.stream_index != stream_index) |
| 962 | 24173 | continue; | |
| 963 |
2/2✓ Branch 0 taken 790 times.
✓ Branch 1 taken 27967 times.
|
28757 | if ((pktl->pkt.pts == pktl->pkt.dts || |
| 964 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 776 times.
|
790 | pktl->pkt.pts == AV_NOPTS_VALUE) && |
| 965 |
2/2✓ Branch 0 taken 3799 times.
✓ Branch 1 taken 24182 times.
|
27981 | (pktl->pkt.dts == AV_NOPTS_VALUE || |
| 966 |
2/2✓ Branch 0 taken 179 times.
✓ Branch 1 taken 3620 times.
|
3799 | pktl->pkt.dts == sti->first_dts || |
| 967 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 177 times.
|
179 | pktl->pkt.dts == RELATIVE_TS_BASE) && |
| 968 |
2/2✓ Branch 0 taken 185 times.
✓ Branch 1 taken 27619 times.
|
27804 | !pktl->pkt.duration && |
| 969 |
1/2✓ Branch 1 taken 185 times.
✗ Branch 2 not taken.
|
185 | av_sat_add64(cur_dts, duration) == cur_dts + (uint64_t)duration |
| 970 | ) { | ||
| 971 | 185 | pktl->pkt.dts = cur_dts; | |
| 972 |
2/2✓ Branch 0 taken 169 times.
✓ Branch 1 taken 16 times.
|
185 | if (!sti->avctx->has_b_frames) |
| 973 | 169 | pktl->pkt.pts = cur_dts; | |
| 974 | 185 | pktl->pkt.duration = duration; | |
| 975 | } else | ||
| 976 | break; | ||
| 977 | 185 | cur_dts = pktl->pkt.dts + pktl->pkt.duration; | |
| 978 | } | ||
| 979 |
2/2✓ Branch 0 taken 722 times.
✓ Branch 1 taken 28572 times.
|
29294 | if (!pktl) |
| 980 | 722 | sti->cur_dts = cur_dts; | |
| 981 | } | ||
| 982 | |||
| 983 | 644421 | static void compute_pkt_fields(AVFormatContext *s, AVStream *st, | |
| 984 | AVCodecParserContext *pc, AVPacket *pkt, | ||
| 985 | int64_t next_dts, int64_t next_pts) | ||
| 986 | { | ||
| 987 | 644421 | FormatContextInternal *const fci = ff_fc_internal(s); | |
| 988 | 644421 | FFFormatContext *const si = &fci->fc; | |
| 989 | 644421 | FFStream *const sti = ffstream(st); | |
| 990 | int num, den, presentation_delayed, delay; | ||
| 991 | int64_t offset; | ||
| 992 | AVRational duration; | ||
| 993 | 1898184 | int onein_oneout = st->codecpar->codec_id != AV_CODEC_ID_H264 && | |
| 994 |
4/4✓ Branch 0 taken 609342 times.
✓ Branch 1 taken 35079 times.
✓ Branch 2 taken 595291 times.
✓ Branch 3 taken 14051 times.
|
1239712 | st->codecpar->codec_id != AV_CODEC_ID_HEVC && |
| 995 |
2/2✓ Branch 0 taken 591898 times.
✓ Branch 1 taken 3393 times.
|
595291 | st->codecpar->codec_id != AV_CODEC_ID_VVC; |
| 996 | |||
| 997 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 644421 times.
|
644421 | if (s->flags & AVFMT_FLAG_NOFILLIN) |
| 998 | ✗ | return; | |
| 999 | |||
| 1000 |
4/4✓ Branch 0 taken 253237 times.
✓ Branch 1 taken 391184 times.
✓ Branch 2 taken 76007 times.
✓ Branch 3 taken 177230 times.
|
644421 | if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && pkt->dts != AV_NOPTS_VALUE) { |
| 1001 |
4/4✓ Branch 0 taken 44463 times.
✓ Branch 1 taken 31544 times.
✓ Branch 2 taken 43211 times.
✓ Branch 3 taken 1252 times.
|
76007 | if (pkt->dts == pkt->pts && sti->last_dts_for_order_check != AV_NOPTS_VALUE) { |
| 1002 |
2/2✓ Branch 0 taken 43202 times.
✓ Branch 1 taken 9 times.
|
43211 | if (sti->last_dts_for_order_check <= pkt->dts) { |
| 1003 | 43202 | sti->dts_ordered++; | |
| 1004 | } else { | ||
| 1005 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
|
9 | av_log(s, sti->dts_misordered ? AV_LOG_DEBUG : AV_LOG_WARNING, |
| 1006 | "DTS %"PRIi64" < %"PRIi64" out of order\n", | ||
| 1007 | pkt->dts, | ||
| 1008 | sti->last_dts_for_order_check); | ||
| 1009 | 9 | sti->dts_misordered++; | |
| 1010 | } | ||
| 1011 |
2/2✓ Branch 0 taken 29 times.
✓ Branch 1 taken 43182 times.
|
43211 | if (sti->dts_ordered + sti->dts_misordered > 250) { |
| 1012 | 29 | sti->dts_ordered >>= 1; | |
| 1013 | 29 | sti->dts_misordered >>= 1; | |
| 1014 | } | ||
| 1015 | } | ||
| 1016 | |||
| 1017 | 76007 | sti->last_dts_for_order_check = pkt->dts; | |
| 1018 |
4/4✓ Branch 0 taken 37 times.
✓ Branch 1 taken 75970 times.
✓ Branch 2 taken 20 times.
✓ Branch 3 taken 17 times.
|
76007 | if (sti->dts_ordered < 8 * sti->dts_misordered && pkt->dts == pkt->pts) |
| 1019 | 20 | pkt->dts = AV_NOPTS_VALUE; | |
| 1020 | } | ||
| 1021 | |||
| 1022 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 644421 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
644421 | if ((s->flags & AVFMT_FLAG_IGNDTS) && pkt->pts != AV_NOPTS_VALUE) |
| 1023 | ✗ | pkt->dts = AV_NOPTS_VALUE; | |
| 1024 | |||
| 1025 |
4/4✓ Branch 0 taken 239629 times.
✓ Branch 1 taken 404792 times.
✓ Branch 2 taken 29261 times.
✓ Branch 3 taken 210368 times.
|
644421 | if (pc && pc->pict_type == AV_PICTURE_TYPE_B |
| 1026 |
2/2✓ Branch 0 taken 84 times.
✓ Branch 1 taken 29177 times.
|
29261 | && !sti->avctx->has_b_frames) |
| 1027 | //FIXME Set low_delay = 0 when has_b_frames = 1 | ||
| 1028 | 84 | sti->avctx->has_b_frames = 1; | |
| 1029 | |||
| 1030 | /* do we have a video B-frame ? */ | ||
| 1031 | 644421 | delay = sti->avctx->has_b_frames; | |
| 1032 | 644421 | presentation_delayed = 0; | |
| 1033 | |||
| 1034 | /* XXX: need has_b_frame, but cannot get it if the codec is | ||
| 1035 | * not initialized */ | ||
| 1036 |
4/4✓ Branch 0 taken 49551 times.
✓ Branch 1 taken 594870 times.
✓ Branch 2 taken 44859 times.
✓ Branch 3 taken 4692 times.
|
644421 | if (delay && |
| 1037 |
2/2✓ Branch 0 taken 15598 times.
✓ Branch 1 taken 29261 times.
|
44859 | pc && pc->pict_type != AV_PICTURE_TYPE_B) |
| 1038 | 15598 | presentation_delayed = 1; | |
| 1039 | |||
| 1040 |
4/4✓ Branch 0 taken 352205 times.
✓ Branch 1 taken 292216 times.
✓ Branch 2 taken 172314 times.
✓ Branch 3 taken 179891 times.
|
644421 | if (pkt->pts != AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE && |
| 1041 |
3/4✓ Branch 0 taken 30758 times.
✓ Branch 1 taken 141556 times.
✓ Branch 2 taken 30758 times.
✗ Branch 3 not taken.
|
172314 | st->pts_wrap_bits < 63 && pkt->dts > INT64_MIN + (1LL << st->pts_wrap_bits) && |
| 1042 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 30758 times.
|
30758 | pkt->dts - (1LL << (st->pts_wrap_bits - 1)) > pkt->pts) { |
| 1043 | ✗ | if (is_relative(sti->cur_dts) || pkt->dts - (1LL<<(st->pts_wrap_bits - 1)) > sti->cur_dts) { | |
| 1044 | ✗ | pkt->dts -= 1LL << st->pts_wrap_bits; | |
| 1045 | } else | ||
| 1046 | ✗ | pkt->pts += 1LL << st->pts_wrap_bits; | |
| 1047 | } | ||
| 1048 | |||
| 1049 | /* Some MPEG-2 in MPEG-PS lack dts (issue #171 / input_file.mpg). | ||
| 1050 | * We take the conservative approach and discard both. | ||
| 1051 | * Note: If this is misbehaving for an H.264 file, then possibly | ||
| 1052 | * presentation_delayed is not set correctly. */ | ||
| 1053 |
4/4✓ Branch 0 taken 31893 times.
✓ Branch 1 taken 612528 times.
✓ Branch 2 taken 26071 times.
✓ Branch 3 taken 5822 times.
|
644421 | if (delay == 1 && pkt->dts == pkt->pts && |
| 1054 |
4/4✓ Branch 0 taken 6659 times.
✓ Branch 1 taken 19412 times.
✓ Branch 2 taken 632 times.
✓ Branch 3 taken 6027 times.
|
26071 | pkt->dts != AV_NOPTS_VALUE && presentation_delayed) { |
| 1055 | 632 | av_log(s, AV_LOG_DEBUG, "invalid dts/pts combination %"PRIi64"\n", pkt->dts); | |
| 1056 |
2/2✓ Branch 0 taken 293 times.
✓ Branch 1 taken 339 times.
|
632 | if ( strcmp(s->iformat->name, "mov,mp4,m4a,3gp,3g2,mj2") |
| 1057 |
2/2✓ Branch 0 taken 22 times.
✓ Branch 1 taken 271 times.
|
293 | && strcmp(s->iformat->name, "flv")) // otherwise we discard correct timestamps for vc1-wmapro.ism |
| 1058 | 22 | pkt->dts = AV_NOPTS_VALUE; | |
| 1059 | } | ||
| 1060 | |||
| 1061 | 644421 | duration = av_mul_q((AVRational) {pkt->duration, 1}, st->time_base); | |
| 1062 |
2/2✓ Branch 0 taken 330754 times.
✓ Branch 1 taken 313667 times.
|
644421 | if (pkt->duration <= 0) { |
| 1063 | 330754 | compute_frame_duration(s, &num, &den, st, pc, pkt); | |
| 1064 |
3/4✓ Branch 0 taken 320841 times.
✓ Branch 1 taken 9913 times.
✓ Branch 2 taken 320841 times.
✗ Branch 3 not taken.
|
330754 | if (den && num) { |
| 1065 | 320841 | duration = (AVRational) {num, den}; | |
| 1066 | 320841 | pkt->duration = av_rescale_rnd(1, | |
| 1067 | 320841 | num * (int64_t) st->time_base.den, | |
| 1068 | 320841 | den * (int64_t) st->time_base.num, | |
| 1069 | AV_ROUND_DOWN); | ||
| 1070 | } | ||
| 1071 | } | ||
| 1072 | |||
| 1073 |
6/6✓ Branch 0 taken 631686 times.
✓ Branch 1 taken 12735 times.
✓ Branch 2 taken 443728 times.
✓ Branch 3 taken 187958 times.
✓ Branch 4 taken 89370 times.
✓ Branch 5 taken 354358 times.
|
644421 | if (pkt->duration > 0 && (si->packet_buffer.head || fci->parse_queue.head)) |
| 1074 | 277328 | update_initial_durations(s, st, pkt->stream_index, pkt->duration); | |
| 1075 | |||
| 1076 | /* Correct timestamps with byte offset if demuxers only have timestamps | ||
| 1077 | * on packet boundaries */ | ||
| 1078 |
5/6✓ Branch 0 taken 239629 times.
✓ Branch 1 taken 404792 times.
✓ Branch 2 taken 961 times.
✓ Branch 3 taken 238668 times.
✓ Branch 4 taken 961 times.
✗ Branch 5 not taken.
|
644421 | if (pc && sti->need_parsing == AVSTREAM_PARSE_TIMESTAMPS && pkt->size) { |
| 1079 | /* this will estimate bitrate based on this frame's duration and size */ | ||
| 1080 | 961 | offset = av_rescale(pc->offset, pkt->duration, pkt->size); | |
| 1081 |
2/2✓ Branch 0 taken 576 times.
✓ Branch 1 taken 385 times.
|
961 | if (pkt->pts != AV_NOPTS_VALUE) |
| 1082 | 576 | pkt->pts += offset; | |
| 1083 |
2/2✓ Branch 0 taken 121 times.
✓ Branch 1 taken 840 times.
|
961 | if (pkt->dts != AV_NOPTS_VALUE) |
| 1084 | 121 | pkt->dts += offset; | |
| 1085 | } | ||
| 1086 | |||
| 1087 | /* This may be redundant, but it should not hurt. */ | ||
| 1088 |
2/2✓ Branch 0 taken 202779 times.
✓ Branch 1 taken 441642 times.
|
644421 | if (pkt->dts != AV_NOPTS_VALUE && |
| 1089 |
2/2✓ Branch 0 taken 172292 times.
✓ Branch 1 taken 30487 times.
|
202779 | pkt->pts != AV_NOPTS_VALUE && |
| 1090 |
2/2✓ Branch 0 taken 6359 times.
✓ Branch 1 taken 165933 times.
|
172292 | pkt->pts > pkt->dts) |
| 1091 | 6359 | presentation_delayed = 1; | |
| 1092 | |||
| 1093 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 644421 times.
|
644421 | if (s->debug & AV_FDEBUG_TS) |
| 1094 | ✗ | av_log(s, AV_LOG_DEBUG, | |
| 1095 | "IN delayed:%d pts:%s, dts:%s cur_dts:%s st:%d pc:%p duration:%"PRId64" delay:%d onein_oneout:%d\n", | ||
| 1096 | ✗ | presentation_delayed, av_ts2str(pkt->pts), av_ts2str(pkt->dts), av_ts2str(sti->cur_dts), | |
| 1097 | pkt->stream_index, pc, pkt->duration, delay, onein_oneout); | ||
| 1098 | |||
| 1099 | /* Interpolate PTS and DTS if they are not present. We skip H264 | ||
| 1100 | * currently because delay and has_b_frames are not reliably set. */ | ||
| 1101 |
8/8✓ Branch 0 taken 49551 times.
✓ Branch 1 taken 594870 times.
✓ Branch 2 taken 31893 times.
✓ Branch 3 taken 17658 times.
✓ Branch 4 taken 28116 times.
✓ Branch 5 taken 3777 times.
✓ Branch 6 taken 588134 times.
✓ Branch 7 taken 34852 times.
|
644421 | if ((delay == 0 || (delay == 1 && pc)) && |
| 1102 | onein_oneout) { | ||
| 1103 |
2/2✓ Branch 0 taken 5931 times.
✓ Branch 1 taken 582203 times.
|
588134 | if (presentation_delayed) { |
| 1104 | /* DTS = decompression timestamp */ | ||
| 1105 | /* PTS = presentation timestamp */ | ||
| 1106 |
2/2✓ Branch 0 taken 2848 times.
✓ Branch 1 taken 3083 times.
|
5931 | if (pkt->dts == AV_NOPTS_VALUE) |
| 1107 | 2848 | pkt->dts = sti->last_IP_pts; | |
| 1108 | 5931 | update_initial_timestamps(s, pkt->stream_index, pkt->dts, pkt->pts, pkt); | |
| 1109 |
2/2✓ Branch 0 taken 2506 times.
✓ Branch 1 taken 3425 times.
|
5931 | if (pkt->dts == AV_NOPTS_VALUE) |
| 1110 | 2506 | pkt->dts = sti->cur_dts; | |
| 1111 | |||
| 1112 | /* This is tricky: the dts must be incremented by the duration | ||
| 1113 | * of the frame we are displaying, i.e. the last I- or P-frame. */ | ||
| 1114 |
3/4✓ Branch 0 taken 388 times.
✓ Branch 1 taken 5543 times.
✓ Branch 2 taken 388 times.
✗ Branch 3 not taken.
|
5931 | if (sti->last_IP_duration == 0 && (uint64_t)pkt->duration <= INT32_MAX) |
| 1115 | 388 | sti->last_IP_duration = pkt->duration; | |
| 1116 |
1/2✓ Branch 0 taken 5931 times.
✗ Branch 1 not taken.
|
5931 | if (pkt->dts != AV_NOPTS_VALUE) |
| 1117 | 5931 | sti->cur_dts = av_sat_add64(pkt->dts, sti->last_IP_duration); | |
| 1118 |
1/2✓ Branch 0 taken 5931 times.
✗ Branch 1 not taken.
|
5931 | if (pkt->dts != AV_NOPTS_VALUE && |
| 1119 |
2/2✓ Branch 0 taken 3273 times.
✓ Branch 1 taken 2658 times.
|
5931 | pkt->pts == AV_NOPTS_VALUE && |
| 1120 |
2/2✓ Branch 0 taken 3271 times.
✓ Branch 1 taken 2 times.
|
3273 | sti->last_IP_duration > 0 && |
| 1121 |
4/4✓ Branch 0 taken 784 times.
✓ Branch 1 taken 2487 times.
✓ Branch 2 taken 774 times.
✓ Branch 3 taken 10 times.
|
3271 | ((uint64_t)sti->cur_dts - (uint64_t)next_dts + 1) <= 2 && |
| 1122 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 763 times.
|
774 | next_dts != next_pts && |
| 1123 | next_pts != AV_NOPTS_VALUE) | ||
| 1124 | 11 | pkt->pts = next_dts; | |
| 1125 | |||
| 1126 |
1/2✓ Branch 0 taken 5931 times.
✗ Branch 1 not taken.
|
5931 | if ((uint64_t)pkt->duration <= INT32_MAX) |
| 1127 | 5931 | sti->last_IP_duration = pkt->duration; | |
| 1128 | 5931 | sti->last_IP_pts = pkt->pts; | |
| 1129 | /* Cannot compute PTS if not present (we can compute it only | ||
| 1130 | * by knowing the future. */ | ||
| 1131 |
2/2✓ Branch 0 taken 246340 times.
✓ Branch 1 taken 335863 times.
|
582203 | } else if (pkt->pts != AV_NOPTS_VALUE || |
| 1132 |
2/2✓ Branch 0 taken 216695 times.
✓ Branch 1 taken 29645 times.
|
246340 | pkt->dts != AV_NOPTS_VALUE || |
| 1133 |
2/2✓ Branch 0 taken 214104 times.
✓ Branch 1 taken 2591 times.
|
216695 | pkt->duration > 0 ) { |
| 1134 | |||
| 1135 | /* presentation is not delayed : PTS and DTS are the same */ | ||
| 1136 |
2/2✓ Branch 0 taken 243749 times.
✓ Branch 1 taken 335863 times.
|
579612 | if (pkt->pts == AV_NOPTS_VALUE) |
| 1137 | 243749 | pkt->pts = pkt->dts; | |
| 1138 | 579612 | update_initial_timestamps(s, pkt->stream_index, pkt->pts, | |
| 1139 | pkt->pts, pkt); | ||
| 1140 |
2/2✓ Branch 0 taken 214104 times.
✓ Branch 1 taken 365508 times.
|
579612 | if (pkt->pts == AV_NOPTS_VALUE) |
| 1141 | 214104 | pkt->pts = sti->cur_dts; | |
| 1142 | 579612 | pkt->dts = pkt->pts; | |
| 1143 |
3/4✓ Branch 0 taken 579612 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 579603 times.
✓ Branch 3 taken 9 times.
|
579612 | if (pkt->pts != AV_NOPTS_VALUE && duration.num >= 0) |
| 1144 | 579603 | sti->cur_dts = av_add_stable(st->time_base, pkt->pts, duration, 1); | |
| 1145 | } | ||
| 1146 | } | ||
| 1147 | |||
| 1148 |
3/4✓ Branch 0 taken 595965 times.
✓ Branch 1 taken 48456 times.
✓ Branch 2 taken 595965 times.
✗ Branch 3 not taken.
|
644421 | if (pkt->pts != AV_NOPTS_VALUE && delay <= MAX_REORDER_DELAY) { |
| 1149 | 595965 | sti->pts_buffer[0] = pkt->pts; | |
| 1150 |
4/4✓ Branch 0 taken 25486 times.
✓ Branch 1 taken 589528 times.
✓ Branch 2 taken 19049 times.
✓ Branch 3 taken 6437 times.
|
615014 | for (int i = 0; i < delay && sti->pts_buffer[i] > sti->pts_buffer[i + 1]; i++) |
| 1151 | 19049 | FFSWAP(int64_t, sti->pts_buffer[i], sti->pts_buffer[i + 1]); | |
| 1152 | |||
| 1153 |
2/2✓ Branch 1 taken 595282 times.
✓ Branch 2 taken 683 times.
|
595965 | if (has_decode_delay_been_guessed(st)) |
| 1154 | 595282 | pkt->dts = select_from_pts_buffer(st, sti->pts_buffer, pkt->dts); | |
| 1155 | } | ||
| 1156 | // We skipped it above so we try here. | ||
| 1157 |
2/2✓ Branch 0 taken 52523 times.
✓ Branch 1 taken 591898 times.
|
644421 | if (!onein_oneout) |
| 1158 | // This should happen on the first packet | ||
| 1159 | 52523 | update_initial_timestamps(s, pkt->stream_index, pkt->dts, pkt->pts, pkt); | |
| 1160 |
2/2✓ Branch 0 taken 9410 times.
✓ Branch 1 taken 635011 times.
|
644421 | if (pkt->dts > sti->cur_dts) |
| 1161 | 9410 | sti->cur_dts = pkt->dts; | |
| 1162 | |||
| 1163 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 644421 times.
|
644421 | if (s->debug & AV_FDEBUG_TS) |
| 1164 | ✗ | av_log(s, AV_LOG_DEBUG, "OUTdelayed:%d/%d pts:%s, dts:%s cur_dts:%s st:%d (%d)\n", | |
| 1165 | ✗ | presentation_delayed, delay, av_ts2str(pkt->pts), av_ts2str(pkt->dts), av_ts2str(sti->cur_dts), st->index, st->id); | |
| 1166 | |||
| 1167 | /* update flags */ | ||
| 1168 |
4/4✓ Branch 0 taken 644268 times.
✓ Branch 1 taken 153 times.
✓ Branch 3 taken 434172 times.
✓ Branch 4 taken 210096 times.
|
644421 | if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA || ff_is_intra_only(st->codecpar->codec_id)) |
| 1169 | 434325 | pkt->flags |= AV_PKT_FLAG_KEY; | |
| 1170 | } | ||
| 1171 | |||
| 1172 | /** | ||
| 1173 | * Parse a packet, add all split parts to parse_queue. | ||
| 1174 | * | ||
| 1175 | * @param pkt Packet to parse; must not be NULL. | ||
| 1176 | * @param flush Indicates whether to flush. If set, pkt must be blank. | ||
| 1177 | */ | ||
| 1178 | 722983 | static int parse_packet(AVFormatContext *s, AVPacket *pkt, | |
| 1179 | int stream_index, int flush) | ||
| 1180 | { | ||
| 1181 | 722983 | FormatContextInternal *const fci = ff_fc_internal(s); | |
| 1182 | 722983 | AVStream *st = s->streams[stream_index]; | |
| 1183 | 722983 | FFStream *const sti = ffstream(st); | |
| 1184 | 722983 | AVPacket *out_pkt = sti->parse_pkt; | |
| 1185 | 722983 | const AVPacketSideData *sd = NULL; | |
| 1186 | 722983 | const uint8_t *data = pkt->data; | |
| 1187 | 722983 | uint8_t *extradata = sti->avctx->extradata; | |
| 1188 | 722983 | int extradata_size = sti->avctx->extradata_size; | |
| 1189 | 722983 | int size = pkt->size; | |
| 1190 | 722983 | int ret = 0, got_output = flush, pkt_side_data_consumed = 0; | |
| 1191 | |||
| 1192 |
5/6✓ Branch 0 taken 2486 times.
✓ Branch 1 taken 720497 times.
✓ Branch 2 taken 164 times.
✓ Branch 3 taken 2322 times.
✓ Branch 4 taken 164 times.
✗ Branch 5 not taken.
|
722983 | if (!size && !flush && sti->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) { |
| 1193 | // preserve 0-size sync packets | ||
| 1194 | 164 | compute_pkt_fields(s, st, sti->parser, pkt, pkt->dts, pkt->pts); | |
| 1195 | |||
| 1196 | // Theora has valid 0-sized packets that need to be output | ||
| 1197 |
2/2✓ Branch 0 taken 148 times.
✓ Branch 1 taken 16 times.
|
164 | if (st->codecpar->codec_id == AV_CODEC_ID_THEORA) { |
| 1198 | 148 | ret = ff_packet_list_put(&fci->parse_queue, | |
| 1199 | pkt, NULL, 0); | ||
| 1200 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 148 times.
|
148 | if (ret < 0) |
| 1201 | ✗ | goto fail; | |
| 1202 | } | ||
| 1203 | } | ||
| 1204 | |||
| 1205 |
2/2✓ Branch 0 taken 28000 times.
✓ Branch 1 taken 694983 times.
|
722983 | if (pkt->side_data_elems) |
| 1206 | 28000 | sd = av_packet_side_data_get(pkt->side_data, pkt->side_data_elems, | |
| 1207 | AV_PKT_DATA_NEW_EXTRADATA); | ||
| 1208 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 722977 times.
|
722983 | if (sd) { |
| 1209 | av_assert1(size && !flush); | ||
| 1210 | |||
| 1211 | 6 | sti->avctx->extradata = sd->data; | |
| 1212 | 6 | sti->avctx->extradata_size = sd->size; | |
| 1213 | } | ||
| 1214 | |||
| 1215 |
6/6✓ Branch 0 taken 888753 times.
✓ Branch 1 taken 726579 times.
✓ Branch 2 taken 5918 times.
✓ Branch 3 taken 720661 times.
✓ Branch 4 taken 3596 times.
✓ Branch 5 taken 2322 times.
|
1615332 | while (size > 0 || (flush && got_output)) { |
| 1216 | 892349 | int64_t next_pts = pkt->pts; | |
| 1217 | 892349 | int64_t next_dts = pkt->dts; | |
| 1218 | int len; | ||
| 1219 | |||
| 1220 | 892349 | len = av_parser_parse2(sti->parser, sti->avctx, | |
| 1221 | &out_pkt->data, &out_pkt->size, data, size, | ||
| 1222 | pkt->pts, pkt->dts, pkt->pos); | ||
| 1223 | |||
| 1224 | 892349 | pkt->pts = pkt->dts = AV_NOPTS_VALUE; | |
| 1225 | 892349 | pkt->pos = -1; | |
| 1226 | /* increment read pointer */ | ||
| 1227 | av_assert1(data || !len); | ||
| 1228 |
2/2✓ Branch 0 taken 876467 times.
✓ Branch 1 taken 15882 times.
|
892349 | data = len ? data + len : data; |
| 1229 | 892349 | size -= len; | |
| 1230 | |||
| 1231 | 892349 | got_output = !!out_pkt->size; | |
| 1232 | |||
| 1233 |
4/4✓ Branch 0 taken 38584 times.
✓ Branch 1 taken 853765 times.
✓ Branch 2 taken 16652 times.
✓ Branch 3 taken 21932 times.
|
892349 | if (pkt->side_data && !out_pkt->side_data) { |
| 1234 | /* for the first iteration, side_data are simply moved to output. | ||
| 1235 | * in case of additional iterations, they are duplicated each time. */ | ||
| 1236 |
2/2✓ Branch 0 taken 10873 times.
✓ Branch 1 taken 5779 times.
|
16652 | if (!pkt_side_data_consumed) { |
| 1237 | 10873 | pkt_side_data_consumed = 1; | |
| 1238 | 10873 | out_pkt->side_data = pkt->side_data; | |
| 1239 | 10873 | out_pkt->side_data_elems = pkt->side_data_elems; | |
| 1240 |
2/2✓ Branch 0 taken 5779 times.
✓ Branch 1 taken 5779 times.
|
11558 | } else for (int i = 0; i < pkt->side_data_elems; i++) { |
| 1241 | 5779 | const AVPacketSideData *const src_sd = &pkt->side_data[i]; | |
| 1242 | 5779 | uint8_t *dst_data = av_packet_new_side_data(out_pkt, src_sd->type, src_sd->size); | |
| 1243 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5779 times.
|
5779 | if (!dst_data) { |
| 1244 | ✗ | ret = AVERROR(ENOMEM); | |
| 1245 | ✗ | goto fail; | |
| 1246 | } | ||
| 1247 | 5779 | memcpy(dst_data, src_sd->data, src_sd->size); | |
| 1248 | } | ||
| 1249 | } | ||
| 1250 | |||
| 1251 |
2/2✓ Branch 0 taken 652884 times.
✓ Branch 1 taken 239465 times.
|
892349 | if (!out_pkt->size) |
| 1252 | 652884 | continue; | |
| 1253 | |||
| 1254 |
4/4✓ Branch 0 taken 238191 times.
✓ Branch 1 taken 1274 times.
✓ Branch 2 taken 70026 times.
✓ Branch 3 taken 168165 times.
|
239465 | if (pkt->buf && out_pkt->data == pkt->data) { |
| 1255 | /* reference pkt->buf only when out_pkt->data is guaranteed to point | ||
| 1256 | * to data in it and not in the parser's internal buffer. */ | ||
| 1257 | /* XXX: Ensure this is the case with all parsers when sti->parser->flags | ||
| 1258 | * is PARSER_FLAG_COMPLETE_FRAMES and check for that instead? */ | ||
| 1259 | 70026 | out_pkt->buf = av_buffer_ref(pkt->buf); | |
| 1260 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 70026 times.
|
70026 | if (!out_pkt->buf) { |
| 1261 | ✗ | ret = AVERROR(ENOMEM); | |
| 1262 | ✗ | goto fail; | |
| 1263 | } | ||
| 1264 | } else { | ||
| 1265 | 169439 | ret = av_packet_make_refcounted(out_pkt); | |
| 1266 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 169439 times.
|
169439 | if (ret < 0) |
| 1267 | ✗ | goto fail; | |
| 1268 | } | ||
| 1269 | |||
| 1270 | /* set the duration */ | ||
| 1271 |
2/2✓ Branch 0 taken 51100 times.
✓ Branch 1 taken 188365 times.
|
239465 | out_pkt->duration = (sti->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) ? pkt->duration : 0; |
| 1272 |
2/2✓ Branch 0 taken 157347 times.
✓ Branch 1 taken 82118 times.
|
239465 | if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { |
| 1273 |
6/6✓ Branch 0 taken 157220 times.
✓ Branch 1 taken 127 times.
✓ Branch 2 taken 157010 times.
✓ Branch 3 taken 210 times.
✓ Branch 4 taken 145269 times.
✓ Branch 5 taken 11741 times.
|
157347 | if (sti->avctx->sample_rate > 0 && !out_pkt->duration && sti->parser->duration > 0) { |
| 1274 | 145269 | out_pkt->duration = | |
| 1275 | 145269 | av_rescale_q_rnd(sti->parser->duration, | |
| 1276 | 145269 | (AVRational) { 1, sti->avctx->sample_rate }, | |
| 1277 | st->time_base, | ||
| 1278 | AV_ROUND_DOWN); | ||
| 1279 | } | ||
| 1280 |
2/2✓ Branch 0 taken 1822 times.
✓ Branch 1 taken 80296 times.
|
82118 | } else if (st->codecpar->codec_id == AV_CODEC_ID_GIF) { |
| 1281 |
2/4✓ Branch 0 taken 1822 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1822 times.
✗ Branch 3 not taken.
|
1822 | if (st->time_base.num > 0 && st->time_base.den > 0 && |
| 1282 |
1/2✓ Branch 0 taken 1822 times.
✗ Branch 1 not taken.
|
1822 | sti->parser->duration) { |
| 1283 | 1822 | out_pkt->duration = sti->parser->duration; | |
| 1284 | } | ||
| 1285 | } | ||
| 1286 | |||
| 1287 | 239465 | out_pkt->stream_index = st->index; | |
| 1288 | 239465 | out_pkt->pts = sti->parser->pts; | |
| 1289 | 239465 | out_pkt->dts = sti->parser->dts; | |
| 1290 | 239465 | out_pkt->pos = sti->parser->pos; | |
| 1291 | 239465 | out_pkt->flags |= pkt->flags & (AV_PKT_FLAG_DISCARD | AV_PKT_FLAG_CORRUPT); | |
| 1292 | |||
| 1293 |
2/2✓ Branch 0 taken 162766 times.
✓ Branch 1 taken 76699 times.
|
239465 | if (sti->need_parsing == AVSTREAM_PARSE_FULL_RAW) |
| 1294 | 162766 | out_pkt->pos = sti->parser->frame_offset; | |
| 1295 | |||
| 1296 |
2/2✓ Branch 0 taken 228204 times.
✓ Branch 1 taken 11261 times.
|
239465 | if (sti->parser->key_frame == 1 || |
| 1297 |
2/2✓ Branch 0 taken 143993 times.
✓ Branch 1 taken 84211 times.
|
228204 | (sti->parser->key_frame == -1 && |
| 1298 |
2/2✓ Branch 0 taken 131576 times.
✓ Branch 1 taken 12417 times.
|
143993 | sti->parser->pict_type == AV_PICTURE_TYPE_I)) |
| 1299 | 142837 | out_pkt->flags |= AV_PKT_FLAG_KEY; | |
| 1300 | |||
| 1301 |
6/6✓ Branch 0 taken 143993 times.
✓ Branch 1 taken 95472 times.
✓ Branch 2 taken 322 times.
✓ Branch 3 taken 143671 times.
✓ Branch 4 taken 291 times.
✓ Branch 5 taken 31 times.
|
239465 | if (sti->parser->key_frame == -1 && sti->parser->pict_type ==AV_PICTURE_TYPE_NONE && (pkt->flags&AV_PKT_FLAG_KEY)) |
| 1302 | 291 | out_pkt->flags |= AV_PKT_FLAG_KEY; | |
| 1303 | |||
| 1304 | 239465 | compute_pkt_fields(s, st, sti->parser, out_pkt, next_dts, next_pts); | |
| 1305 | |||
| 1306 | 239465 | ret = ff_packet_list_put(&fci->parse_queue, | |
| 1307 | out_pkt, NULL, 0); | ||
| 1308 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 239465 times.
|
239465 | if (ret < 0) |
| 1309 | ✗ | goto fail; | |
| 1310 | } | ||
| 1311 | |||
| 1312 | /* end of the stream => close and free the parser */ | ||
| 1313 |
2/2✓ Branch 0 taken 720661 times.
✓ Branch 1 taken 2322 times.
|
722983 | if (flush) { |
| 1314 | 2322 | av_parser_close(sti->parser); | |
| 1315 | 2322 | sti->parser = NULL; | |
| 1316 | } | ||
| 1317 | |||
| 1318 | 720661 | fail: | |
| 1319 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 722977 times.
|
722983 | if (sd) { |
| 1320 | 6 | sti->avctx->extradata = extradata; | |
| 1321 | 6 | sti->avctx->extradata_size = extradata_size; | |
| 1322 | } | ||
| 1323 |
2/2✓ Branch 0 taken 10873 times.
✓ Branch 1 taken 712110 times.
|
722983 | if (pkt_side_data_consumed) { |
| 1324 | 10873 | pkt->side_data = NULL; | |
| 1325 | 10873 | pkt->side_data_elems = 0; | |
| 1326 | } | ||
| 1327 | |||
| 1328 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 722983 times.
|
722983 | if (ret < 0) |
| 1329 | ✗ | av_packet_unref(out_pkt); | |
| 1330 | 722983 | av_packet_unref(pkt); | |
| 1331 | 722983 | return ret; | |
| 1332 | } | ||
| 1333 | |||
| 1334 | 49379 | static int64_t ts_to_samples(AVStream *st, int64_t ts) | |
| 1335 | { | ||
| 1336 | 49379 | return av_rescale(ts, st->time_base.num * st->codecpar->sample_rate, st->time_base.den); | |
| 1337 | } | ||
| 1338 | |||
| 1339 | 9023 | static int codec_close(FFStream *sti) | |
| 1340 | { | ||
| 1341 | 9023 | AVCodecContext *avctx_new = NULL; | |
| 1342 | 9023 | AVCodecParameters *par_tmp = NULL; | |
| 1343 | 9023 | const AVCodec *new_codec = NULL; | |
| 1344 | int ret; | ||
| 1345 | |||
| 1346 | 9023 | new_codec = | |
| 1347 | 9023 | (sti->avctx->codec_id != sti->pub.codecpar->codec_id) ? | |
| 1348 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 9012 times.
|
9023 | avcodec_find_decoder(sti->pub.codecpar->codec_id) : |
| 1349 | 9012 | sti->avctx->codec; | |
| 1350 | |||
| 1351 | 9023 | avctx_new = avcodec_alloc_context3(new_codec); | |
| 1352 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9023 times.
|
9023 | if (!avctx_new) { |
| 1353 | ✗ | ret = AVERROR(ENOMEM); | |
| 1354 | ✗ | goto fail; | |
| 1355 | } | ||
| 1356 | |||
| 1357 | 9023 | par_tmp = avcodec_parameters_alloc(); | |
| 1358 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9023 times.
|
9023 | if (!par_tmp) { |
| 1359 | ✗ | ret = AVERROR(ENOMEM); | |
| 1360 | ✗ | goto fail; | |
| 1361 | } | ||
| 1362 | |||
| 1363 | 9023 | ret = avcodec_parameters_from_context(par_tmp, sti->avctx); | |
| 1364 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9023 times.
|
9023 | if (ret < 0) |
| 1365 | ✗ | goto fail; | |
| 1366 | |||
| 1367 | 9023 | ret = avcodec_parameters_to_context(avctx_new, par_tmp); | |
| 1368 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9023 times.
|
9023 | if (ret < 0) |
| 1369 | ✗ | goto fail; | |
| 1370 | |||
| 1371 | 9023 | avctx_new->pkt_timebase = sti->avctx->pkt_timebase; | |
| 1372 | |||
| 1373 | 9023 | avcodec_free_context(&sti->avctx); | |
| 1374 | 9023 | sti->avctx = avctx_new; | |
| 1375 | |||
| 1376 | 9023 | avctx_new = NULL; | |
| 1377 | 9023 | ret = 0; | |
| 1378 | |||
| 1379 | 9023 | fail: | |
| 1380 | 9023 | avcodec_free_context(&avctx_new); | |
| 1381 | 9023 | avcodec_parameters_free(&par_tmp); | |
| 1382 | |||
| 1383 | 9023 | return ret; | |
| 1384 | } | ||
| 1385 | |||
| 1386 | static int extract_extradata(FFFormatContext *si, AVStream *st, const AVPacket *pkt); | ||
| 1387 | |||
| 1388 | 649434 | static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) | |
| 1389 | { | ||
| 1390 | 649434 | FormatContextInternal *const fci = ff_fc_internal(s); | |
| 1391 | 649434 | FFFormatContext *const si = &fci->fc; | |
| 1392 | 649434 | int ret, got_packet = 0; | |
| 1393 | 649434 | AVDictionary *metadata = NULL; | |
| 1394 | |||
| 1395 |
4/4✓ Branch 0 taken 1370228 times.
✓ Branch 1 taken 404792 times.
✓ Branch 2 taken 1132709 times.
✓ Branch 3 taken 237519 times.
|
1775020 | while (!got_packet && !fci->parse_queue.head) { |
| 1396 | AVStream *st; | ||
| 1397 | FFStream *sti; | ||
| 1398 | |||
| 1399 | /* read next packet */ | ||
| 1400 | 1132709 | ret = ff_read_packet(s, pkt); | |
| 1401 |
2/2✓ Branch 0 taken 7123 times.
✓ Branch 1 taken 1125586 times.
|
1132709 | if (ret < 0) { |
| 1402 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7122 times.
|
7123 | if (ret == AVERROR(EAGAIN)) |
| 1403 | 1 | return ret; | |
| 1404 | /* flush the parsers */ | ||
| 1405 |
2/2✓ Branch 0 taken 8278 times.
✓ Branch 1 taken 7122 times.
|
15400 | for (unsigned i = 0; i < s->nb_streams; i++) { |
| 1406 | 8278 | AVStream *const st = s->streams[i]; | |
| 1407 | 8278 | FFStream *const sti = ffstream(st); | |
| 1408 |
4/4✓ Branch 0 taken 3179 times.
✓ Branch 1 taken 5099 times.
✓ Branch 2 taken 2322 times.
✓ Branch 3 taken 857 times.
|
8278 | if (sti->parser && sti->need_parsing) |
| 1409 | 2322 | parse_packet(s, pkt, st->index, 1); | |
| 1410 | } | ||
| 1411 | /* all remaining packets are now in parse_queue => | ||
| 1412 | * really terminate parsing */ | ||
| 1413 | 7122 | break; | |
| 1414 | } | ||
| 1415 | 1125586 | ret = 0; | |
| 1416 | 1125586 | st = s->streams[pkt->stream_index]; | |
| 1417 | 1125586 | sti = ffstream(st); | |
| 1418 | |||
| 1419 | 1125586 | st->event_flags |= AVSTREAM_EVENT_FLAG_NEW_PACKETS; | |
| 1420 | |||
| 1421 | 1125586 | int new_extradata = !!av_packet_side_data_get(pkt->side_data, pkt->side_data_elems, | |
| 1422 | AV_PKT_DATA_NEW_EXTRADATA); | ||
| 1423 |
2/2✓ Branch 0 taken 21 times.
✓ Branch 1 taken 1125565 times.
|
1125586 | if (new_extradata) |
| 1424 | 21 | sti->need_context_update = 1; | |
| 1425 | |||
| 1426 | /* update context if required */ | ||
| 1427 |
2/2✓ Branch 0 taken 187 times.
✓ Branch 1 taken 1125399 times.
|
1125586 | if (sti->need_context_update) { |
| 1428 |
2/2✓ Branch 1 taken 15 times.
✓ Branch 2 taken 172 times.
|
187 | if (avcodec_is_open(sti->avctx)) { |
| 1429 | 15 | av_log(s, AV_LOG_DEBUG, "Demuxer context update while decoder is open, closing and trying to re-open\n"); | |
| 1430 | 15 | ret = codec_close(sti); | |
| 1431 | 15 | sti->info->found_decoder = 0; | |
| 1432 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
|
15 | if (ret < 0) |
| 1433 | ✗ | return ret; | |
| 1434 | } | ||
| 1435 | |||
| 1436 | /* close parser, because it depends on the codec and extradata */ | ||
| 1437 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 159 times.
|
187 | if (sti->parser && |
| 1438 |
4/4✓ Branch 0 taken 17 times.
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 14 times.
✓ Branch 3 taken 3 times.
|
28 | (sti->avctx->codec_id != st->codecpar->codec_id || new_extradata)) { |
| 1439 | 25 | av_parser_close(sti->parser); | |
| 1440 | 25 | sti->parser = NULL; | |
| 1441 | } | ||
| 1442 | |||
| 1443 | 187 | ret = avcodec_parameters_to_context(sti->avctx, st->codecpar); | |
| 1444 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 187 times.
|
187 | if (ret < 0) { |
| 1445 | ✗ | av_packet_unref(pkt); | |
| 1446 | ✗ | return ret; | |
| 1447 | } | ||
| 1448 | |||
| 1449 |
2/2✓ Branch 0 taken 143 times.
✓ Branch 1 taken 44 times.
|
187 | if (!sti->avctx->extradata) { |
| 1450 | 143 | sti->extract_extradata.inited = 0; | |
| 1451 | |||
| 1452 | 143 | ret = extract_extradata(si, st, pkt); | |
| 1453 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 143 times.
|
143 | if (ret < 0) { |
| 1454 | ✗ | av_packet_unref(pkt); | |
| 1455 | ✗ | return ret; | |
| 1456 | } | ||
| 1457 | } | ||
| 1458 | |||
| 1459 | 187 | sti->codec_desc = avcodec_descriptor_get(sti->avctx->codec_id); | |
| 1460 | |||
| 1461 | 187 | sti->need_context_update = 0; | |
| 1462 | } | ||
| 1463 | |||
| 1464 |
2/2✓ Branch 0 taken 349967 times.
✓ Branch 1 taken 775619 times.
|
1125586 | if (pkt->pts != AV_NOPTS_VALUE && |
| 1465 |
2/2✓ Branch 0 taken 173442 times.
✓ Branch 1 taken 176525 times.
|
349967 | pkt->dts != AV_NOPTS_VALUE && |
| 1466 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 173442 times.
|
173442 | pkt->pts < pkt->dts) { |
| 1467 | ✗ | av_log(s, AV_LOG_WARNING, | |
| 1468 | "Invalid timestamps stream=%d, pts=%s, dts=%s, size=%d\n", | ||
| 1469 | pkt->stream_index, | ||
| 1470 | ✗ | av_ts2str(pkt->pts), | |
| 1471 | ✗ | av_ts2str(pkt->dts), | |
| 1472 | pkt->size); | ||
| 1473 | } | ||
| 1474 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1125586 times.
|
1125586 | if (s->debug & AV_FDEBUG_TS) |
| 1475 | ✗ | av_log(s, AV_LOG_DEBUG, | |
| 1476 | "ff_read_packet stream=%d, pts=%s, dts=%s, size=%d, duration=%"PRId64", flags=%d\n", | ||
| 1477 | pkt->stream_index, | ||
| 1478 | ✗ | av_ts2str(pkt->pts), | |
| 1479 | ✗ | av_ts2str(pkt->dts), | |
| 1480 | pkt->size, pkt->duration, pkt->flags); | ||
| 1481 | |||
| 1482 |
5/6✓ Branch 0 taken 722040 times.
✓ Branch 1 taken 403546 times.
✓ Branch 2 taken 2943 times.
✓ Branch 3 taken 719097 times.
✓ Branch 4 taken 2943 times.
✗ Branch 5 not taken.
|
1125586 | if (sti->need_parsing && !sti->parser && !(s->flags & AVFMT_FLAG_NOPARSE)) { |
| 1483 | 2943 | sti->parser = av_parser_init(st->codecpar->codec_id); | |
| 1484 |
2/2✓ Branch 0 taken 1246 times.
✓ Branch 1 taken 1697 times.
|
2943 | if (!sti->parser) { |
| 1485 | 1246 | av_log(s, AV_LOG_VERBOSE, "parser not found for codec " | |
| 1486 | "%s, packets or times may be invalid.\n", | ||
| 1487 | 1246 | avcodec_get_name(st->codecpar->codec_id)); | |
| 1488 | /* no parser available: just output the raw packets */ | ||
| 1489 | 1246 | sti->need_parsing = AVSTREAM_PARSE_NONE; | |
| 1490 |
2/2✓ Branch 0 taken 725 times.
✓ Branch 1 taken 972 times.
|
1697 | } else if (sti->need_parsing == AVSTREAM_PARSE_HEADERS) |
| 1491 | 725 | sti->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES; | |
| 1492 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 972 times.
|
972 | else if (sti->need_parsing == AVSTREAM_PARSE_FULL_ONCE) |
| 1493 | ✗ | sti->parser->flags |= PARSER_FLAG_ONCE; | |
| 1494 |
2/2✓ Branch 0 taken 478 times.
✓ Branch 1 taken 494 times.
|
972 | else if (sti->need_parsing == AVSTREAM_PARSE_FULL_RAW) |
| 1495 | 478 | sti->parser->flags |= PARSER_FLAG_USE_CODEC_TS; | |
| 1496 | } | ||
| 1497 | |||
| 1498 |
3/4✓ Branch 0 taken 720794 times.
✓ Branch 1 taken 404792 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 720794 times.
|
1125586 | if (!sti->need_parsing || !sti->parser) { |
| 1499 | /* no parsing needed: we just output the packet as is */ | ||
| 1500 | 404792 | compute_pkt_fields(s, st, NULL, pkt, AV_NOPTS_VALUE, AV_NOPTS_VALUE); | |
| 1501 |
2/2✓ Branch 0 taken 96574 times.
✓ Branch 1 taken 308218 times.
|
404792 | if ((s->iformat->flags & AVFMT_GENERIC_INDEX) && |
| 1502 |
4/4✓ Branch 0 taken 95704 times.
✓ Branch 1 taken 870 times.
✓ Branch 2 taken 95431 times.
✓ Branch 3 taken 273 times.
|
96574 | (pkt->flags & AV_PKT_FLAG_KEY) && pkt->dts != AV_NOPTS_VALUE) { |
| 1503 | 95431 | ff_reduce_index(s, st->index); | |
| 1504 | 95431 | av_add_index_entry(st, pkt->pos, pkt->dts, | |
| 1505 | 0, 0, AVINDEX_KEYFRAME); | ||
| 1506 | } | ||
| 1507 | 404792 | got_packet = 1; | |
| 1508 |
2/2✓ Branch 0 taken 720661 times.
✓ Branch 1 taken 133 times.
|
720794 | } else if (st->discard < AVDISCARD_ALL) { |
| 1509 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 720661 times.
|
720661 | if ((ret = parse_packet(s, pkt, pkt->stream_index, 0)) < 0) |
| 1510 | ✗ | return ret; | |
| 1511 | 720661 | st->codecpar->sample_rate = sti->avctx->sample_rate; | |
| 1512 | 720661 | st->codecpar->bit_rate = sti->avctx->bit_rate; | |
| 1513 | 720661 | ret = av_channel_layout_copy(&st->codecpar->ch_layout, &sti->avctx->ch_layout); | |
| 1514 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 720661 times.
|
720661 | if (ret < 0) |
| 1515 | ✗ | return ret; | |
| 1516 | 720661 | st->codecpar->codec_id = sti->avctx->codec_id; | |
| 1517 | } else { | ||
| 1518 | /* free packet */ | ||
| 1519 | 133 | av_packet_unref(pkt); | |
| 1520 | } | ||
| 1521 |
2/2✓ Branch 0 taken 378525 times.
✓ Branch 1 taken 747061 times.
|
1125586 | if (pkt->flags & AV_PKT_FLAG_KEY) |
| 1522 | 378525 | sti->skip_to_keyframe = 0; | |
| 1523 |
2/2✓ Branch 0 taken 85 times.
✓ Branch 1 taken 1125501 times.
|
1125586 | if (sti->skip_to_keyframe) { |
| 1524 | 85 | av_packet_unref(pkt); | |
| 1525 | 85 | got_packet = 0; | |
| 1526 | } | ||
| 1527 | } | ||
| 1528 | |||
| 1529 |
4/4✓ Branch 0 taken 244641 times.
✓ Branch 1 taken 404792 times.
✓ Branch 2 taken 238528 times.
✓ Branch 3 taken 6113 times.
|
649433 | if (!got_packet && fci->parse_queue.head) |
| 1530 | 238528 | ret = ff_packet_list_get(&fci->parse_queue, pkt); | |
| 1531 | |||
| 1532 |
2/2✓ Branch 0 taken 643320 times.
✓ Branch 1 taken 6113 times.
|
649433 | if (ret >= 0) { |
| 1533 | 643320 | AVStream *const st = s->streams[pkt->stream_index]; | |
| 1534 | 643320 | FFStream *const sti = ffstream(st); | |
| 1535 | 643320 | int discard_padding = 0; | |
| 1536 |
3/4✓ Branch 0 taken 16465 times.
✓ Branch 1 taken 626855 times.
✓ Branch 2 taken 16465 times.
✗ Branch 3 not taken.
|
643320 | if (sti->first_discard_sample && pkt->pts != AV_NOPTS_VALUE) { |
| 1537 |
2/2✓ Branch 1 taken 6911 times.
✓ Branch 2 taken 9554 times.
|
16465 | int64_t pts = pkt->pts - (is_relative(pkt->pts) ? RELATIVE_TS_BASE : 0); |
| 1538 | 16465 | int64_t sample = ts_to_samples(st, pts); | |
| 1539 |
2/2✓ Branch 1 taken 16 times.
✓ Branch 2 taken 16449 times.
|
16465 | int64_t duration = FFMAX(st->codecpar->frame_size, ts_to_samples(st, pkt->duration)); |
| 1540 | 16465 | int64_t end_sample = sample + duration; | |
| 1541 |
3/4✓ Branch 0 taken 16465 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 326 times.
✓ Branch 3 taken 16139 times.
|
16465 | if (duration > 0 && end_sample >= sti->first_discard_sample && |
| 1542 |
2/2✓ Branch 0 taken 322 times.
✓ Branch 1 taken 4 times.
|
326 | sample < sti->last_discard_sample) |
| 1543 | 322 | discard_padding = FFMIN(end_sample - sti->first_discard_sample, duration); | |
| 1544 | } | ||
| 1545 |
6/6✓ Branch 0 taken 9577 times.
✓ Branch 1 taken 633743 times.
✓ Branch 2 taken 9559 times.
✓ Branch 3 taken 18 times.
✓ Branch 4 taken 125 times.
✓ Branch 5 taken 9434 times.
|
643320 | if (sti->start_skip_samples && (pkt->pts == 0 || pkt->pts == RELATIVE_TS_BASE)) |
| 1546 | 143 | sti->skip_samples = sti->start_skip_samples; | |
| 1547 | 643320 | sti->skip_samples = FFMAX(0, sti->skip_samples); | |
| 1548 |
4/4✓ Branch 0 taken 643073 times.
✓ Branch 1 taken 247 times.
✓ Branch 2 taken 126 times.
✓ Branch 3 taken 642947 times.
|
643320 | if (sti->skip_samples || discard_padding) { |
| 1549 | 373 | uint8_t *p = av_packet_new_side_data(pkt, AV_PKT_DATA_SKIP_SAMPLES, 10); | |
| 1550 |
1/2✓ Branch 0 taken 373 times.
✗ Branch 1 not taken.
|
373 | if (p) { |
| 1551 | 373 | AV_WL32(p, sti->skip_samples); | |
| 1552 | 373 | AV_WL32(p + 4, discard_padding); | |
| 1553 | 373 | av_log(s, AV_LOG_DEBUG, "demuxer injecting skip %u / discard %u\n", | |
| 1554 | 373 | (unsigned)sti->skip_samples, (unsigned)discard_padding); | |
| 1555 | } | ||
| 1556 | 373 | sti->skip_samples = 0; | |
| 1557 | } | ||
| 1558 | } | ||
| 1559 | |||
| 1560 |
2/2✓ Branch 0 taken 8228 times.
✓ Branch 1 taken 641205 times.
|
649433 | if (!fci->metafree) { |
| 1561 | 8228 | int metaret = av_opt_get_dict_val(s, "metadata", AV_OPT_SEARCH_CHILDREN, &metadata); | |
| 1562 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8228 times.
|
8228 | if (metadata) { |
| 1563 | ✗ | s->event_flags |= AVFMT_EVENT_FLAG_METADATA_UPDATED; | |
| 1564 | ✗ | av_dict_copy(&s->metadata, metadata, 0); | |
| 1565 | ✗ | av_dict_free(&metadata); | |
| 1566 | ✗ | av_opt_set_dict_val(s, "metadata", NULL, AV_OPT_SEARCH_CHILDREN); | |
| 1567 | } | ||
| 1568 | 8228 | fci->metafree = metaret == AVERROR_OPTION_NOT_FOUND; | |
| 1569 | } | ||
| 1570 | |||
| 1571 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 649433 times.
|
649433 | if (s->debug & AV_FDEBUG_TS) |
| 1572 | ✗ | av_log(s, AV_LOG_DEBUG, | |
| 1573 | "read_frame_internal stream=%d, pts=%s, dts=%s, " | ||
| 1574 | "size=%d, duration=%"PRId64", flags=%d\n", | ||
| 1575 | pkt->stream_index, | ||
| 1576 | ✗ | av_ts2str(pkt->pts), | |
| 1577 | ✗ | av_ts2str(pkt->dts), | |
| 1578 | pkt->size, pkt->duration, pkt->flags); | ||
| 1579 | |||
| 1580 | /* A demuxer might have returned EOF because of an IO error, let's | ||
| 1581 | * propagate this back to the user. */ | ||
| 1582 |
5/8✓ Branch 0 taken 6003 times.
✓ Branch 1 taken 643430 times.
✓ Branch 2 taken 5757 times.
✓ Branch 3 taken 246 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 5757 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
649433 | if (ret == AVERROR_EOF && s->pb && s->pb->error < 0 && s->pb->error != AVERROR(EAGAIN)) |
| 1583 | ✗ | ret = s->pb->error; | |
| 1584 | |||
| 1585 | 649433 | return ret; | |
| 1586 | } | ||
| 1587 | |||
| 1588 | 566893 | int av_read_frame(AVFormatContext *s, AVPacket *pkt) | |
| 1589 | { | ||
| 1590 | 566893 | FFFormatContext *const si = ffformatcontext(s); | |
| 1591 | 566893 | const int genpts = s->flags & AVFMT_FLAG_GENPTS; | |
| 1592 | 566893 | int eof = 0; | |
| 1593 | int ret; | ||
| 1594 | AVStream *st; | ||
| 1595 | |||
| 1596 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 566893 times.
|
566893 | if (!genpts) { |
| 1597 | 1133786 | ret = si->packet_buffer.head | |
| 1598 | 120720 | ? ff_packet_list_get(&si->packet_buffer, pkt) | |
| 1599 |
2/2✓ Branch 0 taken 120720 times.
✓ Branch 1 taken 446173 times.
|
566893 | : read_frame_internal(s, pkt); |
| 1600 |
2/2✓ Branch 0 taken 4718 times.
✓ Branch 1 taken 562175 times.
|
566893 | if (ret < 0) |
| 1601 | 4718 | return ret; | |
| 1602 | 562175 | goto return_packet; | |
| 1603 | } | ||
| 1604 | |||
| 1605 | ✗ | for (;;) { | |
| 1606 | ✗ | PacketListEntry *pktl = si->packet_buffer.head; | |
| 1607 | |||
| 1608 | ✗ | if (pktl) { | |
| 1609 | ✗ | AVPacket *next_pkt = &pktl->pkt; | |
| 1610 | |||
| 1611 | ✗ | if (next_pkt->dts != AV_NOPTS_VALUE) { | |
| 1612 | ✗ | int wrap_bits = s->streams[next_pkt->stream_index]->pts_wrap_bits; | |
| 1613 | // last dts seen for this stream. if any of packets following | ||
| 1614 | // current one had no dts, we will set this to AV_NOPTS_VALUE. | ||
| 1615 | ✗ | int64_t last_dts = next_pkt->dts; | |
| 1616 | av_assert2(wrap_bits <= 64); | ||
| 1617 | ✗ | while (pktl && next_pkt->pts == AV_NOPTS_VALUE) { | |
| 1618 | ✗ | if (pktl->pkt.stream_index == next_pkt->stream_index && | |
| 1619 | ✗ | av_compare_mod(next_pkt->dts, pktl->pkt.dts, 2ULL << (wrap_bits - 1)) < 0) { | |
| 1620 | ✗ | if (av_compare_mod(pktl->pkt.pts, pktl->pkt.dts, 2ULL << (wrap_bits - 1))) { | |
| 1621 | // not B-frame | ||
| 1622 | ✗ | next_pkt->pts = pktl->pkt.dts; | |
| 1623 | } | ||
| 1624 | ✗ | if (last_dts != AV_NOPTS_VALUE) { | |
| 1625 | // Once last dts was set to AV_NOPTS_VALUE, we don't change it. | ||
| 1626 | ✗ | last_dts = pktl->pkt.dts; | |
| 1627 | } | ||
| 1628 | } | ||
| 1629 | ✗ | pktl = pktl->next; | |
| 1630 | } | ||
| 1631 | ✗ | if (eof && next_pkt->pts == AV_NOPTS_VALUE && last_dts != AV_NOPTS_VALUE) { | |
| 1632 | // Fixing the last reference frame had none pts issue (For MXF etc). | ||
| 1633 | // We only do this when | ||
| 1634 | // 1. eof. | ||
| 1635 | // 2. we are not able to resolve a pts value for current packet. | ||
| 1636 | // 3. the packets for this stream at the end of the files had valid dts. | ||
| 1637 | ✗ | next_pkt->pts = last_dts + next_pkt->duration; | |
| 1638 | } | ||
| 1639 | ✗ | pktl = si->packet_buffer.head; | |
| 1640 | } | ||
| 1641 | |||
| 1642 | /* read packet from packet buffer, if there is data */ | ||
| 1643 | ✗ | st = s->streams[next_pkt->stream_index]; | |
| 1644 | ✗ | if (!(next_pkt->pts == AV_NOPTS_VALUE && st->discard < AVDISCARD_ALL && | |
| 1645 | ✗ | next_pkt->dts != AV_NOPTS_VALUE && !eof)) { | |
| 1646 | ✗ | ret = ff_packet_list_get(&si->packet_buffer, pkt); | |
| 1647 | ✗ | goto return_packet; | |
| 1648 | } | ||
| 1649 | } | ||
| 1650 | |||
| 1651 | ✗ | ret = read_frame_internal(s, pkt); | |
| 1652 | ✗ | if (ret < 0) { | |
| 1653 | ✗ | if (pktl && ret != AVERROR(EAGAIN)) { | |
| 1654 | ✗ | eof = 1; | |
| 1655 | ✗ | continue; | |
| 1656 | } else | ||
| 1657 | ✗ | return ret; | |
| 1658 | } | ||
| 1659 | |||
| 1660 | ✗ | ret = ff_packet_list_put(&si->packet_buffer, | |
| 1661 | pkt, NULL, 0); | ||
| 1662 | ✗ | if (ret < 0) { | |
| 1663 | ✗ | av_packet_unref(pkt); | |
| 1664 | ✗ | return ret; | |
| 1665 | } | ||
| 1666 | } | ||
| 1667 | |||
| 1668 | 562175 | return_packet: | |
| 1669 | 562175 | st = s->streams[pkt->stream_index]; | |
| 1670 |
4/4✓ Branch 0 taken 243556 times.
✓ Branch 1 taken 318619 times.
✓ Branch 2 taken 168570 times.
✓ Branch 3 taken 74986 times.
|
562175 | if ((s->iformat->flags & AVFMT_GENERIC_INDEX) && pkt->flags & AV_PKT_FLAG_KEY) { |
| 1671 | 168570 | ff_reduce_index(s, st->index); | |
| 1672 | 168570 | av_add_index_entry(st, pkt->pos, pkt->dts, 0, 0, AVINDEX_KEYFRAME); | |
| 1673 | } | ||
| 1674 | |||
| 1675 |
2/2✓ Branch 1 taken 158724 times.
✓ Branch 2 taken 403451 times.
|
562175 | if (is_relative(pkt->dts)) |
| 1676 | 158724 | pkt->dts -= RELATIVE_TS_BASE; | |
| 1677 |
2/2✓ Branch 1 taken 157031 times.
✓ Branch 2 taken 405144 times.
|
562175 | if (is_relative(pkt->pts)) |
| 1678 | 157031 | pkt->pts -= RELATIVE_TS_BASE; | |
| 1679 | |||
| 1680 | 562175 | return ret; | |
| 1681 | } | ||
| 1682 | |||
| 1683 | /** | ||
| 1684 | * Return TRUE if the stream has accurate duration in any stream. | ||
| 1685 | * | ||
| 1686 | * @return TRUE if the stream has accurate duration for at least one component. | ||
| 1687 | */ | ||
| 1688 | 8138 | static int has_duration(AVFormatContext *ic) | |
| 1689 | { | ||
| 1690 |
2/2✓ Branch 0 taken 8486 times.
✓ Branch 1 taken 2676 times.
|
11162 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
| 1691 | 8486 | const AVStream *const st = ic->streams[i]; | |
| 1692 |
2/2✓ Branch 0 taken 5462 times.
✓ Branch 1 taken 3024 times.
|
8486 | if (st->duration != AV_NOPTS_VALUE) |
| 1693 | 5462 | return 1; | |
| 1694 | } | ||
| 1695 |
2/2✓ Branch 0 taken 521 times.
✓ Branch 1 taken 2155 times.
|
2676 | if (ic->duration != AV_NOPTS_VALUE) |
| 1696 | 521 | return 1; | |
| 1697 | 2155 | return 0; | |
| 1698 | } | ||
| 1699 | |||
| 1700 | /** | ||
| 1701 | * Estimate the stream timings from the one of each components. | ||
| 1702 | * | ||
| 1703 | * Also computes the global bitrate if possible. | ||
| 1704 | */ | ||
| 1705 | 14307 | static void update_stream_timings(AVFormatContext *ic) | |
| 1706 | { | ||
| 1707 | int64_t start_time, start_time1, start_time_text, end_time, end_time1, end_time_text; | ||
| 1708 | int64_t duration, duration1, duration_text, filesize; | ||
| 1709 | |||
| 1710 | 14307 | start_time = INT64_MAX; | |
| 1711 | 14307 | start_time_text = INT64_MAX; | |
| 1712 | 14307 | end_time = INT64_MIN; | |
| 1713 | 14307 | end_time_text = INT64_MIN; | |
| 1714 | 14307 | duration = INT64_MIN; | |
| 1715 | 14307 | duration_text = INT64_MIN; | |
| 1716 | |||
| 1717 |
2/2✓ Branch 0 taken 15928 times.
✓ Branch 1 taken 14307 times.
|
30235 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
| 1718 | 15928 | AVStream *const st = ic->streams[i]; | |
| 1719 |
2/2✓ Branch 0 taken 15787 times.
✓ Branch 1 taken 141 times.
|
31715 | int is_text = st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE || |
| 1720 |
2/2✓ Branch 0 taken 159 times.
✓ Branch 1 taken 15628 times.
|
15787 | st->codecpar->codec_type == AVMEDIA_TYPE_DATA; |
| 1721 | |||
| 1722 |
3/4✓ Branch 0 taken 13010 times.
✓ Branch 1 taken 2918 times.
✓ Branch 2 taken 13010 times.
✗ Branch 3 not taken.
|
15928 | if (st->start_time != AV_NOPTS_VALUE && st->time_base.den) { |
| 1723 | 13010 | start_time1 = av_rescale_q(st->start_time, st->time_base, | |
| 1724 | 13010 | AV_TIME_BASE_Q); | |
| 1725 |
2/2✓ Branch 0 taken 166 times.
✓ Branch 1 taken 12844 times.
|
13010 | if (is_text) |
| 1726 | 166 | start_time_text = FFMIN(start_time_text, start_time1); | |
| 1727 | else | ||
| 1728 | 12844 | start_time = FFMIN(start_time, start_time1); | |
| 1729 | 13010 | end_time1 = av_rescale_q_rnd(st->duration, st->time_base, | |
| 1730 | 13010 | AV_TIME_BASE_Q, | |
| 1731 | AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX); | ||
| 1732 |
5/6✓ Branch 0 taken 11436 times.
✓ Branch 1 taken 1574 times.
✓ Branch 2 taken 11407 times.
✓ Branch 3 taken 29 times.
✓ Branch 4 taken 11436 times.
✗ Branch 5 not taken.
|
13010 | if (end_time1 != AV_NOPTS_VALUE && (end_time1 > 0 ? start_time1 <= INT64_MAX - end_time1 : start_time1 >= INT64_MIN - end_time1)) { |
| 1733 | 11436 | end_time1 += start_time1; | |
| 1734 |
2/2✓ Branch 0 taken 149 times.
✓ Branch 1 taken 11287 times.
|
11436 | if (is_text) |
| 1735 | 149 | end_time_text = FFMAX(end_time_text, end_time1); | |
| 1736 | else | ||
| 1737 | 11287 | end_time = FFMAX(end_time, end_time1); | |
| 1738 | } | ||
| 1739 |
2/2✓ Branch 1 taken 273 times.
✓ Branch 2 taken 13010 times.
|
13283 | for (AVProgram *p = NULL; (p = av_find_program_from_stream(ic, p, i)); ) { |
| 1740 |
4/4✓ Branch 0 taken 191 times.
✓ Branch 1 taken 82 times.
✓ Branch 2 taken 25 times.
✓ Branch 3 taken 166 times.
|
273 | if (p->start_time == AV_NOPTS_VALUE || p->start_time > start_time1) |
| 1741 | 107 | p->start_time = start_time1; | |
| 1742 |
2/2✓ Branch 0 taken 73 times.
✓ Branch 1 taken 200 times.
|
273 | if (p->end_time < end_time1) |
| 1743 | 73 | p->end_time = end_time1; | |
| 1744 | } | ||
| 1745 | } | ||
| 1746 |
2/2✓ Branch 0 taken 13022 times.
✓ Branch 1 taken 2906 times.
|
15928 | if (st->duration != AV_NOPTS_VALUE) { |
| 1747 | 13022 | duration1 = av_rescale_q(st->duration, st->time_base, | |
| 1748 | 13022 | AV_TIME_BASE_Q); | |
| 1749 |
2/2✓ Branch 0 taken 179 times.
✓ Branch 1 taken 12843 times.
|
13022 | if (is_text) |
| 1750 | 179 | duration_text = FFMAX(duration_text, duration1); | |
| 1751 | else | ||
| 1752 | 12843 | duration = FFMAX(duration, duration1); | |
| 1753 | } | ||
| 1754 | } | ||
| 1755 |
3/6✓ Branch 0 taken 11650 times.
✓ Branch 1 taken 2657 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 11650 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
14307 | if (start_time == INT64_MAX || (start_time > start_time_text && start_time - (uint64_t)start_time_text < AV_TIME_BASE)) |
| 1756 | 2657 | start_time = start_time_text; | |
| 1757 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11650 times.
|
11650 | else if (start_time > start_time_text) |
| 1758 | ✗ | av_log(ic, AV_LOG_VERBOSE, "Ignoring outlier non primary stream starttime %f\n", start_time_text / (float)AV_TIME_BASE); | |
| 1759 | |||
| 1760 |
6/6✓ Branch 0 taken 10533 times.
✓ Branch 1 taken 3774 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 10527 times.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 2 times.
|
14307 | if (end_time == INT64_MIN || (end_time < end_time_text && end_time_text - (uint64_t)end_time < AV_TIME_BASE)) |
| 1761 | 3778 | end_time = end_time_text; | |
| 1762 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 10527 times.
|
10529 | else if (end_time < end_time_text) |
| 1763 | 2 | av_log(ic, AV_LOG_VERBOSE, "Ignoring outlier non primary stream endtime %f\n", end_time_text / (float)AV_TIME_BASE); | |
| 1764 | |||
| 1765 |
6/6✓ Branch 0 taken 12071 times.
✓ Branch 1 taken 2236 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 12059 times.
✓ Branch 4 taken 10 times.
✓ Branch 5 taken 2 times.
|
14307 | if (duration == INT64_MIN || (duration < duration_text && (uint64_t)duration_text - duration < AV_TIME_BASE)) |
| 1766 | 2246 | duration = duration_text; | |
| 1767 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 12059 times.
|
12061 | else if (duration < duration_text) |
| 1768 | 2 | av_log(ic, AV_LOG_VERBOSE, "Ignoring outlier non primary stream duration %f\n", duration_text / (float)AV_TIME_BASE); | |
| 1769 | |||
| 1770 |
2/2✓ Branch 0 taken 11673 times.
✓ Branch 1 taken 2634 times.
|
14307 | if (start_time != INT64_MAX) { |
| 1771 | 11673 | ic->start_time = start_time; | |
| 1772 |
2/2✓ Branch 0 taken 10550 times.
✓ Branch 1 taken 1123 times.
|
11673 | if (end_time != INT64_MIN) { |
| 1773 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10550 times.
|
10550 | if (ic->nb_programs > 1) { |
| 1774 | ✗ | for (unsigned i = 0; i < ic->nb_programs; i++) { | |
| 1775 | ✗ | AVProgram *const p = ic->programs[i]; | |
| 1776 | |||
| 1777 | ✗ | if (p->start_time != AV_NOPTS_VALUE && | |
| 1778 | ✗ | p->end_time > p->start_time && | |
| 1779 | ✗ | p->end_time - (uint64_t)p->start_time <= INT64_MAX) | |
| 1780 | ✗ | duration = FFMAX(duration, p->end_time - p->start_time); | |
| 1781 | } | ||
| 1782 |
2/4✓ Branch 0 taken 10550 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10550 times.
✗ Branch 3 not taken.
|
10550 | } else if (end_time >= start_time && end_time - (uint64_t)start_time <= INT64_MAX) { |
| 1783 | 10550 | duration = FFMAX(duration, end_time - start_time); | |
| 1784 | } | ||
| 1785 | } | ||
| 1786 | } | ||
| 1787 |
6/6✓ Branch 0 taken 12101 times.
✓ Branch 1 taken 2206 times.
✓ Branch 2 taken 12065 times.
✓ Branch 3 taken 36 times.
✓ Branch 4 taken 6454 times.
✓ Branch 5 taken 5611 times.
|
14307 | if (duration != INT64_MIN && duration > 0 && ic->duration == AV_NOPTS_VALUE) { |
| 1788 | 6454 | ic->duration = duration; | |
| 1789 | } | ||
| 1790 |
6/6✓ Branch 0 taken 7989 times.
✓ Branch 1 taken 6318 times.
✓ Branch 3 taken 7988 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 6791 times.
✓ Branch 6 taken 1197 times.
|
14307 | if (ic->pb && (filesize = avio_size(ic->pb)) > 0 && ic->duration > 0) { |
| 1791 | /* compute the bitrate */ | ||
| 1792 | 6791 | double bitrate = (double) filesize * 8.0 * AV_TIME_BASE / | |
| 1793 | 6791 | (double) ic->duration; | |
| 1794 |
2/4✓ Branch 0 taken 6791 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6791 times.
✗ Branch 3 not taken.
|
6791 | if (bitrate >= 0 && bitrate <= INT64_MAX) |
| 1795 | 6791 | ic->bit_rate = bitrate; | |
| 1796 | } | ||
| 1797 | 14307 | } | |
| 1798 | |||
| 1799 | 6076 | static void fill_all_stream_timings(AVFormatContext *ic) | |
| 1800 | { | ||
| 1801 | 6076 | update_stream_timings(ic); | |
| 1802 |
2/2✓ Branch 0 taken 6794 times.
✓ Branch 1 taken 6076 times.
|
12870 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
| 1803 | 6794 | AVStream *const st = ic->streams[i]; | |
| 1804 | |||
| 1805 |
2/2✓ Branch 0 taken 861 times.
✓ Branch 1 taken 5933 times.
|
6794 | if (st->start_time == AV_NOPTS_VALUE) { |
| 1806 |
2/2✓ Branch 0 taken 153 times.
✓ Branch 1 taken 708 times.
|
861 | if (ic->start_time != AV_NOPTS_VALUE) |
| 1807 | 153 | st->start_time = av_rescale_q(ic->start_time, AV_TIME_BASE_Q, | |
| 1808 | st->time_base); | ||
| 1809 |
2/2✓ Branch 0 taken 846 times.
✓ Branch 1 taken 15 times.
|
861 | if (ic->duration != AV_NOPTS_VALUE) |
| 1810 | 846 | st->duration = av_rescale_q(ic->duration, AV_TIME_BASE_Q, | |
| 1811 | st->time_base); | ||
| 1812 | } | ||
| 1813 | } | ||
| 1814 | 6076 | } | |
| 1815 | |||
| 1816 | 2155 | static void estimate_timings_from_bit_rate(AVFormatContext *ic) | |
| 1817 | { | ||
| 1818 | 2155 | FFFormatContext *const si = ffformatcontext(ic); | |
| 1819 | 2155 | int show_warning = 0; | |
| 1820 | |||
| 1821 | /* if bit_rate is already set, we believe it */ | ||
| 1822 |
2/2✓ Branch 0 taken 2120 times.
✓ Branch 1 taken 35 times.
|
2155 | if (ic->bit_rate <= 0) { |
| 1823 | 2120 | int64_t bit_rate = 0; | |
| 1824 |
2/2✓ Branch 0 taken 2281 times.
✓ Branch 1 taken 1445 times.
|
3726 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
| 1825 | 2281 | const AVStream *const st = ic->streams[i]; | |
| 1826 | 2281 | const FFStream *const sti = cffstream(st); | |
| 1827 |
4/4✓ Branch 0 taken 1448 times.
✓ Branch 1 taken 833 times.
✓ Branch 2 taken 120 times.
✓ Branch 3 taken 1328 times.
|
2281 | if (st->codecpar->bit_rate <= 0 && sti->avctx->bit_rate > 0) |
| 1828 | 120 | st->codecpar->bit_rate = sti->avctx->bit_rate; | |
| 1829 |
2/2✓ Branch 0 taken 953 times.
✓ Branch 1 taken 1328 times.
|
2281 | if (st->codecpar->bit_rate > 0) { |
| 1830 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 953 times.
|
953 | if (INT64_MAX - st->codecpar->bit_rate < bit_rate) { |
| 1831 | ✗ | bit_rate = 0; | |
| 1832 | ✗ | break; | |
| 1833 | } | ||
| 1834 | 953 | bit_rate += st->codecpar->bit_rate; | |
| 1835 |
4/4✓ Branch 0 taken 1111 times.
✓ Branch 1 taken 217 times.
✓ Branch 2 taken 675 times.
✓ Branch 3 taken 436 times.
|
1328 | } else if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && sti->codec_info_nb_frames > 1) { |
| 1836 | // If we have a videostream with packets but without a bitrate | ||
| 1837 | // then consider the sum not known | ||
| 1838 | 675 | bit_rate = 0; | |
| 1839 | 675 | break; | |
| 1840 | } | ||
| 1841 | } | ||
| 1842 | 2120 | ic->bit_rate = bit_rate; | |
| 1843 | } | ||
| 1844 | |||
| 1845 | /* if duration is already set, we believe it */ | ||
| 1846 |
1/2✓ Branch 0 taken 2155 times.
✗ Branch 1 not taken.
|
2155 | if (ic->duration == AV_NOPTS_VALUE && |
| 1847 |
2/2✓ Branch 0 taken 960 times.
✓ Branch 1 taken 1195 times.
|
2155 | ic->bit_rate != 0) { |
| 1848 |
2/2✓ Branch 0 taken 926 times.
✓ Branch 1 taken 34 times.
|
960 | int64_t filesize = ic->pb ? avio_size(ic->pb) : 0; |
| 1849 |
2/2✓ Branch 0 taken 917 times.
✓ Branch 1 taken 43 times.
|
960 | if (filesize > si->data_offset) { |
| 1850 | 917 | filesize -= si->data_offset; | |
| 1851 |
2/2✓ Branch 0 taken 956 times.
✓ Branch 1 taken 917 times.
|
1873 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
| 1852 | 956 | AVStream *const st = ic->streams[i]; | |
| 1853 | |||
| 1854 |
1/2✓ Branch 0 taken 956 times.
✗ Branch 1 not taken.
|
956 | if ( st->time_base.num <= INT64_MAX / ic->bit_rate |
| 1855 |
1/2✓ Branch 0 taken 956 times.
✗ Branch 1 not taken.
|
956 | && st->duration == AV_NOPTS_VALUE) { |
| 1856 | 956 | st->duration = av_rescale(filesize, 8LL * st->time_base.den, | |
| 1857 | 956 | ic->bit_rate * | |
| 1858 | 956 | (int64_t) st->time_base.num); | |
| 1859 | 956 | show_warning = 1; | |
| 1860 | } | ||
| 1861 | } | ||
| 1862 | } | ||
| 1863 | } | ||
| 1864 |
2/2✓ Branch 0 taken 917 times.
✓ Branch 1 taken 1238 times.
|
2155 | if (show_warning) |
| 1865 | 917 | av_log(ic, AV_LOG_WARNING, | |
| 1866 | "Estimating duration from bitrate, this may be inaccurate\n"); | ||
| 1867 | 2155 | } | |
| 1868 | |||
| 1869 | #define DURATION_DEFAULT_MAX_READ_SIZE 250000LL | ||
| 1870 | #define DURATION_DEFAULT_MAX_RETRY 6 | ||
| 1871 | #define DURATION_MAX_RETRY 1 | ||
| 1872 | |||
| 1873 | /* only usable for MPEG-PS streams */ | ||
| 1874 | 93 | static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) | |
| 1875 | { | ||
| 1876 | 93 | FFFormatContext *const si = ffformatcontext(ic); | |
| 1877 | 93 | AVPacket *const pkt = si->pkt; | |
| 1878 | int num, den, read_size, ret; | ||
| 1879 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 93 times.
|
93 | int64_t duration_max_read_size = ic->duration_probesize ? ic->duration_probesize >> DURATION_MAX_RETRY : DURATION_DEFAULT_MAX_READ_SIZE; |
| 1880 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 93 times.
|
93 | int duration_max_retry = ic->duration_probesize ? DURATION_MAX_RETRY : DURATION_DEFAULT_MAX_RETRY; |
| 1881 | 93 | int found_duration = 0; | |
| 1882 | int is_end; | ||
| 1883 | int64_t filesize, offset, duration; | ||
| 1884 | 93 | int retry = 0; | |
| 1885 | |||
| 1886 | /* flush packet queue */ | ||
| 1887 | 93 | ff_flush_packet_queue(ic); | |
| 1888 | |||
| 1889 |
2/2✓ Branch 0 taken 173 times.
✓ Branch 1 taken 93 times.
|
266 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
| 1890 | 173 | AVStream *const st = ic->streams[i]; | |
| 1891 | 173 | FFStream *const sti = ffstream(st); | |
| 1892 | |||
| 1893 |
2/2✓ Branch 0 taken 22 times.
✓ Branch 1 taken 151 times.
|
173 | if (st->start_time == AV_NOPTS_VALUE && |
| 1894 |
1/2✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
|
22 | sti->first_dts == AV_NOPTS_VALUE && |
| 1895 |
1/2✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
|
22 | st->codecpar->codec_type != AVMEDIA_TYPE_UNKNOWN) |
| 1896 | 22 | av_log(ic, AV_LOG_WARNING, | |
| 1897 | "start time for stream %d is not set in estimate_timings_from_pts\n", i); | ||
| 1898 | |||
| 1899 |
2/2✓ Branch 0 taken 25 times.
✓ Branch 1 taken 148 times.
|
173 | if (sti->parser) { |
| 1900 | 25 | av_parser_close(sti->parser); | |
| 1901 | 25 | sti->parser = NULL; | |
| 1902 | } | ||
| 1903 | } | ||
| 1904 | |||
| 1905 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 93 times.
|
93 | if (ic->skip_estimate_duration_from_pts) { |
| 1906 | ✗ | av_log(ic, AV_LOG_INFO, "Skipping duration calculation in estimate_timings_from_pts\n"); | |
| 1907 | ✗ | goto skip_duration_calc; | |
| 1908 | } | ||
| 1909 | |||
| 1910 | 93 | av_opt_set_int(ic, "skip_changes", 1, AV_OPT_SEARCH_CHILDREN); | |
| 1911 | /* estimate the end time (duration) */ | ||
| 1912 | /* XXX: may need to support wrapping */ | ||
| 1913 |
1/2✓ Branch 0 taken 93 times.
✗ Branch 1 not taken.
|
93 | filesize = ic->pb ? avio_size(ic->pb) : 0; |
| 1914 | do { | ||
| 1915 | 100 | is_end = found_duration; | |
| 1916 | 100 | offset = filesize - (duration_max_read_size << retry); | |
| 1917 |
2/2✓ Branch 0 taken 44 times.
✓ Branch 1 taken 56 times.
|
100 | if (offset < 0) |
| 1918 | 44 | offset = 0; | |
| 1919 | |||
| 1920 | 100 | avio_seek(ic->pb, offset, SEEK_SET); | |
| 1921 | 100 | read_size = 0; | |
| 1922 | 8088 | for (;;) { | |
| 1923 | AVStream *st; | ||
| 1924 | FFStream *sti; | ||
| 1925 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 8181 times.
|
8188 | if (read_size >= duration_max_read_size << (FFMAX(retry - 1, 0))) |
| 1926 | 7 | break; | |
| 1927 | |||
| 1928 | do { | ||
| 1929 | 8181 | ret = ff_read_packet(ic, pkt); | |
| 1930 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8181 times.
|
8181 | } while (ret == AVERROR(EAGAIN)); |
| 1931 |
2/2✓ Branch 0 taken 93 times.
✓ Branch 1 taken 8088 times.
|
8181 | if (ret != 0) |
| 1932 | 93 | break; | |
| 1933 | 8088 | read_size += pkt->size; | |
| 1934 | 8088 | st = ic->streams[pkt->stream_index]; | |
| 1935 | 8088 | sti = ffstream(st); | |
| 1936 |
2/2✓ Branch 0 taken 3989 times.
✓ Branch 1 taken 4099 times.
|
8088 | if (pkt->pts != AV_NOPTS_VALUE && |
| 1937 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3989 times.
|
3989 | (st->start_time != AV_NOPTS_VALUE || |
| 1938 | ✗ | sti->first_dts != AV_NOPTS_VALUE)) { | |
| 1939 |
1/2✓ Branch 0 taken 3989 times.
✗ Branch 1 not taken.
|
3989 | if (pkt->duration == 0) { |
| 1940 | 3989 | compute_frame_duration(ic, &num, &den, st, sti->parser, pkt); | |
| 1941 |
3/4✓ Branch 0 taken 3505 times.
✓ Branch 1 taken 484 times.
✓ Branch 2 taken 3505 times.
✗ Branch 3 not taken.
|
3989 | if (den && num) { |
| 1942 | 3505 | pkt->duration = av_rescale_rnd(1, | |
| 1943 | 3505 | num * (int64_t) st->time_base.den, | |
| 1944 | 3505 | den * (int64_t) st->time_base.num, | |
| 1945 | AV_ROUND_DOWN); | ||
| 1946 | } | ||
| 1947 | } | ||
| 1948 | 3989 | duration = pkt->pts + pkt->duration; | |
| 1949 | 3989 | found_duration = 1; | |
| 1950 |
1/2✓ Branch 0 taken 3989 times.
✗ Branch 1 not taken.
|
3989 | if (st->start_time != AV_NOPTS_VALUE) |
| 1951 | 3989 | duration -= st->start_time; | |
| 1952 | else | ||
| 1953 | ✗ | duration -= sti->first_dts; | |
| 1954 |
2/2✓ Branch 0 taken 3979 times.
✓ Branch 1 taken 10 times.
|
3989 | if (duration > 0) { |
| 1955 |
3/4✓ Branch 0 taken 3838 times.
✓ Branch 1 taken 141 times.
✓ Branch 2 taken 3838 times.
✗ Branch 3 not taken.
|
3979 | if (st->duration == AV_NOPTS_VALUE || sti->info->last_duration<= 0 || |
| 1956 |
3/4✓ Branch 0 taken 3120 times.
✓ Branch 1 taken 718 times.
✓ Branch 2 taken 3120 times.
✗ Branch 3 not taken.
|
3838 | (st->duration < duration && FFABS(duration - sti->info->last_duration) < 60LL*st->time_base.den / st->time_base.num)) |
| 1957 | 3261 | st->duration = duration; | |
| 1958 | 3979 | sti->info->last_duration = duration; | |
| 1959 | } | ||
| 1960 | } | ||
| 1961 | 8088 | av_packet_unref(pkt); | |
| 1962 | } | ||
| 1963 | |||
| 1964 | /* check if all audio/video streams have valid duration */ | ||
| 1965 |
2/2✓ Branch 0 taken 93 times.
✓ Branch 1 taken 7 times.
|
100 | if (!is_end) { |
| 1966 | 93 | is_end = 1; | |
| 1967 |
2/2✓ Branch 0 taken 173 times.
✓ Branch 1 taken 93 times.
|
266 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
| 1968 | 173 | const AVStream *const st = ic->streams[i]; | |
| 1969 |
2/2✓ Branch 0 taken 155 times.
✓ Branch 1 taken 18 times.
|
173 | switch (st->codecpar->codec_type) { |
| 1970 | 155 | case AVMEDIA_TYPE_VIDEO: | |
| 1971 | case AVMEDIA_TYPE_AUDIO: | ||
| 1972 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 131 times.
|
155 | if (st->duration == AV_NOPTS_VALUE) |
| 1973 | 24 | is_end = 0; | |
| 1974 | } | ||
| 1975 | } | ||
| 1976 | } | ||
| 1977 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 2 times.
|
9 | } while (!is_end && |
| 1978 |
3/4✓ Branch 0 taken 9 times.
✓ Branch 1 taken 91 times.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
|
107 | offset && |
| 1979 | ++retry <= duration_max_retry); | ||
| 1980 | |||
| 1981 | 93 | av_opt_set_int(ic, "skip_changes", 0, AV_OPT_SEARCH_CHILDREN); | |
| 1982 | |||
| 1983 | /* warn about audio/video streams which duration could not be estimated */ | ||
| 1984 |
2/2✓ Branch 0 taken 173 times.
✓ Branch 1 taken 93 times.
|
266 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
| 1985 | 173 | const AVStream *const st = ic->streams[i]; | |
| 1986 | 173 | const FFStream *const sti = cffstream(st); | |
| 1987 | |||
| 1988 |
2/2✓ Branch 0 taken 32 times.
✓ Branch 1 taken 141 times.
|
173 | if (st->duration == AV_NOPTS_VALUE) { |
| 1989 |
2/2✓ Branch 0 taken 17 times.
✓ Branch 1 taken 15 times.
|
32 | switch (st->codecpar->codec_type) { |
| 1990 | 17 | case AVMEDIA_TYPE_VIDEO: | |
| 1991 | case AVMEDIA_TYPE_AUDIO: | ||
| 1992 |
3/4✓ Branch 0 taken 10 times.
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 10 times.
|
17 | if (st->start_time != AV_NOPTS_VALUE || sti->first_dts != AV_NOPTS_VALUE) { |
| 1993 | 7 | av_log(ic, AV_LOG_WARNING, "stream %d : no PTS found at end of file, duration not set\n", i); | |
| 1994 | } else | ||
| 1995 | 10 | av_log(ic, AV_LOG_WARNING, "stream %d : no TS found at start of file, duration not set\n", i); | |
| 1996 | } | ||
| 1997 | } | ||
| 1998 | } | ||
| 1999 | 93 | skip_duration_calc: | |
| 2000 | 93 | fill_all_stream_timings(ic); | |
| 2001 | |||
| 2002 | 93 | avio_seek(ic->pb, old_offset, SEEK_SET); | |
| 2003 |
2/2✓ Branch 0 taken 173 times.
✓ Branch 1 taken 93 times.
|
266 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
| 2004 | 173 | AVStream *const st = ic->streams[i]; | |
| 2005 | 173 | FFStream *const sti = ffstream(st); | |
| 2006 | |||
| 2007 | 173 | sti->cur_dts = sti->first_dts; | |
| 2008 | 173 | sti->last_IP_pts = AV_NOPTS_VALUE; | |
| 2009 | 173 | sti->last_dts_for_order_check = AV_NOPTS_VALUE; | |
| 2010 |
2/2✓ Branch 0 taken 2941 times.
✓ Branch 1 taken 173 times.
|
3114 | for (int j = 0; j < MAX_REORDER_DELAY + 1; j++) |
| 2011 | 2941 | sti->pts_buffer[j] = AV_NOPTS_VALUE; | |
| 2012 | } | ||
| 2013 | 93 | } | |
| 2014 | |||
| 2015 | /* 1:1 map to AVDurationEstimationMethod */ | ||
| 2016 | static const char *const duration_name[] = { | ||
| 2017 | [AVFMT_DURATION_FROM_PTS] = "pts", | ||
| 2018 | [AVFMT_DURATION_FROM_STREAM] = "stream", | ||
| 2019 | [AVFMT_DURATION_FROM_BITRATE] = "bit rate", | ||
| 2020 | }; | ||
| 2021 | |||
| 2022 | 8231 | static const char *duration_estimate_name(enum AVDurationEstimationMethod method) | |
| 2023 | { | ||
| 2024 | 8231 | return duration_name[method]; | |
| 2025 | } | ||
| 2026 | |||
| 2027 | 8231 | static void estimate_timings(AVFormatContext *ic, int64_t old_offset) | |
| 2028 | { | ||
| 2029 | int64_t file_size; | ||
| 2030 | |||
| 2031 | /* get the file size, if possible */ | ||
| 2032 |
2/2✓ Branch 0 taken 3224 times.
✓ Branch 1 taken 5007 times.
|
8231 | if (ic->iformat->flags & AVFMT_NOFILE) { |
| 2033 | 3224 | file_size = 0; | |
| 2034 | } else { | ||
| 2035 | 5007 | file_size = avio_size(ic->pb); | |
| 2036 | 5007 | file_size = FFMAX(0, file_size); | |
| 2037 | } | ||
| 2038 | |||
| 2039 |
2/2✓ Branch 0 taken 8203 times.
✓ Branch 1 taken 28 times.
|
8231 | if ((!strcmp(ic->iformat->name, "mpeg") || |
| 2040 |
4/4✓ Branch 0 taken 66 times.
✓ Branch 1 taken 8137 times.
✓ Branch 2 taken 93 times.
✓ Branch 3 taken 1 times.
|
8231 | !strcmp(ic->iformat->name, "mpegts")) && |
| 2041 |
1/2✓ Branch 0 taken 93 times.
✗ Branch 1 not taken.
|
93 | file_size && (ic->pb->seekable & AVIO_SEEKABLE_NORMAL)) { |
| 2042 | /* get accurate estimate from the PTSes */ | ||
| 2043 | 93 | estimate_timings_from_pts(ic, old_offset); | |
| 2044 | 93 | ic->duration_estimation_method = AVFMT_DURATION_FROM_PTS; | |
| 2045 |
2/2✓ Branch 1 taken 5983 times.
✓ Branch 2 taken 2155 times.
|
8138 | } else if (has_duration(ic)) { |
| 2046 | /* at least one component has timings - we use them for all | ||
| 2047 | * the components */ | ||
| 2048 | 5983 | fill_all_stream_timings(ic); | |
| 2049 | /* nut demuxer estimate the duration from PTS */ | ||
| 2050 |
2/2✓ Branch 0 taken 69 times.
✓ Branch 1 taken 5914 times.
|
5983 | if (!strcmp(ic->iformat->name, "nut")) |
| 2051 | 69 | ic->duration_estimation_method = AVFMT_DURATION_FROM_PTS; | |
| 2052 | else | ||
| 2053 | 5914 | ic->duration_estimation_method = AVFMT_DURATION_FROM_STREAM; | |
| 2054 | } else { | ||
| 2055 | /* less precise: use bitrate info */ | ||
| 2056 | 2155 | estimate_timings_from_bit_rate(ic); | |
| 2057 | 2155 | ic->duration_estimation_method = AVFMT_DURATION_FROM_BITRATE; | |
| 2058 | } | ||
| 2059 | 8231 | update_stream_timings(ic); | |
| 2060 | |||
| 2061 |
2/2✓ Branch 0 taken 9134 times.
✓ Branch 1 taken 8231 times.
|
17365 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
| 2062 | 9134 | AVStream *const st = ic->streams[i]; | |
| 2063 |
1/2✓ Branch 0 taken 9134 times.
✗ Branch 1 not taken.
|
9134 | if (st->time_base.den) |
| 2064 | 9134 | av_log(ic, AV_LOG_TRACE, "stream %u: start_time: %s duration: %s\n", i, | |
| 2065 | 9134 | av_ts2timestr(st->start_time, &st->time_base), | |
| 2066 | 9134 | av_ts2timestr(st->duration, &st->time_base)); | |
| 2067 | } | ||
| 2068 | 8231 | av_log(ic, AV_LOG_TRACE, | |
| 2069 | "format: start_time: %s duration: %s (estimate from %s) bitrate=%"PRId64" kb/s\n", | ||
| 2070 | 8231 | av_ts2timestr(ic->start_time, &AV_TIME_BASE_Q), | |
| 2071 | 8231 | av_ts2timestr(ic->duration, &AV_TIME_BASE_Q), | |
| 2072 | duration_estimate_name(ic->duration_estimation_method), | ||
| 2073 | 8231 | (int64_t)ic->bit_rate / 1000); | |
| 2074 | 8231 | } | |
| 2075 | |||
| 2076 | 107538 | static int determinable_frame_size(const AVCodecContext *avctx) | |
| 2077 | { | ||
| 2078 |
2/2✓ Branch 0 taken 408 times.
✓ Branch 1 taken 107130 times.
|
107538 | switch(avctx->codec_id) { |
| 2079 | 408 | case AV_CODEC_ID_MP1: | |
| 2080 | case AV_CODEC_ID_MP2: | ||
| 2081 | case AV_CODEC_ID_MP3: | ||
| 2082 | case AV_CODEC_ID_CODEC2: | ||
| 2083 | 408 | return 1; | |
| 2084 | } | ||
| 2085 | |||
| 2086 | 107130 | return 0; | |
| 2087 | } | ||
| 2088 | |||
| 2089 | 445354 | static int has_codec_parameters(const AVStream *st, const char **errmsg_ptr) | |
| 2090 | { | ||
| 2091 | 445354 | const FFStream *const sti = cffstream(st); | |
| 2092 | 445354 | const AVCodecContext *const avctx = sti->avctx; | |
| 2093 | |||
| 2094 | #define FAIL(errmsg) do { \ | ||
| 2095 | if (errmsg_ptr) \ | ||
| 2096 | *errmsg_ptr = errmsg; \ | ||
| 2097 | return 0; \ | ||
| 2098 | } while (0) | ||
| 2099 | |||
| 2100 |
2/2✓ Branch 0 taken 735 times.
✓ Branch 1 taken 444619 times.
|
445354 | if ( avctx->codec_id == AV_CODEC_ID_NONE |
| 2101 |
2/2✓ Branch 0 taken 513 times.
✓ Branch 1 taken 222 times.
|
735 | && avctx->codec_type != AVMEDIA_TYPE_DATA) |
| 2102 |
2/2✓ Branch 0 taken 15 times.
✓ Branch 1 taken 498 times.
|
513 | FAIL("unknown codec"); |
| 2103 |
4/5✓ Branch 0 taken 129858 times.
✓ Branch 1 taken 313328 times.
✓ Branch 2 taken 665 times.
✓ Branch 3 taken 990 times.
✗ Branch 4 not taken.
|
444841 | switch (avctx->codec_type) { |
| 2104 | 129858 | case AVMEDIA_TYPE_AUDIO: | |
| 2105 |
4/4✓ Branch 0 taken 107538 times.
✓ Branch 1 taken 22320 times.
✓ Branch 3 taken 408 times.
✓ Branch 4 taken 107130 times.
|
129858 | if (!avctx->frame_size && determinable_frame_size(avctx)) |
| 2106 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 406 times.
|
408 | FAIL("unspecified frame size"); |
| 2107 |
1/2✓ Branch 0 taken 129450 times.
✗ Branch 1 not taken.
|
129450 | if (sti->info->found_decoder >= 0 && |
| 2108 |
2/2✓ Branch 0 taken 2854 times.
✓ Branch 1 taken 126596 times.
|
129450 | avctx->sample_fmt == AV_SAMPLE_FMT_NONE) |
| 2109 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2853 times.
|
2854 | FAIL("unspecified sample format"); |
| 2110 |
2/2✓ Branch 0 taken 188 times.
✓ Branch 1 taken 126408 times.
|
126596 | if (!avctx->sample_rate) |
| 2111 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 182 times.
|
188 | FAIL("unspecified sample rate"); |
| 2112 |
2/2✓ Branch 0 taken 22 times.
✓ Branch 1 taken 126386 times.
|
126408 | if (!avctx->ch_layout.nb_channels) |
| 2113 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
|
22 | FAIL("unspecified number of channels"); |
| 2114 |
5/6✓ Branch 0 taken 126386 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 81561 times.
✓ Branch 3 taken 44825 times.
✓ Branch 4 taken 110 times.
✓ Branch 5 taken 81451 times.
|
126386 | if (sti->info->found_decoder >= 0 && !sti->nb_decoded_frames && avctx->codec_id == AV_CODEC_ID_DTS) |
| 2115 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 110 times.
|
110 | FAIL("no decodable DTS frames"); |
| 2116 | 126276 | break; | |
| 2117 | 313328 | case AVMEDIA_TYPE_VIDEO: | |
| 2118 |
2/2✓ Branch 0 taken 13324 times.
✓ Branch 1 taken 300004 times.
|
313328 | if (!avctx->width) |
| 2119 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 13312 times.
|
13324 | FAIL("unspecified size"); |
| 2120 |
4/4✓ Branch 0 taken 299732 times.
✓ Branch 1 taken 272 times.
✓ Branch 2 taken 4590 times.
✓ Branch 3 taken 295142 times.
|
300004 | if (sti->info->found_decoder >= 0 && avctx->pix_fmt == AV_PIX_FMT_NONE) |
| 2121 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 4587 times.
|
4590 | FAIL("unspecified pixel format"); |
| 2122 |
4/4✓ Branch 0 taken 295314 times.
✓ Branch 1 taken 100 times.
✓ Branch 2 taken 86 times.
✓ Branch 3 taken 295228 times.
|
295414 | if (st->codecpar->codec_id == AV_CODEC_ID_RV30 || st->codecpar->codec_id == AV_CODEC_ID_RV40) |
| 2123 |
4/6✓ Branch 0 taken 186 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 186 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 67 times.
✓ Branch 5 taken 119 times.
|
186 | if (!st->sample_aspect_ratio.num && !st->codecpar->sample_aspect_ratio.num && !sti->codec_info_nb_frames) |
| 2124 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 67 times.
|
67 | FAIL("no frame in rv30/40 and no sar"); |
| 2125 | 295347 | break; | |
| 2126 | 665 | case AVMEDIA_TYPE_SUBTITLE: | |
| 2127 |
4/4✓ Branch 0 taken 35 times.
✓ Branch 1 taken 630 times.
✓ Branch 2 taken 21 times.
✓ Branch 3 taken 14 times.
|
665 | if (avctx->codec_id == AV_CODEC_ID_HDMV_PGS_SUBTITLE && !avctx->width) |
| 2128 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
|
21 | FAIL("unspecified size"); |
| 2129 | 644 | break; | |
| 2130 | 990 | case AVMEDIA_TYPE_DATA: | |
| 2131 |
2/2✓ Branch 0 taken 222 times.
✓ Branch 1 taken 768 times.
|
990 | if (avctx->codec_id == AV_CODEC_ID_NONE) return 1; |
| 2132 | } | ||
| 2133 | |||
| 2134 | 423035 | return 1; | |
| 2135 | } | ||
| 2136 | |||
| 2137 | /* returns 1 or 0 if or if not decoded data was returned, or a negative error */ | ||
| 2138 | 206646 | static int try_decode_frame(AVFormatContext *s, AVStream *st, | |
| 2139 | const AVPacket *pkt, AVDictionary **options) | ||
| 2140 | { | ||
| 2141 | 206646 | FFStream *const sti = ffstream(st); | |
| 2142 | 206646 | AVCodecContext *const avctx = sti->avctx; | |
| 2143 | const AVCodec *codec; | ||
| 2144 | 206646 | int got_picture = 1, ret = 0; | |
| 2145 | 206646 | AVFrame *frame = av_frame_alloc(); | |
| 2146 | AVSubtitle subtitle; | ||
| 2147 | 206646 | int do_skip_frame = 0; | |
| 2148 | enum AVDiscard skip_frame; | ||
| 2149 | 206646 | int pkt_to_send = pkt->size > 0; | |
| 2150 | |||
| 2151 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 206646 times.
|
206646 | if (!frame) |
| 2152 | ✗ | return AVERROR(ENOMEM); | |
| 2153 | |||
| 2154 |
2/2✓ Branch 1 taken 1774 times.
✓ Branch 2 taken 204872 times.
|
206646 | if (!avcodec_is_open(avctx) && |
| 2155 |
1/2✓ Branch 0 taken 1774 times.
✗ Branch 1 not taken.
|
1774 | sti->info->found_decoder <= 0 && |
| 2156 |
4/4✓ Branch 0 taken 270 times.
✓ Branch 1 taken 1504 times.
✓ Branch 2 taken 57 times.
✓ Branch 3 taken 213 times.
|
1774 | (st->codecpar->codec_id != -sti->info->found_decoder || !st->codecpar->codec_id)) { |
| 2157 | 1561 | AVDictionary *thread_opt = NULL; | |
| 2158 | |||
| 2159 | 1561 | codec = find_probe_decoder(s, st, st->codecpar->codec_id); | |
| 2160 | |||
| 2161 |
2/2✓ Branch 0 taken 81 times.
✓ Branch 1 taken 1480 times.
|
1561 | if (!codec) { |
| 2162 | 81 | sti->info->found_decoder = -st->codecpar->codec_id; | |
| 2163 | 81 | ret = -1; | |
| 2164 | 83 | goto fail; | |
| 2165 | } | ||
| 2166 | |||
| 2167 | /* Force thread count to 1 since the H.264 decoder will not extract | ||
| 2168 | * SPS and PPS to extradata during multi-threaded decoding. */ | ||
| 2169 |
2/2✓ Branch 0 taken 169 times.
✓ Branch 1 taken 1311 times.
|
1480 | av_dict_set(options ? options : &thread_opt, "threads", "1", 0); |
| 2170 | /* Force lowres to 0. The decoder might reduce the video size by the | ||
| 2171 | * lowres factor, and we don't want that propagated to the stream's | ||
| 2172 | * codecpar */ | ||
| 2173 |
2/2✓ Branch 0 taken 169 times.
✓ Branch 1 taken 1311 times.
|
1480 | av_dict_set(options ? options : &thread_opt, "lowres", "0", 0); |
| 2174 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1480 times.
|
1480 | if (s->codec_whitelist) |
| 2175 | ✗ | av_dict_set(options ? options : &thread_opt, "codec_whitelist", s->codec_whitelist, 0); | |
| 2176 |
2/2✓ Branch 0 taken 169 times.
✓ Branch 1 taken 1311 times.
|
1480 | ret = avcodec_open2(avctx, codec, options ? options : &thread_opt); |
| 2177 |
2/2✓ Branch 0 taken 169 times.
✓ Branch 1 taken 1311 times.
|
1480 | if (!options) |
| 2178 | 169 | av_dict_free(&thread_opt); | |
| 2179 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1478 times.
|
1480 | if (ret < 0) { |
| 2180 | 2 | sti->info->found_decoder = -avctx->codec_id; | |
| 2181 | 2 | goto fail; | |
| 2182 | } | ||
| 2183 | 1478 | sti->info->found_decoder = 1; | |
| 2184 |
2/2✓ Branch 0 taken 7237 times.
✓ Branch 1 taken 197848 times.
|
205085 | } else if (!sti->info->found_decoder) |
| 2185 | 7237 | sti->info->found_decoder = 1; | |
| 2186 | |||
| 2187 |
2/2✓ Branch 0 taken 213 times.
✓ Branch 1 taken 206350 times.
|
206563 | if (sti->info->found_decoder < 0) { |
| 2188 | 213 | ret = -1; | |
| 2189 | 213 | goto fail; | |
| 2190 | } | ||
| 2191 | |||
| 2192 |
2/2✓ Branch 1 taken 112552 times.
✓ Branch 2 taken 93798 times.
|
206350 | if (avpriv_codec_get_cap_skip_frame_fill_param(avctx->codec)) { |
| 2193 | 112552 | do_skip_frame = 1; | |
| 2194 | 112552 | skip_frame = avctx->skip_frame; | |
| 2195 | 112552 | avctx->skip_frame = AVDISCARD_ALL; | |
| 2196 | } | ||
| 2197 | |||
| 2198 |
5/6✓ Branch 0 taken 8615 times.
✓ Branch 1 taken 4916 times.
✓ Branch 2 taken 30 times.
✓ Branch 3 taken 4886 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 206358 times.
|
421353 | while ((pkt_to_send || (!pkt->data && got_picture)) && |
| 2199 |
4/4✓ Branch 0 taken 13531 times.
✓ Branch 1 taken 201472 times.
✓ Branch 2 taken 6006 times.
✓ Branch 3 taken 200352 times.
|
421361 | ret >= 0 && |
| 2200 |
2/2✓ Branch 2 taken 2336 times.
✓ Branch 3 taken 198016 times.
|
406710 | (!has_codec_parameters(st, NULL) || !has_decode_delay_been_guessed(st) || |
| 2201 |
2/2✓ Branch 0 taken 194954 times.
✓ Branch 1 taken 3062 times.
|
198016 | (!sti->codec_info_nb_frames && |
| 2202 |
2/2✓ Branch 0 taken 561 times.
✓ Branch 1 taken 2501 times.
|
3062 | (avctx->codec->capabilities & AV_CODEC_CAP_CHANNEL_CONF)))) { |
| 2203 | 8903 | got_picture = 0; | |
| 2204 |
2/2✓ Branch 0 taken 1012 times.
✓ Branch 1 taken 7891 times.
|
8903 | if (avctx->codec_type == AVMEDIA_TYPE_VIDEO || |
| 2205 |
2/2✓ Branch 0 taken 1005 times.
✓ Branch 1 taken 7 times.
|
1012 | avctx->codec_type == AVMEDIA_TYPE_AUDIO) { |
| 2206 | 8896 | ret = avcodec_send_packet(avctx, pkt); | |
| 2207 |
5/6✓ Branch 0 taken 259 times.
✓ Branch 1 taken 8637 times.
✓ Branch 2 taken 259 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 250 times.
✓ Branch 5 taken 9 times.
|
8896 | if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) |
| 2208 | 250 | break; | |
| 2209 |
2/2✓ Branch 0 taken 8637 times.
✓ Branch 1 taken 9 times.
|
8646 | if (ret >= 0) |
| 2210 | 8637 | pkt_to_send = 0; | |
| 2211 | 8646 | ret = avcodec_receive_frame(avctx, frame); | |
| 2212 |
2/2✓ Branch 0 taken 3397 times.
✓ Branch 1 taken 5249 times.
|
8646 | if (ret >= 0) |
| 2213 | 3397 | got_picture = 1; | |
| 2214 |
4/4✓ Branch 0 taken 3427 times.
✓ Branch 1 taken 5219 times.
✓ Branch 2 taken 30 times.
✓ Branch 3 taken 3397 times.
|
8646 | if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) |
| 2215 | 5249 | ret = 0; | |
| 2216 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
7 | } else if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE) { |
| 2217 | 7 | ret = avcodec_decode_subtitle2(avctx, &subtitle, | |
| 2218 | &got_picture, pkt); | ||
| 2219 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 5 times.
|
7 | if (got_picture) |
| 2220 | 2 | avsubtitle_free(&subtitle); | |
| 2221 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
7 | if (ret >= 0) |
| 2222 | 7 | pkt_to_send = 0; | |
| 2223 | } | ||
| 2224 |
1/2✓ Branch 0 taken 8653 times.
✗ Branch 1 not taken.
|
8653 | if (ret >= 0) { |
| 2225 |
2/2✓ Branch 0 taken 3399 times.
✓ Branch 1 taken 5254 times.
|
8653 | if (got_picture) |
| 2226 | 3399 | sti->nb_decoded_frames++; | |
| 2227 | 8653 | ret = got_picture; | |
| 2228 | } | ||
| 2229 | } | ||
| 2230 | |||
| 2231 | 206100 | fail: | |
| 2232 |
2/2✓ Branch 0 taken 112552 times.
✓ Branch 1 taken 94094 times.
|
206646 | if (do_skip_frame) { |
| 2233 | 112552 | avctx->skip_frame = skip_frame; | |
| 2234 | } | ||
| 2235 | |||
| 2236 | 206646 | av_frame_free(&frame); | |
| 2237 | 206646 | return ret; | |
| 2238 | } | ||
| 2239 | |||
| 2240 | 87 | static int chapter_start_cmp(const void *p1, const void *p2) | |
| 2241 | { | ||
| 2242 | 87 | const AVChapter *const ch1 = *(AVChapter**)p1; | |
| 2243 | 87 | const AVChapter *const ch2 = *(AVChapter**)p2; | |
| 2244 | 87 | int delta = av_compare_ts(ch1->start, ch1->time_base, ch2->start, ch2->time_base); | |
| 2245 |
1/2✓ Branch 0 taken 87 times.
✗ Branch 1 not taken.
|
87 | if (delta) |
| 2246 | 87 | return delta; | |
| 2247 | ✗ | return FFDIFFSIGN(ch1->id, ch2->id); | |
| 2248 | } | ||
| 2249 | |||
| 2250 | 8231 | static int compute_chapters_end(AVFormatContext *s) | |
| 2251 | { | ||
| 2252 | 8231 | int64_t max_time = 0; | |
| 2253 | AVChapter **timetable; | ||
| 2254 | |||
| 2255 |
2/2✓ Branch 0 taken 8175 times.
✓ Branch 1 taken 56 times.
|
8231 | if (!s->nb_chapters) |
| 2256 | 8175 | return 0; | |
| 2257 | |||
| 2258 |
2/4✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 56 times.
✗ Branch 3 not taken.
|
56 | if (s->duration > 0 && s->start_time < INT64_MAX - s->duration) |
| 2259 | 56 | max_time = s->duration + | |
| 2260 |
2/2✓ Branch 0 taken 33 times.
✓ Branch 1 taken 23 times.
|
56 | ((s->start_time == AV_NOPTS_VALUE) ? 0 : s->start_time); |
| 2261 | |||
| 2262 | 56 | timetable = av_memdup(s->chapters, s->nb_chapters * sizeof(*timetable)); | |
| 2263 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
|
56 | if (!timetable) |
| 2264 | ✗ | return AVERROR(ENOMEM); | |
| 2265 | 56 | qsort(timetable, s->nb_chapters, sizeof(*timetable), chapter_start_cmp); | |
| 2266 | |||
| 2267 |
2/2✓ Branch 0 taken 131 times.
✓ Branch 1 taken 56 times.
|
187 | for (unsigned i = 0; i < s->nb_chapters; i++) |
| 2268 |
2/2✓ Branch 0 taken 50 times.
✓ Branch 1 taken 81 times.
|
131 | if (timetable[i]->end == AV_NOPTS_VALUE) { |
| 2269 | 50 | AVChapter *const ch = timetable[i]; | |
| 2270 | 50 | int64_t end = max_time ? av_rescale_q(max_time, AV_TIME_BASE_Q, | |
| 2271 | ch->time_base) | ||
| 2272 |
1/2✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
|
50 | : INT64_MAX; |
| 2273 | |||
| 2274 |
2/2✓ Branch 0 taken 21 times.
✓ Branch 1 taken 29 times.
|
50 | if (i + 1 < s->nb_chapters) { |
| 2275 | 21 | const AVChapter *const ch1 = timetable[i + 1]; | |
| 2276 | 21 | int64_t next_start = av_rescale_q(ch1->start, ch1->time_base, | |
| 2277 | ch->time_base); | ||
| 2278 |
2/4✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
|
21 | if (next_start > ch->start && next_start < end) |
| 2279 | 21 | end = next_start; | |
| 2280 | } | ||
| 2281 |
2/4✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 50 times.
|
50 | ch->end = (end == INT64_MAX || end < ch->start) ? ch->start : end; |
| 2282 | } | ||
| 2283 | 56 | av_free(timetable); | |
| 2284 | 56 | return 0; | |
| 2285 | } | ||
| 2286 | |||
| 2287 | 19824200 | static int get_std_framerate(int i) | |
| 2288 | { | ||
| 2289 |
2/2✓ Branch 0 taken 18007080 times.
✓ Branch 1 taken 1817120 times.
|
19824200 | if (i < 30*12) |
| 2290 | 18007080 | return (i + 1) * 1001; | |
| 2291 | 1817120 | i -= 30*12; | |
| 2292 | |||
| 2293 |
2/2✓ Branch 0 taken 1380550 times.
✓ Branch 1 taken 436570 times.
|
1817120 | if (i < 30) |
| 2294 | 1380550 | return (i + 31) * 1001 * 12; | |
| 2295 | 436570 | i -= 30; | |
| 2296 | |||
| 2297 |
2/2✓ Branch 0 taken 139955 times.
✓ Branch 1 taken 296615 times.
|
436570 | if (i < 3) |
| 2298 | 139955 | return ((const int[]) { 80, 120, 240})[i] * 1001 * 12; | |
| 2299 | |||
| 2300 | 296615 | i -= 3; | |
| 2301 | |||
| 2302 | 296615 | return ((const int[]) { 24, 30, 60, 12, 15, 48 })[i] * 1000 * 12; | |
| 2303 | } | ||
| 2304 | |||
| 2305 | /* Is the time base unreliable? | ||
| 2306 | * This is a heuristic to balance between quick acceptance of the values in | ||
| 2307 | * the headers vs. some extra checks. | ||
| 2308 | * Old DivX and Xvid often have nonsense timebases like 1fps or 2fps. | ||
| 2309 | * MPEG-2 commonly misuses field repeat flags to store different framerates. | ||
| 2310 | * And there are "variable" fps files this needs to detect as well. */ | ||
| 2311 | 218719 | static int tb_unreliable(AVFormatContext *ic, AVStream *st) | |
| 2312 | { | ||
| 2313 | 218719 | FFStream *const sti = ffstream(st); | |
| 2314 | 218719 | const AVCodecDescriptor *desc = sti->codec_desc; | |
| 2315 | 218719 | AVCodecContext *c = sti->avctx; | |
| 2316 |
4/4✓ Branch 0 taken 218173 times.
✓ Branch 1 taken 546 times.
✓ Branch 2 taken 22017 times.
✓ Branch 3 taken 196156 times.
|
218719 | AVRational mul = (AVRational){ desc && (desc->props & AV_CODEC_PROP_FIELDS) ? 2 : 1, 1 }; |
| 2317 | 218719 | AVRational time_base = c->framerate.num ? av_inv_q(av_mul_q(c->framerate, mul)) | |
| 2318 | /* NOHEADER check added to not break existing behavior */ | ||
| 2319 |
2/2✓ Branch 0 taken 19308 times.
✓ Branch 1 taken 199411 times.
|
218719 | : (((ic->ctx_flags & AVFMTCTX_NOHEADER) || |
| 2320 |
2/2✓ Branch 0 taken 48136 times.
✓ Branch 1 taken 31569 times.
|
79705 | st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) ? (AVRational){0, 1} |
| 2321 |
2/2✓ Branch 0 taken 79705 times.
✓ Branch 1 taken 119706 times.
|
199411 | : st->time_base); |
| 2322 | |||
| 2323 |
2/2✓ Branch 0 taken 25875 times.
✓ Branch 1 taken 192844 times.
|
218719 | if (time_base.den >= 101LL * time_base.num || |
| 2324 |
2/2✓ Branch 0 taken 25359 times.
✓ Branch 1 taken 516 times.
|
25875 | time_base.den < 5LL * time_base.num || |
| 2325 | // c->codec_tag == AV_RL32("DIVX") || | ||
| 2326 | // c->codec_tag == AV_RL32("XVID") || | ||
| 2327 |
2/2✓ Branch 0 taken 25148 times.
✓ Branch 1 taken 211 times.
|
25359 | c->codec_tag == AV_RL32("mp4v") || |
| 2328 |
2/2✓ Branch 0 taken 15902 times.
✓ Branch 1 taken 9246 times.
|
25148 | c->codec_id == AV_CODEC_ID_MPEG2VIDEO || |
| 2329 |
2/2✓ Branch 0 taken 15372 times.
✓ Branch 1 taken 530 times.
|
15902 | c->codec_id == AV_CODEC_ID_GIF || |
| 2330 |
2/2✓ Branch 0 taken 14088 times.
✓ Branch 1 taken 1284 times.
|
15372 | c->codec_id == AV_CODEC_ID_HEVC || |
| 2331 |
2/2✓ Branch 0 taken 3823 times.
✓ Branch 1 taken 10265 times.
|
14088 | c->codec_id == AV_CODEC_ID_H264) |
| 2332 | 208454 | return 1; | |
| 2333 | 10265 | return 0; | |
| 2334 | } | ||
| 2335 | |||
| 2336 | 149100 | int ff_rfps_add_frame(AVFormatContext *ic, AVStream *st, int64_t ts) | |
| 2337 | { | ||
| 2338 | 149100 | FFStream *const sti = ffstream(st); | |
| 2339 | 149100 | FFStreamInfo *info = sti->info; | |
| 2340 | 149100 | int64_t last = info->last_dts; | |
| 2341 | |||
| 2342 |
6/6✓ Branch 0 taken 132255 times.
✓ Branch 1 taken 16845 times.
✓ Branch 2 taken 125833 times.
✓ Branch 3 taken 6422 times.
✓ Branch 4 taken 125807 times.
✓ Branch 5 taken 26 times.
|
149100 | if ( ts != AV_NOPTS_VALUE && last != AV_NOPTS_VALUE && ts > last |
| 2343 |
1/2✓ Branch 0 taken 125807 times.
✗ Branch 1 not taken.
|
125807 | && ts - (uint64_t)last < INT64_MAX) { |
| 2344 |
2/2✓ Branch 1 taken 6615 times.
✓ Branch 2 taken 119192 times.
|
125807 | double dts = (is_relative(ts) ? ts - RELATIVE_TS_BASE : ts) * av_q2d(st->time_base); |
| 2345 | 125807 | int64_t duration = ts - last; | |
| 2346 | |||
| 2347 |
2/2✓ Branch 0 taken 4134 times.
✓ Branch 1 taken 121673 times.
|
125807 | if (!info->duration_error) |
| 2348 | 4134 | info->duration_error = av_mallocz(sizeof(info->duration_error[0])*2); | |
| 2349 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 125807 times.
|
125807 | if (!info->duration_error) |
| 2350 | ✗ | return AVERROR(ENOMEM); | |
| 2351 | |||
| 2352 | // if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) | ||
| 2353 | // av_log(NULL, AV_LOG_ERROR, "%f\n", dts); | ||
| 2354 |
2/2✓ Branch 0 taken 50196993 times.
✓ Branch 1 taken 125807 times.
|
50322800 | for (int i = 0; i < MAX_STD_TIMEBASES; i++) { |
| 2355 |
2/2✓ Branch 0 taken 19431752 times.
✓ Branch 1 taken 30765241 times.
|
50196993 | if (info->duration_error[0][1][i] < 1e10) { |
| 2356 | 19431752 | int framerate = get_std_framerate(i); | |
| 2357 | 19431752 | double sdts = dts*framerate/(1001*12); | |
| 2358 |
2/2✓ Branch 0 taken 38863504 times.
✓ Branch 1 taken 19431752 times.
|
58295256 | for (int j = 0; j < 2; j++) { |
| 2359 | 38863504 | int64_t ticks = llrint(sdts+j*0.5); | |
| 2360 | 38863504 | double error = sdts - ticks + j*0.5; | |
| 2361 | 38863504 | info->duration_error[j][0][i] += error; | |
| 2362 | 38863504 | info->duration_error[j][1][i] += error*error; | |
| 2363 | } | ||
| 2364 | } | ||
| 2365 | } | ||
| 2366 |
1/2✓ Branch 0 taken 125807 times.
✗ Branch 1 not taken.
|
125807 | if (info->rfps_duration_sum <= INT64_MAX - duration) { |
| 2367 | 125807 | info->duration_count++; | |
| 2368 | 125807 | info->rfps_duration_sum += duration; | |
| 2369 | } | ||
| 2370 | |||
| 2371 |
2/2✓ Branch 0 taken 11418 times.
✓ Branch 1 taken 114389 times.
|
125807 | if (info->duration_count % 10 == 0) { |
| 2372 | 11418 | int n = info->duration_count; | |
| 2373 |
2/2✓ Branch 0 taken 4555782 times.
✓ Branch 1 taken 11418 times.
|
4567200 | for (int i = 0; i < MAX_STD_TIMEBASES; i++) { |
| 2374 |
2/2✓ Branch 0 taken 1853222 times.
✓ Branch 1 taken 2702560 times.
|
4555782 | if (info->duration_error[0][1][i] < 1e10) { |
| 2375 | 1853222 | double a0 = info->duration_error[0][0][i] / n; | |
| 2376 | 1853222 | double error0 = info->duration_error[0][1][i] / n - a0*a0; | |
| 2377 | 1853222 | double a1 = info->duration_error[1][0][i] / n; | |
| 2378 | 1853222 | double error1 = info->duration_error[1][1][i] / n - a1*a1; | |
| 2379 |
4/4✓ Branch 0 taken 1518155 times.
✓ Branch 1 taken 335067 times.
✓ Branch 2 taken 1417043 times.
✓ Branch 3 taken 101112 times.
|
1853222 | if (error0 > 0.04 && error1 > 0.04) { |
| 2380 | 1417043 | info->duration_error[0][1][i] = 2e10; | |
| 2381 | 1417043 | info->duration_error[1][1][i] = 2e10; | |
| 2382 | } | ||
| 2383 | } | ||
| 2384 | } | ||
| 2385 | } | ||
| 2386 | |||
| 2387 | // ignore the first 4 values, they might have some random jitter | ||
| 2388 |
3/4✓ Branch 0 taken 113504 times.
✓ Branch 1 taken 12303 times.
✓ Branch 4 taken 113504 times.
✗ Branch 5 not taken.
|
125807 | if (info->duration_count > 3 && is_relative(ts) == is_relative(last)) |
| 2389 | 113504 | info->duration_gcd = av_gcd(info->duration_gcd, duration); | |
| 2390 | } | ||
| 2391 |
2/2✓ Branch 0 taken 132255 times.
✓ Branch 1 taken 16845 times.
|
149100 | if (ts != AV_NOPTS_VALUE) |
| 2392 | 132255 | info->last_dts = ts; | |
| 2393 | |||
| 2394 | 149100 | return 0; | |
| 2395 | } | ||
| 2396 | |||
| 2397 | 8839 | void ff_rfps_calculate(AVFormatContext *ic) | |
| 2398 | { | ||
| 2399 |
2/2✓ Branch 0 taken 9957 times.
✓ Branch 1 taken 8839 times.
|
18796 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
| 2400 | 9957 | AVStream *const st = ic->streams[i]; | |
| 2401 | 9957 | FFStream *const sti = ffstream(st); | |
| 2402 | |||
| 2403 |
2/2✓ Branch 0 taken 2893 times.
✓ Branch 1 taken 7064 times.
|
9957 | if (st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO) |
| 2404 | 2893 | continue; | |
| 2405 | // the check for tb_unreliable() is not completely correct, since this is not about handling | ||
| 2406 | // an unreliable/inexact time base, but a time base that is finer than necessary, as e.g. | ||
| 2407 | // ipmovie.c produces. | ||
| 2408 |
8/8✓ Branch 1 taken 5626 times.
✓ Branch 2 taken 1438 times.
✓ Branch 3 taken 3557 times.
✓ Branch 4 taken 2069 times.
✓ Branch 5 taken 354 times.
✓ Branch 6 taken 3203 times.
✓ Branch 7 taken 173 times.
✓ Branch 8 taken 181 times.
|
7064 | if (tb_unreliable(ic, st) && sti->info->duration_count > 15 && sti->info->duration_gcd > FFMAX(1, st->time_base.den/(500LL*st->time_base.num)) && !st->r_frame_rate.num && |
| 2409 |
1/2✓ Branch 0 taken 173 times.
✗ Branch 1 not taken.
|
173 | sti->info->duration_gcd < INT64_MAX / st->time_base.num) |
| 2410 | 173 | av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, st->time_base.den, st->time_base.num * sti->info->duration_gcd, INT_MAX); | |
| 2411 |
4/4✓ Branch 0 taken 4092 times.
✓ Branch 1 taken 2972 times.
✓ Branch 2 taken 421 times.
✓ Branch 3 taken 3671 times.
|
7064 | if (sti->info->duration_count > 1 && !st->r_frame_rate.num |
| 2412 |
2/2✓ Branch 1 taken 312 times.
✓ Branch 2 taken 109 times.
|
421 | && tb_unreliable(ic, st)) { |
| 2413 | 312 | int num = 0; | |
| 2414 | 312 | double best_error = 0.01; | |
| 2415 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 312 times.
|
312 | AVRational ref_rate = st->r_frame_rate.num ? st->r_frame_rate : av_inv_q(st->time_base); |
| 2416 | |||
| 2417 |
2/2✓ Branch 0 taken 124488 times.
✓ Branch 1 taken 312 times.
|
124800 | for (int j = 0; j < MAX_STD_TIMEBASES; j++) { |
| 2418 |
2/2✓ Branch 0 taken 91371 times.
✓ Branch 1 taken 33117 times.
|
124488 | if (sti->info->codec_info_duration && |
| 2419 |
2/2✓ Branch 2 taken 9961 times.
✓ Branch 3 taken 81410 times.
|
91371 | sti->info->codec_info_duration*av_q2d(st->time_base) < (1001*11.5)/get_std_framerate(j)) |
| 2420 | 9961 | continue; | |
| 2421 |
4/4✓ Branch 0 taken 33117 times.
✓ Branch 1 taken 81410 times.
✓ Branch 3 taken 913 times.
✓ Branch 4 taken 32204 times.
|
114527 | if (!sti->info->codec_info_duration && get_std_framerate(j) < 1001*12) |
| 2422 | 913 | continue; | |
| 2423 | |||
| 2424 |
2/2✓ Branch 2 taken 53313 times.
✓ Branch 3 taken 60301 times.
|
113614 | if (av_q2d(st->time_base) * sti->info->rfps_duration_sum / sti->info->duration_count < (1001*12.0 * 0.8)/get_std_framerate(j)) |
| 2425 | 53313 | continue; | |
| 2426 | |||
| 2427 |
2/2✓ Branch 0 taken 120602 times.
✓ Branch 1 taken 60301 times.
|
180903 | for (int k = 0; k < 2; k++) { |
| 2428 | 120602 | int n = sti->info->duration_count; | |
| 2429 | 120602 | double a = sti->info->duration_error[k][0][j] / n; | |
| 2430 | 120602 | double error = sti->info->duration_error[k][1][j]/n - a*a; | |
| 2431 | |||
| 2432 |
4/4✓ Branch 0 taken 4548 times.
✓ Branch 1 taken 116054 times.
✓ Branch 2 taken 4477 times.
✓ Branch 3 taken 71 times.
|
120602 | if (error < best_error && best_error> 0.000000001) { |
| 2433 | 4477 | best_error= error; | |
| 2434 | 4477 | num = get_std_framerate(j); | |
| 2435 | } | ||
| 2436 |
2/2✓ Branch 0 taken 24982 times.
✓ Branch 1 taken 95620 times.
|
120602 | if (error < 0.02) |
| 2437 | 24982 | av_log(ic, AV_LOG_DEBUG, "rfps: %f %f\n", get_std_framerate(j) / 12.0/1001, error); | |
| 2438 | } | ||
| 2439 | } | ||
| 2440 | // do not increase frame rate by more than 1 % in order to match a standard rate. | ||
| 2441 |
5/6✓ Branch 0 taken 306 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 306 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 304 times.
✓ Branch 6 taken 2 times.
|
312 | if (num && (!ref_rate.num || (double)num/(12*1001) < 1.01 * av_q2d(ref_rate))) |
| 2442 | 304 | av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, num, 12*1001, INT_MAX); | |
| 2443 | } | ||
| 2444 |
2/2✓ Branch 0 taken 1166 times.
✓ Branch 1 taken 5898 times.
|
7064 | if ( !st->avg_frame_rate.num |
| 2445 |
4/4✓ Branch 0 taken 329 times.
✓ Branch 1 taken 837 times.
✓ Branch 2 taken 324 times.
✓ Branch 3 taken 5 times.
|
1166 | && st->r_frame_rate.num && sti->info->rfps_duration_sum |
| 2446 |
2/2✓ Branch 0 taken 79 times.
✓ Branch 1 taken 245 times.
|
324 | && sti->info->codec_info_duration <= 0 |
| 2447 |
2/2✓ Branch 0 taken 76 times.
✓ Branch 1 taken 3 times.
|
79 | && sti->info->duration_count > 2 |
| 2448 |
2/2✓ Branch 2 taken 61 times.
✓ Branch 3 taken 15 times.
|
76 | && fabs(1.0 / (av_q2d(st->r_frame_rate) * av_q2d(st->time_base)) - sti->info->rfps_duration_sum / (double)sti->info->duration_count) <= 1.0 |
| 2449 | ) { | ||
| 2450 | 61 | av_log(ic, AV_LOG_DEBUG, "Setting avg frame rate based on r frame rate\n"); | |
| 2451 | 61 | st->avg_frame_rate = st->r_frame_rate; | |
| 2452 | } | ||
| 2453 | |||
| 2454 | 7064 | av_freep(&sti->info->duration_error); | |
| 2455 | 7064 | sti->info->last_dts = AV_NOPTS_VALUE; | |
| 2456 | 7064 | sti->info->duration_count = 0; | |
| 2457 | 7064 | sti->info->rfps_duration_sum = 0; | |
| 2458 | } | ||
| 2459 | 8839 | } | |
| 2460 | |||
| 2461 | 9566 | static int extract_extradata_check(AVStream *st) | |
| 2462 | { | ||
| 2463 | 9566 | const AVBitStreamFilter *const f = av_bsf_get_by_name("extract_extradata"); | |
| 2464 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9566 times.
|
9566 | if (!f) |
| 2465 | ✗ | return 0; | |
| 2466 | |||
| 2467 |
1/2✓ Branch 0 taken 9566 times.
✗ Branch 1 not taken.
|
9566 | if (f->codec_ids) { |
| 2468 | const enum AVCodecID *ids; | ||
| 2469 |
2/2✓ Branch 0 taken 110384 times.
✓ Branch 1 taken 8603 times.
|
118987 | for (ids = f->codec_ids; *ids != AV_CODEC_ID_NONE; ids++) |
| 2470 |
2/2✓ Branch 0 taken 963 times.
✓ Branch 1 taken 109421 times.
|
110384 | if (*ids == st->codecpar->codec_id) |
| 2471 | 963 | return 1; | |
| 2472 | } | ||
| 2473 | |||
| 2474 | 8603 | return 0; | |
| 2475 | } | ||
| 2476 | |||
| 2477 | 7516 | static int extract_extradata_init(AVStream *st) | |
| 2478 | { | ||
| 2479 | 7516 | FFStream *const sti = ffstream(st); | |
| 2480 | const AVBitStreamFilter *f; | ||
| 2481 | int ret; | ||
| 2482 | |||
| 2483 | 7516 | f = av_bsf_get_by_name("extract_extradata"); | |
| 2484 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7516 times.
|
7516 | if (!f) |
| 2485 | ✗ | goto finish; | |
| 2486 | |||
| 2487 | /* check that the codec id is supported */ | ||
| 2488 | 7516 | ret = extract_extradata_check(st); | |
| 2489 |
2/2✓ Branch 0 taken 6663 times.
✓ Branch 1 taken 853 times.
|
7516 | if (!ret) |
| 2490 | 6663 | goto finish; | |
| 2491 | |||
| 2492 | 853 | av_bsf_free(&sti->extract_extradata.bsf); | |
| 2493 | 853 | ret = av_bsf_alloc(f, &sti->extract_extradata.bsf); | |
| 2494 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 853 times.
|
853 | if (ret < 0) |
| 2495 | ✗ | return ret; | |
| 2496 | |||
| 2497 | 853 | ret = avcodec_parameters_copy(sti->extract_extradata.bsf->par_in, | |
| 2498 | 853 | st->codecpar); | |
| 2499 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 853 times.
|
853 | if (ret < 0) |
| 2500 | ✗ | goto fail; | |
| 2501 | |||
| 2502 | 853 | sti->extract_extradata.bsf->time_base_in = st->time_base; | |
| 2503 | |||
| 2504 | 853 | ret = av_bsf_init(sti->extract_extradata.bsf); | |
| 2505 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 853 times.
|
853 | if (ret < 0) |
| 2506 | ✗ | goto fail; | |
| 2507 | |||
| 2508 | 853 | finish: | |
| 2509 | 7516 | sti->extract_extradata.inited = 1; | |
| 2510 | |||
| 2511 | 7516 | return 0; | |
| 2512 | ✗ | fail: | |
| 2513 | ✗ | av_bsf_free(&sti->extract_extradata.bsf); | |
| 2514 | ✗ | return ret; | |
| 2515 | } | ||
| 2516 | |||
| 2517 | 168862 | static int extract_extradata(FFFormatContext *si, AVStream *st, const AVPacket *pkt) | |
| 2518 | { | ||
| 2519 | 168862 | FFStream *const sti = ffstream(st); | |
| 2520 | 168862 | AVPacket *const pkt_ref = si->parse_pkt; | |
| 2521 | int ret; | ||
| 2522 | |||
| 2523 |
2/2✓ Branch 0 taken 7516 times.
✓ Branch 1 taken 161346 times.
|
168862 | if (!sti->extract_extradata.inited) { |
| 2524 | 7516 | ret = extract_extradata_init(st); | |
| 2525 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7516 times.
|
7516 | if (ret < 0) |
| 2526 | ✗ | return ret; | |
| 2527 | } | ||
| 2528 | |||
| 2529 |
3/4✓ Branch 0 taken 168862 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 167612 times.
✓ Branch 3 taken 1250 times.
|
168862 | if (sti->extract_extradata.inited && !sti->extract_extradata.bsf) |
| 2530 | 167612 | return 0; | |
| 2531 | |||
| 2532 | 1250 | ret = av_packet_ref(pkt_ref, pkt); | |
| 2533 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1250 times.
|
1250 | if (ret < 0) |
| 2534 | ✗ | return ret; | |
| 2535 | |||
| 2536 | 1250 | ret = av_bsf_send_packet(sti->extract_extradata.bsf, pkt_ref); | |
| 2537 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1250 times.
|
1250 | if (ret < 0) { |
| 2538 | ✗ | av_packet_unref(pkt_ref); | |
| 2539 | ✗ | return ret; | |
| 2540 | } | ||
| 2541 | |||
| 2542 |
4/4✓ Branch 0 taken 2500 times.
✓ Branch 1 taken 394 times.
✓ Branch 2 taken 1644 times.
✓ Branch 3 taken 856 times.
|
2894 | while (ret >= 0 && !sti->avctx->extradata) { |
| 2543 | 1644 | ret = av_bsf_receive_packet(sti->extract_extradata.bsf, pkt_ref); | |
| 2544 |
2/2✓ Branch 0 taken 394 times.
✓ Branch 1 taken 1250 times.
|
1644 | if (ret < 0) { |
| 2545 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 394 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
394 | if (ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) |
| 2546 | ✗ | return ret; | |
| 2547 | 394 | continue; | |
| 2548 | } | ||
| 2549 | |||
| 2550 |
2/2✓ Branch 0 taken 1141 times.
✓ Branch 1 taken 394 times.
|
1535 | for (int i = 0; i < pkt_ref->side_data_elems; i++) { |
| 2551 | 1141 | AVPacketSideData *const side_data = &pkt_ref->side_data[i]; | |
| 2552 |
2/2✓ Branch 0 taken 856 times.
✓ Branch 1 taken 285 times.
|
1141 | if (side_data->type == AV_PKT_DATA_NEW_EXTRADATA) { |
| 2553 | 856 | sti->avctx->extradata = side_data->data; | |
| 2554 | 856 | sti->avctx->extradata_size = side_data->size; | |
| 2555 | 856 | side_data->data = NULL; | |
| 2556 | 856 | side_data->size = 0; | |
| 2557 | 856 | break; | |
| 2558 | } | ||
| 2559 | } | ||
| 2560 | 1250 | av_packet_unref(pkt_ref); | |
| 2561 | } | ||
| 2562 | |||
| 2563 | 1250 | return 0; | |
| 2564 | } | ||
| 2565 | |||
| 2566 | 9119 | static int parameters_from_context(AVFormatContext *ic, AVCodecParameters *par, | |
| 2567 | const AVCodecContext *avctx) | ||
| 2568 | { | ||
| 2569 | AVCodecParameters *par_tmp; | ||
| 2570 | int ret; | ||
| 2571 | |||
| 2572 | 9119 | par_tmp = avcodec_parameters_alloc(); | |
| 2573 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9119 times.
|
9119 | if (!par_tmp) |
| 2574 | ✗ | return AVERROR(ENOMEM); | |
| 2575 | |||
| 2576 | 9119 | ret = avcodec_parameters_copy(par_tmp, par); | |
| 2577 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9119 times.
|
9119 | if (ret < 0) |
| 2578 | ✗ | goto fail; | |
| 2579 | |||
| 2580 | 9119 | ret = avcodec_parameters_from_context(par, avctx); | |
| 2581 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9119 times.
|
9119 | if (ret < 0) |
| 2582 | ✗ | goto fail; | |
| 2583 | |||
| 2584 | /* Restore some values if they are signaled at the container level | ||
| 2585 | * given they may have been replaced by codec level values as read | ||
| 2586 | * internally by avformat_find_stream_info(). | ||
| 2587 | */ | ||
| 2588 |
2/2✓ Branch 0 taken 229 times.
✓ Branch 1 taken 8890 times.
|
9119 | if (par_tmp->color_range != AVCOL_RANGE_UNSPECIFIED) |
| 2589 | 229 | par->color_range = par_tmp->color_range; | |
| 2590 |
2/2✓ Branch 0 taken 101 times.
✓ Branch 1 taken 9018 times.
|
9119 | if (par_tmp->color_primaries != AVCOL_PRI_UNSPECIFIED) |
| 2591 | 101 | par->color_primaries = par_tmp->color_primaries; | |
| 2592 |
2/2✓ Branch 0 taken 116 times.
✓ Branch 1 taken 9003 times.
|
9119 | if (par_tmp->color_trc != AVCOL_TRC_UNSPECIFIED) |
| 2593 | 116 | par->color_trc = par_tmp->color_trc; | |
| 2594 |
2/2✓ Branch 0 taken 117 times.
✓ Branch 1 taken 9002 times.
|
9119 | if (par_tmp->color_space != AVCOL_SPC_UNSPECIFIED) |
| 2595 | 117 | par->color_space = par_tmp->color_space; | |
| 2596 |
2/2✓ Branch 0 taken 57 times.
✓ Branch 1 taken 9062 times.
|
9119 | if (par_tmp->chroma_location != AVCHROMA_LOC_UNSPECIFIED) |
| 2597 | 57 | par->chroma_location = par_tmp->chroma_location; | |
| 2598 | |||
| 2599 | /* A failed avcodec_open2() zeroes ch_layout through | ||
| 2600 | * ff_codec_close() -> av_opt_free(); do not copy that empty layout | ||
| 2601 | * over a container-signaled one. Other AVOption types used here are | ||
| 2602 | * integers and are not cleared. */ | ||
| 2603 |
4/4✓ Branch 0 taken 2243 times.
✓ Branch 1 taken 6876 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2242 times.
|
9119 | if (par_tmp->ch_layout.nb_channels > 0 && !par->ch_layout.nb_channels) { |
| 2604 | 1 | ret = av_channel_layout_copy(&par->ch_layout, &par_tmp->ch_layout); | |
| 2605 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (ret < 0) |
| 2606 | ✗ | goto fail; | |
| 2607 | } | ||
| 2608 | |||
| 2609 | 9119 | ret = 0; | |
| 2610 | 9119 | fail: | |
| 2611 | 9119 | avcodec_parameters_free(&par_tmp); | |
| 2612 | |||
| 2613 | 9119 | return ret; | |
| 2614 | } | ||
| 2615 | |||
| 2616 | 8231 | int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) | |
| 2617 | { | ||
| 2618 | 8231 | FFFormatContext *const si = ffformatcontext(ic); | |
| 2619 | 8231 | int count = 0, ret = 0, err; | |
| 2620 | int64_t read_size; | ||
| 2621 | 8231 | AVPacket *pkt1 = si->pkt; | |
| 2622 | 8231 | int64_t old_offset = avio_tell(ic->pb); | |
| 2623 | // new streams might appear, no options for those | ||
| 2624 | 8231 | int orig_nb_streams = ic->nb_streams; | |
| 2625 | int flush_codecs; | ||
| 2626 | 8231 | int64_t max_analyze_duration = ic->max_analyze_duration; | |
| 2627 | int64_t max_stream_analyze_duration; | ||
| 2628 | int64_t max_subtitle_analyze_duration; | ||
| 2629 | 8231 | int64_t probesize = ic->probesize; | |
| 2630 | 8231 | int eof_reached = 0; | |
| 2631 | |||
| 2632 | 8231 | flush_codecs = probesize > 0; | |
| 2633 | |||
| 2634 | 8231 | av_opt_set_int(ic, "skip_clear", 1, AV_OPT_SEARCH_CHILDREN); | |
| 2635 | |||
| 2636 | 8231 | max_stream_analyze_duration = max_analyze_duration; | |
| 2637 | 8231 | max_subtitle_analyze_duration = max_analyze_duration; | |
| 2638 |
2/2✓ Branch 0 taken 8229 times.
✓ Branch 1 taken 2 times.
|
8231 | if (!max_analyze_duration) { |
| 2639 | 8229 | max_stream_analyze_duration = | |
| 2640 | 8229 | max_analyze_duration = 5*AV_TIME_BASE; | |
| 2641 | 8229 | max_subtitle_analyze_duration = 30*AV_TIME_BASE; | |
| 2642 |
2/2✓ Branch 0 taken 39 times.
✓ Branch 1 taken 8190 times.
|
8229 | if (!strcmp(ic->iformat->name, "flv")) |
| 2643 | 39 | max_stream_analyze_duration = 90*AV_TIME_BASE; | |
| 2644 |
4/4✓ Branch 0 taken 8201 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 65 times.
✓ Branch 3 taken 8136 times.
|
8229 | if (!strcmp(ic->iformat->name, "mpeg") || !strcmp(ic->iformat->name, "mpegts")) |
| 2645 | 93 | max_stream_analyze_duration = 7*AV_TIME_BASE; | |
| 2646 | } | ||
| 2647 | |||
| 2648 |
2/2✓ Branch 0 taken 5034 times.
✓ Branch 1 taken 3197 times.
|
8231 | if (ic->pb) { |
| 2649 | 5034 | FFIOContext *const ctx = ffiocontext(ic->pb); | |
| 2650 | 5034 | av_log(ic, AV_LOG_DEBUG, "Before avformat_find_stream_info() pos: %"PRId64" bytes read:%"PRId64" seeks:%d nb_streams:%d\n", | |
| 2651 | avio_tell(ic->pb), ctx->bytes_read, ctx->seek_count, ic->nb_streams); | ||
| 2652 | } | ||
| 2653 | |||
| 2654 |
2/2✓ Branch 0 taken 8945 times.
✓ Branch 1 taken 8231 times.
|
17176 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
| 2655 | const AVCodec *codec; | ||
| 2656 | 8945 | AVDictionary *thread_opt = NULL; | |
| 2657 | 8945 | AVStream *const st = ic->streams[i]; | |
| 2658 | 8945 | FFStream *const sti = ffstream(st); | |
| 2659 | 8945 | AVCodecContext *const avctx = sti->avctx; | |
| 2660 | |||
| 2661 | /* check if the caller has overridden the codec id */ | ||
| 2662 | // only for the split stuff | ||
| 2663 |
4/6✓ Branch 0 taken 8945 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8945 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8381 times.
✓ Branch 5 taken 564 times.
|
8945 | if (!sti->parser && !(ic->flags & AVFMT_FLAG_NOPARSE) && sti->request_probe <= 0) { |
| 2664 | 8381 | sti->parser = av_parser_init(st->codecpar->codec_id); | |
| 2665 |
2/2✓ Branch 0 taken 5939 times.
✓ Branch 1 taken 2442 times.
|
8381 | if (sti->parser) { |
| 2666 |
2/2✓ Branch 0 taken 838 times.
✓ Branch 1 taken 5101 times.
|
5939 | if (sti->need_parsing == AVSTREAM_PARSE_HEADERS) { |
| 2667 | 838 | sti->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES; | |
| 2668 |
2/2✓ Branch 0 taken 954 times.
✓ Branch 1 taken 4147 times.
|
5101 | } else if (sti->need_parsing == AVSTREAM_PARSE_FULL_RAW) { |
| 2669 | 954 | sti->parser->flags |= PARSER_FLAG_USE_CODEC_TS; | |
| 2670 | } | ||
| 2671 |
2/2✓ Branch 0 taken 682 times.
✓ Branch 1 taken 1760 times.
|
2442 | } else if (sti->need_parsing) { |
| 2672 | 682 | av_log(ic, AV_LOG_VERBOSE, "parser not found for codec " | |
| 2673 | "%s, packets or times may be invalid.\n", | ||
| 2674 | 682 | avcodec_get_name(st->codecpar->codec_id)); | |
| 2675 | } | ||
| 2676 | } | ||
| 2677 | |||
| 2678 | 8945 | ret = avcodec_parameters_to_context(avctx, st->codecpar); | |
| 2679 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8945 times.
|
8945 | if (ret < 0) |
| 2680 | ✗ | goto find_stream_info_err; | |
| 2681 |
2/2✓ Branch 0 taken 8381 times.
✓ Branch 1 taken 564 times.
|
8945 | if (sti->request_probe <= 0) |
| 2682 | 8381 | sti->avctx_inited = 1; | |
| 2683 | |||
| 2684 | 8945 | codec = find_probe_decoder(ic, st, st->codecpar->codec_id); | |
| 2685 | |||
| 2686 | /* Force thread count to 1 since the H.264 decoder will not extract | ||
| 2687 | * SPS and PPS to extradata during multi-threaded decoding. */ | ||
| 2688 |
2/2✓ Branch 0 taken 8649 times.
✓ Branch 1 taken 296 times.
|
8945 | av_dict_set(options ? &options[i] : &thread_opt, "threads", "1", 0); |
| 2689 | /* Force lowres to 0. The decoder might reduce the video size by the | ||
| 2690 | * lowres factor, and we don't want that propagated to the stream's | ||
| 2691 | * codecpar */ | ||
| 2692 |
2/2✓ Branch 0 taken 8649 times.
✓ Branch 1 taken 296 times.
|
8945 | av_dict_set(options ? &options[i] : &thread_opt, "lowres", "0", 0); |
| 2693 | |||
| 2694 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8945 times.
|
8945 | if (ic->codec_whitelist) |
| 2695 | ✗ | av_dict_set(options ? &options[i] : &thread_opt, "codec_whitelist", ic->codec_whitelist, 0); | |
| 2696 | |||
| 2697 | // Try to just open decoders, in case this is enough to get parameters. | ||
| 2698 | // Also ensure that subtitle_header is properly set. | ||
| 2699 |
4/4✓ Branch 1 taken 8057 times.
✓ Branch 2 taken 888 times.
✓ Branch 3 taken 563 times.
✓ Branch 4 taken 7494 times.
|
8945 | if (!has_codec_parameters(st, NULL) && sti->request_probe <= 0 || |
| 2700 |
2/2✓ Branch 0 taken 90 times.
✓ Branch 1 taken 1361 times.
|
1451 | st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) { |
| 2701 |
3/4✓ Branch 0 taken 7542 times.
✓ Branch 1 taken 42 times.
✓ Branch 2 taken 7542 times.
✗ Branch 3 not taken.
|
7584 | if (codec && !avctx->codec) |
| 2702 |
4/4✓ Branch 0 taken 7252 times.
✓ Branch 1 taken 290 times.
✓ Branch 3 taken 7 times.
✓ Branch 4 taken 7535 times.
|
7542 | if (avcodec_open2(avctx, codec, options ? &options[i] : &thread_opt) < 0) |
| 2703 | 7 | av_log(ic, AV_LOG_WARNING, | |
| 2704 | "Failed to open codec in %s\n", __func__); | ||
| 2705 | } | ||
| 2706 |
2/2✓ Branch 0 taken 296 times.
✓ Branch 1 taken 8649 times.
|
8945 | if (!options) |
| 2707 | 296 | av_dict_free(&thread_opt); | |
| 2708 | } | ||
| 2709 | |||
| 2710 | 8231 | read_size = 0; | |
| 2711 | 201769 | for (;;) { | |
| 2712 | const AVPacket *pkt; | ||
| 2713 | AVStream *st; | ||
| 2714 | FFStream *sti; | ||
| 2715 | AVCodecContext *avctx; | ||
| 2716 | int analyzed_all_streams; | ||
| 2717 | unsigned i; | ||
| 2718 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 210000 times.
|
210000 | if (ff_check_interrupt(&ic->interrupt_callback)) { |
| 2719 | ✗ | ret = AVERROR_EXIT; | |
| 2720 | ✗ | av_log(ic, AV_LOG_DEBUG, "interrupted\n"); | |
| 2721 | ✗ | break; | |
| 2722 | } | ||
| 2723 | |||
| 2724 | /* read_frame_internal() in a previous iteration of this loop may | ||
| 2725 | * have made changes to streams without returning a packet for them. | ||
| 2726 | * Handle that here. */ | ||
| 2727 | 210000 | ret = update_stream_avctx(ic); | |
| 2728 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 210000 times.
|
210000 | if (ret < 0) |
| 2729 | ✗ | goto unref_then_goto_end; | |
| 2730 | |||
| 2731 | /* check if one codec still needs to be handled */ | ||
| 2732 |
2/2✓ Branch 0 taken 219189 times.
✓ Branch 1 taken 115233 times.
|
334422 | for (i = 0; i < ic->nb_streams; i++) { |
| 2733 | 219189 | AVStream *const st = ic->streams[i]; | |
| 2734 | 219189 | FFStream *const sti = ffstream(st); | |
| 2735 | 219189 | int fps_analyze_framecount = 20; | |
| 2736 | int count; | ||
| 2737 | |||
| 2738 |
2/2✓ Branch 1 taken 7955 times.
✓ Branch 2 taken 211234 times.
|
219189 | if (!has_codec_parameters(st, NULL)) |
| 2739 | 7955 | break; | |
| 2740 | /* If the timebase is coarse (like the usual millisecond precision | ||
| 2741 | * of mkv), we need to analyze more frames to reliably arrive at | ||
| 2742 | * the correct fps. */ | ||
| 2743 |
2/2✓ Branch 1 taken 125298 times.
✓ Branch 2 taken 85936 times.
|
211234 | if (av_q2d(st->time_base) > 0.0005) |
| 2744 | 125298 | fps_analyze_framecount *= 2; | |
| 2745 |
2/2✓ Branch 1 taken 8718 times.
✓ Branch 2 taken 202516 times.
|
211234 | if (!tb_unreliable(ic, st)) |
| 2746 | 8718 | fps_analyze_framecount = 0; | |
| 2747 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 211234 times.
|
211234 | if (ic->fps_probe_size >= 0) |
| 2748 | ✗ | fps_analyze_framecount = ic->fps_probe_size; | |
| 2749 |
2/2✓ Branch 0 taken 52 times.
✓ Branch 1 taken 211182 times.
|
211234 | if (st->disposition & AV_DISPOSITION_ATTACHED_PIC) |
| 2750 | 52 | fps_analyze_framecount = 0; | |
| 2751 | /* variable fps and no guess at the real fps */ | ||
| 2752 |
2/2✓ Branch 0 taken 20062 times.
✓ Branch 1 taken 191172 times.
|
211234 | count = (ic->iformat->flags & AVFMT_NOTIMESTAMPS) ? |
| 2753 | 20062 | sti->info->codec_info_duration_fields/2 : | |
| 2754 | 191172 | sti->info->duration_count; | |
| 2755 |
4/4✓ Branch 0 taken 105934 times.
✓ Branch 1 taken 105300 times.
✓ Branch 2 taken 423 times.
✓ Branch 3 taken 105511 times.
|
211234 | if (!(st->r_frame_rate.num && st->avg_frame_rate.num) && |
| 2756 |
2/2✓ Branch 0 taken 45337 times.
✓ Branch 1 taken 60386 times.
|
105723 | st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { |
| 2757 |
2/2✓ Branch 0 taken 26547 times.
✓ Branch 1 taken 18790 times.
|
45337 | if (count < fps_analyze_framecount) |
| 2758 | 26547 | break; | |
| 2759 | } | ||
| 2760 | // Look at the first 3 frames if there is evidence of frame delay | ||
| 2761 | // but the decoder delay is not set. | ||
| 2762 |
6/6✓ Branch 0 taken 3366 times.
✓ Branch 1 taken 181321 times.
✓ Branch 2 taken 173 times.
✓ Branch 3 taken 3193 times.
✓ Branch 4 taken 8 times.
✓ Branch 5 taken 165 times.
|
184687 | if (sti->info->frame_delay_evidence && count < 2 && sti->avctx->has_b_frames == 0) |
| 2763 | 8 | break; | |
| 2764 |
2/2✓ Branch 0 taken 163075 times.
✓ Branch 1 taken 21604 times.
|
184679 | if (!sti->avctx->extradata && |
| 2765 |
6/6✓ Branch 0 taken 161135 times.
✓ Branch 1 taken 1940 times.
✓ Branch 2 taken 110 times.
✓ Branch 3 taken 161025 times.
✓ Branch 4 taken 110 times.
✓ Branch 5 taken 1940 times.
|
165125 | (!sti->extract_extradata.inited || sti->extract_extradata.bsf) && |
| 2766 | 2050 | extract_extradata_check(st)) | |
| 2767 | 110 | break; | |
| 2768 |
2/2✓ Branch 0 taken 63526 times.
✓ Branch 1 taken 121043 times.
|
184569 | if (sti->first_dts == AV_NOPTS_VALUE && |
| 2769 |
6/6✓ Branch 0 taken 9767 times.
✓ Branch 1 taken 53759 times.
✓ Branch 2 taken 9583 times.
✓ Branch 3 taken 184 times.
✓ Branch 4 taken 61005 times.
✓ Branch 5 taken 2337 times.
|
126868 | (!(ic->iformat->flags & AVFMT_NOTIMESTAMPS) || sti->need_parsing == AVSTREAM_PARSE_FULL_RAW) && |
| 2770 |
2/2✓ Branch 0 taken 63290 times.
✓ Branch 1 taken 52 times.
|
63342 | sti->codec_info_nb_frames < ((st->disposition & AV_DISPOSITION_ATTACHED_PIC) ? 1 : ic->max_ts_probe) && |
| 2771 |
2/2✓ Branch 0 taken 44793 times.
✓ Branch 1 taken 16212 times.
|
61005 | (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || |
| 2772 |
2/2✓ Branch 0 taken 858 times.
✓ Branch 1 taken 43935 times.
|
44793 | st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)) |
| 2773 | break; | ||
| 2774 | } | ||
| 2775 | 210000 | analyzed_all_streams = 0; | |
| 2776 |
4/4✓ Branch 0 taken 115233 times.
✓ Branch 1 taken 94767 times.
✓ Branch 2 taken 115193 times.
✓ Branch 3 taken 40 times.
|
210000 | if (i == ic->nb_streams && !si->missing_streams) { |
| 2777 | 115193 | analyzed_all_streams = 1; | |
| 2778 | /* NOTE: If the format has no header, then we need to read some | ||
| 2779 | * packets to get most of the streams, so we cannot stop here. */ | ||
| 2780 |
2/2✓ Branch 0 taken 3646 times.
✓ Branch 1 taken 111547 times.
|
115193 | if (!(ic->ctx_flags & AVFMTCTX_NOHEADER)) { |
| 2781 | /* If we found the info for all the codecs, we can stop. */ | ||
| 2782 | 3646 | ret = count; | |
| 2783 | 3646 | av_log(ic, AV_LOG_DEBUG, "All info found\n"); | |
| 2784 | 3646 | flush_codecs = 0; | |
| 2785 | 3646 | break; | |
| 2786 | } | ||
| 2787 | } | ||
| 2788 | /* We did not get all the codec info, but we read too much data. */ | ||
| 2789 |
2/2✓ Branch 0 taken 3093 times.
✓ Branch 1 taken 203261 times.
|
206354 | if (read_size >= probesize) { |
| 2790 | 3093 | ret = count; | |
| 2791 | 3093 | av_log(ic, AV_LOG_DEBUG, | |
| 2792 | "Probe buffer size limit of %"PRId64" bytes reached\n", probesize); | ||
| 2793 |
2/2✓ Branch 0 taken 3107 times.
✓ Branch 1 taken 3093 times.
|
6200 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
| 2794 | 3107 | AVStream *const st = ic->streams[i]; | |
| 2795 | 3107 | FFStream *const sti = ffstream(st); | |
| 2796 |
2/2✓ Branch 0 taken 57 times.
✓ Branch 1 taken 3050 times.
|
3107 | if (!st->r_frame_rate.num && |
| 2797 |
2/2✓ Branch 0 taken 17 times.
✓ Branch 1 taken 40 times.
|
57 | sti->info->duration_count <= 1 && |
| 2798 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 16 times.
|
17 | st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && |
| 2799 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | strcmp(ic->iformat->name, "image2")) |
| 2800 | 1 | av_log(ic, AV_LOG_WARNING, | |
| 2801 | "Stream #%d: not enough frames to estimate rate; " | ||
| 2802 | "consider increasing probesize\n", i); | ||
| 2803 | } | ||
| 2804 | 3093 | break; | |
| 2805 | } | ||
| 2806 | |||
| 2807 | /* NOTE: A new stream can be added there if no header in file | ||
| 2808 | * (AVFMTCTX_NOHEADER). */ | ||
| 2809 | 203261 | ret = read_frame_internal(ic, pkt1); | |
| 2810 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 203261 times.
|
203261 | if (ret == AVERROR(EAGAIN)) |
| 2811 | ✗ | continue; | |
| 2812 | |||
| 2813 |
2/2✓ Branch 0 taken 1396 times.
✓ Branch 1 taken 201865 times.
|
203261 | if (ret < 0) { |
| 2814 | /* EOF or error*/ | ||
| 2815 | 1396 | eof_reached = 1; | |
| 2816 | 1396 | break; | |
| 2817 | } | ||
| 2818 | |||
| 2819 |
1/2✓ Branch 0 taken 201865 times.
✗ Branch 1 not taken.
|
201865 | if (!(ic->flags & AVFMT_FLAG_NOBUFFER)) { |
| 2820 | 201865 | ret = ff_packet_list_put(&si->packet_buffer, | |
| 2821 | pkt1, NULL, 0); | ||
| 2822 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 201865 times.
|
201865 | if (ret < 0) |
| 2823 | ✗ | goto unref_then_goto_end; | |
| 2824 | |||
| 2825 | 201865 | pkt = &si->packet_buffer.tail->pkt; | |
| 2826 | } else { | ||
| 2827 | ✗ | pkt = pkt1; | |
| 2828 | } | ||
| 2829 | |||
| 2830 | 201865 | st = ic->streams[pkt->stream_index]; | |
| 2831 | 201865 | sti = ffstream(st); | |
| 2832 |
2/2✓ Branch 0 taken 201800 times.
✓ Branch 1 taken 65 times.
|
201865 | if (!(st->disposition & AV_DISPOSITION_ATTACHED_PIC)) |
| 2833 | 201800 | read_size += pkt->size; | |
| 2834 | |||
| 2835 | 201865 | avctx = sti->avctx; | |
| 2836 |
2/2✓ Branch 0 taken 738 times.
✓ Branch 1 taken 201127 times.
|
201865 | if (!sti->avctx_inited) { |
| 2837 | 738 | ret = avcodec_parameters_to_context(avctx, st->codecpar); | |
| 2838 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 738 times.
|
738 | if (ret < 0) |
| 2839 | ✗ | goto unref_then_goto_end; | |
| 2840 | 738 | sti->avctx_inited = 1; | |
| 2841 | } | ||
| 2842 | |||
| 2843 |
4/4✓ Branch 0 taken 184643 times.
✓ Branch 1 taken 17222 times.
✓ Branch 2 taken 171444 times.
✓ Branch 3 taken 13199 times.
|
201865 | if (pkt->dts != AV_NOPTS_VALUE && sti->codec_info_nb_frames > 1) { |
| 2844 | /* check for non-increasing dts */ | ||
| 2845 |
2/2✓ Branch 0 taken 166270 times.
✓ Branch 1 taken 5174 times.
|
171444 | if (sti->info->fps_last_dts != AV_NOPTS_VALUE && |
| 2846 |
2/2✓ Branch 0 taken 23 times.
✓ Branch 1 taken 166247 times.
|
166270 | sti->info->fps_last_dts >= pkt->dts) { |
| 2847 | 23 | av_log(ic, AV_LOG_DEBUG, | |
| 2848 | "Non-increasing DTS in stream %d: packet %d with DTS " | ||
| 2849 | "%"PRId64", packet %d with DTS %"PRId64"\n", | ||
| 2850 | 23 | st->index, sti->info->fps_last_dts_idx, | |
| 2851 | 23 | sti->info->fps_last_dts, sti->codec_info_nb_frames, | |
| 2852 | 23 | pkt->dts); | |
| 2853 | 23 | sti->info->fps_first_dts = | |
| 2854 | 23 | sti->info->fps_last_dts = AV_NOPTS_VALUE; | |
| 2855 | } | ||
| 2856 | /* Check for a discontinuity in dts. If the difference in dts | ||
| 2857 | * is more than 1000 times the average packet duration in the | ||
| 2858 | * sequence, we treat it as a discontinuity. */ | ||
| 2859 |
2/2✓ Branch 0 taken 166247 times.
✓ Branch 1 taken 5197 times.
|
171444 | if (sti->info->fps_last_dts != AV_NOPTS_VALUE && |
| 2860 |
2/2✓ Branch 0 taken 161108 times.
✓ Branch 1 taken 5139 times.
|
166247 | sti->info->fps_last_dts_idx > sti->info->fps_first_dts_idx && |
| 2861 | 161108 | (pkt->dts - (uint64_t)sti->info->fps_last_dts) / 1000 > | |
| 2862 | 161108 | (sti->info->fps_last_dts - (uint64_t)sti->info->fps_first_dts) / | |
| 2863 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 161108 times.
|
161108 | (sti->info->fps_last_dts_idx - sti->info->fps_first_dts_idx)) { |
| 2864 | ✗ | av_log(ic, AV_LOG_WARNING, | |
| 2865 | "DTS discontinuity in stream %d: packet %d with DTS " | ||
| 2866 | "%"PRId64", packet %d with DTS %"PRId64"\n", | ||
| 2867 | ✗ | st->index, sti->info->fps_last_dts_idx, | |
| 2868 | ✗ | sti->info->fps_last_dts, sti->codec_info_nb_frames, | |
| 2869 | ✗ | pkt->dts); | |
| 2870 | ✗ | sti->info->fps_first_dts = | |
| 2871 | ✗ | sti->info->fps_last_dts = AV_NOPTS_VALUE; | |
| 2872 | } | ||
| 2873 | |||
| 2874 | /* update stored dts values */ | ||
| 2875 |
2/2✓ Branch 0 taken 5197 times.
✓ Branch 1 taken 166247 times.
|
171444 | if (sti->info->fps_first_dts == AV_NOPTS_VALUE) { |
| 2876 | 5197 | sti->info->fps_first_dts = pkt->dts; | |
| 2877 | 5197 | sti->info->fps_first_dts_idx = sti->codec_info_nb_frames; | |
| 2878 | } | ||
| 2879 | 171444 | sti->info->fps_last_dts = pkt->dts; | |
| 2880 | 171444 | sti->info->fps_last_dts_idx = sti->codec_info_nb_frames; | |
| 2881 | } | ||
| 2882 |
2/2✓ Branch 0 taken 187360 times.
✓ Branch 1 taken 14505 times.
|
201865 | if (sti->codec_info_nb_frames > 1) { |
| 2883 | 187360 | int64_t t = 0; | |
| 2884 | int64_t limit; | ||
| 2885 | |||
| 2886 |
1/2✓ Branch 0 taken 187360 times.
✗ Branch 1 not taken.
|
187360 | if (st->time_base.den > 0) |
| 2887 | 187360 | t = av_rescale_q(sti->info->codec_info_duration, st->time_base, AV_TIME_BASE_Q); | |
| 2888 |
2/2✓ Branch 0 taken 117315 times.
✓ Branch 1 taken 70045 times.
|
187360 | if (st->avg_frame_rate.num > 0) |
| 2889 |
2/2✓ Branch 1 taken 116788 times.
✓ Branch 2 taken 527 times.
|
117315 | t = FFMAX(t, av_rescale_q(sti->codec_info_nb_frames, av_inv_q(st->avg_frame_rate), AV_TIME_BASE_Q)); |
| 2890 | |||
| 2891 |
2/2✓ Branch 0 taken 4640 times.
✓ Branch 1 taken 182720 times.
|
187360 | if ( t == 0 |
| 2892 |
2/2✓ Branch 0 taken 564 times.
✓ Branch 1 taken 4076 times.
|
4640 | && sti->codec_info_nb_frames > 30 |
| 2893 |
2/2✓ Branch 0 taken 497 times.
✓ Branch 1 taken 67 times.
|
564 | && sti->info->fps_first_dts != AV_NOPTS_VALUE |
| 2894 |
1/2✓ Branch 0 taken 497 times.
✗ Branch 1 not taken.
|
497 | && sti->info->fps_last_dts != AV_NOPTS_VALUE) { |
| 2895 | 497 | int64_t dur = av_sat_sub64(sti->info->fps_last_dts, sti->info->fps_first_dts); | |
| 2896 |
1/2✓ Branch 0 taken 497 times.
✗ Branch 1 not taken.
|
497 | t = FFMAX(t, av_rescale_q(dur, st->time_base, AV_TIME_BASE_Q)); |
| 2897 | } | ||
| 2898 | |||
| 2899 |
2/2✓ Branch 0 taken 105060 times.
✓ Branch 1 taken 82300 times.
|
187360 | if (analyzed_all_streams) limit = max_analyze_duration; |
| 2900 |
2/2✓ Branch 0 taken 91 times.
✓ Branch 1 taken 82209 times.
|
82300 | else if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE) limit = max_subtitle_analyze_duration; |
| 2901 | 82209 | else limit = max_stream_analyze_duration; | |
| 2902 | |||
| 2903 |
2/2✓ Branch 0 taken 96 times.
✓ Branch 1 taken 187264 times.
|
187360 | if (t >= limit) { |
| 2904 | 96 | av_log(ic, AV_LOG_VERBOSE, "max_analyze_duration %"PRId64" reached at %"PRId64" microseconds st:%d\n", | |
| 2905 | limit, | ||
| 2906 | 96 | t, pkt->stream_index); | |
| 2907 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 96 times.
|
96 | if (ic->flags & AVFMT_FLAG_NOBUFFER) |
| 2908 | ✗ | av_packet_unref(pkt1); | |
| 2909 | 96 | break; | |
| 2910 | } | ||
| 2911 |
3/4✓ Branch 0 taken 183237 times.
✓ Branch 1 taken 4027 times.
✓ Branch 2 taken 183237 times.
✗ Branch 3 not taken.
|
187264 | if (pkt->duration > 0 && pkt->duration < INT64_MAX - sti->info->codec_info_duration) { |
| 2912 |
4/4✓ Branch 0 taken 183197 times.
✓ Branch 1 taken 40 times.
✓ Branch 2 taken 14926 times.
✓ Branch 3 taken 168271 times.
|
183237 | const int fields = sti->codec_desc && (sti->codec_desc->props & AV_CODEC_PROP_FIELDS); |
| 2913 |
1/8✗ Branch 0 not taken.
✓ Branch 1 taken 183237 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
183237 | if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE && pkt->pts != AV_NOPTS_VALUE && st->start_time != AV_NOPTS_VALUE && pkt->pts >= st->start_time |
| 2914 | ✗ | && (uint64_t)pkt->pts - st->start_time < INT64_MAX | |
| 2915 | ) { | ||
| 2916 | ✗ | sti->info->codec_info_duration = FFMIN(pkt->pts - st->start_time, sti->info->codec_info_duration + pkt->duration); | |
| 2917 | } else | ||
| 2918 | 183237 | sti->info->codec_info_duration += pkt->duration; | |
| 2919 |
4/4✓ Branch 0 taken 39773 times.
✓ Branch 1 taken 96127 times.
✓ Branch 2 taken 14284 times.
✓ Branch 3 taken 25489 times.
|
319137 | sti->info->codec_info_duration_fields += sti->parser && sti->need_parsing && fields |
| 2920 |
2/2✓ Branch 0 taken 135900 times.
✓ Branch 1 taken 47337 times.
|
319137 | ? sti->parser->repeat_pict + 1 : 2; |
| 2921 | } | ||
| 2922 | } | ||
| 2923 |
2/2✓ Branch 0 taken 137453 times.
✓ Branch 1 taken 64316 times.
|
201769 | if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { |
| 2924 | #if FF_API_R_FRAME_RATE | ||
| 2925 | 137453 | ff_rfps_add_frame(ic, st, pkt->dts); | |
| 2926 | #endif | ||
| 2927 |
6/6✓ Branch 0 taken 5064 times.
✓ Branch 1 taken 132389 times.
✓ Branch 2 taken 4762 times.
✓ Branch 3 taken 302 times.
✓ Branch 4 taken 2736 times.
✓ Branch 5 taken 2026 times.
|
137453 | if (pkt->dts != pkt->pts && pkt->dts != AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE) |
| 2928 | 2736 | sti->info->frame_delay_evidence = 1; | |
| 2929 | } | ||
| 2930 |
2/2✓ Branch 0 taken 168719 times.
✓ Branch 1 taken 33050 times.
|
201769 | if (!sti->avctx->extradata) { |
| 2931 | 168719 | ret = extract_extradata(si, st, pkt); | |
| 2932 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 168719 times.
|
168719 | if (ret < 0) |
| 2933 | ✗ | goto unref_then_goto_end; | |
| 2934 | } | ||
| 2935 | |||
| 2936 | /* If still no information, we try to open the codec and to | ||
| 2937 | * decompress the frame. We try to avoid that in most cases as | ||
| 2938 | * it takes longer and uses more memory. For MPEG-4, we need to | ||
| 2939 | * decompress for QuickTime. | ||
| 2940 | * | ||
| 2941 | * If AV_CODEC_CAP_CHANNEL_CONF is set this will force decoding of at | ||
| 2942 | * least one frame of codec data, this makes sure the codec initializes | ||
| 2943 | * the channel configuration and does not only trust the values from | ||
| 2944 | * the container. */ | ||
| 2945 |
2/2✓ Branch 0 taken 184023 times.
✓ Branch 1 taken 17746 times.
|
385792 | try_decode_frame(ic, st, pkt, |
| 2946 |
2/2✓ Branch 0 taken 83114 times.
✓ Branch 1 taken 100909 times.
|
184023 | (options && i < orig_nb_streams) ? &options[i] : NULL); |
| 2947 | |||
| 2948 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 201769 times.
|
201769 | if (ic->flags & AVFMT_FLAG_NOBUFFER) |
| 2949 | ✗ | av_packet_unref(pkt1); | |
| 2950 | |||
| 2951 | 201769 | sti->codec_info_nb_frames++; | |
| 2952 | 201769 | count++; | |
| 2953 | } | ||
| 2954 | |||
| 2955 |
2/2✓ Branch 0 taken 1396 times.
✓ Branch 1 taken 6835 times.
|
8231 | if (eof_reached) { |
| 2956 |
2/2✓ Branch 0 taken 1728 times.
✓ Branch 1 taken 1396 times.
|
3124 | for (unsigned stream_index = 0; stream_index < ic->nb_streams; stream_index++) { |
| 2957 | 1728 | AVStream *const st = ic->streams[stream_index]; | |
| 2958 | 1728 | AVCodecContext *const avctx = ffstream(st)->avctx; | |
| 2959 |
2/2✓ Branch 1 taken 40 times.
✓ Branch 2 taken 1688 times.
|
1728 | if (!has_codec_parameters(st, NULL)) { |
| 2960 | 40 | const AVCodec *codec = find_probe_decoder(ic, st, st->codecpar->codec_id); | |
| 2961 |
4/4✓ Branch 0 taken 25 times.
✓ Branch 1 taken 15 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 14 times.
|
40 | if (codec && !avctx->codec) { |
| 2962 | 11 | AVDictionary *opts = NULL; | |
| 2963 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
|
11 | if (ic->codec_whitelist) |
| 2964 | ✗ | av_dict_set(&opts, "codec_whitelist", ic->codec_whitelist, 0); | |
| 2965 |
5/6✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 6 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 10 times.
|
11 | if (avcodec_open2(avctx, codec, (options && stream_index < orig_nb_streams) ? &options[stream_index] : &opts) < 0) |
| 2966 | 1 | av_log(ic, AV_LOG_WARNING, | |
| 2967 | "Failed to open codec in %s\n", __func__); | ||
| 2968 | 11 | av_dict_free(&opts); | |
| 2969 | } | ||
| 2970 | } | ||
| 2971 | |||
| 2972 | // EOF already reached while reading the stream above. | ||
| 2973 | // So continue with reoordering DTS with whatever delay we have. | ||
| 2974 |
4/4✓ Branch 0 taken 1705 times.
✓ Branch 1 taken 23 times.
✓ Branch 3 taken 21 times.
✓ Branch 4 taken 1684 times.
|
1728 | if (si->packet_buffer.head && !has_decode_delay_been_guessed(st)) { |
| 2975 | 21 | update_dts_from_pts(ic, stream_index, si->packet_buffer.head); | |
| 2976 | } | ||
| 2977 | } | ||
| 2978 | } | ||
| 2979 | |||
| 2980 |
2/2✓ Branch 0 taken 4585 times.
✓ Branch 1 taken 3646 times.
|
8231 | if (flush_codecs) { |
| 2981 | 4585 | AVPacket *empty_pkt = si->pkt; | |
| 2982 | 4585 | int err = 0; | |
| 2983 | 4585 | av_packet_unref(empty_pkt); | |
| 2984 | |||
| 2985 |
2/2✓ Branch 0 taken 4970 times.
✓ Branch 1 taken 4585 times.
|
9555 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
| 2986 | 4970 | AVStream *const st = ic->streams[i]; | |
| 2987 | 4970 | FFStream *const sti = ffstream(st); | |
| 2988 | |||
| 2989 | /* flush the decoders */ | ||
| 2990 |
2/2✓ Branch 0 taken 4877 times.
✓ Branch 1 taken 93 times.
|
4970 | if (sti->info->found_decoder == 1) { |
| 2991 |
2/2✓ Branch 0 taken 4557 times.
✓ Branch 1 taken 320 times.
|
9434 | err = try_decode_frame(ic, st, empty_pkt, |
| 2992 |
2/2✓ Branch 0 taken 4541 times.
✓ Branch 1 taken 16 times.
|
4557 | (options && i < orig_nb_streams) |
| 2993 | 4541 | ? &options[i] : NULL); | |
| 2994 | |||
| 2995 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4877 times.
|
4877 | if (err < 0) { |
| 2996 | ✗ | av_log(ic, AV_LOG_INFO, | |
| 2997 | "decoding for stream %d failed\n", st->index); | ||
| 2998 | } | ||
| 2999 | } | ||
| 3000 | } | ||
| 3001 | } | ||
| 3002 | |||
| 3003 | 8231 | ff_rfps_calculate(ic); | |
| 3004 | |||
| 3005 |
2/2✓ Branch 0 taken 9134 times.
✓ Branch 1 taken 8231 times.
|
17365 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
| 3006 | 9134 | AVStream *const st = ic->streams[i]; | |
| 3007 | 9134 | FFStream *const sti = ffstream(st); | |
| 3008 | 9134 | AVCodecContext *const avctx = sti->avctx; | |
| 3009 | |||
| 3010 |
2/2✓ Branch 0 taken 6636 times.
✓ Branch 1 taken 2498 times.
|
9134 | if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) { |
| 3011 |
6/6✓ Branch 0 taken 649 times.
✓ Branch 1 taken 5987 times.
✓ Branch 2 taken 600 times.
✓ Branch 3 taken 49 times.
✓ Branch 4 taken 584 times.
✓ Branch 5 taken 16 times.
|
6636 | if (avctx->codec_id == AV_CODEC_ID_RAWVIDEO && !avctx->codec_tag && !avctx->bits_per_coded_sample) { |
| 3012 | 584 | uint32_t tag= avcodec_pix_fmt_to_codec_tag(avctx->pix_fmt); | |
| 3013 |
2/2✓ Branch 1 taken 577 times.
✓ Branch 2 taken 7 times.
|
584 | if (avpriv_pix_fmt_find(PIX_FMT_LIST_RAW, tag) == avctx->pix_fmt) |
| 3014 | 577 | avctx->codec_tag= tag; | |
| 3015 | } | ||
| 3016 | |||
| 3017 | /* estimate average framerate if not set by demuxer */ | ||
| 3018 |
2/2✓ Branch 0 taken 4202 times.
✓ Branch 1 taken 2434 times.
|
6636 | if (sti->info->codec_info_duration_fields && |
| 3019 |
2/2✓ Branch 0 taken 313 times.
✓ Branch 1 taken 3889 times.
|
4202 | !st->avg_frame_rate.num && |
| 3020 |
1/2✓ Branch 0 taken 313 times.
✗ Branch 1 not taken.
|
313 | sti->info->codec_info_duration) { |
| 3021 | 313 | int best_fps = 0; | |
| 3022 | 313 | double best_error = 0.01; | |
| 3023 | 313 | AVRational codec_frame_rate = avctx->framerate; | |
| 3024 | |||
| 3025 |
1/2✓ Branch 0 taken 313 times.
✗ Branch 1 not taken.
|
313 | if (sti->info->codec_info_duration >= INT64_MAX / st->time_base.num / 2|| |
| 3026 |
1/2✓ Branch 0 taken 313 times.
✗ Branch 1 not taken.
|
313 | sti->info->codec_info_duration_fields >= INT64_MAX / st->time_base.den || |
| 3027 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 313 times.
|
313 | sti->info->codec_info_duration < 0) |
| 3028 | ✗ | continue; | |
| 3029 | 313 | av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den, | |
| 3030 | 313 | sti->info->codec_info_duration_fields * (int64_t) st->time_base.den, | |
| 3031 | 313 | sti->info->codec_info_duration * 2 * (int64_t) st->time_base.num, 60000); | |
| 3032 | |||
| 3033 | /* Round guessed framerate to a "standard" framerate if it's | ||
| 3034 | * within 1% of the original estimate. */ | ||
| 3035 |
2/2✓ Branch 0 taken 124887 times.
✓ Branch 1 taken 313 times.
|
125200 | for (int j = 0; j < MAX_STD_TIMEBASES; j++) { |
| 3036 | 124887 | AVRational std_fps = { get_std_framerate(j), 12 * 1001 }; | |
| 3037 | 124887 | double error = fabs(av_q2d(st->avg_frame_rate) / | |
| 3038 | 124887 | av_q2d(std_fps) - 1); | |
| 3039 | |||
| 3040 |
2/2✓ Branch 0 taken 868 times.
✓ Branch 1 taken 124019 times.
|
124887 | if (error < best_error) { |
| 3041 | 868 | best_error = error; | |
| 3042 | 868 | best_fps = std_fps.num; | |
| 3043 | } | ||
| 3044 | |||
| 3045 |
2/2✓ Branch 1 taken 18753 times.
✓ Branch 2 taken 106134 times.
|
124887 | if ((ffifmt(ic->iformat)->flags_internal & FF_INFMT_FLAG_PREFER_CODEC_FRAMERATE) && |
| 3046 |
2/4✓ Branch 0 taken 18753 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18753 times.
✗ Branch 3 not taken.
|
18753 | codec_frame_rate.num > 0 && codec_frame_rate.den > 0) { |
| 3047 | 18753 | error = fabs(av_q2d(codec_frame_rate) / | |
| 3048 | 18753 | av_q2d(std_fps) - 1); | |
| 3049 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 18743 times.
|
18753 | if (error < best_error) { |
| 3050 | 10 | best_error = error; | |
| 3051 | 10 | best_fps = std_fps.num; | |
| 3052 | } | ||
| 3053 | } | ||
| 3054 | } | ||
| 3055 |
2/2✓ Branch 0 taken 310 times.
✓ Branch 1 taken 3 times.
|
313 | if (best_fps) |
| 3056 | 310 | av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den, | |
| 3057 | best_fps, 12 * 1001, INT_MAX); | ||
| 3058 | } | ||
| 3059 |
2/2✓ Branch 0 taken 1937 times.
✓ Branch 1 taken 4699 times.
|
6636 | if (!st->r_frame_rate.num) { |
| 3060 | 1937 | const AVCodecDescriptor *desc = sti->codec_desc; | |
| 3061 |
3/4✓ Branch 0 taken 1937 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 254 times.
✓ Branch 3 taken 1683 times.
|
1937 | AVRational mul = (AVRational){ desc && (desc->props & AV_CODEC_PROP_FIELDS) ? 2 : 1, 1 }; |
| 3062 | 1937 | AVRational fr = av_mul_q(avctx->framerate, mul); | |
| 3063 | |||
| 3064 |
5/6✓ Branch 0 taken 198 times.
✓ Branch 1 taken 1739 times.
✓ Branch 2 taken 198 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 184 times.
✓ Branch 7 taken 14 times.
|
1937 | if (fr.num && fr.den && av_cmp_q(st->time_base, av_inv_q(fr)) <= 0) { |
| 3065 | 184 | st->r_frame_rate = fr; | |
| 3066 | } else { | ||
| 3067 | 1753 | st->r_frame_rate.num = st->time_base.den; | |
| 3068 | 1753 | st->r_frame_rate.den = st->time_base.num; | |
| 3069 | } | ||
| 3070 | } | ||
| 3071 | 6636 | st->codecpar->framerate = avctx->framerate; | |
| 3072 |
3/4✓ Branch 0 taken 116 times.
✓ Branch 1 taken 6520 times.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
|
6636 | if (sti->display_aspect_ratio.num && sti->display_aspect_ratio.den) { |
| 3073 | 116 | AVRational hw_ratio = { avctx->height, avctx->width }; | |
| 3074 | 116 | st->sample_aspect_ratio = av_mul_q(sti->display_aspect_ratio, | |
| 3075 | hw_ratio); | ||
| 3076 | } | ||
| 3077 |
2/2✓ Branch 0 taken 2302 times.
✓ Branch 1 taken 196 times.
|
2498 | } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) { |
| 3078 |
2/2✓ Branch 0 taken 854 times.
✓ Branch 1 taken 1448 times.
|
2302 | if (!avctx->bits_per_coded_sample) |
| 3079 | 854 | avctx->bits_per_coded_sample = | |
| 3080 | 854 | av_get_bits_per_sample(avctx->codec_id); | |
| 3081 | // set stream disposition based on audio service type | ||
| 3082 |
1/6✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2302 times.
|
2302 | switch (avctx->audio_service_type) { |
| 3083 | ✗ | case AV_AUDIO_SERVICE_TYPE_EFFECTS: | |
| 3084 | ✗ | st->disposition = AV_DISPOSITION_CLEAN_EFFECTS; | |
| 3085 | ✗ | break; | |
| 3086 | ✗ | case AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED: | |
| 3087 | ✗ | st->disposition = AV_DISPOSITION_VISUAL_IMPAIRED; | |
| 3088 | ✗ | break; | |
| 3089 | ✗ | case AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED: | |
| 3090 | ✗ | st->disposition = AV_DISPOSITION_HEARING_IMPAIRED; | |
| 3091 | ✗ | break; | |
| 3092 | ✗ | case AV_AUDIO_SERVICE_TYPE_COMMENTARY: | |
| 3093 | ✗ | st->disposition = AV_DISPOSITION_COMMENT; | |
| 3094 | ✗ | break; | |
| 3095 | ✗ | case AV_AUDIO_SERVICE_TYPE_KARAOKE: | |
| 3096 | ✗ | st->disposition = AV_DISPOSITION_KARAOKE; | |
| 3097 | ✗ | break; | |
| 3098 | } | ||
| 3099 | } | ||
| 3100 | } | ||
| 3101 | |||
| 3102 |
1/2✓ Branch 0 taken 8231 times.
✗ Branch 1 not taken.
|
8231 | if (probesize) |
| 3103 | 8231 | estimate_timings(ic, old_offset); | |
| 3104 | |||
| 3105 | 8231 | av_opt_set_int(ic, "skip_clear", 0, AV_OPT_SEARCH_CHILDREN); | |
| 3106 | |||
| 3107 |
4/4✓ Branch 0 taken 6835 times.
✓ Branch 1 taken 1396 times.
✓ Branch 2 taken 6834 times.
✓ Branch 3 taken 1 times.
|
8231 | if (ret >= 0 && ic->nb_streams) |
| 3108 | /* We could not have all the codec parameters before EOF. */ | ||
| 3109 | 6834 | ret = -1; | |
| 3110 |
2/2✓ Branch 0 taken 9134 times.
✓ Branch 1 taken 8231 times.
|
17365 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
| 3111 | 9134 | AVStream *const st = ic->streams[i]; | |
| 3112 | 9134 | FFStream *const sti = ffstream(st); | |
| 3113 | const char *errmsg; | ||
| 3114 | |||
| 3115 | /* if no packet was ever seen, update context now for has_codec_parameters */ | ||
| 3116 |
2/2✓ Branch 0 taken 15 times.
✓ Branch 1 taken 9119 times.
|
9134 | if (!sti->avctx_inited) { |
| 3117 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 5 times.
|
15 | if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && |
| 3118 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | st->codecpar->format == AV_SAMPLE_FMT_NONE) |
| 3119 | 10 | st->codecpar->format = sti->avctx->sample_fmt; | |
| 3120 | 15 | ret = avcodec_parameters_to_context(sti->avctx, st->codecpar); | |
| 3121 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
|
15 | if (ret < 0) |
| 3122 | ✗ | goto find_stream_info_err; | |
| 3123 | } | ||
| 3124 |
2/2✓ Branch 1 taken 39 times.
✓ Branch 2 taken 9095 times.
|
9134 | if (!has_codec_parameters(st, &errmsg)) { |
| 3125 | char buf[256]; | ||
| 3126 | 39 | avcodec_string(buf, sizeof(buf), sti->avctx, 0); | |
| 3127 | 39 | av_log(ic, AV_LOG_WARNING, | |
| 3128 | "Could not find codec parameters for stream %d (%s): %s\n" | ||
| 3129 | "Consider increasing the value for the 'analyzeduration' (%"PRId64") and 'probesize' (%"PRId64") options\n", | ||
| 3130 | i, buf, errmsg, ic->max_analyze_duration, ic->probesize); | ||
| 3131 | } else { | ||
| 3132 | 9095 | ret = 0; | |
| 3133 | } | ||
| 3134 | } | ||
| 3135 | |||
| 3136 | 8231 | err = compute_chapters_end(ic); | |
| 3137 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8231 times.
|
8231 | if (err < 0) { |
| 3138 | ✗ | ret = err; | |
| 3139 | ✗ | goto find_stream_info_err; | |
| 3140 | } | ||
| 3141 | |||
| 3142 | /* update the stream parameters from the internal codec contexts */ | ||
| 3143 |
2/2✓ Branch 0 taken 9134 times.
✓ Branch 1 taken 8231 times.
|
17365 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
| 3144 | 9134 | AVStream *const st = ic->streams[i]; | |
| 3145 | 9134 | FFStream *const sti = ffstream(st); | |
| 3146 | |||
| 3147 |
2/2✓ Branch 0 taken 9119 times.
✓ Branch 1 taken 15 times.
|
9134 | if (sti->avctx_inited) { |
| 3148 | 9119 | ret = parameters_from_context(ic, st->codecpar, sti->avctx); | |
| 3149 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9119 times.
|
9119 | if (ret < 0) |
| 3150 | ✗ | goto find_stream_info_err; | |
| 3151 | |||
| 3152 |
3/4✓ Branch 0 taken 8906 times.
✓ Branch 1 taken 213 times.
✓ Branch 2 taken 8906 times.
✗ Branch 3 not taken.
|
9119 | if (sti->avctx->rc_buffer_size > 0 || sti->avctx->rc_max_rate > 0 || |
| 3153 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8906 times.
|
8906 | sti->avctx->rc_min_rate) { |
| 3154 | size_t cpb_size; | ||
| 3155 | 213 | AVCPBProperties *props = av_cpb_properties_alloc(&cpb_size); | |
| 3156 |
1/2✓ Branch 0 taken 213 times.
✗ Branch 1 not taken.
|
213 | if (props) { |
| 3157 |
1/2✓ Branch 0 taken 213 times.
✗ Branch 1 not taken.
|
213 | if (sti->avctx->rc_buffer_size > 0) |
| 3158 | 213 | props->buffer_size = sti->avctx->rc_buffer_size; | |
| 3159 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 213 times.
|
213 | if (sti->avctx->rc_min_rate > 0) |
| 3160 | ✗ | props->min_bitrate = sti->avctx->rc_min_rate; | |
| 3161 |
2/2✓ Branch 0 taken 79 times.
✓ Branch 1 taken 134 times.
|
213 | if (sti->avctx->rc_max_rate > 0) |
| 3162 | 79 | props->max_bitrate = sti->avctx->rc_max_rate; | |
| 3163 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 213 times.
|
213 | if (!av_packet_side_data_add(&st->codecpar->coded_side_data, |
| 3164 | 213 | &st->codecpar->nb_coded_side_data, | |
| 3165 | AV_PKT_DATA_CPB_PROPERTIES, | ||
| 3166 | (uint8_t *)props, cpb_size, 0)) | ||
| 3167 | ✗ | av_free(props); | |
| 3168 | } | ||
| 3169 | } | ||
| 3170 | } | ||
| 3171 | |||
| 3172 | 9134 | sti->avctx_inited = 0; | |
| 3173 | } | ||
| 3174 | |||
| 3175 | /* update the stream group parameters from the stream contexts if needed */ | ||
| 3176 |
2/2✓ Branch 0 taken 121 times.
✓ Branch 1 taken 8231 times.
|
8352 | for (unsigned i = 0; i < ic->nb_stream_groups; i++) { |
| 3177 | 121 | AVStreamGroup *const stg = ic->stream_groups[i]; | |
| 3178 | AVStreamGroupLayeredVideo *lcevc; | ||
| 3179 | const AVStream *st; | ||
| 3180 | |||
| 3181 |
2/2✓ Branch 0 taken 115 times.
✓ Branch 1 taken 6 times.
|
121 | if (stg->type != AV_STREAM_GROUP_PARAMS_LCEVC) |
| 3182 | 115 | continue; | |
| 3183 | |||
| 3184 | /* For LCEVC in mpegts, the parser is needed to get the enhancement layer | ||
| 3185 | * dimensions */ | ||
| 3186 | 6 | lcevc = stg->params.layered_video; | |
| 3187 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
6 | if (lcevc->width && lcevc->height) |
| 3188 | ✗ | continue; | |
| 3189 | 6 | st = stg->streams[lcevc->el_index]; | |
| 3190 | 6 | lcevc->width = st->codecpar->width; | |
| 3191 | 6 | lcevc->height = st->codecpar->height; | |
| 3192 | } | ||
| 3193 | |||
| 3194 | 8231 | find_stream_info_err: | |
| 3195 |
2/2✓ Branch 0 taken 9134 times.
✓ Branch 1 taken 8231 times.
|
17365 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
| 3196 | 9134 | AVStream *const st = ic->streams[i]; | |
| 3197 | 9134 | FFStream *const sti = ffstream(st); | |
| 3198 | int err; | ||
| 3199 | |||
| 3200 |
1/2✓ Branch 0 taken 9134 times.
✗ Branch 1 not taken.
|
9134 | if (sti->info) { |
| 3201 | 9134 | av_freep(&sti->info->duration_error); | |
| 3202 | 9134 | av_freep(&sti->info); | |
| 3203 | } | ||
| 3204 | |||
| 3205 |
2/2✓ Branch 1 taken 9006 times.
✓ Branch 2 taken 128 times.
|
9134 | if (avcodec_is_open(sti->avctx)) { |
| 3206 | 9006 | err = codec_close(sti); | |
| 3207 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 9006 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
9006 | if (err < 0 && ret >= 0) |
| 3208 | ✗ | ret = err; | |
| 3209 | } | ||
| 3210 | |||
| 3211 | 9134 | av_bsf_free(&sti->extract_extradata.bsf); | |
| 3212 | } | ||
| 3213 |
2/2✓ Branch 0 taken 5034 times.
✓ Branch 1 taken 3197 times.
|
8231 | if (ic->pb) { |
| 3214 | 5034 | FFIOContext *const ctx = ffiocontext(ic->pb); | |
| 3215 | 5034 | av_log(ic, AV_LOG_DEBUG, "After avformat_find_stream_info() pos: %"PRId64" bytes read:%"PRId64" seeks:%d frames:%d\n", | |
| 3216 | avio_tell(ic->pb), ctx->bytes_read, ctx->seek_count, count); | ||
| 3217 | } | ||
| 3218 | 8231 | return ret; | |
| 3219 | |||
| 3220 | ✗ | unref_then_goto_end: | |
| 3221 | ✗ | av_packet_unref(pkt1); | |
| 3222 | ✗ | goto find_stream_info_err; | |
| 3223 | } | ||
| 3224 |