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 | 2474362 | static int64_t wrap_timestamp(const AVStream *st, int64_t timestamp) | |
54 | { | ||
55 | 2474362 | const FFStream *const sti = cffstream(st); | |
56 |
4/4✓ Branch 0 taken 150409 times.
✓ Branch 1 taken 2323953 times.
✓ Branch 2 taken 145823 times.
✓ Branch 3 taken 4586 times.
|
2474362 | if (sti->pts_wrap_behavior != AV_PTS_WRAP_IGNORE && st->pts_wrap_bits < 64 && |
57 |
3/4✓ Branch 0 taken 145823 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 88223 times.
✓ Branch 3 taken 57600 times.
|
145823 | sti->pts_wrap_reference != AV_NOPTS_VALUE && timestamp != AV_NOPTS_VALUE) { |
58 |
2/2✓ Branch 0 taken 88019 times.
✓ Branch 1 taken 204 times.
|
88223 | if (sti->pts_wrap_behavior == AV_PTS_WRAP_ADD_OFFSET && |
59 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 88019 times.
|
88019 | timestamp < sti->pts_wrap_reference) |
60 | ✗ | return timestamp + (1ULL << st->pts_wrap_bits); | |
61 |
2/2✓ Branch 0 taken 204 times.
✓ Branch 1 taken 88019 times.
|
88223 | 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 | 2474312 | return timestamp; | |
66 | } | ||
67 | |||
68 | 303906 | int64_t ff_wrap_timestamp(const AVStream *st, int64_t timestamp) | |
69 | { | ||
70 | 303906 | return wrap_timestamp(st, timestamp); | |
71 | } | ||
72 | |||
73 | 9660 | 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 9325 times.
|
9660 | if (codec_id == AV_CODEC_ID_H264) |
81 | 335 | return avcodec_find_decoder_by_name("h264"); | |
82 | #endif | ||
83 | |||
84 | 9325 | codec = ff_find_decoder(s, st, codec_id); | |
85 |
2/2✓ Branch 0 taken 171 times.
✓ Branch 1 taken 9154 times.
|
9325 | if (!codec) |
86 | 171 | return NULL; | |
87 | |||
88 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9154 times.
|
9154 | 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 | 9154 | return codec; | |
101 | } | ||
102 | |||
103 | 3025 | 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 | 3025 | const AVInputFormat *fmt = av_probe_input_format3(pd, 1, &score); | |
133 | 3025 | FFStream *const sti = ffstream(st); | |
134 | |||
135 |
2/2✓ Branch 0 taken 946 times.
✓ Branch 1 taken 2079 times.
|
3025 | if (fmt) { |
136 | 946 | av_log(s, AV_LOG_DEBUG, | |
137 | "Probe with size=%d, packets=%d detected %s with score=%d\n", | ||
138 | 946 | pd->buf_size, s->max_probe_packets - sti->probe_packets, | |
139 | 946 | fmt->name, score); | |
140 |
2/2✓ Branch 0 taken 16879 times.
✓ Branch 1 taken 924 times.
|
17803 | for (int i = 0; fmt_id_type[i].name; i++) { |
141 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 16855 times.
|
16879 | if (!strcmp(fmt->name, fmt_id_type[i].name)) { |
142 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 13 times.
|
24 | 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 6 times.
✓ Branch 1 taken 18 times.
|
24 | if (sti->request_probe > score && |
146 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
|
6 | st->codecpar->codec_id != fmt_id_type[i].id) |
147 | 2 | continue; | |
148 | 22 | st->codecpar->codec_id = fmt_id_type[i].id; | |
149 | 22 | st->codecpar->codec_type = fmt_id_type[i].type; | |
150 | 22 | sti->need_context_update = 1; | |
151 | 22 | return score; | |
152 | } | ||
153 | } | ||
154 | } | ||
155 | 3003 | return 0; | |
156 | } | ||
157 | |||
158 | 7591 | static int init_input(AVFormatContext *s, const char *filename, | |
159 | AVDictionary **options) | ||
160 | { | ||
161 | int ret; | ||
162 | 7591 | AVProbeData pd = { filename, NULL, 0 }; | |
163 | 7591 | int score = AVPROBE_SCORE_RETRY; | |
164 | |||
165 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 7579 times.
|
7591 | 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 3720 times.
✓ Branch 1 taken 3859 times.
✓ Branch 2 taken 854 times.
✓ Branch 3 taken 2866 times.
|
7579 | if ((s->iformat && s->iformat->flags & AVFMT_NOFILE) || |
177 |
4/4✓ Branch 0 taken 3859 times.
✓ Branch 1 taken 854 times.
✓ Branch 3 taken 193 times.
✓ Branch 4 taken 3666 times.
|
4713 | (!s->iformat && (s->iformat = av_probe_input_format2(&pd, 0, &score)))) |
178 | 3059 | return score; | |
179 | |||
180 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4520 times.
|
4520 | 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 854 times.
✓ Branch 1 taken 3666 times.
|
4520 | if (s->iformat) |
184 | 854 | return 0; | |
185 | 3666 | return av_probe_input_buffer2(s->pb, &s->iformat, filename, | |
186 | 3666 | s, 0, s->format_probesize); | |
187 | } | ||
188 | |||
189 | 7591 | static int update_stream_avctx(AVFormatContext *s) | |
190 | { | ||
191 | int ret; | ||
192 |
2/2✓ Branch 0 taken 8212 times.
✓ Branch 1 taken 7591 times.
|
15803 | for (unsigned i = 0; i < s->nb_streams; i++) { |
193 | 8212 | AVStream *const st = s->streams[i]; | |
194 | 8212 | FFStream *const sti = ffstream(st); | |
195 | |||
196 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8212 times.
|
8212 | 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 8212 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
8212 | 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 | 8212 | ret = avcodec_parameters_to_context(sti->avctx, st->codecpar); | |
207 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8212 times.
|
8212 | if (ret < 0) |
208 | ✗ | return ret; | |
209 | |||
210 | 8212 | sti->codec_desc = avcodec_descriptor_get(sti->avctx->codec_id); | |
211 | |||
212 | 8212 | sti->need_context_update = 0; | |
213 | } | ||
214 | 7591 | return 0; | |
215 | } | ||
216 | |||
217 | 7591 | int avformat_open_input(AVFormatContext **ps, const char *filename, | |
218 | const AVInputFormat *fmt, AVDictionary **options) | ||
219 | { | ||
220 | FormatContextInternal *fci; | ||
221 | 7591 | AVFormatContext *s = *ps; | |
222 | FFFormatContext *si; | ||
223 | 7591 | AVDictionary *tmp = NULL; | |
224 | 7591 | ID3v2ExtraMeta *id3v2_extra_meta = NULL; | |
225 | 7591 | int ret = 0; | |
226 | |||
227 |
3/4✓ Branch 0 taken 22 times.
✓ Branch 1 taken 7569 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 22 times.
|
7591 | if (!s && !(s = avformat_alloc_context())) |
228 | ✗ | return AVERROR(ENOMEM); | |
229 | 7591 | fci = ff_fc_internal(s); | |
230 | 7591 | si = &fci->fc; | |
231 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7591 times.
|
7591 | 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 3732 times.
✓ Branch 1 taken 3859 times.
|
7591 | if (fmt) |
236 | 3732 | s->iformat = fmt; | |
237 | |||
238 |
2/2✓ Branch 0 taken 7581 times.
✓ Branch 1 taken 10 times.
|
7591 | if (options) |
239 | 7581 | av_dict_copy(&tmp, *options, 0); | |
240 | |||
241 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 7579 times.
|
7591 | 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 7591 times.
|
7591 | if ((ret = av_opt_set_dict(s, &tmp)) < 0) |
245 | ✗ | goto fail; | |
246 | |||
247 |
2/4✓ Branch 0 taken 7591 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 7591 times.
|
7591 | 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 7591 times.
|
7591 | if ((ret = init_input(s, filename, &tmp)) < 0) |
253 | ✗ | goto fail; | |
254 | 7591 | s->probe_score = ret; | |
255 | |||
256 |
6/6✓ Branch 0 taken 7508 times.
✓ Branch 1 taken 83 times.
✓ Branch 2 taken 4449 times.
✓ Branch 3 taken 3059 times.
✓ Branch 4 taken 4448 times.
✓ Branch 5 taken 1 times.
|
7591 | if (!s->protocol_whitelist && s->pb && s->pb->protocol_whitelist) { |
257 | 4448 | s->protocol_whitelist = av_strdup(s->pb->protocol_whitelist); | |
258 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4448 times.
|
4448 | if (!s->protocol_whitelist) { |
259 | ✗ | ret = AVERROR(ENOMEM); | |
260 | ✗ | goto fail; | |
261 | } | ||
262 | } | ||
263 | |||
264 |
4/6✓ Branch 0 taken 7591 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4532 times.
✓ Branch 3 taken 3059 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4532 times.
|
7591 | 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 7591 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
7591 | 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 | 7591 | 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 7591 times.
|
7591 | if (s->iformat->flags & AVFMT_NEEDNUMBER) { |
282 | ✗ | if (!av_filename_number_test(filename)) { | |
283 | ✗ | ret = AVERROR(EINVAL); | |
284 | ✗ | goto fail; | |
285 | } | ||
286 | } | ||
287 | |||
288 | 7591 | s->duration = s->start_time = AV_NOPTS_VALUE; | |
289 | |||
290 | /* Allocate private data. */ | ||
291 |
2/2✓ Branch 1 taken 7434 times.
✓ Branch 2 taken 157 times.
|
7591 | if (ffifmt(s->iformat)->priv_data_size > 0) { |
292 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 7434 times.
|
7434 | 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 6605 times.
✓ Branch 1 taken 829 times.
|
7434 | if (s->iformat->priv_class) { |
297 | 6605 | *(const AVClass **) s->priv_data = s->iformat->priv_class; | |
298 | 6605 | av_opt_set_defaults(s->priv_data); | |
299 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 6605 times.
|
6605 | 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 4532 times.
✓ Branch 1 taken 3059 times.
|
7591 | if (s->pb) |
306 | 4532 | ff_id3v2_read_dict(s->pb, &si->id3v2_meta, ID3v2_DEFAULT_MAGIC, &id3v2_extra_meta); | |
307 | |||
308 |
1/2✓ Branch 1 taken 7591 times.
✗ Branch 2 not taken.
|
7591 | if (ffifmt(s->iformat)->read_header) |
309 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 7591 times.
|
7591 | 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 6316 times.
✓ Branch 1 taken 1275 times.
|
7591 | if (!s->metadata) { |
316 | 6316 | s->metadata = si->id3v2_meta; | |
317 | 6316 | si->id3v2_meta = NULL; | |
318 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1275 times.
|
1275 | } 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 7581 times.
|
7591 | 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 7591 times.
|
7591 | if ((ret = avformat_queue_attached_pictures(s)) < 0) |
338 | ✗ | goto close; | |
339 | |||
340 |
4/4✓ Branch 0 taken 4532 times.
✓ Branch 1 taken 3059 times.
✓ Branch 2 taken 4095 times.
✓ Branch 3 taken 437 times.
|
7591 | if (s->pb && !si->data_offset) |
341 | 4095 | si->data_offset = avio_tell(s->pb); | |
342 | |||
343 | 7591 | fci->raw_packet_buffer_size = 0; | |
344 | |||
345 | 7591 | update_stream_avctx(s); | |
346 | |||
347 |
2/2✓ Branch 0 taken 7581 times.
✓ Branch 1 taken 10 times.
|
7591 | if (options) { |
348 | 7581 | av_dict_free(options); | |
349 | 7581 | *options = tmp; | |
350 | } | ||
351 | 7591 | *ps = s; | |
352 | 7591 | 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 | 7591 | void avformat_close_input(AVFormatContext **ps) | |
368 | { | ||
369 | AVFormatContext *s; | ||
370 | AVIOContext *pb; | ||
371 | |||
372 |
2/4✓ Branch 0 taken 7591 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7591 times.
|
7591 | if (!ps || !*ps) |
373 | ✗ | return; | |
374 | |||
375 | 7591 | s = *ps; | |
376 | 7591 | pb = s->pb; | |
377 | |||
378 |
5/6✓ Branch 0 taken 7591 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4550 times.
✓ Branch 3 taken 3041 times.
✓ Branch 4 taken 4507 times.
✓ Branch 5 taken 43 times.
|
7591 | if ((s->iformat && strcmp(s->iformat->name, "image2") && s->iformat->flags & AVFMT_NOFILE) || |
379 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 7536 times.
|
7548 | (s->flags & AVFMT_FLAG_CUSTOM_IO)) |
380 | 55 | pb = NULL; | |
381 | |||
382 |
1/2✓ Branch 0 taken 7591 times.
✗ Branch 1 not taken.
|
7591 | if (s->iformat) |
383 |
2/2✓ Branch 1 taken 4931 times.
✓ Branch 2 taken 2660 times.
|
7591 | if (ffifmt(s->iformat)->read_close) |
384 | 4931 | ffifmt(s->iformat)->read_close(s); | |
385 | |||
386 | 7591 | avformat_free_context(s); | |
387 | |||
388 | 7591 | *ps = NULL; | |
389 | |||
390 | 7591 | avio_close(pb); | |
391 | } | ||
392 | |||
393 | 1088252 | static void force_codec_ids(AVFormatContext *s, AVStream *st) | |
394 | { | ||
395 |
5/5✓ Branch 0 taken 738730 times.
✓ Branch 1 taken 346424 times.
✓ Branch 2 taken 2968 times.
✓ Branch 3 taken 128 times.
✓ Branch 4 taken 2 times.
|
1088252 | switch (st->codecpar->codec_type) { |
396 | 738730 | case AVMEDIA_TYPE_VIDEO: | |
397 |
2/2✓ Branch 0 taken 115393 times.
✓ Branch 1 taken 623337 times.
|
738730 | if (s->video_codec_id) |
398 | 115393 | st->codecpar->codec_id = s->video_codec_id; | |
399 | 738730 | break; | |
400 | 346424 | case AVMEDIA_TYPE_AUDIO: | |
401 |
2/2✓ Branch 0 taken 2558 times.
✓ Branch 1 taken 343866 times.
|
346424 | if (s->audio_codec_id) |
402 | 2558 | st->codecpar->codec_id = s->audio_codec_id; | |
403 | 346424 | break; | |
404 | 2968 | case AVMEDIA_TYPE_SUBTITLE: | |
405 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2968 times.
|
2968 | if (s->subtitle_codec_id) |
406 | ✗ | st->codecpar->codec_id = s->subtitle_codec_id; | |
407 | 2968 | break; | |
408 | 128 | case AVMEDIA_TYPE_DATA: | |
409 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 128 times.
|
128 | if (s->data_codec_id) |
410 | ✗ | st->codecpar->codec_id = s->data_codec_id; | |
411 | 128 | break; | |
412 | } | ||
413 | 1088252 | } | |
414 | |||
415 | 22109 | static int probe_codec(AVFormatContext *s, AVStream *st, const AVPacket *pkt) | |
416 | { | ||
417 | 22109 | FormatContextInternal *const fci = ff_fc_internal(s); | |
418 | 22109 | FFStream *const sti = ffstream(st); | |
419 | |||
420 |
2/2✓ Branch 0 taken 15942 times.
✓ Branch 1 taken 6167 times.
|
22109 | if (sti->request_probe > 0) { |
421 | 15942 | AVProbeData *const pd = &sti->probe_data; | |
422 | int end; | ||
423 | 15942 | av_log(s, AV_LOG_DEBUG, "probing stream %d pp:%d\n", st->index, sti->probe_packets); | |
424 | 15942 | --sti->probe_packets; | |
425 | |||
426 |
2/2✓ Branch 0 taken 15931 times.
✓ Branch 1 taken 11 times.
|
15942 | if (pkt) { |
427 | 15931 | uint8_t *new_buf = av_realloc(pd->buf, pd->buf_size+pkt->size+AVPROBE_PADDING_SIZE); | |
428 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15931 times.
|
15931 | if (!new_buf) { |
429 | ✗ | av_log(s, AV_LOG_WARNING, | |
430 | "Failed to reallocate probe buffer for stream %d\n", | ||
431 | st->index); | ||
432 | ✗ | goto no_packet; | |
433 | } | ||
434 | 15931 | pd->buf = new_buf; | |
435 | 15931 | memcpy(pd->buf + pd->buf_size, pkt->data, pkt->size); | |
436 | 15931 | pd->buf_size += pkt->size; | |
437 | 15931 | memset(pd->buf + pd->buf_size, 0, AVPROBE_PADDING_SIZE); | |
438 | } else { | ||
439 | 11 | no_packet: | |
440 | 11 | sti->probe_packets = 0; | |
441 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
|
11 | if (!pd->buf_size) { |
442 | ✗ | av_log(s, AV_LOG_WARNING, | |
443 | "nothing to probe for stream %d\n", st->index); | ||
444 | } | ||
445 | } | ||
446 | |||
447 |
1/2✓ Branch 0 taken 15942 times.
✗ Branch 1 not taken.
|
31884 | end = fci->raw_packet_buffer_size >= s->probesize || |
448 |
2/2✓ Branch 0 taken 497 times.
✓ Branch 1 taken 15445 times.
|
15942 | sti->probe_packets <= 0; |
449 | |||
450 |
4/4✓ Branch 0 taken 15445 times.
✓ Branch 1 taken 497 times.
✓ Branch 2 taken 2528 times.
✓ Branch 3 taken 12917 times.
|
15942 | if (end || av_log2(pd->buf_size) != av_log2(pd->buf_size - pkt->size)) { |
451 | 3025 | int score = set_codec_from_probe_data(s, st, pd); | |
452 |
4/4✓ Branch 0 taken 3017 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2999 times.
✓ Branch 3 taken 18 times.
|
3025 | if ( (st->codecpar->codec_id != AV_CODEC_ID_NONE && score > AVPROBE_SCORE_STREAM_RETRY) |
453 |
2/2✓ Branch 0 taken 497 times.
✓ Branch 1 taken 2510 times.
|
3007 | || end) { |
454 | 515 | pd->buf_size = 0; | |
455 | 515 | av_freep(&pd->buf); | |
456 | 515 | sti->request_probe = -1; | |
457 |
1/2✓ Branch 0 taken 515 times.
✗ Branch 1 not taken.
|
515 | if (st->codecpar->codec_id != AV_CODEC_ID_NONE) { |
458 | 515 | av_log(s, AV_LOG_DEBUG, "probed stream %d\n", st->index); | |
459 | } else | ||
460 | ✗ | av_log(s, AV_LOG_WARNING, "probed stream %d failed\n", st->index); | |
461 | } | ||
462 | 3025 | force_codec_ids(s, st); | |
463 | } | ||
464 | } | ||
465 | 22109 | return 0; | |
466 | } | ||
467 | |||
468 | 1085227 | static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_index, AVPacket *pkt) | |
469 | { | ||
470 | 1085227 | FFStream *const sti = ffstream(st); | |
471 | 1085227 | int64_t ref = pkt->dts; | |
472 | int pts_wrap_behavior; | ||
473 | int64_t pts_wrap_reference; | ||
474 | AVProgram *first_program; | ||
475 | |||
476 |
2/2✓ Branch 0 taken 883151 times.
✓ Branch 1 taken 202076 times.
|
1085227 | if (ref == AV_NOPTS_VALUE) |
477 | 883151 | ref = pkt->pts; | |
478 |
7/8✓ Branch 0 taken 1017645 times.
✓ Branch 1 taken 67582 times.
✓ Branch 2 taken 48572 times.
✓ Branch 3 taken 969073 times.
✓ Branch 4 taken 302 times.
✓ Branch 5 taken 48270 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 302 times.
|
1085227 | if (sti->pts_wrap_reference != AV_NOPTS_VALUE || st->pts_wrap_bits >= 63 || ref == AV_NOPTS_VALUE || !s->correct_ts_overflow) |
479 | 1084925 | return 0; | |
480 | 302 | ref &= (1LL << st->pts_wrap_bits)-1; | |
481 | |||
482 | // reference time stamp should be 60 s before first time stamp | ||
483 | 302 | pts_wrap_reference = ref - av_rescale(60, st->time_base.den, st->time_base.num); | |
484 | // if first time stamp is not more than 1/8 and 60s before the wrap point, subtract rather than add wrap offset | ||
485 | 605 | pts_wrap_behavior = (ref < (1LL << st->pts_wrap_bits) - (1LL << st->pts_wrap_bits-3)) || | |
486 |
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)) ? |
487 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 301 times.
|
303 | AV_PTS_WRAP_ADD_OFFSET : AV_PTS_WRAP_SUB_OFFSET; |
488 | |||
489 | 302 | first_program = av_find_program_from_stream(s, NULL, stream_index); | |
490 | |||
491 |
2/2✓ Branch 0 taken 196 times.
✓ Branch 1 taken 106 times.
|
302 | if (!first_program) { |
492 | 196 | int default_stream_index = av_find_default_stream_index(s); | |
493 | 196 | FFStream *const default_sti = ffstream(s->streams[default_stream_index]); | |
494 |
2/2✓ Branch 0 taken 185 times.
✓ Branch 1 taken 11 times.
|
196 | if (default_sti->pts_wrap_reference == AV_NOPTS_VALUE) { |
495 |
2/2✓ Branch 0 taken 345 times.
✓ Branch 1 taken 185 times.
|
530 | for (unsigned i = 0; i < s->nb_streams; i++) { |
496 | 345 | FFStream *const sti = ffstream(s->streams[i]); | |
497 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 345 times.
|
345 | if (av_find_program_from_stream(s, NULL, i)) |
498 | ✗ | continue; | |
499 | 345 | sti->pts_wrap_reference = pts_wrap_reference; | |
500 | 345 | sti->pts_wrap_behavior = pts_wrap_behavior; | |
501 | } | ||
502 | } else { | ||
503 | 11 | sti->pts_wrap_reference = default_sti->pts_wrap_reference; | |
504 | 11 | sti->pts_wrap_behavior = default_sti->pts_wrap_behavior; | |
505 | } | ||
506 | } else { | ||
507 | 106 | AVProgram *program = first_program; | |
508 |
2/2✓ Branch 0 taken 106 times.
✓ Branch 1 taken 66 times.
|
172 | while (program) { |
509 |
2/2✓ Branch 0 taken 40 times.
✓ Branch 1 taken 66 times.
|
106 | if (program->pts_wrap_reference != AV_NOPTS_VALUE) { |
510 | 40 | pts_wrap_reference = program->pts_wrap_reference; | |
511 | 40 | pts_wrap_behavior = program->pts_wrap_behavior; | |
512 | 40 | break; | |
513 | } | ||
514 | 66 | program = av_find_program_from_stream(s, program, stream_index); | |
515 | } | ||
516 | |||
517 | // update every program with differing pts_wrap_reference | ||
518 | 106 | program = first_program; | |
519 |
2/2✓ Branch 0 taken 106 times.
✓ Branch 1 taken 106 times.
|
212 | while (program) { |
520 |
2/2✓ Branch 0 taken 66 times.
✓ Branch 1 taken 40 times.
|
106 | if (program->pts_wrap_reference != pts_wrap_reference) { |
521 |
2/2✓ Branch 0 taken 108 times.
✓ Branch 1 taken 66 times.
|
174 | for (unsigned i = 0; i < program->nb_stream_indexes; i++) { |
522 | 108 | FFStream *const sti = ffstream(s->streams[program->stream_index[i]]); | |
523 | 108 | sti->pts_wrap_reference = pts_wrap_reference; | |
524 | 108 | sti->pts_wrap_behavior = pts_wrap_behavior; | |
525 | } | ||
526 | |||
527 | 66 | program->pts_wrap_reference = pts_wrap_reference; | |
528 | 66 | program->pts_wrap_behavior = pts_wrap_behavior; | |
529 | } | ||
530 | 106 | program = av_find_program_from_stream(s, program, stream_index); | |
531 | } | ||
532 | } | ||
533 | 302 | return 1; | |
534 | } | ||
535 | |||
536 | 1085227 | static void update_timestamps(AVFormatContext *s, AVStream *st, AVPacket *pkt) | |
537 | { | ||
538 | 1085227 | FFStream *const sti = ffstream(st); | |
539 | |||
540 |
4/4✓ Branch 1 taken 302 times.
✓ Branch 2 taken 1084925 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 301 times.
|
1085227 | if (update_wrap_reference(s, st, pkt->stream_index, pkt) && sti->pts_wrap_behavior == AV_PTS_WRAP_SUB_OFFSET) { |
541 | // correct first time stamps to negative values | ||
542 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | if (!is_relative(sti->first_dts)) |
543 | 1 | sti->first_dts = wrap_timestamp(st, sti->first_dts); | |
544 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | if (!is_relative(st->start_time)) |
545 | 1 | st->start_time = wrap_timestamp(st, st->start_time); | |
546 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (!is_relative(sti->cur_dts)) |
547 | ✗ | sti->cur_dts = wrap_timestamp(st, sti->cur_dts); | |
548 | } | ||
549 | |||
550 | 1085227 | pkt->dts = wrap_timestamp(st, pkt->dts); | |
551 | 1085227 | pkt->pts = wrap_timestamp(st, pkt->pts); | |
552 | |||
553 | 1085227 | force_codec_ids(s, st); | |
554 | |||
555 | /* TODO: audio: time filter; video: frame reordering (pts != dts) */ | ||
556 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1085227 times.
|
1085227 | if (s->use_wallclock_as_timestamps) |
557 | ✗ | pkt->dts = pkt->pts = av_rescale_q(av_gettime(), AV_TIME_BASE_Q, st->time_base); | |
558 | 1085227 | } | |
559 | |||
560 | /** | ||
561 | * Handle a new packet and either return it directly if possible and | ||
562 | * allow_passthrough is true or queue the packet (or drop the packet | ||
563 | * if corrupt). | ||
564 | * | ||
565 | * @return < 0 on error, 0 if the packet was passed through, | ||
566 | * 1 if it was queued or dropped | ||
567 | */ | ||
568 | 1085227 | static int handle_new_packet(AVFormatContext *s, AVPacket *pkt, int allow_passthrough) | |
569 | { | ||
570 | 1085227 | FormatContextInternal *const fci = ff_fc_internal(s); | |
571 | AVStream *st; | ||
572 | FFStream *sti; | ||
573 | int err; | ||
574 | |||
575 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1085227 times.
|
1085227 | av_assert0(pkt->stream_index < (unsigned)s->nb_streams && |
576 | "Invalid stream index.\n"); | ||
577 | |||
578 |
2/2✓ Branch 0 taken 200 times.
✓ Branch 1 taken 1085027 times.
|
1085227 | if (pkt->flags & AV_PKT_FLAG_CORRUPT) { |
579 | 400 | av_log(s, AV_LOG_WARNING, | |
580 | "Packet corrupt (stream = %d, dts = %s)%s.\n", | ||
581 | 200 | pkt->stream_index, av_ts2str(pkt->dts), | |
582 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 200 times.
|
200 | s->flags & AVFMT_FLAG_DISCARD_CORRUPT ? ", dropping it" : ""); |
583 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 200 times.
|
200 | if (s->flags & AVFMT_FLAG_DISCARD_CORRUPT) { |
584 | ✗ | av_packet_unref(pkt); | |
585 | ✗ | return 1; | |
586 | } | ||
587 | } | ||
588 | |||
589 | 1085227 | st = s->streams[pkt->stream_index]; | |
590 | 1085227 | sti = ffstream(st); | |
591 | |||
592 | 1085227 | update_timestamps(s, st, pkt); | |
593 | |||
594 |
6/6✓ Branch 0 taken 1069296 times.
✓ Branch 1 taken 15931 times.
✓ Branch 2 taken 1063171 times.
✓ Branch 3 taken 6125 times.
✓ Branch 4 taken 1063129 times.
✓ Branch 5 taken 42 times.
|
1085227 | if (sti->request_probe <= 0 && allow_passthrough && !fci->raw_packet_buffer.head) |
595 | 1063129 | return 0; | |
596 | |||
597 | 22098 | err = avpriv_packet_list_put(&fci->raw_packet_buffer, pkt, NULL, 0); | |
598 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 22098 times.
|
22098 | if (err < 0) { |
599 | ✗ | av_packet_unref(pkt); | |
600 | ✗ | return err; | |
601 | } | ||
602 | |||
603 | 22098 | pkt = &fci->raw_packet_buffer.tail->pkt; | |
604 | 22098 | fci->raw_packet_buffer_size += pkt->size; | |
605 | |||
606 | 22098 | err = probe_codec(s, st, pkt); | |
607 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 22098 times.
|
22098 | if (err < 0) |
608 | ✗ | return err; | |
609 | |||
610 | 22098 | return 1; | |
611 | } | ||
612 | |||
613 | 6125 | int ff_buffer_packet(AVFormatContext *s, AVPacket *pkt) | |
614 | { | ||
615 | 6125 | int err = handle_new_packet(s, pkt, 0); | |
616 | |||
617 | 6125 | return err < 0 ? err : 0; | |
618 | } | ||
619 | |||
620 | 1091753 | int ff_read_packet(AVFormatContext *s, AVPacket *pkt) | |
621 | { | ||
622 | 1091753 | FormatContextInternal *const fci = ff_fc_internal(s); | |
623 | int err; | ||
624 | |||
625 | #if FF_API_INIT_PACKET | ||
626 | FF_DISABLE_DEPRECATION_WARNINGS | ||
627 | 1091753 | pkt->data = NULL; | |
628 | 1091753 | pkt->size = 0; | |
629 | 1091753 | av_init_packet(pkt); | |
630 | FF_ENABLE_DEPRECATION_WARNINGS | ||
631 | #else | ||
632 | av_packet_unref(pkt); | ||
633 | #endif | ||
634 | |||
635 | 22386 | for (;;) { | |
636 | 1114139 | PacketListEntry *pktl = fci->raw_packet_buffer.head; | |
637 | |||
638 |
2/2✓ Branch 0 taken 37614 times.
✓ Branch 1 taken 1076525 times.
|
1114139 | if (pktl) { |
639 | 37614 | AVStream *const st = s->streams[pktl->pkt.stream_index]; | |
640 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37614 times.
|
37614 | if (fci->raw_packet_buffer_size >= s->probesize) |
641 | ✗ | if ((err = probe_codec(s, st, NULL)) < 0) | |
642 | ✗ | return err; | |
643 |
2/2✓ Branch 1 taken 22145 times.
✓ Branch 2 taken 15469 times.
|
37614 | if (ffstream(st)->request_probe <= 0) { |
644 | 22145 | avpriv_packet_list_get(&fci->raw_packet_buffer, pkt); | |
645 | 22145 | fci->raw_packet_buffer_size -= pkt->size; | |
646 | 22145 | return 0; | |
647 | } | ||
648 | } | ||
649 | |||
650 | 1091994 | err = ffifmt(s->iformat)->read_packet(s, pkt); | |
651 |
2/2✓ Branch 0 taken 12892 times.
✓ Branch 1 taken 1079102 times.
|
1091994 | if (err < 0) { |
652 | 12892 | av_packet_unref(pkt); | |
653 | |||
654 | /* Some demuxers return FFERROR_REDO when they consume | ||
655 | data and discard it (ignored streams, junk, extradata). | ||
656 | We must re-call the demuxer to get the real packet. */ | ||
657 |
2/2✓ Branch 0 taken 6402 times.
✓ Branch 1 taken 6490 times.
|
12892 | if (err == FFERROR_REDO) |
658 | 6402 | continue; | |
659 |
3/4✓ Branch 0 taken 11 times.
✓ Branch 1 taken 6479 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 11 times.
|
6490 | if (!pktl || err == AVERROR(EAGAIN)) |
660 | 6479 | return err; | |
661 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 11 times.
|
22 | for (unsigned i = 0; i < s->nb_streams; i++) { |
662 | 11 | AVStream *const st = s->streams[i]; | |
663 | 11 | FFStream *const sti = ffstream(st); | |
664 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
11 | if (sti->probe_packets || sti->request_probe > 0) |
665 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
|
11 | if ((err = probe_codec(s, st, NULL)) < 0) |
666 | ✗ | return err; | |
667 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
|
11 | av_assert0(sti->request_probe <= 0); |
668 | } | ||
669 | 11 | continue; | |
670 | } | ||
671 | |||
672 | 1079102 | err = av_packet_make_refcounted(pkt); | |
673 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1079102 times.
|
1079102 | if (err < 0) { |
674 | ✗ | av_packet_unref(pkt); | |
675 | ✗ | return err; | |
676 | } | ||
677 | |||
678 | 1079102 | err = handle_new_packet(s, pkt, 1); | |
679 |
2/2✓ Branch 0 taken 1063129 times.
✓ Branch 1 taken 15973 times.
|
1079102 | if (err <= 0) /* Error or passthrough */ |
680 | 1063129 | return err; | |
681 | } | ||
682 | } | ||
683 | |||
684 | /** | ||
685 | * Return the frame duration in seconds. Return 0 if not available. | ||
686 | */ | ||
687 | 321696 | static void compute_frame_duration(AVFormatContext *s, int *pnum, int *pden, | |
688 | AVStream *st, AVCodecParserContext *pc, | ||
689 | AVPacket *pkt) | ||
690 | { | ||
691 | 321696 | FFStream *const sti = ffstream(st); | |
692 | 321696 | AVRational codec_framerate = sti->avctx->framerate; | |
693 | int frame_size, sample_rate; | ||
694 | |||
695 | 321696 | *pnum = 0; | |
696 | 321696 | *pden = 0; | |
697 |
3/3✓ Branch 0 taken 220043 times.
✓ Branch 1 taken 100272 times.
✓ Branch 2 taken 1381 times.
|
321696 | switch (st->codecpar->codec_type) { |
698 | 220043 | case AVMEDIA_TYPE_VIDEO: | |
699 |
6/6✓ Branch 0 taken 190283 times.
✓ Branch 1 taken 29760 times.
✓ Branch 2 taken 42281 times.
✓ Branch 3 taken 148002 times.
✓ Branch 4 taken 30826 times.
✓ Branch 5 taken 11455 times.
|
220043 | if (st->r_frame_rate.num && (!pc || !codec_framerate.num)) { |
700 | 178828 | *pnum = st->r_frame_rate.den; | |
701 | 178828 | *pden = st->r_frame_rate.num; | |
702 |
2/2✓ Branch 0 taken 23639 times.
✓ Branch 1 taken 17576 times.
|
41215 | } else if ((s->iformat->flags & AVFMT_NOTIMESTAMPS) && |
703 |
2/2✓ Branch 0 taken 14675 times.
✓ Branch 1 taken 8964 times.
|
23639 | !codec_framerate.num && |
704 |
3/4✓ Branch 0 taken 14673 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 14673 times.
✗ Branch 3 not taken.
|
14675 | st->avg_frame_rate.num && st->avg_frame_rate.den) { |
705 | 14673 | *pnum = st->avg_frame_rate.den; | |
706 | 14673 | *pden = st->avg_frame_rate.num; | |
707 |
2/2✓ Branch 0 taken 9169 times.
✓ Branch 1 taken 17373 times.
|
26542 | } else if (st->time_base.num * 1000LL > st->time_base.den) { |
708 | 9169 | *pnum = st->time_base.num; | |
709 | 9169 | *pden = st->time_base.den; | |
710 |
2/2✓ Branch 0 taken 17348 times.
✓ Branch 1 taken 25 times.
|
17373 | } else if (codec_framerate.den * 1000LL > codec_framerate.num) { |
711 | 52044 | int ticks_per_frame = (sti->codec_desc && | |
712 |
3/4✓ Branch 0 taken 17348 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12081 times.
✓ Branch 3 taken 5267 times.
|
17348 | (sti->codec_desc->props & AV_CODEC_PROP_FIELDS)) ? 2 : 1; |
713 | 17348 | av_reduce(pnum, pden, | |
714 | 17348 | codec_framerate.den, | |
715 | 17348 | codec_framerate.num * (int64_t)ticks_per_frame, | |
716 | INT_MAX); | ||
717 | |||
718 |
4/4✓ Branch 0 taken 15522 times.
✓ Branch 1 taken 1826 times.
✓ Branch 2 taken 11452 times.
✓ Branch 3 taken 4070 times.
|
17348 | if (pc && pc->repeat_pict) { |
719 | 11452 | av_reduce(pnum, pden, | |
720 | 11452 | (*pnum) * (1LL + pc->repeat_pict), | |
721 | 11452 | (*pden), | |
722 | INT_MAX); | ||
723 | } | ||
724 | /* If this codec can be interlaced or progressive then we need | ||
725 | * a parser to compute duration of a packet. Thus if we have | ||
726 | * no parser in such case leave duration undefined. */ | ||
727 |
1/2✓ Branch 0 taken 17348 times.
✗ Branch 1 not taken.
|
17348 | if (sti->codec_desc && |
728 |
3/4✓ Branch 0 taken 12081 times.
✓ Branch 1 taken 5267 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12081 times.
|
17348 | (sti->codec_desc->props & AV_CODEC_PROP_FIELDS) && !pc) |
729 | ✗ | *pnum = *pden = 0; | |
730 | } | ||
731 | 220043 | break; | |
732 | 100272 | case AVMEDIA_TYPE_AUDIO: | |
733 |
2/2✓ Branch 0 taken 45099 times.
✓ Branch 1 taken 55173 times.
|
100272 | if (sti->avctx_inited) { |
734 | 45099 | frame_size = av_get_audio_frame_duration(sti->avctx, pkt->size); | |
735 | 45099 | sample_rate = sti->avctx->sample_rate; | |
736 | } else { | ||
737 | 55173 | frame_size = av_get_audio_frame_duration2(st->codecpar, pkt->size); | |
738 | 55173 | sample_rate = st->codecpar->sample_rate; | |
739 | } | ||
740 |
4/4✓ Branch 0 taken 95011 times.
✓ Branch 1 taken 5261 times.
✓ Branch 2 taken 95006 times.
✓ Branch 3 taken 5 times.
|
100272 | if (frame_size <= 0 || sample_rate <= 0) |
741 | break; | ||
742 | 95006 | *pnum = frame_size; | |
743 | 95006 | *pden = sample_rate; | |
744 | 95006 | break; | |
745 | 1381 | default: | |
746 | 1381 | break; | |
747 | } | ||
748 | 321696 | } | |
749 | |||
750 | 720896 | static int has_decode_delay_been_guessed(AVStream *st) | |
751 | { | ||
752 | 720896 | FFStream *const sti = ffstream(st); | |
753 |
2/2✓ Branch 0 taken 703935 times.
✓ Branch 1 taken 16961 times.
|
720896 | if (st->codecpar->codec_id != AV_CODEC_ID_H264) return 1; |
754 |
2/2✓ Branch 0 taken 6054 times.
✓ Branch 1 taken 10907 times.
|
16961 | if (!sti->info) // if we have left find_stream_info then nb_decoded_frames won't increase anymore for stream copy |
755 | 6054 | return 1; | |
756 | #if CONFIG_H264_DECODER | ||
757 |
2/2✓ Branch 0 taken 6687 times.
✓ Branch 1 taken 4220 times.
|
10907 | if (sti->avctx->has_b_frames && |
758 |
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) |
759 | 1416 | return 1; | |
760 | #endif | ||
761 |
2/2✓ Branch 0 taken 9303 times.
✓ Branch 1 taken 188 times.
|
9491 | if (sti->avctx->has_b_frames < 3) |
762 | 9303 | return sti->nb_decoded_frames >= 7; | |
763 |
2/2✓ Branch 0 taken 36 times.
✓ Branch 1 taken 152 times.
|
188 | else if (sti->avctx->has_b_frames < 4) |
764 | 36 | return sti->nb_decoded_frames >= 18; | |
765 | else | ||
766 | 152 | return sti->nb_decoded_frames >= 20; | |
767 | } | ||
768 | |||
769 | 36689 | static PacketListEntry *get_next_pkt(AVFormatContext *s, AVStream *st, | |
770 | PacketListEntry *pktl) | ||
771 | { | ||
772 | 36689 | FormatContextInternal *const fci = ff_fc_internal(s); | |
773 | 36689 | FFFormatContext *const si = &fci->fc; | |
774 |
2/2✓ Branch 0 taken 34772 times.
✓ Branch 1 taken 1917 times.
|
36689 | if (pktl->next) |
775 | 34772 | return pktl->next; | |
776 |
2/2✓ Branch 0 taken 1887 times.
✓ Branch 1 taken 30 times.
|
1917 | if (pktl == si->packet_buffer.tail) |
777 | 1887 | return fci->parse_queue.head; | |
778 | 30 | return NULL; | |
779 | } | ||
780 | |||
781 | 522695 | static int64_t select_from_pts_buffer(AVStream *st, int64_t *pts_buffer, int64_t dts) | |
782 | { | ||
783 | 522695 | FFStream *const sti = ffstream(st); | |
784 | 1560840 | int onein_oneout = st->codecpar->codec_id != AV_CODEC_ID_H264 && | |
785 |
4/4✓ Branch 0 taken 515450 times.
✓ Branch 1 taken 7245 times.
✓ Branch 2 taken 514482 times.
✓ Branch 3 taken 968 times.
|
1037177 | st->codecpar->codec_id != AV_CODEC_ID_HEVC && |
786 |
2/2✓ Branch 0 taken 514463 times.
✓ Branch 1 taken 19 times.
|
514482 | st->codecpar->codec_id != AV_CODEC_ID_VVC; |
787 | |||
788 |
2/2✓ Branch 0 taken 8232 times.
✓ Branch 1 taken 514463 times.
|
522695 | if (!onein_oneout) { |
789 | 8232 | int delay = sti->avctx->has_b_frames; | |
790 | |||
791 |
2/2✓ Branch 0 taken 1217 times.
✓ Branch 1 taken 7015 times.
|
8232 | if (dts == AV_NOPTS_VALUE) { |
792 | 1217 | int64_t best_score = INT64_MAX; | |
793 |
2/2✓ Branch 0 taken 1395 times.
✓ Branch 1 taken 1217 times.
|
2612 | for (int i = 0; i < delay; i++) { |
794 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1395 times.
|
1395 | if (sti->pts_reorder_error_count[i]) { |
795 | ✗ | int64_t score = sti->pts_reorder_error[i] / sti->pts_reorder_error_count[i]; | |
796 | ✗ | if (score < best_score) { | |
797 | ✗ | best_score = score; | |
798 | ✗ | dts = pts_buffer[i]; | |
799 | } | ||
800 | } | ||
801 | } | ||
802 | } else { | ||
803 |
2/2✓ Branch 0 taken 11895 times.
✓ Branch 1 taken 7015 times.
|
18910 | for (int i = 0; i < delay; i++) { |
804 |
2/2✓ Branch 0 taken 11098 times.
✓ Branch 1 taken 797 times.
|
11895 | if (pts_buffer[i] != AV_NOPTS_VALUE) { |
805 | 11098 | int64_t diff = FFABS(pts_buffer[i] - dts) | |
806 | 11098 | + (uint64_t)sti->pts_reorder_error[i]; | |
807 | 11098 | diff = FFMAX(diff, sti->pts_reorder_error[i]); | |
808 | 11098 | sti->pts_reorder_error[i] = diff; | |
809 | 11098 | sti->pts_reorder_error_count[i]++; | |
810 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 11095 times.
|
11098 | if (sti->pts_reorder_error_count[i] > 250) { |
811 | 3 | sti->pts_reorder_error[i] >>= 1; | |
812 | 3 | sti->pts_reorder_error_count[i] >>= 1; | |
813 | } | ||
814 | } | ||
815 | } | ||
816 | } | ||
817 | } | ||
818 | |||
819 |
2/2✓ Branch 0 taken 1392 times.
✓ Branch 1 taken 521303 times.
|
522695 | if (dts == AV_NOPTS_VALUE) |
820 | 1392 | dts = pts_buffer[0]; | |
821 | |||
822 | 522695 | return dts; | |
823 | } | ||
824 | |||
825 | /** | ||
826 | * Updates the dts of packets of a stream in pkt_buffer, by re-ordering the pts | ||
827 | * of the packets in a window. | ||
828 | */ | ||
829 | 6122 | static void update_dts_from_pts(AVFormatContext *s, int stream_index, | |
830 | PacketListEntry *pkt_buffer) | ||
831 | { | ||
832 | 6122 | AVStream *const st = s->streams[stream_index]; | |
833 | 6122 | int delay = ffstream(st)->avctx->has_b_frames; | |
834 | |||
835 | int64_t pts_buffer[MAX_REORDER_DELAY+1]; | ||
836 | |||
837 |
2/2✓ Branch 0 taken 104074 times.
✓ Branch 1 taken 6122 times.
|
110196 | for (int i = 0; i < MAX_REORDER_DELAY + 1; i++) |
838 | 104074 | pts_buffer[i] = AV_NOPTS_VALUE; | |
839 | |||
840 |
2/2✓ Branch 1 taken 5506 times.
✓ Branch 2 taken 6122 times.
|
11628 | for (; pkt_buffer; pkt_buffer = get_next_pkt(s, st, pkt_buffer)) { |
841 |
2/2✓ Branch 0 taken 4848 times.
✓ Branch 1 taken 658 times.
|
5506 | if (pkt_buffer->pkt.stream_index != stream_index) |
842 | 4848 | continue; | |
843 | |||
844 |
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) { |
845 | 561 | pts_buffer[0] = pkt_buffer->pkt.pts; | |
846 |
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++) |
847 | 212 | FFSWAP(int64_t, pts_buffer[i], pts_buffer[i + 1]); | |
848 | |||
849 | 561 | pkt_buffer->pkt.dts = select_from_pts_buffer(st, pts_buffer, pkt_buffer->pkt.dts); | |
850 | } | ||
851 | } | ||
852 | 6122 | } | |
853 | |||
854 | 564078 | static void update_initial_timestamps(AVFormatContext *s, int stream_index, | |
855 | int64_t dts, int64_t pts, AVPacket *pkt) | ||
856 | { | ||
857 | 564078 | FormatContextInternal *const fci = ff_fc_internal(s); | |
858 | 564078 | FFFormatContext *const si = &fci->fc; | |
859 | 564078 | AVStream *const st = s->streams[stream_index]; | |
860 | 564078 | FFStream *const sti = ffstream(st); | |
861 |
2/2✓ Branch 0 taken 184254 times.
✓ Branch 1 taken 379824 times.
|
564078 | PacketListEntry *pktl = si->packet_buffer.head ? si->packet_buffer.head : fci->parse_queue.head; |
862 | |||
863 | uint64_t shift; | ||
864 | |||
865 |
4/4✓ Branch 0 taken 185691 times.
✓ Branch 1 taken 378387 times.
✓ Branch 2 taken 6185 times.
✓ Branch 3 taken 179506 times.
|
564078 | if (sti->first_dts != AV_NOPTS_VALUE || |
866 | 6185 | dts == AV_NOPTS_VALUE || | |
867 |
1/2✓ Branch 0 taken 6185 times.
✗ Branch 1 not taken.
|
6185 | sti->cur_dts == AV_NOPTS_VALUE || |
868 |
1/2✓ Branch 0 taken 6185 times.
✗ Branch 1 not taken.
|
6185 | sti->cur_dts < INT_MIN + RELATIVE_TS_BASE || |
869 |
2/4✓ Branch 0 taken 6185 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6185 times.
|
12370 | dts < INT_MIN + (sti->cur_dts - RELATIVE_TS_BASE) || |
870 | 6185 | is_relative(dts)) | |
871 | 557893 | return; | |
872 | |||
873 | 6185 | sti->first_dts = dts - (sti->cur_dts - RELATIVE_TS_BASE); | |
874 | 6185 | sti->cur_dts = dts; | |
875 | 6185 | shift = (uint64_t)sti->first_dts - RELATIVE_TS_BASE; | |
876 | |||
877 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 6185 times.
|
6185 | if (is_relative(pts)) |
878 | ✗ | pts += shift; | |
879 | |||
880 |
2/2✓ Branch 1 taken 5247 times.
✓ Branch 2 taken 6185 times.
|
11432 | for (PacketListEntry *pktl_it = pktl; pktl_it; pktl_it = get_next_pkt(s, st, pktl_it)) { |
881 |
2/2✓ Branch 0 taken 4777 times.
✓ Branch 1 taken 470 times.
|
5247 | if (pktl_it->pkt.stream_index != stream_index) |
882 | 4777 | continue; | |
883 |
2/2✓ Branch 1 taken 205 times.
✓ Branch 2 taken 265 times.
|
470 | if (is_relative(pktl_it->pkt.pts)) |
884 | 205 | pktl_it->pkt.pts += shift; | |
885 | |||
886 |
2/2✓ Branch 1 taken 233 times.
✓ Branch 2 taken 237 times.
|
470 | if (is_relative(pktl_it->pkt.dts)) |
887 | 233 | pktl_it->pkt.dts += shift; | |
888 | |||
889 |
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) { |
890 | 41 | st->start_time = pktl_it->pkt.pts; | |
891 |
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) |
892 | 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)); | |
893 | } | ||
894 | } | ||
895 | |||
896 |
2/2✓ Branch 1 taken 6104 times.
✓ Branch 2 taken 81 times.
|
6185 | if (has_decode_delay_been_guessed(st)) |
897 | 6104 | update_dts_from_pts(s, stream_index, pktl); | |
898 | |||
899 |
2/2✓ Branch 0 taken 1706 times.
✓ Branch 1 taken 4479 times.
|
6185 | if (st->start_time == AV_NOPTS_VALUE) { |
900 |
3/4✓ Branch 0 taken 1231 times.
✓ Branch 1 taken 475 times.
✓ Branch 2 taken 1231 times.
✗ Branch 3 not taken.
|
1706 | if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO || !(pkt->flags & AV_PKT_FLAG_DISCARD)) { |
901 | 1706 | st->start_time = pts; | |
902 | } | ||
903 |
4/4✓ Branch 0 taken 475 times.
✓ Branch 1 taken 1231 times.
✓ Branch 2 taken 391 times.
✓ Branch 3 taken 84 times.
|
1706 | if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && st->codecpar->sample_rate) |
904 | 391 | st->start_time = av_sat_add64(st->start_time, av_rescale_q(sti->skip_samples, (AVRational){1, st->codecpar->sample_rate}, st->time_base)); | |
905 | } | ||
906 | } | ||
907 | |||
908 | 228072 | static void update_initial_durations(AVFormatContext *s, AVStream *st, | |
909 | int stream_index, int64_t duration) | ||
910 | { | ||
911 | 228072 | FormatContextInternal *const fci = ff_fc_internal(s); | |
912 | 228072 | FFFormatContext *const si = &fci->fc; | |
913 | 228072 | FFStream *const sti = ffstream(st); | |
914 |
2/2✓ Branch 0 taken 180946 times.
✓ Branch 1 taken 47126 times.
|
228072 | PacketListEntry *pktl = si->packet_buffer.head ? si->packet_buffer.head : fci->parse_queue.head; |
915 | 228072 | int64_t cur_dts = RELATIVE_TS_BASE; | |
916 | |||
917 |
2/2✓ Branch 0 taken 123271 times.
✓ Branch 1 taken 104801 times.
|
228072 | if (sti->first_dts != AV_NOPTS_VALUE) { |
918 |
2/2✓ Branch 0 taken 119631 times.
✓ Branch 1 taken 3640 times.
|
123271 | if (sti->update_initial_durations_done) |
919 | 119631 | return; | |
920 | 3640 | sti->update_initial_durations_done = 1; | |
921 | 3640 | cur_dts = sti->first_dts; | |
922 |
1/2✓ Branch 1 taken 5456 times.
✗ Branch 2 not taken.
|
5456 | for (; pktl; pktl = get_next_pkt(s, st, pktl)) { |
923 |
2/2✓ Branch 0 taken 3655 times.
✓ Branch 1 taken 1801 times.
|
5456 | if (pktl->pkt.stream_index == stream_index) { |
924 |
2/2✓ Branch 0 taken 3544 times.
✓ Branch 1 taken 111 times.
|
3655 | if (pktl->pkt.pts != pktl->pkt.dts || |
925 |
2/2✓ Branch 0 taken 15 times.
✓ Branch 1 taken 3529 times.
|
3544 | pktl->pkt.dts != AV_NOPTS_VALUE || |
926 |
1/2✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
|
15 | pktl->pkt.duration) |
927 | break; | ||
928 | 15 | cur_dts -= duration; | |
929 | } | ||
930 | } | ||
931 |
3/4✓ Branch 0 taken 3640 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 33 times.
✓ Branch 3 taken 3607 times.
|
3640 | if (pktl && pktl->pkt.dts != sti->first_dts) { |
932 | 33 | av_log(s, AV_LOG_DEBUG, "first_dts %s not matching first dts %s (pts %s, duration %"PRId64") in the queue\n", | |
933 | 33 | av_ts2str(sti->first_dts), av_ts2str(pktl->pkt.dts), av_ts2str(pktl->pkt.pts), pktl->pkt.duration); | |
934 | 33 | return; | |
935 | } | ||
936 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3607 times.
|
3607 | if (!pktl) { |
937 | ✗ | av_log(s, AV_LOG_DEBUG, "first_dts %s but no packet with dts in the queue\n", av_ts2str(sti->first_dts)); | |
938 | ✗ | return; | |
939 | } | ||
940 |
2/2✓ Branch 0 taken 3586 times.
✓ Branch 1 taken 21 times.
|
3607 | pktl = si->packet_buffer.head ? si->packet_buffer.head : fci->parse_queue.head; |
941 | 3607 | sti->first_dts = cur_dts; | |
942 |
2/2✓ Branch 0 taken 80307 times.
✓ Branch 1 taken 24494 times.
|
104801 | } else if (sti->cur_dts != RELATIVE_TS_BASE) |
943 | 80307 | return; | |
944 | |||
945 |
2/2✓ Branch 1 taken 51578 times.
✓ Branch 2 taken 643 times.
|
52221 | for (; pktl; pktl = get_next_pkt(s, st, pktl)) { |
946 |
2/2✓ Branch 0 taken 23965 times.
✓ Branch 1 taken 27613 times.
|
51578 | if (pktl->pkt.stream_index != stream_index) |
947 | 23965 | continue; | |
948 |
2/2✓ Branch 0 taken 567 times.
✓ Branch 1 taken 27046 times.
|
27613 | if ((pktl->pkt.pts == pktl->pkt.dts || |
949 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 553 times.
|
567 | pktl->pkt.pts == AV_NOPTS_VALUE) && |
950 |
2/2✓ Branch 0 taken 3676 times.
✓ Branch 1 taken 23384 times.
|
27060 | (pktl->pkt.dts == AV_NOPTS_VALUE || |
951 |
2/2✓ Branch 0 taken 178 times.
✓ Branch 1 taken 3498 times.
|
3676 | pktl->pkt.dts == sti->first_dts || |
952 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 176 times.
|
178 | pktl->pkt.dts == RELATIVE_TS_BASE) && |
953 |
2/2✓ Branch 0 taken 155 times.
✓ Branch 1 taken 26729 times.
|
26884 | !pktl->pkt.duration && |
954 |
1/2✓ Branch 1 taken 155 times.
✗ Branch 2 not taken.
|
155 | av_sat_add64(cur_dts, duration) == cur_dts + (uint64_t)duration |
955 | ) { | ||
956 | 155 | pktl->pkt.dts = cur_dts; | |
957 |
2/2✓ Branch 0 taken 139 times.
✓ Branch 1 taken 16 times.
|
155 | if (!sti->avctx->has_b_frames) |
958 | 139 | pktl->pkt.pts = cur_dts; | |
959 | 155 | pktl->pkt.duration = duration; | |
960 | } else | ||
961 | break; | ||
962 | 155 | cur_dts = pktl->pkt.dts + pktl->pkt.duration; | |
963 | } | ||
964 |
2/2✓ Branch 0 taken 643 times.
✓ Branch 1 taken 27458 times.
|
28101 | if (!pktl) |
965 | 643 | sti->cur_dts = cur_dts; | |
966 | } | ||
967 | |||
968 | 569903 | static void compute_pkt_fields(AVFormatContext *s, AVStream *st, | |
969 | AVCodecParserContext *pc, AVPacket *pkt, | ||
970 | int64_t next_dts, int64_t next_pts) | ||
971 | { | ||
972 | 569903 | FormatContextInternal *const fci = ff_fc_internal(s); | |
973 | 569903 | FFFormatContext *const si = &fci->fc; | |
974 | 569903 | FFStream *const sti = ffstream(st); | |
975 | int num, den, presentation_delayed, delay; | ||
976 | int64_t offset; | ||
977 | AVRational duration; | ||
978 | 1675786 | int onein_oneout = st->codecpar->codec_id != AV_CODEC_ID_H264 && | |
979 |
4/4✓ Branch 0 taken 535980 times.
✓ Branch 1 taken 33923 times.
✓ Branch 2 taken 522970 times.
✓ Branch 3 taken 13010 times.
|
1092873 | st->codecpar->codec_id != AV_CODEC_ID_HEVC && |
980 |
2/2✓ Branch 0 taken 519923 times.
✓ Branch 1 taken 3047 times.
|
522970 | st->codecpar->codec_id != AV_CODEC_ID_VVC; |
981 | |||
982 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 569903 times.
|
569903 | if (s->flags & AVFMT_FLAG_NOFILLIN) |
983 | ✗ | return; | |
984 | |||
985 |
4/4✓ Branch 0 taken 244080 times.
✓ Branch 1 taken 325823 times.
✓ Branch 2 taken 73737 times.
✓ Branch 3 taken 170343 times.
|
569903 | if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && pkt->dts != AV_NOPTS_VALUE) { |
986 |
4/4✓ Branch 0 taken 43454 times.
✓ Branch 1 taken 30283 times.
✓ Branch 2 taken 42285 times.
✓ Branch 3 taken 1169 times.
|
73737 | if (pkt->dts == pkt->pts && sti->last_dts_for_order_check != AV_NOPTS_VALUE) { |
987 |
2/2✓ Branch 0 taken 42276 times.
✓ Branch 1 taken 9 times.
|
42285 | if (sti->last_dts_for_order_check <= pkt->dts) { |
988 | 42276 | sti->dts_ordered++; | |
989 | } else { | ||
990 |
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, |
991 | "DTS %"PRIi64" < %"PRIi64" out of order\n", | ||
992 | pkt->dts, | ||
993 | sti->last_dts_for_order_check); | ||
994 | 9 | sti->dts_misordered++; | |
995 | } | ||
996 |
2/2✓ Branch 0 taken 29 times.
✓ Branch 1 taken 42256 times.
|
42285 | if (sti->dts_ordered + sti->dts_misordered > 250) { |
997 | 29 | sti->dts_ordered >>= 1; | |
998 | 29 | sti->dts_misordered >>= 1; | |
999 | } | ||
1000 | } | ||
1001 | |||
1002 | 73737 | sti->last_dts_for_order_check = pkt->dts; | |
1003 |
4/4✓ Branch 0 taken 37 times.
✓ Branch 1 taken 73700 times.
✓ Branch 2 taken 20 times.
✓ Branch 3 taken 17 times.
|
73737 | if (sti->dts_ordered < 8 * sti->dts_misordered && pkt->dts == pkt->pts) |
1004 | 20 | pkt->dts = AV_NOPTS_VALUE; | |
1005 | } | ||
1006 | |||
1007 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 569903 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
569903 | if ((s->flags & AVFMT_FLAG_IGNDTS) && pkt->pts != AV_NOPTS_VALUE) |
1008 | ✗ | pkt->dts = AV_NOPTS_VALUE; | |
1009 | |||
1010 |
4/4✓ Branch 0 taken 186925 times.
✓ Branch 1 taken 382978 times.
✓ Branch 2 taken 27675 times.
✓ Branch 3 taken 159250 times.
|
569903 | if (pc && pc->pict_type == AV_PICTURE_TYPE_B |
1011 |
2/2✓ Branch 0 taken 81 times.
✓ Branch 1 taken 27594 times.
|
27675 | && !sti->avctx->has_b_frames) |
1012 | //FIXME Set low_delay = 0 when has_b_frames = 1 | ||
1013 | 81 | sti->avctx->has_b_frames = 1; | |
1014 | |||
1015 | /* do we have a video B-frame ? */ | ||
1016 | 569903 | delay = sti->avctx->has_b_frames; | |
1017 | 569903 | presentation_delayed = 0; | |
1018 | |||
1019 | /* XXX: need has_b_frame, but cannot get it if the codec is | ||
1020 | * not initialized */ | ||
1021 |
4/4✓ Branch 0 taken 46548 times.
✓ Branch 1 taken 523355 times.
✓ Branch 2 taken 42517 times.
✓ Branch 3 taken 4031 times.
|
569903 | if (delay && |
1022 |
2/2✓ Branch 0 taken 14842 times.
✓ Branch 1 taken 27675 times.
|
42517 | pc && pc->pict_type != AV_PICTURE_TYPE_B) |
1023 | 14842 | presentation_delayed = 1; | |
1024 | |||
1025 |
4/4✓ Branch 0 taken 340365 times.
✓ Branch 1 taken 229538 times.
✓ Branch 2 taken 167825 times.
✓ Branch 3 taken 172540 times.
|
569903 | if (pkt->pts != AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE && |
1026 |
3/4✓ Branch 0 taken 27451 times.
✓ Branch 1 taken 140374 times.
✓ Branch 2 taken 27451 times.
✗ Branch 3 not taken.
|
167825 | st->pts_wrap_bits < 63 && pkt->dts > INT64_MIN + (1LL << st->pts_wrap_bits) && |
1027 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 27451 times.
|
27451 | pkt->dts - (1LL << (st->pts_wrap_bits - 1)) > pkt->pts) { |
1028 | ✗ | if (is_relative(sti->cur_dts) || pkt->dts - (1LL<<(st->pts_wrap_bits - 1)) > sti->cur_dts) { | |
1029 | ✗ | pkt->dts -= 1LL << st->pts_wrap_bits; | |
1030 | } else | ||
1031 | ✗ | pkt->pts += 1LL << st->pts_wrap_bits; | |
1032 | } | ||
1033 | |||
1034 | /* Some MPEG-2 in MPEG-PS lack dts (issue #171 / input_file.mpg). | ||
1035 | * We take the conservative approach and discard both. | ||
1036 | * Note: If this is misbehaving for an H.264 file, then possibly | ||
1037 | * presentation_delayed is not set correctly. */ | ||
1038 |
4/4✓ Branch 0 taken 30105 times.
✓ Branch 1 taken 539798 times.
✓ Branch 2 taken 24943 times.
✓ Branch 3 taken 5162 times.
|
569903 | if (delay == 1 && pkt->dts == pkt->pts && |
1039 |
4/4✓ Branch 0 taken 6135 times.
✓ Branch 1 taken 18808 times.
✓ Branch 2 taken 628 times.
✓ Branch 3 taken 5507 times.
|
24943 | pkt->dts != AV_NOPTS_VALUE && presentation_delayed) { |
1040 | 628 | av_log(s, AV_LOG_DEBUG, "invalid dts/pts combination %"PRIi64"\n", pkt->dts); | |
1041 |
2/2✓ Branch 0 taken 293 times.
✓ Branch 1 taken 335 times.
|
628 | if ( strcmp(s->iformat->name, "mov,mp4,m4a,3gp,3g2,mj2") |
1042 |
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 |
1043 | 22 | pkt->dts = AV_NOPTS_VALUE; | |
1044 | } | ||
1045 | |||
1046 | 569903 | duration = av_mul_q((AVRational) {pkt->duration, 1}, st->time_base); | |
1047 |
2/2✓ Branch 0 taken 318891 times.
✓ Branch 1 taken 251012 times.
|
569903 | if (pkt->duration <= 0) { |
1048 | 318891 | compute_frame_duration(s, &num, &den, st, pc, pkt); | |
1049 |
3/4✓ Branch 0 taken 309608 times.
✓ Branch 1 taken 9283 times.
✓ Branch 2 taken 309608 times.
✗ Branch 3 not taken.
|
318891 | if (den && num) { |
1050 | 309608 | duration = (AVRational) {num, den}; | |
1051 | 309608 | pkt->duration = av_rescale_rnd(1, | |
1052 | 309608 | num * (int64_t) st->time_base.den, | |
1053 | 309608 | den * (int64_t) st->time_base.num, | |
1054 | AV_ROUND_DOWN); | ||
1055 | } | ||
1056 | } | ||
1057 | |||
1058 |
6/6✓ Branch 0 taken 557798 times.
✓ Branch 1 taken 12105 times.
✓ Branch 2 taken 376852 times.
✓ Branch 3 taken 180946 times.
✓ Branch 4 taken 47126 times.
✓ Branch 5 taken 329726 times.
|
569903 | if (pkt->duration > 0 && (si->packet_buffer.head || fci->parse_queue.head)) |
1059 | 228072 | update_initial_durations(s, st, pkt->stream_index, pkt->duration); | |
1060 | |||
1061 | /* Correct timestamps with byte offset if demuxers only have timestamps | ||
1062 | * on packet boundaries */ | ||
1063 |
5/6✓ Branch 0 taken 186925 times.
✓ Branch 1 taken 382978 times.
✓ Branch 2 taken 960 times.
✓ Branch 3 taken 185965 times.
✓ Branch 4 taken 960 times.
✗ Branch 5 not taken.
|
569903 | if (pc && sti->need_parsing == AVSTREAM_PARSE_TIMESTAMPS && pkt->size) { |
1064 | /* this will estimate bitrate based on this frame's duration and size */ | ||
1065 | 960 | offset = av_rescale(pc->offset, pkt->duration, pkt->size); | |
1066 |
2/2✓ Branch 0 taken 575 times.
✓ Branch 1 taken 385 times.
|
960 | if (pkt->pts != AV_NOPTS_VALUE) |
1067 | 575 | pkt->pts += offset; | |
1068 |
2/2✓ Branch 0 taken 121 times.
✓ Branch 1 taken 839 times.
|
960 | if (pkt->dts != AV_NOPTS_VALUE) |
1069 | 121 | pkt->dts += offset; | |
1070 | } | ||
1071 | |||
1072 | /* This may be redundant, but it should not hurt. */ | ||
1073 |
2/2✓ Branch 0 taken 198221 times.
✓ Branch 1 taken 371682 times.
|
569903 | if (pkt->dts != AV_NOPTS_VALUE && |
1074 |
2/2✓ Branch 0 taken 167803 times.
✓ Branch 1 taken 30418 times.
|
198221 | pkt->pts != AV_NOPTS_VALUE && |
1075 |
2/2✓ Branch 0 taken 5158 times.
✓ Branch 1 taken 162645 times.
|
167803 | pkt->pts > pkt->dts) |
1076 | 5158 | presentation_delayed = 1; | |
1077 | |||
1078 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 569903 times.
|
569903 | if (s->debug & FF_FDEBUG_TS) |
1079 | ✗ | av_log(s, AV_LOG_DEBUG, | |
1080 | "IN delayed:%d pts:%s, dts:%s cur_dts:%s st:%d pc:%p duration:%"PRId64" delay:%d onein_oneout:%d\n", | ||
1081 | ✗ | presentation_delayed, av_ts2str(pkt->pts), av_ts2str(pkt->dts), av_ts2str(sti->cur_dts), | |
1082 | pkt->stream_index, pc, pkt->duration, delay, onein_oneout); | ||
1083 | |||
1084 | /* Interpolate PTS and DTS if they are not present. We skip H264 | ||
1085 | * currently because delay and has_b_frames are not reliably set. */ | ||
1086 |
8/8✓ Branch 0 taken 46548 times.
✓ Branch 1 taken 523355 times.
✓ Branch 2 taken 30105 times.
✓ Branch 3 taken 16443 times.
✓ Branch 4 taken 26651 times.
✓ Branch 5 taken 3454 times.
✓ Branch 6 taken 516482 times.
✓ Branch 7 taken 33524 times.
|
569903 | if ((delay == 0 || (delay == 1 && pc)) && |
1087 | onein_oneout) { | ||
1088 |
2/2✓ Branch 0 taken 5513 times.
✓ Branch 1 taken 510969 times.
|
516482 | if (presentation_delayed) { |
1089 | /* DTS = decompression timestamp */ | ||
1090 | /* PTS = presentation timestamp */ | ||
1091 |
2/2✓ Branch 0 taken 2845 times.
✓ Branch 1 taken 2668 times.
|
5513 | if (pkt->dts == AV_NOPTS_VALUE) |
1092 | 2845 | pkt->dts = sti->last_IP_pts; | |
1093 | 5513 | update_initial_timestamps(s, pkt->stream_index, pkt->dts, pkt->pts, pkt); | |
1094 |
2/2✓ Branch 0 taken 2507 times.
✓ Branch 1 taken 3006 times.
|
5513 | if (pkt->dts == AV_NOPTS_VALUE) |
1095 | 2507 | pkt->dts = sti->cur_dts; | |
1096 | |||
1097 | /* This is tricky: the dts must be incremented by the duration | ||
1098 | * of the frame we are displaying, i.e. the last I- or P-frame. */ | ||
1099 |
3/4✓ Branch 0 taken 238 times.
✓ Branch 1 taken 5275 times.
✓ Branch 2 taken 238 times.
✗ Branch 3 not taken.
|
5513 | if (sti->last_IP_duration == 0 && (uint64_t)pkt->duration <= INT32_MAX) |
1100 | 238 | sti->last_IP_duration = pkt->duration; | |
1101 |
1/2✓ Branch 0 taken 5513 times.
✗ Branch 1 not taken.
|
5513 | if (pkt->dts != AV_NOPTS_VALUE) |
1102 | 5513 | sti->cur_dts = av_sat_add64(pkt->dts, sti->last_IP_duration); | |
1103 |
1/2✓ Branch 0 taken 5513 times.
✗ Branch 1 not taken.
|
5513 | if (pkt->dts != AV_NOPTS_VALUE && |
1104 |
2/2✓ Branch 0 taken 3283 times.
✓ Branch 1 taken 2230 times.
|
5513 | pkt->pts == AV_NOPTS_VALUE && |
1105 |
2/2✓ Branch 0 taken 3281 times.
✓ Branch 1 taken 2 times.
|
3283 | sti->last_IP_duration > 0 && |
1106 |
4/4✓ Branch 0 taken 793 times.
✓ Branch 1 taken 2488 times.
✓ Branch 2 taken 787 times.
✓ Branch 3 taken 6 times.
|
3281 | ((uint64_t)sti->cur_dts - (uint64_t)next_dts + 1) <= 2 && |
1107 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 776 times.
|
787 | next_dts != next_pts && |
1108 | next_pts != AV_NOPTS_VALUE) | ||
1109 | 11 | pkt->pts = next_dts; | |
1110 | |||
1111 |
1/2✓ Branch 0 taken 5513 times.
✗ Branch 1 not taken.
|
5513 | if ((uint64_t)pkt->duration <= INT32_MAX) |
1112 | 5513 | sti->last_IP_duration = pkt->duration; | |
1113 | 5513 | sti->last_IP_pts = pkt->pts; | |
1114 | /* Cannot compute PTS if not present (we can compute it only | ||
1115 | * by knowing the future. */ | ||
1116 |
2/2✓ Branch 0 taken 184771 times.
✓ Branch 1 taken 326198 times.
|
510969 | } else if (pkt->pts != AV_NOPTS_VALUE || |
1117 |
2/2✓ Branch 0 taken 155208 times.
✓ Branch 1 taken 29563 times.
|
184771 | pkt->dts != AV_NOPTS_VALUE || |
1118 |
2/2✓ Branch 0 taken 152824 times.
✓ Branch 1 taken 2384 times.
|
155208 | pkt->duration > 0 ) { |
1119 | |||
1120 | /* presentation is not delayed : PTS and DTS are the same */ | ||
1121 |
2/2✓ Branch 0 taken 182387 times.
✓ Branch 1 taken 326198 times.
|
508585 | if (pkt->pts == AV_NOPTS_VALUE) |
1122 | 182387 | pkt->pts = pkt->dts; | |
1123 | 508585 | update_initial_timestamps(s, pkt->stream_index, pkt->pts, | |
1124 | pkt->pts, pkt); | ||
1125 |
2/2✓ Branch 0 taken 152824 times.
✓ Branch 1 taken 355761 times.
|
508585 | if (pkt->pts == AV_NOPTS_VALUE) |
1126 | 152824 | pkt->pts = sti->cur_dts; | |
1127 | 508585 | pkt->dts = pkt->pts; | |
1128 |
3/4✓ Branch 0 taken 508585 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 508577 times.
✓ Branch 3 taken 8 times.
|
508585 | if (pkt->pts != AV_NOPTS_VALUE && duration.num >= 0) |
1129 | 508577 | sti->cur_dts = av_add_stable(st->time_base, pkt->pts, duration, 1); | |
1130 | } | ||
1131 | } | ||
1132 | |||
1133 |
3/4✓ Branch 0 taken 522763 times.
✓ Branch 1 taken 47140 times.
✓ Branch 2 taken 522763 times.
✗ Branch 3 not taken.
|
569903 | if (pkt->pts != AV_NOPTS_VALUE && delay <= MAX_REORDER_DELAY) { |
1134 | 522763 | sti->pts_buffer[0] = pkt->pts; | |
1135 |
4/4✓ Branch 0 taken 22106 times.
✓ Branch 1 taken 517466 times.
✓ Branch 2 taken 16809 times.
✓ Branch 3 taken 5297 times.
|
539572 | for (int i = 0; i < delay && sti->pts_buffer[i] > sti->pts_buffer[i + 1]; i++) |
1136 | 16809 | FFSWAP(int64_t, sti->pts_buffer[i], sti->pts_buffer[i + 1]); | |
1137 | |||
1138 |
2/2✓ Branch 1 taken 522134 times.
✓ Branch 2 taken 629 times.
|
522763 | if (has_decode_delay_been_guessed(st)) |
1139 | 522134 | pkt->dts = select_from_pts_buffer(st, sti->pts_buffer, pkt->dts); | |
1140 | } | ||
1141 | // We skipped it above so we try here. | ||
1142 |
2/2✓ Branch 0 taken 49980 times.
✓ Branch 1 taken 519923 times.
|
569903 | if (!onein_oneout) |
1143 | // This should happen on the first packet | ||
1144 | 49980 | update_initial_timestamps(s, pkt->stream_index, pkt->dts, pkt->pts, pkt); | |
1145 |
2/2✓ Branch 0 taken 8018 times.
✓ Branch 1 taken 561885 times.
|
569903 | if (pkt->dts > sti->cur_dts) |
1146 | 8018 | sti->cur_dts = pkt->dts; | |
1147 | |||
1148 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 569903 times.
|
569903 | if (s->debug & FF_FDEBUG_TS) |
1149 | ✗ | av_log(s, AV_LOG_DEBUG, "OUTdelayed:%d/%d pts:%s, dts:%s cur_dts:%s st:%d (%d)\n", | |
1150 | ✗ | presentation_delayed, delay, av_ts2str(pkt->pts), av_ts2str(pkt->dts), av_ts2str(sti->cur_dts), st->index, st->id); | |
1151 | |||
1152 | /* update flags */ | ||
1153 |
4/4✓ Branch 0 taken 569818 times.
✓ Branch 1 taken 85 times.
✓ Branch 3 taken 373931 times.
✓ Branch 4 taken 195887 times.
|
569903 | if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA || ff_is_intra_only(st->codecpar->codec_id)) |
1154 | 374016 | pkt->flags |= AV_PKT_FLAG_KEY; | |
1155 | } | ||
1156 | |||
1157 | /** | ||
1158 | * Parse a packet, add all split parts to parse_queue. | ||
1159 | * | ||
1160 | * @param pkt Packet to parse; must not be NULL. | ||
1161 | * @param flush Indicates whether to flush. If set, pkt must be blank. | ||
1162 | */ | ||
1163 | 697686 | static int parse_packet(AVFormatContext *s, AVPacket *pkt, | |
1164 | int stream_index, int flush) | ||
1165 | { | ||
1166 | 697686 | FormatContextInternal *const fci = ff_fc_internal(s); | |
1167 | 697686 | FFFormatContext *const si = &fci->fc; | |
1168 | 697686 | AVPacket *out_pkt = si->parse_pkt; | |
1169 | 697686 | AVStream *st = s->streams[stream_index]; | |
1170 | 697686 | FFStream *const sti = ffstream(st); | |
1171 | 697686 | const uint8_t *data = pkt->data; | |
1172 | 697686 | int size = pkt->size; | |
1173 | 697686 | int ret = 0, got_output = flush; | |
1174 | |||
1175 |
5/6✓ Branch 0 taken 2239 times.
✓ Branch 1 taken 695447 times.
✓ Branch 2 taken 164 times.
✓ Branch 3 taken 2075 times.
✓ Branch 4 taken 164 times.
✗ Branch 5 not taken.
|
697686 | if (!size && !flush && sti->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) { |
1176 | // preserve 0-size sync packets | ||
1177 | 164 | compute_pkt_fields(s, st, sti->parser, pkt, pkt->dts, pkt->pts); | |
1178 | |||
1179 | // Theora has valid 0-sized packets that need to be output | ||
1180 |
2/2✓ Branch 0 taken 148 times.
✓ Branch 1 taken 16 times.
|
164 | if (st->codecpar->codec_id == AV_CODEC_ID_THEORA) { |
1181 | 148 | ret = avpriv_packet_list_put(&fci->parse_queue, | |
1182 | pkt, NULL, 0); | ||
1183 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 148 times.
|
148 | if (ret < 0) |
1184 | ✗ | goto fail; | |
1185 | } | ||
1186 | } | ||
1187 | |||
1188 |
6/6✓ Branch 0 taken 811506 times.
✓ Branch 1 taken 700924 times.
✓ Branch 2 taken 5313 times.
✓ Branch 3 taken 695611 times.
✓ Branch 4 taken 3238 times.
✓ Branch 5 taken 2075 times.
|
1512430 | while (size > 0 || (flush && got_output)) { |
1189 | 814744 | int64_t next_pts = pkt->pts; | |
1190 | 814744 | int64_t next_dts = pkt->dts; | |
1191 | int len; | ||
1192 | |||
1193 | 814744 | len = av_parser_parse2(sti->parser, sti->avctx, | |
1194 | &out_pkt->data, &out_pkt->size, data, size, | ||
1195 | pkt->pts, pkt->dts, pkt->pos); | ||
1196 | |||
1197 | 814744 | pkt->pts = pkt->dts = AV_NOPTS_VALUE; | |
1198 | 814744 | pkt->pos = -1; | |
1199 | /* increment read pointer */ | ||
1200 | av_assert1(data || !len); | ||
1201 |
2/2✓ Branch 0 taken 801844 times.
✓ Branch 1 taken 12900 times.
|
814744 | data = len ? data + len : data; |
1202 | 814744 | size -= len; | |
1203 | |||
1204 | 814744 | got_output = !!out_pkt->size; | |
1205 | |||
1206 |
2/2✓ Branch 0 taken 627983 times.
✓ Branch 1 taken 186761 times.
|
814744 | if (!out_pkt->size) |
1207 | 627983 | continue; | |
1208 | |||
1209 |
4/4✓ Branch 0 taken 185598 times.
✓ Branch 1 taken 1163 times.
✓ Branch 2 taken 69187 times.
✓ Branch 3 taken 116411 times.
|
186761 | if (pkt->buf && out_pkt->data == pkt->data) { |
1210 | /* reference pkt->buf only when out_pkt->data is guaranteed to point | ||
1211 | * to data in it and not in the parser's internal buffer. */ | ||
1212 | /* XXX: Ensure this is the case with all parsers when sti->parser->flags | ||
1213 | * is PARSER_FLAG_COMPLETE_FRAMES and check for that instead? */ | ||
1214 | 69187 | out_pkt->buf = av_buffer_ref(pkt->buf); | |
1215 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 69187 times.
|
69187 | if (!out_pkt->buf) { |
1216 | ✗ | ret = AVERROR(ENOMEM); | |
1217 | ✗ | goto fail; | |
1218 | } | ||
1219 | } else { | ||
1220 | 117574 | ret = av_packet_make_refcounted(out_pkt); | |
1221 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 117574 times.
|
117574 | if (ret < 0) |
1222 | ✗ | goto fail; | |
1223 | } | ||
1224 | |||
1225 |
2/2✓ Branch 0 taken 9165 times.
✓ Branch 1 taken 177596 times.
|
186761 | if (pkt->side_data) { |
1226 | 9165 | out_pkt->side_data = pkt->side_data; | |
1227 | 9165 | out_pkt->side_data_elems = pkt->side_data_elems; | |
1228 | 9165 | pkt->side_data = NULL; | |
1229 | 9165 | pkt->side_data_elems = 0; | |
1230 | } | ||
1231 | |||
1232 | /* set the duration */ | ||
1233 |
2/2✓ Branch 0 taken 49388 times.
✓ Branch 1 taken 137373 times.
|
186761 | out_pkt->duration = (sti->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) ? pkt->duration : 0; |
1234 |
2/2✓ Branch 0 taken 108851 times.
✓ Branch 1 taken 77910 times.
|
186761 | if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { |
1235 |
2/2✓ Branch 0 taken 108745 times.
✓ Branch 1 taken 106 times.
|
108851 | if (sti->avctx->sample_rate > 0) { |
1236 | 108745 | out_pkt->duration = | |
1237 | 108745 | av_rescale_q_rnd(sti->parser->duration, | |
1238 | 108745 | (AVRational) { 1, sti->avctx->sample_rate }, | |
1239 | st->time_base, | ||
1240 | AV_ROUND_DOWN); | ||
1241 | } | ||
1242 |
2/2✓ Branch 0 taken 1822 times.
✓ Branch 1 taken 76088 times.
|
77910 | } else if (st->codecpar->codec_id == AV_CODEC_ID_GIF) { |
1243 |
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 && |
1244 |
1/2✓ Branch 0 taken 1822 times.
✗ Branch 1 not taken.
|
1822 | sti->parser->duration) { |
1245 | 1822 | out_pkt->duration = sti->parser->duration; | |
1246 | } | ||
1247 | } | ||
1248 | |||
1249 | 186761 | out_pkt->stream_index = st->index; | |
1250 | 186761 | out_pkt->pts = sti->parser->pts; | |
1251 | 186761 | out_pkt->dts = sti->parser->dts; | |
1252 | 186761 | out_pkt->pos = sti->parser->pos; | |
1253 | 186761 | out_pkt->flags |= pkt->flags & (AV_PKT_FLAG_DISCARD | AV_PKT_FLAG_CORRUPT); | |
1254 | |||
1255 |
2/2✓ Branch 0 taken 114532 times.
✓ Branch 1 taken 72229 times.
|
186761 | if (sti->need_parsing == AVSTREAM_PARSE_FULL_RAW) |
1256 | 114532 | out_pkt->pos = sti->parser->frame_offset; | |
1257 | |||
1258 |
2/2✓ Branch 0 taken 174992 times.
✓ Branch 1 taken 11769 times.
|
186761 | if (sti->parser->key_frame == 1 || |
1259 |
2/2✓ Branch 0 taken 93684 times.
✓ Branch 1 taken 81308 times.
|
174992 | (sti->parser->key_frame == -1 && |
1260 |
2/2✓ Branch 0 taken 81787 times.
✓ Branch 1 taken 11897 times.
|
93684 | sti->parser->pict_type == AV_PICTURE_TYPE_I)) |
1261 | 93556 | out_pkt->flags |= AV_PKT_FLAG_KEY; | |
1262 | |||
1263 |
6/6✓ Branch 0 taken 93684 times.
✓ Branch 1 taken 93077 times.
✓ Branch 2 taken 317 times.
✓ Branch 3 taken 93367 times.
✓ Branch 4 taken 288 times.
✓ Branch 5 taken 29 times.
|
186761 | if (sti->parser->key_frame == -1 && sti->parser->pict_type ==AV_PICTURE_TYPE_NONE && (pkt->flags&AV_PKT_FLAG_KEY)) |
1264 | 288 | out_pkt->flags |= AV_PKT_FLAG_KEY; | |
1265 | |||
1266 | 186761 | compute_pkt_fields(s, st, sti->parser, out_pkt, next_dts, next_pts); | |
1267 | |||
1268 | 186761 | ret = avpriv_packet_list_put(&fci->parse_queue, | |
1269 | out_pkt, NULL, 0); | ||
1270 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 186761 times.
|
186761 | if (ret < 0) |
1271 | ✗ | goto fail; | |
1272 | } | ||
1273 | |||
1274 | /* end of the stream => close and free the parser */ | ||
1275 |
2/2✓ Branch 0 taken 695611 times.
✓ Branch 1 taken 2075 times.
|
697686 | if (flush) { |
1276 | 2075 | av_parser_close(sti->parser); | |
1277 | 2075 | sti->parser = NULL; | |
1278 | } | ||
1279 | |||
1280 | 695611 | fail: | |
1281 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 697686 times.
|
697686 | if (ret < 0) |
1282 | ✗ | av_packet_unref(out_pkt); | |
1283 | 697686 | av_packet_unref(pkt); | |
1284 | 697686 | return ret; | |
1285 | } | ||
1286 | |||
1287 | 8774 | static int64_t ts_to_samples(AVStream *st, int64_t ts) | |
1288 | { | ||
1289 | 8774 | return av_rescale(ts, st->time_base.num * st->codecpar->sample_rate, st->time_base.den); | |
1290 | } | ||
1291 | |||
1292 | 8284 | static int codec_close(FFStream *sti) | |
1293 | { | ||
1294 | 8284 | AVCodecContext *avctx_new = NULL; | |
1295 | 8284 | AVCodecParameters *par_tmp = NULL; | |
1296 | int ret; | ||
1297 | |||
1298 | 8284 | avctx_new = avcodec_alloc_context3(sti->avctx->codec); | |
1299 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8284 times.
|
8284 | if (!avctx_new) { |
1300 | ✗ | ret = AVERROR(ENOMEM); | |
1301 | ✗ | goto fail; | |
1302 | } | ||
1303 | |||
1304 | 8284 | par_tmp = avcodec_parameters_alloc(); | |
1305 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8284 times.
|
8284 | if (!par_tmp) { |
1306 | ✗ | ret = AVERROR(ENOMEM); | |
1307 | ✗ | goto fail; | |
1308 | } | ||
1309 | |||
1310 | 8284 | ret = avcodec_parameters_from_context(par_tmp, sti->avctx); | |
1311 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8284 times.
|
8284 | if (ret < 0) |
1312 | ✗ | goto fail; | |
1313 | |||
1314 | 8284 | ret = avcodec_parameters_to_context(avctx_new, par_tmp); | |
1315 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8284 times.
|
8284 | if (ret < 0) |
1316 | ✗ | goto fail; | |
1317 | |||
1318 | 8284 | avctx_new->pkt_timebase = sti->avctx->pkt_timebase; | |
1319 | |||
1320 | 8284 | avcodec_free_context(&sti->avctx); | |
1321 | 8284 | sti->avctx = avctx_new; | |
1322 | |||
1323 | 8284 | avctx_new = NULL; | |
1324 | 8284 | ret = 0; | |
1325 | |||
1326 | 8284 | fail: | |
1327 | 8284 | avcodec_free_context(&avctx_new); | |
1328 | 8284 | avcodec_parameters_free(&par_tmp); | |
1329 | |||
1330 | 8284 | return ret; | |
1331 | } | ||
1332 | |||
1333 | static int extract_extradata(FFFormatContext *si, AVStream *st, const AVPacket *pkt); | ||
1334 | |||
1335 | 574320 | static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) | |
1336 | { | ||
1337 | 574320 | FormatContextInternal *const fci = ff_fc_internal(s); | |
1338 | 574320 | FFFormatContext *const si = &fci->fc; | |
1339 | 574320 | int ret, got_packet = 0; | |
1340 | 574320 | AVDictionary *metadata = NULL; | |
1341 | |||
1342 |
4/4✓ Branch 0 taken 1270062 times.
✓ Branch 1 taken 382978 times.
✓ Branch 2 taken 1085130 times.
✓ Branch 3 taken 184932 times.
|
1653040 | while (!got_packet && !fci->parse_queue.head) { |
1343 | AVStream *st; | ||
1344 | FFStream *sti; | ||
1345 | |||
1346 | /* read next packet */ | ||
1347 | 1085130 | ret = ff_read_packet(s, pkt); | |
1348 |
2/2✓ Branch 0 taken 6410 times.
✓ Branch 1 taken 1078720 times.
|
1085130 | if (ret < 0) { |
1349 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6409 times.
|
6410 | if (ret == AVERROR(EAGAIN)) |
1350 | 1 | return ret; | |
1351 | /* flush the parsers */ | ||
1352 |
2/2✓ Branch 0 taken 7452 times.
✓ Branch 1 taken 6409 times.
|
13861 | for (unsigned i = 0; i < s->nb_streams; i++) { |
1353 | 7452 | AVStream *const st = s->streams[i]; | |
1354 | 7452 | FFStream *const sti = ffstream(st); | |
1355 |
4/4✓ Branch 0 taken 2731 times.
✓ Branch 1 taken 4721 times.
✓ Branch 2 taken 2075 times.
✓ Branch 3 taken 656 times.
|
7452 | if (sti->parser && sti->need_parsing) |
1356 | 2075 | parse_packet(s, pkt, st->index, 1); | |
1357 | } | ||
1358 | /* all remaining packets are now in parse_queue => | ||
1359 | * really terminate parsing */ | ||
1360 | 6409 | break; | |
1361 | } | ||
1362 | 1078720 | ret = 0; | |
1363 | 1078720 | st = s->streams[pkt->stream_index]; | |
1364 | 1078720 | sti = ffstream(st); | |
1365 | |||
1366 | 1078720 | st->event_flags |= AVSTREAM_EVENT_FLAG_NEW_PACKETS; | |
1367 | |||
1368 | /* update context if required */ | ||
1369 |
2/2✓ Branch 0 taken 198 times.
✓ Branch 1 taken 1078522 times.
|
1078720 | if (sti->need_context_update) { |
1370 |
2/2✓ Branch 1 taken 13 times.
✓ Branch 2 taken 185 times.
|
198 | if (avcodec_is_open(sti->avctx)) { |
1371 | 13 | av_log(s, AV_LOG_DEBUG, "Demuxer context update while decoder is open, closing and trying to re-open\n"); | |
1372 | 13 | ret = codec_close(sti); | |
1373 | 13 | sti->info->found_decoder = 0; | |
1374 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
|
13 | if (ret < 0) |
1375 | ✗ | return ret; | |
1376 | } | ||
1377 | |||
1378 | /* close parser, because it depends on the codec */ | ||
1379 |
4/4✓ Branch 0 taken 13 times.
✓ Branch 1 taken 185 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 3 times.
|
198 | if (sti->parser && sti->avctx->codec_id != st->codecpar->codec_id) { |
1380 | 10 | av_parser_close(sti->parser); | |
1381 | 10 | sti->parser = NULL; | |
1382 | } | ||
1383 | |||
1384 | 198 | ret = avcodec_parameters_to_context(sti->avctx, st->codecpar); | |
1385 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 198 times.
|
198 | if (ret < 0) { |
1386 | ✗ | av_packet_unref(pkt); | |
1387 | ✗ | return ret; | |
1388 | } | ||
1389 | |||
1390 |
2/2✓ Branch 0 taken 149 times.
✓ Branch 1 taken 49 times.
|
198 | if (!sti->avctx->extradata) { |
1391 | 149 | sti->extract_extradata.inited = 0; | |
1392 | |||
1393 | 149 | ret = extract_extradata(si, st, pkt); | |
1394 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 149 times.
|
149 | if (ret < 0) { |
1395 | ✗ | av_packet_unref(pkt); | |
1396 | ✗ | return ret; | |
1397 | } | ||
1398 | } | ||
1399 | |||
1400 | 198 | sti->codec_desc = avcodec_descriptor_get(sti->avctx->codec_id); | |
1401 | |||
1402 | 198 | sti->need_context_update = 0; | |
1403 | } | ||
1404 | |||
1405 |
2/2✓ Branch 0 taken 337766 times.
✓ Branch 1 taken 740954 times.
|
1078720 | if (pkt->pts != AV_NOPTS_VALUE && |
1406 |
2/2✓ Branch 0 taken 168844 times.
✓ Branch 1 taken 168922 times.
|
337766 | pkt->dts != AV_NOPTS_VALUE && |
1407 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 168844 times.
|
168844 | pkt->pts < pkt->dts) { |
1408 | ✗ | av_log(s, AV_LOG_WARNING, | |
1409 | "Invalid timestamps stream=%d, pts=%s, dts=%s, size=%d\n", | ||
1410 | pkt->stream_index, | ||
1411 | ✗ | av_ts2str(pkt->pts), | |
1412 | ✗ | av_ts2str(pkt->dts), | |
1413 | pkt->size); | ||
1414 | } | ||
1415 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1078720 times.
|
1078720 | if (s->debug & FF_FDEBUG_TS) |
1416 | ✗ | av_log(s, AV_LOG_DEBUG, | |
1417 | "ff_read_packet stream=%d, pts=%s, dts=%s, size=%d, duration=%"PRId64", flags=%d\n", | ||
1418 | pkt->stream_index, | ||
1419 | ✗ | av_ts2str(pkt->pts), | |
1420 | ✗ | av_ts2str(pkt->dts), | |
1421 | pkt->size, pkt->duration, pkt->flags); | ||
1422 | |||
1423 |
5/6✓ Branch 0 taken 696899 times.
✓ Branch 1 taken 381821 times.
✓ Branch 2 taken 2770 times.
✓ Branch 3 taken 694129 times.
✓ Branch 4 taken 2770 times.
✗ Branch 5 not taken.
|
1078720 | if (sti->need_parsing && !sti->parser && !(s->flags & AVFMT_FLAG_NOPARSE)) { |
1424 | 2770 | sti->parser = av_parser_init(st->codecpar->codec_id); | |
1425 |
2/2✓ Branch 0 taken 1157 times.
✓ Branch 1 taken 1613 times.
|
2770 | if (!sti->parser) { |
1426 | 1157 | av_log(s, AV_LOG_VERBOSE, "parser not found for codec " | |
1427 | "%s, packets or times may be invalid.\n", | ||
1428 | 1157 | avcodec_get_name(st->codecpar->codec_id)); | |
1429 | /* no parser available: just output the raw packets */ | ||
1430 | 1157 | sti->need_parsing = AVSTREAM_PARSE_NONE; | |
1431 |
2/2✓ Branch 0 taken 718 times.
✓ Branch 1 taken 895 times.
|
1613 | } else if (sti->need_parsing == AVSTREAM_PARSE_HEADERS) |
1432 | 718 | sti->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES; | |
1433 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 895 times.
|
895 | else if (sti->need_parsing == AVSTREAM_PARSE_FULL_ONCE) |
1434 | ✗ | sti->parser->flags |= PARSER_FLAG_ONCE; | |
1435 |
2/2✓ Branch 0 taken 471 times.
✓ Branch 1 taken 424 times.
|
895 | else if (sti->need_parsing == AVSTREAM_PARSE_FULL_RAW) |
1436 | 471 | sti->parser->flags |= PARSER_FLAG_USE_CODEC_TS; | |
1437 | } | ||
1438 | |||
1439 |
3/4✓ Branch 0 taken 695742 times.
✓ Branch 1 taken 382978 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 695742 times.
|
1078720 | if (!sti->need_parsing || !sti->parser) { |
1440 | /* no parsing needed: we just output the packet as is */ | ||
1441 | 382978 | compute_pkt_fields(s, st, NULL, pkt, AV_NOPTS_VALUE, AV_NOPTS_VALUE); | |
1442 |
2/2✓ Branch 0 taken 93130 times.
✓ Branch 1 taken 289848 times.
|
382978 | if ((s->iformat->flags & AVFMT_GENERIC_INDEX) && |
1443 |
4/4✓ Branch 0 taken 92394 times.
✓ Branch 1 taken 736 times.
✓ Branch 2 taken 92249 times.
✓ Branch 3 taken 145 times.
|
93130 | (pkt->flags & AV_PKT_FLAG_KEY) && pkt->dts != AV_NOPTS_VALUE) { |
1444 | 92249 | ff_reduce_index(s, st->index); | |
1445 | 92249 | av_add_index_entry(st, pkt->pos, pkt->dts, | |
1446 | 0, 0, AVINDEX_KEYFRAME); | ||
1447 | } | ||
1448 | 382978 | got_packet = 1; | |
1449 |
2/2✓ Branch 0 taken 695611 times.
✓ Branch 1 taken 131 times.
|
695742 | } else if (st->discard < AVDISCARD_ALL) { |
1450 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 695611 times.
|
695611 | if ((ret = parse_packet(s, pkt, pkt->stream_index, 0)) < 0) |
1451 | ✗ | return ret; | |
1452 | 695611 | st->codecpar->sample_rate = sti->avctx->sample_rate; | |
1453 | 695611 | st->codecpar->bit_rate = sti->avctx->bit_rate; | |
1454 | 695611 | ret = av_channel_layout_copy(&st->codecpar->ch_layout, &sti->avctx->ch_layout); | |
1455 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 695611 times.
|
695611 | if (ret < 0) |
1456 | ✗ | return ret; | |
1457 | 695611 | st->codecpar->codec_id = sti->avctx->codec_id; | |
1458 | } else { | ||
1459 | /* free packet */ | ||
1460 | 131 | av_packet_unref(pkt); | |
1461 | } | ||
1462 |
2/2✓ Branch 0 taken 359561 times.
✓ Branch 1 taken 719159 times.
|
1078720 | if (pkt->flags & AV_PKT_FLAG_KEY) |
1463 | 359561 | sti->skip_to_keyframe = 0; | |
1464 |
2/2✓ Branch 0 taken 85 times.
✓ Branch 1 taken 1078635 times.
|
1078720 | if (sti->skip_to_keyframe) { |
1465 | 85 | av_packet_unref(pkt); | |
1466 | 85 | got_packet = 0; | |
1467 | } | ||
1468 | } | ||
1469 | |||
1470 |
4/4✓ Branch 0 taken 191341 times.
✓ Branch 1 taken 382978 times.
✓ Branch 2 taken 185838 times.
✓ Branch 3 taken 5503 times.
|
574319 | if (!got_packet && fci->parse_queue.head) |
1471 | 185838 | ret = avpriv_packet_list_get(&fci->parse_queue, pkt); | |
1472 | |||
1473 |
2/2✓ Branch 0 taken 568816 times.
✓ Branch 1 taken 5503 times.
|
574319 | if (ret >= 0) { |
1474 | 568816 | AVStream *const st = s->streams[pkt->stream_index]; | |
1475 | 568816 | FFStream *const sti = ffstream(st); | |
1476 | 568816 | int discard_padding = 0; | |
1477 |
3/4✓ Branch 0 taken 4387 times.
✓ Branch 1 taken 564429 times.
✓ Branch 2 taken 4387 times.
✗ Branch 3 not taken.
|
568816 | if (sti->first_discard_sample && pkt->pts != AV_NOPTS_VALUE) { |
1478 |
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); |
1479 | 4387 | int64_t sample = ts_to_samples(st, pts); | |
1480 | 4387 | int64_t duration = ts_to_samples(st, pkt->duration); | |
1481 | 4387 | int64_t end_sample = sample + duration; | |
1482 |
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 && |
1483 |
1/2✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
|
14 | sample < sti->last_discard_sample) |
1484 | 14 | discard_padding = FFMIN(end_sample - sti->first_discard_sample, duration); | |
1485 | } | ||
1486 |
6/6✓ Branch 0 taken 4387 times.
✓ Branch 1 taken 564429 times.
✓ Branch 2 taken 4371 times.
✓ Branch 3 taken 16 times.
✓ Branch 4 taken 20 times.
✓ Branch 5 taken 4351 times.
|
568816 | if (sti->start_skip_samples && (pkt->pts == 0 || pkt->pts == RELATIVE_TS_BASE)) |
1487 | 36 | sti->skip_samples = sti->start_skip_samples; | |
1488 | 568816 | sti->skip_samples = FFMAX(0, sti->skip_samples); | |
1489 |
4/4✓ Branch 0 taken 568728 times.
✓ Branch 1 taken 88 times.
✓ Branch 2 taken 14 times.
✓ Branch 3 taken 568714 times.
|
568816 | if (sti->skip_samples || discard_padding) { |
1490 | 102 | uint8_t *p = av_packet_new_side_data(pkt, AV_PKT_DATA_SKIP_SAMPLES, 10); | |
1491 |
1/2✓ Branch 0 taken 102 times.
✗ Branch 1 not taken.
|
102 | if (p) { |
1492 | 102 | AV_WL32(p, sti->skip_samples); | |
1493 | 102 | AV_WL32(p + 4, discard_padding); | |
1494 | 102 | av_log(s, AV_LOG_DEBUG, "demuxer injecting skip %u / discard %u\n", | |
1495 | 102 | (unsigned)sti->skip_samples, (unsigned)discard_padding); | |
1496 | } | ||
1497 | 102 | sti->skip_samples = 0; | |
1498 | } | ||
1499 | } | ||
1500 | |||
1501 |
2/2✓ Branch 0 taken 7578 times.
✓ Branch 1 taken 566741 times.
|
574319 | if (!fci->metafree) { |
1502 | 7578 | int metaret = av_opt_get_dict_val(s, "metadata", AV_OPT_SEARCH_CHILDREN, &metadata); | |
1503 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7578 times.
|
7578 | if (metadata) { |
1504 | ✗ | s->event_flags |= AVFMT_EVENT_FLAG_METADATA_UPDATED; | |
1505 | ✗ | av_dict_copy(&s->metadata, metadata, 0); | |
1506 | ✗ | av_dict_free(&metadata); | |
1507 | ✗ | av_opt_set_dict_val(s, "metadata", NULL, AV_OPT_SEARCH_CHILDREN); | |
1508 | } | ||
1509 | 7578 | fci->metafree = metaret == AVERROR_OPTION_NOT_FOUND; | |
1510 | } | ||
1511 | |||
1512 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 574319 times.
|
574319 | if (s->debug & FF_FDEBUG_TS) |
1513 | ✗ | av_log(s, AV_LOG_DEBUG, | |
1514 | "read_frame_internal stream=%d, pts=%s, dts=%s, " | ||
1515 | "size=%d, duration=%"PRId64", flags=%d\n", | ||
1516 | pkt->stream_index, | ||
1517 | ✗ | av_ts2str(pkt->pts), | |
1518 | ✗ | av_ts2str(pkt->dts), | |
1519 | pkt->size, pkt->duration, pkt->flags); | ||
1520 | |||
1521 | /* A demuxer might have returned EOF because of an IO error, let's | ||
1522 | * propagate this back to the user. */ | ||
1523 |
5/8✓ Branch 0 taken 5391 times.
✓ Branch 1 taken 568928 times.
✓ Branch 2 taken 5173 times.
✓ Branch 3 taken 218 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 5173 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
574319 | if (ret == AVERROR_EOF && s->pb && s->pb->error < 0 && s->pb->error != AVERROR(EAGAIN)) |
1524 | ✗ | ret = s->pb->error; | |
1525 | |||
1526 | 574319 | return ret; | |
1527 | } | ||
1528 | |||
1529 | 512261 | int av_read_frame(AVFormatContext *s, AVPacket *pkt) | |
1530 | { | ||
1531 | 512261 | FFFormatContext *const si = ffformatcontext(s); | |
1532 | 512261 | const int genpts = s->flags & AVFMT_FLAG_GENPTS; | |
1533 | 512261 | int eof = 0; | |
1534 | int ret; | ||
1535 | AVStream *st; | ||
1536 | |||
1537 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 512261 times.
|
512261 | if (!genpts) { |
1538 | 1024522 | ret = si->packet_buffer.head | |
1539 | 132786 | ? avpriv_packet_list_get(&si->packet_buffer, pkt) | |
1540 |
2/2✓ Branch 0 taken 132786 times.
✓ Branch 1 taken 379475 times.
|
512261 | : read_frame_internal(s, pkt); |
1541 |
2/2✓ Branch 0 taken 4318 times.
✓ Branch 1 taken 507943 times.
|
512261 | if (ret < 0) |
1542 | 4318 | return ret; | |
1543 | 507943 | goto return_packet; | |
1544 | } | ||
1545 | |||
1546 | ✗ | for (;;) { | |
1547 | ✗ | PacketListEntry *pktl = si->packet_buffer.head; | |
1548 | |||
1549 | ✗ | if (pktl) { | |
1550 | ✗ | AVPacket *next_pkt = &pktl->pkt; | |
1551 | |||
1552 | ✗ | if (next_pkt->dts != AV_NOPTS_VALUE) { | |
1553 | ✗ | int wrap_bits = s->streams[next_pkt->stream_index]->pts_wrap_bits; | |
1554 | // last dts seen for this stream. if any of packets following | ||
1555 | // current one had no dts, we will set this to AV_NOPTS_VALUE. | ||
1556 | ✗ | int64_t last_dts = next_pkt->dts; | |
1557 | av_assert2(wrap_bits <= 64); | ||
1558 | ✗ | while (pktl && next_pkt->pts == AV_NOPTS_VALUE) { | |
1559 | ✗ | if (pktl->pkt.stream_index == next_pkt->stream_index && | |
1560 | ✗ | av_compare_mod(next_pkt->dts, pktl->pkt.dts, 2ULL << (wrap_bits - 1)) < 0) { | |
1561 | ✗ | if (av_compare_mod(pktl->pkt.pts, pktl->pkt.dts, 2ULL << (wrap_bits - 1))) { | |
1562 | // not B-frame | ||
1563 | ✗ | next_pkt->pts = pktl->pkt.dts; | |
1564 | } | ||
1565 | ✗ | if (last_dts != AV_NOPTS_VALUE) { | |
1566 | // Once last dts was set to AV_NOPTS_VALUE, we don't change it. | ||
1567 | ✗ | last_dts = pktl->pkt.dts; | |
1568 | } | ||
1569 | } | ||
1570 | ✗ | pktl = pktl->next; | |
1571 | } | ||
1572 | ✗ | if (eof && next_pkt->pts == AV_NOPTS_VALUE && last_dts != AV_NOPTS_VALUE) { | |
1573 | // Fixing the last reference frame had none pts issue (For MXF etc). | ||
1574 | // We only do this when | ||
1575 | // 1. eof. | ||
1576 | // 2. we are not able to resolve a pts value for current packet. | ||
1577 | // 3. the packets for this stream at the end of the files had valid dts. | ||
1578 | ✗ | next_pkt->pts = last_dts + next_pkt->duration; | |
1579 | } | ||
1580 | ✗ | pktl = si->packet_buffer.head; | |
1581 | } | ||
1582 | |||
1583 | /* read packet from packet buffer, if there is data */ | ||
1584 | ✗ | st = s->streams[next_pkt->stream_index]; | |
1585 | ✗ | if (!(next_pkt->pts == AV_NOPTS_VALUE && st->discard < AVDISCARD_ALL && | |
1586 | ✗ | next_pkt->dts != AV_NOPTS_VALUE && !eof)) { | |
1587 | ✗ | ret = avpriv_packet_list_get(&si->packet_buffer, pkt); | |
1588 | ✗ | goto return_packet; | |
1589 | } | ||
1590 | } | ||
1591 | |||
1592 | ✗ | ret = read_frame_internal(s, pkt); | |
1593 | ✗ | if (ret < 0) { | |
1594 | ✗ | if (pktl && ret != AVERROR(EAGAIN)) { | |
1595 | ✗ | eof = 1; | |
1596 | ✗ | continue; | |
1597 | } else | ||
1598 | ✗ | return ret; | |
1599 | } | ||
1600 | |||
1601 | ✗ | ret = avpriv_packet_list_put(&si->packet_buffer, | |
1602 | pkt, NULL, 0); | ||
1603 | ✗ | if (ret < 0) { | |
1604 | ✗ | av_packet_unref(pkt); | |
1605 | ✗ | return ret; | |
1606 | } | ||
1607 | } | ||
1608 | |||
1609 | 507943 | return_packet: | |
1610 | 507943 | st = s->streams[pkt->stream_index]; | |
1611 |
4/4✓ Branch 0 taken 194337 times.
✓ Branch 1 taken 313606 times.
✓ Branch 2 taken 120669 times.
✓ Branch 3 taken 73668 times.
|
507943 | if ((s->iformat->flags & AVFMT_GENERIC_INDEX) && pkt->flags & AV_PKT_FLAG_KEY) { |
1612 | 120669 | ff_reduce_index(s, st->index); | |
1613 | 120669 | av_add_index_entry(st, pkt->pos, pkt->dts, 0, 0, AVINDEX_KEYFRAME); | |
1614 | } | ||
1615 | |||
1616 |
2/2✓ Branch 1 taken 120264 times.
✓ Branch 2 taken 387679 times.
|
507943 | if (is_relative(pkt->dts)) |
1617 | 120264 | pkt->dts -= RELATIVE_TS_BASE; | |
1618 |
2/2✓ Branch 1 taken 118570 times.
✓ Branch 2 taken 389373 times.
|
507943 | if (is_relative(pkt->pts)) |
1619 | 118570 | pkt->pts -= RELATIVE_TS_BASE; | |
1620 | |||
1621 | 507943 | return ret; | |
1622 | } | ||
1623 | |||
1624 | /** | ||
1625 | * Return TRUE if the stream has accurate duration in any stream. | ||
1626 | * | ||
1627 | * @return TRUE if the stream has accurate duration for at least one component. | ||
1628 | */ | ||
1629 | 7501 | static int has_duration(AVFormatContext *ic) | |
1630 | { | ||
1631 |
2/2✓ Branch 0 taken 7792 times.
✓ Branch 1 taken 2423 times.
|
10215 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
1632 | 7792 | const AVStream *const st = ic->streams[i]; | |
1633 |
2/2✓ Branch 0 taken 5078 times.
✓ Branch 1 taken 2714 times.
|
7792 | if (st->duration != AV_NOPTS_VALUE) |
1634 | 5078 | return 1; | |
1635 | } | ||
1636 |
2/2✓ Branch 0 taken 439 times.
✓ Branch 1 taken 1984 times.
|
2423 | if (ic->duration != AV_NOPTS_VALUE) |
1637 | 439 | return 1; | |
1638 | 1984 | return 0; | |
1639 | } | ||
1640 | |||
1641 | /** | ||
1642 | * Estimate the stream timings from the one of each components. | ||
1643 | * | ||
1644 | * Also computes the global bitrate if possible. | ||
1645 | */ | ||
1646 | 13156 | static void update_stream_timings(AVFormatContext *ic) | |
1647 | { | ||
1648 | int64_t start_time, start_time1, start_time_text, end_time, end_time1, end_time_text; | ||
1649 | int64_t duration, duration1, duration_text, filesize; | ||
1650 | |||
1651 | 13156 | start_time = INT64_MAX; | |
1652 | 13156 | start_time_text = INT64_MAX; | |
1653 | 13156 | end_time = INT64_MIN; | |
1654 | 13156 | end_time_text = INT64_MIN; | |
1655 | 13156 | duration = INT64_MIN; | |
1656 | 13156 | duration_text = INT64_MIN; | |
1657 | |||
1658 |
2/2✓ Branch 0 taken 14628 times.
✓ Branch 1 taken 13156 times.
|
27784 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
1659 | 14628 | AVStream *const st = ic->streams[i]; | |
1660 |
2/2✓ Branch 0 taken 14503 times.
✓ Branch 1 taken 125 times.
|
29131 | int is_text = st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE || |
1661 |
2/2✓ Branch 0 taken 151 times.
✓ Branch 1 taken 14352 times.
|
14503 | st->codecpar->codec_type == AVMEDIA_TYPE_DATA; |
1662 | |||
1663 |
3/4✓ Branch 0 taken 11976 times.
✓ Branch 1 taken 2652 times.
✓ Branch 2 taken 11976 times.
✗ Branch 3 not taken.
|
14628 | if (st->start_time != AV_NOPTS_VALUE && st->time_base.den) { |
1664 | 11976 | start_time1 = av_rescale_q(st->start_time, st->time_base, | |
1665 | 11976 | AV_TIME_BASE_Q); | |
1666 |
2/2✓ Branch 0 taken 158 times.
✓ Branch 1 taken 11818 times.
|
11976 | if (is_text) |
1667 | 158 | start_time_text = FFMIN(start_time_text, start_time1); | |
1668 | else | ||
1669 | 11818 | start_time = FFMIN(start_time, start_time1); | |
1670 | 11976 | end_time1 = av_rescale_q_rnd(st->duration, st->time_base, | |
1671 | 11976 | AV_TIME_BASE_Q, | |
1672 | AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX); | ||
1673 |
5/6✓ Branch 0 taken 10588 times.
✓ Branch 1 taken 1388 times.
✓ Branch 2 taken 10559 times.
✓ Branch 3 taken 29 times.
✓ Branch 4 taken 10588 times.
✗ Branch 5 not taken.
|
11976 | if (end_time1 != AV_NOPTS_VALUE && (end_time1 > 0 ? start_time1 <= INT64_MAX - end_time1 : start_time1 >= INT64_MIN - end_time1)) { |
1674 | 10588 | end_time1 += start_time1; | |
1675 |
2/2✓ Branch 0 taken 143 times.
✓ Branch 1 taken 10445 times.
|
10588 | if (is_text) |
1676 | 143 | end_time_text = FFMAX(end_time_text, end_time1); | |
1677 | else | ||
1678 | 10445 | end_time = FFMAX(end_time, end_time1); | |
1679 | } | ||
1680 |
2/2✓ Branch 1 taken 208 times.
✓ Branch 2 taken 11976 times.
|
12184 | for (AVProgram *p = NULL; (p = av_find_program_from_stream(ic, p, i)); ) { |
1681 |
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) |
1682 | 81 | p->start_time = start_time1; | |
1683 |
2/2✓ Branch 0 taken 52 times.
✓ Branch 1 taken 156 times.
|
208 | if (p->end_time < end_time1) |
1684 | 52 | p->end_time = end_time1; | |
1685 | } | ||
1686 | } | ||
1687 |
2/2✓ Branch 0 taken 12045 times.
✓ Branch 1 taken 2583 times.
|
14628 | if (st->duration != AV_NOPTS_VALUE) { |
1688 | 12045 | duration1 = av_rescale_q(st->duration, st->time_base, | |
1689 | 12045 | AV_TIME_BASE_Q); | |
1690 |
2/2✓ Branch 0 taken 167 times.
✓ Branch 1 taken 11878 times.
|
12045 | if (is_text) |
1691 | 167 | duration_text = FFMAX(duration_text, duration1); | |
1692 | else | ||
1693 | 11878 | duration = FFMAX(duration, duration1); | |
1694 | } | ||
1695 | } | ||
1696 |
3/6✓ Branch 0 taken 10718 times.
✓ Branch 1 taken 2438 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 10718 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
13156 | if (start_time == INT64_MAX || (start_time > start_time_text && start_time - (uint64_t)start_time_text < AV_TIME_BASE)) |
1697 | 2438 | start_time = start_time_text; | |
1698 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10718 times.
|
10718 | else if (start_time > start_time_text) |
1699 | ✗ | av_log(ic, AV_LOG_VERBOSE, "Ignoring outlier non primary stream starttime %f\n", start_time_text / (float)AV_TIME_BASE); | |
1700 | |||
1701 |
5/6✓ Branch 0 taken 9740 times.
✓ Branch 1 taken 3416 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 9738 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
13156 | if (end_time == INT64_MIN || (end_time < end_time_text && end_time_text - (uint64_t)end_time < AV_TIME_BASE)) |
1702 | 3418 | end_time = end_time_text; | |
1703 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9738 times.
|
9738 | else if (end_time < end_time_text) |
1704 | ✗ | av_log(ic, AV_LOG_VERBOSE, "Ignoring outlier non primary stream endtime %f\n", end_time_text / (float)AV_TIME_BASE); | |
1705 | |||
1706 |
5/6✓ Branch 0 taken 11158 times.
✓ Branch 1 taken 1998 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 11152 times.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
|
13156 | if (duration == INT64_MIN || (duration < duration_text && (uint64_t)duration_text - duration < AV_TIME_BASE)) |
1707 | 2004 | duration = duration_text; | |
1708 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11152 times.
|
11152 | else if (duration < duration_text) |
1709 | ✗ | av_log(ic, AV_LOG_VERBOSE, "Ignoring outlier non primary stream duration %f\n", duration_text / (float)AV_TIME_BASE); | |
1710 | |||
1711 |
2/2✓ Branch 0 taken 10739 times.
✓ Branch 1 taken 2417 times.
|
13156 | if (start_time != INT64_MAX) { |
1712 | 10739 | ic->start_time = start_time; | |
1713 |
2/2✓ Branch 0 taken 9757 times.
✓ Branch 1 taken 982 times.
|
10739 | if (end_time != INT64_MIN) { |
1714 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9757 times.
|
9757 | if (ic->nb_programs > 1) { |
1715 | ✗ | for (unsigned i = 0; i < ic->nb_programs; i++) { | |
1716 | ✗ | AVProgram *const p = ic->programs[i]; | |
1717 | |||
1718 | ✗ | if (p->start_time != AV_NOPTS_VALUE && | |
1719 | ✗ | p->end_time > p->start_time && | |
1720 | ✗ | p->end_time - (uint64_t)p->start_time <= INT64_MAX) | |
1721 | ✗ | duration = FFMAX(duration, p->end_time - p->start_time); | |
1722 | } | ||
1723 |
2/4✓ Branch 0 taken 9757 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9757 times.
✗ Branch 3 not taken.
|
9757 | } else if (end_time >= start_time && end_time - (uint64_t)start_time <= INT64_MAX) { |
1724 | 9757 | duration = FFMAX(duration, end_time - start_time); | |
1725 | } | ||
1726 | } | ||
1727 | } | ||
1728 |
6/6✓ Branch 0 taken 11188 times.
✓ Branch 1 taken 1968 times.
✓ Branch 2 taken 11152 times.
✓ Branch 3 taken 36 times.
✓ Branch 4 taken 5992 times.
✓ Branch 5 taken 5160 times.
|
13156 | if (duration != INT64_MIN && duration > 0 && ic->duration == AV_NOPTS_VALUE) { |
1729 | 5992 | ic->duration = duration; | |
1730 | } | ||
1731 |
5/6✓ Branch 0 taken 7081 times.
✓ Branch 1 taken 6075 times.
✓ Branch 3 taken 7081 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 5967 times.
✓ Branch 6 taken 1114 times.
|
13156 | if (ic->pb && (filesize = avio_size(ic->pb)) > 0 && ic->duration > 0) { |
1732 | /* compute the bitrate */ | ||
1733 | 5967 | double bitrate = (double) filesize * 8.0 * AV_TIME_BASE / | |
1734 | 5967 | (double) ic->duration; | |
1735 |
2/4✓ Branch 0 taken 5967 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5967 times.
✗ Branch 3 not taken.
|
5967 | if (bitrate >= 0 && bitrate <= INT64_MAX) |
1736 | 5967 | ic->bit_rate = bitrate; | |
1737 | } | ||
1738 | 13156 | } | |
1739 | |||
1740 | 5586 | static void fill_all_stream_timings(AVFormatContext *ic) | |
1741 | { | ||
1742 | 5586 | update_stream_timings(ic); | |
1743 |
2/2✓ Branch 0 taken 6249 times.
✓ Branch 1 taken 5586 times.
|
11835 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
1744 | 6249 | AVStream *const st = ic->streams[i]; | |
1745 | |||
1746 |
2/2✓ Branch 0 taken 772 times.
✓ Branch 1 taken 5477 times.
|
6249 | if (st->start_time == AV_NOPTS_VALUE) { |
1747 |
2/2✓ Branch 0 taken 129 times.
✓ Branch 1 taken 643 times.
|
772 | if (ic->start_time != AV_NOPTS_VALUE) |
1748 | 129 | st->start_time = av_rescale_q(ic->start_time, AV_TIME_BASE_Q, | |
1749 | st->time_base); | ||
1750 |
2/2✓ Branch 0 taken 757 times.
✓ Branch 1 taken 15 times.
|
772 | if (ic->duration != AV_NOPTS_VALUE) |
1751 | 757 | st->duration = av_rescale_q(ic->duration, AV_TIME_BASE_Q, | |
1752 | st->time_base); | ||
1753 | } | ||
1754 | } | ||
1755 | 5586 | } | |
1756 | |||
1757 | 1984 | static void estimate_timings_from_bit_rate(AVFormatContext *ic) | |
1758 | { | ||
1759 | 1984 | FFFormatContext *const si = ffformatcontext(ic); | |
1760 | 1984 | int show_warning = 0; | |
1761 | |||
1762 | /* if bit_rate is already set, we believe it */ | ||
1763 |
2/2✓ Branch 0 taken 1949 times.
✓ Branch 1 taken 35 times.
|
1984 | if (ic->bit_rate <= 0) { |
1764 | 1949 | int64_t bit_rate = 0; | |
1765 |
2/2✓ Branch 0 taken 2073 times.
✓ Branch 1 taken 1302 times.
|
3375 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
1766 | 2073 | const AVStream *const st = ic->streams[i]; | |
1767 | 2073 | const FFStream *const sti = cffstream(st); | |
1768 |
4/4✓ Branch 0 taken 1297 times.
✓ Branch 1 taken 776 times.
✓ Branch 2 taken 110 times.
✓ Branch 3 taken 1187 times.
|
2073 | if (st->codecpar->bit_rate <= 0 && sti->avctx->bit_rate > 0) |
1769 | 110 | st->codecpar->bit_rate = sti->avctx->bit_rate; | |
1770 |
2/2✓ Branch 0 taken 886 times.
✓ Branch 1 taken 1187 times.
|
2073 | if (st->codecpar->bit_rate > 0) { |
1771 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 886 times.
|
886 | if (INT64_MAX - st->codecpar->bit_rate < bit_rate) { |
1772 | ✗ | bit_rate = 0; | |
1773 | ✗ | break; | |
1774 | } | ||
1775 | 886 | bit_rate += st->codecpar->bit_rate; | |
1776 |
4/4✓ Branch 0 taken 1019 times.
✓ Branch 1 taken 168 times.
✓ Branch 2 taken 647 times.
✓ Branch 3 taken 372 times.
|
1187 | } else if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && sti->codec_info_nb_frames > 1) { |
1777 | // If we have a videostream with packets but without a bitrate | ||
1778 | // then consider the sum not known | ||
1779 | 647 | bit_rate = 0; | |
1780 | 647 | break; | |
1781 | } | ||
1782 | } | ||
1783 | 1949 | ic->bit_rate = bit_rate; | |
1784 | } | ||
1785 | |||
1786 | /* if duration is already set, we believe it */ | ||
1787 |
1/2✓ Branch 0 taken 1984 times.
✗ Branch 1 not taken.
|
1984 | if (ic->duration == AV_NOPTS_VALUE && |
1788 |
2/2✓ Branch 0 taken 893 times.
✓ Branch 1 taken 1091 times.
|
1984 | ic->bit_rate != 0) { |
1789 |
2/2✓ Branch 0 taken 869 times.
✓ Branch 1 taken 24 times.
|
893 | int64_t filesize = ic->pb ? avio_size(ic->pb) : 0; |
1790 |
2/2✓ Branch 0 taken 863 times.
✓ Branch 1 taken 30 times.
|
893 | if (filesize > si->data_offset) { |
1791 | 863 | filesize -= si->data_offset; | |
1792 |
2/2✓ Branch 0 taken 900 times.
✓ Branch 1 taken 863 times.
|
1763 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
1793 | 900 | AVStream *const st = ic->streams[i]; | |
1794 | |||
1795 |
1/2✓ Branch 0 taken 900 times.
✗ Branch 1 not taken.
|
900 | if ( st->time_base.num <= INT64_MAX / ic->bit_rate |
1796 |
1/2✓ Branch 0 taken 900 times.
✗ Branch 1 not taken.
|
900 | && st->duration == AV_NOPTS_VALUE) { |
1797 | 900 | st->duration = av_rescale(filesize, 8LL * st->time_base.den, | |
1798 | 900 | ic->bit_rate * | |
1799 | 900 | (int64_t) st->time_base.num); | |
1800 | 900 | show_warning = 1; | |
1801 | } | ||
1802 | } | ||
1803 | } | ||
1804 | } | ||
1805 |
2/2✓ Branch 0 taken 863 times.
✓ Branch 1 taken 1121 times.
|
1984 | if (show_warning) |
1806 | 863 | av_log(ic, AV_LOG_WARNING, | |
1807 | "Estimating duration from bitrate, this may be inaccurate\n"); | ||
1808 | 1984 | } | |
1809 | |||
1810 | #define DURATION_DEFAULT_MAX_READ_SIZE 250000LL | ||
1811 | #define DURATION_DEFAULT_MAX_RETRY 6 | ||
1812 | #define DURATION_MAX_RETRY 1 | ||
1813 | |||
1814 | /* only usable for MPEG-PS streams */ | ||
1815 | 69 | static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) | |
1816 | { | ||
1817 | 69 | FFFormatContext *const si = ffformatcontext(ic); | |
1818 | 69 | AVPacket *const pkt = si->pkt; | |
1819 | int num, den, read_size, ret; | ||
1820 |
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; |
1821 |
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; |
1822 | 69 | int found_duration = 0; | |
1823 | int is_end; | ||
1824 | int64_t filesize, offset, duration; | ||
1825 | 69 | int retry = 0; | |
1826 | |||
1827 | /* flush packet queue */ | ||
1828 | 69 | ff_flush_packet_queue(ic); | |
1829 | |||
1830 |
2/2✓ Branch 0 taken 143 times.
✓ Branch 1 taken 69 times.
|
212 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
1831 | 143 | AVStream *const st = ic->streams[i]; | |
1832 | 143 | FFStream *const sti = ffstream(st); | |
1833 | |||
1834 |
2/2✓ Branch 0 taken 22 times.
✓ Branch 1 taken 121 times.
|
143 | if (st->start_time == AV_NOPTS_VALUE && |
1835 |
1/2✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
|
22 | sti->first_dts == AV_NOPTS_VALUE && |
1836 |
1/2✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
|
22 | st->codecpar->codec_type != AVMEDIA_TYPE_UNKNOWN) |
1837 | 22 | av_log(ic, AV_LOG_WARNING, | |
1838 | "start time for stream %d is not set in estimate_timings_from_pts\n", i); | ||
1839 | |||
1840 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 119 times.
|
143 | if (sti->parser) { |
1841 | 24 | av_parser_close(sti->parser); | |
1842 | 24 | sti->parser = NULL; | |
1843 | } | ||
1844 | } | ||
1845 | |||
1846 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 69 times.
|
69 | if (ic->skip_estimate_duration_from_pts) { |
1847 | ✗ | av_log(ic, AV_LOG_INFO, "Skipping duration calculation in estimate_timings_from_pts\n"); | |
1848 | ✗ | goto skip_duration_calc; | |
1849 | } | ||
1850 | |||
1851 | 69 | av_opt_set_int(ic, "skip_changes", 1, AV_OPT_SEARCH_CHILDREN); | |
1852 | /* estimate the end time (duration) */ | ||
1853 | /* XXX: may need to support wrapping */ | ||
1854 |
1/2✓ Branch 0 taken 69 times.
✗ Branch 1 not taken.
|
69 | filesize = ic->pb ? avio_size(ic->pb) : 0; |
1855 | do { | ||
1856 | 76 | is_end = found_duration; | |
1857 | 76 | offset = filesize - (duration_max_read_size << retry); | |
1858 |
2/2✓ Branch 0 taken 26 times.
✓ Branch 1 taken 50 times.
|
76 | if (offset < 0) |
1859 | 26 | offset = 0; | |
1860 | |||
1861 | 76 | avio_seek(ic->pb, offset, SEEK_SET); | |
1862 | 76 | read_size = 0; | |
1863 | 6554 | for (;;) { | |
1864 | AVStream *st; | ||
1865 | FFStream *sti; | ||
1866 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 6623 times.
|
6630 | if (read_size >= duration_max_read_size << (FFMAX(retry - 1, 0))) |
1867 | 7 | break; | |
1868 | |||
1869 | do { | ||
1870 | 6623 | ret = ff_read_packet(ic, pkt); | |
1871 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6623 times.
|
6623 | } while (ret == AVERROR(EAGAIN)); |
1872 |
2/2✓ Branch 0 taken 69 times.
✓ Branch 1 taken 6554 times.
|
6623 | if (ret != 0) |
1873 | 69 | break; | |
1874 | 6554 | read_size += pkt->size; | |
1875 | 6554 | st = ic->streams[pkt->stream_index]; | |
1876 | 6554 | sti = ffstream(st); | |
1877 |
2/2✓ Branch 0 taken 2805 times.
✓ Branch 1 taken 3749 times.
|
6554 | if (pkt->pts != AV_NOPTS_VALUE && |
1878 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2805 times.
|
2805 | (st->start_time != AV_NOPTS_VALUE || |
1879 | ✗ | sti->first_dts != AV_NOPTS_VALUE)) { | |
1880 |
1/2✓ Branch 0 taken 2805 times.
✗ Branch 1 not taken.
|
2805 | if (pkt->duration == 0) { |
1881 | 2805 | compute_frame_duration(ic, &num, &den, st, sti->parser, pkt); | |
1882 |
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) { |
1883 | 2345 | pkt->duration = av_rescale_rnd(1, | |
1884 | 2345 | num * (int64_t) st->time_base.den, | |
1885 | 2345 | den * (int64_t) st->time_base.num, | |
1886 | AV_ROUND_DOWN); | ||
1887 | } | ||
1888 | } | ||
1889 | 2805 | duration = pkt->pts + pkt->duration; | |
1890 | 2805 | found_duration = 1; | |
1891 |
1/2✓ Branch 0 taken 2805 times.
✗ Branch 1 not taken.
|
2805 | if (st->start_time != AV_NOPTS_VALUE) |
1892 | 2805 | duration -= st->start_time; | |
1893 | else | ||
1894 | ✗ | duration -= sti->first_dts; | |
1895 |
2/2✓ Branch 0 taken 2796 times.
✓ Branch 1 taken 9 times.
|
2805 | if (duration > 0) { |
1896 |
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 || |
1897 |
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)) |
1898 | 2542 | st->duration = duration; | |
1899 | 2796 | sti->info->last_duration = duration; | |
1900 | } | ||
1901 | } | ||
1902 | 6554 | av_packet_unref(pkt); | |
1903 | } | ||
1904 | |||
1905 | /* check if all audio/video streams have valid duration */ | ||
1906 |
2/2✓ Branch 0 taken 69 times.
✓ Branch 1 taken 7 times.
|
76 | if (!is_end) { |
1907 | 69 | is_end = 1; | |
1908 |
2/2✓ Branch 0 taken 143 times.
✓ Branch 1 taken 69 times.
|
212 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
1909 | 143 | const AVStream *const st = ic->streams[i]; | |
1910 |
2/2✓ Branch 0 taken 125 times.
✓ Branch 1 taken 18 times.
|
143 | switch (st->codecpar->codec_type) { |
1911 | 125 | case AVMEDIA_TYPE_VIDEO: | |
1912 | case AVMEDIA_TYPE_AUDIO: | ||
1913 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 101 times.
|
125 | if (st->duration == AV_NOPTS_VALUE) |
1914 | 24 | is_end = 0; | |
1915 | } | ||
1916 | } | ||
1917 | } | ||
1918 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 2 times.
|
9 | } while (!is_end && |
1919 |
3/4✓ Branch 0 taken 9 times.
✓ Branch 1 taken 67 times.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
|
83 | offset && |
1920 | ++retry <= duration_max_retry); | ||
1921 | |||
1922 | 69 | av_opt_set_int(ic, "skip_changes", 0, AV_OPT_SEARCH_CHILDREN); | |
1923 | |||
1924 | /* warn about audio/video streams which duration could not be estimated */ | ||
1925 |
2/2✓ Branch 0 taken 143 times.
✓ Branch 1 taken 69 times.
|
212 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
1926 | 143 | const AVStream *const st = ic->streams[i]; | |
1927 | 143 | const FFStream *const sti = cffstream(st); | |
1928 | |||
1929 |
2/2✓ Branch 0 taken 32 times.
✓ Branch 1 taken 111 times.
|
143 | if (st->duration == AV_NOPTS_VALUE) { |
1930 |
2/2✓ Branch 0 taken 17 times.
✓ Branch 1 taken 15 times.
|
32 | switch (st->codecpar->codec_type) { |
1931 | 17 | case AVMEDIA_TYPE_VIDEO: | |
1932 | case AVMEDIA_TYPE_AUDIO: | ||
1933 |
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) { |
1934 | 7 | av_log(ic, AV_LOG_WARNING, "stream %d : no PTS found at end of file, duration not set\n", i); | |
1935 | } else | ||
1936 | 10 | av_log(ic, AV_LOG_WARNING, "stream %d : no TS found at start of file, duration not set\n", i); | |
1937 | } | ||
1938 | } | ||
1939 | } | ||
1940 | 69 | skip_duration_calc: | |
1941 | 69 | fill_all_stream_timings(ic); | |
1942 | |||
1943 | 69 | avio_seek(ic->pb, old_offset, SEEK_SET); | |
1944 |
2/2✓ Branch 0 taken 143 times.
✓ Branch 1 taken 69 times.
|
212 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
1945 | 143 | AVStream *const st = ic->streams[i]; | |
1946 | 143 | FFStream *const sti = ffstream(st); | |
1947 | |||
1948 | 143 | sti->cur_dts = sti->first_dts; | |
1949 | 143 | sti->last_IP_pts = AV_NOPTS_VALUE; | |
1950 | 143 | sti->last_dts_for_order_check = AV_NOPTS_VALUE; | |
1951 |
2/2✓ Branch 0 taken 2431 times.
✓ Branch 1 taken 143 times.
|
2574 | for (int j = 0; j < MAX_REORDER_DELAY + 1; j++) |
1952 | 2431 | sti->pts_buffer[j] = AV_NOPTS_VALUE; | |
1953 | } | ||
1954 | 69 | } | |
1955 | |||
1956 | /* 1:1 map to AVDurationEstimationMethod */ | ||
1957 | static const char *const duration_name[] = { | ||
1958 | [AVFMT_DURATION_FROM_PTS] = "pts", | ||
1959 | [AVFMT_DURATION_FROM_STREAM] = "stream", | ||
1960 | [AVFMT_DURATION_FROM_BITRATE] = "bit rate", | ||
1961 | }; | ||
1962 | |||
1963 | 7570 | static const char *duration_estimate_name(enum AVDurationEstimationMethod method) | |
1964 | { | ||
1965 | 7570 | return duration_name[method]; | |
1966 | } | ||
1967 | |||
1968 | 7570 | static void estimate_timings(AVFormatContext *ic, int64_t old_offset) | |
1969 | { | ||
1970 | int64_t file_size; | ||
1971 | |||
1972 | /* get the file size, if possible */ | ||
1973 |
2/2✓ Branch 0 taken 3084 times.
✓ Branch 1 taken 4486 times.
|
7570 | if (ic->iformat->flags & AVFMT_NOFILE) { |
1974 | 3084 | file_size = 0; | |
1975 | } else { | ||
1976 | 4486 | file_size = avio_size(ic->pb); | |
1977 | 4486 | file_size = FFMAX(0, file_size); | |
1978 | } | ||
1979 | |||
1980 |
2/2✓ Branch 0 taken 7545 times.
✓ Branch 1 taken 25 times.
|
7570 | if ((!strcmp(ic->iformat->name, "mpeg") || |
1981 |
3/4✓ Branch 0 taken 44 times.
✓ Branch 1 taken 7501 times.
✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
|
7570 | !strcmp(ic->iformat->name, "mpegts")) && |
1982 |
1/2✓ Branch 0 taken 69 times.
✗ Branch 1 not taken.
|
69 | file_size && (ic->pb->seekable & AVIO_SEEKABLE_NORMAL)) { |
1983 | /* get accurate estimate from the PTSes */ | ||
1984 | 69 | estimate_timings_from_pts(ic, old_offset); | |
1985 | 69 | ic->duration_estimation_method = AVFMT_DURATION_FROM_PTS; | |
1986 |
2/2✓ Branch 1 taken 5517 times.
✓ Branch 2 taken 1984 times.
|
7501 | } else if (has_duration(ic)) { |
1987 | /* at least one component has timings - we use them for all | ||
1988 | * the components */ | ||
1989 | 5517 | fill_all_stream_timings(ic); | |
1990 | /* nut demuxer estimate the duration from PTS */ | ||
1991 |
2/2✓ Branch 0 taken 30 times.
✓ Branch 1 taken 5487 times.
|
5517 | if (!strcmp(ic->iformat->name, "nut")) |
1992 | 30 | ic->duration_estimation_method = AVFMT_DURATION_FROM_PTS; | |
1993 | else | ||
1994 | 5487 | ic->duration_estimation_method = AVFMT_DURATION_FROM_STREAM; | |
1995 | } else { | ||
1996 | /* less precise: use bitrate info */ | ||
1997 | 1984 | estimate_timings_from_bit_rate(ic); | |
1998 | 1984 | ic->duration_estimation_method = AVFMT_DURATION_FROM_BITRATE; | |
1999 | } | ||
2000 | 7570 | update_stream_timings(ic); | |
2001 | |||
2002 |
2/2✓ Branch 0 taken 8379 times.
✓ Branch 1 taken 7570 times.
|
15949 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
2003 | 8379 | AVStream *const st = ic->streams[i]; | |
2004 |
1/2✓ Branch 0 taken 8379 times.
✗ Branch 1 not taken.
|
8379 | if (st->time_base.den) |
2005 | 8379 | av_log(ic, AV_LOG_TRACE, "stream %u: start_time: %s duration: %s\n", i, | |
2006 | 8379 | av_ts2timestr(st->start_time, &st->time_base), | |
2007 | 8379 | av_ts2timestr(st->duration, &st->time_base)); | |
2008 | } | ||
2009 | 7570 | av_log(ic, AV_LOG_TRACE, | |
2010 | "format: start_time: %s duration: %s (estimate from %s) bitrate=%"PRId64" kb/s\n", | ||
2011 | 7570 | av_ts2timestr(ic->start_time, &AV_TIME_BASE_Q), | |
2012 | 7570 | av_ts2timestr(ic->duration, &AV_TIME_BASE_Q), | |
2013 | duration_estimate_name(ic->duration_estimation_method), | ||
2014 | 7570 | (int64_t)ic->bit_rate / 1000); | |
2015 | 7570 | } | |
2016 | |||
2017 | 106265 | static int determinable_frame_size(const AVCodecContext *avctx) | |
2018 | { | ||
2019 |
2/2✓ Branch 0 taken 2187 times.
✓ Branch 1 taken 104078 times.
|
106265 | switch(avctx->codec_id) { |
2020 | 2187 | case AV_CODEC_ID_MP1: | |
2021 | case AV_CODEC_ID_MP2: | ||
2022 | case AV_CODEC_ID_MP3: | ||
2023 | case AV_CODEC_ID_CODEC2: | ||
2024 | 2187 | return 1; | |
2025 | } | ||
2026 | |||
2027 | 104078 | return 0; | |
2028 | } | ||
2029 | |||
2030 | 423831 | static int has_codec_parameters(const AVStream *st, const char **errmsg_ptr) | |
2031 | { | ||
2032 | 423831 | const FFStream *const sti = cffstream(st); | |
2033 | 423831 | const AVCodecContext *const avctx = sti->avctx; | |
2034 | |||
2035 | #define FAIL(errmsg) do { \ | ||
2036 | if (errmsg_ptr) \ | ||
2037 | *errmsg_ptr = errmsg; \ | ||
2038 | return 0; \ | ||
2039 | } while (0) | ||
2040 | |||
2041 |
2/2✓ Branch 0 taken 644 times.
✓ Branch 1 taken 423187 times.
|
423831 | if ( avctx->codec_id == AV_CODEC_ID_NONE |
2042 |
2/2✓ Branch 0 taken 419 times.
✓ Branch 1 taken 225 times.
|
644 | && avctx->codec_type != AVMEDIA_TYPE_DATA) |
2043 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 414 times.
|
419 | FAIL("unknown codec"); |
2044 |
4/5✓ Branch 0 taken 121624 times.
✓ Branch 1 taken 300246 times.
✓ Branch 2 taken 629 times.
✓ Branch 3 taken 913 times.
✗ Branch 4 not taken.
|
423412 | switch (avctx->codec_type) { |
2045 | 121624 | case AVMEDIA_TYPE_AUDIO: | |
2046 |
4/4✓ Branch 0 taken 106265 times.
✓ Branch 1 taken 15359 times.
✓ Branch 3 taken 2187 times.
✓ Branch 4 taken 104078 times.
|
121624 | if (!avctx->frame_size && determinable_frame_size(avctx)) |
2047 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 2175 times.
|
2187 | FAIL("unspecified frame size"); |
2048 |
1/2✓ Branch 0 taken 119437 times.
✗ Branch 1 not taken.
|
119437 | if (sti->info->found_decoder >= 0 && |
2049 |
2/2✓ Branch 0 taken 2432 times.
✓ Branch 1 taken 117005 times.
|
119437 | avctx->sample_fmt == AV_SAMPLE_FMT_NONE) |
2050 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2432 times.
|
2432 | FAIL("unspecified sample format"); |
2051 |
2/2✓ Branch 0 taken 137 times.
✓ Branch 1 taken 116868 times.
|
117005 | if (!avctx->sample_rate) |
2052 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 131 times.
|
137 | FAIL("unspecified sample rate"); |
2053 |
2/2✓ Branch 0 taken 17 times.
✓ Branch 1 taken 116851 times.
|
116868 | if (!avctx->ch_layout.nb_channels) |
2054 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
|
17 | FAIL("unspecified number of channels"); |
2055 |
4/6✓ Branch 0 taken 116851 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80775 times.
✓ Branch 3 taken 36076 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 80775 times.
|
116851 | if (sti->info->found_decoder >= 0 && !sti->nb_decoded_frames && avctx->codec_id == AV_CODEC_ID_DTS) |
2056 | ✗ | FAIL("no decodable DTS frames"); | |
2057 | 116851 | break; | |
2058 | 300246 | case AVMEDIA_TYPE_VIDEO: | |
2059 |
2/2✓ Branch 0 taken 12798 times.
✓ Branch 1 taken 287448 times.
|
300246 | if (!avctx->width) |
2060 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 12788 times.
|
12798 | FAIL("unspecified size"); |
2061 |
4/4✓ Branch 0 taken 287393 times.
✓ Branch 1 taken 55 times.
✓ Branch 2 taken 4236 times.
✓ Branch 3 taken 283157 times.
|
287448 | if (sti->info->found_decoder >= 0 && avctx->pix_fmt == AV_PIX_FMT_NONE) |
2062 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 4233 times.
|
4236 | FAIL("unspecified pixel format"); |
2063 |
4/4✓ Branch 0 taken 283112 times.
✓ Branch 1 taken 100 times.
✓ Branch 2 taken 86 times.
✓ Branch 3 taken 283026 times.
|
283212 | if (st->codecpar->codec_id == AV_CODEC_ID_RV30 || st->codecpar->codec_id == AV_CODEC_ID_RV40) |
2064 |
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) |
2065 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 67 times.
|
67 | FAIL("no frame in rv30/40 and no sar"); |
2066 | 283145 | break; | |
2067 | 629 | case AVMEDIA_TYPE_SUBTITLE: | |
2068 |
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) |
2069 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
|
21 | FAIL("unspecified size"); |
2070 | 608 | break; | |
2071 | 913 | case AVMEDIA_TYPE_DATA: | |
2072 |
2/2✓ Branch 0 taken 225 times.
✓ Branch 1 taken 688 times.
|
913 | if (avctx->codec_id == AV_CODEC_ID_NONE) return 1; |
2073 | } | ||
2074 | |||
2075 | 401292 | return 1; | |
2076 | } | ||
2077 | |||
2078 | /* returns 1 or 0 if or if not decoded data was returned, or a negative error */ | ||
2079 | 198096 | static int try_decode_frame(AVFormatContext *s, AVStream *st, | |
2080 | const AVPacket *pkt, AVDictionary **options) | ||
2081 | { | ||
2082 | 198096 | FFStream *const sti = ffstream(st); | |
2083 | 198096 | AVCodecContext *const avctx = sti->avctx; | |
2084 | const AVCodec *codec; | ||
2085 | 198096 | int got_picture = 1, ret = 0; | |
2086 | 198096 | AVFrame *frame = av_frame_alloc(); | |
2087 | AVSubtitle subtitle; | ||
2088 | 198096 | int do_skip_frame = 0; | |
2089 | enum AVDiscard skip_frame; | ||
2090 | 198096 | int pkt_to_send = pkt->size > 0; | |
2091 | |||
2092 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 198096 times.
|
198096 | if (!frame) |
2093 | ✗ | return AVERROR(ENOMEM); | |
2094 | |||
2095 |
2/2✓ Branch 1 taken 3398 times.
✓ Branch 2 taken 194698 times.
|
198096 | if (!avcodec_is_open(avctx) && |
2096 |
1/2✓ Branch 0 taken 3398 times.
✗ Branch 1 not taken.
|
3398 | sti->info->found_decoder <= 0 && |
2097 |
4/4✓ Branch 0 taken 2024 times.
✓ Branch 1 taken 1374 times.
✓ Branch 2 taken 63 times.
✓ Branch 3 taken 1961 times.
|
3398 | (st->codecpar->codec_id != -sti->info->found_decoder || !st->codecpar->codec_id)) { |
2098 | 1437 | AVDictionary *thread_opt = NULL; | |
2099 | |||
2100 | 1437 | codec = find_probe_decoder(s, st, st->codecpar->codec_id); | |
2101 | |||
2102 |
2/2✓ Branch 0 taken 76 times.
✓ Branch 1 taken 1361 times.
|
1437 | if (!codec) { |
2103 | 76 | sti->info->found_decoder = -st->codecpar->codec_id; | |
2104 | 76 | ret = -1; | |
2105 | 88 | goto fail; | |
2106 | } | ||
2107 | |||
2108 | /* Force thread count to 1 since the H.264 decoder will not extract | ||
2109 | * SPS and PPS to extradata during multi-threaded decoding. */ | ||
2110 |
2/2✓ Branch 0 taken 163 times.
✓ Branch 1 taken 1198 times.
|
1361 | av_dict_set(options ? options : &thread_opt, "threads", "1", 0); |
2111 | /* Force lowres to 0. The decoder might reduce the video size by the | ||
2112 | * lowres factor, and we don't want that propagated to the stream's | ||
2113 | * codecpar */ | ||
2114 |
2/2✓ Branch 0 taken 163 times.
✓ Branch 1 taken 1198 times.
|
1361 | av_dict_set(options ? options : &thread_opt, "lowres", "0", 0); |
2115 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1361 times.
|
1361 | if (s->codec_whitelist) |
2116 | ✗ | av_dict_set(options ? options : &thread_opt, "codec_whitelist", s->codec_whitelist, 0); | |
2117 |
2/2✓ Branch 0 taken 163 times.
✓ Branch 1 taken 1198 times.
|
1361 | ret = avcodec_open2(avctx, codec, options ? options : &thread_opt); |
2118 |
2/2✓ Branch 0 taken 163 times.
✓ Branch 1 taken 1198 times.
|
1361 | if (!options) |
2119 | 163 | av_dict_free(&thread_opt); | |
2120 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 1349 times.
|
1361 | if (ret < 0) { |
2121 | 12 | sti->info->found_decoder = -avctx->codec_id; | |
2122 | 12 | goto fail; | |
2123 | } | ||
2124 | 1349 | sti->info->found_decoder = 1; | |
2125 |
2/2✓ Branch 0 taken 6740 times.
✓ Branch 1 taken 189919 times.
|
196659 | } else if (!sti->info->found_decoder) |
2126 | 6740 | sti->info->found_decoder = 1; | |
2127 | |||
2128 |
2/2✓ Branch 0 taken 1961 times.
✓ Branch 1 taken 196047 times.
|
198008 | if (sti->info->found_decoder < 0) { |
2129 | 1961 | ret = -1; | |
2130 | 1961 | goto fail; | |
2131 | } | ||
2132 | |||
2133 |
2/2✓ Branch 1 taken 108330 times.
✓ Branch 2 taken 87717 times.
|
196047 | if (avpriv_codec_get_cap_skip_frame_fill_param(avctx->codec)) { |
2134 | 108330 | do_skip_frame = 1; | |
2135 | 108330 | skip_frame = avctx->skip_frame; | |
2136 | 108330 | avctx->skip_frame = AVDISCARD_ALL; | |
2137 | } | ||
2138 | |||
2139 |
5/6✓ Branch 0 taken 7989 times.
✓ Branch 1 taken 4575 times.
✓ Branch 2 taken 26 times.
✓ Branch 3 taken 4549 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 196055 times.
|
400117 | while ((pkt_to_send || (!pkt->data && got_picture)) && |
2140 |
4/4✓ Branch 0 taken 12564 times.
✓ Branch 1 taken 191506 times.
✓ Branch 2 taken 5565 times.
✓ Branch 3 taken 190490 times.
|
400125 | ret >= 0 && |
2141 |
2/2✓ Branch 2 taken 2241 times.
✓ Branch 3 taken 188249 times.
|
386545 | (!has_codec_parameters(st, NULL) || !has_decode_delay_been_guessed(st) || |
2142 |
2/2✓ Branch 0 taken 185438 times.
✓ Branch 1 taken 2811 times.
|
188249 | (!sti->codec_info_nb_frames && |
2143 |
2/2✓ Branch 0 taken 457 times.
✓ Branch 1 taken 2354 times.
|
2811 | (avctx->codec->capabilities & AV_CODEC_CAP_CHANNEL_CONF)))) { |
2144 | 8263 | got_picture = 0; | |
2145 |
2/2✓ Branch 0 taken 730 times.
✓ Branch 1 taken 7533 times.
|
8263 | if (avctx->codec_type == AVMEDIA_TYPE_VIDEO || |
2146 |
2/2✓ Branch 0 taken 723 times.
✓ Branch 1 taken 7 times.
|
730 | avctx->codec_type == AVMEDIA_TYPE_AUDIO) { |
2147 | 8256 | ret = avcodec_send_packet(avctx, pkt); | |
2148 |
5/6✓ Branch 0 taken 249 times.
✓ Branch 1 taken 8007 times.
✓ Branch 2 taken 249 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 240 times.
✓ Branch 5 taken 9 times.
|
8256 | if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) |
2149 | 240 | break; | |
2150 |
2/2✓ Branch 0 taken 8007 times.
✓ Branch 1 taken 9 times.
|
8016 | if (ret >= 0) |
2151 | 8007 | pkt_to_send = 0; | |
2152 | 8016 | ret = avcodec_receive_frame(avctx, frame); | |
2153 |
2/2✓ Branch 0 taken 3156 times.
✓ Branch 1 taken 4860 times.
|
8016 | if (ret >= 0) |
2154 | 3156 | got_picture = 1; | |
2155 |
4/4✓ Branch 0 taken 3182 times.
✓ Branch 1 taken 4834 times.
✓ Branch 2 taken 26 times.
✓ Branch 3 taken 3156 times.
|
8016 | if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) |
2156 | 4860 | ret = 0; | |
2157 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
7 | } else if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE) { |
2158 | 7 | ret = avcodec_decode_subtitle2(avctx, &subtitle, | |
2159 | &got_picture, pkt); | ||
2160 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 5 times.
|
7 | if (got_picture) |
2161 | 2 | avsubtitle_free(&subtitle); | |
2162 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
7 | if (ret >= 0) |
2163 | 7 | pkt_to_send = 0; | |
2164 | } | ||
2165 |
1/2✓ Branch 0 taken 8023 times.
✗ Branch 1 not taken.
|
8023 | if (ret >= 0) { |
2166 |
2/2✓ Branch 0 taken 3158 times.
✓ Branch 1 taken 4865 times.
|
8023 | if (got_picture) |
2167 | 3158 | sti->nb_decoded_frames++; | |
2168 | 8023 | ret = got_picture; | |
2169 | } | ||
2170 | } | ||
2171 | |||
2172 | 195807 | fail: | |
2173 |
2/2✓ Branch 0 taken 108330 times.
✓ Branch 1 taken 89766 times.
|
198096 | if (do_skip_frame) { |
2174 | 108330 | avctx->skip_frame = skip_frame; | |
2175 | } | ||
2176 | |||
2177 | 198096 | av_frame_free(&frame); | |
2178 | 198096 | return ret; | |
2179 | } | ||
2180 | |||
2181 | 57 | static int chapter_start_cmp(const void *p1, const void *p2) | |
2182 | { | ||
2183 | 57 | const AVChapter *const ch1 = *(AVChapter**)p1; | |
2184 | 57 | const AVChapter *const ch2 = *(AVChapter**)p2; | |
2185 | 57 | int delta = av_compare_ts(ch1->start, ch1->time_base, ch2->start, ch2->time_base); | |
2186 |
1/2✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
|
57 | if (delta) |
2187 | 57 | return delta; | |
2188 | ✗ | return FFDIFFSIGN(ch1->id, ch2->id); | |
2189 | } | ||
2190 | |||
2191 | 7570 | static int compute_chapters_end(AVFormatContext *s) | |
2192 | { | ||
2193 | 7570 | int64_t max_time = 0; | |
2194 | AVChapter **timetable; | ||
2195 | |||
2196 |
2/2✓ Branch 0 taken 7544 times.
✓ Branch 1 taken 26 times.
|
7570 | if (!s->nb_chapters) |
2197 | 7544 | return 0; | |
2198 | |||
2199 |
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) |
2200 | 26 | max_time = s->duration + | |
2201 |
2/2✓ Branch 0 taken 23 times.
✓ Branch 1 taken 3 times.
|
26 | ((s->start_time == AV_NOPTS_VALUE) ? 0 : s->start_time); |
2202 | |||
2203 | 26 | timetable = av_memdup(s->chapters, s->nb_chapters * sizeof(*timetable)); | |
2204 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
|
26 | if (!timetable) |
2205 | ✗ | return AVERROR(ENOMEM); | |
2206 | 26 | qsort(timetable, s->nb_chapters, sizeof(*timetable), chapter_start_cmp); | |
2207 | |||
2208 |
2/2✓ Branch 0 taken 71 times.
✓ Branch 1 taken 26 times.
|
97 | for (unsigned i = 0; i < s->nb_chapters; i++) |
2209 |
2/2✓ Branch 0 taken 40 times.
✓ Branch 1 taken 31 times.
|
71 | if (timetable[i]->end == AV_NOPTS_VALUE) { |
2210 | 40 | AVChapter *const ch = timetable[i]; | |
2211 | 40 | int64_t end = max_time ? av_rescale_q(max_time, AV_TIME_BASE_Q, | |
2212 | ch->time_base) | ||
2213 |
1/2✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
|
40 | : INT64_MAX; |
2214 | |||
2215 |
2/2✓ Branch 0 taken 21 times.
✓ Branch 1 taken 19 times.
|
40 | if (i + 1 < s->nb_chapters) { |
2216 | 21 | const AVChapter *const ch1 = timetable[i + 1]; | |
2217 | 21 | int64_t next_start = av_rescale_q(ch1->start, ch1->time_base, | |
2218 | ch->time_base); | ||
2219 |
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) |
2220 | 21 | end = next_start; | |
2221 | } | ||
2222 |
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; |
2223 | } | ||
2224 | 26 | av_free(timetable); | |
2225 | 26 | return 0; | |
2226 | } | ||
2227 | |||
2228 | 18817411 | static int get_std_framerate(int i) | |
2229 | { | ||
2230 |
2/2✓ Branch 0 taken 17096285 times.
✓ Branch 1 taken 1721126 times.
|
18817411 | if (i < 30*12) |
2231 | 17096285 | return (i + 1) * 1001; | |
2232 | 1721126 | i -= 30*12; | |
2233 | |||
2234 |
2/2✓ Branch 0 taken 1309013 times.
✓ Branch 1 taken 412113 times.
|
1721126 | if (i < 30) |
2235 | 1309013 | return (i + 31) * 1001 * 12; | |
2236 | 412113 | i -= 30; | |
2237 | |||
2238 |
2/2✓ Branch 0 taken 131316 times.
✓ Branch 1 taken 280797 times.
|
412113 | if (i < 3) |
2239 | 131316 | return ((const int[]) { 80, 120, 240})[i] * 1001 * 12; | |
2240 | |||
2241 | 280797 | i -= 3; | |
2242 | |||
2243 | 280797 | return ((const int[]) { 24, 30, 60, 12, 15, 48 })[i] * 1000 * 12; | |
2244 | } | ||
2245 | |||
2246 | /* Is the time base unreliable? | ||
2247 | * This is a heuristic to balance between quick acceptance of the values in | ||
2248 | * the headers vs. some extra checks. | ||
2249 | * Old DivX and Xvid often have nonsense timebases like 1fps or 2fps. | ||
2250 | * MPEG-2 commonly misuses field repeat flags to store different framerates. | ||
2251 | * And there are "variable" fps files this needs to detect as well. */ | ||
2252 | 207417 | static int tb_unreliable(AVFormatContext *ic, AVStream *st) | |
2253 | { | ||
2254 | 207417 | FFStream *const sti = ffstream(st); | |
2255 | 207417 | const AVCodecDescriptor *desc = sti->codec_desc; | |
2256 | 207417 | AVCodecContext *c = sti->avctx; | |
2257 |
4/4✓ Branch 0 taken 206965 times.
✓ Branch 1 taken 452 times.
✓ Branch 2 taken 21029 times.
✓ Branch 3 taken 185936 times.
|
207417 | AVRational mul = (AVRational){ desc && (desc->props & AV_CODEC_PROP_FIELDS) ? 2 : 1, 1 }; |
2258 | 207417 | AVRational time_base = c->framerate.num ? av_inv_q(av_mul_q(c->framerate, mul)) | |
2259 | /* NOHEADER check added to not break existing behavior */ | ||
2260 |
2/2✓ Branch 0 taken 17678 times.
✓ Branch 1 taken 189739 times.
|
207417 | : (((ic->ctx_flags & AVFMTCTX_NOHEADER) || |
2261 |
2/2✓ Branch 0 taken 44400 times.
✓ Branch 1 taken 30395 times.
|
74795 | st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) ? (AVRational){0, 1} |
2262 |
2/2✓ Branch 0 taken 74795 times.
✓ Branch 1 taken 114944 times.
|
189739 | : st->time_base); |
2263 | |||
2264 |
2/2✓ Branch 0 taken 23976 times.
✓ Branch 1 taken 183441 times.
|
207417 | if (time_base.den >= 101LL * time_base.num || |
2265 |
2/2✓ Branch 0 taken 23568 times.
✓ Branch 1 taken 408 times.
|
23976 | time_base.den < 5LL * time_base.num || |
2266 | // c->codec_tag == AV_RL32("DIVX") || | ||
2267 | // c->codec_tag == AV_RL32("XVID") || | ||
2268 |
2/2✓ Branch 0 taken 23469 times.
✓ Branch 1 taken 99 times.
|
23568 | c->codec_tag == AV_RL32("mp4v") || |
2269 |
2/2✓ Branch 0 taken 14640 times.
✓ Branch 1 taken 8829 times.
|
23469 | c->codec_id == AV_CODEC_ID_MPEG2VIDEO || |
2270 |
2/2✓ Branch 0 taken 14110 times.
✓ Branch 1 taken 530 times.
|
14640 | c->codec_id == AV_CODEC_ID_GIF || |
2271 |
2/2✓ Branch 0 taken 13405 times.
✓ Branch 1 taken 705 times.
|
14110 | c->codec_id == AV_CODEC_ID_HEVC || |
2272 |
2/2✓ Branch 0 taken 3483 times.
✓ Branch 1 taken 9922 times.
|
13405 | c->codec_id == AV_CODEC_ID_H264) |
2273 | 197495 | return 1; | |
2274 | 9922 | return 0; | |
2275 | } | ||
2276 | |||
2277 | 142195 | int ff_rfps_add_frame(AVFormatContext *ic, AVStream *st, int64_t ts) | |
2278 | { | ||
2279 | 142195 | FFStream *const sti = ffstream(st); | |
2280 | 142195 | FFStreamInfo *info = sti->info; | |
2281 | 142195 | int64_t last = info->last_dts; | |
2282 | |||
2283 |
6/6✓ Branch 0 taken 126099 times.
✓ Branch 1 taken 16096 times.
✓ Branch 2 taken 120096 times.
✓ Branch 3 taken 6003 times.
✓ Branch 4 taken 120068 times.
✓ Branch 5 taken 28 times.
|
142195 | if ( ts != AV_NOPTS_VALUE && last != AV_NOPTS_VALUE && ts > last |
2284 |
1/2✓ Branch 0 taken 120068 times.
✗ Branch 1 not taken.
|
120068 | && ts - (uint64_t)last < INT64_MAX) { |
2285 |
2/2✓ Branch 1 taken 6523 times.
✓ Branch 2 taken 113545 times.
|
120068 | double dts = (is_relative(ts) ? ts - RELATIVE_TS_BASE : ts) * av_q2d(st->time_base); |
2286 | 120068 | int64_t duration = ts - last; | |
2287 | |||
2288 |
2/2✓ Branch 0 taken 3912 times.
✓ Branch 1 taken 116156 times.
|
120068 | if (!info->duration_error) |
2289 | 3912 | info->duration_error = av_mallocz(sizeof(info->duration_error[0])*2); | |
2290 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 120068 times.
|
120068 | if (!info->duration_error) |
2291 | ✗ | return AVERROR(ENOMEM); | |
2292 | |||
2293 | // if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) | ||
2294 | // av_log(NULL, AV_LOG_ERROR, "%f\n", dts); | ||
2295 |
2/2✓ Branch 0 taken 47907132 times.
✓ Branch 1 taken 120068 times.
|
48027200 | for (int i = 0; i < MAX_STD_TIMEBASES; i++) { |
2296 |
2/2✓ Branch 0 taken 18450735 times.
✓ Branch 1 taken 29456397 times.
|
47907132 | if (info->duration_error[0][1][i] < 1e10) { |
2297 | 18450735 | int framerate = get_std_framerate(i); | |
2298 | 18450735 | double sdts = dts*framerate/(1001*12); | |
2299 |
2/2✓ Branch 0 taken 36901470 times.
✓ Branch 1 taken 18450735 times.
|
55352205 | for (int j = 0; j < 2; j++) { |
2300 | 36901470 | int64_t ticks = llrint(sdts+j*0.5); | |
2301 | 36901470 | double error = sdts - ticks + j*0.5; | |
2302 | 36901470 | info->duration_error[j][0][i] += error; | |
2303 | 36901470 | info->duration_error[j][1][i] += error*error; | |
2304 | } | ||
2305 | } | ||
2306 | } | ||
2307 |
1/2✓ Branch 0 taken 120068 times.
✗ Branch 1 not taken.
|
120068 | if (info->rfps_duration_sum <= INT64_MAX - duration) { |
2308 | 120068 | info->duration_count++; | |
2309 | 120068 | info->rfps_duration_sum += duration; | |
2310 | } | ||
2311 | |||
2312 |
2/2✓ Branch 0 taken 10927 times.
✓ Branch 1 taken 109141 times.
|
120068 | if (info->duration_count % 10 == 0) { |
2313 | 10927 | int n = info->duration_count; | |
2314 |
2/2✓ Branch 0 taken 4359873 times.
✓ Branch 1 taken 10927 times.
|
4370800 | for (int i = 0; i < MAX_STD_TIMEBASES; i++) { |
2315 |
2/2✓ Branch 0 taken 1767720 times.
✓ Branch 1 taken 2592153 times.
|
4359873 | if (info->duration_error[0][1][i] < 1e10) { |
2316 | 1767720 | double a0 = info->duration_error[0][0][i] / n; | |
2317 | 1767720 | double error0 = info->duration_error[0][1][i] / n - a0*a0; | |
2318 | 1767720 | double a1 = info->duration_error[1][0][i] / n; | |
2319 | 1767720 | double error1 = info->duration_error[1][1][i] / n - a1*a1; | |
2320 |
4/4✓ Branch 0 taken 1447642 times.
✓ Branch 1 taken 320078 times.
✓ Branch 2 taken 1351109 times.
✓ Branch 3 taken 96533 times.
|
1767720 | if (error0 > 0.04 && error1 > 0.04) { |
2321 | 1351109 | info->duration_error[0][1][i] = 2e10; | |
2322 | 1351109 | info->duration_error[1][1][i] = 2e10; | |
2323 | } | ||
2324 | } | ||
2325 | } | ||
2326 | } | ||
2327 | |||
2328 | // ignore the first 4 values, they might have some random jitter | ||
2329 |
3/4✓ Branch 0 taken 108418 times.
✓ Branch 1 taken 11650 times.
✓ Branch 4 taken 108418 times.
✗ Branch 5 not taken.
|
120068 | if (info->duration_count > 3 && is_relative(ts) == is_relative(last)) |
2330 | 108418 | info->duration_gcd = av_gcd(info->duration_gcd, duration); | |
2331 | } | ||
2332 |
2/2✓ Branch 0 taken 126099 times.
✓ Branch 1 taken 16096 times.
|
142195 | if (ts != AV_NOPTS_VALUE) |
2333 | 126099 | info->last_dts = ts; | |
2334 | |||
2335 | 142195 | return 0; | |
2336 | } | ||
2337 | |||
2338 | 8063 | void ff_rfps_calculate(AVFormatContext *ic) | |
2339 | { | ||
2340 |
2/2✓ Branch 0 taken 9050 times.
✓ Branch 1 taken 8063 times.
|
17113 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
2341 | 9050 | AVStream *const st = ic->streams[i]; | |
2342 | 9050 | FFStream *const sti = ffstream(st); | |
2343 | |||
2344 |
2/2✓ Branch 0 taken 2460 times.
✓ Branch 1 taken 6590 times.
|
9050 | if (st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO) |
2345 | 2460 | continue; | |
2346 | // the check for tb_unreliable() is not completely correct, since this is not about handling | ||
2347 | // an unreliable/inexact time base, but a time base that is finer than necessary, as e.g. | ||
2348 | // ipmovie.c produces. | ||
2349 |
8/8✓ Branch 1 taken 5207 times.
✓ Branch 2 taken 1383 times.
✓ Branch 3 taken 3388 times.
✓ Branch 4 taken 1819 times.
✓ Branch 5 taken 295 times.
✓ Branch 6 taken 3093 times.
✓ Branch 7 taken 144 times.
✓ Branch 8 taken 151 times.
|
6590 | 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 && |
2350 |
1/2✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
|
144 | sti->info->duration_gcd < INT64_MAX / st->time_base.num) |
2351 | 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); | |
2352 |
4/4✓ Branch 0 taken 3875 times.
✓ Branch 1 taken 2715 times.
✓ Branch 2 taken 407 times.
✓ Branch 3 taken 3468 times.
|
6590 | if (sti->info->duration_count > 1 && !st->r_frame_rate.num |
2353 |
2/2✓ Branch 1 taken 303 times.
✓ Branch 2 taken 104 times.
|
407 | && tb_unreliable(ic, st)) { |
2354 | 303 | int num = 0; | |
2355 | 303 | double best_error = 0.01; | |
2356 |
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); |
2357 | |||
2358 |
2/2✓ Branch 0 taken 120897 times.
✓ Branch 1 taken 303 times.
|
121200 | for (int j = 0; j < MAX_STD_TIMEBASES; j++) { |
2359 |
2/2✓ Branch 0 taken 89775 times.
✓ Branch 1 taken 31122 times.
|
120897 | if (sti->info->codec_info_duration && |
2360 |
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)) |
2361 | 9919 | continue; | |
2362 |
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) |
2363 | 858 | continue; | |
2364 | |||
2365 |
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)) |
2366 | 51873 | continue; | |
2367 | |||
2368 |
2/2✓ Branch 0 taken 116494 times.
✓ Branch 1 taken 58247 times.
|
174741 | for (int k = 0; k < 2; k++) { |
2369 | 116494 | int n = sti->info->duration_count; | |
2370 | 116494 | double a = sti->info->duration_error[k][0][j] / n; | |
2371 | 116494 | double error = sti->info->duration_error[k][1][j]/n - a*a; | |
2372 | |||
2373 |
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) { |
2374 | 4434 | best_error= error; | |
2375 | 4434 | num = get_std_framerate(j); | |
2376 | } | ||
2377 |
2/2✓ Branch 0 taken 23894 times.
✓ Branch 1 taken 92600 times.
|
116494 | if (error < 0.02) |
2378 | 23894 | av_log(ic, AV_LOG_DEBUG, "rfps: %f %f\n", get_std_framerate(j) / 12.0/1001, error); | |
2379 | } | ||
2380 | } | ||
2381 | // do not increase frame rate by more than 1 % in order to match a standard rate. | ||
2382 |
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))) |
2383 | 295 | av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, num, 12*1001, INT_MAX); | |
2384 | } | ||
2385 |
2/2✓ Branch 0 taken 1094 times.
✓ Branch 1 taken 5496 times.
|
6590 | if ( !st->avg_frame_rate.num |
2386 |
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 |
2387 |
2/2✓ Branch 0 taken 73 times.
✓ Branch 1 taken 207 times.
|
280 | && sti->info->codec_info_duration <= 0 |
2388 |
2/2✓ Branch 0 taken 70 times.
✓ Branch 1 taken 3 times.
|
73 | && sti->info->duration_count > 2 |
2389 |
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 |
2390 | ) { | ||
2391 | 55 | av_log(ic, AV_LOG_DEBUG, "Setting avg frame rate based on r frame rate\n"); | |
2392 | 55 | st->avg_frame_rate = st->r_frame_rate; | |
2393 | } | ||
2394 | |||
2395 | 6590 | av_freep(&sti->info->duration_error); | |
2396 | 6590 | sti->info->last_dts = AV_NOPTS_VALUE; | |
2397 | 6590 | sti->info->duration_count = 0; | |
2398 | 6590 | sti->info->rfps_duration_sum = 0; | |
2399 | } | ||
2400 | 8063 | } | |
2401 | |||
2402 | 9003 | static int extract_extradata_check(AVStream *st) | |
2403 | { | ||
2404 | 9003 | const AVBitStreamFilter *const f = av_bsf_get_by_name("extract_extradata"); | |
2405 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9003 times.
|
9003 | if (!f) |
2406 | ✗ | return 0; | |
2407 | |||
2408 |
1/2✓ Branch 0 taken 9003 times.
✗ Branch 1 not taken.
|
9003 | if (f->codec_ids) { |
2409 | const enum AVCodecID *ids; | ||
2410 |
2/2✓ Branch 0 taken 95388 times.
✓ Branch 1 taken 8111 times.
|
103499 | for (ids = f->codec_ids; *ids != AV_CODEC_ID_NONE; ids++) |
2411 |
2/2✓ Branch 0 taken 892 times.
✓ Branch 1 taken 94496 times.
|
95388 | if (*ids == st->codecpar->codec_id) |
2412 | 892 | return 1; | |
2413 | } | ||
2414 | |||
2415 | 8111 | return 0; | |
2416 | } | ||
2417 | |||
2418 | 7092 | static int extract_extradata_init(AVStream *st) | |
2419 | { | ||
2420 | 7092 | FFStream *const sti = ffstream(st); | |
2421 | const AVBitStreamFilter *f; | ||
2422 | int ret; | ||
2423 | |||
2424 | 7092 | f = av_bsf_get_by_name("extract_extradata"); | |
2425 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7092 times.
|
7092 | if (!f) |
2426 | ✗ | goto finish; | |
2427 | |||
2428 | /* check that the codec id is supported */ | ||
2429 | 7092 | ret = extract_extradata_check(st); | |
2430 |
2/2✓ Branch 0 taken 6310 times.
✓ Branch 1 taken 782 times.
|
7092 | if (!ret) |
2431 | 6310 | goto finish; | |
2432 | |||
2433 | 782 | av_bsf_free(&sti->extract_extradata.bsf); | |
2434 | 782 | ret = av_bsf_alloc(f, &sti->extract_extradata.bsf); | |
2435 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 782 times.
|
782 | if (ret < 0) |
2436 | ✗ | return ret; | |
2437 | |||
2438 | 782 | ret = avcodec_parameters_copy(sti->extract_extradata.bsf->par_in, | |
2439 | 782 | st->codecpar); | |
2440 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 782 times.
|
782 | if (ret < 0) |
2441 | ✗ | goto fail; | |
2442 | |||
2443 | 782 | sti->extract_extradata.bsf->time_base_in = st->time_base; | |
2444 | |||
2445 | 782 | ret = av_bsf_init(sti->extract_extradata.bsf); | |
2446 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 782 times.
|
782 | if (ret < 0) |
2447 | ✗ | goto fail; | |
2448 | |||
2449 | 782 | finish: | |
2450 | 7092 | sti->extract_extradata.inited = 1; | |
2451 | |||
2452 | 7092 | return 0; | |
2453 | ✗ | fail: | |
2454 | ✗ | av_bsf_free(&sti->extract_extradata.bsf); | |
2455 | ✗ | return ret; | |
2456 | } | ||
2457 | |||
2458 | 162844 | static int extract_extradata(FFFormatContext *si, AVStream *st, const AVPacket *pkt) | |
2459 | { | ||
2460 | 162844 | FFStream *const sti = ffstream(st); | |
2461 | 162844 | AVPacket *const pkt_ref = si->parse_pkt; | |
2462 | int ret; | ||
2463 | |||
2464 |
2/2✓ Branch 0 taken 7092 times.
✓ Branch 1 taken 155752 times.
|
162844 | if (!sti->extract_extradata.inited) { |
2465 | 7092 | ret = extract_extradata_init(st); | |
2466 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7092 times.
|
7092 | if (ret < 0) |
2467 | ✗ | return ret; | |
2468 | } | ||
2469 | |||
2470 |
3/4✓ Branch 0 taken 162844 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 161677 times.
✓ Branch 3 taken 1167 times.
|
162844 | if (sti->extract_extradata.inited && !sti->extract_extradata.bsf) |
2471 | 161677 | return 0; | |
2472 | |||
2473 | 1167 | ret = av_packet_ref(pkt_ref, pkt); | |
2474 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1167 times.
|
1167 | if (ret < 0) |
2475 | ✗ | return ret; | |
2476 | |||
2477 | 1167 | ret = av_bsf_send_packet(sti->extract_extradata.bsf, pkt_ref); | |
2478 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1167 times.
|
1167 | if (ret < 0) { |
2479 | ✗ | av_packet_unref(pkt_ref); | |
2480 | ✗ | return ret; | |
2481 | } | ||
2482 | |||
2483 |
4/4✓ Branch 0 taken 2334 times.
✓ Branch 1 taken 384 times.
✓ Branch 2 taken 1551 times.
✓ Branch 3 taken 783 times.
|
2718 | while (ret >= 0 && !sti->avctx->extradata) { |
2484 | 1551 | ret = av_bsf_receive_packet(sti->extract_extradata.bsf, pkt_ref); | |
2485 |
2/2✓ Branch 0 taken 384 times.
✓ Branch 1 taken 1167 times.
|
1551 | if (ret < 0) { |
2486 |
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) |
2487 | ✗ | return ret; | |
2488 | 384 | continue; | |
2489 | } | ||
2490 | |||
2491 |
2/2✓ Branch 0 taken 1029 times.
✓ Branch 1 taken 384 times.
|
1413 | for (int i = 0; i < pkt_ref->side_data_elems; i++) { |
2492 | 1029 | AVPacketSideData *const side_data = &pkt_ref->side_data[i]; | |
2493 |
2/2✓ Branch 0 taken 783 times.
✓ Branch 1 taken 246 times.
|
1029 | if (side_data->type == AV_PKT_DATA_NEW_EXTRADATA) { |
2494 | 783 | sti->avctx->extradata = side_data->data; | |
2495 | 783 | sti->avctx->extradata_size = side_data->size; | |
2496 | 783 | side_data->data = NULL; | |
2497 | 783 | side_data->size = 0; | |
2498 | 783 | break; | |
2499 | } | ||
2500 | } | ||
2501 | 1167 | av_packet_unref(pkt_ref); | |
2502 | } | ||
2503 | |||
2504 | 1167 | return 0; | |
2505 | } | ||
2506 | |||
2507 | 7570 | int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) | |
2508 | { | ||
2509 | 7570 | FFFormatContext *const si = ffformatcontext(ic); | |
2510 | 7570 | int count = 0, ret = 0, err; | |
2511 | int64_t read_size; | ||
2512 | 7570 | AVPacket *pkt1 = si->pkt; | |
2513 | 7570 | int64_t old_offset = avio_tell(ic->pb); | |
2514 | // new streams might appear, no options for those | ||
2515 | 7570 | int orig_nb_streams = ic->nb_streams; | |
2516 | int flush_codecs; | ||
2517 | 7570 | int64_t max_analyze_duration = ic->max_analyze_duration; | |
2518 | int64_t max_stream_analyze_duration; | ||
2519 | int64_t max_subtitle_analyze_duration; | ||
2520 | 7570 | int64_t probesize = ic->probesize; | |
2521 | 7570 | int eof_reached = 0; | |
2522 | |||
2523 | 7570 | flush_codecs = probesize > 0; | |
2524 | |||
2525 | 7570 | av_opt_set_int(ic, "skip_clear", 1, AV_OPT_SEARCH_CHILDREN); | |
2526 | |||
2527 | 7570 | max_stream_analyze_duration = max_analyze_duration; | |
2528 | 7570 | max_subtitle_analyze_duration = max_analyze_duration; | |
2529 |
2/2✓ Branch 0 taken 7569 times.
✓ Branch 1 taken 1 times.
|
7570 | if (!max_analyze_duration) { |
2530 | 7569 | max_stream_analyze_duration = | |
2531 | 7569 | max_analyze_duration = 5*AV_TIME_BASE; | |
2532 | 7569 | max_subtitle_analyze_duration = 30*AV_TIME_BASE; | |
2533 |
2/2✓ Branch 0 taken 38 times.
✓ Branch 1 taken 7531 times.
|
7569 | if (!strcmp(ic->iformat->name, "flv")) |
2534 | 38 | max_stream_analyze_duration = 90*AV_TIME_BASE; | |
2535 |
4/4✓ Branch 0 taken 7544 times.
✓ Branch 1 taken 25 times.
✓ Branch 2 taken 44 times.
✓ Branch 3 taken 7500 times.
|
7569 | if (!strcmp(ic->iformat->name, "mpeg") || !strcmp(ic->iformat->name, "mpegts")) |
2536 | 69 | max_stream_analyze_duration = 7*AV_TIME_BASE; | |
2537 | } | ||
2538 | |||
2539 |
2/2✓ Branch 0 taken 4511 times.
✓ Branch 1 taken 3059 times.
|
7570 | if (ic->pb) { |
2540 | 4511 | FFIOContext *const ctx = ffiocontext(ic->pb); | |
2541 | 4511 | av_log(ic, AV_LOG_DEBUG, "Before avformat_find_stream_info() pos: %"PRId64" bytes read:%"PRId64" seeks:%d nb_streams:%d\n", | |
2542 | avio_tell(ic->pb), ctx->bytes_read, ctx->seek_count, ic->nb_streams); | ||
2543 | } | ||
2544 | |||
2545 |
2/2✓ Branch 0 taken 8194 times.
✓ Branch 1 taken 7570 times.
|
15764 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
2546 | const AVCodec *codec; | ||
2547 | 8194 | AVDictionary *thread_opt = NULL; | |
2548 | 8194 | AVStream *const st = ic->streams[i]; | |
2549 | 8194 | FFStream *const sti = ffstream(st); | |
2550 | 8194 | AVCodecContext *const avctx = sti->avctx; | |
2551 | |||
2552 | /* check if the caller has overridden the codec id */ | ||
2553 | // only for the split stuff | ||
2554 |
4/6✓ Branch 0 taken 8194 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8194 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7690 times.
✓ Branch 5 taken 504 times.
|
8194 | if (!sti->parser && !(ic->flags & AVFMT_FLAG_NOPARSE) && sti->request_probe <= 0) { |
2555 | 7690 | sti->parser = av_parser_init(st->codecpar->codec_id); | |
2556 |
2/2✓ Branch 0 taken 5360 times.
✓ Branch 1 taken 2330 times.
|
7690 | if (sti->parser) { |
2557 |
2/2✓ Branch 0 taken 751 times.
✓ Branch 1 taken 4609 times.
|
5360 | if (sti->need_parsing == AVSTREAM_PARSE_HEADERS) { |
2558 | 751 | sti->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES; | |
2559 |
2/2✓ Branch 0 taken 818 times.
✓ Branch 1 taken 3791 times.
|
4609 | } else if (sti->need_parsing == AVSTREAM_PARSE_FULL_RAW) { |
2560 | 818 | sti->parser->flags |= PARSER_FLAG_USE_CODEC_TS; | |
2561 | } | ||
2562 |
2/2✓ Branch 0 taken 652 times.
✓ Branch 1 taken 1678 times.
|
2330 | } else if (sti->need_parsing) { |
2563 | 652 | av_log(ic, AV_LOG_VERBOSE, "parser not found for codec " | |
2564 | "%s, packets or times may be invalid.\n", | ||
2565 | 652 | avcodec_get_name(st->codecpar->codec_id)); | |
2566 | } | ||
2567 | } | ||
2568 | |||
2569 | 8194 | ret = avcodec_parameters_to_context(avctx, st->codecpar); | |
2570 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8194 times.
|
8194 | if (ret < 0) |
2571 | ✗ | goto find_stream_info_err; | |
2572 |
2/2✓ Branch 0 taken 7690 times.
✓ Branch 1 taken 504 times.
|
8194 | if (sti->request_probe <= 0) |
2573 | 7690 | sti->avctx_inited = 1; | |
2574 | |||
2575 | 8194 | codec = find_probe_decoder(ic, st, st->codecpar->codec_id); | |
2576 | |||
2577 | /* Force thread count to 1 since the H.264 decoder will not extract | ||
2578 | * SPS and PPS to extradata during multi-threaded decoding. */ | ||
2579 |
2/2✓ Branch 0 taken 7910 times.
✓ Branch 1 taken 284 times.
|
8194 | av_dict_set(options ? &options[i] : &thread_opt, "threads", "1", 0); |
2580 | /* Force lowres to 0. The decoder might reduce the video size by the | ||
2581 | * lowres factor, and we don't want that propagated to the stream's | ||
2582 | * codecpar */ | ||
2583 |
2/2✓ Branch 0 taken 7910 times.
✓ Branch 1 taken 284 times.
|
8194 | av_dict_set(options ? &options[i] : &thread_opt, "lowres", "0", 0); |
2584 | |||
2585 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8194 times.
|
8194 | if (ic->codec_whitelist) |
2586 | ✗ | av_dict_set(options ? &options[i] : &thread_opt, "codec_whitelist", ic->codec_whitelist, 0); | |
2587 | |||
2588 | // Try to just open decoders, in case this is enough to get parameters. | ||
2589 | // Also ensure that subtitle_header is properly set. | ||
2590 |
4/4✓ Branch 1 taken 7377 times.
✓ Branch 2 taken 817 times.
✓ Branch 3 taken 503 times.
✓ Branch 4 taken 6874 times.
|
8194 | if (!has_codec_parameters(st, NULL) && sti->request_probe <= 0 || |
2591 |
2/2✓ Branch 0 taken 78 times.
✓ Branch 1 taken 1242 times.
|
1320 | st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) { |
2592 |
3/4✓ Branch 0 taken 6933 times.
✓ Branch 1 taken 19 times.
✓ Branch 2 taken 6933 times.
✗ Branch 3 not taken.
|
6952 | if (codec && !avctx->codec) |
2593 |
4/4✓ Branch 0 taken 6653 times.
✓ Branch 1 taken 280 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 6927 times.
|
6933 | if (avcodec_open2(avctx, codec, options ? &options[i] : &thread_opt) < 0) |
2594 | 6 | av_log(ic, AV_LOG_WARNING, | |
2595 | "Failed to open codec in %s\n", __func__); | ||
2596 | } | ||
2597 |
2/2✓ Branch 0 taken 284 times.
✓ Branch 1 taken 7910 times.
|
8194 | if (!options) |
2598 | 284 | av_dict_free(&thread_opt); | |
2599 | } | ||
2600 | |||
2601 | 7570 | read_size = 0; | |
2602 | 193556 | for (;;) { | |
2603 | const AVPacket *pkt; | ||
2604 | AVStream *st; | ||
2605 | FFStream *sti; | ||
2606 | AVCodecContext *avctx; | ||
2607 | int analyzed_all_streams; | ||
2608 | unsigned i; | ||
2609 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 201126 times.
|
201126 | if (ff_check_interrupt(&ic->interrupt_callback)) { |
2610 | ✗ | ret = AVERROR_EXIT; | |
2611 | ✗ | av_log(ic, AV_LOG_DEBUG, "interrupted\n"); | |
2612 | ✗ | break; | |
2613 | } | ||
2614 | |||
2615 | /* check if one codec still needs to be handled */ | ||
2616 |
2/2✓ Branch 0 taken 209727 times.
✓ Branch 1 taken 110446 times.
|
320173 | for (i = 0; i < ic->nb_streams; i++) { |
2617 | 209727 | AVStream *const st = ic->streams[i]; | |
2618 | 209727 | FFStream *const sti = ffstream(st); | |
2619 | 209727 | int fps_analyze_framecount = 20; | |
2620 | int count; | ||
2621 | |||
2622 |
2/2✓ Branch 1 taken 9307 times.
✓ Branch 2 taken 200420 times.
|
209727 | if (!has_codec_parameters(st, NULL)) |
2623 | 9307 | break; | |
2624 | /* If the timebase is coarse (like the usual millisecond precision | ||
2625 | * of mkv), we need to analyze more frames to reliably arrive at | ||
2626 | * the correct fps. */ | ||
2627 |
2/2✓ Branch 1 taken 121121 times.
✓ Branch 2 taken 79299 times.
|
200420 | if (av_q2d(st->time_base) > 0.0005) |
2628 | 121121 | fps_analyze_framecount *= 2; | |
2629 |
2/2✓ Branch 1 taken 8435 times.
✓ Branch 2 taken 191985 times.
|
200420 | if (!tb_unreliable(ic, st)) |
2630 | 8435 | fps_analyze_framecount = 0; | |
2631 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 200420 times.
|
200420 | if (ic->fps_probe_size >= 0) |
2632 | ✗ | fps_analyze_framecount = ic->fps_probe_size; | |
2633 |
2/2✓ Branch 0 taken 44 times.
✓ Branch 1 taken 200376 times.
|
200420 | if (st->disposition & AV_DISPOSITION_ATTACHED_PIC) |
2634 | 44 | fps_analyze_framecount = 0; | |
2635 | /* variable fps and no guess at the real fps */ | ||
2636 |
2/2✓ Branch 0 taken 19298 times.
✓ Branch 1 taken 181122 times.
|
200420 | count = (ic->iformat->flags & AVFMT_NOTIMESTAMPS) ? |
2637 | 19298 | sti->info->codec_info_duration_fields/2 : | |
2638 | 181122 | sti->info->duration_count; | |
2639 |
4/4✓ Branch 0 taken 101897 times.
✓ Branch 1 taken 98523 times.
✓ Branch 2 taken 223 times.
✓ Branch 3 taken 101674 times.
|
200420 | if (!(st->r_frame_rate.num && st->avg_frame_rate.num) && |
2640 |
2/2✓ Branch 0 taken 42928 times.
✓ Branch 1 taken 55818 times.
|
98746 | st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { |
2641 |
2/2✓ Branch 0 taken 24882 times.
✓ Branch 1 taken 18046 times.
|
42928 | if (count < fps_analyze_framecount) |
2642 | 24882 | break; | |
2643 | } | ||
2644 | // Look at the first 3 frames if there is evidence of frame delay | ||
2645 | // but the decoder delay is not set. | ||
2646 |
6/6✓ Branch 0 taken 2898 times.
✓ Branch 1 taken 172640 times.
✓ Branch 2 taken 130 times.
✓ Branch 3 taken 2768 times.
✓ Branch 4 taken 12 times.
✓ Branch 5 taken 118 times.
|
175538 | if (sti->info->frame_delay_evidence && count < 2 && sti->avctx->has_b_frames == 0) |
2647 | 12 | break; | |
2648 |
2/2✓ Branch 0 taken 155341 times.
✓ Branch 1 taken 20185 times.
|
175526 | if (!sti->avctx->extradata && |
2649 |
6/6✓ Branch 0 taken 153540 times.
✓ Branch 1 taken 1801 times.
✓ Branch 2 taken 110 times.
✓ Branch 3 taken 153430 times.
✓ Branch 4 taken 110 times.
✓ Branch 5 taken 1801 times.
|
157252 | (!sti->extract_extradata.inited || sti->extract_extradata.bsf) && |
2650 | 1911 | extract_extradata_check(st)) | |
2651 | 110 | break; | |
2652 |
2/2✓ Branch 0 taken 59521 times.
✓ Branch 1 taken 115895 times.
|
175416 | if (sti->first_dts == AV_NOPTS_VALUE && |
2653 |
6/6✓ Branch 0 taken 9372 times.
✓ Branch 1 taken 50149 times.
✓ Branch 2 taken 9291 times.
✓ Branch 3 taken 81 times.
✓ Branch 4 taken 57152 times.
✓ Branch 5 taken 2288 times.
|
118961 | (!(ic->iformat->flags & AVFMT_NOTIMESTAMPS) || sti->need_parsing == AVSTREAM_PARSE_FULL_RAW) && |
2654 |
2/2✓ Branch 0 taken 59396 times.
✓ Branch 1 taken 44 times.
|
59440 | sti->codec_info_nb_frames < ((st->disposition & AV_DISPOSITION_ATTACHED_PIC) ? 1 : ic->max_ts_probe) && |
2655 |
2/2✓ Branch 0 taken 41396 times.
✓ Branch 1 taken 15756 times.
|
57152 | (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || |
2656 |
2/2✓ Branch 0 taken 783 times.
✓ Branch 1 taken 40613 times.
|
41396 | st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)) |
2657 | break; | ||
2658 | } | ||
2659 | 201126 | analyzed_all_streams = 0; | |
2660 |
4/4✓ Branch 0 taken 110446 times.
✓ Branch 1 taken 90680 times.
✓ Branch 2 taken 110407 times.
✓ Branch 3 taken 39 times.
|
201126 | if (i == ic->nb_streams && !si->missing_streams) { |
2661 | 110407 | analyzed_all_streams = 1; | |
2662 | /* NOTE: If the format has no header, then we need to read some | ||
2663 | * packets to get most of the streams, so we cannot stop here. */ | ||
2664 |
2/2✓ Branch 0 taken 3295 times.
✓ Branch 1 taken 107112 times.
|
110407 | if (!(ic->ctx_flags & AVFMTCTX_NOHEADER)) { |
2665 | /* If we found the info for all the codecs, we can stop. */ | ||
2666 | 3295 | ret = count; | |
2667 | 3295 | av_log(ic, AV_LOG_DEBUG, "All info found\n"); | |
2668 | 3295 | flush_codecs = 0; | |
2669 | 3295 | break; | |
2670 | } | ||
2671 | } | ||
2672 | /* We did not get all the codec info, but we read too much data. */ | ||
2673 |
2/2✓ Branch 0 taken 2986 times.
✓ Branch 1 taken 194845 times.
|
197831 | if (read_size >= probesize) { |
2674 | 2986 | ret = count; | |
2675 | 2986 | av_log(ic, AV_LOG_DEBUG, | |
2676 | "Probe buffer size limit of %"PRId64" bytes reached\n", probesize); | ||
2677 |
2/2✓ Branch 0 taken 3000 times.
✓ Branch 1 taken 2986 times.
|
5986 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
2678 | 3000 | AVStream *const st = ic->streams[i]; | |
2679 | 3000 | FFStream *const sti = ffstream(st); | |
2680 |
2/2✓ Branch 0 taken 55 times.
✓ Branch 1 taken 2945 times.
|
3000 | if (!st->r_frame_rate.num && |
2681 |
2/2✓ Branch 0 taken 15 times.
✓ Branch 1 taken 40 times.
|
55 | sti->info->duration_count <= 1 && |
2682 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 14 times.
|
15 | st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && |
2683 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | strcmp(ic->iformat->name, "image2")) |
2684 | 1 | av_log(ic, AV_LOG_WARNING, | |
2685 | "Stream #%d: not enough frames to estimate rate; " | ||
2686 | "consider increasing probesize\n", i); | ||
2687 | } | ||
2688 | 2986 | break; | |
2689 | } | ||
2690 | |||
2691 | /* NOTE: A new stream can be added there if no header in file | ||
2692 | * (AVFMTCTX_NOHEADER). */ | ||
2693 | 194845 | ret = read_frame_internal(ic, pkt1); | |
2694 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 194845 times.
|
194845 | if (ret == AVERROR(EAGAIN)) |
2695 | ✗ | continue; | |
2696 | |||
2697 |
2/2✓ Branch 0 taken 1186 times.
✓ Branch 1 taken 193659 times.
|
194845 | if (ret < 0) { |
2698 | /* EOF or error*/ | ||
2699 | 1186 | eof_reached = 1; | |
2700 | 1186 | break; | |
2701 | } | ||
2702 | |||
2703 |
1/2✓ Branch 0 taken 193659 times.
✗ Branch 1 not taken.
|
193659 | if (!(ic->flags & AVFMT_FLAG_NOBUFFER)) { |
2704 | 193659 | ret = avpriv_packet_list_put(&si->packet_buffer, | |
2705 | pkt1, NULL, 0); | ||
2706 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 193659 times.
|
193659 | if (ret < 0) |
2707 | ✗ | goto unref_then_goto_end; | |
2708 | |||
2709 | 193659 | pkt = &si->packet_buffer.tail->pkt; | |
2710 | } else { | ||
2711 | ✗ | pkt = pkt1; | |
2712 | } | ||
2713 | |||
2714 | 193659 | st = ic->streams[pkt->stream_index]; | |
2715 | 193659 | sti = ffstream(st); | |
2716 |
2/2✓ Branch 0 taken 193603 times.
✓ Branch 1 taken 56 times.
|
193659 | if (!(st->disposition & AV_DISPOSITION_ATTACHED_PIC)) |
2717 | 193603 | read_size += pkt->size; | |
2718 | |||
2719 | 193659 | avctx = sti->avctx; | |
2720 |
2/2✓ Branch 0 taken 676 times.
✓ Branch 1 taken 192983 times.
|
193659 | if (!sti->avctx_inited) { |
2721 | 676 | ret = avcodec_parameters_to_context(avctx, st->codecpar); | |
2722 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 676 times.
|
676 | if (ret < 0) |
2723 | ✗ | goto unref_then_goto_end; | |
2724 | 676 | sti->avctx_inited = 1; | |
2725 | } | ||
2726 | |||
2727 |
4/4✓ Branch 0 taken 177327 times.
✓ Branch 1 taken 16332 times.
✓ Branch 2 taken 164936 times.
✓ Branch 3 taken 12391 times.
|
193659 | if (pkt->dts != AV_NOPTS_VALUE && sti->codec_info_nb_frames > 1) { |
2728 | /* check for non-increasing dts */ | ||
2729 |
2/2✓ Branch 0 taken 160053 times.
✓ Branch 1 taken 4883 times.
|
164936 | if (sti->info->fps_last_dts != AV_NOPTS_VALUE && |
2730 |
2/2✓ Branch 0 taken 23 times.
✓ Branch 1 taken 160030 times.
|
160053 | sti->info->fps_last_dts >= pkt->dts) { |
2731 | 23 | av_log(ic, AV_LOG_DEBUG, | |
2732 | "Non-increasing DTS in stream %d: packet %d with DTS " | ||
2733 | "%"PRId64", packet %d with DTS %"PRId64"\n", | ||
2734 | 23 | st->index, sti->info->fps_last_dts_idx, | |
2735 | 23 | sti->info->fps_last_dts, sti->codec_info_nb_frames, | |
2736 | 23 | pkt->dts); | |
2737 | 23 | sti->info->fps_first_dts = | |
2738 | 23 | sti->info->fps_last_dts = AV_NOPTS_VALUE; | |
2739 | } | ||
2740 | /* Check for a discontinuity in dts. If the difference in dts | ||
2741 | * is more than 1000 times the average packet duration in the | ||
2742 | * sequence, we treat it as a discontinuity. */ | ||
2743 |
2/2✓ Branch 0 taken 160030 times.
✓ Branch 1 taken 4906 times.
|
164936 | if (sti->info->fps_last_dts != AV_NOPTS_VALUE && |
2744 |
2/2✓ Branch 0 taken 155176 times.
✓ Branch 1 taken 4854 times.
|
160030 | sti->info->fps_last_dts_idx > sti->info->fps_first_dts_idx && |
2745 | 155176 | (pkt->dts - (uint64_t)sti->info->fps_last_dts) / 1000 > | |
2746 | 155176 | (sti->info->fps_last_dts - (uint64_t)sti->info->fps_first_dts) / | |
2747 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 155176 times.
|
155176 | (sti->info->fps_last_dts_idx - sti->info->fps_first_dts_idx)) { |
2748 | ✗ | av_log(ic, AV_LOG_WARNING, | |
2749 | "DTS discontinuity in stream %d: packet %d with DTS " | ||
2750 | "%"PRId64", packet %d with DTS %"PRId64"\n", | ||
2751 | ✗ | st->index, sti->info->fps_last_dts_idx, | |
2752 | ✗ | sti->info->fps_last_dts, sti->codec_info_nb_frames, | |
2753 | ✗ | pkt->dts); | |
2754 | ✗ | sti->info->fps_first_dts = | |
2755 | ✗ | sti->info->fps_last_dts = AV_NOPTS_VALUE; | |
2756 | } | ||
2757 | |||
2758 | /* update stored dts values */ | ||
2759 |
2/2✓ Branch 0 taken 4906 times.
✓ Branch 1 taken 160030 times.
|
164936 | if (sti->info->fps_first_dts == AV_NOPTS_VALUE) { |
2760 | 4906 | sti->info->fps_first_dts = pkt->dts; | |
2761 | 4906 | sti->info->fps_first_dts_idx = sti->codec_info_nb_frames; | |
2762 | } | ||
2763 | 164936 | sti->info->fps_last_dts = pkt->dts; | |
2764 | 164936 | sti->info->fps_last_dts_idx = sti->codec_info_nb_frames; | |
2765 | } | ||
2766 |
2/2✓ Branch 0 taken 180098 times.
✓ Branch 1 taken 13561 times.
|
193659 | if (sti->codec_info_nb_frames > 1) { |
2767 | 180098 | int64_t t = 0; | |
2768 | int64_t limit; | ||
2769 | |||
2770 |
1/2✓ Branch 0 taken 180098 times.
✗ Branch 1 not taken.
|
180098 | if (st->time_base.den > 0) |
2771 | 180098 | t = av_rescale_q(sti->info->codec_info_duration, st->time_base, AV_TIME_BASE_Q); | |
2772 |
2/2✓ Branch 0 taken 113220 times.
✓ Branch 1 taken 66878 times.
|
180098 | if (st->avg_frame_rate.num > 0) |
2773 |
2/2✓ Branch 1 taken 112693 times.
✓ Branch 2 taken 527 times.
|
113220 | t = FFMAX(t, av_rescale_q(sti->codec_info_nb_frames, av_inv_q(st->avg_frame_rate), AV_TIME_BASE_Q)); |
2774 | |||
2775 |
2/2✓ Branch 0 taken 4115 times.
✓ Branch 1 taken 175983 times.
|
180098 | if ( t == 0 |
2776 |
2/2✓ Branch 0 taken 535 times.
✓ Branch 1 taken 3580 times.
|
4115 | && sti->codec_info_nb_frames > 30 |
2777 |
2/2✓ Branch 0 taken 497 times.
✓ Branch 1 taken 38 times.
|
535 | && sti->info->fps_first_dts != AV_NOPTS_VALUE |
2778 |
1/2✓ Branch 0 taken 497 times.
✗ Branch 1 not taken.
|
497 | && sti->info->fps_last_dts != AV_NOPTS_VALUE) { |
2779 | 497 | int64_t dur = av_sat_sub64(sti->info->fps_last_dts, sti->info->fps_first_dts); | |
2780 |
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)); |
2781 | } | ||
2782 | |||
2783 |
2/2✓ Branch 0 taken 100868 times.
✓ Branch 1 taken 79230 times.
|
180098 | if (analyzed_all_streams) limit = max_analyze_duration; |
2784 |
2/2✓ Branch 0 taken 91 times.
✓ Branch 1 taken 79139 times.
|
79230 | else if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE) limit = max_subtitle_analyze_duration; |
2785 | 79139 | else limit = max_stream_analyze_duration; | |
2786 | |||
2787 |
2/2✓ Branch 0 taken 103 times.
✓ Branch 1 taken 179995 times.
|
180098 | if (t >= limit) { |
2788 | 103 | av_log(ic, AV_LOG_VERBOSE, "max_analyze_duration %"PRId64" reached at %"PRId64" microseconds st:%d\n", | |
2789 | limit, | ||
2790 | 103 | t, pkt->stream_index); | |
2791 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 103 times.
|
103 | if (ic->flags & AVFMT_FLAG_NOBUFFER) |
2792 | ✗ | av_packet_unref(pkt1); | |
2793 | 103 | break; | |
2794 | } | ||
2795 |
3/4✓ Branch 0 taken 176349 times.
✓ Branch 1 taken 3646 times.
✓ Branch 2 taken 176349 times.
✗ Branch 3 not taken.
|
179995 | if (pkt->duration > 0 && pkt->duration < INT64_MAX - sti->info->codec_info_duration) { |
2796 |
4/4✓ Branch 0 taken 176305 times.
✓ Branch 1 taken 44 times.
✓ Branch 2 taken 14236 times.
✓ Branch 3 taken 162069 times.
|
176349 | const int fields = sti->codec_desc && (sti->codec_desc->props & AV_CODEC_PROP_FIELDS); |
2797 |
1/8✗ Branch 0 not taken.
✓ Branch 1 taken 176349 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.
|
176349 | if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE && pkt->pts != AV_NOPTS_VALUE && st->start_time != AV_NOPTS_VALUE && pkt->pts >= st->start_time |
2798 | ✗ | && (uint64_t)pkt->pts - st->start_time < INT64_MAX | |
2799 | ) { | ||
2800 | ✗ | sti->info->codec_info_duration = FFMIN(pkt->pts - st->start_time, sti->info->codec_info_duration + pkt->duration); | |
2801 | } else | ||
2802 | 176349 | sti->info->codec_info_duration += pkt->duration; | |
2803 |
4/4✓ Branch 0 taken 35590 times.
✓ Branch 1 taken 92454 times.
✓ Branch 2 taken 13864 times.
✓ Branch 3 taken 21726 times.
|
304393 | sti->info->codec_info_duration_fields += sti->parser && sti->need_parsing && fields |
2804 |
2/2✓ Branch 0 taken 128044 times.
✓ Branch 1 taken 48305 times.
|
304393 | ? sti->parser->repeat_pict + 1 : 2; |
2805 | } | ||
2806 | } | ||
2807 |
2/2✓ Branch 0 taken 131836 times.
✓ Branch 1 taken 61720 times.
|
193556 | if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { |
2808 | #if FF_API_R_FRAME_RATE | ||
2809 | 131836 | ff_rfps_add_frame(ic, st, pkt->dts); | |
2810 | #endif | ||
2811 |
6/6✓ Branch 0 taken 4230 times.
✓ Branch 1 taken 127606 times.
✓ Branch 2 taken 3991 times.
✓ Branch 3 taken 239 times.
✓ Branch 4 taken 1965 times.
✓ Branch 5 taken 2026 times.
|
131836 | if (pkt->dts != pkt->pts && pkt->dts != AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE) |
2812 | 1965 | sti->info->frame_delay_evidence = 1; | |
2813 | } | ||
2814 |
2/2✓ Branch 0 taken 162695 times.
✓ Branch 1 taken 30861 times.
|
193556 | if (!sti->avctx->extradata) { |
2815 | 162695 | ret = extract_extradata(si, st, pkt); | |
2816 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 162695 times.
|
162695 | if (ret < 0) |
2817 | ✗ | goto unref_then_goto_end; | |
2818 | } | ||
2819 | |||
2820 | /* If still no information, we try to open the codec and to | ||
2821 | * decompress the frame. We try to avoid that in most cases as | ||
2822 | * it takes longer and uses more memory. For MPEG-4, we need to | ||
2823 | * decompress for QuickTime. | ||
2824 | * | ||
2825 | * If AV_CODEC_CAP_CHANNEL_CONF is set this will force decoding of at | ||
2826 | * least one frame of codec data, this makes sure the codec initializes | ||
2827 | * the channel configuration and does not only trust the values from | ||
2828 | * the container. */ | ||
2829 |
2/2✓ Branch 0 taken 176047 times.
✓ Branch 1 taken 17509 times.
|
369603 | try_decode_frame(ic, st, pkt, |
2830 |
2/2✓ Branch 0 taken 79481 times.
✓ Branch 1 taken 96566 times.
|
176047 | (options && i < orig_nb_streams) ? &options[i] : NULL); |
2831 | |||
2832 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 193556 times.
|
193556 | if (ic->flags & AVFMT_FLAG_NOBUFFER) |
2833 | ✗ | av_packet_unref(pkt1); | |
2834 | |||
2835 | 193556 | sti->codec_info_nb_frames++; | |
2836 | 193556 | count++; | |
2837 | } | ||
2838 | |||
2839 |
2/2✓ Branch 0 taken 1186 times.
✓ Branch 1 taken 6384 times.
|
7570 | if (eof_reached) { |
2840 |
2/2✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 1186 times.
|
2662 | for (unsigned stream_index = 0; stream_index < ic->nb_streams; stream_index++) { |
2841 | 1476 | AVStream *const st = ic->streams[stream_index]; | |
2842 | 1476 | AVCodecContext *const avctx = ffstream(st)->avctx; | |
2843 |
2/2✓ Branch 1 taken 29 times.
✓ Branch 2 taken 1447 times.
|
1476 | if (!has_codec_parameters(st, NULL)) { |
2844 | 29 | const AVCodec *codec = find_probe_decoder(ic, st, st->codecpar->codec_id); | |
2845 |
4/4✓ Branch 0 taken 22 times.
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 14 times.
|
29 | if (codec && !avctx->codec) { |
2846 | 8 | AVDictionary *opts = NULL; | |
2847 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
|
8 | if (ic->codec_whitelist) |
2848 | ✗ | av_dict_set(&opts, "codec_whitelist", ic->codec_whitelist, 0); | |
2849 |
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) |
2850 | ✗ | av_log(ic, AV_LOG_WARNING, | |
2851 | "Failed to open codec in %s\n", __func__); | ||
2852 | 8 | av_dict_free(&opts); | |
2853 | } | ||
2854 | } | ||
2855 | |||
2856 | // EOF already reached while reading the stream above. | ||
2857 | // So continue with reoordering DTS with whatever delay we have. | ||
2858 |
4/4✓ Branch 0 taken 1458 times.
✓ Branch 1 taken 18 times.
✓ Branch 3 taken 18 times.
✓ Branch 4 taken 1440 times.
|
1476 | if (si->packet_buffer.head && !has_decode_delay_been_guessed(st)) { |
2859 | 18 | update_dts_from_pts(ic, stream_index, si->packet_buffer.head); | |
2860 | } | ||
2861 | } | ||
2862 | } | ||
2863 | |||
2864 |
2/2✓ Branch 0 taken 4275 times.
✓ Branch 1 taken 3295 times.
|
7570 | if (flush_codecs) { |
2865 | 4275 | AVPacket *empty_pkt = si->pkt; | |
2866 | 4275 | int err = 0; | |
2867 | 4275 | av_packet_unref(empty_pkt); | |
2868 | |||
2869 |
2/2✓ Branch 0 taken 4618 times.
✓ Branch 1 taken 4275 times.
|
8893 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
2870 | 4618 | AVStream *const st = ic->streams[i]; | |
2871 | 4618 | FFStream *const sti = ffstream(st); | |
2872 | |||
2873 | /* flush the decoders */ | ||
2874 |
2/2✓ Branch 0 taken 4540 times.
✓ Branch 1 taken 78 times.
|
4618 | if (sti->info->found_decoder == 1) { |
2875 |
2/2✓ Branch 0 taken 4223 times.
✓ Branch 1 taken 317 times.
|
8763 | err = try_decode_frame(ic, st, empty_pkt, |
2876 |
2/2✓ Branch 0 taken 4207 times.
✓ Branch 1 taken 16 times.
|
4223 | (options && i < orig_nb_streams) |
2877 | 4207 | ? &options[i] : NULL); | |
2878 | |||
2879 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4540 times.
|
4540 | if (err < 0) { |
2880 | ✗ | av_log(ic, AV_LOG_INFO, | |
2881 | "decoding for stream %d failed\n", st->index); | ||
2882 | } | ||
2883 | } | ||
2884 | } | ||
2885 | } | ||
2886 | |||
2887 | 7570 | ff_rfps_calculate(ic); | |
2888 | |||
2889 |
2/2✓ Branch 0 taken 8379 times.
✓ Branch 1 taken 7570 times.
|
15949 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
2890 | 8379 | AVStream *const st = ic->streams[i]; | |
2891 | 8379 | FFStream *const sti = ffstream(st); | |
2892 | 8379 | AVCodecContext *const avctx = sti->avctx; | |
2893 | |||
2894 |
2/2✓ Branch 0 taken 6251 times.
✓ Branch 1 taken 2128 times.
|
8379 | if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) { |
2895 |
6/6✓ Branch 0 taken 638 times.
✓ Branch 1 taken 5613 times.
✓ Branch 2 taken 589 times.
✓ Branch 3 taken 49 times.
✓ Branch 4 taken 573 times.
✓ Branch 5 taken 16 times.
|
6251 | if (avctx->codec_id == AV_CODEC_ID_RAWVIDEO && !avctx->codec_tag && !avctx->bits_per_coded_sample) { |
2896 | 573 | uint32_t tag= avcodec_pix_fmt_to_codec_tag(avctx->pix_fmt); | |
2897 |
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) |
2898 | 566 | avctx->codec_tag= tag; | |
2899 | } | ||
2900 | |||
2901 | /* estimate average framerate if not set by demuxer */ | ||
2902 |
2/2✓ Branch 0 taken 4012 times.
✓ Branch 1 taken 2239 times.
|
6251 | if (sti->info->codec_info_duration_fields && |
2903 |
2/2✓ Branch 0 taken 269 times.
✓ Branch 1 taken 3743 times.
|
4012 | !st->avg_frame_rate.num && |
2904 |
1/2✓ Branch 0 taken 269 times.
✗ Branch 1 not taken.
|
269 | sti->info->codec_info_duration) { |
2905 | 269 | int best_fps = 0; | |
2906 | 269 | double best_error = 0.01; | |
2907 | 269 | AVRational codec_frame_rate = avctx->framerate; | |
2908 | |||
2909 |
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|| |
2910 |
1/2✓ Branch 0 taken 269 times.
✗ Branch 1 not taken.
|
269 | sti->info->codec_info_duration_fields >= INT64_MAX / st->time_base.den || |
2911 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 269 times.
|
269 | sti->info->codec_info_duration < 0) |
2912 | ✗ | continue; | |
2913 | 269 | av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den, | |
2914 | 269 | sti->info->codec_info_duration_fields * (int64_t) st->time_base.den, | |
2915 | 269 | sti->info->codec_info_duration * 2 * (int64_t) st->time_base.num, 60000); | |
2916 | |||
2917 | /* Round guessed framerate to a "standard" framerate if it's | ||
2918 | * within 1% of the original estimate. */ | ||
2919 |
2/2✓ Branch 0 taken 107331 times.
✓ Branch 1 taken 269 times.
|
107600 | for (int j = 0; j < MAX_STD_TIMEBASES; j++) { |
2920 | 107331 | AVRational std_fps = { get_std_framerate(j), 12 * 1001 }; | |
2921 | 107331 | double error = fabs(av_q2d(st->avg_frame_rate) / | |
2922 | 107331 | av_q2d(std_fps) - 1); | |
2923 | |||
2924 |
2/2✓ Branch 0 taken 736 times.
✓ Branch 1 taken 106595 times.
|
107331 | if (error < best_error) { |
2925 | 736 | best_error = error; | |
2926 | 736 | best_fps = std_fps.num; | |
2927 | } | ||
2928 | |||
2929 |
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) && |
2930 |
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) { |
2931 | 12768 | error = fabs(av_q2d(codec_frame_rate) / | |
2932 | 12768 | av_q2d(std_fps) - 1); | |
2933 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 12758 times.
|
12768 | if (error < best_error) { |
2934 | 10 | best_error = error; | |
2935 | 10 | best_fps = std_fps.num; | |
2936 | } | ||
2937 | } | ||
2938 | } | ||
2939 |
2/2✓ Branch 0 taken 267 times.
✓ Branch 1 taken 2 times.
|
269 | if (best_fps) |
2940 | 267 | av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den, | |
2941 | best_fps, 12 * 1001, INT_MAX); | ||
2942 | } | ||
2943 |
2/2✓ Branch 0 taken 1846 times.
✓ Branch 1 taken 4405 times.
|
6251 | if (!st->r_frame_rate.num) { |
2944 | 1846 | const AVCodecDescriptor *desc = sti->codec_desc; | |
2945 |
3/4✓ Branch 0 taken 1846 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 246 times.
✓ Branch 3 taken 1600 times.
|
1846 | AVRational mul = (AVRational){ desc && (desc->props & AV_CODEC_PROP_FIELDS) ? 2 : 1, 1 }; |
2946 | 1846 | AVRational fr = av_mul_q(avctx->framerate, mul); | |
2947 | |||
2948 |
5/6✓ Branch 0 taken 189 times.
✓ Branch 1 taken 1657 times.
✓ Branch 2 taken 189 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 175 times.
✓ Branch 7 taken 14 times.
|
1846 | if (fr.num && fr.den && av_cmp_q(st->time_base, av_inv_q(fr)) <= 0) { |
2949 | 175 | st->r_frame_rate = fr; | |
2950 | } else { | ||
2951 | 1671 | st->r_frame_rate.num = st->time_base.den; | |
2952 | 1671 | st->r_frame_rate.den = st->time_base.num; | |
2953 | } | ||
2954 | } | ||
2955 | 6251 | st->codecpar->framerate = avctx->framerate; | |
2956 |
3/4✓ Branch 0 taken 116 times.
✓ Branch 1 taken 6135 times.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
|
6251 | if (sti->display_aspect_ratio.num && sti->display_aspect_ratio.den) { |
2957 | 116 | AVRational hw_ratio = { avctx->height, avctx->width }; | |
2958 | 116 | st->sample_aspect_ratio = av_mul_q(sti->display_aspect_ratio, | |
2959 | hw_ratio); | ||
2960 | } | ||
2961 |
2/2✓ Branch 0 taken 1959 times.
✓ Branch 1 taken 169 times.
|
2128 | } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) { |
2962 |
2/2✓ Branch 0 taken 642 times.
✓ Branch 1 taken 1317 times.
|
1959 | if (!avctx->bits_per_coded_sample) |
2963 | 642 | avctx->bits_per_coded_sample = | |
2964 | 642 | av_get_bits_per_sample(avctx->codec_id); | |
2965 | // set stream disposition based on audio service type | ||
2966 |
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 1959 times.
|
1959 | switch (avctx->audio_service_type) { |
2967 | ✗ | case AV_AUDIO_SERVICE_TYPE_EFFECTS: | |
2968 | ✗ | st->disposition = AV_DISPOSITION_CLEAN_EFFECTS; | |
2969 | ✗ | break; | |
2970 | ✗ | case AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED: | |
2971 | ✗ | st->disposition = AV_DISPOSITION_VISUAL_IMPAIRED; | |
2972 | ✗ | break; | |
2973 | ✗ | case AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED: | |
2974 | ✗ | st->disposition = AV_DISPOSITION_HEARING_IMPAIRED; | |
2975 | ✗ | break; | |
2976 | ✗ | case AV_AUDIO_SERVICE_TYPE_COMMENTARY: | |
2977 | ✗ | st->disposition = AV_DISPOSITION_COMMENT; | |
2978 | ✗ | break; | |
2979 | ✗ | case AV_AUDIO_SERVICE_TYPE_KARAOKE: | |
2980 | ✗ | st->disposition = AV_DISPOSITION_KARAOKE; | |
2981 | ✗ | break; | |
2982 | } | ||
2983 | } | ||
2984 | } | ||
2985 | |||
2986 |
1/2✓ Branch 0 taken 7570 times.
✗ Branch 1 not taken.
|
7570 | if (probesize) |
2987 | 7570 | estimate_timings(ic, old_offset); | |
2988 | |||
2989 | 7570 | av_opt_set_int(ic, "skip_clear", 0, AV_OPT_SEARCH_CHILDREN); | |
2990 | |||
2991 |
3/4✓ Branch 0 taken 6384 times.
✓ Branch 1 taken 1186 times.
✓ Branch 2 taken 6384 times.
✗ Branch 3 not taken.
|
7570 | if (ret >= 0 && ic->nb_streams) |
2992 | /* We could not have all the codec parameters before EOF. */ | ||
2993 | 6384 | ret = -1; | |
2994 |
2/2✓ Branch 0 taken 8379 times.
✓ Branch 1 taken 7570 times.
|
15949 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
2995 | 8379 | AVStream *const st = ic->streams[i]; | |
2996 | 8379 | FFStream *const sti = ffstream(st); | |
2997 | const char *errmsg; | ||
2998 | |||
2999 | /* if no packet was ever seen, update context now for has_codec_parameters */ | ||
3000 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 8366 times.
|
8379 | if (!sti->avctx_inited) { |
3001 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 5 times.
|
13 | if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && |
3002 |
1/2✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
|
8 | st->codecpar->format == AV_SAMPLE_FMT_NONE) |
3003 | 8 | st->codecpar->format = sti->avctx->sample_fmt; | |
3004 | 13 | ret = avcodec_parameters_to_context(sti->avctx, st->codecpar); | |
3005 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
|
13 | if (ret < 0) |
3006 | ✗ | goto find_stream_info_err; | |
3007 | } | ||
3008 |
2/2✓ Branch 1 taken 36 times.
✓ Branch 2 taken 8343 times.
|
8379 | if (!has_codec_parameters(st, &errmsg)) { |
3009 | char buf[256]; | ||
3010 | 36 | avcodec_string(buf, sizeof(buf), sti->avctx, 0); | |
3011 | 36 | av_log(ic, AV_LOG_WARNING, | |
3012 | "Could not find codec parameters for stream %d (%s): %s\n" | ||
3013 | "Consider increasing the value for the 'analyzeduration' (%"PRId64") and 'probesize' (%"PRId64") options\n", | ||
3014 | i, buf, errmsg, ic->max_analyze_duration, ic->probesize); | ||
3015 | } else { | ||
3016 | 8343 | ret = 0; | |
3017 | } | ||
3018 | } | ||
3019 | |||
3020 | 7570 | err = compute_chapters_end(ic); | |
3021 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7570 times.
|
7570 | if (err < 0) { |
3022 | ✗ | ret = err; | |
3023 | ✗ | goto find_stream_info_err; | |
3024 | } | ||
3025 | |||
3026 | /* update the stream parameters from the internal codec contexts */ | ||
3027 |
2/2✓ Branch 0 taken 8379 times.
✓ Branch 1 taken 7570 times.
|
15949 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
3028 | 8379 | AVStream *const st = ic->streams[i]; | |
3029 | 8379 | FFStream *const sti = ffstream(st); | |
3030 | |||
3031 |
2/2✓ Branch 0 taken 8366 times.
✓ Branch 1 taken 13 times.
|
8379 | if (sti->avctx_inited) { |
3032 | 8366 | ret = avcodec_parameters_from_context(st->codecpar, sti->avctx); | |
3033 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8366 times.
|
8366 | if (ret < 0) |
3034 | ✗ | goto find_stream_info_err; | |
3035 | |||
3036 |
3/4✓ Branch 0 taken 8182 times.
✓ Branch 1 taken 184 times.
✓ Branch 2 taken 8182 times.
✗ Branch 3 not taken.
|
8366 | if (sti->avctx->rc_buffer_size > 0 || sti->avctx->rc_max_rate > 0 || |
3037 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8182 times.
|
8182 | sti->avctx->rc_min_rate) { |
3038 | size_t cpb_size; | ||
3039 | 184 | AVCPBProperties *props = av_cpb_properties_alloc(&cpb_size); | |
3040 |
1/2✓ Branch 0 taken 184 times.
✗ Branch 1 not taken.
|
184 | if (props) { |
3041 |
1/2✓ Branch 0 taken 184 times.
✗ Branch 1 not taken.
|
184 | if (sti->avctx->rc_buffer_size > 0) |
3042 | 184 | props->buffer_size = sti->avctx->rc_buffer_size; | |
3043 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 184 times.
|
184 | if (sti->avctx->rc_min_rate > 0) |
3044 | ✗ | props->min_bitrate = sti->avctx->rc_min_rate; | |
3045 |
2/2✓ Branch 0 taken 77 times.
✓ Branch 1 taken 107 times.
|
184 | if (sti->avctx->rc_max_rate > 0) |
3046 | 77 | props->max_bitrate = sti->avctx->rc_max_rate; | |
3047 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 184 times.
|
184 | if (!av_packet_side_data_add(&st->codecpar->coded_side_data, |
3048 | 184 | &st->codecpar->nb_coded_side_data, | |
3049 | AV_PKT_DATA_CPB_PROPERTIES, | ||
3050 | (uint8_t *)props, cpb_size, 0)) | ||
3051 | ✗ | av_free(props); | |
3052 | } | ||
3053 | } | ||
3054 | } | ||
3055 | |||
3056 | 8379 | sti->avctx_inited = 0; | |
3057 | } | ||
3058 | |||
3059 | 7570 | find_stream_info_err: | |
3060 |
2/2✓ Branch 0 taken 8379 times.
✓ Branch 1 taken 7570 times.
|
15949 | for (unsigned i = 0; i < ic->nb_streams; i++) { |
3061 | 8379 | AVStream *const st = ic->streams[i]; | |
3062 | 8379 | FFStream *const sti = ffstream(st); | |
3063 | int err; | ||
3064 | |||
3065 |
1/2✓ Branch 0 taken 8379 times.
✗ Branch 1 not taken.
|
8379 | if (sti->info) { |
3066 | 8379 | av_freep(&sti->info->duration_error); | |
3067 | 8379 | av_freep(&sti->info); | |
3068 | } | ||
3069 | |||
3070 |
2/2✓ Branch 1 taken 8271 times.
✓ Branch 2 taken 108 times.
|
8379 | if (avcodec_is_open(sti->avctx)) { |
3071 | 8271 | err = codec_close(sti); | |
3072 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 8271 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
8271 | if (err < 0 && ret >= 0) |
3073 | ✗ | ret = err; | |
3074 | } | ||
3075 | |||
3076 | 8379 | av_bsf_free(&sti->extract_extradata.bsf); | |
3077 | } | ||
3078 |
2/2✓ Branch 0 taken 4511 times.
✓ Branch 1 taken 3059 times.
|
7570 | if (ic->pb) { |
3079 | 4511 | FFIOContext *const ctx = ffiocontext(ic->pb); | |
3080 | 4511 | av_log(ic, AV_LOG_DEBUG, "After avformat_find_stream_info() pos: %"PRId64" bytes read:%"PRId64" seeks:%d frames:%d\n", | |
3081 | avio_tell(ic->pb), ctx->bytes_read, ctx->seek_count, count); | ||
3082 | } | ||
3083 | 7570 | return ret; | |
3084 | |||
3085 | ✗ | unref_then_goto_end: | |
3086 | ✗ | av_packet_unref(pkt1); | |
3087 | ✗ | goto find_stream_info_err; | |
3088 | } | ||
3089 |