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 "libavcodec/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 | 2481851 | static int64_t wrap_timestamp(const AVStream *st, int64_t timestamp) | |
54 | { | ||
55 | 2481851 | const FFStream *const sti = cffstream(st); | |
56 |
4/4✓ Branch 0 taken 150193 times.
✓ Branch 1 taken 2331658 times.
✓ Branch 2 taken 145607 times.
✓ Branch 3 taken 4586 times.
|
2481851 | if (sti->pts_wrap_behavior != AV_PTS_WRAP_IGNORE && st->pts_wrap_bits < 64 && |
57 |
3/4✓ Branch 0 taken 145607 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 88193 times.
✓ Branch 3 taken 57414 times.
|
145607 | sti->pts_wrap_reference != AV_NOPTS_VALUE && timestamp != AV_NOPTS_VALUE) { |
58 |
2/2✓ Branch 0 taken 87989 times.
✓ Branch 1 taken 204 times.
|
88193 | if (sti->pts_wrap_behavior == AV_PTS_WRAP_ADD_OFFSET && |
59 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 87989 times.
|
87989 | timestamp < sti->pts_wrap_reference) |
60 | ✗ | return timestamp + (1ULL << st->pts_wrap_bits); | |
61 |
2/2✓ Branch 0 taken 204 times.
✓ Branch 1 taken 87989 times.
|
88193 | 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 | 2481801 | return timestamp; | |
66 | } | ||
67 | |||
68 | 303897 | int64_t ff_wrap_timestamp(const AVStream *st, int64_t timestamp) | |
69 | { | ||
70 | 303897 | return wrap_timestamp(st, timestamp); | |
71 | } | ||
72 | |||
73 | 9682 | 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 335 times.
✓ Branch 1 taken 9347 times.
|
9682 | if (codec_id == AV_CODEC_ID_H264) |
81 | 335 | return avcodec_find_decoder_by_name("h264"); | |
82 | #endif | ||
83 | |||
84 | 9347 | codec = ff_find_decoder(s, st, codec_id); | |
85 |
2/2✓ Branch 0 taken 171 times.
✓ Branch 1 taken 9176 times.
|
9347 | if (!codec) |
86 | 171 | return NULL; | |
87 | |||
88 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9176 times.
|
9176 | 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 | 9176 | return codec; | |
101 | } | ||
102 | |||
103 | 3037 | 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 | 3037 | const AVInputFormat *fmt = av_probe_input_format3(pd, 1, &score); | |
133 | 3037 | FFStream *const sti = ffstream(st); | |
134 | |||
135 |
2/2✓ Branch 0 taken 955 times.
✓ Branch 1 taken 2082 times.
|
3037 | if (fmt) { |
136 | 955 | av_log(s, AV_LOG_DEBUG, | |
137 | "Probe with size=%d, packets=%d detected %s with score=%d\n", | ||
138 | 955 | pd->buf_size, s->max_probe_packets - sti->probe_packets, | |
139 | 955 | fmt->name, score); | |
140 |
2/2✓ Branch 0 taken 17028 times.
✓ Branch 1 taken 932 times.
|
17960 | for (int i = 0; fmt_id_type[i].name; i++) { |
141 |
2/2✓ Branch 0 taken 26 times.
✓ Branch 1 taken 17002 times.
|
17028 | if (!strcmp(fmt->name, fmt_id_type[i].name)) { |
142 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 15 times.
|
26 | if (fmt_id_type[i].type != AVMEDIA_TYPE_AUDIO && |
143 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
|
11 | st->codecpar->sample_rate) |
144 | ✗ | continue; | |
145 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 19 times.
|
26 | if (sti->request_probe > score && |
146 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 4 times.
|
7 | st->codecpar->codec_id != fmt_id_type[i].id) |
147 | 3 | continue; | |
148 | 23 | st->codecpar->codec_id = fmt_id_type[i].id; | |
149 | 23 | st->codecpar->codec_type = fmt_id_type[i].type; | |
150 | 23 | sti->need_context_update = 1; | |
151 | 23 | return score; | |
152 | } | ||
153 | } | ||
154 | } | ||
155 | 3014 | return 0; | |
156 | } | ||
157 | |||
158 | 7601 | static int init_input(AVFormatContext *s, const char *filename, | |
159 | AVDictionary **options) | ||
160 | { | ||
161 | int ret; | ||
162 | 7601 | AVProbeData pd = { filename, NULL, 0 }; | |
163 | 7601 | int score = AVPROBE_SCORE_RETRY; | |
164 | |||
165 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 7589 times.
|
7601 | if (s->pb) { |
166 | 12 | s->flags |= AVFMT_FLAG_CUSTOM_IO; | |
167 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
|
12 | 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 12 times.
|
12 | 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 | 12 | return 0; | |
174 | } | ||
175 | |||
176 |
4/4✓ Branch 0 taken 3717 times.
✓ Branch 1 taken 3872 times.
✓ Branch 2 taken 856 times.
✓ Branch 3 taken 2861 times.
|
7589 | if ((s->iformat && s->iformat->flags & AVFMT_NOFILE) || |
177 |
4/4✓ Branch 0 taken 3872 times.
✓ Branch 1 taken 856 times.
✓ Branch 3 taken 193 times.
✓ Branch 4 taken 3679 times.
|
4728 | (!s->iformat && (s->iformat = av_probe_input_format2(&pd, 0, &score)))) |
178 | 3054 | return score; | |
179 | |||
180 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4535 times.
|
4535 | 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 856 times.
✓ Branch 1 taken 3679 times.
|
4535 | if (s->iformat) |
184 | 856 | return 0; | |
185 | 3679 | return av_probe_input_buffer2(s->pb, &s->iformat, filename, | |
186 | 3679 | s, 0, s->format_probesize); | |
187 | } | ||
188 | |||
189 | 7601 | static int update_stream_avctx(AVFormatContext *s) | |
190 | { | ||
191 | int ret; | ||
192 |
2/2✓ Branch 0 taken 8228 times.
✓ Branch 1 taken 7601 times.
|
15829 | for (unsigned i = 0; i < s->nb_streams; i++) { |
193 | 8228 | AVStream *const st = s->streams[i]; | |
194 | 8228 | FFStream *const sti = ffstream(st); | |
195 | |||
196 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8228 times.
|
8228 | if (!sti->need_context_update) |
197 | ✗ | continue; | |
198 | |||
199 | /* close parser, because it depends on the codec */ | ||
200 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 8228 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
8228 | if (sti->parser && sti->avctx->codec_id != st->codecpar->codec_id) { |
201 | ✗ | av_parser_close(sti->parser); | |
202 | ✗ | sti->parser = NULL; | |
203 | } | ||
204 | |||
205 | /* update internal codec context, for the parser */ | ||
206 | 8228 | ret = avcodec_parameters_to_context(sti->avctx, st->codecpar); | |
207 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8228 times.
|
8228 | if (ret < 0) |
208 | ✗ | return ret; | |
209 | |||
210 | 8228 | sti->codec_desc = avcodec_descriptor_get(sti->avctx->codec_id); | |
211 | |||
212 | 8228 | sti->need_context_update = 0; | |
213 | } | ||
214 | 7601 | return 0; | |
215 | } | ||
216 | |||
217 | 7601 | int avformat_open_input(AVFormatContext **ps, const char *filename, | |
218 | const AVInputFormat *fmt, AVDictionary **options) | ||
219 | { | ||
220 | FormatContextInternal *fci; | ||
221 | 7601 | AVFormatContext *s = *ps; | |
222 | FFFormatContext *si; | ||
223 | 7601 | AVDictionary *tmp = NULL; | |
224 | 7601 | ID3v2ExtraMeta *id3v2_extra_meta = NULL; | |
225 | 7601 | int ret = 0; | |
226 | |||
227 |
3/4✓ Branch 0 taken 25 times.
✓ Branch 1 taken 7576 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 25 times.
|
7601 | if (!s && !(s = avformat_alloc_context())) |
228 | ✗ | return AVERROR(ENOMEM); | |
229 | 7601 | fci = ff_fc_internal(s); | |
230 | 7601 | si = &fci->fc; | |
231 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7601 times.
|
7601 | if (!s->av_class) { |
232 | ✗ | av_log(NULL, AV_LOG_ERROR, "Input context has not been properly allocated by avformat_alloc_context() and is not NULL either\n"); | |
233 | ✗ | return AVERROR(EINVAL); | |
234 | } | ||
235 |
2/2✓ Branch 0 taken 3729 times.
✓ Branch 1 taken 3872 times.
|
7601 | if (fmt) |
236 | 3729 | s->iformat = fmt; | |
237 | |||
238 |
2/2✓ Branch 0 taken 7588 times.
✓ Branch 1 taken 13 times.
|
7601 | if (options) |
239 | 7588 | av_dict_copy(&tmp, *options, 0); | |
240 | |||
241 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 7589 times.
|
7601 | if (s->pb) // must be before any goto fail |
242 | 12 | s->flags |= AVFMT_FLAG_CUSTOM_IO; | |
243 | |||
244 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 7601 times.
|
7601 | if ((ret = av_opt_set_dict(s, &tmp)) < 0) |
245 | ✗ | goto fail; | |
246 | |||
247 |
2/4✓ Branch 0 taken 7601 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 7601 times.
|
7601 | if (!(s->url = av_strdup(filename ? filename : ""))) { |
248 | ✗ | ret = AVERROR(ENOMEM); | |
249 | ✗ | goto fail; | |
250 | } | ||
251 | |||
252 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 7601 times.
|
7601 | if ((ret = init_input(s, filename, &tmp)) < 0) |
253 | ✗ | goto fail; | |
254 | 7601 | s->probe_score = ret; | |
255 | |||
256 |
6/6✓ Branch 0 taken 7518 times.
✓ Branch 1 taken 83 times.
✓ Branch 2 taken 4464 times.
✓ Branch 3 taken 3054 times.
✓ Branch 4 taken 4463 times.
✓ Branch 5 taken 1 times.
|
7601 | if (!s->protocol_whitelist && s->pb && s->pb->protocol_whitelist) { |
257 | 4463 | s->protocol_whitelist = av_strdup(s->pb->protocol_whitelist); | |
258 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4463 times.
|
4463 | if (!s->protocol_whitelist) { |
259 | ✗ | ret = AVERROR(ENOMEM); | |
260 | ✗ | goto fail; | |
261 | } | ||
262 | } | ||
263 | |||
264 |
4/6✓ Branch 0 taken 7601 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4547 times.
✓ Branch 3 taken 3054 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4547 times.
|
7601 | if (!s->protocol_blacklist && s->pb && s->pb->protocol_blacklist) { |
265 | ✗ | s->protocol_blacklist = av_strdup(s->pb->protocol_blacklist); | |
266 | ✗ | if (!s->protocol_blacklist) { | |
267 | ✗ | ret = AVERROR(ENOMEM); | |
268 | ✗ | goto fail; | |
269 | } | ||
270 | } | ||
271 | |||
272 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 7601 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
7601 | if (s->format_whitelist && av_match_list(s->iformat->name, s->format_whitelist, ',') <= 0) { |
273 | ✗ | av_log(s, AV_LOG_ERROR, "Format not on whitelist \'%s\'\n", s->format_whitelist); | |
274 | ✗ | ret = AVERROR(EINVAL); | |
275 | ✗ | goto fail; | |
276 | } | ||
277 | |||
278 | 7601 | avio_skip(s->pb, s->skip_initial_bytes); | |
279 | |||
280 | /* Check filename in case an image number is expected. */ | ||
281 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7601 times.
|
7601 | if (s->iformat->flags & AVFMT_NEEDNUMBER) { |
282 | ✗ | if (!av_filename_number_test(filename)) { | |
283 | ✗ | ret = AVERROR(EINVAL); | |
284 | ✗ | goto fail; | |
285 | } | ||
286 | } | ||
287 | |||
288 | 7601 | s->duration = s->start_time = AV_NOPTS_VALUE; | |
289 | |||
290 | /* Allocate private data. */ | ||
291 |
2/2✓ Branch 1 taken 7444 times.
✓ Branch 2 taken 157 times.
|
7601 | if (ffifmt(s->iformat)->priv_data_size > 0) { |
292 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 7444 times.
|
7444 | if (!(s->priv_data = av_mallocz(ffifmt(s->iformat)->priv_data_size))) { |
293 | ✗ | ret = AVERROR(ENOMEM); | |
294 | ✗ | goto fail; | |
295 | } | ||
296 |
2/2✓ Branch 0 taken 6610 times.
✓ Branch 1 taken 834 times.
|
7444 | if (s->iformat->priv_class) { |
297 | 6610 | *(const AVClass **) s->priv_data = s->iformat->priv_class; | |
298 | 6610 | av_opt_set_defaults(s->priv_data); | |
299 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 6610 times.
|
6610 | if ((ret = av_opt_set_dict(s->priv_data, &tmp)) < 0) |
300 | ✗ | goto fail; | |
301 | } | ||
302 | } | ||
303 | |||
304 | /* e.g. AVFMT_NOFILE formats will not have an AVIOContext */ | ||
305 |
2/2✓ Branch 0 taken 4547 times.
✓ Branch 1 taken 3054 times.
|
7601 | if (s->pb) |
306 | 4547 | ff_id3v2_read_dict(s->pb, &si->id3v2_meta, ID3v2_DEFAULT_MAGIC, &id3v2_extra_meta); | |
307 | |||
308 |
1/2✓ Branch 1 taken 7601 times.
✗ Branch 2 not taken.
|
7601 | if (ffifmt(s->iformat)->read_header) |
309 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 7601 times.
|
7601 | if ((ret = ffifmt(s->iformat)->read_header(s)) < 0) { |
310 | ✗ | if (ffifmt(s->iformat)->flags_internal & FF_INFMT_FLAG_INIT_CLEANUP) | |
311 | ✗ | goto close; | |
312 | ✗ | goto fail; | |
313 | } | ||
314 | |||
315 |
2/2✓ Branch 0 taken 6320 times.
✓ Branch 1 taken 1281 times.
|
7601 | if (!s->metadata) { |
316 | 6320 | s->metadata = si->id3v2_meta; | |
317 | 6320 | si->id3v2_meta = NULL; | |
318 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1281 times.
|
1281 | } else if (si->id3v2_meta) { |
319 | ✗ | av_log(s, AV_LOG_WARNING, "Discarding ID3 tags because more suitable tags were found.\n"); | |
320 | ✗ | av_dict_free(&si->id3v2_meta); | |
321 | } | ||
322 | |||
323 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 7591 times.
|
7601 | if (id3v2_extra_meta) { |
324 |
3/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
10 | if (!strcmp(s->iformat->name, "mp3") || !strcmp(s->iformat->name, "aac") || |
325 | ✗ | !strcmp(s->iformat->name, "tta") || !strcmp(s->iformat->name, "wav")) { | |
326 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
|
10 | if ((ret = ff_id3v2_parse_apic(s, id3v2_extra_meta)) < 0) |
327 | ✗ | goto close; | |
328 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
|
10 | if ((ret = ff_id3v2_parse_chapters(s, id3v2_extra_meta)) < 0) |
329 | ✗ | goto close; | |
330 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
|
10 | if ((ret = ff_id3v2_parse_priv(s, id3v2_extra_meta)) < 0) |
331 | ✗ | goto close; | |
332 | } else | ||
333 | ✗ | av_log(s, AV_LOG_DEBUG, "demuxer does not support additional id3 data, skipping\n"); | |
334 | 10 | ff_id3v2_free_extra_meta(&id3v2_extra_meta); | |
335 | } | ||
336 | |||
337 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 7601 times.
|
7601 | if ((ret = avformat_queue_attached_pictures(s)) < 0) |
338 | ✗ | goto close; | |
339 | |||
340 |
4/4✓ Branch 0 taken 4547 times.
✓ Branch 1 taken 3054 times.
✓ Branch 2 taken 4105 times.
✓ Branch 3 taken 442 times.
|
7601 | if (s->pb && !si->data_offset) |
341 | 4105 | si->data_offset = avio_tell(s->pb); | |
342 | |||
343 | 7601 | fci->raw_packet_buffer_size = 0; | |
344 | |||
345 | 7601 | update_stream_avctx(s); | |
346 | |||
347 |
2/2✓ Branch 0 taken 7588 times.
✓ Branch 1 taken 13 times.
|
7601 | if (options) { |
348 | 7588 | av_dict_free(options); | |
349 | 7588 | *options = tmp; | |
350 | } | ||
351 | 7601 | *ps = s; | |
352 | 7601 | return 0; | |
353 | |||
354 | ✗ | close: | |
355 | ✗ | if (ffifmt(s->iformat)->read_close) | |
356 | ✗ | ffifmt(s->iformat)->read_close(s); | |
357 | ✗ | fail: | |
358 | ✗ | ff_id3v2_free_extra_meta(&id3v2_extra_meta); | |
359 | ✗ | av_dict_free(&tmp); | |
360 | ✗ | if (s->pb && !(s->flags & AVFMT_FLAG_CUSTOM_IO)) | |
361 | ✗ | avio_closep(&s->pb); | |
362 | ✗ | avformat_free_context(s); | |
363 | ✗ | *ps = NULL; | |
364 | ✗ | return ret; | |
365 | } | ||
366 | |||
367 | 7601 | void avformat_close_input(AVFormatContext **ps) | |
368 | { | ||
369 | AVFormatContext *s; | ||
370 | AVIOContext *pb; | ||
371 | |||
372 |
2/4✓ Branch 0 taken 7601 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7601 times.
|
7601 | if (!ps || !*ps) |
373 | ✗ | return; | |
374 | |||
375 | 7601 | s = *ps; | |
376 | 7601 | pb = s->pb; | |
377 | |||
378 |
5/6✓ Branch 0 taken 7601 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4567 times.
✓ Branch 3 taken 3034 times.
✓ Branch 4 taken 4522 times.
✓ Branch 5 taken 45 times.
|
7601 | if ((s->iformat && strcmp(s->iformat->name, "image2") && s->iformat->flags & AVFMT_NOFILE) || |
379 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 7544 times.
|
7556 | (s->flags & AVFMT_FLAG_CUSTOM_IO)) |
380 | 57 | pb = NULL; | |
381 | |||
382 |
1/2✓ Branch 0 taken 7601 times.
✗ Branch 1 not taken.
|
7601 | if (s->iformat) |
383 |
2/2✓ Branch 1 taken 4933 times.
✓ Branch 2 taken 2668 times.
|
7601 | if (ffifmt(s->iformat)->read_close) |
384 | 4933 | ffifmt(s->iformat)->read_close(s); | |
385 | |||
386 | 7601 | ff_format_io_close(s, &pb); | |
387 | 7601 | avformat_free_context(s); | |
388 | |||
389 | 7601 | *ps = NULL; | |
390 | } | ||
391 | |||
392 | 1092013 | static void force_codec_ids(AVFormatContext *s, AVStream *st) | |
393 | { | ||
394 |
5/5✓ Branch 0 taken 742261 times.
✓ Branch 1 taken 346655 times.
✓ Branch 2 taken 2967 times.
✓ Branch 3 taken 128 times.
✓ Branch 4 taken 2 times.
|
1092013 | switch (st->codecpar->codec_type) { |
395 | 742261 | case AVMEDIA_TYPE_VIDEO: | |
396 |
2/2✓ Branch 0 taken 115168 times.
✓ Branch 1 taken 627093 times.
|
742261 | if (s->video_codec_id) |
397 | 115168 | st->codecpar->codec_id = s->video_codec_id; | |
398 | 742261 | break; | |
399 | 346655 | case AVMEDIA_TYPE_AUDIO: | |
400 |
2/2✓ Branch 0 taken 2558 times.
✓ Branch 1 taken 344097 times.
|
346655 | if (s->audio_codec_id) |
401 | 2558 | st->codecpar->codec_id = s->audio_codec_id; | |
402 | 346655 | break; | |
403 | 2967 | case AVMEDIA_TYPE_SUBTITLE: | |
404 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2967 times.
|
2967 | if (s->subtitle_codec_id) |
405 | ✗ | st->codecpar->codec_id = s->subtitle_codec_id; | |
406 | 2967 | break; | |
407 | 128 | case AVMEDIA_TYPE_DATA: | |
408 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 128 times.
|
128 | if (s->data_codec_id) |
409 | ✗ | st->codecpar->codec_id = s->data_codec_id; | |
410 | 128 | break; | |
411 | } | ||
412 | 1092013 | } | |
413 | |||
414 | 22150 | static int probe_codec(AVFormatContext *s, AVStream *st, const AVPacket *pkt) | |
415 | { | ||
416 | 22150 | FormatContextInternal *const fci = ff_fc_internal(s); | |
417 | 22150 | FFStream *const sti = ffstream(st); | |
418 | |||
419 |
2/2✓ Branch 0 taken 15983 times.
✓ Branch 1 taken 6167 times.
|
22150 | if (sti->request_probe > 0) { |
420 | 15983 | AVProbeData *const pd = &sti->probe_data; | |
421 | int end; | ||
422 | 15983 | av_log(s, AV_LOG_DEBUG, "probing stream %d pp:%d\n", st->index, sti->probe_packets); | |
423 | 15983 | --sti->probe_packets; | |
424 | |||
425 |
2/2✓ Branch 0 taken 15971 times.
✓ Branch 1 taken 12 times.
|
15983 | if (pkt) { |
426 | 15971 | uint8_t *new_buf = av_realloc(pd->buf, pd->buf_size+pkt->size+AVPROBE_PADDING_SIZE); | |
427 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15971 times.
|
15971 | if (!new_buf) { |
428 | ✗ | av_log(s, AV_LOG_WARNING, | |
429 | "Failed to reallocate probe buffer for stream %d\n", | ||
430 | st->index); | ||
431 | ✗ | goto no_packet; | |
432 | } | ||
433 | 15971 | pd->buf = new_buf; | |
434 | 15971 | memcpy(pd->buf + pd->buf_size, pkt->data, pkt->size); | |
435 | 15971 | pd->buf_size += pkt->size; | |
436 | 15971 | memset(pd->buf + pd->buf_size, 0, AVPROBE_PADDING_SIZE); | |
437 | } else { | ||
438 | 12 | no_packet: | |
439 | 12 | sti->probe_packets = 0; | |
440 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
|
12 | if (!pd->buf_size) { |
441 | ✗ | av_log(s, AV_LOG_WARNING, | |
442 | "nothing to probe for stream %d\n", st->index); | ||
443 | } | ||
444 | } | ||
445 | |||
446 |
1/2✓ Branch 0 taken 15983 times.
✗ Branch 1 not taken.
|
31966 | end = fci->raw_packet_buffer_size >= s->probesize || |
447 |
2/2✓ Branch 0 taken 499 times.
✓ Branch 1 taken 15484 times.
|
15983 | sti->probe_packets <= 0; |
448 | |||
449 |
4/4✓ Branch 0 taken 15484 times.
✓ Branch 1 taken 499 times.
✓ Branch 2 taken 2538 times.
✓ Branch 3 taken 12946 times.
|
15983 | if (end || av_log2(pd->buf_size) != av_log2(pd->buf_size - pkt->size)) { |
450 | 3037 | int score = set_codec_from_probe_data(s, st, pd); | |
451 |
4/4✓ Branch 0 taken 3029 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 3010 times.
✓ Branch 3 taken 19 times.
|
3037 | if ( (st->codecpar->codec_id != AV_CODEC_ID_NONE && score > AVPROBE_SCORE_STREAM_RETRY) |
452 |
2/2✓ Branch 0 taken 499 times.
✓ Branch 1 taken 2519 times.
|
3018 | || end) { |
453 | 518 | pd->buf_size = 0; | |
454 | 518 | av_freep(&pd->buf); | |
455 | 518 | sti->request_probe = -1; | |
456 |
1/2✓ Branch 0 taken 518 times.
✗ Branch 1 not taken.
|
518 | if (st->codecpar->codec_id != AV_CODEC_ID_NONE) { |
457 | 518 | av_log(s, AV_LOG_DEBUG, "probed stream %d\n", st->index); | |
458 | } else | ||
459 | ✗ | av_log(s, AV_LOG_WARNING, "probed stream %d failed\n", st->index); | |
460 | } | ||
461 | 3037 | force_codec_ids(s, st); | |
462 | } | ||
463 | } | ||
464 | 22150 | return 0; | |
465 | } | ||
466 | |||
467 | 1088976 | static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_index, AVPacket *pkt) | |
468 | { | ||
469 | 1088976 | FFStream *const sti = ffstream(st); | |
470 | 1088976 | int64_t ref = pkt->dts; | |
471 | int pts_wrap_behavior; | ||
472 | int64_t pts_wrap_reference; | ||
473 | AVProgram *first_program; | ||
474 | |||
475 |
2/2✓ Branch 0 taken 886914 times.
✓ Branch 1 taken 202062 times.
|
1088976 | if (ref == AV_NOPTS_VALUE) |
476 | 886914 | ref = pkt->pts; | |
477 |
7/8✓ Branch 0 taken 1021503 times.
✓ Branch 1 taken 67473 times.
✓ Branch 2 taken 48580 times.
✓ Branch 3 taken 972923 times.
✓ Branch 4 taken 303 times.
✓ Branch 5 taken 48277 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 303 times.
|
1088976 | if (sti->pts_wrap_reference != AV_NOPTS_VALUE || st->pts_wrap_bits >= 63 || ref == AV_NOPTS_VALUE || !s->correct_ts_overflow) |
478 | 1088673 | return 0; | |
479 | 303 | ref &= (1LL << st->pts_wrap_bits)-1; | |
480 | |||
481 | // reference time stamp should be 60 s before first time stamp | ||
482 | 303 | pts_wrap_reference = ref - av_rescale(60, st->time_base.den, st->time_base.num); | |
483 | // if first time stamp is not more than 1/8 and 60s before the wrap point, subtract rather than add wrap offset | ||
484 | 607 | pts_wrap_behavior = (ref < (1LL << st->pts_wrap_bits) - (1LL << st->pts_wrap_bits-3)) || | |
485 |
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)) ? |
486 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 302 times.
|
304 | AV_PTS_WRAP_ADD_OFFSET : AV_PTS_WRAP_SUB_OFFSET; |
487 | |||
488 | 303 | first_program = av_find_program_from_stream(s, NULL, stream_index); | |
489 | |||
490 |
2/2✓ Branch 0 taken 197 times.
✓ Branch 1 taken 106 times.
|
303 | if (!first_program) { |
491 | 197 | int default_stream_index = av_find_default_stream_index(s); | |
492 | 197 | FFStream *const default_sti = ffstream(s->streams[default_stream_index]); | |
493 |
2/2✓ Branch 0 taken 186 times.
✓ Branch 1 taken 11 times.
|
197 | if (default_sti->pts_wrap_reference == AV_NOPTS_VALUE) { |
494 |
2/2✓ Branch 0 taken 347 times.
✓ Branch 1 taken 186 times.
|
533 | for (unsigned i = 0; i < s->nb_streams; i++) { |
495 | 347 | FFStream *const sti = ffstream(s->streams[i]); | |
496 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 347 times.
|
347 | if (av_find_program_from_stream(s, NULL, i)) |
497 | ✗ | continue; | |
498 | 347 | sti->pts_wrap_reference = pts_wrap_reference; | |
499 | 347 | sti->pts_wrap_behavior = pts_wrap_behavior; | |
500 | } | ||
501 | } else { | ||
502 | 11 | sti->pts_wrap_reference = default_sti->pts_wrap_reference; | |
503 | 11 | sti->pts_wrap_behavior = default_sti->pts_wrap_behavior; | |
504 | } | ||
505 | } else { | ||
506 | 106 | AVProgram *program = first_program; | |
507 |
2/2✓ Branch 0 taken 106 times.
✓ Branch 1 taken 66 times.
|
172 | while (program) { |
508 |
2/2✓ Branch 0 taken 40 times.
✓ Branch 1 taken 66 times.
|
106 | if (program->pts_wrap_reference != AV_NOPTS_VALUE) { |
509 | 40 | pts_wrap_reference = program->pts_wrap_reference; | |
510 | 40 | pts_wrap_behavior = program->pts_wrap_behavior; | |
511 | 40 | break; | |
512 | } | ||
513 | 66 | program = av_find_program_from_stream(s, program, stream_index); | |
514 | } | ||
515 | |||
516 | // update every program with differing pts_wrap_reference | ||
517 | 106 | program = first_program; | |
518 |
2/2✓ Branch 0 taken 106 times.
✓ Branch 1 taken 106 times.
|
212 | while (program) { |
519 |
2/2✓ Branch 0 taken 66 times.
✓ Branch 1 taken 40 times.
|
106 | if (program->pts_wrap_reference != pts_wrap_reference) { |
520 |
2/2✓ Branch 0 taken 108 times.
✓ Branch 1 taken 66 times.
|
174 | for (unsigned i = 0; i < program->nb_stream_indexes; i++) { |
521 | 108 | FFStream *const sti = ffstream(s->streams[program->stream_index[i]]); | |
522 | 108 | sti->pts_wrap_reference = pts_wrap_reference; | |
523 | 108 | sti->pts_wrap_behavior = pts_wrap_behavior; | |
524 | } | ||
525 | |||
526 | 66 | program->pts_wrap_reference = pts_wrap_reference; | |
527 | 66 | program->pts_wrap_behavior = pts_wrap_behavior; | |
528 | } | ||
529 | 106 | program = av_find_program_from_stream(s, program, stream_index); | |
530 | } | ||
531 | } | ||
532 | 303 | return 1; | |
533 | } | ||
534 | |||
535 | 1088976 | static void update_timestamps(AVFormatContext *s, AVStream *st, AVPacket *pkt) | |
536 | { | ||
537 | 1088976 | FFStream *const sti = ffstream(st); | |
538 | |||
539 |
4/4✓ Branch 1 taken 303 times.
✓ Branch 2 taken 1088673 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 302 times.
|
1088976 | if (update_wrap_reference(s, st, pkt->stream_index, pkt) && sti->pts_wrap_behavior == AV_PTS_WRAP_SUB_OFFSET) { |
540 | // correct first time stamps to negative values | ||
541 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | if (!is_relative(sti->first_dts)) |
542 | 1 | sti->first_dts = wrap_timestamp(st, sti->first_dts); | |
543 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | if (!is_relative(st->start_time)) |
544 | 1 | st->start_time = wrap_timestamp(st, st->start_time); | |
545 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (!is_relative(sti->cur_dts)) |
546 | ✗ | sti->cur_dts = wrap_timestamp(st, sti->cur_dts); | |
547 | } | ||
548 | |||
549 | 1088976 | pkt->dts = wrap_timestamp(st, pkt->dts); | |
550 | 1088976 | pkt->pts = wrap_timestamp(st, pkt->pts); | |
551 | |||
552 | 1088976 | force_codec_ids(s, st); | |
553 | |||
554 | /* TODO: audio: time filter; video: frame reordering (pts != dts) */ | ||
555 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1088976 times.
|
1088976 | if (s->use_wallclock_as_timestamps) |
556 | ✗ | pkt->dts = pkt->pts = av_rescale_q(av_gettime(), AV_TIME_BASE_Q, st->time_base); | |
557 | 1088976 | } | |
558 | |||
559 | /** | ||
560 | * Handle a new packet and either return it directly if possible and | ||
561 | * allow_passthrough is true or queue the packet (or drop the packet | ||
562 | * if corrupt). | ||
563 | * | ||
564 | * @return < 0 on error, 0 if the packet was passed through, | ||
565 | * 1 if it was queued or dropped | ||
566 | */ | ||
567 | 1088976 | static int handle_new_packet(AVFormatContext *s, AVPacket *pkt, int allow_passthrough) | |
568 | { | ||
569 | 1088976 | FormatContextInternal *const fci = ff_fc_internal(s); | |
570 | AVStream *st; | ||
571 | FFStream *sti; | ||
572 | int err; | ||
573 | |||
574 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1088976 times.
|
1088976 | av_assert0(pkt->stream_index < (unsigned)s->nb_streams && |
575 | "Invalid stream index.\n"); | ||
576 | |||
577 |
2/2✓ Branch 0 taken 200 times.
✓ Branch 1 taken 1088776 times.
|
1088976 | if (pkt->flags & AV_PKT_FLAG_CORRUPT) { |
578 | 400 | av_log(s, AV_LOG_WARNING, | |
579 | "Packet corrupt (stream = %d, dts = %s)%s.\n", | ||
580 | 200 | pkt->stream_index, av_ts2str(pkt->dts), | |
581 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 200 times.
|
200 | s->flags & AVFMT_FLAG_DISCARD_CORRUPT ? ", dropping it" : ""); |
582 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 200 times.
|
200 | if (s->flags & AVFMT_FLAG_DISCARD_CORRUPT) { |
583 | ✗ | av_packet_unref(pkt); | |
584 | ✗ | return 1; | |
585 | } | ||
586 | } | ||
587 | |||
588 | 1088976 | st = s->streams[pkt->stream_index]; | |
589 | 1088976 | sti = ffstream(st); | |
590 | |||
591 | 1088976 | update_timestamps(s, st, pkt); | |
592 | |||
593 |
6/6✓ Branch 0 taken 1073005 times.
✓ Branch 1 taken 15971 times.
✓ Branch 2 taken 1066880 times.
✓ Branch 3 taken 6125 times.
✓ Branch 4 taken 1066838 times.
✓ Branch 5 taken 42 times.
|
1088976 | if (sti->request_probe <= 0 && allow_passthrough && !fci->raw_packet_buffer.head) |
594 | 1066838 | return 0; | |
595 | |||
596 | 22138 | err = avpriv_packet_list_put(&fci->raw_packet_buffer, pkt, NULL, 0); | |
597 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 22138 times.
|
22138 | if (err < 0) { |
598 | ✗ | av_packet_unref(pkt); | |
599 | ✗ | return err; | |
600 | } | ||
601 | |||
602 | 22138 | pkt = &fci->raw_packet_buffer.tail->pkt; | |
603 | 22138 | fci->raw_packet_buffer_size += pkt->size; | |
604 | |||
605 | 22138 | err = probe_codec(s, st, pkt); | |
606 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 22138 times.
|
22138 | if (err < 0) |
607 | ✗ | return err; | |
608 | |||
609 | 22138 | return 1; | |
610 | } | ||
611 | |||
612 | 6125 | int ff_buffer_packet(AVFormatContext *s, AVPacket *pkt) | |
613 | { | ||
614 | 6125 | int err = handle_new_packet(s, pkt, 0); | |
615 | |||
616 | 6125 | return err < 0 ? err : 0; | |
617 | } | ||
618 | |||
619 | 1095517 | int ff_read_packet(AVFormatContext *s, AVPacket *pkt) | |
620 | { | ||
621 | 1095517 | FormatContextInternal *const fci = ff_fc_internal(s); | |
622 | int err; | ||
623 | |||
624 | #if FF_API_INIT_PACKET | ||
625 | FF_DISABLE_DEPRECATION_WARNINGS | ||
626 | 1095517 | pkt->data = NULL; | |
627 | 1095517 | pkt->size = 0; | |
628 | 1095517 | av_init_packet(pkt); | |
629 | FF_ENABLE_DEPRECATION_WARNINGS | ||
630 | #else | ||
631 | av_packet_unref(pkt); | ||
632 | #endif | ||
633 | |||
634 | 22427 | for (;;) { | |
635 | 1117944 | PacketListEntry *pktl = fci->raw_packet_buffer.head; | |
636 | |||
637 |
2/2✓ Branch 0 taken 37692 times.
✓ Branch 1 taken 1080252 times.
|
1117944 | if (pktl) { |
638 | 37692 | AVStream *const st = s->streams[pktl->pkt.stream_index]; | |
639 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37692 times.
|
37692 | if (fci->raw_packet_buffer_size >= s->probesize) |
640 | ✗ | if ((err = probe_codec(s, st, NULL)) < 0) | |
641 | ✗ | return err; | |
642 |
2/2✓ Branch 1 taken 22185 times.
✓ Branch 2 taken 15507 times.
|
37692 | if (ffstream(st)->request_probe <= 0) { |
643 | 22185 | avpriv_packet_list_get(&fci->raw_packet_buffer, pkt); | |
644 | 22185 | fci->raw_packet_buffer_size -= pkt->size; | |
645 | 22185 | return 0; | |
646 | } | ||
647 | } | ||
648 | |||
649 | 1095759 | err = ffifmt(s->iformat)->read_packet(s, pkt); | |
650 |
2/2✓ Branch 0 taken 12908 times.
✓ Branch 1 taken 1082851 times.
|
1095759 | if (err < 0) { |
651 | 12908 | av_packet_unref(pkt); | |
652 | |||
653 | /* Some demuxers return FFERROR_REDO when they consume | ||
654 | data and discard it (ignored streams, junk, extradata). | ||
655 | We must re-call the demuxer to get the real packet. */ | ||
656 |
2/2✓ Branch 0 taken 6402 times.
✓ Branch 1 taken 6506 times.
|
12908 | if (err == FFERROR_REDO) |
657 | 6402 | continue; | |
658 |
3/4✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6494 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
|
6506 | if (!pktl || err == AVERROR(EAGAIN)) |
659 | 6494 | return err; | |
660 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
|
24 | for (unsigned i = 0; i < s->nb_streams; i++) { |
661 | 12 | AVStream *const st = s->streams[i]; | |
662 | 12 | FFStream *const sti = ffstream(st); | |
663 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
12 | if (sti->probe_packets || sti->request_probe > 0) |
664 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
|
12 | if ((err = probe_codec(s, st, NULL)) < 0) |
665 | ✗ | return err; | |
666 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
|
12 | av_assert0(sti->request_probe <= 0); |
667 | } | ||
668 | 12 | continue; | |
669 | } | ||
670 | |||
671 | 1082851 | err = av_packet_make_refcounted(pkt); | |
672 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1082851 times.
|
1082851 | if (err < 0) { |
673 | ✗ | av_packet_unref(pkt); | |
674 | ✗ | return err; | |
675 | } | ||
676 | |||
677 | 1082851 | err = handle_new_packet(s, pkt, 1); | |
678 |
2/2✓ Branch 0 taken 1066838 times.
✓ Branch 1 taken 16013 times.
|
1082851 | if (err <= 0) /* Error or passthrough */ |
679 | 1066838 | return err; | |
680 | } | ||
681 | } | ||
682 | |||
683 | /** | ||
684 | * Return the frame duration in seconds. Return 0 if not available. | ||
685 | */ | ||
686 | 321685 | static void compute_frame_duration(AVFormatContext *s, int *pnum, int *pden, | |
687 | AVStream *st, AVCodecParserContext *pc, | ||
688 | AVPacket *pkt) | ||
689 | { | ||
690 | 321685 | FFStream *const sti = ffstream(st); | |
691 | 321685 | AVRational codec_framerate = sti->avctx->framerate; | |
692 | int frame_size, sample_rate; | ||
693 | |||
694 | 321685 | *pnum = 0; | |
695 | 321685 | *pden = 0; | |
696 |
3/3✓ Branch 0 taken 219885 times.
✓ Branch 1 taken 100420 times.
✓ Branch 2 taken 1380 times.
|
321685 | switch (st->codecpar->codec_type) { |
697 | 219885 | case AVMEDIA_TYPE_VIDEO: | |
698 |
6/6✓ Branch 0 taken 190021 times.
✓ Branch 1 taken 29864 times.
✓ Branch 2 taken 42269 times.
✓ Branch 3 taken 147752 times.
✓ Branch 4 taken 30841 times.
✓ Branch 5 taken 11428 times.
|
219885 | if (st->r_frame_rate.num && (!pc || !codec_framerate.num)) { |
699 | 178593 | *pnum = st->r_frame_rate.den; | |
700 | 178593 | *pden = st->r_frame_rate.num; | |
701 |
2/2✓ Branch 0 taken 23740 times.
✓ Branch 1 taken 17552 times.
|
41292 | } else if ((s->iformat->flags & AVFMT_NOTIMESTAMPS) && |
702 |
2/2✓ Branch 0 taken 14778 times.
✓ Branch 1 taken 8962 times.
|
23740 | !codec_framerate.num && |
703 |
3/4✓ Branch 0 taken 14776 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 14776 times.
✗ Branch 3 not taken.
|
14778 | st->avg_frame_rate.num && st->avg_frame_rate.den) { |
704 | 14776 | *pnum = st->avg_frame_rate.den; | |
705 | 14776 | *pden = st->avg_frame_rate.num; | |
706 |
2/2✓ Branch 0 taken 9152 times.
✓ Branch 1 taken 17364 times.
|
26516 | } else if (st->time_base.num * 1000LL > st->time_base.den) { |
707 | 9152 | *pnum = st->time_base.num; | |
708 | 9152 | *pden = st->time_base.den; | |
709 |
2/2✓ Branch 0 taken 17339 times.
✓ Branch 1 taken 25 times.
|
17364 | } else if (codec_framerate.den * 1000LL > codec_framerate.num) { |
710 | 52017 | int ticks_per_frame = (sti->codec_desc && | |
711 |
3/4✓ Branch 0 taken 17339 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12072 times.
✓ Branch 3 taken 5267 times.
|
17339 | (sti->codec_desc->props & AV_CODEC_PROP_FIELDS)) ? 2 : 1; |
712 | 17339 | av_reduce(pnum, pden, | |
713 | 17339 | codec_framerate.den, | |
714 | 17339 | codec_framerate.num * (int64_t)ticks_per_frame, | |
715 | INT_MAX); | ||
716 | |||
717 |
4/4✓ Branch 0 taken 15513 times.
✓ Branch 1 taken 1826 times.
✓ Branch 2 taken 11443 times.
✓ Branch 3 taken 4070 times.
|
17339 | if (pc && pc->repeat_pict) { |
718 | 11443 | av_reduce(pnum, pden, | |
719 | 11443 | (*pnum) * (1LL + pc->repeat_pict), | |
720 | 11443 | (*pden), | |
721 | INT_MAX); | ||
722 | } | ||
723 | /* If this codec can be interlaced or progressive then we need | ||
724 | * a parser to compute duration of a packet. Thus if we have | ||
725 | * no parser in such case leave duration undefined. */ | ||
726 |
1/2✓ Branch 0 taken 17339 times.
✗ Branch 1 not taken.
|
17339 | if (sti->codec_desc && |
727 |
3/4✓ Branch 0 taken 12072 times.
✓ Branch 1 taken 5267 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12072 times.
|
17339 | (sti->codec_desc->props & AV_CODEC_PROP_FIELDS) && !pc) |
728 | ✗ | *pnum = *pden = 0; | |
729 | } | ||
730 | 219885 | break; | |
731 | 100420 | case AVMEDIA_TYPE_AUDIO: | |
732 |
2/2✓ Branch 0 taken 45154 times.
✓ Branch 1 taken 55266 times.
|
100420 | if (sti->avctx_inited) { |
733 | 45154 | frame_size = av_get_audio_frame_duration(sti->avctx, pkt->size); | |
734 | 45154 | sample_rate = sti->avctx->sample_rate; | |
735 | } else { | ||
736 | 55266 | frame_size = av_get_audio_frame_duration2(st->codecpar, pkt->size); | |
737 | 55266 | sample_rate = st->codecpar->sample_rate; | |
738 | } | ||
739 |
4/4✓ Branch 0 taken 95150 times.
✓ Branch 1 taken 5270 times.
✓ Branch 2 taken 95145 times.
✓ Branch 3 taken 5 times.
|
100420 | if (frame_size <= 0 || sample_rate <= 0) |
740 | break; | ||
741 | 95145 | *pnum = frame_size; | |
742 | 95145 | *pden = sample_rate; | |
743 | 95145 | break; | |
744 | 1380 | default: | |
745 | 1380 | break; | |
746 | } | ||
747 | 321685 | } | |
748 | |||
749 | 720843 | static int has_decode_delay_been_guessed(AVStream *st) | |
750 | { | ||
751 | 720843 | FFStream *const sti = ffstream(st); | |
752 |
2/2✓ Branch 0 taken 703886 times.
✓ Branch 1 taken 16957 times.
|
720843 | if (st->codecpar->codec_id != AV_CODEC_ID_H264) return 1; |
753 |
2/2✓ Branch 0 taken 6050 times.
✓ Branch 1 taken 10907 times.
|
16957 | if (!sti->info) // if we have left find_stream_info then nb_decoded_frames won't increase anymore for stream copy |
754 | 6050 | return 1; | |
755 | #if CONFIG_H264_DECODER | ||
756 |
2/2✓ Branch 0 taken 6687 times.
✓ Branch 1 taken 4220 times.
|
10907 | if (sti->avctx->has_b_frames && |
757 |
2/2✓ Branch 1 taken 1416 times.
✓ Branch 2 taken 5271 times.
|
6687 | avpriv_h264_has_num_reorder_frames(sti->avctx) == sti->avctx->has_b_frames) |
758 | 1416 | return 1; | |
759 | #endif | ||
760 |
2/2✓ Branch 0 taken 9303 times.
✓ Branch 1 taken 188 times.
|
9491 | if (sti->avctx->has_b_frames < 3) |
761 | 9303 | return sti->nb_decoded_frames >= 7; | |
762 |
2/2✓ Branch 0 taken 36 times.
✓ Branch 1 taken 152 times.
|
188 | else if (sti->avctx->has_b_frames < 4) |
763 | 36 | return sti->nb_decoded_frames >= 18; | |
764 | else | ||
765 | 152 | return sti->nb_decoded_frames >= 20; | |
766 | } | ||
767 | |||
768 | 36713 | static PacketListEntry *get_next_pkt(AVFormatContext *s, AVStream *st, | |
769 | PacketListEntry *pktl) | ||
770 | { | ||
771 | 36713 | FormatContextInternal *const fci = ff_fc_internal(s); | |
772 | 36713 | FFFormatContext *const si = &fci->fc; | |
773 |
2/2✓ Branch 0 taken 34778 times.
✓ Branch 1 taken 1935 times.
|
36713 | if (pktl->next) |
774 | 34778 | return pktl->next; | |
775 |
2/2✓ Branch 0 taken 1905 times.
✓ Branch 1 taken 30 times.
|
1935 | if (pktl == si->packet_buffer.tail) |
776 | 1905 | return fci->parse_queue.head; | |
777 | 30 | return NULL; | |
778 | } | ||
779 | |||
780 | 522666 | static int64_t select_from_pts_buffer(AVStream *st, int64_t *pts_buffer, int64_t dts) | |
781 | { | ||
782 | 522666 | FFStream *const sti = ffstream(st); | |
783 | 1560757 | int onein_oneout = st->codecpar->codec_id != AV_CODEC_ID_H264 && | |
784 |
4/4✓ Branch 0 taken 515425 times.
✓ Branch 1 taken 7241 times.
✓ Branch 2 taken 514451 times.
✓ Branch 3 taken 974 times.
|
1037117 | st->codecpar->codec_id != AV_CODEC_ID_HEVC && |
785 |
2/2✓ Branch 0 taken 514432 times.
✓ Branch 1 taken 19 times.
|
514451 | st->codecpar->codec_id != AV_CODEC_ID_VVC; |
786 | |||
787 |
2/2✓ Branch 0 taken 8234 times.
✓ Branch 1 taken 514432 times.
|
522666 | if (!onein_oneout) { |
788 | 8234 | int delay = sti->avctx->has_b_frames; | |
789 | |||
790 |
2/2✓ Branch 0 taken 1217 times.
✓ Branch 1 taken 7017 times.
|
8234 | if (dts == AV_NOPTS_VALUE) { |
791 | 1217 | int64_t best_score = INT64_MAX; | |
792 |
2/2✓ Branch 0 taken 1387 times.
✓ Branch 1 taken 1217 times.
|
2604 | for (int i = 0; i < delay; i++) { |
793 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1387 times.
|
1387 | if (sti->pts_reorder_error_count[i]) { |
794 | ✗ | int64_t score = sti->pts_reorder_error[i] / sti->pts_reorder_error_count[i]; | |
795 | ✗ | if (score < best_score) { | |
796 | ✗ | best_score = score; | |
797 | ✗ | dts = pts_buffer[i]; | |
798 | } | ||
799 | } | ||
800 | } | ||
801 | } else { | ||
802 |
2/2✓ Branch 0 taken 11895 times.
✓ Branch 1 taken 7017 times.
|
18912 | for (int i = 0; i < delay; i++) { |
803 |
2/2✓ Branch 0 taken 11098 times.
✓ Branch 1 taken 797 times.
|
11895 | if (pts_buffer[i] != AV_NOPTS_VALUE) { |
804 | 11098 | int64_t diff = FFABS(pts_buffer[i] - dts) | |
805 | 11098 | + (uint64_t)sti->pts_reorder_error[i]; | |
806 | 11098 | diff = FFMAX(diff, sti->pts_reorder_error[i]); | |
807 | 11098 | sti->pts_reorder_error[i] = diff; | |
808 | 11098 | sti->pts_reorder_error_count[i]++; | |
809 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 11095 times.
|
11098 | if (sti->pts_reorder_error_count[i] > 250) { |
810 | 3 | sti->pts_reorder_error[i] >>= 1; | |
811 | 3 | sti->pts_reorder_error_count[i] >>= 1; | |
812 | } | ||
813 | } | ||
814 | } | ||
815 | } | ||
816 | } | ||
817 | |||
818 |
2/2✓ Branch 0 taken 1392 times.
✓ Branch 1 taken 521274 times.
|
522666 | if (dts == AV_NOPTS_VALUE) |
819 | 1392 | dts = pts_buffer[0]; | |
820 | |||
821 | 522666 | return dts; | |
822 | } | ||
823 | |||
824 | /** | ||
825 | * Updates the dts of packets of a stream in pkt_buffer, by re-ordering the pts | ||
826 | * of the packets in a window. | ||
827 | */ | ||
828 | 6130 | static void update_dts_from_pts(AVFormatContext *s, int stream_index, | |
829 | PacketListEntry *pkt_buffer) | ||
830 | { | ||
831 | 6130 | AVStream *const st = s->streams[stream_index]; | |
832 | 6130 | int delay = ffstream(st)->avctx->has_b_frames; | |
833 | |||
834 | int64_t pts_buffer[MAX_REORDER_DELAY+1]; | ||
835 | |||
836 |
2/2✓ Branch 0 taken 104210 times.
✓ Branch 1 taken 6130 times.
|
110340 | for (int i = 0; i < MAX_REORDER_DELAY + 1; i++) |
837 | 104210 | pts_buffer[i] = AV_NOPTS_VALUE; | |
838 | |||
839 |
2/2✓ Branch 1 taken 5514 times.
✓ Branch 2 taken 6130 times.
|
11644 | for (; pkt_buffer; pkt_buffer = get_next_pkt(s, st, pkt_buffer)) { |
840 |
2/2✓ Branch 0 taken 4856 times.
✓ Branch 1 taken 658 times.
|
5514 | if (pkt_buffer->pkt.stream_index != stream_index) |
841 | 4856 | continue; | |
842 | |||
843 |
3/4✓ Branch 0 taken 561 times.
✓ Branch 1 taken 97 times.
✓ Branch 2 taken 561 times.
✗ Branch 3 not taken.
|
658 | if (pkt_buffer->pkt.pts != AV_NOPTS_VALUE && delay <= MAX_REORDER_DELAY) { |
844 | 561 | pts_buffer[0] = pkt_buffer->pkt.pts; | |
845 |
4/4✓ Branch 0 taken 377 times.
✓ Branch 1 taken 396 times.
✓ Branch 2 taken 212 times.
✓ Branch 3 taken 165 times.
|
773 | for (int i = 0; i < delay && pts_buffer[i] > pts_buffer[i + 1]; i++) |
846 | 212 | FFSWAP(int64_t, pts_buffer[i], pts_buffer[i + 1]); | |
847 | |||
848 | 561 | pkt_buffer->pkt.dts = select_from_pts_buffer(st, pts_buffer, pkt_buffer->pkt.dts); | |
849 | } | ||
850 | } | ||
851 | 6130 | } | |
852 | |||
853 | 564154 | static void update_initial_timestamps(AVFormatContext *s, int stream_index, | |
854 | int64_t dts, int64_t pts, AVPacket *pkt) | ||
855 | { | ||
856 | 564154 | FormatContextInternal *const fci = ff_fc_internal(s); | |
857 | 564154 | FFFormatContext *const si = &fci->fc; | |
858 | 564154 | AVStream *const st = s->streams[stream_index]; | |
859 | 564154 | FFStream *const sti = ffstream(st); | |
860 |
2/2✓ Branch 0 taken 182262 times.
✓ Branch 1 taken 381892 times.
|
564154 | PacketListEntry *pktl = si->packet_buffer.head ? si->packet_buffer.head : fci->parse_queue.head; |
861 | |||
862 | uint64_t shift; | ||
863 | |||
864 |
4/4✓ Branch 0 taken 185898 times.
✓ Branch 1 taken 378256 times.
✓ Branch 2 taken 6193 times.
✓ Branch 3 taken 179705 times.
|
564154 | if (sti->first_dts != AV_NOPTS_VALUE || |
865 | 6193 | dts == AV_NOPTS_VALUE || | |
866 |
1/2✓ Branch 0 taken 6193 times.
✗ Branch 1 not taken.
|
6193 | sti->cur_dts == AV_NOPTS_VALUE || |
867 |
1/2✓ Branch 0 taken 6193 times.
✗ Branch 1 not taken.
|
6193 | sti->cur_dts < INT_MIN + RELATIVE_TS_BASE || |
868 |
2/4✓ Branch 0 taken 6193 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6193 times.
|
12386 | dts < INT_MIN + (sti->cur_dts - RELATIVE_TS_BASE) || |
869 | 6193 | is_relative(dts)) | |
870 | 557961 | return; | |
871 | |||
872 | 6193 | sti->first_dts = dts - (sti->cur_dts - RELATIVE_TS_BASE); | |
873 | 6193 | sti->cur_dts = dts; | |
874 | 6193 | shift = (uint64_t)sti->first_dts - RELATIVE_TS_BASE; | |
875 | |||
876 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 6193 times.
|
6193 | if (is_relative(pts)) |
877 | ✗ | pts += shift; | |
878 | |||
879 |
2/2✓ Branch 1 taken 5255 times.
✓ Branch 2 taken 6193 times.
|
11448 | for (PacketListEntry *pktl_it = pktl; pktl_it; pktl_it = get_next_pkt(s, st, pktl_it)) { |
880 |
2/2✓ Branch 0 taken 4785 times.
✓ Branch 1 taken 470 times.
|
5255 | if (pktl_it->pkt.stream_index != stream_index) |
881 | 4785 | continue; | |
882 |
2/2✓ Branch 1 taken 205 times.
✓ Branch 2 taken 265 times.
|
470 | if (is_relative(pktl_it->pkt.pts)) |
883 | 205 | pktl_it->pkt.pts += shift; | |
884 | |||
885 |
2/2✓ Branch 1 taken 233 times.
✓ Branch 2 taken 237 times.
|
470 | if (is_relative(pktl_it->pkt.dts)) |
886 | 233 | pktl_it->pkt.dts += shift; | |
887 | |||
888 |
4/4✓ Branch 0 taken 69 times.
✓ Branch 1 taken 401 times.
✓ Branch 2 taken 41 times.
✓ Branch 3 taken 28 times.
|
470 | if (st->start_time == AV_NOPTS_VALUE && pktl_it->pkt.pts != AV_NOPTS_VALUE) { |
889 | 41 | st->start_time = pktl_it->pkt.pts; | |
890 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 40 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
41 | if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && st->codecpar->sample_rate) |
891 | 1 | st->start_time = av_sat_add64(st->start_time, av_rescale_q(sti->skip_samples, (AVRational){1, st->codecpar->sample_rate}, st->time_base)); | |
892 | } | ||
893 | } | ||
894 | |||
895 |
2/2✓ Branch 1 taken 6112 times.
✓ Branch 2 taken 81 times.
|
6193 | if (has_decode_delay_been_guessed(st)) |
896 | 6112 | update_dts_from_pts(s, stream_index, pktl); | |
897 | |||
898 |
2/2✓ Branch 0 taken 1716 times.
✓ Branch 1 taken 4477 times.
|
6193 | if (st->start_time == AV_NOPTS_VALUE) { |
899 |
3/4✓ Branch 0 taken 1238 times.
✓ Branch 1 taken 478 times.
✓ Branch 2 taken 1238 times.
✗ Branch 3 not taken.
|
1716 | if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO || !(pkt->flags & AV_PKT_FLAG_DISCARD)) { |
900 | 1716 | st->start_time = pts; | |
901 | } | ||
902 |
4/4✓ Branch 0 taken 478 times.
✓ Branch 1 taken 1238 times.
✓ Branch 2 taken 393 times.
✓ Branch 3 taken 85 times.
|
1716 | if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && st->codecpar->sample_rate) |
903 | 393 | st->start_time = av_sat_add64(st->start_time, av_rescale_q(sti->skip_samples, (AVRational){1, st->codecpar->sample_rate}, st->time_base)); | |
904 | } | ||
905 | } | ||
906 | |||
907 | 226077 | static void update_initial_durations(AVFormatContext *s, AVStream *st, | |
908 | int stream_index, int64_t duration) | ||
909 | { | ||
910 | 226077 | FormatContextInternal *const fci = ff_fc_internal(s); | |
911 | 226077 | FFFormatContext *const si = &fci->fc; | |
912 | 226077 | FFStream *const sti = ffstream(st); | |
913 |
2/2✓ Branch 0 taken 178954 times.
✓ Branch 1 taken 47123 times.
|
226077 | PacketListEntry *pktl = si->packet_buffer.head ? si->packet_buffer.head : fci->parse_queue.head; |
914 | 226077 | int64_t cur_dts = RELATIVE_TS_BASE; | |
915 | |||
916 |
2/2✓ Branch 0 taken 121106 times.
✓ Branch 1 taken 104971 times.
|
226077 | if (sti->first_dts != AV_NOPTS_VALUE) { |
917 |
2/2✓ Branch 0 taken 117483 times.
✓ Branch 1 taken 3623 times.
|
121106 | if (sti->update_initial_durations_done) |
918 | 117483 | return; | |
919 | 3623 | sti->update_initial_durations_done = 1; | |
920 | 3623 | cur_dts = sti->first_dts; | |
921 |
1/2✓ Branch 1 taken 5439 times.
✗ Branch 2 not taken.
|
5439 | for (; pktl; pktl = get_next_pkt(s, st, pktl)) { |
922 |
2/2✓ Branch 0 taken 3638 times.
✓ Branch 1 taken 1801 times.
|
5439 | if (pktl->pkt.stream_index == stream_index) { |
923 |
2/2✓ Branch 0 taken 3527 times.
✓ Branch 1 taken 111 times.
|
3638 | if (pktl->pkt.pts != pktl->pkt.dts || |
924 |
2/2✓ Branch 0 taken 15 times.
✓ Branch 1 taken 3512 times.
|
3527 | pktl->pkt.dts != AV_NOPTS_VALUE || |
925 |
1/2✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
|
15 | pktl->pkt.duration) |
926 | break; | ||
927 | 15 | cur_dts -= duration; | |
928 | } | ||
929 | } | ||
930 |
3/4✓ Branch 0 taken 3623 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 33 times.
✓ Branch 3 taken 3590 times.
|
3623 | if (pktl && pktl->pkt.dts != sti->first_dts) { |
931 | 33 | av_log(s, AV_LOG_DEBUG, "first_dts %s not matching first dts %s (pts %s, duration %"PRId64") in the queue\n", | |
932 | 33 | av_ts2str(sti->first_dts), av_ts2str(pktl->pkt.dts), av_ts2str(pktl->pkt.pts), pktl->pkt.duration); | |
933 | 33 | return; | |
934 | } | ||
935 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3590 times.
|
3590 | if (!pktl) { |
936 | ✗ | av_log(s, AV_LOG_DEBUG, "first_dts %s but no packet with dts in the queue\n", av_ts2str(sti->first_dts)); | |
937 | ✗ | return; | |
938 | } | ||
939 |
2/2✓ Branch 0 taken 3569 times.
✓ Branch 1 taken 21 times.
|
3590 | pktl = si->packet_buffer.head ? si->packet_buffer.head : fci->parse_queue.head; |
940 | 3590 | sti->first_dts = cur_dts; | |
941 |
2/2✓ Branch 0 taken 80374 times.
✓ Branch 1 taken 24597 times.
|
104971 | } else if (sti->cur_dts != RELATIVE_TS_BASE) |
942 | 80374 | return; | |
943 | |||
944 |
2/2✓ Branch 1 taken 51666 times.
✓ Branch 2 taken 649 times.
|
52315 | for (; pktl; pktl = get_next_pkt(s, st, pktl)) { |
945 |
2/2✓ Branch 0 taken 23973 times.
✓ Branch 1 taken 27693 times.
|
51666 | if (pktl->pkt.stream_index != stream_index) |
946 | 23973 | continue; | |
947 |
2/2✓ Branch 0 taken 567 times.
✓ Branch 1 taken 27126 times.
|
27693 | if ((pktl->pkt.pts == pktl->pkt.dts || |
948 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 553 times.
|
567 | pktl->pkt.pts == AV_NOPTS_VALUE) && |
949 |
2/2✓ Branch 0 taken 3659 times.
✓ Branch 1 taken 23481 times.
|
27140 | (pktl->pkt.dts == AV_NOPTS_VALUE || |
950 |
2/2✓ Branch 0 taken 178 times.
✓ Branch 1 taken 3481 times.
|
3659 | pktl->pkt.dts == sti->first_dts || |
951 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 176 times.
|
178 | pktl->pkt.dts == RELATIVE_TS_BASE) && |
952 |
2/2✓ Branch 0 taken 155 times.
✓ Branch 1 taken 26809 times.
|
26964 | !pktl->pkt.duration && |
953 |
1/2✓ Branch 1 taken 155 times.
✗ Branch 2 not taken.
|
155 | av_sat_add64(cur_dts, duration) == cur_dts + (uint64_t)duration |
954 | ) { | ||
955 | 155 | pktl->pkt.dts = cur_dts; | |
956 |
2/2✓ Branch 0 taken 139 times.
✓ Branch 1 taken 16 times.
|
155 | if (!sti->avctx->has_b_frames) |
957 | 139 | pktl->pkt.pts = cur_dts; | |
958 | 155 | pktl->pkt.duration = duration; | |
959 | } else | ||
960 | break; | ||
961 | 155 | cur_dts = pktl->pkt.dts + pktl->pkt.duration; | |
962 | } | ||
963 |
2/2✓ Branch 0 taken 649 times.
✓ Branch 1 taken 27538 times.
|
28187 | if (!pktl) |
964 | 649 | sti->cur_dts = cur_dts; | |
965 | } | ||
966 | |||
967 | 569978 | static void compute_pkt_fields(AVFormatContext *s, AVStream *st, | |
968 | AVCodecParserContext *pc, AVPacket *pkt, | ||
969 | int64_t next_dts, int64_t next_pts) | ||
970 | { | ||
971 | 569978 | FormatContextInternal *const fci = ff_fc_internal(s); | |
972 | 569978 | FFFormatContext *const si = &fci->fc; | |
973 | 569978 | FFStream *const sti = ffstream(st); | |
974 | int num, den, presentation_delayed, delay; | ||
975 | int64_t offset; | ||
976 | AVRational duration; | ||
977 | 1676017 | int onein_oneout = st->codecpar->codec_id != AV_CODEC_ID_H264 && | |
978 |
4/4✓ Branch 0 taken 536061 times.
✓ Branch 1 taken 33917 times.
✓ Branch 2 taken 522935 times.
✓ Branch 3 taken 13126 times.
|
1092913 | st->codecpar->codec_id != AV_CODEC_ID_HEVC && |
979 |
2/2✓ Branch 0 taken 519888 times.
✓ Branch 1 taken 3047 times.
|
522935 | st->codecpar->codec_id != AV_CODEC_ID_VVC; |
980 | |||
981 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 569978 times.
|
569978 | if (s->flags & AVFMT_FLAG_NOFILLIN) |
982 | ✗ | return; | |
983 | |||
984 |
4/4✓ Branch 0 taken 243931 times.
✓ Branch 1 taken 326047 times.
✓ Branch 2 taken 73693 times.
✓ Branch 3 taken 170238 times.
|
569978 | if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && pkt->dts != AV_NOPTS_VALUE) { |
985 |
4/4✓ Branch 0 taken 43451 times.
✓ Branch 1 taken 30242 times.
✓ Branch 2 taken 42277 times.
✓ Branch 3 taken 1174 times.
|
73693 | if (pkt->dts == pkt->pts && sti->last_dts_for_order_check != AV_NOPTS_VALUE) { |
986 |
2/2✓ Branch 0 taken 42268 times.
✓ Branch 1 taken 9 times.
|
42277 | if (sti->last_dts_for_order_check <= pkt->dts) { |
987 | 42268 | sti->dts_ordered++; | |
988 | } else { | ||
989 |
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, |
990 | "DTS %"PRIi64" < %"PRIi64" out of order\n", | ||
991 | pkt->dts, | ||
992 | sti->last_dts_for_order_check); | ||
993 | 9 | sti->dts_misordered++; | |
994 | } | ||
995 |
2/2✓ Branch 0 taken 29 times.
✓ Branch 1 taken 42248 times.
|
42277 | if (sti->dts_ordered + sti->dts_misordered > 250) { |
996 | 29 | sti->dts_ordered >>= 1; | |
997 | 29 | sti->dts_misordered >>= 1; | |
998 | } | ||
999 | } | ||
1000 | |||
1001 | 73693 | sti->last_dts_for_order_check = pkt->dts; | |
1002 |
4/4✓ Branch 0 taken 37 times.
✓ Branch 1 taken 73656 times.
✓ Branch 2 taken 20 times.
✓ Branch 3 taken 17 times.
|
73693 | if (sti->dts_ordered < 8 * sti->dts_misordered && pkt->dts == pkt->pts) |
1003 | 20 | pkt->dts = AV_NOPTS_VALUE; | |
1004 | } | ||
1005 | |||
1006 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 569978 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
569978 | if ((s->flags & AVFMT_FLAG_IGNDTS) && pkt->pts != AV_NOPTS_VALUE) |
1007 | ✗ | pkt->dts = AV_NOPTS_VALUE; | |
1008 | |||
1009 |
4/4✓ Branch 0 taken 187033 times.
✓ Branch 1 taken 382945 times.
✓ Branch 2 taken 27765 times.
✓ Branch 3 taken 159268 times.
|
569978 | if (pc && pc->pict_type == AV_PICTURE_TYPE_B |
1010 |
2/2✓ Branch 0 taken 81 times.
✓ Branch 1 taken 27684 times.
|
27765 | && !sti->avctx->has_b_frames) |
1011 | //FIXME Set low_delay = 0 when has_b_frames = 1 | ||
1012 | 81 | sti->avctx->has_b_frames = 1; | |
1013 | |||
1014 | /* do we have a video B-frame ? */ | ||
1015 | 569978 | delay = sti->avctx->has_b_frames; | |
1016 | 569978 | presentation_delayed = 0; | |
1017 | |||
1018 | /* XXX: need has_b_frame, but cannot get it if the codec is | ||
1019 | * not initialized */ | ||
1020 |
4/4✓ Branch 0 taken 46631 times.
✓ Branch 1 taken 523347 times.
✓ Branch 2 taken 42601 times.
✓ Branch 3 taken 4030 times.
|
569978 | if (delay && |
1021 |
2/2✓ Branch 0 taken 14836 times.
✓ Branch 1 taken 27765 times.
|
42601 | pc && pc->pict_type != AV_PICTURE_TYPE_B) |
1022 | 14836 | presentation_delayed = 1; | |
1023 | |||
1024 |
4/4✓ Branch 0 taken 340276 times.
✓ Branch 1 taken 229702 times.
✓ Branch 2 taken 167860 times.
✓ Branch 3 taken 172416 times.
|
569978 | if (pkt->pts != AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE && |
1025 |
3/4✓ Branch 0 taken 27443 times.
✓ Branch 1 taken 140417 times.
✓ Branch 2 taken 27443 times.
✗ Branch 3 not taken.
|
167860 | st->pts_wrap_bits < 63 && pkt->dts > INT64_MIN + (1LL << st->pts_wrap_bits) && |
1026 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 27443 times.
|
27443 | pkt->dts - (1LL << (st->pts_wrap_bits - 1)) > pkt->pts) { |
1027 | ✗ | if (is_relative(sti->cur_dts) || pkt->dts - (1LL<<(st->pts_wrap_bits - 1)) > sti->cur_dts) { | |
1028 | ✗ | pkt->dts -= 1LL << st->pts_wrap_bits; | |
1029 | } else | ||
1030 | ✗ | pkt->pts += 1LL << st->pts_wrap_bits; | |
1031 | } | ||
1032 | |||
1033 | /* Some MPEG-2 in MPEG-PS lack dts (issue #171 / input_file.mpg). | ||
1034 | * We take the conservative approach and discard both. | ||
1035 | * Note: If this is misbehaving for an H.264 file, then possibly | ||
1036 | * presentation_delayed is not set correctly. */ | ||
1037 |
4/4✓ Branch 0 taken 30084 times.
✓ Branch 1 taken 539894 times.
✓ Branch 2 taken 24945 times.
✓ Branch 3 taken 5139 times.
|
569978 | if (delay == 1 && pkt->dts == pkt->pts && |
1038 |
4/4✓ Branch 0 taken 6134 times.
✓ Branch 1 taken 18811 times.
✓ Branch 2 taken 628 times.
✓ Branch 3 taken 5506 times.
|
24945 | pkt->dts != AV_NOPTS_VALUE && presentation_delayed) { |
1039 | 628 | av_log(s, AV_LOG_DEBUG, "invalid dts/pts combination %"PRIi64"\n", pkt->dts); | |
1040 |
2/2✓ Branch 0 taken 293 times.
✓ Branch 1 taken 335 times.
|
628 | if ( strcmp(s->iformat->name, "mov,mp4,m4a,3gp,3g2,mj2") |
1041 |
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 |
1042 | 22 | pkt->dts = AV_NOPTS_VALUE; | |
1043 | } | ||
1044 | |||
1045 | 569978 | duration = av_mul_q((AVRational) {pkt->duration, 1}, st->time_base); | |
1046 |
2/2✓ Branch 0 taken 318880 times.
✓ Branch 1 taken 251098 times.
|
569978 | if (pkt->duration <= 0) { |
1047 | 318880 | compute_frame_duration(s, &num, &den, st, pc, pkt); | |
1048 |
3/4✓ Branch 0 taken 309589 times.
✓ Branch 1 taken 9291 times.
✓ Branch 2 taken 309589 times.
✗ Branch 3 not taken.
|
318880 | if (den && num) { |
1049 | 309589 | duration = (AVRational) {num, den}; | |
1050 | 309589 | pkt->duration = av_rescale_rnd(1, | |
1051 | 309589 | num * (int64_t) st->time_base.den, | |
1052 | 309589 | den * (int64_t) st->time_base.num, | |
1053 | AV_ROUND_DOWN); | ||
1054 | } | ||
1055 | } | ||
1056 | |||
1057 |
6/6✓ Branch 0 taken 557865 times.
✓ Branch 1 taken 12113 times.
✓ Branch 2 taken 378911 times.
✓ Branch 3 taken 178954 times.
✓ Branch 4 taken 47123 times.
✓ Branch 5 taken 331788 times.
|
569978 | if (pkt->duration > 0 && (si->packet_buffer.head || fci->parse_queue.head)) |
1058 | 226077 | update_initial_durations(s, st, pkt->stream_index, pkt->duration); | |
1059 | |||
1060 | /* Correct timestamps with byte offset if demuxers only have timestamps | ||
1061 | * on packet boundaries */ | ||
1062 |
5/6✓ Branch 0 taken 187033 times.
✓ Branch 1 taken 382945 times.
✓ Branch 2 taken 960 times.
✓ Branch 3 taken 186073 times.
✓ Branch 4 taken 960 times.
✗ Branch 5 not taken.
|
569978 | if (pc && sti->need_parsing == AVSTREAM_PARSE_TIMESTAMPS && pkt->size) { |
1063 | /* this will estimate bitrate based on this frame's duration and size */ | ||
1064 | 960 | offset = av_rescale(pc->offset, pkt->duration, pkt->size); | |
1065 |
2/2✓ Branch 0 taken 575 times.
✓ Branch 1 taken 385 times.
|
960 | if (pkt->pts != AV_NOPTS_VALUE) |
1066 | 575 | pkt->pts += offset; | |
1067 |
2/2✓ Branch 0 taken 121 times.
✓ Branch 1 taken 839 times.
|
960 | if (pkt->dts != AV_NOPTS_VALUE) |
1068 | 121 | pkt->dts += offset; | |
1069 | } | ||
1070 | |||
1071 | /* This may be redundant, but it should not hurt. */ | ||
1072 |
2/2✓ Branch 0 taken 198212 times.
✓ Branch 1 taken 371766 times.
|
569978 | if (pkt->dts != AV_NOPTS_VALUE && |
1073 |
2/2✓ Branch 0 taken 167838 times.
✓ Branch 1 taken 30374 times.
|
198212 | pkt->pts != AV_NOPTS_VALUE && |
1074 |
2/2✓ Branch 0 taken 5158 times.
✓ Branch 1 taken 162680 times.
|
167838 | pkt->pts > pkt->dts) |
1075 | 5158 | presentation_delayed = 1; | |
1076 | |||
1077 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 569978 times.
|
569978 | if (s->debug & FF_FDEBUG_TS) |
1078 | ✗ | av_log(s, AV_LOG_DEBUG, | |
1079 | "IN delayed:%d pts:%s, dts:%s cur_dts:%s st:%d pc:%p duration:%"PRId64" delay:%d onein_oneout:%d\n", | ||
1080 | ✗ | presentation_delayed, av_ts2str(pkt->pts), av_ts2str(pkt->dts), av_ts2str(sti->cur_dts), | |
1081 | pkt->stream_index, pc, pkt->duration, delay, onein_oneout); | ||
1082 | |||
1083 | /* Interpolate PTS and DTS if they are not present. We skip H264 | ||
1084 | * currently because delay and has_b_frames are not reliably set. */ | ||
1085 |
8/8✓ Branch 0 taken 46631 times.
✓ Branch 1 taken 523347 times.
✓ Branch 2 taken 30084 times.
✓ Branch 3 taken 16547 times.
✓ Branch 4 taken 26631 times.
✓ Branch 5 taken 3453 times.
✓ Branch 6 taken 516448 times.
✓ Branch 7 taken 33530 times.
|
569978 | if ((delay == 0 || (delay == 1 && pc)) && |
1086 | onein_oneout) { | ||
1087 |
2/2✓ Branch 0 taken 5509 times.
✓ Branch 1 taken 510939 times.
|
516448 | if (presentation_delayed) { |
1088 | /* DTS = decompression timestamp */ | ||
1089 | /* PTS = presentation timestamp */ | ||
1090 |
2/2✓ Branch 0 taken 2850 times.
✓ Branch 1 taken 2659 times.
|
5509 | if (pkt->dts == AV_NOPTS_VALUE) |
1091 | 2850 | pkt->dts = sti->last_IP_pts; | |
1092 | 5509 | update_initial_timestamps(s, pkt->stream_index, pkt->dts, pkt->pts, pkt); | |
1093 |
2/2✓ Branch 0 taken 2512 times.
✓ Branch 1 taken 2997 times.
|
5509 | if (pkt->dts == AV_NOPTS_VALUE) |
1094 | 2512 | pkt->dts = sti->cur_dts; | |
1095 | |||
1096 | /* This is tricky: the dts must be incremented by the duration | ||
1097 | * of the frame we are displaying, i.e. the last I- or P-frame. */ | ||
1098 |
3/4✓ Branch 0 taken 237 times.
✓ Branch 1 taken 5272 times.
✓ Branch 2 taken 237 times.
✗ Branch 3 not taken.
|
5509 | if (sti->last_IP_duration == 0 && (uint64_t)pkt->duration <= INT32_MAX) |
1099 | 237 | sti->last_IP_duration = pkt->duration; | |
1100 |
1/2✓ Branch 0 taken 5509 times.
✗ Branch 1 not taken.
|
5509 | if (pkt->dts != AV_NOPTS_VALUE) |
1101 | 5509 | sti->cur_dts = av_sat_add64(pkt->dts, sti->last_IP_duration); | |
1102 |
1/2✓ Branch 0 taken 5509 times.
✗ Branch 1 not taken.
|
5509 | if (pkt->dts != AV_NOPTS_VALUE && |
1103 |
2/2✓ Branch 0 taken 3279 times.
✓ Branch 1 taken 2230 times.
|
5509 | pkt->pts == AV_NOPTS_VALUE && |
1104 |
2/2✓ Branch 0 taken 3277 times.
✓ Branch 1 taken 2 times.
|
3279 | sti->last_IP_duration > 0 && |
1105 |
4/4✓ Branch 0 taken 784 times.
✓ Branch 1 taken 2493 times.
✓ Branch 2 taken 778 times.
✓ Branch 3 taken 6 times.
|
3277 | ((uint64_t)sti->cur_dts - (uint64_t)next_dts + 1) <= 2 && |
1106 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 767 times.
|
778 | next_dts != next_pts && |
1107 | next_pts != AV_NOPTS_VALUE) | ||
1108 | 11 | pkt->pts = next_dts; | |
1109 | |||
1110 |
1/2✓ Branch 0 taken 5509 times.
✗ Branch 1 not taken.
|
5509 | if ((uint64_t)pkt->duration <= INT32_MAX) |
1111 | 5509 | sti->last_IP_duration = pkt->duration; | |
1112 | 5509 | sti->last_IP_pts = pkt->pts; | |
1113 | /* Cannot compute PTS if not present (we can compute it only | ||
1114 | * by knowing the future. */ | ||
1115 |
2/2✓ Branch 0 taken 184831 times.
✓ Branch 1 taken 326108 times.
|
510939 | } else if (pkt->pts != AV_NOPTS_VALUE || |
1116 |
2/2✓ Branch 0 taken 155303 times.
✓ Branch 1 taken 29528 times.
|
184831 | pkt->dts != AV_NOPTS_VALUE || |
1117 |
2/2✓ Branch 0 taken 152919 times.
✓ Branch 1 taken 2384 times.
|
155303 | pkt->duration > 0 ) { |
1118 | |||
1119 | /* presentation is not delayed : PTS and DTS are the same */ | ||
1120 |
2/2✓ Branch 0 taken 182447 times.
✓ Branch 1 taken 326108 times.
|
508555 | if (pkt->pts == AV_NOPTS_VALUE) |
1121 | 182447 | pkt->pts = pkt->dts; | |
1122 | 508555 | update_initial_timestamps(s, pkt->stream_index, pkt->pts, | |
1123 | pkt->pts, pkt); | ||
1124 |
2/2✓ Branch 0 taken 152919 times.
✓ Branch 1 taken 355636 times.
|
508555 | if (pkt->pts == AV_NOPTS_VALUE) |
1125 | 152919 | pkt->pts = sti->cur_dts; | |
1126 | 508555 | pkt->dts = pkt->pts; | |
1127 |
3/4✓ Branch 0 taken 508555 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 508547 times.
✓ Branch 3 taken 8 times.
|
508555 | if (pkt->pts != AV_NOPTS_VALUE && duration.num >= 0) |
1128 | 508547 | sti->cur_dts = av_add_stable(st->time_base, pkt->pts, duration, 1); | |
1129 | } | ||
1130 | } | ||
1131 | |||
1132 |
3/4✓ Branch 0 taken 522734 times.
✓ Branch 1 taken 47244 times.
✓ Branch 2 taken 522734 times.
✗ Branch 3 not taken.
|
569978 | if (pkt->pts != AV_NOPTS_VALUE && delay <= MAX_REORDER_DELAY) { |
1133 | 522734 | sti->pts_buffer[0] = pkt->pts; | |
1134 |
4/4✓ Branch 0 taken 22083 times.
✓ Branch 1 taken 517438 times.
✓ Branch 2 taken 16787 times.
✓ Branch 3 taken 5296 times.
|
539521 | for (int i = 0; i < delay && sti->pts_buffer[i] > sti->pts_buffer[i + 1]; i++) |
1135 | 16787 | FFSWAP(int64_t, sti->pts_buffer[i], sti->pts_buffer[i + 1]); | |
1136 | |||
1137 |
2/2✓ Branch 1 taken 522105 times.
✓ Branch 2 taken 629 times.
|
522734 | if (has_decode_delay_been_guessed(st)) |
1138 | 522105 | pkt->dts = select_from_pts_buffer(st, sti->pts_buffer, pkt->dts); | |
1139 | } | ||
1140 | // We skipped it above so we try here. | ||
1141 |
2/2✓ Branch 0 taken 50090 times.
✓ Branch 1 taken 519888 times.
|
569978 | if (!onein_oneout) |
1142 | // This should happen on the first packet | ||
1143 | 50090 | update_initial_timestamps(s, pkt->stream_index, pkt->dts, pkt->pts, pkt); | |
1144 |
2/2✓ Branch 0 taken 8014 times.
✓ Branch 1 taken 561964 times.
|
569978 | if (pkt->dts > sti->cur_dts) |
1145 | 8014 | sti->cur_dts = pkt->dts; | |
1146 | |||
1147 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 569978 times.
|
569978 | if (s->debug & FF_FDEBUG_TS) |
1148 | ✗ | av_log(s, AV_LOG_DEBUG, "OUTdelayed:%d/%d pts:%s, dts:%s cur_dts:%s st:%d (%d)\n", | |
1149 | ✗ | presentation_delayed, delay, av_ts2str(pkt->pts), av_ts2str(pkt->dts), av_ts2str(sti->cur_dts), st->index, st->id); | |
1150 | |||
1151 | /* update flags */ | ||
1152 |
4/4✓ Branch 0 taken 569893 times.
✓ Branch 1 taken 85 times.
✓ Branch 3 taken 373943 times.
✓ Branch 4 taken 195950 times.
|
569978 | if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA || ff_is_intra_only(st->codecpar->codec_id)) |
1153 | 374028 | pkt->flags |= AV_PKT_FLAG_KEY; | |
1154 | } | ||
1155 | |||
1156 | /** | ||
1157 | * Parse a packet, add all split parts to parse_queue. | ||
1158 | * | ||
1159 | * @param pkt Packet to parse; must not be NULL. | ||
1160 | * @param flush Indicates whether to flush. If set, pkt must be blank. | ||
1161 | */ | ||
1162 | 701473 | static int parse_packet(AVFormatContext *s, AVPacket *pkt, | |
1163 | int stream_index, int flush) | ||
1164 | { | ||
1165 | 701473 | FormatContextInternal *const fci = ff_fc_internal(s); | |
1166 | 701473 | FFFormatContext *const si = &fci->fc; | |
1167 | 701473 | AVPacket *out_pkt = si->parse_pkt; | |
1168 | 701473 | AVStream *st = s->streams[stream_index]; | |
1169 | 701473 | FFStream *const sti = ffstream(st); | |
1170 | 701473 | const uint8_t *data = pkt->data; | |
1171 | 701473 | int size = pkt->size; | |
1172 | 701473 | int ret = 0, got_output = flush; | |
1173 | |||
1174 |
5/6✓ Branch 0 taken 2244 times.
✓ Branch 1 taken 699229 times.
✓ Branch 2 taken 164 times.
✓ Branch 3 taken 2080 times.
✓ Branch 4 taken 164 times.
✗ Branch 5 not taken.
|
701473 | if (!size && !flush && sti->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) { |
1175 | // preserve 0-size sync packets | ||
1176 | 164 | compute_pkt_fields(s, st, sti->parser, pkt, pkt->dts, pkt->pts); | |
1177 | |||
1178 | // Theora has valid 0-sized packets that need to be output | ||
1179 |
2/2✓ Branch 0 taken 148 times.
✓ Branch 1 taken 16 times.
|
164 | if (st->codecpar->codec_id == AV_CODEC_ID_THEORA) { |
1180 | 148 | ret = avpriv_packet_list_put(&fci->parse_queue, | |
1181 | pkt, NULL, 0); | ||
1182 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 148 times.
|
148 | if (ret < 0) |
1183 | ✗ | goto fail; | |
1184 | } | ||
1185 | } | ||
1186 | |||
1187 |
6/6✓ Branch 0 taken 815398 times.
✓ Branch 1 taken 704717 times.
✓ Branch 2 taken 5324 times.
✓ Branch 3 taken 699393 times.
✓ Branch 4 taken 3244 times.
✓ Branch 5 taken 2080 times.
|
1520115 | while (size > 0 || (flush && got_output)) { |
1188 | 818642 | int64_t next_pts = pkt->pts; | |
1189 | 818642 | int64_t next_dts = pkt->dts; | |
1190 | int len; | ||
1191 | |||
1192 | 818642 | len = av_parser_parse2(sti->parser, sti->avctx, | |
1193 | &out_pkt->data, &out_pkt->size, data, size, | ||
1194 | pkt->pts, pkt->dts, pkt->pos); | ||
1195 | |||
1196 | 818642 | pkt->pts = pkt->dts = AV_NOPTS_VALUE; | |
1197 | 818642 | pkt->pos = -1; | |
1198 | /* increment read pointer */ | ||
1199 | av_assert1(data || !len); | ||
1200 |
2/2✓ Branch 0 taken 805739 times.
✓ Branch 1 taken 12903 times.
|
818642 | data = len ? data + len : data; |
1201 | 818642 | size -= len; | |
1202 | |||
1203 | 818642 | got_output = !!out_pkt->size; | |
1204 | |||
1205 |
2/2✓ Branch 0 taken 631773 times.
✓ Branch 1 taken 186869 times.
|
818642 | if (!out_pkt->size) |
1206 | 631773 | continue; | |
1207 | |||
1208 |
4/4✓ Branch 0 taken 185705 times.
✓ Branch 1 taken 1164 times.
✓ Branch 2 taken 69189 times.
✓ Branch 3 taken 116516 times.
|
186869 | if (pkt->buf && out_pkt->data == pkt->data) { |
1209 | /* reference pkt->buf only when out_pkt->data is guaranteed to point | ||
1210 | * to data in it and not in the parser's internal buffer. */ | ||
1211 | /* XXX: Ensure this is the case with all parsers when sti->parser->flags | ||
1212 | * is PARSER_FLAG_COMPLETE_FRAMES and check for that instead? */ | ||
1213 | 69189 | out_pkt->buf = av_buffer_ref(pkt->buf); | |
1214 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 69189 times.
|
69189 | if (!out_pkt->buf) { |
1215 | ✗ | ret = AVERROR(ENOMEM); | |
1216 | ✗ | goto fail; | |
1217 | } | ||
1218 | } else { | ||
1219 | 117680 | ret = av_packet_make_refcounted(out_pkt); | |
1220 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 117680 times.
|
117680 | if (ret < 0) |
1221 | ✗ | goto fail; | |
1222 | } | ||
1223 | |||
1224 |
2/2✓ Branch 0 taken 9159 times.
✓ Branch 1 taken 177710 times.
|
186869 | if (pkt->side_data) { |
1225 | 9159 | out_pkt->side_data = pkt->side_data; | |
1226 | 9159 | out_pkt->side_data_elems = pkt->side_data_elems; | |
1227 | 9159 | pkt->side_data = NULL; | |
1228 | 9159 | pkt->side_data_elems = 0; | |
1229 | } | ||
1230 | |||
1231 | /* set the duration */ | ||
1232 |
2/2✓ Branch 0 taken 49387 times.
✓ Branch 1 taken 137482 times.
|
186869 | out_pkt->duration = (sti->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) ? pkt->duration : 0; |
1233 |
2/2✓ Branch 0 taken 108872 times.
✓ Branch 1 taken 77997 times.
|
186869 | if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { |
1234 |
2/2✓ Branch 0 taken 108766 times.
✓ Branch 1 taken 106 times.
|
108872 | if (sti->avctx->sample_rate > 0) { |
1235 | 108766 | out_pkt->duration = | |
1236 | 108766 | av_rescale_q_rnd(sti->parser->duration, | |
1237 | 108766 | (AVRational) { 1, sti->avctx->sample_rate }, | |
1238 | st->time_base, | ||
1239 | AV_ROUND_DOWN); | ||
1240 | } | ||
1241 |
2/2✓ Branch 0 taken 1822 times.
✓ Branch 1 taken 76175 times.
|
77997 | } else if (st->codecpar->codec_id == AV_CODEC_ID_GIF) { |
1242 |
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 && |
1243 |
1/2✓ Branch 0 taken 1822 times.
✗ Branch 1 not taken.
|
1822 | sti->parser->duration) { |
1244 | 1822 | out_pkt->duration = sti->parser->duration; | |
1245 | } | ||
1246 | } | ||
1247 | |||
1248 | 186869 | out_pkt->stream_index = st->index; | |
1249 | 186869 | out_pkt->pts = sti->parser->pts; | |
1250 | 186869 | out_pkt->dts = sti->parser->dts; | |
1251 | 186869 | out_pkt->pos = sti->parser->pos; | |
1252 | 186869 | out_pkt->flags |= pkt->flags & (AV_PKT_FLAG_DISCARD | AV_PKT_FLAG_CORRUPT); | |
1253 | |||
1254 |
2/2✓ Branch 0 taken 114654 times.
✓ Branch 1 taken 72215 times.
|
186869 | if (sti->need_parsing == AVSTREAM_PARSE_FULL_RAW) |
1255 | 114654 | out_pkt->pos = sti->parser->frame_offset; | |
1256 | |||
1257 |
2/2✓ Branch 0 taken 175087 times.
✓ Branch 1 taken 11782 times.
|
186869 | if (sti->parser->key_frame == 1 || |
1258 |
2/2✓ Branch 0 taken 93680 times.
✓ Branch 1 taken 81407 times.
|
175087 | (sti->parser->key_frame == -1 && |
1259 |
2/2✓ Branch 0 taken 81804 times.
✓ Branch 1 taken 11876 times.
|
93680 | sti->parser->pict_type == AV_PICTURE_TYPE_I)) |
1260 | 93586 | out_pkt->flags |= AV_PKT_FLAG_KEY; | |
1261 | |||
1262 |
6/6✓ Branch 0 taken 93680 times.
✓ Branch 1 taken 93189 times.
✓ Branch 2 taken 317 times.
✓ Branch 3 taken 93363 times.
✓ Branch 4 taken 288 times.
✓ Branch 5 taken 29 times.
|
186869 | if (sti->parser->key_frame == -1 && sti->parser->pict_type ==AV_PICTURE_TYPE_NONE && (pkt->flags&AV_PKT_FLAG_KEY)) |
1263 | 288 | out_pkt->flags |= AV_PKT_FLAG_KEY; | |
1264 | |||
1265 | 186869 | compute_pkt_fields(s, st, sti->parser, out_pkt, next_dts, next_pts); | |
1266 | |||
1267 | 186869 | ret = avpriv_packet_list_put(&fci->parse_queue, | |
1268 | out_pkt, NULL, 0); | ||
1269 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 186869 times.
|
186869 | if (ret < 0) |
1270 | ✗ | goto fail; | |
1271 | } | ||
1272 | |||
1273 | /* end of the stream => close and free the parser */ | ||
1274 |
2/2✓ Branch 0 taken 699393 times.
✓ Branch 1 taken 2080 times.
|
701473 | if (flush) { |
1275 | 2080 | av_parser_close(sti->parser); | |
1276 | 2080 | sti->parser = NULL; | |
1277 | } | ||
1278 | |||
1279 | 699393 | fail: | |
1280 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 701473 times.
|
701473 | if (ret < 0) |
1281 | ✗ | av_packet_unref(out_pkt); | |
1282 | 701473 | av_packet_unref(pkt); | |
1283 | 701473 | return ret; | |
1284 | } | ||
1285 | |||
1286 | 8774 | static int64_t ts_to_samples(AVStream *st, int64_t ts) | |
1287 | { | ||
1288 | 8774 | return av_rescale(ts, st->time_base.num * st->codecpar->sample_rate, st->time_base.den); | |
1289 | } | ||
1290 | |||
1291 | 8312 | static int codec_close(FFStream *sti) | |
1292 | { | ||
1293 | 8312 | AVCodecContext *avctx_new = NULL; | |
1294 | 8312 | AVCodecParameters *par_tmp = NULL; | |
1295 | 8312 | const AVCodec *new_codec = NULL; | |
1296 | int ret; | ||
1297 | |||
1298 | 8312 | new_codec = | |
1299 | 8312 | (sti->avctx->codec_id != sti->pub.codecpar->codec_id) ? | |
1300 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 8302 times.
|
8312 | avcodec_find_decoder(sti->pub.codecpar->codec_id) : |
1301 | 8302 | sti->avctx->codec; | |
1302 | |||
1303 | 8312 | avctx_new = avcodec_alloc_context3(new_codec); | |
1304 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8312 times.
|
8312 | if (!avctx_new) { |
1305 | ✗ | ret = AVERROR(ENOMEM); | |
1306 | ✗ | goto fail; | |
1307 | } | ||
1308 | |||
1309 | 8312 | par_tmp = avcodec_parameters_alloc(); | |
1310 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8312 times.
|
8312 | if (!par_tmp) { |
1311 | ✗ | ret = AVERROR(ENOMEM); | |
1312 | ✗ | goto fail; | |
1313 | } | ||
1314 | |||
1315 | 8312 | ret = avcodec_parameters_from_context(par_tmp, sti->avctx); | |
1316 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8312 times.
|
8312 | if (ret < 0) |
1317 | ✗ | goto fail; | |
1318 | |||
1319 | 8312 | ret = avcodec_parameters_to_context(avctx_new, par_tmp); | |
1320 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8312 times.
|
8312 | if (ret < 0) |
1321 | ✗ | goto fail; | |
1322 | |||
1323 | 8312 | avctx_new->pkt_timebase = sti->avctx->pkt_timebase; | |
1324 | |||
1325 | 8312 | avcodec_free_context(&sti->avctx); | |
1326 | 8312 | sti->avctx = avctx_new; | |
1327 | |||
1328 | 8312 | avctx_new = NULL; | |
1329 | 8312 | ret = 0; | |
1330 | |||
1331 | 8312 | fail: | |
1332 | 8312 | avcodec_free_context(&avctx_new); | |
1333 | 8312 | avcodec_parameters_free(&par_tmp); | |
1334 | |||
1335 | 8312 | return ret; | |
1336 | } | ||
1337 | |||
1338 | static int extract_extradata(FFFormatContext *si, AVStream *st, const AVPacket *pkt); | ||
1339 | |||
1340 | 574421 | static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) | |
1341 | { | ||
1342 | 574421 | FormatContextInternal *const fci = ff_fc_internal(s); | |
1343 | 574421 | FFFormatContext *const si = &fci->fc; | |
1344 | 574421 | int ret, got_packet = 0; | |
1345 | 574421 | AVDictionary *metadata = NULL; | |
1346 | |||
1347 |
4/4✓ Branch 0 taken 1273945 times.
✓ Branch 1 taken 382945 times.
✓ Branch 2 taken 1088894 times.
✓ Branch 3 taken 185051 times.
|
1656890 | while (!got_packet && !fci->parse_queue.head) { |
1348 | AVStream *st; | ||
1349 | FFStream *sti; | ||
1350 | |||
1351 | /* read next packet */ | ||
1352 | 1088894 | ret = ff_read_packet(s, pkt); | |
1353 |
2/2✓ Branch 0 taken 6425 times.
✓ Branch 1 taken 1082469 times.
|
1088894 | if (ret < 0) { |
1354 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6424 times.
|
6425 | if (ret == AVERROR(EAGAIN)) |
1355 | 1 | return ret; | |
1356 | /* flush the parsers */ | ||
1357 |
2/2✓ Branch 0 taken 7476 times.
✓ Branch 1 taken 6424 times.
|
13900 | for (unsigned i = 0; i < s->nb_streams; i++) { |
1358 | 7476 | AVStream *const st = s->streams[i]; | |
1359 | 7476 | FFStream *const sti = ffstream(st); | |
1360 |
4/4✓ Branch 0 taken 2748 times.
✓ Branch 1 taken 4728 times.
✓ Branch 2 taken 2080 times.
✓ Branch 3 taken 668 times.
|
7476 | if (sti->parser && sti->need_parsing) |
1361 | 2080 | parse_packet(s, pkt, st->index, 1); | |
1362 | } | ||
1363 | /* all remaining packets are now in parse_queue => | ||
1364 | * really terminate parsing */ | ||
1365 | 6424 | break; | |
1366 | } | ||
1367 | 1082469 | ret = 0; | |
1368 | 1082469 | st = s->streams[pkt->stream_index]; | |
1369 | 1082469 | sti = ffstream(st); | |
1370 | |||
1371 | 1082469 | st->event_flags |= AVSTREAM_EVENT_FLAG_NEW_PACKETS; | |
1372 | |||
1373 | /* update context if required */ | ||
1374 |
2/2✓ Branch 0 taken 203 times.
✓ Branch 1 taken 1082266 times.
|
1082469 | if (sti->need_context_update) { |
1375 |
2/2✓ Branch 1 taken 15 times.
✓ Branch 2 taken 188 times.
|
203 | if (avcodec_is_open(sti->avctx)) { |
1376 | 15 | av_log(s, AV_LOG_DEBUG, "Demuxer context update while decoder is open, closing and trying to re-open\n"); | |
1377 | 15 | ret = codec_close(sti); | |
1378 | 15 | sti->info->found_decoder = 0; | |
1379 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
|
15 | if (ret < 0) |
1380 | ✗ | return ret; | |
1381 | } | ||
1382 | |||
1383 | /* close parser, because it depends on the codec */ | ||
1384 |
4/4✓ Branch 0 taken 15 times.
✓ Branch 1 taken 188 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 5 times.
|
203 | if (sti->parser && sti->avctx->codec_id != st->codecpar->codec_id) { |
1385 | 10 | av_parser_close(sti->parser); | |
1386 | 10 | sti->parser = NULL; | |
1387 | } | ||
1388 | |||
1389 | 203 | ret = avcodec_parameters_to_context(sti->avctx, st->codecpar); | |
1390 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 203 times.
|
203 | if (ret < 0) { |
1391 | ✗ | av_packet_unref(pkt); | |
1392 | ✗ | return ret; | |
1393 | } | ||
1394 | |||
1395 |
2/2✓ Branch 0 taken 154 times.
✓ Branch 1 taken 49 times.
|
203 | if (!sti->avctx->extradata) { |
1396 | 154 | sti->extract_extradata.inited = 0; | |
1397 | |||
1398 | 154 | ret = extract_extradata(si, st, pkt); | |
1399 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 154 times.
|
154 | if (ret < 0) { |
1400 | ✗ | av_packet_unref(pkt); | |
1401 | ✗ | return ret; | |
1402 | } | ||
1403 | } | ||
1404 | |||
1405 | 203 | sti->codec_desc = avcodec_descriptor_get(sti->avctx->codec_id); | |
1406 | |||
1407 | 203 | sti->need_context_update = 0; | |
1408 | } | ||
1409 | |||
1410 |
2/2✓ Branch 0 taken 337672 times.
✓ Branch 1 taken 744797 times.
|
1082469 | if (pkt->pts != AV_NOPTS_VALUE && |
1411 |
2/2✓ Branch 0 taken 168874 times.
✓ Branch 1 taken 168798 times.
|
337672 | pkt->dts != AV_NOPTS_VALUE && |
1412 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 168874 times.
|
168874 | pkt->pts < pkt->dts) { |
1413 | ✗ | av_log(s, AV_LOG_WARNING, | |
1414 | "Invalid timestamps stream=%d, pts=%s, dts=%s, size=%d\n", | ||
1415 | pkt->stream_index, | ||
1416 | ✗ | av_ts2str(pkt->pts), | |
1417 | ✗ | av_ts2str(pkt->dts), | |
1418 | pkt->size); | ||
1419 | } | ||
1420 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1082469 times.
|
1082469 | if (s->debug & FF_FDEBUG_TS) |
1421 | ✗ | av_log(s, AV_LOG_DEBUG, | |
1422 | "ff_read_packet stream=%d, pts=%s, dts=%s, size=%d, duration=%"PRId64", flags=%d\n", | ||
1423 | pkt->stream_index, | ||
1424 | ✗ | av_ts2str(pkt->pts), | |
1425 | ✗ | av_ts2str(pkt->dts), | |
1426 | pkt->size, pkt->duration, pkt->flags); | ||
1427 | |||
1428 |
5/6✓ Branch 0 taken 700685 times.
✓ Branch 1 taken 381784 times.
✓ Branch 2 taken 2775 times.
✓ Branch 3 taken 697910 times.
✓ Branch 4 taken 2775 times.
✗ Branch 5 not taken.
|
1082469 | if (sti->need_parsing && !sti->parser && !(s->flags & AVFMT_FLAG_NOPARSE)) { |
1429 | 2775 | sti->parser = av_parser_init(st->codecpar->codec_id); | |
1430 |
2/2✓ Branch 0 taken 1161 times.
✓ Branch 1 taken 1614 times.
|
2775 | if (!sti->parser) { |
1431 | 1161 | av_log(s, AV_LOG_VERBOSE, "parser not found for codec " | |
1432 | "%s, packets or times may be invalid.\n", | ||
1433 | 1161 | avcodec_get_name(st->codecpar->codec_id)); | |
1434 | /* no parser available: just output the raw packets */ | ||
1435 | 1161 | sti->need_parsing = AVSTREAM_PARSE_NONE; | |
1436 |
2/2✓ Branch 0 taken 718 times.
✓ Branch 1 taken 896 times.
|
1614 | } else if (sti->need_parsing == AVSTREAM_PARSE_HEADERS) |
1437 | 718 | sti->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES; | |
1438 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 896 times.
|
896 | else if (sti->need_parsing == AVSTREAM_PARSE_FULL_ONCE) |
1439 | ✗ | sti->parser->flags |= PARSER_FLAG_ONCE; | |
1440 |
2/2✓ Branch 0 taken 472 times.
✓ Branch 1 taken 424 times.
|
896 | else if (sti->need_parsing == AVSTREAM_PARSE_FULL_RAW) |
1441 | 472 | sti->parser->flags |= PARSER_FLAG_USE_CODEC_TS; | |
1442 | } | ||
1443 | |||
1444 |
3/4✓ Branch 0 taken 699524 times.
✓ Branch 1 taken 382945 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 699524 times.
|
1082469 | if (!sti->need_parsing || !sti->parser) { |
1445 | /* no parsing needed: we just output the packet as is */ | ||
1446 | 382945 | compute_pkt_fields(s, st, NULL, pkt, AV_NOPTS_VALUE, AV_NOPTS_VALUE); | |
1447 |
2/2✓ Branch 0 taken 93198 times.
✓ Branch 1 taken 289747 times.
|
382945 | if ((s->iformat->flags & AVFMT_GENERIC_INDEX) && |
1448 |
4/4✓ Branch 0 taken 92462 times.
✓ Branch 1 taken 736 times.
✓ Branch 2 taken 92317 times.
✓ Branch 3 taken 145 times.
|
93198 | (pkt->flags & AV_PKT_FLAG_KEY) && pkt->dts != AV_NOPTS_VALUE) { |
1449 | 92317 | ff_reduce_index(s, st->index); | |
1450 | 92317 | av_add_index_entry(st, pkt->pos, pkt->dts, | |
1451 | 0, 0, AVINDEX_KEYFRAME); | ||
1452 | } | ||
1453 | 382945 | got_packet = 1; | |
1454 |
2/2✓ Branch 0 taken 699393 times.
✓ Branch 1 taken 131 times.
|
699524 | } else if (st->discard < AVDISCARD_ALL) { |
1455 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 699393 times.
|
699393 | if ((ret = parse_packet(s, pkt, pkt->stream_index, 0)) < 0) |
1456 | ✗ | return ret; | |
1457 | 699393 | st->codecpar->sample_rate = sti->avctx->sample_rate; | |
1458 | 699393 | st->codecpar->bit_rate = sti->avctx->bit_rate; | |
1459 | 699393 | ret = av_channel_layout_copy(&st->codecpar->ch_layout, &sti->avctx->ch_layout); | |
1460 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 699393 times.
|
699393 | if (ret < 0) |
1461 | ✗ | return ret; | |
1462 | 699393 | st->codecpar->codec_id = sti->avctx->codec_id; | |
1463 | } else { | ||
1464 | /* free packet */ | ||
1465 | 131 | av_packet_unref(pkt); | |
1466 | } | ||
1467 |
2/2✓ Branch 0 taken 359552 times.
✓ Branch 1 taken 722917 times.
|
1082469 | if (pkt->flags & AV_PKT_FLAG_KEY) |
1468 | 359552 | sti->skip_to_keyframe = 0; | |
1469 |
2/2✓ Branch 0 taken 85 times.
✓ Branch 1 taken 1082384 times.
|
1082469 | if (sti->skip_to_keyframe) { |
1470 | 85 | av_packet_unref(pkt); | |
1471 | 85 | got_packet = 0; | |
1472 | } | ||
1473 | } | ||
1474 | |||
1475 |
4/4✓ Branch 0 taken 191475 times.
✓ Branch 1 taken 382945 times.
✓ Branch 2 taken 185958 times.
✓ Branch 3 taken 5517 times.
|
574420 | if (!got_packet && fci->parse_queue.head) |
1476 | 185958 | ret = avpriv_packet_list_get(&fci->parse_queue, pkt); | |
1477 | |||
1478 |
2/2✓ Branch 0 taken 568903 times.
✓ Branch 1 taken 5517 times.
|
574420 | if (ret >= 0) { |
1479 | 568903 | AVStream *const st = s->streams[pkt->stream_index]; | |
1480 | 568903 | FFStream *const sti = ffstream(st); | |
1481 | 568903 | int discard_padding = 0; | |
1482 |
3/4✓ Branch 0 taken 4387 times.
✓ Branch 1 taken 564516 times.
✓ Branch 2 taken 4387 times.
✗ Branch 3 not taken.
|
568903 | if (sti->first_discard_sample && pkt->pts != AV_NOPTS_VALUE) { |
1483 |
2/2✓ Branch 1 taken 2632 times.
✓ Branch 2 taken 1755 times.
|
4387 | int64_t pts = pkt->pts - (is_relative(pkt->pts) ? RELATIVE_TS_BASE : 0); |
1484 | 4387 | int64_t sample = ts_to_samples(st, pts); | |
1485 | 4387 | int64_t duration = ts_to_samples(st, pkt->duration); | |
1486 | 4387 | int64_t end_sample = sample + duration; | |
1487 |
3/4✓ Branch 0 taken 4387 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
✓ Branch 3 taken 4373 times.
|
4387 | if (duration > 0 && end_sample >= sti->first_discard_sample && |
1488 |
1/2✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
|
14 | sample < sti->last_discard_sample) |
1489 | 14 | discard_padding = FFMIN(end_sample - sti->first_discard_sample, duration); | |
1490 | } | ||
1491 |
6/6✓ Branch 0 taken 4387 times.
✓ Branch 1 taken 564516 times.
✓ Branch 2 taken 4371 times.
✓ Branch 3 taken 16 times.
✓ Branch 4 taken 20 times.
✓ Branch 5 taken 4351 times.
|
568903 | if (sti->start_skip_samples && (pkt->pts == 0 || pkt->pts == RELATIVE_TS_BASE)) |
1492 | 36 | sti->skip_samples = sti->start_skip_samples; | |
1493 | 568903 | sti->skip_samples = FFMAX(0, sti->skip_samples); | |
1494 |
4/4✓ Branch 0 taken 568815 times.
✓ Branch 1 taken 88 times.
✓ Branch 2 taken 14 times.
✓ Branch 3 taken 568801 times.
|
568903 | if (sti->skip_samples || discard_padding) { |
1495 | 102 | uint8_t *p = av_packet_new_side_data(pkt, AV_PKT_DATA_SKIP_SAMPLES, 10); | |
1496 |
1/2✓ Branch 0 taken 102 times.
✗ Branch 1 not taken.
|
102 | if (p) { |
1497 | 102 | AV_WL32(p, sti->skip_samples); | |
1498 | 102 | AV_WL32(p + 4, discard_padding); | |
1499 | 102 | av_log(s, AV_LOG_DEBUG, "demuxer injecting skip %u / discard %u\n", | |
1500 | 102 | (unsigned)sti->skip_samples, (unsigned)discard_padding); | |
1501 | } | ||
1502 | 102 | sti->skip_samples = 0; | |
1503 | } | ||
1504 | } | ||
1505 | |||
1506 |
2/2✓ Branch 0 taken 7588 times.
✓ Branch 1 taken 566832 times.
|
574420 | if (!fci->metafree) { |
1507 | 7588 | int metaret = av_opt_get_dict_val(s, "metadata", AV_OPT_SEARCH_CHILDREN, &metadata); | |
1508 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7588 times.
|
7588 | if (metadata) { |
1509 | ✗ | s->event_flags |= AVFMT_EVENT_FLAG_METADATA_UPDATED; | |
1510 | ✗ | av_dict_copy(&s->metadata, metadata, 0); | |
1511 | ✗ | av_dict_free(&metadata); | |
1512 | ✗ | av_opt_set_dict_val(s, "metadata", NULL, AV_OPT_SEARCH_CHILDREN); | |
1513 | } | ||
1514 | 7588 | fci->metafree = metaret == AVERROR_OPTION_NOT_FOUND; | |
1515 | } | ||
1516 | |||
1517 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 574420 times.
|
574420 | if (s->debug & FF_FDEBUG_TS) |
1518 | ✗ | av_log(s, AV_LOG_DEBUG, | |
1519 | "read_frame_internal stream=%d, pts=%s, dts=%s, " | ||
1520 | "size=%d, duration=%"PRId64", flags=%d\n", | ||
1521 | pkt->stream_index, | ||
1522 | ✗ | av_ts2str(pkt->pts), | |
1523 | ✗ | av_ts2str(pkt->dts), | |
1524 | pkt->size, pkt->duration, pkt->flags); | ||
1525 | |||
1526 | /* A demuxer might have returned EOF because of an IO error, let's | ||
1527 | * propagate this back to the user. */ | ||
1528 |
5/8✓ Branch 0 taken 5405 times.
✓ Branch 1 taken 569015 times.
✓ Branch 2 taken 5185 times.
✓ Branch 3 taken 220 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 5185 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
574420 | if (ret == AVERROR_EOF && s->pb && s->pb->error < 0 && s->pb->error != AVERROR(EAGAIN)) |
1529 | ✗ | ret = s->pb->error; | |
1530 | |||
1531 | 574420 | return ret; | |
1532 | } | ||
1533 | |||
1534 | 512250 | int av_read_frame(AVFormatContext *s, AVPacket *pkt) | |
1535 | { | ||
1536 | 512250 | FFFormatContext *const si = ffformatcontext(s); | |
1537 | 512250 | const int genpts = s->flags & AVFMT_FLAG_GENPTS; | |
1538 | 512250 | int eof = 0; | |
1539 | int ret; | ||
1540 | AVStream *st; | ||
1541 | |||
1542 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 512250 times.
|
512250 | if (!genpts) { |
1543 | 1024500 | ret = si->packet_buffer.head | |
1544 | 130698 | ? avpriv_packet_list_get(&si->packet_buffer, pkt) | |
1545 |
2/2✓ Branch 0 taken 130698 times.
✓ Branch 1 taken 381552 times.
|
512250 | : read_frame_internal(s, pkt); |
1546 |
2/2✓ Branch 0 taken 4328 times.
✓ Branch 1 taken 507922 times.
|
512250 | if (ret < 0) |
1547 | 4328 | return ret; | |
1548 | 507922 | goto return_packet; | |
1549 | } | ||
1550 | |||
1551 | ✗ | for (;;) { | |
1552 | ✗ | PacketListEntry *pktl = si->packet_buffer.head; | |
1553 | |||
1554 | ✗ | if (pktl) { | |
1555 | ✗ | AVPacket *next_pkt = &pktl->pkt; | |
1556 | |||
1557 | ✗ | if (next_pkt->dts != AV_NOPTS_VALUE) { | |
1558 | ✗ | int wrap_bits = s->streams[next_pkt->stream_index]->pts_wrap_bits; | |
1559 | // last dts seen for this stream. if any of packets following | ||
1560 | // current one had no dts, we will set this to AV_NOPTS_VALUE. | ||
1561 | ✗ | int64_t last_dts = next_pkt->dts; | |
1562 | av_assert2(wrap_bits <= 64); | ||
1563 | ✗ | while (pktl && next_pkt->pts == AV_NOPTS_VALUE) { | |
1564 | ✗ | if (pktl->pkt.stream_index == next_pkt->stream_index && | |
1565 | ✗ | av_compare_mod(next_pkt->dts, pktl->pkt.dts, 2ULL << (wrap_bits - 1)) < 0) { | |
1566 | ✗ | if (av_compare_mod(pktl->pkt.pts, pktl->pkt.dts, 2ULL << (wrap_bits - 1))) { | |
1567 | // not B-frame | ||
1568 | ✗ | next_pkt->pts = pktl->pkt.dts; | |
1569 | } | ||
1570 | ✗ | if (last_dts != AV_NOPTS_VALUE) { | |
1571 | // Once last dts was set to AV_NOPTS_VALUE, we don't change it. | ||
1572 | ✗ | last_dts = pktl->pkt.dts; | |
1573 | } | ||
1574 | } | ||
1575 | ✗ | pktl = pktl->next; | |
1576 | } | ||
1577 | ✗ | if (eof && next_pkt->pts == AV_NOPTS_VALUE && last_dts != AV_NOPTS_VALUE) { | |
1578 | // Fixing the last reference frame had none pts issue (For MXF etc). | ||
1579 | // We only do this when | ||
1580 | // 1. eof. | ||
1581 | // 2. we are not able to resolve a pts value for current packet. | ||
1582 | // 3. the packets for this stream at the end of the files had valid dts. | ||
1583 | ✗ | next_pkt->pts = last_dts + next_pkt->duration; | |
1584 | } | ||
1585 | ✗ | pktl = si->packet_buffer.head; | |
1586 | } | ||
1587 | |||
1588 | /* read packet from packet buffer, if there is data */ | ||
1589 | ✗ | st = s->streams[next_pkt->stream_index]; | |
1590 | ✗ | if (!(next_pkt->pts == AV_NOPTS_VALUE && st->discard < AVDISCARD_ALL && | |
1591 | ✗ | next_pkt->dts != AV_NOPTS_VALUE && !eof)) { | |
1592 | ✗ | ret = avpriv_packet_list_get(&si->packet_buffer, pkt); | |
1593 | ✗ | goto return_packet; | |
1594 | } | ||
1595 | } | ||
1596 | |||
1597 | ✗ | ret = read_frame_internal(s, pkt); | |
1598 | ✗ | if (ret < 0) { | |
1599 | ✗ | if (pktl && ret != AVERROR(EAGAIN)) { | |
1600 | ✗ | eof = 1; | |
1601 | ✗ | continue; | |
1602 | } else | ||
1603 | ✗ | return ret; | |
1604 | } | ||
1605 | |||
1606 | ✗ | ret = avpriv_packet_list_put(&si->packet_buffer, | |
1607 | pkt, NULL, 0); | ||
1608 | ✗ | if (ret < 0) { | |
1609 | ✗ | av_packet_unref(pkt); | |
1610 | ✗ | return ret; | |
1611 | } | ||
1612 | } | ||
1613 | |||
1614 | 507922 | return_packet: | |
1615 | 507922 | st = s->streams[pkt->stream_index]; | |
1616 |
4/4✓ Branch 0 taken 194439 times.
✓ Branch 1 taken 313483 times.
✓ Branch 2 taken 120702 times.
✓ Branch 3 taken 73737 times.
|
507922 | if ((s->iformat->flags & AVFMT_GENERIC_INDEX) && pkt->flags & AV_PKT_FLAG_KEY) { |
1617 | 120702 | ff_reduce_index(s, st->index); | |
1618 | 120702 | av_add_index_entry(st, pkt->pos, pkt->dts, 0, 0, AVINDEX_KEYFRAME); | |
1619 | } | ||
1620 | |||
1621 |
2/2✓ Branch 1 taken 120273 times.
✓ Branch 2 taken 387649 times.
|
507922 | if (is_relative(pkt->dts)) |
1622 | 120273 | pkt->dts -= RELATIVE_TS_BASE; | |
1623 |
2/2✓ Branch 1 taken 118574 times.
✓ Branch 2 taken 389348 times.
|
507922 | if (is_relative(pkt->pts)) |
1624 | 118574 | pkt->pts -= RELATIVE_TS_BASE; | |
1625 | |||
1626 | 507922 | return ret; | |
1627 | } | ||
1628 | |||
1629 | /** | ||
1630 | * Return TRUE if the stream has accurate duration in any stream. | ||
1631 | * | ||
1632 | * @return TRUE if the stream has accurate duration for at least one component. | ||
1633 | */ | ||
1634 | 7511 | static int has_duration(AVFormatContext *ic) | |
1635 | { | ||
1636 |
2/2✓ Branch 0 taken 7807 times.
✓ Branch 1 taken 2434 times.
|
10241 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
1637 | 7807 | const AVStream *const st = ic->streams[i]; | |
1638 |
2/2✓ Branch 0 taken 5077 times.
✓ Branch 1 taken 2730 times.
|
7807 | if (st->duration != AV_NOPTS_VALUE) |
1639 | 5077 | return 1; | |
1640 | } | ||
1641 |
2/2✓ Branch 0 taken 441 times.
✓ Branch 1 taken 1993 times.
|
2434 | if (ic->duration != AV_NOPTS_VALUE) |
1642 | 441 | return 1; | |
1643 | 1993 | return 0; | |
1644 | } | ||
1645 | |||
1646 | /** | ||
1647 | * Estimate the stream timings from the one of each components. | ||
1648 | * | ||
1649 | * Also computes the global bitrate if possible. | ||
1650 | */ | ||
1651 | 13167 | static void update_stream_timings(AVFormatContext *ic) | |
1652 | { | ||
1653 | int64_t start_time, start_time1, start_time_text, end_time, end_time1, end_time_text; | ||
1654 | int64_t duration, duration1, duration_text, filesize; | ||
1655 | |||
1656 | 13167 | start_time = INT64_MAX; | |
1657 | 13167 | start_time_text = INT64_MAX; | |
1658 | 13167 | end_time = INT64_MIN; | |
1659 | 13167 | end_time_text = INT64_MIN; | |
1660 | 13167 | duration = INT64_MIN; | |
1661 | 13167 | duration_text = INT64_MIN; | |
1662 | |||
1663 |
2/2✓ Branch 0 taken 14650 times.
✓ Branch 1 taken 13167 times.
|
27817 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
1664 | 14650 | AVStream *const st = ic->streams[i]; | |
1665 |
2/2✓ Branch 0 taken 14525 times.
✓ Branch 1 taken 125 times.
|
29175 | int is_text = st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE || |
1666 |
2/2✓ Branch 0 taken 151 times.
✓ Branch 1 taken 14374 times.
|
14525 | st->codecpar->codec_type == AVMEDIA_TYPE_DATA; |
1667 | |||
1668 |
3/4✓ Branch 0 taken 11988 times.
✓ Branch 1 taken 2662 times.
✓ Branch 2 taken 11988 times.
✗ Branch 3 not taken.
|
14650 | if (st->start_time != AV_NOPTS_VALUE && st->time_base.den) { |
1669 | 11988 | start_time1 = av_rescale_q(st->start_time, st->time_base, | |
1670 | 11988 | AV_TIME_BASE_Q); | |
1671 |
2/2✓ Branch 0 taken 158 times.
✓ Branch 1 taken 11830 times.
|
11988 | if (is_text) |
1672 | 158 | start_time_text = FFMIN(start_time_text, start_time1); | |
1673 | else | ||
1674 | 11830 | start_time = FFMIN(start_time, start_time1); | |
1675 | 11988 | end_time1 = av_rescale_q_rnd(st->duration, st->time_base, | |
1676 | 11988 | AV_TIME_BASE_Q, | |
1677 | AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX); | ||
1678 |
5/6✓ Branch 0 taken 10584 times.
✓ Branch 1 taken 1404 times.
✓ Branch 2 taken 10555 times.
✓ Branch 3 taken 29 times.
✓ Branch 4 taken 10584 times.
✗ Branch 5 not taken.
|
11988 | if (end_time1 != AV_NOPTS_VALUE && (end_time1 > 0 ? start_time1 <= INT64_MAX - end_time1 : start_time1 >= INT64_MIN - end_time1)) { |
1679 | 10584 | end_time1 += start_time1; | |
1680 |
2/2✓ Branch 0 taken 143 times.
✓ Branch 1 taken 10441 times.
|
10584 | if (is_text) |
1681 | 143 | end_time_text = FFMAX(end_time_text, end_time1); | |
1682 | else | ||
1683 | 10441 | end_time = FFMAX(end_time, end_time1); | |
1684 | } | ||
1685 |
2/2✓ Branch 1 taken 208 times.
✓ Branch 2 taken 11988 times.
|
12196 | for (AVProgram *p = NULL; (p = av_find_program_from_stream(ic, p, i)); ) { |
1686 |
4/4✓ Branch 0 taken 152 times.
✓ Branch 1 taken 56 times.
✓ Branch 2 taken 25 times.
✓ Branch 3 taken 127 times.
|
208 | if (p->start_time == AV_NOPTS_VALUE || p->start_time > start_time1) |
1687 | 81 | p->start_time = start_time1; | |
1688 |
2/2✓ Branch 0 taken 52 times.
✓ Branch 1 taken 156 times.
|
208 | if (p->end_time < end_time1) |
1689 | 52 | p->end_time = end_time1; | |
1690 | } | ||
1691 | } | ||
1692 |
2/2✓ Branch 0 taken 12046 times.
✓ Branch 1 taken 2604 times.
|
14650 | if (st->duration != AV_NOPTS_VALUE) { |
1693 | 12046 | duration1 = av_rescale_q(st->duration, st->time_base, | |
1694 | 12046 | AV_TIME_BASE_Q); | |
1695 |
2/2✓ Branch 0 taken 167 times.
✓ Branch 1 taken 11879 times.
|
12046 | if (is_text) |
1696 | 167 | duration_text = FFMAX(duration_text, duration1); | |
1697 | else | ||
1698 | 11879 | duration = FFMAX(duration, duration1); | |
1699 | } | ||
1700 | } | ||
1701 |
3/6✓ Branch 0 taken 10719 times.
✓ Branch 1 taken 2448 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 10719 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
13167 | if (start_time == INT64_MAX || (start_time > start_time_text && start_time - (uint64_t)start_time_text < AV_TIME_BASE)) |
1702 | 2448 | start_time = start_time_text; | |
1703 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10719 times.
|
10719 | else if (start_time > start_time_text) |
1704 | ✗ | av_log(ic, AV_LOG_VERBOSE, "Ignoring outlier non primary stream starttime %f\n", start_time_text / (float)AV_TIME_BASE); | |
1705 | |||
1706 |
5/6✓ Branch 0 taken 9734 times.
✓ Branch 1 taken 3433 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 9732 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
13167 | if (end_time == INT64_MIN || (end_time < end_time_text && end_time_text - (uint64_t)end_time < AV_TIME_BASE)) |
1707 | 3435 | end_time = end_time_text; | |
1708 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9732 times.
|
9732 | else if (end_time < end_time_text) |
1709 | ✗ | av_log(ic, AV_LOG_VERBOSE, "Ignoring outlier non primary stream endtime %f\n", end_time_text / (float)AV_TIME_BASE); | |
1710 | |||
1711 |
5/6✓ Branch 0 taken 11157 times.
✓ Branch 1 taken 2010 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 11151 times.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
|
13167 | if (duration == INT64_MIN || (duration < duration_text && (uint64_t)duration_text - duration < AV_TIME_BASE)) |
1712 | 2016 | duration = duration_text; | |
1713 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11151 times.
|
11151 | else if (duration < duration_text) |
1714 | ✗ | av_log(ic, AV_LOG_VERBOSE, "Ignoring outlier non primary stream duration %f\n", duration_text / (float)AV_TIME_BASE); | |
1715 | |||
1716 |
2/2✓ Branch 0 taken 10740 times.
✓ Branch 1 taken 2427 times.
|
13167 | if (start_time != INT64_MAX) { |
1717 | 10740 | ic->start_time = start_time; | |
1718 |
2/2✓ Branch 0 taken 9751 times.
✓ Branch 1 taken 989 times.
|
10740 | if (end_time != INT64_MIN) { |
1719 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9751 times.
|
9751 | if (ic->nb_programs > 1) { |
1720 | ✗ | for (unsigned i = 0; i < ic->nb_programs; i++) { | |
1721 | ✗ | AVProgram *const p = ic->programs[i]; | |
1722 | |||
1723 | ✗ | if (p->start_time != AV_NOPTS_VALUE && | |
1724 | ✗ | p->end_time > p->start_time && | |
1725 | ✗ | p->end_time - (uint64_t)p->start_time <= INT64_MAX) | |
1726 | ✗ | duration = FFMAX(duration, p->end_time - p->start_time); | |
1727 | } | ||
1728 |
2/4✓ Branch 0 taken 9751 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9751 times.
✗ Branch 3 not taken.
|
9751 | } else if (end_time >= start_time && end_time - (uint64_t)start_time <= INT64_MAX) { |
1729 | 9751 | duration = FFMAX(duration, end_time - start_time); | |
1730 | } | ||
1731 | } | ||
1732 | } | ||
1733 |
6/6✓ Branch 0 taken 11187 times.
✓ Branch 1 taken 1980 times.
✓ Branch 2 taken 11151 times.
✓ Branch 3 taken 36 times.
✓ Branch 4 taken 5992 times.
✓ Branch 5 taken 5159 times.
|
13167 | if (duration != INT64_MIN && duration > 0 && ic->duration == AV_NOPTS_VALUE) { |
1734 | 5992 | ic->duration = duration; | |
1735 | } | ||
1736 |
5/6✓ Branch 0 taken 7104 times.
✓ Branch 1 taken 6063 times.
✓ Branch 3 taken 7104 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 5984 times.
✓ Branch 6 taken 1120 times.
|
13167 | if (ic->pb && (filesize = avio_size(ic->pb)) > 0 && ic->duration > 0) { |
1737 | /* compute the bitrate */ | ||
1738 | 5984 | double bitrate = (double) filesize * 8.0 * AV_TIME_BASE / | |
1739 | 5984 | (double) ic->duration; | |
1740 |
2/4✓ Branch 0 taken 5984 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5984 times.
✗ Branch 3 not taken.
|
5984 | if (bitrate >= 0 && bitrate <= INT64_MAX) |
1741 | 5984 | ic->bit_rate = bitrate; | |
1742 | } | ||
1743 | 13167 | } | |
1744 | |||
1745 | 5587 | static void fill_all_stream_timings(AVFormatContext *ic) | |
1746 | { | ||
1747 | 5587 | update_stream_timings(ic); | |
1748 |
2/2✓ Branch 0 taken 6255 times.
✓ Branch 1 taken 5587 times.
|
11842 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
1749 | 6255 | AVStream *const st = ic->streams[i]; | |
1750 | |||
1751 |
2/2✓ Branch 0 taken 774 times.
✓ Branch 1 taken 5481 times.
|
6255 | if (st->start_time == AV_NOPTS_VALUE) { |
1752 |
2/2✓ Branch 0 taken 129 times.
✓ Branch 1 taken 645 times.
|
774 | if (ic->start_time != AV_NOPTS_VALUE) |
1753 | 129 | st->start_time = av_rescale_q(ic->start_time, AV_TIME_BASE_Q, | |
1754 | st->time_base); | ||
1755 |
2/2✓ Branch 0 taken 759 times.
✓ Branch 1 taken 15 times.
|
774 | if (ic->duration != AV_NOPTS_VALUE) |
1756 | 759 | st->duration = av_rescale_q(ic->duration, AV_TIME_BASE_Q, | |
1757 | st->time_base); | ||
1758 | } | ||
1759 | } | ||
1760 | 5587 | } | |
1761 | |||
1762 | 1993 | static void estimate_timings_from_bit_rate(AVFormatContext *ic) | |
1763 | { | ||
1764 | 1993 | FFFormatContext *const si = ffformatcontext(ic); | |
1765 | 1993 | int show_warning = 0; | |
1766 | |||
1767 | /* if bit_rate is already set, we believe it */ | ||
1768 |
2/2✓ Branch 0 taken 1958 times.
✓ Branch 1 taken 35 times.
|
1993 | if (ic->bit_rate <= 0) { |
1769 | 1958 | int64_t bit_rate = 0; | |
1770 |
2/2✓ Branch 0 taken 2083 times.
✓ Branch 1 taken 1309 times.
|
3392 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
1771 | 2083 | const AVStream *const st = ic->streams[i]; | |
1772 | 2083 | const FFStream *const sti = cffstream(st); | |
1773 |
4/4✓ Branch 0 taken 1306 times.
✓ Branch 1 taken 777 times.
✓ Branch 2 taken 111 times.
✓ Branch 3 taken 1195 times.
|
2083 | if (st->codecpar->bit_rate <= 0 && sti->avctx->bit_rate > 0) |
1774 | 111 | st->codecpar->bit_rate = sti->avctx->bit_rate; | |
1775 |
2/2✓ Branch 0 taken 888 times.
✓ Branch 1 taken 1195 times.
|
2083 | if (st->codecpar->bit_rate > 0) { |
1776 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 888 times.
|
888 | if (INT64_MAX - st->codecpar->bit_rate < bit_rate) { |
1777 | ✗ | bit_rate = 0; | |
1778 | ✗ | break; | |
1779 | } | ||
1780 | 888 | bit_rate += st->codecpar->bit_rate; | |
1781 |
4/4✓ Branch 0 taken 1027 times.
✓ Branch 1 taken 168 times.
✓ Branch 2 taken 649 times.
✓ Branch 3 taken 378 times.
|
1195 | } else if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && sti->codec_info_nb_frames > 1) { |
1782 | // If we have a videostream with packets but without a bitrate | ||
1783 | // then consider the sum not known | ||
1784 | 649 | bit_rate = 0; | |
1785 | 649 | break; | |
1786 | } | ||
1787 | } | ||
1788 | 1958 | ic->bit_rate = bit_rate; | |
1789 | } | ||
1790 | |||
1791 | /* if duration is already set, we believe it */ | ||
1792 |
1/2✓ Branch 0 taken 1993 times.
✗ Branch 1 not taken.
|
1993 | if (ic->duration == AV_NOPTS_VALUE && |
1793 |
2/2✓ Branch 0 taken 895 times.
✓ Branch 1 taken 1098 times.
|
1993 | ic->bit_rate != 0) { |
1794 |
2/2✓ Branch 0 taken 870 times.
✓ Branch 1 taken 25 times.
|
895 | int64_t filesize = ic->pb ? avio_size(ic->pb) : 0; |
1795 |
2/2✓ Branch 0 taken 864 times.
✓ Branch 1 taken 31 times.
|
895 | if (filesize > si->data_offset) { |
1796 | 864 | filesize -= si->data_offset; | |
1797 |
2/2✓ Branch 0 taken 901 times.
✓ Branch 1 taken 864 times.
|
1765 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
1798 | 901 | AVStream *const st = ic->streams[i]; | |
1799 | |||
1800 |
1/2✓ Branch 0 taken 901 times.
✗ Branch 1 not taken.
|
901 | if ( st->time_base.num <= INT64_MAX / ic->bit_rate |
1801 |
1/2✓ Branch 0 taken 901 times.
✗ Branch 1 not taken.
|
901 | && st->duration == AV_NOPTS_VALUE) { |
1802 | 901 | st->duration = av_rescale(filesize, 8LL * st->time_base.den, | |
1803 | 901 | ic->bit_rate * | |
1804 | 901 | (int64_t) st->time_base.num); | |
1805 | 901 | show_warning = 1; | |
1806 | } | ||
1807 | } | ||
1808 | } | ||
1809 | } | ||
1810 |
2/2✓ Branch 0 taken 864 times.
✓ Branch 1 taken 1129 times.
|
1993 | if (show_warning) |
1811 | 864 | av_log(ic, AV_LOG_WARNING, | |
1812 | "Estimating duration from bitrate, this may be inaccurate\n"); | ||
1813 | 1993 | } | |
1814 | |||
1815 | #define DURATION_DEFAULT_MAX_READ_SIZE 250000LL | ||
1816 | #define DURATION_DEFAULT_MAX_RETRY 6 | ||
1817 | #define DURATION_MAX_RETRY 1 | ||
1818 | |||
1819 | /* only usable for MPEG-PS streams */ | ||
1820 | 69 | static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) | |
1821 | { | ||
1822 | 69 | FFFormatContext *const si = ffformatcontext(ic); | |
1823 | 69 | AVPacket *const pkt = si->pkt; | |
1824 | int num, den, read_size, ret; | ||
1825 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 69 times.
|
69 | int64_t duration_max_read_size = ic->duration_probesize ? ic->duration_probesize >> DURATION_MAX_RETRY : DURATION_DEFAULT_MAX_READ_SIZE; |
1826 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 69 times.
|
69 | int duration_max_retry = ic->duration_probesize ? DURATION_MAX_RETRY : DURATION_DEFAULT_MAX_RETRY; |
1827 | 69 | int found_duration = 0; | |
1828 | int is_end; | ||
1829 | int64_t filesize, offset, duration; | ||
1830 | 69 | int retry = 0; | |
1831 | |||
1832 | /* flush packet queue */ | ||
1833 | 69 | ff_flush_packet_queue(ic); | |
1834 | |||
1835 |
2/2✓ Branch 0 taken 143 times.
✓ Branch 1 taken 69 times.
|
212 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
1836 | 143 | AVStream *const st = ic->streams[i]; | |
1837 | 143 | FFStream *const sti = ffstream(st); | |
1838 | |||
1839 |
2/2✓ Branch 0 taken 22 times.
✓ Branch 1 taken 121 times.
|
143 | if (st->start_time == AV_NOPTS_VALUE && |
1840 |
1/2✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
|
22 | sti->first_dts == AV_NOPTS_VALUE && |
1841 |
1/2✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
|
22 | st->codecpar->codec_type != AVMEDIA_TYPE_UNKNOWN) |
1842 | 22 | av_log(ic, AV_LOG_WARNING, | |
1843 | "start time for stream %d is not set in estimate_timings_from_pts\n", i); | ||
1844 | |||
1845 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 119 times.
|
143 | if (sti->parser) { |
1846 | 24 | av_parser_close(sti->parser); | |
1847 | 24 | sti->parser = NULL; | |
1848 | } | ||
1849 | } | ||
1850 | |||
1851 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 69 times.
|
69 | if (ic->skip_estimate_duration_from_pts) { |
1852 | ✗ | av_log(ic, AV_LOG_INFO, "Skipping duration calculation in estimate_timings_from_pts\n"); | |
1853 | ✗ | goto skip_duration_calc; | |
1854 | } | ||
1855 | |||
1856 | 69 | av_opt_set_int(ic, "skip_changes", 1, AV_OPT_SEARCH_CHILDREN); | |
1857 | /* estimate the end time (duration) */ | ||
1858 | /* XXX: may need to support wrapping */ | ||
1859 |
1/2✓ Branch 0 taken 69 times.
✗ Branch 1 not taken.
|
69 | filesize = ic->pb ? avio_size(ic->pb) : 0; |
1860 | do { | ||
1861 | 76 | is_end = found_duration; | |
1862 | 76 | offset = filesize - (duration_max_read_size << retry); | |
1863 |
2/2✓ Branch 0 taken 26 times.
✓ Branch 1 taken 50 times.
|
76 | if (offset < 0) |
1864 | 26 | offset = 0; | |
1865 | |||
1866 | 76 | avio_seek(ic->pb, offset, SEEK_SET); | |
1867 | 76 | read_size = 0; | |
1868 | 6554 | for (;;) { | |
1869 | AVStream *st; | ||
1870 | FFStream *sti; | ||
1871 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 6623 times.
|
6630 | if (read_size >= duration_max_read_size << (FFMAX(retry - 1, 0))) |
1872 | 7 | break; | |
1873 | |||
1874 | do { | ||
1875 | 6623 | ret = ff_read_packet(ic, pkt); | |
1876 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6623 times.
|
6623 | } while (ret == AVERROR(EAGAIN)); |
1877 |
2/2✓ Branch 0 taken 69 times.
✓ Branch 1 taken 6554 times.
|
6623 | if (ret != 0) |
1878 | 69 | break; | |
1879 | 6554 | read_size += pkt->size; | |
1880 | 6554 | st = ic->streams[pkt->stream_index]; | |
1881 | 6554 | sti = ffstream(st); | |
1882 |
2/2✓ Branch 0 taken 2805 times.
✓ Branch 1 taken 3749 times.
|
6554 | if (pkt->pts != AV_NOPTS_VALUE && |
1883 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2805 times.
|
2805 | (st->start_time != AV_NOPTS_VALUE || |
1884 | ✗ | sti->first_dts != AV_NOPTS_VALUE)) { | |
1885 |
1/2✓ Branch 0 taken 2805 times.
✗ Branch 1 not taken.
|
2805 | if (pkt->duration == 0) { |
1886 | 2805 | compute_frame_duration(ic, &num, &den, st, sti->parser, pkt); | |
1887 |
3/4✓ Branch 0 taken 2345 times.
✓ Branch 1 taken 460 times.
✓ Branch 2 taken 2345 times.
✗ Branch 3 not taken.
|
2805 | if (den && num) { |
1888 | 2345 | pkt->duration = av_rescale_rnd(1, | |
1889 | 2345 | num * (int64_t) st->time_base.den, | |
1890 | 2345 | den * (int64_t) st->time_base.num, | |
1891 | AV_ROUND_DOWN); | ||
1892 | } | ||
1893 | } | ||
1894 | 2805 | duration = pkt->pts + pkt->duration; | |
1895 | 2805 | found_duration = 1; | |
1896 |
1/2✓ Branch 0 taken 2805 times.
✗ Branch 1 not taken.
|
2805 | if (st->start_time != AV_NOPTS_VALUE) |
1897 | 2805 | duration -= st->start_time; | |
1898 | else | ||
1899 | ✗ | duration -= sti->first_dts; | |
1900 |
2/2✓ Branch 0 taken 2796 times.
✓ Branch 1 taken 9 times.
|
2805 | if (duration > 0) { |
1901 |
3/4✓ Branch 0 taken 2685 times.
✓ Branch 1 taken 111 times.
✓ Branch 2 taken 2685 times.
✗ Branch 3 not taken.
|
2796 | if (st->duration == AV_NOPTS_VALUE || sti->info->last_duration<= 0 || |
1902 |
3/4✓ Branch 0 taken 2431 times.
✓ Branch 1 taken 254 times.
✓ Branch 2 taken 2431 times.
✗ Branch 3 not taken.
|
2685 | (st->duration < duration && FFABS(duration - sti->info->last_duration) < 60LL*st->time_base.den / st->time_base.num)) |
1903 | 2542 | st->duration = duration; | |
1904 | 2796 | sti->info->last_duration = duration; | |
1905 | } | ||
1906 | } | ||
1907 | 6554 | av_packet_unref(pkt); | |
1908 | } | ||
1909 | |||
1910 | /* check if all audio/video streams have valid duration */ | ||
1911 |
2/2✓ Branch 0 taken 69 times.
✓ Branch 1 taken 7 times.
|
76 | if (!is_end) { |
1912 | 69 | is_end = 1; | |
1913 |
2/2✓ Branch 0 taken 143 times.
✓ Branch 1 taken 69 times.
|
212 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
1914 | 143 | const AVStream *const st = ic->streams[i]; | |
1915 |
2/2✓ Branch 0 taken 125 times.
✓ Branch 1 taken 18 times.
|
143 | switch (st->codecpar->codec_type) { |
1916 | 125 | case AVMEDIA_TYPE_VIDEO: | |
1917 | case AVMEDIA_TYPE_AUDIO: | ||
1918 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 101 times.
|
125 | if (st->duration == AV_NOPTS_VALUE) |
1919 | 24 | is_end = 0; | |
1920 | } | ||
1921 | } | ||
1922 | } | ||
1923 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 2 times.
|
9 | } while (!is_end && |
1924 |
3/4✓ Branch 0 taken 9 times.
✓ Branch 1 taken 67 times.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
|
83 | offset && |
1925 | ++retry <= duration_max_retry); | ||
1926 | |||
1927 | 69 | av_opt_set_int(ic, "skip_changes", 0, AV_OPT_SEARCH_CHILDREN); | |
1928 | |||
1929 | /* warn about audio/video streams which duration could not be estimated */ | ||
1930 |
2/2✓ Branch 0 taken 143 times.
✓ Branch 1 taken 69 times.
|
212 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
1931 | 143 | const AVStream *const st = ic->streams[i]; | |
1932 | 143 | const FFStream *const sti = cffstream(st); | |
1933 | |||
1934 |
2/2✓ Branch 0 taken 32 times.
✓ Branch 1 taken 111 times.
|
143 | if (st->duration == AV_NOPTS_VALUE) { |
1935 |
2/2✓ Branch 0 taken 17 times.
✓ Branch 1 taken 15 times.
|
32 | switch (st->codecpar->codec_type) { |
1936 | 17 | case AVMEDIA_TYPE_VIDEO: | |
1937 | case AVMEDIA_TYPE_AUDIO: | ||
1938 |
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) { |
1939 | 7 | av_log(ic, AV_LOG_WARNING, "stream %d : no PTS found at end of file, duration not set\n", i); | |
1940 | } else | ||
1941 | 10 | av_log(ic, AV_LOG_WARNING, "stream %d : no TS found at start of file, duration not set\n", i); | |
1942 | } | ||
1943 | } | ||
1944 | } | ||
1945 | 69 | skip_duration_calc: | |
1946 | 69 | fill_all_stream_timings(ic); | |
1947 | |||
1948 | 69 | avio_seek(ic->pb, old_offset, SEEK_SET); | |
1949 |
2/2✓ Branch 0 taken 143 times.
✓ Branch 1 taken 69 times.
|
212 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
1950 | 143 | AVStream *const st = ic->streams[i]; | |
1951 | 143 | FFStream *const sti = ffstream(st); | |
1952 | |||
1953 | 143 | sti->cur_dts = sti->first_dts; | |
1954 | 143 | sti->last_IP_pts = AV_NOPTS_VALUE; | |
1955 | 143 | sti->last_dts_for_order_check = AV_NOPTS_VALUE; | |
1956 |
2/2✓ Branch 0 taken 2431 times.
✓ Branch 1 taken 143 times.
|
2574 | for (int j = 0; j < MAX_REORDER_DELAY + 1; j++) |
1957 | 2431 | sti->pts_buffer[j] = AV_NOPTS_VALUE; | |
1958 | } | ||
1959 | 69 | } | |
1960 | |||
1961 | /* 1:1 map to AVDurationEstimationMethod */ | ||
1962 | static const char *const duration_name[] = { | ||
1963 | [AVFMT_DURATION_FROM_PTS] = "pts", | ||
1964 | [AVFMT_DURATION_FROM_STREAM] = "stream", | ||
1965 | [AVFMT_DURATION_FROM_BITRATE] = "bit rate", | ||
1966 | }; | ||
1967 | |||
1968 | 7580 | static const char *duration_estimate_name(enum AVDurationEstimationMethod method) | |
1969 | { | ||
1970 | 7580 | return duration_name[method]; | |
1971 | } | ||
1972 | |||
1973 | 7580 | static void estimate_timings(AVFormatContext *ic, int64_t old_offset) | |
1974 | { | ||
1975 | int64_t file_size; | ||
1976 | |||
1977 | /* get the file size, if possible */ | ||
1978 |
2/2✓ Branch 0 taken 3079 times.
✓ Branch 1 taken 4501 times.
|
7580 | if (ic->iformat->flags & AVFMT_NOFILE) { |
1979 | 3079 | file_size = 0; | |
1980 | } else { | ||
1981 | 4501 | file_size = avio_size(ic->pb); | |
1982 | 4501 | file_size = FFMAX(0, file_size); | |
1983 | } | ||
1984 | |||
1985 |
2/2✓ Branch 0 taken 7555 times.
✓ Branch 1 taken 25 times.
|
7580 | if ((!strcmp(ic->iformat->name, "mpeg") || |
1986 |
3/4✓ Branch 0 taken 44 times.
✓ Branch 1 taken 7511 times.
✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
|
7580 | !strcmp(ic->iformat->name, "mpegts")) && |
1987 |
1/2✓ Branch 0 taken 69 times.
✗ Branch 1 not taken.
|
69 | file_size && (ic->pb->seekable & AVIO_SEEKABLE_NORMAL)) { |
1988 | /* get accurate estimate from the PTSes */ | ||
1989 | 69 | estimate_timings_from_pts(ic, old_offset); | |
1990 | 69 | ic->duration_estimation_method = AVFMT_DURATION_FROM_PTS; | |
1991 |
2/2✓ Branch 1 taken 5518 times.
✓ Branch 2 taken 1993 times.
|
7511 | } else if (has_duration(ic)) { |
1992 | /* at least one component has timings - we use them for all | ||
1993 | * the components */ | ||
1994 | 5518 | fill_all_stream_timings(ic); | |
1995 | /* nut demuxer estimate the duration from PTS */ | ||
1996 |
2/2✓ Branch 0 taken 30 times.
✓ Branch 1 taken 5488 times.
|
5518 | if (!strcmp(ic->iformat->name, "nut")) |
1997 | 30 | ic->duration_estimation_method = AVFMT_DURATION_FROM_PTS; | |
1998 | else | ||
1999 | 5488 | ic->duration_estimation_method = AVFMT_DURATION_FROM_STREAM; | |
2000 | } else { | ||
2001 | /* less precise: use bitrate info */ | ||
2002 | 1993 | estimate_timings_from_bit_rate(ic); | |
2003 | 1993 | ic->duration_estimation_method = AVFMT_DURATION_FROM_BITRATE; | |
2004 | } | ||
2005 | 7580 | update_stream_timings(ic); | |
2006 | |||
2007 |
2/2✓ Branch 0 taken 8395 times.
✓ Branch 1 taken 7580 times.
|
15975 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
2008 | 8395 | AVStream *const st = ic->streams[i]; | |
2009 |
1/2✓ Branch 0 taken 8395 times.
✗ Branch 1 not taken.
|
8395 | if (st->time_base.den) |
2010 | 8395 | av_log(ic, AV_LOG_TRACE, "stream %u: start_time: %s duration: %s\n", i, | |
2011 | 8395 | av_ts2timestr(st->start_time, &st->time_base), | |
2012 | 8395 | av_ts2timestr(st->duration, &st->time_base)); | |
2013 | } | ||
2014 | 7580 | av_log(ic, AV_LOG_TRACE, | |
2015 | "format: start_time: %s duration: %s (estimate from %s) bitrate=%"PRId64" kb/s\n", | ||
2016 | 7580 | av_ts2timestr(ic->start_time, &AV_TIME_BASE_Q), | |
2017 | 7580 | av_ts2timestr(ic->duration, &AV_TIME_BASE_Q), | |
2018 | duration_estimate_name(ic->duration_estimation_method), | ||
2019 | 7580 | (int64_t)ic->bit_rate / 1000); | |
2020 | 7580 | } | |
2021 | |||
2022 | 104499 | static int determinable_frame_size(const AVCodecContext *avctx) | |
2023 | { | ||
2024 |
2/2✓ Branch 0 taken 248 times.
✓ Branch 1 taken 104251 times.
|
104499 | switch(avctx->codec_id) { |
2025 | 248 | case AV_CODEC_ID_MP1: | |
2026 | case AV_CODEC_ID_MP2: | ||
2027 | case AV_CODEC_ID_MP3: | ||
2028 | case AV_CODEC_ID_CODEC2: | ||
2029 | 248 | return 1; | |
2030 | } | ||
2031 | |||
2032 | 104251 | return 0; | |
2033 | } | ||
2034 | |||
2035 | 421883 | static int has_codec_parameters(const AVStream *st, const char **errmsg_ptr) | |
2036 | { | ||
2037 | 421883 | const FFStream *const sti = cffstream(st); | |
2038 | 421883 | const AVCodecContext *const avctx = sti->avctx; | |
2039 | |||
2040 | #define FAIL(errmsg) do { \ | ||
2041 | if (errmsg_ptr) \ | ||
2042 | *errmsg_ptr = errmsg; \ | ||
2043 | return 0; \ | ||
2044 | } while (0) | ||
2045 | |||
2046 |
2/2✓ Branch 0 taken 644 times.
✓ Branch 1 taken 421239 times.
|
421883 | if ( avctx->codec_id == AV_CODEC_ID_NONE |
2047 |
2/2✓ Branch 0 taken 419 times.
✓ Branch 1 taken 225 times.
|
644 | && avctx->codec_type != AVMEDIA_TYPE_DATA) |
2048 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 414 times.
|
419 | FAIL("unknown codec"); |
2049 |
4/5✓ Branch 0 taken 119878 times.
✓ Branch 1 taken 300044 times.
✓ Branch 2 taken 629 times.
✓ Branch 3 taken 913 times.
✗ Branch 4 not taken.
|
421464 | switch (avctx->codec_type) { |
2050 | 119878 | case AVMEDIA_TYPE_AUDIO: | |
2051 |
4/4✓ Branch 0 taken 104499 times.
✓ Branch 1 taken 15379 times.
✓ Branch 3 taken 248 times.
✓ Branch 4 taken 104251 times.
|
119878 | if (!avctx->frame_size && determinable_frame_size(avctx)) |
2052 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 246 times.
|
248 | FAIL("unspecified frame size"); |
2053 |
1/2✓ Branch 0 taken 119630 times.
✗ Branch 1 not taken.
|
119630 | if (sti->info->found_decoder >= 0 && |
2054 |
2/2✓ Branch 0 taken 2442 times.
✓ Branch 1 taken 117188 times.
|
119630 | avctx->sample_fmt == AV_SAMPLE_FMT_NONE) |
2055 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2442 times.
|
2442 | FAIL("unspecified sample format"); |
2056 |
2/2✓ Branch 0 taken 137 times.
✓ Branch 1 taken 117051 times.
|
117188 | if (!avctx->sample_rate) |
2057 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 131 times.
|
137 | FAIL("unspecified sample rate"); |
2058 |
2/2✓ Branch 0 taken 17 times.
✓ Branch 1 taken 117034 times.
|
117051 | if (!avctx->ch_layout.nb_channels) |
2059 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
|
17 | FAIL("unspecified number of channels"); |
2060 |
4/6✓ Branch 0 taken 117034 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80904 times.
✓ Branch 3 taken 36130 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 80904 times.
|
117034 | if (sti->info->found_decoder >= 0 && !sti->nb_decoded_frames && avctx->codec_id == AV_CODEC_ID_DTS) |
2061 | ✗ | FAIL("no decodable DTS frames"); | |
2062 | 117034 | break; | |
2063 | 300044 | case AVMEDIA_TYPE_VIDEO: | |
2064 |
2/2✓ Branch 0 taken 12787 times.
✓ Branch 1 taken 287257 times.
|
300044 | if (!avctx->width) |
2065 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 12777 times.
|
12787 | FAIL("unspecified size"); |
2066 |
4/4✓ Branch 0 taken 287202 times.
✓ Branch 1 taken 55 times.
✓ Branch 2 taken 4255 times.
✓ Branch 3 taken 282947 times.
|
287257 | if (sti->info->found_decoder >= 0 && avctx->pix_fmt == AV_PIX_FMT_NONE) |
2067 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 4252 times.
|
4255 | FAIL("unspecified pixel format"); |
2068 |
4/4✓ Branch 0 taken 282902 times.
✓ Branch 1 taken 100 times.
✓ Branch 2 taken 86 times.
✓ Branch 3 taken 282816 times.
|
283002 | if (st->codecpar->codec_id == AV_CODEC_ID_RV30 || st->codecpar->codec_id == AV_CODEC_ID_RV40) |
2069 |
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) |
2070 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 67 times.
|
67 | FAIL("no frame in rv30/40 and no sar"); |
2071 | 282935 | break; | |
2072 | 629 | case AVMEDIA_TYPE_SUBTITLE: | |
2073 |
4/4✓ Branch 0 taken 35 times.
✓ Branch 1 taken 594 times.
✓ Branch 2 taken 21 times.
✓ Branch 3 taken 14 times.
|
629 | if (avctx->codec_id == AV_CODEC_ID_HDMV_PGS_SUBTITLE && !avctx->width) |
2074 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
|
21 | FAIL("unspecified size"); |
2075 | 608 | break; | |
2076 | 913 | case AVMEDIA_TYPE_DATA: | |
2077 |
2/2✓ Branch 0 taken 225 times.
✓ Branch 1 taken 688 times.
|
913 | if (avctx->codec_id == AV_CODEC_ID_NONE) return 1; |
2078 | } | ||
2079 | |||
2080 | 401265 | return 1; | |
2081 | } | ||
2082 | |||
2083 | /* returns 1 or 0 if or if not decoded data was returned, or a negative error */ | ||
2084 | 196128 | static int try_decode_frame(AVFormatContext *s, AVStream *st, | |
2085 | const AVPacket *pkt, AVDictionary **options) | ||
2086 | { | ||
2087 | 196128 | FFStream *const sti = ffstream(st); | |
2088 | 196128 | AVCodecContext *const avctx = sti->avctx; | |
2089 | const AVCodec *codec; | ||
2090 | 196128 | int got_picture = 1, ret = 0; | |
2091 | 196128 | AVFrame *frame = av_frame_alloc(); | |
2092 | AVSubtitle subtitle; | ||
2093 | 196128 | int do_skip_frame = 0; | |
2094 | enum AVDiscard skip_frame; | ||
2095 | 196128 | int pkt_to_send = pkt->size > 0; | |
2096 | |||
2097 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 196128 times.
|
196128 | if (!frame) |
2098 | ✗ | return AVERROR(ENOMEM); | |
2099 | |||
2100 |
2/2✓ Branch 1 taken 1477 times.
✓ Branch 2 taken 194651 times.
|
196128 | if (!avcodec_is_open(avctx) && |
2101 |
1/2✓ Branch 0 taken 1477 times.
✗ Branch 1 not taken.
|
1477 | sti->info->found_decoder <= 0 && |
2102 |
4/4✓ Branch 0 taken 96 times.
✓ Branch 1 taken 1381 times.
✓ Branch 2 taken 63 times.
✓ Branch 3 taken 33 times.
|
1477 | (st->codecpar->codec_id != -sti->info->found_decoder || !st->codecpar->codec_id)) { |
2103 | 1444 | AVDictionary *thread_opt = NULL; | |
2104 | |||
2105 | 1444 | codec = find_probe_decoder(s, st, st->codecpar->codec_id); | |
2106 | |||
2107 |
2/2✓ Branch 0 taken 76 times.
✓ Branch 1 taken 1368 times.
|
1444 | if (!codec) { |
2108 | 76 | sti->info->found_decoder = -st->codecpar->codec_id; | |
2109 | 76 | ret = -1; | |
2110 | 78 | goto fail; | |
2111 | } | ||
2112 | |||
2113 | /* Force thread count to 1 since the H.264 decoder will not extract | ||
2114 | * SPS and PPS to extradata during multi-threaded decoding. */ | ||
2115 |
2/2✓ Branch 0 taken 163 times.
✓ Branch 1 taken 1205 times.
|
1368 | av_dict_set(options ? options : &thread_opt, "threads", "1", 0); |
2116 | /* Force lowres to 0. The decoder might reduce the video size by the | ||
2117 | * lowres factor, and we don't want that propagated to the stream's | ||
2118 | * codecpar */ | ||
2119 |
2/2✓ Branch 0 taken 163 times.
✓ Branch 1 taken 1205 times.
|
1368 | av_dict_set(options ? options : &thread_opt, "lowres", "0", 0); |
2120 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1368 times.
|
1368 | if (s->codec_whitelist) |
2121 | ✗ | av_dict_set(options ? options : &thread_opt, "codec_whitelist", s->codec_whitelist, 0); | |
2122 |
2/2✓ Branch 0 taken 163 times.
✓ Branch 1 taken 1205 times.
|
1368 | ret = avcodec_open2(avctx, codec, options ? options : &thread_opt); |
2123 |
2/2✓ Branch 0 taken 163 times.
✓ Branch 1 taken 1205 times.
|
1368 | if (!options) |
2124 | 163 | av_dict_free(&thread_opt); | |
2125 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1366 times.
|
1368 | if (ret < 0) { |
2126 | 2 | sti->info->found_decoder = -avctx->codec_id; | |
2127 | 2 | goto fail; | |
2128 | } | ||
2129 | 1366 | sti->info->found_decoder = 1; | |
2130 |
2/2✓ Branch 0 taken 6749 times.
✓ Branch 1 taken 187935 times.
|
194684 | } else if (!sti->info->found_decoder) |
2131 | 6749 | sti->info->found_decoder = 1; | |
2132 | |||
2133 |
2/2✓ Branch 0 taken 33 times.
✓ Branch 1 taken 196017 times.
|
196050 | if (sti->info->found_decoder < 0) { |
2134 | 33 | ret = -1; | |
2135 | 33 | goto fail; | |
2136 | } | ||
2137 | |||
2138 |
2/2✓ Branch 1 taken 108091 times.
✓ Branch 2 taken 87926 times.
|
196017 | if (avpriv_codec_get_cap_skip_frame_fill_param(avctx->codec)) { |
2139 | 108091 | do_skip_frame = 1; | |
2140 | 108091 | skip_frame = avctx->skip_frame; | |
2141 | 108091 | avctx->skip_frame = AVDISCARD_ALL; | |
2142 | } | ||
2143 | |||
2144 |
5/6✓ Branch 0 taken 8003 times.
✓ Branch 1 taken 4578 times.
✓ Branch 2 taken 26 times.
✓ Branch 3 taken 4552 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 196025 times.
|
400071 | while ((pkt_to_send || (!pkt->data && got_picture)) && |
2145 |
4/4✓ Branch 0 taken 12581 times.
✓ Branch 1 taken 191473 times.
✓ Branch 2 taken 5576 times.
✓ Branch 3 taken 190449 times.
|
400079 | ret >= 0 && |
2146 |
2/2✓ Branch 2 taken 2241 times.
✓ Branch 3 taken 188208 times.
|
386474 | (!has_codec_parameters(st, NULL) || !has_decode_delay_been_guessed(st) || |
2147 |
2/2✓ Branch 0 taken 185382 times.
✓ Branch 1 taken 2826 times.
|
188208 | (!sti->codec_info_nb_frames && |
2148 |
2/2✓ Branch 0 taken 460 times.
✓ Branch 1 taken 2366 times.
|
2826 | (avctx->codec->capabilities & AV_CODEC_CAP_CHANNEL_CONF)))) { |
2149 | 8277 | got_picture = 0; | |
2150 |
2/2✓ Branch 0 taken 744 times.
✓ Branch 1 taken 7533 times.
|
8277 | if (avctx->codec_type == AVMEDIA_TYPE_VIDEO || |
2151 |
2/2✓ Branch 0 taken 737 times.
✓ Branch 1 taken 7 times.
|
744 | avctx->codec_type == AVMEDIA_TYPE_AUDIO) { |
2152 | 8270 | ret = avcodec_send_packet(avctx, pkt); | |
2153 |
5/6✓ Branch 0 taken 249 times.
✓ Branch 1 taken 8021 times.
✓ Branch 2 taken 249 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 240 times.
✓ Branch 5 taken 9 times.
|
8270 | if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) |
2154 | 240 | break; | |
2155 |
2/2✓ Branch 0 taken 8021 times.
✓ Branch 1 taken 9 times.
|
8030 | if (ret >= 0) |
2156 | 8021 | pkt_to_send = 0; | |
2157 | 8030 | ret = avcodec_receive_frame(avctx, frame); | |
2158 |
2/2✓ Branch 0 taken 3175 times.
✓ Branch 1 taken 4855 times.
|
8030 | if (ret >= 0) |
2159 | 3175 | got_picture = 1; | |
2160 |
4/4✓ Branch 0 taken 3201 times.
✓ Branch 1 taken 4829 times.
✓ Branch 2 taken 26 times.
✓ Branch 3 taken 3175 times.
|
8030 | if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) |
2161 | 4855 | ret = 0; | |
2162 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
7 | } else if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE) { |
2163 | 7 | ret = avcodec_decode_subtitle2(avctx, &subtitle, | |
2164 | &got_picture, pkt); | ||
2165 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 5 times.
|
7 | if (got_picture) |
2166 | 2 | avsubtitle_free(&subtitle); | |
2167 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
7 | if (ret >= 0) |
2168 | 7 | pkt_to_send = 0; | |
2169 | } | ||
2170 |
1/2✓ Branch 0 taken 8037 times.
✗ Branch 1 not taken.
|
8037 | if (ret >= 0) { |
2171 |
2/2✓ Branch 0 taken 3177 times.
✓ Branch 1 taken 4860 times.
|
8037 | if (got_picture) |
2172 | 3177 | sti->nb_decoded_frames++; | |
2173 | 8037 | ret = got_picture; | |
2174 | } | ||
2175 | } | ||
2176 | |||
2177 | 195777 | fail: | |
2178 |
2/2✓ Branch 0 taken 108091 times.
✓ Branch 1 taken 88037 times.
|
196128 | if (do_skip_frame) { |
2179 | 108091 | avctx->skip_frame = skip_frame; | |
2180 | } | ||
2181 | |||
2182 | 196128 | av_frame_free(&frame); | |
2183 | 196128 | return ret; | |
2184 | } | ||
2185 | |||
2186 | 57 | static int chapter_start_cmp(const void *p1, const void *p2) | |
2187 | { | ||
2188 | 57 | const AVChapter *const ch1 = *(AVChapter**)p1; | |
2189 | 57 | const AVChapter *const ch2 = *(AVChapter**)p2; | |
2190 | 57 | int delta = av_compare_ts(ch1->start, ch1->time_base, ch2->start, ch2->time_base); | |
2191 |
1/2✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
|
57 | if (delta) |
2192 | 57 | return delta; | |
2193 | ✗ | return FFDIFFSIGN(ch1->id, ch2->id); | |
2194 | } | ||
2195 | |||
2196 | 7580 | static int compute_chapters_end(AVFormatContext *s) | |
2197 | { | ||
2198 | 7580 | int64_t max_time = 0; | |
2199 | AVChapter **timetable; | ||
2200 | |||
2201 |
2/2✓ Branch 0 taken 7554 times.
✓ Branch 1 taken 26 times.
|
7580 | if (!s->nb_chapters) |
2202 | 7554 | return 0; | |
2203 | |||
2204 |
2/4✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 26 times.
✗ Branch 3 not taken.
|
26 | if (s->duration > 0 && s->start_time < INT64_MAX - s->duration) |
2205 | 26 | max_time = s->duration + | |
2206 |
2/2✓ Branch 0 taken 23 times.
✓ Branch 1 taken 3 times.
|
26 | ((s->start_time == AV_NOPTS_VALUE) ? 0 : s->start_time); |
2207 | |||
2208 | 26 | timetable = av_memdup(s->chapters, s->nb_chapters * sizeof(*timetable)); | |
2209 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
|
26 | if (!timetable) |
2210 | ✗ | return AVERROR(ENOMEM); | |
2211 | 26 | qsort(timetable, s->nb_chapters, sizeof(*timetable), chapter_start_cmp); | |
2212 | |||
2213 |
2/2✓ Branch 0 taken 71 times.
✓ Branch 1 taken 26 times.
|
97 | for (unsigned i = 0; i < s->nb_chapters; i++) |
2214 |
2/2✓ Branch 0 taken 40 times.
✓ Branch 1 taken 31 times.
|
71 | if (timetable[i]->end == AV_NOPTS_VALUE) { |
2215 | 40 | AVChapter *const ch = timetable[i]; | |
2216 | 40 | int64_t end = max_time ? av_rescale_q(max_time, AV_TIME_BASE_Q, | |
2217 | ch->time_base) | ||
2218 |
1/2✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
|
40 | : INT64_MAX; |
2219 | |||
2220 |
2/2✓ Branch 0 taken 21 times.
✓ Branch 1 taken 19 times.
|
40 | if (i + 1 < s->nb_chapters) { |
2221 | 21 | const AVChapter *const ch1 = timetable[i + 1]; | |
2222 | 21 | int64_t next_start = av_rescale_q(ch1->start, ch1->time_base, | |
2223 | ch->time_base); | ||
2224 |
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) |
2225 | 21 | end = next_start; | |
2226 | } | ||
2227 |
2/4✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 40 times.
|
40 | ch->end = (end == INT64_MAX || end < ch->start) ? ch->start : end; |
2228 | } | ||
2229 | 26 | av_free(timetable); | |
2230 | 26 | return 0; | |
2231 | } | ||
2232 | |||
2233 | 18782411 | static int get_std_framerate(int i) | |
2234 | { | ||
2235 |
2/2✓ Branch 0 taken 17064379 times.
✓ Branch 1 taken 1718032 times.
|
18782411 | if (i < 30*12) |
2236 | 17064379 | return (i + 1) * 1001; | |
2237 | 1718032 | i -= 30*12; | |
2238 | |||
2239 |
2/2✓ Branch 0 taken 1306619 times.
✓ Branch 1 taken 411413 times.
|
1718032 | if (i < 30) |
2240 | 1306619 | return (i + 31) * 1001 * 12; | |
2241 | 411413 | i -= 30; | |
2242 | |||
2243 |
2/2✓ Branch 0 taken 131106 times.
✓ Branch 1 taken 280307 times.
|
411413 | if (i < 3) |
2244 | 131106 | return ((const int[]) { 80, 120, 240})[i] * 1001 * 12; | |
2245 | |||
2246 | 280307 | i -= 3; | |
2247 | |||
2248 | 280307 | return ((const int[]) { 24, 30, 60, 12, 15, 48 })[i] * 1000 * 12; | |
2249 | } | ||
2250 | |||
2251 | /* Is the time base unreliable? | ||
2252 | * This is a heuristic to balance between quick acceptance of the values in | ||
2253 | * the headers vs. some extra checks. | ||
2254 | * Old DivX and Xvid often have nonsense timebases like 1fps or 2fps. | ||
2255 | * MPEG-2 commonly misuses field repeat flags to store different framerates. | ||
2256 | * And there are "variable" fps files this needs to detect as well. */ | ||
2257 | 207407 | static int tb_unreliable(AVFormatContext *ic, AVStream *st) | |
2258 | { | ||
2259 | 207407 | FFStream *const sti = ffstream(st); | |
2260 | 207407 | const AVCodecDescriptor *desc = sti->codec_desc; | |
2261 | 207407 | AVCodecContext *c = sti->avctx; | |
2262 |
4/4✓ Branch 0 taken 206950 times.
✓ Branch 1 taken 457 times.
✓ Branch 2 taken 21029 times.
✓ Branch 3 taken 185921 times.
|
207407 | AVRational mul = (AVRational){ desc && (desc->props & AV_CODEC_PROP_FIELDS) ? 2 : 1, 1 }; |
2263 | 207407 | AVRational time_base = c->framerate.num ? av_inv_q(av_mul_q(c->framerate, mul)) | |
2264 | /* NOHEADER check added to not break existing behavior */ | ||
2265 |
2/2✓ Branch 0 taken 17676 times.
✓ Branch 1 taken 189731 times.
|
207407 | : (((ic->ctx_flags & AVFMTCTX_NOHEADER) || |
2266 |
2/2✓ Branch 0 taken 44488 times.
✓ Branch 1 taken 30537 times.
|
75025 | st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) ? (AVRational){0, 1} |
2267 |
2/2✓ Branch 0 taken 75025 times.
✓ Branch 1 taken 114706 times.
|
189731 | : st->time_base); |
2268 | |||
2269 |
2/2✓ Branch 0 taken 23990 times.
✓ Branch 1 taken 183417 times.
|
207407 | if (time_base.den >= 101LL * time_base.num || |
2270 |
2/2✓ Branch 0 taken 23575 times.
✓ Branch 1 taken 415 times.
|
23990 | time_base.den < 5LL * time_base.num || |
2271 | // c->codec_tag == AV_RL32("DIVX") || | ||
2272 | // c->codec_tag == AV_RL32("XVID") || | ||
2273 |
2/2✓ Branch 0 taken 23476 times.
✓ Branch 1 taken 99 times.
|
23575 | c->codec_tag == AV_RL32("mp4v") || |
2274 |
2/2✓ Branch 0 taken 14647 times.
✓ Branch 1 taken 8829 times.
|
23476 | c->codec_id == AV_CODEC_ID_MPEG2VIDEO || |
2275 |
2/2✓ Branch 0 taken 14117 times.
✓ Branch 1 taken 530 times.
|
14647 | c->codec_id == AV_CODEC_ID_GIF || |
2276 |
2/2✓ Branch 0 taken 13412 times.
✓ Branch 1 taken 705 times.
|
14117 | c->codec_id == AV_CODEC_ID_HEVC || |
2277 |
2/2✓ Branch 0 taken 3483 times.
✓ Branch 1 taken 9929 times.
|
13412 | c->codec_id == AV_CODEC_ID_H264) |
2278 | 197478 | return 1; | |
2279 | 9929 | return 0; | |
2280 | } | ||
2281 | |||
2282 | 142083 | int ff_rfps_add_frame(AVFormatContext *ic, AVStream *st, int64_t ts) | |
2283 | { | ||
2284 | 142083 | FFStream *const sti = ffstream(st); | |
2285 | 142083 | FFStreamInfo *info = sti->info; | |
2286 | 142083 | int64_t last = info->last_dts; | |
2287 | |||
2288 |
6/6✓ Branch 0 taken 125887 times.
✓ Branch 1 taken 16196 times.
✓ Branch 2 taken 119872 times.
✓ Branch 3 taken 6015 times.
✓ Branch 4 taken 119844 times.
✓ Branch 5 taken 28 times.
|
142083 | if ( ts != AV_NOPTS_VALUE && last != AV_NOPTS_VALUE && ts > last |
2289 |
1/2✓ Branch 0 taken 119844 times.
✗ Branch 1 not taken.
|
119844 | && ts - (uint64_t)last < INT64_MAX) { |
2290 |
2/2✓ Branch 1 taken 6523 times.
✓ Branch 2 taken 113321 times.
|
119844 | double dts = (is_relative(ts) ? ts - RELATIVE_TS_BASE : ts) * av_q2d(st->time_base); |
2291 | 119844 | int64_t duration = ts - last; | |
2292 | |||
2293 |
2/2✓ Branch 0 taken 3905 times.
✓ Branch 1 taken 115939 times.
|
119844 | if (!info->duration_error) |
2294 | 3905 | info->duration_error = av_mallocz(sizeof(info->duration_error[0])*2); | |
2295 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 119844 times.
|
119844 | if (!info->duration_error) |
2296 | ✗ | return AVERROR(ENOMEM); | |
2297 | |||
2298 | // if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) | ||
2299 | // av_log(NULL, AV_LOG_ERROR, "%f\n", dts); | ||
2300 |
2/2✓ Branch 0 taken 47817756 times.
✓ Branch 1 taken 119844 times.
|
47937600 | for (int i = 0; i < MAX_STD_TIMEBASES; i++) { |
2301 |
2/2✓ Branch 0 taken 18415735 times.
✓ Branch 1 taken 29402021 times.
|
47817756 | if (info->duration_error[0][1][i] < 1e10) { |
2302 | 18415735 | int framerate = get_std_framerate(i); | |
2303 | 18415735 | double sdts = dts*framerate/(1001*12); | |
2304 |
2/2✓ Branch 0 taken 36831470 times.
✓ Branch 1 taken 18415735 times.
|
55247205 | for (int j = 0; j < 2; j++) { |
2305 | 36831470 | int64_t ticks = llrint(sdts+j*0.5); | |
2306 | 36831470 | double error = sdts - ticks + j*0.5; | |
2307 | 36831470 | info->duration_error[j][0][i] += error; | |
2308 | 36831470 | info->duration_error[j][1][i] += error*error; | |
2309 | } | ||
2310 | } | ||
2311 | } | ||
2312 |
1/2✓ Branch 0 taken 119844 times.
✗ Branch 1 not taken.
|
119844 | if (info->rfps_duration_sum <= INT64_MAX - duration) { |
2313 | 119844 | info->duration_count++; | |
2314 | 119844 | info->rfps_duration_sum += duration; | |
2315 | } | ||
2316 | |||
2317 |
2/2✓ Branch 0 taken 10906 times.
✓ Branch 1 taken 108938 times.
|
119844 | if (info->duration_count % 10 == 0) { |
2318 | 10906 | int n = info->duration_count; | |
2319 |
2/2✓ Branch 0 taken 4351494 times.
✓ Branch 1 taken 10906 times.
|
4362400 | for (int i = 0; i < MAX_STD_TIMEBASES; i++) { |
2320 |
2/2✓ Branch 0 taken 1764248 times.
✓ Branch 1 taken 2587246 times.
|
4351494 | if (info->duration_error[0][1][i] < 1e10) { |
2321 | 1764248 | double a0 = info->duration_error[0][0][i] / n; | |
2322 | 1764248 | double error0 = info->duration_error[0][1][i] / n - a0*a0; | |
2323 | 1764248 | double a1 = info->duration_error[1][0][i] / n; | |
2324 | 1764248 | double error1 = info->duration_error[1][1][i] / n - a1*a1; | |
2325 |
4/4✓ Branch 0 taken 1444800 times.
✓ Branch 1 taken 319448 times.
✓ Branch 2 taken 1348456 times.
✓ Branch 3 taken 96344 times.
|
1764248 | if (error0 > 0.04 && error1 > 0.04) { |
2326 | 1348456 | info->duration_error[0][1][i] = 2e10; | |
2327 | 1348456 | info->duration_error[1][1][i] = 2e10; | |
2328 | } | ||
2329 | } | ||
2330 | } | ||
2331 | } | ||
2332 | |||
2333 | // ignore the first 4 values, they might have some random jitter | ||
2334 |
3/4✓ Branch 0 taken 108215 times.
✓ Branch 1 taken 11629 times.
✓ Branch 4 taken 108215 times.
✗ Branch 5 not taken.
|
119844 | if (info->duration_count > 3 && is_relative(ts) == is_relative(last)) |
2335 | 108215 | info->duration_gcd = av_gcd(info->duration_gcd, duration); | |
2336 | } | ||
2337 |
2/2✓ Branch 0 taken 125887 times.
✓ Branch 1 taken 16196 times.
|
142083 | if (ts != AV_NOPTS_VALUE) |
2338 | 125887 | info->last_dts = ts; | |
2339 | |||
2340 | 142083 | return 0; | |
2341 | } | ||
2342 | |||
2343 | 8076 | void ff_rfps_calculate(AVFormatContext *ic) | |
2344 | { | ||
2345 |
2/2✓ Branch 0 taken 9071 times.
✓ Branch 1 taken 8076 times.
|
17147 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
2346 | 9071 | AVStream *const st = ic->streams[i]; | |
2347 | 9071 | FFStream *const sti = ffstream(st); | |
2348 | |||
2349 |
2/2✓ Branch 0 taken 2467 times.
✓ Branch 1 taken 6604 times.
|
9071 | if (st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO) |
2350 | 2467 | continue; | |
2351 | // the check for tb_unreliable() is not completely correct, since this is not about handling | ||
2352 | // an unreliable/inexact time base, but a time base that is finer than necessary, as e.g. | ||
2353 | // ipmovie.c produces. | ||
2354 |
8/8✓ Branch 1 taken 5218 times.
✓ Branch 2 taken 1386 times.
✓ Branch 3 taken 3381 times.
✓ Branch 4 taken 1837 times.
✓ Branch 5 taken 295 times.
✓ Branch 6 taken 3086 times.
✓ Branch 7 taken 144 times.
✓ Branch 8 taken 151 times.
|
6604 | 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 && |
2355 |
1/2✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
|
144 | sti->info->duration_gcd < INT64_MAX / st->time_base.num) |
2356 | 144 | 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); | |
2357 |
4/4✓ Branch 0 taken 3868 times.
✓ Branch 1 taken 2736 times.
✓ Branch 2 taken 407 times.
✓ Branch 3 taken 3461 times.
|
6604 | if (sti->info->duration_count > 1 && !st->r_frame_rate.num |
2358 |
2/2✓ Branch 1 taken 303 times.
✓ Branch 2 taken 104 times.
|
407 | && tb_unreliable(ic, st)) { |
2359 | 303 | int num = 0; | |
2360 | 303 | double best_error = 0.01; | |
2361 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 303 times.
|
303 | AVRational ref_rate = st->r_frame_rate.num ? st->r_frame_rate : av_inv_q(st->time_base); |
2362 | |||
2363 |
2/2✓ Branch 0 taken 120897 times.
✓ Branch 1 taken 303 times.
|
121200 | for (int j = 0; j < MAX_STD_TIMEBASES; j++) { |
2364 |
2/2✓ Branch 0 taken 89775 times.
✓ Branch 1 taken 31122 times.
|
120897 | if (sti->info->codec_info_duration && |
2365 |
2/2✓ Branch 2 taken 9919 times.
✓ Branch 3 taken 79856 times.
|
89775 | sti->info->codec_info_duration*av_q2d(st->time_base) < (1001*11.5)/get_std_framerate(j)) |
2366 | 9919 | continue; | |
2367 |
4/4✓ Branch 0 taken 31122 times.
✓ Branch 1 taken 79856 times.
✓ Branch 3 taken 858 times.
✓ Branch 4 taken 30264 times.
|
110978 | if (!sti->info->codec_info_duration && get_std_framerate(j) < 1001*12) |
2368 | 858 | continue; | |
2369 | |||
2370 |
2/2✓ Branch 2 taken 51873 times.
✓ Branch 3 taken 58247 times.
|
110120 | if (av_q2d(st->time_base) * sti->info->rfps_duration_sum / sti->info->duration_count < (1001*12.0 * 0.8)/get_std_framerate(j)) |
2371 | 51873 | continue; | |
2372 | |||
2373 |
2/2✓ Branch 0 taken 116494 times.
✓ Branch 1 taken 58247 times.
|
174741 | for (int k = 0; k < 2; k++) { |
2374 | 116494 | int n = sti->info->duration_count; | |
2375 | 116494 | double a = sti->info->duration_error[k][0][j] / n; | |
2376 | 116494 | double error = sti->info->duration_error[k][1][j]/n - a*a; | |
2377 | |||
2378 |
4/4✓ Branch 0 taken 4505 times.
✓ Branch 1 taken 111989 times.
✓ Branch 2 taken 4434 times.
✓ Branch 3 taken 71 times.
|
116494 | if (error < best_error && best_error> 0.000000001) { |
2379 | 4434 | best_error= error; | |
2380 | 4434 | num = get_std_framerate(j); | |
2381 | } | ||
2382 |
2/2✓ Branch 0 taken 23894 times.
✓ Branch 1 taken 92600 times.
|
116494 | if (error < 0.02) |
2383 | 23894 | av_log(ic, AV_LOG_DEBUG, "rfps: %f %f\n", get_std_framerate(j) / 12.0/1001, error); | |
2384 | } | ||
2385 | } | ||
2386 | // do not increase frame rate by more than 1 % in order to match a standard rate. | ||
2387 |
5/6✓ Branch 0 taken 297 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 297 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 295 times.
✓ Branch 6 taken 2 times.
|
303 | if (num && (!ref_rate.num || (double)num/(12*1001) < 1.01 * av_q2d(ref_rate))) |
2388 | 295 | av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, num, 12*1001, INT_MAX); | |
2389 | } | ||
2390 |
2/2✓ Branch 0 taken 1094 times.
✓ Branch 1 taken 5510 times.
|
6604 | if ( !st->avg_frame_rate.num |
2391 |
4/4✓ Branch 0 taken 284 times.
✓ Branch 1 taken 810 times.
✓ Branch 2 taken 280 times.
✓ Branch 3 taken 4 times.
|
1094 | && st->r_frame_rate.num && sti->info->rfps_duration_sum |
2392 |
2/2✓ Branch 0 taken 73 times.
✓ Branch 1 taken 207 times.
|
280 | && sti->info->codec_info_duration <= 0 |
2393 |
2/2✓ Branch 0 taken 70 times.
✓ Branch 1 taken 3 times.
|
73 | && sti->info->duration_count > 2 |
2394 |
2/2✓ Branch 2 taken 55 times.
✓ Branch 3 taken 15 times.
|
70 | && 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 |
2395 | ) { | ||
2396 | 55 | av_log(ic, AV_LOG_DEBUG, "Setting avg frame rate based on r frame rate\n"); | |
2397 | 55 | st->avg_frame_rate = st->r_frame_rate; | |
2398 | } | ||
2399 | |||
2400 | 6604 | av_freep(&sti->info->duration_error); | |
2401 | 6604 | sti->info->last_dts = AV_NOPTS_VALUE; | |
2402 | 6604 | sti->info->duration_count = 0; | |
2403 | 6604 | sti->info->rfps_duration_sum = 0; | |
2404 | } | ||
2405 | 8076 | } | |
2406 | |||
2407 | 9012 | static int extract_extradata_check(AVStream *st) | |
2408 | { | ||
2409 | 9012 | const AVBitStreamFilter *const f = av_bsf_get_by_name("extract_extradata"); | |
2410 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9012 times.
|
9012 | if (!f) |
2411 | ✗ | return 0; | |
2412 | |||
2413 |
1/2✓ Branch 0 taken 9012 times.
✗ Branch 1 not taken.
|
9012 | if (f->codec_ids) { |
2414 | const enum AVCodecID *ids; | ||
2415 |
2/2✓ Branch 0 taken 95479 times.
✓ Branch 1 taken 8119 times.
|
103598 | for (ids = f->codec_ids; *ids != AV_CODEC_ID_NONE; ids++) |
2416 |
2/2✓ Branch 0 taken 893 times.
✓ Branch 1 taken 94586 times.
|
95479 | if (*ids == st->codecpar->codec_id) |
2417 | 893 | return 1; | |
2418 | } | ||
2419 | |||
2420 | 8119 | return 0; | |
2421 | } | ||
2422 | |||
2423 | 7099 | static int extract_extradata_init(AVStream *st) | |
2424 | { | ||
2425 | 7099 | FFStream *const sti = ffstream(st); | |
2426 | const AVBitStreamFilter *f; | ||
2427 | int ret; | ||
2428 | |||
2429 | 7099 | f = av_bsf_get_by_name("extract_extradata"); | |
2430 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7099 times.
|
7099 | if (!f) |
2431 | ✗ | goto finish; | |
2432 | |||
2433 | /* check that the codec id is supported */ | ||
2434 | 7099 | ret = extract_extradata_check(st); | |
2435 |
2/2✓ Branch 0 taken 6316 times.
✓ Branch 1 taken 783 times.
|
7099 | if (!ret) |
2436 | 6316 | goto finish; | |
2437 | |||
2438 | 783 | av_bsf_free(&sti->extract_extradata.bsf); | |
2439 | 783 | ret = av_bsf_alloc(f, &sti->extract_extradata.bsf); | |
2440 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 783 times.
|
783 | if (ret < 0) |
2441 | ✗ | return ret; | |
2442 | |||
2443 | 783 | ret = avcodec_parameters_copy(sti->extract_extradata.bsf->par_in, | |
2444 | 783 | st->codecpar); | |
2445 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 783 times.
|
783 | if (ret < 0) |
2446 | ✗ | goto fail; | |
2447 | |||
2448 | 783 | sti->extract_extradata.bsf->time_base_in = st->time_base; | |
2449 | |||
2450 | 783 | ret = av_bsf_init(sti->extract_extradata.bsf); | |
2451 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 783 times.
|
783 | if (ret < 0) |
2452 | ✗ | goto fail; | |
2453 | |||
2454 | 783 | finish: | |
2455 | 7099 | sti->extract_extradata.inited = 1; | |
2456 | |||
2457 | 7099 | return 0; | |
2458 | ✗ | fail: | |
2459 | ✗ | av_bsf_free(&sti->extract_extradata.bsf); | |
2460 | ✗ | return ret; | |
2461 | } | ||
2462 | |||
2463 | 160769 | static int extract_extradata(FFFormatContext *si, AVStream *st, const AVPacket *pkt) | |
2464 | { | ||
2465 | 160769 | FFStream *const sti = ffstream(st); | |
2466 | 160769 | AVPacket *const pkt_ref = si->parse_pkt; | |
2467 | int ret; | ||
2468 | |||
2469 |
2/2✓ Branch 0 taken 7099 times.
✓ Branch 1 taken 153670 times.
|
160769 | if (!sti->extract_extradata.inited) { |
2470 | 7099 | ret = extract_extradata_init(st); | |
2471 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7099 times.
|
7099 | if (ret < 0) |
2472 | ✗ | return ret; | |
2473 | } | ||
2474 | |||
2475 |
3/4✓ Branch 0 taken 160769 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 159601 times.
✓ Branch 3 taken 1168 times.
|
160769 | if (sti->extract_extradata.inited && !sti->extract_extradata.bsf) |
2476 | 159601 | return 0; | |
2477 | |||
2478 | 1168 | ret = av_packet_ref(pkt_ref, pkt); | |
2479 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1168 times.
|
1168 | if (ret < 0) |
2480 | ✗ | return ret; | |
2481 | |||
2482 | 1168 | ret = av_bsf_send_packet(sti->extract_extradata.bsf, pkt_ref); | |
2483 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1168 times.
|
1168 | if (ret < 0) { |
2484 | ✗ | av_packet_unref(pkt_ref); | |
2485 | ✗ | return ret; | |
2486 | } | ||
2487 | |||
2488 |
4/4✓ Branch 0 taken 2336 times.
✓ Branch 1 taken 384 times.
✓ Branch 2 taken 1552 times.
✓ Branch 3 taken 784 times.
|
2720 | while (ret >= 0 && !sti->avctx->extradata) { |
2489 | 1552 | ret = av_bsf_receive_packet(sti->extract_extradata.bsf, pkt_ref); | |
2490 |
2/2✓ Branch 0 taken 384 times.
✓ Branch 1 taken 1168 times.
|
1552 | if (ret < 0) { |
2491 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 384 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
384 | if (ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) |
2492 | ✗ | return ret; | |
2493 | 384 | continue; | |
2494 | } | ||
2495 | |||
2496 |
2/2✓ Branch 0 taken 1030 times.
✓ Branch 1 taken 384 times.
|
1414 | for (int i = 0; i < pkt_ref->side_data_elems; i++) { |
2497 | 1030 | AVPacketSideData *const side_data = &pkt_ref->side_data[i]; | |
2498 |
2/2✓ Branch 0 taken 784 times.
✓ Branch 1 taken 246 times.
|
1030 | if (side_data->type == AV_PKT_DATA_NEW_EXTRADATA) { |
2499 | 784 | sti->avctx->extradata = side_data->data; | |
2500 | 784 | sti->avctx->extradata_size = side_data->size; | |
2501 | 784 | side_data->data = NULL; | |
2502 | 784 | side_data->size = 0; | |
2503 | 784 | break; | |
2504 | } | ||
2505 | } | ||
2506 | 1168 | av_packet_unref(pkt_ref); | |
2507 | } | ||
2508 | |||
2509 | 1168 | return 0; | |
2510 | } | ||
2511 | |||
2512 | 7580 | int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) | |
2513 | { | ||
2514 | 7580 | FFFormatContext *const si = ffformatcontext(ic); | |
2515 | 7580 | int count = 0, ret = 0, err; | |
2516 | int64_t read_size; | ||
2517 | 7580 | AVPacket *pkt1 = si->pkt; | |
2518 | 7580 | int64_t old_offset = avio_tell(ic->pb); | |
2519 | // new streams might appear, no options for those | ||
2520 | 7580 | int orig_nb_streams = ic->nb_streams; | |
2521 | int flush_codecs; | ||
2522 | 7580 | int64_t max_analyze_duration = ic->max_analyze_duration; | |
2523 | int64_t max_stream_analyze_duration; | ||
2524 | int64_t max_subtitle_analyze_duration; | ||
2525 | 7580 | int64_t probesize = ic->probesize; | |
2526 | 7580 | int eof_reached = 0; | |
2527 | |||
2528 | 7580 | flush_codecs = probesize > 0; | |
2529 | |||
2530 | 7580 | av_opt_set_int(ic, "skip_clear", 1, AV_OPT_SEARCH_CHILDREN); | |
2531 | |||
2532 | 7580 | max_stream_analyze_duration = max_analyze_duration; | |
2533 | 7580 | max_subtitle_analyze_duration = max_analyze_duration; | |
2534 |
2/2✓ Branch 0 taken 7579 times.
✓ Branch 1 taken 1 times.
|
7580 | if (!max_analyze_duration) { |
2535 | 7579 | max_stream_analyze_duration = | |
2536 | 7579 | max_analyze_duration = 5*AV_TIME_BASE; | |
2537 | 7579 | max_subtitle_analyze_duration = 30*AV_TIME_BASE; | |
2538 |
2/2✓ Branch 0 taken 38 times.
✓ Branch 1 taken 7541 times.
|
7579 | if (!strcmp(ic->iformat->name, "flv")) |
2539 | 38 | max_stream_analyze_duration = 90*AV_TIME_BASE; | |
2540 |
4/4✓ Branch 0 taken 7554 times.
✓ Branch 1 taken 25 times.
✓ Branch 2 taken 44 times.
✓ Branch 3 taken 7510 times.
|
7579 | if (!strcmp(ic->iformat->name, "mpeg") || !strcmp(ic->iformat->name, "mpegts")) |
2541 | 69 | max_stream_analyze_duration = 7*AV_TIME_BASE; | |
2542 | } | ||
2543 | |||
2544 |
2/2✓ Branch 0 taken 4526 times.
✓ Branch 1 taken 3054 times.
|
7580 | if (ic->pb) { |
2545 | 4526 | FFIOContext *const ctx = ffiocontext(ic->pb); | |
2546 | 4526 | av_log(ic, AV_LOG_DEBUG, "Before avformat_find_stream_info() pos: %"PRId64" bytes read:%"PRId64" seeks:%d nb_streams:%d\n", | |
2547 | avio_tell(ic->pb), ctx->bytes_read, ctx->seek_count, ic->nb_streams); | ||
2548 | } | ||
2549 | |||
2550 |
2/2✓ Branch 0 taken 8210 times.
✓ Branch 1 taken 7580 times.
|
15790 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
2551 | const AVCodec *codec; | ||
2552 | 8210 | AVDictionary *thread_opt = NULL; | |
2553 | 8210 | AVStream *const st = ic->streams[i]; | |
2554 | 8210 | FFStream *const sti = ffstream(st); | |
2555 | 8210 | AVCodecContext *const avctx = sti->avctx; | |
2556 | |||
2557 | /* check if the caller has overridden the codec id */ | ||
2558 | // only for the split stuff | ||
2559 |
4/6✓ Branch 0 taken 8210 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8210 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7703 times.
✓ Branch 5 taken 507 times.
|
8210 | if (!sti->parser && !(ic->flags & AVFMT_FLAG_NOPARSE) && sti->request_probe <= 0) { |
2560 | 7703 | sti->parser = av_parser_init(st->codecpar->codec_id); | |
2561 |
2/2✓ Branch 0 taken 5366 times.
✓ Branch 1 taken 2337 times.
|
7703 | if (sti->parser) { |
2562 |
2/2✓ Branch 0 taken 754 times.
✓ Branch 1 taken 4612 times.
|
5366 | if (sti->need_parsing == AVSTREAM_PARSE_HEADERS) { |
2563 | 754 | sti->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES; | |
2564 |
2/2✓ Branch 0 taken 820 times.
✓ Branch 1 taken 3792 times.
|
4612 | } else if (sti->need_parsing == AVSTREAM_PARSE_FULL_RAW) { |
2565 | 820 | sti->parser->flags |= PARSER_FLAG_USE_CODEC_TS; | |
2566 | } | ||
2567 |
2/2✓ Branch 0 taken 654 times.
✓ Branch 1 taken 1683 times.
|
2337 | } else if (sti->need_parsing) { |
2568 | 654 | av_log(ic, AV_LOG_VERBOSE, "parser not found for codec " | |
2569 | "%s, packets or times may be invalid.\n", | ||
2570 | 654 | avcodec_get_name(st->codecpar->codec_id)); | |
2571 | } | ||
2572 | } | ||
2573 | |||
2574 | 8210 | ret = avcodec_parameters_to_context(avctx, st->codecpar); | |
2575 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8210 times.
|
8210 | if (ret < 0) |
2576 | ✗ | goto find_stream_info_err; | |
2577 |
2/2✓ Branch 0 taken 7703 times.
✓ Branch 1 taken 507 times.
|
8210 | if (sti->request_probe <= 0) |
2578 | 7703 | sti->avctx_inited = 1; | |
2579 | |||
2580 | 8210 | codec = find_probe_decoder(ic, st, st->codecpar->codec_id); | |
2581 | |||
2582 | /* Force thread count to 1 since the H.264 decoder will not extract | ||
2583 | * SPS and PPS to extradata during multi-threaded decoding. */ | ||
2584 |
2/2✓ Branch 0 taken 7923 times.
✓ Branch 1 taken 287 times.
|
8210 | av_dict_set(options ? &options[i] : &thread_opt, "threads", "1", 0); |
2585 | /* Force lowres to 0. The decoder might reduce the video size by the | ||
2586 | * lowres factor, and we don't want that propagated to the stream's | ||
2587 | * codecpar */ | ||
2588 |
2/2✓ Branch 0 taken 7923 times.
✓ Branch 1 taken 287 times.
|
8210 | av_dict_set(options ? &options[i] : &thread_opt, "lowres", "0", 0); |
2589 | |||
2590 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8210 times.
|
8210 | if (ic->codec_whitelist) |
2591 | ✗ | av_dict_set(options ? &options[i] : &thread_opt, "codec_whitelist", ic->codec_whitelist, 0); | |
2592 | |||
2593 | // Try to just open decoders, in case this is enough to get parameters. | ||
2594 | // Also ensure that subtitle_header is properly set. | ||
2595 |
4/4✓ Branch 1 taken 7391 times.
✓ Branch 2 taken 819 times.
✓ Branch 3 taken 506 times.
✓ Branch 4 taken 6885 times.
|
8210 | if (!has_codec_parameters(st, NULL) && sti->request_probe <= 0 || |
2596 |
2/2✓ Branch 0 taken 78 times.
✓ Branch 1 taken 1247 times.
|
1325 | st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) { |
2597 |
3/4✓ Branch 0 taken 6944 times.
✓ Branch 1 taken 19 times.
✓ Branch 2 taken 6944 times.
✗ Branch 3 not taken.
|
6963 | if (codec && !avctx->codec) |
2598 |
4/4✓ Branch 0 taken 6661 times.
✓ Branch 1 taken 283 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 6938 times.
|
6944 | if (avcodec_open2(avctx, codec, options ? &options[i] : &thread_opt) < 0) |
2599 | 6 | av_log(ic, AV_LOG_WARNING, | |
2600 | "Failed to open codec in %s\n", __func__); | ||
2601 | } | ||
2602 |
2/2✓ Branch 0 taken 287 times.
✓ Branch 1 taken 7923 times.
|
8210 | if (!options) |
2603 | 287 | av_dict_free(&thread_opt); | |
2604 | } | ||
2605 | |||
2606 | 7580 | read_size = 0; | |
2607 | 191585 | for (;;) { | |
2608 | const AVPacket *pkt; | ||
2609 | AVStream *st; | ||
2610 | FFStream *sti; | ||
2611 | AVCodecContext *avctx; | ||
2612 | int analyzed_all_streams; | ||
2613 | unsigned i; | ||
2614 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 199165 times.
|
199165 | if (ff_check_interrupt(&ic->interrupt_callback)) { |
2615 | ✗ | ret = AVERROR_EXIT; | |
2616 | ✗ | av_log(ic, AV_LOG_DEBUG, "interrupted\n"); | |
2617 | ✗ | break; | |
2618 | } | ||
2619 | |||
2620 | /* check if one codec still needs to be handled */ | ||
2621 |
2/2✓ Branch 0 taken 207768 times.
✓ Branch 1 taken 110237 times.
|
318005 | for (i = 0; i < ic->nb_streams; i++) { |
2622 | 207768 | AVStream *const st = ic->streams[i]; | |
2623 | 207768 | FFStream *const sti = ffstream(st); | |
2624 | 207768 | int fps_analyze_framecount = 20; | |
2625 | int count; | ||
2626 | |||
2627 |
2/2✓ Branch 1 taken 7372 times.
✓ Branch 2 taken 200396 times.
|
207768 | if (!has_codec_parameters(st, NULL)) |
2628 | 7372 | break; | |
2629 | /* If the timebase is coarse (like the usual millisecond precision | ||
2630 | * of mkv), we need to analyze more frames to reliably arrive at | ||
2631 | * the correct fps. */ | ||
2632 |
2/2✓ Branch 1 taken 120905 times.
✓ Branch 2 taken 79491 times.
|
200396 | if (av_q2d(st->time_base) > 0.0005) |
2633 | 120905 | fps_analyze_framecount *= 2; | |
2634 |
2/2✓ Branch 1 taken 8439 times.
✓ Branch 2 taken 191957 times.
|
200396 | if (!tb_unreliable(ic, st)) |
2635 | 8439 | fps_analyze_framecount = 0; | |
2636 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 200396 times.
|
200396 | if (ic->fps_probe_size >= 0) |
2637 | ✗ | fps_analyze_framecount = ic->fps_probe_size; | |
2638 |
2/2✓ Branch 0 taken 44 times.
✓ Branch 1 taken 200352 times.
|
200396 | if (st->disposition & AV_DISPOSITION_ATTACHED_PIC) |
2639 | 44 | fps_analyze_framecount = 0; | |
2640 | /* variable fps and no guess at the real fps */ | ||
2641 |
2/2✓ Branch 0 taken 19401 times.
✓ Branch 1 taken 180995 times.
|
200396 | count = (ic->iformat->flags & AVFMT_NOTIMESTAMPS) ? |
2642 | 19401 | sti->info->codec_info_duration_fields/2 : | |
2643 | 180995 | sti->info->duration_count; | |
2644 |
4/4✓ Branch 0 taken 101672 times.
✓ Branch 1 taken 98724 times.
✓ Branch 2 taken 223 times.
✓ Branch 3 taken 101449 times.
|
200396 | if (!(st->r_frame_rate.num && st->avg_frame_rate.num) && |
2645 |
2/2✓ Branch 0 taken 43041 times.
✓ Branch 1 taken 55906 times.
|
98947 | st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { |
2646 |
2/2✓ Branch 0 taken 24935 times.
✓ Branch 1 taken 18106 times.
|
43041 | if (count < fps_analyze_framecount) |
2647 | 24935 | break; | |
2648 | } | ||
2649 | // Look at the first 3 frames if there is evidence of frame delay | ||
2650 | // but the decoder delay is not set. | ||
2651 |
6/6✓ Branch 0 taken 2898 times.
✓ Branch 1 taken 172563 times.
✓ Branch 2 taken 130 times.
✓ Branch 3 taken 2768 times.
✓ Branch 4 taken 12 times.
✓ Branch 5 taken 118 times.
|
175461 | if (sti->info->frame_delay_evidence && count < 2 && sti->avctx->has_b_frames == 0) |
2652 | 12 | break; | |
2653 |
2/2✓ Branch 0 taken 155201 times.
✓ Branch 1 taken 20248 times.
|
175449 | if (!sti->avctx->extradata && |
2654 |
6/6✓ Branch 0 taken 153398 times.
✓ Branch 1 taken 1803 times.
✓ Branch 2 taken 110 times.
✓ Branch 3 taken 153288 times.
✓ Branch 4 taken 110 times.
✓ Branch 5 taken 1803 times.
|
157114 | (!sti->extract_extradata.inited || sti->extract_extradata.bsf) && |
2655 | 1913 | extract_extradata_check(st)) | |
2656 | 110 | break; | |
2657 |
2/2✓ Branch 0 taken 59657 times.
✓ Branch 1 taken 115682 times.
|
175339 | if (sti->first_dts == AV_NOPTS_VALUE && |
2658 |
6/6✓ Branch 0 taken 9433 times.
✓ Branch 1 taken 50224 times.
✓ Branch 2 taken 9349 times.
✓ Branch 3 taken 84 times.
✓ Branch 4 taken 57282 times.
✓ Branch 5 taken 2291 times.
|
119230 | (!(ic->iformat->flags & AVFMT_NOTIMESTAMPS) || sti->need_parsing == AVSTREAM_PARSE_FULL_RAW) && |
2659 |
2/2✓ Branch 0 taken 59529 times.
✓ Branch 1 taken 44 times.
|
59573 | sti->codec_info_nb_frames < ((st->disposition & AV_DISPOSITION_ATTACHED_PIC) ? 1 : ic->max_ts_probe) && |
2660 |
2/2✓ Branch 0 taken 41469 times.
✓ Branch 1 taken 15813 times.
|
57282 | (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || |
2661 |
2/2✓ Branch 0 taken 783 times.
✓ Branch 1 taken 40686 times.
|
41469 | st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)) |
2662 | break; | ||
2663 | } | ||
2664 | 199165 | analyzed_all_streams = 0; | |
2665 |
4/4✓ Branch 0 taken 110237 times.
✓ Branch 1 taken 88928 times.
✓ Branch 2 taken 110198 times.
✓ Branch 3 taken 39 times.
|
199165 | if (i == ic->nb_streams && !si->missing_streams) { |
2666 | 110198 | analyzed_all_streams = 1; | |
2667 | /* NOTE: If the format has no header, then we need to read some | ||
2668 | * packets to get most of the streams, so we cannot stop here. */ | ||
2669 |
2/2✓ Branch 0 taken 3317 times.
✓ Branch 1 taken 106881 times.
|
110198 | if (!(ic->ctx_flags & AVFMTCTX_NOHEADER)) { |
2670 | /* If we found the info for all the codecs, we can stop. */ | ||
2671 | 3317 | ret = count; | |
2672 | 3317 | av_log(ic, AV_LOG_DEBUG, "All info found\n"); | |
2673 | 3317 | flush_codecs = 0; | |
2674 | 3317 | break; | |
2675 | } | ||
2676 | } | ||
2677 | /* We did not get all the codec info, but we read too much data. */ | ||
2678 |
2/2✓ Branch 0 taken 2979 times.
✓ Branch 1 taken 192869 times.
|
195848 | if (read_size >= probesize) { |
2679 | 2979 | ret = count; | |
2680 | 2979 | av_log(ic, AV_LOG_DEBUG, | |
2681 | "Probe buffer size limit of %"PRId64" bytes reached\n", probesize); | ||
2682 |
2/2✓ Branch 0 taken 2993 times.
✓ Branch 1 taken 2979 times.
|
5972 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
2683 | 2993 | AVStream *const st = ic->streams[i]; | |
2684 | 2993 | FFStream *const sti = ffstream(st); | |
2685 |
2/2✓ Branch 0 taken 55 times.
✓ Branch 1 taken 2938 times.
|
2993 | if (!st->r_frame_rate.num && |
2686 |
2/2✓ Branch 0 taken 15 times.
✓ Branch 1 taken 40 times.
|
55 | sti->info->duration_count <= 1 && |
2687 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 14 times.
|
15 | st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && |
2688 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | strcmp(ic->iformat->name, "image2")) |
2689 | 1 | av_log(ic, AV_LOG_WARNING, | |
2690 | "Stream #%d: not enough frames to estimate rate; " | ||
2691 | "consider increasing probesize\n", i); | ||
2692 | } | ||
2693 | 2979 | break; | |
2694 | } | ||
2695 | |||
2696 | /* NOTE: A new stream can be added there if no header in file | ||
2697 | * (AVFMTCTX_NOHEADER). */ | ||
2698 | 192869 | ret = read_frame_internal(ic, pkt1); | |
2699 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 192869 times.
|
192869 | if (ret == AVERROR(EAGAIN)) |
2700 | ✗ | continue; | |
2701 | |||
2702 |
2/2✓ Branch 0 taken 1190 times.
✓ Branch 1 taken 191679 times.
|
192869 | if (ret < 0) { |
2703 | /* EOF or error*/ | ||
2704 | 1190 | eof_reached = 1; | |
2705 | 1190 | break; | |
2706 | } | ||
2707 | |||
2708 |
1/2✓ Branch 0 taken 191679 times.
✗ Branch 1 not taken.
|
191679 | if (!(ic->flags & AVFMT_FLAG_NOBUFFER)) { |
2709 | 191679 | ret = avpriv_packet_list_put(&si->packet_buffer, | |
2710 | pkt1, NULL, 0); | ||
2711 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 191679 times.
|
191679 | if (ret < 0) |
2712 | ✗ | goto unref_then_goto_end; | |
2713 | |||
2714 | 191679 | pkt = &si->packet_buffer.tail->pkt; | |
2715 | } else { | ||
2716 | ✗ | pkt = pkt1; | |
2717 | } | ||
2718 | |||
2719 | 191679 | st = ic->streams[pkt->stream_index]; | |
2720 | 191679 | sti = ffstream(st); | |
2721 |
2/2✓ Branch 0 taken 191623 times.
✓ Branch 1 taken 56 times.
|
191679 | if (!(st->disposition & AV_DISPOSITION_ATTACHED_PIC)) |
2722 | 191623 | read_size += pkt->size; | |
2723 | |||
2724 | 191679 | avctx = sti->avctx; | |
2725 |
2/2✓ Branch 0 taken 679 times.
✓ Branch 1 taken 191000 times.
|
191679 | if (!sti->avctx_inited) { |
2726 | 679 | ret = avcodec_parameters_to_context(avctx, st->codecpar); | |
2727 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 679 times.
|
679 | if (ret < 0) |
2728 | ✗ | goto unref_then_goto_end; | |
2729 | 679 | sti->avctx_inited = 1; | |
2730 | } | ||
2731 | |||
2732 |
4/4✓ Branch 0 taken 175247 times.
✓ Branch 1 taken 16432 times.
✓ Branch 2 taken 162856 times.
✓ Branch 3 taken 12391 times.
|
191679 | if (pkt->dts != AV_NOPTS_VALUE && sti->codec_info_nb_frames > 1) { |
2733 | /* check for non-increasing dts */ | ||
2734 |
2/2✓ Branch 0 taken 157987 times.
✓ Branch 1 taken 4869 times.
|
162856 | if (sti->info->fps_last_dts != AV_NOPTS_VALUE && |
2735 |
2/2✓ Branch 0 taken 23 times.
✓ Branch 1 taken 157964 times.
|
157987 | sti->info->fps_last_dts >= pkt->dts) { |
2736 | 23 | av_log(ic, AV_LOG_DEBUG, | |
2737 | "Non-increasing DTS in stream %d: packet %d with DTS " | ||
2738 | "%"PRId64", packet %d with DTS %"PRId64"\n", | ||
2739 | 23 | st->index, sti->info->fps_last_dts_idx, | |
2740 | 23 | sti->info->fps_last_dts, sti->codec_info_nb_frames, | |
2741 | 23 | pkt->dts); | |
2742 | 23 | sti->info->fps_first_dts = | |
2743 | 23 | sti->info->fps_last_dts = AV_NOPTS_VALUE; | |
2744 | } | ||
2745 | /* Check for a discontinuity in dts. If the difference in dts | ||
2746 | * is more than 1000 times the average packet duration in the | ||
2747 | * sequence, we treat it as a discontinuity. */ | ||
2748 |
2/2✓ Branch 0 taken 157964 times.
✓ Branch 1 taken 4892 times.
|
162856 | if (sti->info->fps_last_dts != AV_NOPTS_VALUE && |
2749 |
2/2✓ Branch 0 taken 153124 times.
✓ Branch 1 taken 4840 times.
|
157964 | sti->info->fps_last_dts_idx > sti->info->fps_first_dts_idx && |
2750 | 153124 | (pkt->dts - (uint64_t)sti->info->fps_last_dts) / 1000 > | |
2751 | 153124 | (sti->info->fps_last_dts - (uint64_t)sti->info->fps_first_dts) / | |
2752 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 153124 times.
|
153124 | (sti->info->fps_last_dts_idx - sti->info->fps_first_dts_idx)) { |
2753 | ✗ | av_log(ic, AV_LOG_WARNING, | |
2754 | "DTS discontinuity in stream %d: packet %d with DTS " | ||
2755 | "%"PRId64", packet %d with DTS %"PRId64"\n", | ||
2756 | ✗ | st->index, sti->info->fps_last_dts_idx, | |
2757 | ✗ | sti->info->fps_last_dts, sti->codec_info_nb_frames, | |
2758 | ✗ | pkt->dts); | |
2759 | ✗ | sti->info->fps_first_dts = | |
2760 | ✗ | sti->info->fps_last_dts = AV_NOPTS_VALUE; | |
2761 | } | ||
2762 | |||
2763 | /* update stored dts values */ | ||
2764 |
2/2✓ Branch 0 taken 4892 times.
✓ Branch 1 taken 157964 times.
|
162856 | if (sti->info->fps_first_dts == AV_NOPTS_VALUE) { |
2765 | 4892 | sti->info->fps_first_dts = pkt->dts; | |
2766 | 4892 | sti->info->fps_first_dts_idx = sti->codec_info_nb_frames; | |
2767 | } | ||
2768 | 162856 | sti->info->fps_last_dts = pkt->dts; | |
2769 | 162856 | sti->info->fps_last_dts_idx = sti->codec_info_nb_frames; | |
2770 | } | ||
2771 |
2/2✓ Branch 0 taken 178114 times.
✓ Branch 1 taken 13565 times.
|
191679 | if (sti->codec_info_nb_frames > 1) { |
2772 | 178114 | int64_t t = 0; | |
2773 | int64_t limit; | ||
2774 | |||
2775 |
1/2✓ Branch 0 taken 178114 times.
✗ Branch 1 not taken.
|
178114 | if (st->time_base.den > 0) |
2776 | 178114 | t = av_rescale_q(sti->info->codec_info_duration, st->time_base, AV_TIME_BASE_Q); | |
2777 |
2/2✓ Branch 0 taken 113099 times.
✓ Branch 1 taken 65015 times.
|
178114 | if (st->avg_frame_rate.num > 0) |
2778 |
2/2✓ Branch 1 taken 112572 times.
✓ Branch 2 taken 527 times.
|
113099 | t = FFMAX(t, av_rescale_q(sti->codec_info_nb_frames, av_inv_q(st->avg_frame_rate), AV_TIME_BASE_Q)); |
2779 | |||
2780 |
2/2✓ Branch 0 taken 4108 times.
✓ Branch 1 taken 174006 times.
|
178114 | if ( t == 0 |
2781 |
2/2✓ Branch 0 taken 535 times.
✓ Branch 1 taken 3573 times.
|
4108 | && sti->codec_info_nb_frames > 30 |
2782 |
2/2✓ Branch 0 taken 497 times.
✓ Branch 1 taken 38 times.
|
535 | && sti->info->fps_first_dts != AV_NOPTS_VALUE |
2783 |
1/2✓ Branch 0 taken 497 times.
✗ Branch 1 not taken.
|
497 | && sti->info->fps_last_dts != AV_NOPTS_VALUE) { |
2784 | 497 | int64_t dur = av_sat_sub64(sti->info->fps_last_dts, sti->info->fps_first_dts); | |
2785 |
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)); |
2786 | } | ||
2787 | |||
2788 |
2/2✓ Branch 0 taken 100651 times.
✓ Branch 1 taken 77463 times.
|
178114 | if (analyzed_all_streams) limit = max_analyze_duration; |
2789 |
2/2✓ Branch 0 taken 91 times.
✓ Branch 1 taken 77372 times.
|
77463 | else if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE) limit = max_subtitle_analyze_duration; |
2790 | 77372 | else limit = max_stream_analyze_duration; | |
2791 | |||
2792 |
2/2✓ Branch 0 taken 94 times.
✓ Branch 1 taken 178020 times.
|
178114 | if (t >= limit) { |
2793 | 94 | av_log(ic, AV_LOG_VERBOSE, "max_analyze_duration %"PRId64" reached at %"PRId64" microseconds st:%d\n", | |
2794 | limit, | ||
2795 | 94 | t, pkt->stream_index); | |
2796 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 94 times.
|
94 | if (ic->flags & AVFMT_FLAG_NOBUFFER) |
2797 | ✗ | av_packet_unref(pkt1); | |
2798 | 94 | break; | |
2799 | } | ||
2800 |
3/4✓ Branch 0 taken 174374 times.
✓ Branch 1 taken 3646 times.
✓ Branch 2 taken 174374 times.
✗ Branch 3 not taken.
|
178020 | if (pkt->duration > 0 && pkt->duration < INT64_MAX - sti->info->codec_info_duration) { |
2801 |
4/4✓ Branch 0 taken 174330 times.
✓ Branch 1 taken 44 times.
✓ Branch 2 taken 14236 times.
✓ Branch 3 taken 160094 times.
|
174374 | const int fields = sti->codec_desc && (sti->codec_desc->props & AV_CODEC_PROP_FIELDS); |
2802 |
1/8✗ Branch 0 not taken.
✓ Branch 1 taken 174374 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.
|
174374 | if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE && pkt->pts != AV_NOPTS_VALUE && st->start_time != AV_NOPTS_VALUE && pkt->pts >= st->start_time |
2803 | ✗ | && (uint64_t)pkt->pts - st->start_time < INT64_MAX | |
2804 | ) { | ||
2805 | ✗ | sti->info->codec_info_duration = FFMIN(pkt->pts - st->start_time, sti->info->codec_info_duration + pkt->duration); | |
2806 | } else | ||
2807 | 174374 | sti->info->codec_info_duration += pkt->duration; | |
2808 |
4/4✓ Branch 0 taken 35697 times.
✓ Branch 1 taken 92237 times.
✓ Branch 2 taken 13864 times.
✓ Branch 3 taken 21833 times.
|
302308 | sti->info->codec_info_duration_fields += sti->parser && sti->need_parsing && fields |
2809 |
2/2✓ Branch 0 taken 127934 times.
✓ Branch 1 taken 46440 times.
|
302308 | ? sti->parser->repeat_pict + 1 : 2; |
2810 | } | ||
2811 | } | ||
2812 |
2/2✓ Branch 0 taken 131719 times.
✓ Branch 1 taken 59866 times.
|
191585 | if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { |
2813 | #if FF_API_R_FRAME_RATE | ||
2814 | 131719 | ff_rfps_add_frame(ic, st, pkt->dts); | |
2815 | #endif | ||
2816 |
6/6✓ Branch 0 taken 4229 times.
✓ Branch 1 taken 127490 times.
✓ Branch 2 taken 3990 times.
✓ Branch 3 taken 239 times.
✓ Branch 4 taken 1965 times.
✓ Branch 5 taken 2025 times.
|
131719 | if (pkt->dts != pkt->pts && pkt->dts != AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE) |
2817 | 1965 | sti->info->frame_delay_evidence = 1; | |
2818 | } | ||
2819 |
2/2✓ Branch 0 taken 160615 times.
✓ Branch 1 taken 30970 times.
|
191585 | if (!sti->avctx->extradata) { |
2820 | 160615 | ret = extract_extradata(si, st, pkt); | |
2821 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 160615 times.
|
160615 | if (ret < 0) |
2822 | ✗ | goto unref_then_goto_end; | |
2823 | } | ||
2824 | |||
2825 | /* If still no information, we try to open the codec and to | ||
2826 | * decompress the frame. We try to avoid that in most cases as | ||
2827 | * it takes longer and uses more memory. For MPEG-4, we need to | ||
2828 | * decompress for QuickTime. | ||
2829 | * | ||
2830 | * If AV_CODEC_CAP_CHANNEL_CONF is set this will force decoding of at | ||
2831 | * least one frame of codec data, this makes sure the codec initializes | ||
2832 | * the channel configuration and does not only trust the values from | ||
2833 | * the container. */ | ||
2834 |
2/2✓ Branch 0 taken 174073 times.
✓ Branch 1 taken 17512 times.
|
365658 | try_decode_frame(ic, st, pkt, |
2835 |
2/2✓ Branch 0 taken 77731 times.
✓ Branch 1 taken 96342 times.
|
174073 | (options && i < orig_nb_streams) ? &options[i] : NULL); |
2836 | |||
2837 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 191585 times.
|
191585 | if (ic->flags & AVFMT_FLAG_NOBUFFER) |
2838 | ✗ | av_packet_unref(pkt1); | |
2839 | |||
2840 | 191585 | sti->codec_info_nb_frames++; | |
2841 | 191585 | count++; | |
2842 | } | ||
2843 | |||
2844 |
2/2✓ Branch 0 taken 1190 times.
✓ Branch 1 taken 6390 times.
|
7580 | if (eof_reached) { |
2845 |
2/2✓ Branch 0 taken 1485 times.
✓ Branch 1 taken 1190 times.
|
2675 | for (unsigned stream_index = 0; stream_index < ic->nb_streams; stream_index++) { |
2846 | 1485 | AVStream *const st = ic->streams[stream_index]; | |
2847 | 1485 | AVCodecContext *const avctx = ffstream(st)->avctx; | |
2848 |
2/2✓ Branch 1 taken 28 times.
✓ Branch 2 taken 1457 times.
|
1485 | if (!has_codec_parameters(st, NULL)) { |
2849 | 28 | const AVCodec *codec = find_probe_decoder(ic, st, st->codecpar->codec_id); | |
2850 |
4/4✓ Branch 0 taken 21 times.
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 13 times.
|
28 | if (codec && !avctx->codec) { |
2851 | 8 | AVDictionary *opts = NULL; | |
2852 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
|
8 | if (ic->codec_whitelist) |
2853 | ✗ | av_dict_set(&opts, "codec_whitelist", ic->codec_whitelist, 0); | |
2854 |
4/6✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 8 times.
|
8 | if (avcodec_open2(avctx, codec, (options && stream_index < orig_nb_streams) ? &options[stream_index] : &opts) < 0) |
2855 | ✗ | av_log(ic, AV_LOG_WARNING, | |
2856 | "Failed to open codec in %s\n", __func__); | ||
2857 | 8 | av_dict_free(&opts); | |
2858 | } | ||
2859 | } | ||
2860 | |||
2861 | // EOF already reached while reading the stream above. | ||
2862 | // So continue with reoordering DTS with whatever delay we have. | ||
2863 |
4/4✓ Branch 0 taken 1467 times.
✓ Branch 1 taken 18 times.
✓ Branch 3 taken 18 times.
✓ Branch 4 taken 1449 times.
|
1485 | if (si->packet_buffer.head && !has_decode_delay_been_guessed(st)) { |
2864 | 18 | update_dts_from_pts(ic, stream_index, si->packet_buffer.head); | |
2865 | } | ||
2866 | } | ||
2867 | } | ||
2868 | |||
2869 |
2/2✓ Branch 0 taken 4263 times.
✓ Branch 1 taken 3317 times.
|
7580 | if (flush_codecs) { |
2870 | 4263 | AVPacket *empty_pkt = si->pkt; | |
2871 | 4263 | int err = 0; | |
2872 | 4263 | av_packet_unref(empty_pkt); | |
2873 | |||
2874 |
2/2✓ Branch 0 taken 4611 times.
✓ Branch 1 taken 4263 times.
|
8874 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
2875 | 4611 | AVStream *const st = ic->streams[i]; | |
2876 | 4611 | FFStream *const sti = ffstream(st); | |
2877 | |||
2878 | /* flush the decoders */ | ||
2879 |
2/2✓ Branch 0 taken 4543 times.
✓ Branch 1 taken 68 times.
|
4611 | if (sti->info->found_decoder == 1) { |
2880 |
2/2✓ Branch 0 taken 4226 times.
✓ Branch 1 taken 317 times.
|
8769 | err = try_decode_frame(ic, st, empty_pkt, |
2881 |
2/2✓ Branch 0 taken 4210 times.
✓ Branch 1 taken 16 times.
|
4226 | (options && i < orig_nb_streams) |
2882 | 4210 | ? &options[i] : NULL); | |
2883 | |||
2884 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4543 times.
|
4543 | if (err < 0) { |
2885 | ✗ | av_log(ic, AV_LOG_INFO, | |
2886 | "decoding for stream %d failed\n", st->index); | ||
2887 | } | ||
2888 | } | ||
2889 | } | ||
2890 | } | ||
2891 | |||
2892 | 7580 | ff_rfps_calculate(ic); | |
2893 | |||
2894 |
2/2✓ Branch 0 taken 8395 times.
✓ Branch 1 taken 7580 times.
|
15975 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
2895 | 8395 | AVStream *const st = ic->streams[i]; | |
2896 | 8395 | FFStream *const sti = ffstream(st); | |
2897 | 8395 | AVCodecContext *const avctx = sti->avctx; | |
2898 | |||
2899 |
2/2✓ Branch 0 taken 6260 times.
✓ Branch 1 taken 2135 times.
|
8395 | if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) { |
2900 |
6/6✓ Branch 0 taken 638 times.
✓ Branch 1 taken 5622 times.
✓ Branch 2 taken 589 times.
✓ Branch 3 taken 49 times.
✓ Branch 4 taken 573 times.
✓ Branch 5 taken 16 times.
|
6260 | if (avctx->codec_id == AV_CODEC_ID_RAWVIDEO && !avctx->codec_tag && !avctx->bits_per_coded_sample) { |
2901 | 573 | uint32_t tag= avcodec_pix_fmt_to_codec_tag(avctx->pix_fmt); | |
2902 |
2/2✓ Branch 1 taken 566 times.
✓ Branch 2 taken 7 times.
|
573 | if (avpriv_pix_fmt_find(PIX_FMT_LIST_RAW, tag) == avctx->pix_fmt) |
2903 | 566 | avctx->codec_tag= tag; | |
2904 | } | ||
2905 | |||
2906 | /* estimate average framerate if not set by demuxer */ | ||
2907 |
2/2✓ Branch 0 taken 4007 times.
✓ Branch 1 taken 2253 times.
|
6260 | if (sti->info->codec_info_duration_fields && |
2908 |
2/2✓ Branch 0 taken 269 times.
✓ Branch 1 taken 3738 times.
|
4007 | !st->avg_frame_rate.num && |
2909 |
1/2✓ Branch 0 taken 269 times.
✗ Branch 1 not taken.
|
269 | sti->info->codec_info_duration) { |
2910 | 269 | int best_fps = 0; | |
2911 | 269 | double best_error = 0.01; | |
2912 | 269 | AVRational codec_frame_rate = avctx->framerate; | |
2913 | |||
2914 |
1/2✓ Branch 0 taken 269 times.
✗ Branch 1 not taken.
|
269 | if (sti->info->codec_info_duration >= INT64_MAX / st->time_base.num / 2|| |
2915 |
1/2✓ Branch 0 taken 269 times.
✗ Branch 1 not taken.
|
269 | sti->info->codec_info_duration_fields >= INT64_MAX / st->time_base.den || |
2916 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 269 times.
|
269 | sti->info->codec_info_duration < 0) |
2917 | ✗ | continue; | |
2918 | 269 | av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den, | |
2919 | 269 | sti->info->codec_info_duration_fields * (int64_t) st->time_base.den, | |
2920 | 269 | sti->info->codec_info_duration * 2 * (int64_t) st->time_base.num, 60000); | |
2921 | |||
2922 | /* Round guessed framerate to a "standard" framerate if it's | ||
2923 | * within 1% of the original estimate. */ | ||
2924 |
2/2✓ Branch 0 taken 107331 times.
✓ Branch 1 taken 269 times.
|
107600 | for (int j = 0; j < MAX_STD_TIMEBASES; j++) { |
2925 | 107331 | AVRational std_fps = { get_std_framerate(j), 12 * 1001 }; | |
2926 | 107331 | double error = fabs(av_q2d(st->avg_frame_rate) / | |
2927 | 107331 | av_q2d(std_fps) - 1); | |
2928 | |||
2929 |
2/2✓ Branch 0 taken 736 times.
✓ Branch 1 taken 106595 times.
|
107331 | if (error < best_error) { |
2930 | 736 | best_error = error; | |
2931 | 736 | best_fps = std_fps.num; | |
2932 | } | ||
2933 | |||
2934 |
2/2✓ Branch 1 taken 12768 times.
✓ Branch 2 taken 94563 times.
|
107331 | if ((ffifmt(ic->iformat)->flags_internal & FF_INFMT_FLAG_PREFER_CODEC_FRAMERATE) && |
2935 |
2/4✓ Branch 0 taken 12768 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12768 times.
✗ Branch 3 not taken.
|
12768 | codec_frame_rate.num > 0 && codec_frame_rate.den > 0) { |
2936 | 12768 | error = fabs(av_q2d(codec_frame_rate) / | |
2937 | 12768 | av_q2d(std_fps) - 1); | |
2938 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 12758 times.
|
12768 | if (error < best_error) { |
2939 | 10 | best_error = error; | |
2940 | 10 | best_fps = std_fps.num; | |
2941 | } | ||
2942 | } | ||
2943 | } | ||
2944 |
2/2✓ Branch 0 taken 267 times.
✓ Branch 1 taken 2 times.
|
269 | if (best_fps) |
2945 | 267 | av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den, | |
2946 | best_fps, 12 * 1001, INT_MAX); | ||
2947 | } | ||
2948 |
2/2✓ Branch 0 taken 1858 times.
✓ Branch 1 taken 4402 times.
|
6260 | if (!st->r_frame_rate.num) { |
2949 | 1858 | const AVCodecDescriptor *desc = sti->codec_desc; | |
2950 |
3/4✓ Branch 0 taken 1858 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 246 times.
✓ Branch 3 taken 1612 times.
|
1858 | AVRational mul = (AVRational){ desc && (desc->props & AV_CODEC_PROP_FIELDS) ? 2 : 1, 1 }; |
2951 | 1858 | AVRational fr = av_mul_q(avctx->framerate, mul); | |
2952 | |||
2953 |
5/6✓ Branch 0 taken 188 times.
✓ Branch 1 taken 1670 times.
✓ Branch 2 taken 188 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 174 times.
✓ Branch 7 taken 14 times.
|
1858 | if (fr.num && fr.den && av_cmp_q(st->time_base, av_inv_q(fr)) <= 0) { |
2954 | 174 | st->r_frame_rate = fr; | |
2955 | } else { | ||
2956 | 1684 | st->r_frame_rate.num = st->time_base.den; | |
2957 | 1684 | st->r_frame_rate.den = st->time_base.num; | |
2958 | } | ||
2959 | } | ||
2960 | 6260 | st->codecpar->framerate = avctx->framerate; | |
2961 |
3/4✓ Branch 0 taken 116 times.
✓ Branch 1 taken 6144 times.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
|
6260 | if (sti->display_aspect_ratio.num && sti->display_aspect_ratio.den) { |
2962 | 116 | AVRational hw_ratio = { avctx->height, avctx->width }; | |
2963 | 116 | st->sample_aspect_ratio = av_mul_q(sti->display_aspect_ratio, | |
2964 | hw_ratio); | ||
2965 | } | ||
2966 |
2/2✓ Branch 0 taken 1966 times.
✓ Branch 1 taken 169 times.
|
2135 | } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) { |
2967 |
2/2✓ Branch 0 taken 646 times.
✓ Branch 1 taken 1320 times.
|
1966 | if (!avctx->bits_per_coded_sample) |
2968 | 646 | avctx->bits_per_coded_sample = | |
2969 | 646 | av_get_bits_per_sample(avctx->codec_id); | |
2970 | // set stream disposition based on audio service type | ||
2971 |
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 1966 times.
|
1966 | switch (avctx->audio_service_type) { |
2972 | ✗ | case AV_AUDIO_SERVICE_TYPE_EFFECTS: | |
2973 | ✗ | st->disposition = AV_DISPOSITION_CLEAN_EFFECTS; | |
2974 | ✗ | break; | |
2975 | ✗ | case AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED: | |
2976 | ✗ | st->disposition = AV_DISPOSITION_VISUAL_IMPAIRED; | |
2977 | ✗ | break; | |
2978 | ✗ | case AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED: | |
2979 | ✗ | st->disposition = AV_DISPOSITION_HEARING_IMPAIRED; | |
2980 | ✗ | break; | |
2981 | ✗ | case AV_AUDIO_SERVICE_TYPE_COMMENTARY: | |
2982 | ✗ | st->disposition = AV_DISPOSITION_COMMENT; | |
2983 | ✗ | break; | |
2984 | ✗ | case AV_AUDIO_SERVICE_TYPE_KARAOKE: | |
2985 | ✗ | st->disposition = AV_DISPOSITION_KARAOKE; | |
2986 | ✗ | break; | |
2987 | } | ||
2988 | } | ||
2989 | } | ||
2990 | |||
2991 |
1/2✓ Branch 0 taken 7580 times.
✗ Branch 1 not taken.
|
7580 | if (probesize) |
2992 | 7580 | estimate_timings(ic, old_offset); | |
2993 | |||
2994 | 7580 | av_opt_set_int(ic, "skip_clear", 0, AV_OPT_SEARCH_CHILDREN); | |
2995 | |||
2996 |
3/4✓ Branch 0 taken 6390 times.
✓ Branch 1 taken 1190 times.
✓ Branch 2 taken 6390 times.
✗ Branch 3 not taken.
|
7580 | if (ret >= 0 && ic->nb_streams) |
2997 | /* We could not have all the codec parameters before EOF. */ | ||
2998 | 6390 | ret = -1; | |
2999 |
2/2✓ Branch 0 taken 8395 times.
✓ Branch 1 taken 7580 times.
|
15975 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
3000 | 8395 | AVStream *const st = ic->streams[i]; | |
3001 | 8395 | FFStream *const sti = ffstream(st); | |
3002 | const char *errmsg; | ||
3003 | |||
3004 | /* if no packet was ever seen, update context now for has_codec_parameters */ | ||
3005 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 8382 times.
|
8395 | if (!sti->avctx_inited) { |
3006 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 5 times.
|
13 | if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && |
3007 |
1/2✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
|
8 | st->codecpar->format == AV_SAMPLE_FMT_NONE) |
3008 | 8 | st->codecpar->format = sti->avctx->sample_fmt; | |
3009 | 13 | ret = avcodec_parameters_to_context(sti->avctx, st->codecpar); | |
3010 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
|
13 | if (ret < 0) |
3011 | ✗ | goto find_stream_info_err; | |
3012 | } | ||
3013 |
2/2✓ Branch 1 taken 26 times.
✓ Branch 2 taken 8369 times.
|
8395 | if (!has_codec_parameters(st, &errmsg)) { |
3014 | char buf[256]; | ||
3015 | 26 | avcodec_string(buf, sizeof(buf), sti->avctx, 0); | |
3016 | 26 | av_log(ic, AV_LOG_WARNING, | |
3017 | "Could not find codec parameters for stream %d (%s): %s\n" | ||
3018 | "Consider increasing the value for the 'analyzeduration' (%"PRId64") and 'probesize' (%"PRId64") options\n", | ||
3019 | i, buf, errmsg, ic->max_analyze_duration, ic->probesize); | ||
3020 | } else { | ||
3021 | 8369 | ret = 0; | |
3022 | } | ||
3023 | } | ||
3024 | |||
3025 | 7580 | err = compute_chapters_end(ic); | |
3026 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7580 times.
|
7580 | if (err < 0) { |
3027 | ✗ | ret = err; | |
3028 | ✗ | goto find_stream_info_err; | |
3029 | } | ||
3030 | |||
3031 | /* update the stream parameters from the internal codec contexts */ | ||
3032 |
2/2✓ Branch 0 taken 8395 times.
✓ Branch 1 taken 7580 times.
|
15975 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
3033 | 8395 | AVStream *const st = ic->streams[i]; | |
3034 | 8395 | FFStream *const sti = ffstream(st); | |
3035 | |||
3036 |
2/2✓ Branch 0 taken 8382 times.
✓ Branch 1 taken 13 times.
|
8395 | if (sti->avctx_inited) { |
3037 | 8382 | ret = avcodec_parameters_from_context(st->codecpar, sti->avctx); | |
3038 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8382 times.
|
8382 | if (ret < 0) |
3039 | ✗ | goto find_stream_info_err; | |
3040 | |||
3041 |
3/4✓ Branch 0 taken 8198 times.
✓ Branch 1 taken 184 times.
✓ Branch 2 taken 8198 times.
✗ Branch 3 not taken.
|
8382 | if (sti->avctx->rc_buffer_size > 0 || sti->avctx->rc_max_rate > 0 || |
3042 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8198 times.
|
8198 | sti->avctx->rc_min_rate) { |
3043 | size_t cpb_size; | ||
3044 | 184 | AVCPBProperties *props = av_cpb_properties_alloc(&cpb_size); | |
3045 |
1/2✓ Branch 0 taken 184 times.
✗ Branch 1 not taken.
|
184 | if (props) { |
3046 |
1/2✓ Branch 0 taken 184 times.
✗ Branch 1 not taken.
|
184 | if (sti->avctx->rc_buffer_size > 0) |
3047 | 184 | props->buffer_size = sti->avctx->rc_buffer_size; | |
3048 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 184 times.
|
184 | if (sti->avctx->rc_min_rate > 0) |
3049 | ✗ | props->min_bitrate = sti->avctx->rc_min_rate; | |
3050 |
2/2✓ Branch 0 taken 77 times.
✓ Branch 1 taken 107 times.
|
184 | if (sti->avctx->rc_max_rate > 0) |
3051 | 77 | props->max_bitrate = sti->avctx->rc_max_rate; | |
3052 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 184 times.
|
184 | if (!av_packet_side_data_add(&st->codecpar->coded_side_data, |
3053 | 184 | &st->codecpar->nb_coded_side_data, | |
3054 | AV_PKT_DATA_CPB_PROPERTIES, | ||
3055 | (uint8_t *)props, cpb_size, 0)) | ||
3056 | ✗ | av_free(props); | |
3057 | } | ||
3058 | } | ||
3059 | } | ||
3060 | |||
3061 | 8395 | sti->avctx_inited = 0; | |
3062 | } | ||
3063 | |||
3064 | 7580 | find_stream_info_err: | |
3065 |
2/2✓ Branch 0 taken 8395 times.
✓ Branch 1 taken 7580 times.
|
15975 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
3066 | 8395 | AVStream *const st = ic->streams[i]; | |
3067 | 8395 | FFStream *const sti = ffstream(st); | |
3068 | int err; | ||
3069 | |||
3070 |
1/2✓ Branch 0 taken 8395 times.
✗ Branch 1 not taken.
|
8395 | if (sti->info) { |
3071 | 8395 | av_freep(&sti->info->duration_error); | |
3072 | 8395 | av_freep(&sti->info); | |
3073 | } | ||
3074 | |||
3075 |
2/2✓ Branch 1 taken 8297 times.
✓ Branch 2 taken 98 times.
|
8395 | if (avcodec_is_open(sti->avctx)) { |
3076 | 8297 | err = codec_close(sti); | |
3077 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 8297 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
8297 | if (err < 0 && ret >= 0) |
3078 | ✗ | ret = err; | |
3079 | } | ||
3080 | |||
3081 | 8395 | av_bsf_free(&sti->extract_extradata.bsf); | |
3082 | } | ||
3083 |
2/2✓ Branch 0 taken 4526 times.
✓ Branch 1 taken 3054 times.
|
7580 | if (ic->pb) { |
3084 | 4526 | FFIOContext *const ctx = ffiocontext(ic->pb); | |
3085 | 4526 | av_log(ic, AV_LOG_DEBUG, "After avformat_find_stream_info() pos: %"PRId64" bytes read:%"PRId64" seeks:%d frames:%d\n", | |
3086 | avio_tell(ic->pb), ctx->bytes_read, ctx->seek_count, count); | ||
3087 | } | ||
3088 | 7580 | return ret; | |
3089 | |||
3090 | ✗ | unref_then_goto_end: | |
3091 | ✗ | av_packet_unref(pkt1); | |
3092 | ✗ | goto find_stream_info_err; | |
3093 | } | ||
3094 |