FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/fftools/ffmpeg_demux.c
Date: 2024-06-18 16:06:53
Exec Total Coverage
Lines: 810 1054 76.9%
Functions: 34 35 97.1%
Branches: 559 1148 48.7%

Line Branch Exec Source
1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include <float.h>
20 #include <stdint.h>
21
22 #include "ffmpeg.h"
23 #include "ffmpeg_sched.h"
24 #include "ffmpeg_utils.h"
25
26 #include "libavutil/avassert.h"
27 #include "libavutil/avstring.h"
28 #include "libavutil/display.h"
29 #include "libavutil/error.h"
30 #include "libavutil/intreadwrite.h"
31 #include "libavutil/mem.h"
32 #include "libavutil/opt.h"
33 #include "libavutil/parseutils.h"
34 #include "libavutil/pixdesc.h"
35 #include "libavutil/time.h"
36 #include "libavutil/timestamp.h"
37
38 #include "libavcodec/bsf.h"
39 #include "libavcodec/packet.h"
40
41 #include "libavformat/avformat.h"
42
43 typedef struct DemuxStream {
44 InputStream ist;
45
46 // name used for logging
47 char log_name[32];
48
49 int sch_idx_stream;
50 int sch_idx_dec;
51
52 double ts_scale;
53
54 /* non zero if the packets must be decoded in 'raw_fifo', see DECODING_FOR_* */
55 int decoding_needed;
56 #define DECODING_FOR_OST 1
57 #define DECODING_FOR_FILTER 2
58
59 /* true if stream data should be discarded */
60 int discard;
61
62 // scheduler returned EOF for this stream
63 int finished;
64
65 int streamcopy_needed;
66 int have_sub2video;
67 int reinit_filters;
68 int autorotate;
69
70
71 int wrap_correction_done;
72 int saw_first_ts;
73 ///< dts of the first packet read for this stream (in AV_TIME_BASE units)
74 int64_t first_dts;
75
76 /* predicted dts of the next packet read for this stream or (when there are
77 * several frames in a packet) of the next frame in current packet (in AV_TIME_BASE units) */
78 int64_t next_dts;
79 ///< dts of the last packet read for this stream (in AV_TIME_BASE units)
80 int64_t dts;
81
82 const AVCodecDescriptor *codec_desc;
83
84 AVDictionary *decoder_opts;
85 DecoderOpts dec_opts;
86 char dec_name[16];
87 // decoded media properties, as estimated by opening the decoder
88 AVFrame *decoded_params;
89
90 AVBSFContext *bsf;
91
92 /* number of packets successfully read for this stream */
93 uint64_t nb_packets;
94 // combined size of all the packets read
95 uint64_t data_size;
96 } DemuxStream;
97
98 typedef struct Demuxer {
99 InputFile f;
100
101 // name used for logging
102 char log_name[32];
103
104 int64_t wallclock_start;
105
106 /**
107 * Extra timestamp offset added by discontinuity handling.
108 */
109 int64_t ts_offset_discont;
110 int64_t last_ts;
111
112 int64_t recording_time;
113 int accurate_seek;
114
115 /* number of times input stream should be looped */
116 int loop;
117 int have_audio_dec;
118 /* duration of the looped segment of the input file */
119 Timestamp duration;
120 /* pts with the smallest/largest values ever seen */
121 Timestamp min_pts;
122 Timestamp max_pts;
123
124 /* number of streams that the user was warned of */
125 int nb_streams_warn;
126
127 float readrate;
128 double readrate_initial_burst;
129
130 Scheduler *sch;
131
132 AVPacket *pkt_heartbeat;
133
134 int read_started;
135 int nb_streams_used;
136 int nb_streams_finished;
137 } Demuxer;
138
139 typedef struct DemuxThreadContext {
140 // packet used for reading from the demuxer
141 AVPacket *pkt_demux;
142 // packet for reading from BSFs
143 AVPacket *pkt_bsf;
144 } DemuxThreadContext;
145
146 1838728 static DemuxStream *ds_from_ist(InputStream *ist)
147 {
148 1838728 return (DemuxStream*)ist;
149 }
150
151 20273 static Demuxer *demuxer_from_ifile(InputFile *f)
152 {
153 20273 return (Demuxer*)f;
154 }
155
156 55 InputStream *ist_find_unused(enum AVMediaType type)
157 {
158
1/2
✓ Branch 2 taken 74 times.
✗ Branch 3 not taken.
74 for (InputStream *ist = ist_iter(NULL); ist; ist = ist_iter(ist)) {
159 74 DemuxStream *ds = ds_from_ist(ist);
160
4/4
✓ Branch 0 taken 73 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 55 times.
✓ Branch 3 taken 18 times.
74 if (ist->par->codec_type == type && ds->discard &&
161
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 ist->user_set_discard != AVDISCARD_ALL)
162 55 return ist;
163 }
164 return NULL;
165 }
166
167 9747 static void report_new_stream(Demuxer *d, const AVPacket *pkt)
168 {
169 9747 const AVStream *st = d->f.ctx->streams[pkt->stream_index];
170
171
1/2
✓ Branch 0 taken 9747 times.
✗ Branch 1 not taken.
9747 if (pkt->stream_index < d->nb_streams_warn)
172 9747 return;
173 av_log(d, AV_LOG_WARNING,
174 "New %s stream with index %d at pos:%"PRId64" and DTS:%ss\n",
175 av_get_media_type_string(st->codecpar->codec_type),
176 pkt->stream_index, pkt->pos, av_ts2timestr(pkt->dts, &st->time_base));
177 d->nb_streams_warn = pkt->stream_index + 1;
178 }
179
180 11 static int seek_to_start(Demuxer *d, Timestamp end_pts)
181 {
182 11 InputFile *ifile = &d->f;
183 11 AVFormatContext *is = ifile->ctx;
184 int ret;
185
186 11 ret = avformat_seek_file(is, -1, INT64_MIN, is->start_time, is->start_time, 0);
187
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (ret < 0)
188 return ret;
189
190
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 8 times.
11 if (end_pts.ts != AV_NOPTS_VALUE &&
191
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
6 (d->max_pts.ts == AV_NOPTS_VALUE ||
192 3 av_compare_ts(d->max_pts.ts, d->max_pts.tb, end_pts.ts, end_pts.tb) < 0))
193 3 d->max_pts = end_pts;
194
195
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (d->max_pts.ts != AV_NOPTS_VALUE) {
196
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 int64_t min_pts = d->min_pts.ts == AV_NOPTS_VALUE ? 0 : d->min_pts.ts;
197 11 d->duration.ts = d->max_pts.ts - av_rescale_q(min_pts, d->min_pts.tb, d->max_pts.tb);
198 }
199 11 d->duration.tb = d->max_pts.tb;
200
201
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (d->loop > 0)
202 11 d->loop--;
203
204 11 return ret;
205 }
206
207 410955 static void ts_discontinuity_detect(Demuxer *d, InputStream *ist,
208 AVPacket *pkt)
209 {
210 410955 InputFile *ifile = &d->f;
211 410955 DemuxStream *ds = ds_from_ist(ist);
212 410955 const int fmt_is_discont = ifile->ctx->iformat->flags & AVFMT_TS_DISCONT;
213 410955 int disable_discontinuity_correction = copy_ts;
214 410955 int64_t pkt_dts = av_rescale_q_rnd(pkt->dts, pkt->time_base, AV_TIME_BASE_Q,
215 AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX);
216
217
6/6
✓ Branch 0 taken 194 times.
✓ Branch 1 taken 410761 times.
✓ Branch 2 taken 188 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 73 times.
✓ Branch 5 taken 115 times.
410955 if (copy_ts && ds->next_dts != AV_NOPTS_VALUE &&
218
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 73 times.
73 fmt_is_discont && ist->st->pts_wrap_bits < 60) {
219 int64_t wrap_dts = av_rescale_q_rnd(pkt->dts + (1LL<<ist->st->pts_wrap_bits),
220 pkt->time_base, AV_TIME_BASE_Q,
221 AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
222 if (FFABS(wrap_dts - ds->next_dts) < FFABS(pkt_dts - ds->next_dts)/10)
223 disable_discontinuity_correction = 0;
224 }
225
226
4/4
✓ Branch 0 taken 404567 times.
✓ Branch 1 taken 6388 times.
✓ Branch 2 taken 404379 times.
✓ Branch 3 taken 188 times.
815334 if (ds->next_dts != AV_NOPTS_VALUE && !disable_discontinuity_correction) {
227 404379 int64_t delta = pkt_dts - ds->next_dts;
228
2/2
✓ Branch 0 taken 22511 times.
✓ Branch 1 taken 381868 times.
404379 if (fmt_is_discont) {
229
4/4
✓ Branch 0 taken 22455 times.
✓ Branch 1 taken 56 times.
✓ Branch 2 taken 22428 times.
✓ Branch 3 taken 83 times.
22511 if (FFABS(delta) > 1LL * dts_delta_threshold * AV_TIME_BASE ||
230
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 22420 times.
22428 pkt_dts + AV_TIME_BASE/10 < ds->dts) {
231 91 d->ts_offset_discont -= delta;
232 91 av_log(ist, AV_LOG_WARNING,
233 "timestamp discontinuity "
234 "(stream id=%d): %"PRId64", new offset= %"PRId64"\n",
235 91 ist->st->id, delta, d->ts_offset_discont);
236 91 pkt->dts -= av_rescale_q(delta, AV_TIME_BASE_Q, pkt->time_base);
237
1/2
✓ Branch 0 taken 91 times.
✗ Branch 1 not taken.
91 if (pkt->pts != AV_NOPTS_VALUE)
238 91 pkt->pts -= av_rescale_q(delta, AV_TIME_BASE_Q, pkt->time_base);
239 }
240 } else {
241
3/4
✓ Branch 0 taken 378404 times.
✓ Branch 1 taken 3464 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 381868 times.
381868 if (FFABS(delta) > 1LL * dts_error_threshold * AV_TIME_BASE) {
242 av_log(NULL, AV_LOG_WARNING,
243 "DTS %"PRId64", next:%"PRId64" st:%d invalid dropping\n",
244 pkt->dts, ds->next_dts, pkt->stream_index);
245 pkt->dts = AV_NOPTS_VALUE;
246 }
247
2/2
✓ Branch 0 taken 379806 times.
✓ Branch 1 taken 2062 times.
381868 if (pkt->pts != AV_NOPTS_VALUE){
248 379806 int64_t pkt_pts = av_rescale_q(pkt->pts, pkt->time_base, AV_TIME_BASE_Q);
249 379806 delta = pkt_pts - ds->next_dts;
250
3/4
✓ Branch 0 taken 376645 times.
✓ Branch 1 taken 3161 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 379806 times.
379806 if (FFABS(delta) > 1LL * dts_error_threshold * AV_TIME_BASE) {
251 av_log(NULL, AV_LOG_WARNING,
252 "PTS %"PRId64", next:%"PRId64" invalid dropping st:%d\n",
253 pkt->pts, ds->next_dts, pkt->stream_index);
254 pkt->pts = AV_NOPTS_VALUE;
255 }
256 }
257 }
258
6/6
✓ Branch 0 taken 6388 times.
✓ Branch 1 taken 188 times.
✓ Branch 2 taken 6382 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 114 times.
✓ Branch 5 taken 6268 times.
6576 } else if (ds->next_dts == AV_NOPTS_VALUE && !copy_ts &&
259
1/2
✓ Branch 0 taken 114 times.
✗ Branch 1 not taken.
114 fmt_is_discont && d->last_ts != AV_NOPTS_VALUE) {
260 114 int64_t delta = pkt_dts - d->last_ts;
261
3/4
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 60 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 114 times.
114 if (FFABS(delta) > 1LL * dts_delta_threshold * AV_TIME_BASE) {
262 d->ts_offset_discont -= delta;
263 av_log(NULL, AV_LOG_DEBUG,
264 "Inter stream timestamp discontinuity %"PRId64", new offset= %"PRId64"\n",
265 delta, d->ts_offset_discont);
266 pkt->dts -= av_rescale_q(delta, AV_TIME_BASE_Q, pkt->time_base);
267 if (pkt->pts != AV_NOPTS_VALUE)
268 pkt->pts -= av_rescale_q(delta, AV_TIME_BASE_Q, pkt->time_base);
269 }
270 }
271
272 410955 d->last_ts = av_rescale_q(pkt->dts, pkt->time_base, AV_TIME_BASE_Q);
273 410955 }
274
275 457733 static void ts_discontinuity_process(Demuxer *d, InputStream *ist,
276 AVPacket *pkt)
277 {
278 457733 int64_t offset = av_rescale_q(d->ts_offset_discont, AV_TIME_BASE_Q,
279 pkt->time_base);
280
281 // apply previously-detected timestamp-discontinuity offset
282 // (to all streams, not just audio/video)
283
2/2
✓ Branch 0 taken 413659 times.
✓ Branch 1 taken 44074 times.
457733 if (pkt->dts != AV_NOPTS_VALUE)
284 413659 pkt->dts += offset;
285
2/2
✓ Branch 0 taken 411557 times.
✓ Branch 1 taken 46176 times.
457733 if (pkt->pts != AV_NOPTS_VALUE)
286 411557 pkt->pts += offset;
287
288 // detect timestamp discontinuities for audio/video
289
2/2
✓ Branch 0 taken 281478 times.
✓ Branch 1 taken 176255 times.
457733 if ((ist->par->codec_type == AVMEDIA_TYPE_VIDEO ||
290
2/2
✓ Branch 0 taken 278770 times.
✓ Branch 1 taken 2708 times.
281478 ist->par->codec_type == AVMEDIA_TYPE_AUDIO) &&
291
2/2
✓ Branch 0 taken 410955 times.
✓ Branch 1 taken 44070 times.
455025 pkt->dts != AV_NOPTS_VALUE)
292 410955 ts_discontinuity_detect(d, ist, pkt);
293 457733 }
294
295 457733 static int ist_dts_update(DemuxStream *ds, AVPacket *pkt, FrameData *fd)
296 {
297 457733 InputStream *ist = &ds->ist;
298 457733 const AVCodecParameters *par = ist->par;
299
300
2/2
✓ Branch 0 taken 6989 times.
✓ Branch 1 taken 450744 times.
457733 if (!ds->saw_first_ts) {
301 6989 ds->first_dts =
302
2/2
✓ Branch 0 taken 4774 times.
✓ Branch 1 taken 2215 times.
6989 ds->dts = ist->st->avg_frame_rate.num ? - ist->par->video_delay * AV_TIME_BASE / av_q2d(ist->st->avg_frame_rate) : 0;
303
2/2
✓ Branch 0 taken 6409 times.
✓ Branch 1 taken 580 times.
6989 if (pkt->pts != AV_NOPTS_VALUE) {
304 6409 ds->first_dts =
305 6409 ds->dts += av_rescale_q(pkt->pts, pkt->time_base, AV_TIME_BASE_Q);
306 }
307 6989 ds->saw_first_ts = 1;
308 }
309
310
2/2
✓ Branch 0 taken 6989 times.
✓ Branch 1 taken 450744 times.
457733 if (ds->next_dts == AV_NOPTS_VALUE)
311 6989 ds->next_dts = ds->dts;
312
313
2/2
✓ Branch 0 taken 413659 times.
✓ Branch 1 taken 44074 times.
457733 if (pkt->dts != AV_NOPTS_VALUE)
314 413659 ds->next_dts = ds->dts = av_rescale_q(pkt->dts, pkt->time_base, AV_TIME_BASE_Q);
315
316 457733 ds->dts = ds->next_dts;
317
3/3
✓ Branch 0 taken 278770 times.
✓ Branch 1 taken 176255 times.
✓ Branch 2 taken 2708 times.
457733 switch (par->codec_type) {
318 278770 case AVMEDIA_TYPE_AUDIO:
319 av_assert1(pkt->duration >= 0);
320
1/2
✓ Branch 0 taken 278770 times.
✗ Branch 1 not taken.
278770 if (par->sample_rate) {
321 278770 ds->next_dts += ((int64_t)AV_TIME_BASE * par->frame_size) /
322 278770 par->sample_rate;
323 } else {
324 ds->next_dts += av_rescale_q(pkt->duration, pkt->time_base, AV_TIME_BASE_Q);
325 }
326 278770 break;
327 176255 case AVMEDIA_TYPE_VIDEO:
328
2/2
✓ Branch 0 taken 597 times.
✓ Branch 1 taken 175658 times.
176255 if (ist->framerate.num) {
329 // TODO: Remove work-around for c99-to-c89 issue 7
330 597 AVRational time_base_q = AV_TIME_BASE_Q;
331 597 int64_t next_dts = av_rescale_q(ds->next_dts, time_base_q, av_inv_q(ist->framerate));
332 597 ds->next_dts = av_rescale_q(next_dts + 1, av_inv_q(ist->framerate), time_base_q);
333
2/2
✓ Branch 0 taken 173520 times.
✓ Branch 1 taken 2138 times.
175658 } else if (pkt->duration) {
334 173520 ds->next_dts += av_rescale_q(pkt->duration, pkt->time_base, AV_TIME_BASE_Q);
335
2/2
✓ Branch 0 taken 70 times.
✓ Branch 1 taken 2068 times.
2138 } else if (ist->par->framerate.num != 0) {
336 70 AVRational field_rate = av_mul_q(ist->par->framerate,
337 70 (AVRational){ 2, 1 });
338 70 int fields = 2;
339
340
1/2
✓ Branch 0 taken 70 times.
✗ Branch 1 not taken.
70 if (ds->codec_desc &&
341
4/4
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 46 times.
✓ Branch 2 taken 14 times.
✓ Branch 3 taken 10 times.
94 (ds->codec_desc->props & AV_CODEC_PROP_FIELDS) &&
342 24 av_stream_get_parser(ist->st))
343 14 fields = 1 + av_stream_get_parser(ist->st)->repeat_pict;
344
345 70 ds->next_dts += av_rescale_q(fields, av_inv_q(field_rate), AV_TIME_BASE_Q);
346 }
347 176255 break;
348 }
349
350 457733 fd->dts_est = ds->dts;
351
352 457733 return 0;
353 }
354
355 457733 static int ts_fixup(Demuxer *d, AVPacket *pkt, FrameData *fd)
356 {
357 457733 InputFile *ifile = &d->f;
358 457733 InputStream *ist = ifile->streams[pkt->stream_index];
359 457733 DemuxStream *ds = ds_from_ist(ist);
360 457733 const int64_t start_time = ifile->start_time_effective;
361 int64_t duration;
362 int ret;
363
364 457733 pkt->time_base = ist->st->time_base;
365
366 #define SHOW_TS_DEBUG(tag_) \
367 if (debug_ts) { \
368 av_log(ist, AV_LOG_INFO, "%s -> ist_index:%d:%d type:%s " \
369 "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s duration:%s duration_time:%s\n", \
370 tag_, ifile->index, pkt->stream_index, \
371 av_get_media_type_string(ist->st->codecpar->codec_type), \
372 av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &pkt->time_base), \
373 av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &pkt->time_base), \
374 av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &pkt->time_base)); \
375 }
376
377
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 457733 times.
457733 SHOW_TS_DEBUG("demuxer");
378
379
4/4
✓ Branch 0 taken 410193 times.
✓ Branch 1 taken 47540 times.
✓ Branch 2 taken 314724 times.
✓ Branch 3 taken 95469 times.
457733 if (!ds->wrap_correction_done && start_time != AV_NOPTS_VALUE &&
380
2/2
✓ Branch 0 taken 346 times.
✓ Branch 1 taken 314378 times.
314724 ist->st->pts_wrap_bits < 64) {
381 int64_t stime, stime2;
382
383 346 stime = av_rescale_q(start_time, AV_TIME_BASE_Q, pkt->time_base);
384 346 stime2= stime + (1ULL<<ist->st->pts_wrap_bits);
385 346 ds->wrap_correction_done = 1;
386
387
5/6
✓ Branch 0 taken 316 times.
✓ Branch 1 taken 30 times.
✓ Branch 2 taken 282 times.
✓ Branch 3 taken 34 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 282 times.
346 if(stime2 > stime && pkt->dts != AV_NOPTS_VALUE && pkt->dts > stime + (1LL<<(ist->st->pts_wrap_bits-1))) {
388 pkt->dts -= 1ULL<<ist->st->pts_wrap_bits;
389 ds->wrap_correction_done = 0;
390 }
391
5/6
✓ Branch 0 taken 316 times.
✓ Branch 1 taken 30 times.
✓ Branch 2 taken 276 times.
✓ Branch 3 taken 40 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 276 times.
346 if(stime2 > stime && pkt->pts != AV_NOPTS_VALUE && pkt->pts > stime + (1LL<<(ist->st->pts_wrap_bits-1))) {
392 pkt->pts -= 1ULL<<ist->st->pts_wrap_bits;
393 ds->wrap_correction_done = 0;
394 }
395 }
396
397
2/2
✓ Branch 0 taken 413659 times.
✓ Branch 1 taken 44074 times.
457733 if (pkt->dts != AV_NOPTS_VALUE)
398 413659 pkt->dts += av_rescale_q(ifile->ts_offset, AV_TIME_BASE_Q, pkt->time_base);
399
2/2
✓ Branch 0 taken 411557 times.
✓ Branch 1 taken 46176 times.
457733 if (pkt->pts != AV_NOPTS_VALUE)
400 411557 pkt->pts += av_rescale_q(ifile->ts_offset, AV_TIME_BASE_Q, pkt->time_base);
401
402
2/2
✓ Branch 0 taken 411557 times.
✓ Branch 1 taken 46176 times.
457733 if (pkt->pts != AV_NOPTS_VALUE)
403 411557 pkt->pts *= ds->ts_scale;
404
2/2
✓ Branch 0 taken 413659 times.
✓ Branch 1 taken 44074 times.
457733 if (pkt->dts != AV_NOPTS_VALUE)
405 413659 pkt->dts *= ds->ts_scale;
406
407 457733 duration = av_rescale_q(d->duration.ts, d->duration.tb, pkt->time_base);
408
2/2
✓ Branch 0 taken 411557 times.
✓ Branch 1 taken 46176 times.
457733 if (pkt->pts != AV_NOPTS_VALUE) {
409 // audio decoders take precedence for estimating total file duration
410
2/2
✓ Branch 0 taken 181093 times.
✓ Branch 1 taken 230464 times.
411557 int64_t pkt_duration = d->have_audio_dec ? 0 : pkt->duration;
411
412 411557 pkt->pts += duration;
413
414 // update max/min pts that will be used to compute total file duration
415 // when using -stream_loop
416
4/4
✓ Branch 0 taken 405295 times.
✓ Branch 1 taken 6262 times.
✓ Branch 2 taken 393255 times.
✓ Branch 3 taken 12040 times.
816852 if (d->max_pts.ts == AV_NOPTS_VALUE ||
417 405295 av_compare_ts(d->max_pts.ts, d->max_pts.tb,
418 405295 pkt->pts + pkt_duration, pkt->time_base) < 0) {
419 399517 d->max_pts = (Timestamp){ .ts = pkt->pts + pkt_duration,
420 399517 .tb = pkt->time_base };
421 }
422
4/4
✓ Branch 0 taken 405295 times.
✓ Branch 1 taken 6262 times.
✓ Branch 2 taken 23 times.
✓ Branch 3 taken 405272 times.
816852 if (d->min_pts.ts == AV_NOPTS_VALUE ||
423 405295 av_compare_ts(d->min_pts.ts, d->min_pts.tb,
424 pkt->pts, pkt->time_base) > 0) {
425 6285 d->min_pts = (Timestamp){ .ts = pkt->pts,
426 6285 .tb = pkt->time_base };
427 }
428 }
429
430
2/2
✓ Branch 0 taken 413659 times.
✓ Branch 1 taken 44074 times.
457733 if (pkt->dts != AV_NOPTS_VALUE)
431 413659 pkt->dts += duration;
432
433
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 457733 times.
457733 SHOW_TS_DEBUG("demuxer+tsfixup");
434
435 // detect and try to correct for timestamp discontinuities
436 457733 ts_discontinuity_process(d, ist, pkt);
437
438 // update estimated/predicted dts
439 457733 ret = ist_dts_update(ds, pkt, fd);
440
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 457733 times.
457733 if (ret < 0)
441 return ret;
442
443 457733 return 0;
444 }
445
446 457733 static int input_packet_process(Demuxer *d, AVPacket *pkt, unsigned *send_flags)
447 {
448 457733 InputFile *f = &d->f;
449 457733 InputStream *ist = f->streams[pkt->stream_index];
450 457733 DemuxStream *ds = ds_from_ist(ist);
451 FrameData *fd;
452 457733 int ret = 0;
453
454 457733 fd = packet_data(pkt);
455
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 457733 times.
457733 if (!fd)
456 return AVERROR(ENOMEM);
457
458 457733 ret = ts_fixup(d, pkt, fd);
459
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 457733 times.
457733 if (ret < 0)
460 return ret;
461
462
2/2
✓ Branch 0 taken 227 times.
✓ Branch 1 taken 457506 times.
457733 if (d->recording_time != INT64_MAX) {
463 227 int64_t start_time = 0;
464
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 153 times.
227 if (copy_ts) {
465
1/2
✓ Branch 0 taken 74 times.
✗ Branch 1 not taken.
74 start_time += f->start_time != AV_NOPTS_VALUE ? f->start_time : 0;
466
1/2
✓ Branch 0 taken 74 times.
✗ Branch 1 not taken.
74 start_time += start_at_zero ? 0 : f->start_time_effective;
467 }
468
2/2
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 196 times.
227 if (ds->dts >= d->recording_time + start_time)
469 31 *send_flags |= DEMUX_SEND_STREAMCOPY_EOF;
470 }
471
472 457733 ds->data_size += pkt->size;
473 457733 ds->nb_packets++;
474
475 457733 fd->wallclock[LATENCY_PROBE_DEMUX] = av_gettime_relative();
476
477
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 457733 times.
457733 if (debug_ts) {
478 av_log(NULL, AV_LOG_INFO, "demuxer+ffmpeg -> ist_index:%d:%d type:%s pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s duration:%s duration_time:%s off:%s off_time:%s\n",
479 f->index, pkt->stream_index,
480 av_get_media_type_string(ist->par->codec_type),
481 av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &pkt->time_base),
482 av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &pkt->time_base),
483 av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &pkt->time_base),
484 av_ts2str(f->ts_offset), av_ts2timestr(f->ts_offset, &AV_TIME_BASE_Q));
485 }
486
487 457733 return 0;
488 }
489
490 216 static void readrate_sleep(Demuxer *d)
491 {
492 216 InputFile *f = &d->f;
493 432 int64_t file_start = copy_ts * (
494
1/2
✓ Branch 0 taken 216 times.
✗ Branch 1 not taken.
216 (f->start_time_effective != AV_NOPTS_VALUE ? f->start_time_effective * !start_at_zero : 0) +
495
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 216 times.
216 (f->start_time != AV_NOPTS_VALUE ? f->start_time : 0)
496 );
497 216 int64_t burst_until = AV_TIME_BASE * d->readrate_initial_burst;
498
2/2
✓ Branch 0 taken 216 times.
✓ Branch 1 taken 216 times.
432 for (int i = 0; i < f->nb_streams; i++) {
499 216 InputStream *ist = f->streams[i];
500 216 DemuxStream *ds = ds_from_ist(ist);
501 int64_t stream_ts_offset, pts, now;
502
1/2
✓ Branch 0 taken 216 times.
✗ Branch 1 not taken.
216 stream_ts_offset = FFMAX(ds->first_dts != AV_NOPTS_VALUE ? ds->first_dts : 0, file_start);
503 216 pts = av_rescale(ds->dts, 1000000, AV_TIME_BASE);
504 216 now = (av_gettime_relative() - d->wallclock_start) * d->readrate + stream_ts_offset;
505
2/2
✓ Branch 0 taken 191 times.
✓ Branch 1 taken 25 times.
216 if (pts - burst_until > now)
506 191 av_usleep(pts - burst_until - now);
507 }
508 216 }
509
510 458681 static int do_send(Demuxer *d, DemuxStream *ds, AVPacket *pkt, unsigned flags,
511 const char *pkt_desc)
512 {
513 int ret;
514
515 458681 pkt->stream_index = ds->sch_idx_stream;
516
517 458681 ret = sch_demux_send(d->sch, d->f.index, pkt, flags);
518
2/2
✓ Branch 0 taken 3123 times.
✓ Branch 1 taken 455558 times.
458681 if (ret == AVERROR_EOF) {
519 3123 av_packet_unref(pkt);
520
521 3123 av_log(ds, AV_LOG_VERBOSE, "All consumers of this stream are done\n");
522 3123 ds->finished = 1;
523
524
2/2
✓ Branch 0 taken 3092 times.
✓ Branch 1 taken 31 times.
3123 if (++d->nb_streams_finished == d->nb_streams_used) {
525 3092 av_log(d, AV_LOG_VERBOSE, "All consumers are done\n");
526 3092 return AVERROR_EOF;
527 }
528
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 455504 times.
455558 } else if (ret < 0) {
529
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 54 times.
54 if (ret != AVERROR_EXIT)
530 av_log(d, AV_LOG_ERROR,
531 "Unable to send %s packet to consumers: %s\n",
532 pkt_desc, av_err2str(ret));
533 54 return ret;
534 }
535
536 455535 return 0;
537 }
538
539 457736 static int demux_send(Demuxer *d, DemuxThreadContext *dt, DemuxStream *ds,
540 AVPacket *pkt, unsigned flags)
541 {
542 457736 InputFile *f = &d->f;
543 int ret;
544
545 // pkt can be NULL only when flushing BSFs
546
3/4
✓ Branch 0 taken 457721 times.
✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 457721 times.
457736 av_assert0(ds->bsf || pkt);
547
548 // send heartbeat for sub2video streams
549
4/6
✓ Branch 0 taken 948 times.
✓ Branch 1 taken 456788 times.
✓ Branch 2 taken 948 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 948 times.
✗ Branch 5 not taken.
457736 if (d->pkt_heartbeat && pkt && pkt->pts != AV_NOPTS_VALUE) {
550
2/2
✓ Branch 0 taken 4332 times.
✓ Branch 1 taken 948 times.
5280 for (int i = 0; i < f->nb_streams; i++) {
551 4332 DemuxStream *ds1 = ds_from_ist(f->streams[i]);
552
553
3/4
✓ Branch 0 taken 4332 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3384 times.
✓ Branch 3 taken 948 times.
4332 if (ds1->finished || !ds1->have_sub2video)
554 3384 continue;
555
556 948 d->pkt_heartbeat->pts = pkt->pts;
557 948 d->pkt_heartbeat->time_base = pkt->time_base;
558 948 d->pkt_heartbeat->opaque = (void*)(intptr_t)PKT_OPAQUE_SUB_HEARTBEAT;
559
560 948 ret = do_send(d, ds1, d->pkt_heartbeat, 0, "heartbeat");
561
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 948 times.
948 if (ret < 0)
562 return ret;
563 }
564 }
565
566
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 457721 times.
457736 if (ds->bsf) {
567
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 3 times.
15 if (pkt)
568 12 av_packet_rescale_ts(pkt, pkt->time_base, ds->bsf->time_base_in);
569
570 15 ret = av_bsf_send_packet(ds->bsf, pkt);
571
1/2
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
15 if (ret < 0) {
572 if (pkt)
573 av_packet_unref(pkt);
574 av_log(ds, AV_LOG_ERROR, "Error submitting a packet for filtering: %s\n",
575 av_err2str(ret));
576 return ret;
577 }
578
579 while (1) {
580 27 ret = av_bsf_receive_packet(ds->bsf, dt->pkt_bsf);
581
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 15 times.
27 if (ret == AVERROR(EAGAIN))
582 12 return 0;
583
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 12 times.
15 else if (ret < 0) {
584
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (ret != AVERROR_EOF)
585 av_log(ds, AV_LOG_ERROR,
586 "Error applying bitstream filters to a packet: %s\n",
587 av_err2str(ret));
588 3 return ret;
589 }
590
591 12 dt->pkt_bsf->time_base = ds->bsf->time_base_out;
592
593 12 ret = do_send(d, ds, dt->pkt_bsf, 0, "filtered");
594
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if (ret < 0) {
595 av_packet_unref(dt->pkt_bsf);
596 return ret;
597 }
598 }
599 } else {
600 457721 ret = do_send(d, ds, pkt, flags, "demuxed");
601
2/2
✓ Branch 0 taken 3146 times.
✓ Branch 1 taken 454575 times.
457721 if (ret < 0)
602 3146 return ret;
603 }
604
605 454575 return 0;
606 }
607
608 3645 static int demux_bsf_flush(Demuxer *d, DemuxThreadContext *dt)
609 {
610 3645 InputFile *f = &d->f;
611 int ret;
612
613
2/2
✓ Branch 0 taken 4098 times.
✓ Branch 1 taken 3645 times.
7743 for (unsigned i = 0; i < f->nb_streams; i++) {
614 4098 DemuxStream *ds = ds_from_ist(f->streams[i]);
615
616
2/2
✓ Branch 0 taken 4095 times.
✓ Branch 1 taken 3 times.
4098 if (!ds->bsf)
617 4095 continue;
618
619 3 ret = demux_send(d, dt, ds, NULL, 0);
620
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3 ret = (ret == AVERROR_EOF) ? 0 : (ret < 0) ? ret : AVERROR_BUG;
621
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (ret < 0) {
622 av_log(ds, AV_LOG_ERROR, "Error flushing BSFs: %s\n",
623 av_err2str(ret));
624 return ret;
625 }
626
627 3 av_bsf_flush(ds->bsf);
628 }
629
630 3645 return 0;
631 }
632
633 6780 static void discard_unused_programs(InputFile *ifile)
634 {
635
2/2
✓ Branch 0 taken 41 times.
✓ Branch 1 taken 6780 times.
6821 for (int j = 0; j < ifile->ctx->nb_programs; j++) {
636 41 AVProgram *p = ifile->ctx->programs[j];
637 41 int discard = AVDISCARD_ALL;
638
639
1/2
✓ Branch 0 taken 49 times.
✗ Branch 1 not taken.
49 for (int k = 0; k < p->nb_stream_indexes; k++) {
640 49 DemuxStream *ds = ds_from_ist(ifile->streams[p->stream_index[k]]);
641
642
2/2
✓ Branch 0 taken 41 times.
✓ Branch 1 taken 8 times.
49 if (!ds->discard) {
643 41 discard = AVDISCARD_DEFAULT;
644 41 break;
645 }
646 }
647 41 p->discard = discard;
648 }
649 6780 }
650
651 6780 static void thread_set_name(InputFile *f)
652 {
653 char name[16];
654 6780 snprintf(name, sizeof(name), "dmx%d:%s", f->index, f->ctx->iformat->name);
655 6780 ff_thread_setname(name);
656 6780 }
657
658 6780 static void demux_thread_uninit(DemuxThreadContext *dt)
659 {
660 6780 av_packet_free(&dt->pkt_demux);
661 6780 av_packet_free(&dt->pkt_bsf);
662
663 6780 memset(dt, 0, sizeof(*dt));
664 6780 }
665
666 6780 static int demux_thread_init(DemuxThreadContext *dt)
667 {
668 6780 memset(dt, 0, sizeof(*dt));
669
670 6780 dt->pkt_demux = av_packet_alloc();
671
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6780 times.
6780 if (!dt->pkt_demux)
672 return AVERROR(ENOMEM);
673
674 6780 dt->pkt_bsf = av_packet_alloc();
675
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6780 times.
6780 if (!dt->pkt_bsf)
676 return AVERROR(ENOMEM);
677
678 6780 return 0;
679 }
680
681 6780 static int input_thread(void *arg)
682 {
683 6780 Demuxer *d = arg;
684 6780 InputFile *f = &d->f;
685
686 DemuxThreadContext dt;
687
688 6780 int ret = 0;
689
690 6780 ret = demux_thread_init(&dt);
691
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6780 times.
6780 if (ret < 0)
692 goto finish;
693
694 6780 thread_set_name(f);
695
696 6780 discard_unused_programs(f);
697
698 6780 d->read_started = 1;
699 6780 d->wallclock_start = av_gettime_relative();
700
701 464346 while (1) {
702 DemuxStream *ds;
703 471126 unsigned send_flags = 0;
704
705 471126 ret = av_read_frame(f->ctx, dt.pkt_demux);
706
707
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 471125 times.
471126 if (ret == AVERROR(EAGAIN)) {
708 1 av_usleep(10000);
709 9759 continue;
710 }
711
2/2
✓ Branch 0 taken 3645 times.
✓ Branch 1 taken 467480 times.
471125 if (ret < 0) {
712 int ret_bsf;
713
714
2/2
✓ Branch 0 taken 3589 times.
✓ Branch 1 taken 56 times.
3645 if (ret == AVERROR_EOF)
715 3589 av_log(d, AV_LOG_VERBOSE, "EOF while reading input\n");
716 else {
717 56 av_log(d, AV_LOG_ERROR, "Error during demuxing: %s\n",
718 56 av_err2str(ret));
719
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
56 ret = exit_on_error ? ret : 0;
720 }
721
722 3645 ret_bsf = demux_bsf_flush(d, &dt);
723
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 3589 times.
3645 ret = err_merge(ret == AVERROR_EOF ? 0 : ret, ret_bsf);
724
725
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 3634 times.
3645 if (d->loop) {
726 /* signal looping to our consumers */
727 11 dt.pkt_demux->stream_index = -1;
728 11 ret = sch_demux_send(d->sch, f->index, dt.pkt_demux, 0);
729
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (ret >= 0)
730 11 ret = seek_to_start(d, (Timestamp){ .ts = dt.pkt_demux->pts,
731 11 .tb = dt.pkt_demux->time_base });
732
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (ret >= 0)
733 11 continue;
734
735 /* fallthrough to the error path */
736 }
737
738 3634 break;
739 }
740
741
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 467480 times.
467480 if (do_pkt_dump) {
742 av_pkt_dump_log2(NULL, AV_LOG_INFO, dt.pkt_demux, do_hex_dump,
743 f->ctx->streams[dt.pkt_demux->stream_index]);
744 }
745
746 /* the following test is needed in case new streams appear
747 dynamically in stream : we ignore them */
748 934960 ds = dt.pkt_demux->stream_index < f->nb_streams ?
749
1/2
✓ Branch 0 taken 467480 times.
✗ Branch 1 not taken.
467480 ds_from_ist(f->streams[dt.pkt_demux->stream_index]) : NULL;
750
5/6
✓ Branch 0 taken 467480 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 459356 times.
✓ Branch 3 taken 8124 times.
✓ Branch 4 taken 1623 times.
✓ Branch 5 taken 457733 times.
467480 if (!ds || ds->discard || ds->finished) {
751 9747 report_new_stream(d, dt.pkt_demux);
752 9747 av_packet_unref(dt.pkt_demux);
753 9747 continue;
754 }
755
756
2/2
✓ Branch 0 taken 98 times.
✓ Branch 1 taken 457635 times.
457733 if (dt.pkt_demux->flags & AV_PKT_FLAG_CORRUPT) {
757 98 av_log(d, exit_on_error ? AV_LOG_FATAL : AV_LOG_WARNING,
758 "corrupt input packet in stream %d\n",
759
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 98 times.
98 dt.pkt_demux->stream_index);
760
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 98 times.
98 if (exit_on_error) {
761 av_packet_unref(dt.pkt_demux);
762 ret = AVERROR_INVALIDDATA;
763 break;
764 }
765 }
766
767 457733 ret = input_packet_process(d, dt.pkt_demux, &send_flags);
768
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 457733 times.
457733 if (ret < 0)
769 break;
770
771
2/2
✓ Branch 0 taken 216 times.
✓ Branch 1 taken 457517 times.
457733 if (d->readrate)
772 216 readrate_sleep(d);
773
774 457733 ret = demux_send(d, &dt, ds, dt.pkt_demux, send_flags);
775
2/2
✓ Branch 0 taken 3146 times.
✓ Branch 1 taken 454587 times.
457733 if (ret < 0)
776 3146 break;
777 }
778
779 // EOF/EXIT is normal termination
780
4/4
✓ Branch 0 taken 3688 times.
✓ Branch 1 taken 3092 times.
✓ Branch 2 taken 3634 times.
✓ Branch 3 taken 54 times.
6780 if (ret == AVERROR_EOF || ret == AVERROR_EXIT)
781 3146 ret = 0;
782
783 3634 finish:
784 6780 demux_thread_uninit(&dt);
785
786 6780 return ret;
787 }
788
789 6780 static void demux_final_stats(Demuxer *d)
790 {
791 6780 InputFile *f = &d->f;
792 6780 uint64_t total_packets = 0, total_size = 0;
793
794 6780 av_log(f, AV_LOG_VERBOSE, "Input file #%d (%s):\n",
795 6780 f->index, f->ctx->url);
796
797
2/2
✓ Branch 0 taken 7290 times.
✓ Branch 1 taken 6780 times.
14070 for (int j = 0; j < f->nb_streams; j++) {
798 7290 InputStream *ist = f->streams[j];
799 7290 DemuxStream *ds = ds_from_ist(ist);
800 7290 enum AVMediaType type = ist->par->codec_type;
801
802
3/4
✓ Branch 0 taken 7010 times.
✓ Branch 1 taken 280 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 7010 times.
7290 if (ds->discard || type == AVMEDIA_TYPE_ATTACHMENT)
803 280 continue;
804
805 7010 total_size += ds->data_size;
806 7010 total_packets += ds->nb_packets;
807
808 7010 av_log(f, AV_LOG_VERBOSE, " Input stream #%d:%d (%s): ",
809 f->index, j, av_get_media_type_string(type));
810 7010 av_log(f, AV_LOG_VERBOSE, "%"PRIu64" packets read (%"PRIu64" bytes); ",
811 ds->nb_packets, ds->data_size);
812
813
2/2
✓ Branch 0 taken 6392 times.
✓ Branch 1 taken 618 times.
7010 if (ds->decoding_needed) {
814 6392 av_log(f, AV_LOG_VERBOSE,
815 "%"PRIu64" frames decoded; %"PRIu64" decode errors",
816 6392 ist->decoder->frames_decoded, ist->decoder->decode_errors);
817
2/2
✓ Branch 0 taken 1202 times.
✓ Branch 1 taken 5190 times.
6392 if (type == AVMEDIA_TYPE_AUDIO)
818 1202 av_log(f, AV_LOG_VERBOSE, " (%"PRIu64" samples)", ist->decoder->samples_decoded);
819 6392 av_log(f, AV_LOG_VERBOSE, "; ");
820 }
821
822 7010 av_log(f, AV_LOG_VERBOSE, "\n");
823 }
824
825 6780 av_log(f, AV_LOG_VERBOSE, " Total: %"PRIu64" packets (%"PRIu64" bytes) demuxed\n",
826 total_packets, total_size);
827 6780 }
828
829 7305 static void ist_free(InputStream **pist)
830 {
831 7305 InputStream *ist = *pist;
832 DemuxStream *ds;
833
834
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7305 times.
7305 if (!ist)
835 return;
836 7305 ds = ds_from_ist(ist);
837
838 7305 dec_free(&ist->decoder);
839
840 7305 av_dict_free(&ds->decoder_opts);
841 7305 av_freep(&ist->filters);
842 7305 av_freep(&ist->outputs);
843 7305 av_freep(&ds->dec_opts.hwaccel_device);
844
845 7305 avcodec_parameters_free(&ist->par);
846
847 7305 av_frame_free(&ds->decoded_params);
848
849 7305 av_bsf_free(&ds->bsf);
850
851 7305 av_freep(pist);
852 }
853
854 6794 void ifile_close(InputFile **pf)
855 {
856 6794 InputFile *f = *pf;
857 6794 Demuxer *d = demuxer_from_ifile(f);
858
859
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6794 times.
6794 if (!f)
860 return;
861
862
2/2
✓ Branch 0 taken 6780 times.
✓ Branch 1 taken 14 times.
6794 if (d->read_started)
863 6780 demux_final_stats(d);
864
865
2/2
✓ Branch 0 taken 7305 times.
✓ Branch 1 taken 6794 times.
14099 for (int i = 0; i < f->nb_streams; i++)
866 7305 ist_free(&f->streams[i]);
867 6794 av_freep(&f->streams);
868
869 6794 avformat_close_input(&f->ctx);
870
871 6794 av_packet_free(&d->pkt_heartbeat);
872
873 6794 av_freep(pf);
874 }
875
876 7079 static int ist_use(InputStream *ist, int decoding_needed)
877 {
878 7079 Demuxer *d = demuxer_from_ifile(ist->file);
879 7079 DemuxStream *ds = ds_from_ist(ist);
880 int ret;
881
882
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7079 times.
7079 if (ist->user_set_discard == AVDISCARD_ALL) {
883 av_log(ist, AV_LOG_ERROR, "Cannot %s a disabled input stream\n",
884 decoding_needed ? "decode" : "streamcopy");
885 return AVERROR(EINVAL);
886 }
887
888
3/4
✓ Branch 0 taken 6438 times.
✓ Branch 1 taken 641 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6438 times.
7079 if (decoding_needed && !ist->dec) {
889 av_log(ist, AV_LOG_ERROR,
890 "Decoding requested, but no decoder found for: %s\n",
891 avcodec_get_name(ist->par->codec_id));
892 return AVERROR(EINVAL);
893 }
894
895
2/2
✓ Branch 0 taken 7010 times.
✓ Branch 1 taken 69 times.
7079 if (ds->sch_idx_stream < 0) {
896 7010 ret = sch_add_demux_stream(d->sch, d->f.index);
897
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7010 times.
7010 if (ret < 0)
898 return ret;
899 7010 ds->sch_idx_stream = ret;
900 }
901
902
2/2
✓ Branch 0 taken 7010 times.
✓ Branch 1 taken 69 times.
7079 if (ds->discard) {
903 7010 ds->discard = 0;
904 7010 d->nb_streams_used++;
905 }
906
907 7079 ist->st->discard = ist->user_set_discard;
908 7079 ds->decoding_needed |= decoding_needed;
909 7079 ds->streamcopy_needed |= !decoding_needed;
910
911
4/4
✓ Branch 0 taken 6438 times.
✓ Branch 1 taken 641 times.
✓ Branch 2 taken 6392 times.
✓ Branch 3 taken 46 times.
7079 if (decoding_needed && ds->sch_idx_dec < 0) {
912 6392 int is_audio = ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO;
913
914 12784 ds->dec_opts.flags |= (!!ist->fix_sub_duration * DECODER_FLAG_FIX_SUB_DURATION) |
915 12784 (!!(d->f.ctx->iformat->flags & AVFMT_NOTIMESTAMPS) * DECODER_FLAG_TS_UNRELIABLE) |
916
4/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6390 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
6392 (!!(d->loop && is_audio) * DECODER_FLAG_SEND_END_TS)
917 #if FFMPEG_OPT_TOP
918
2/2
✓ Branch 0 taken 1242 times.
✓ Branch 1 taken 5150 times.
6392 | ((ist->top_field_first >= 0) * DECODER_FLAG_TOP_FIELD_FIRST)
919 #endif
920 ;
921
922
2/2
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 6367 times.
6392 if (ist->framerate.num) {
923 25 ds->dec_opts.flags |= DECODER_FLAG_FRAMERATE_FORCED;
924 25 ds->dec_opts.framerate = ist->framerate;
925 } else
926 6367 ds->dec_opts.framerate = ist->st->avg_frame_rate;
927
928
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6391 times.
6392 if (ist->dec->id == AV_CODEC_ID_DVB_SUBTITLE &&
929
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 (ds->decoding_needed & DECODING_FOR_OST)) {
930 1 av_dict_set(&ds->decoder_opts, "compute_edt", "1", AV_DICT_DONT_OVERWRITE);
931
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ds->decoding_needed & DECODING_FOR_FILTER)
932 av_log(ist, AV_LOG_WARNING,
933 "Warning using DVB subtitles for filtering and output at the "
934 "same time is not fully supported, also see -compute_edt [0|1]\n");
935 }
936
937 6392 snprintf(ds->dec_name, sizeof(ds->dec_name), "%d:%d", ist->file->index, ist->index);
938 6392 ds->dec_opts.name = ds->dec_name;
939
940 6392 ds->dec_opts.codec = ist->dec;
941 6392 ds->dec_opts.par = ist->par;
942
943 6392 ds->dec_opts.log_parent = ist;
944
945 6392 ds->decoded_params = av_frame_alloc();
946
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6392 times.
6392 if (!ds->decoded_params)
947 return AVERROR(ENOMEM);
948
949 6392 ret = dec_init(&ist->decoder, d->sch,
950 6392 &ds->decoder_opts, &ds->dec_opts, ds->decoded_params);
951
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6392 times.
6392 if (ret < 0)
952 return ret;
953 6392 ds->sch_idx_dec = ret;
954
955 6392 ret = sch_connect(d->sch, SCH_DSTREAM(d->f.index, ds->sch_idx_stream),
956 6392 SCH_DEC(ds->sch_idx_dec));
957
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6392 times.
6392 if (ret < 0)
958 return ret;
959
960 6392 d->have_audio_dec |= is_audio;
961 }
962
963 7079 return 0;
964 }
965
966 679 int ist_output_add(InputStream *ist, OutputStream *ost)
967 {
968 679 DemuxStream *ds = ds_from_ist(ist);
969 int ret;
970
971 679 ret = ist_use(ist, ost->enc ? DECODING_FOR_OST : 0);
972
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 679 times.
679 if (ret < 0)
973 return ret;
974
975 679 ret = GROW_ARRAY(ist->outputs, ist->nb_outputs);
976
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 679 times.
679 if (ret < 0)
977 return ret;
978
979 679 ist->outputs[ist->nb_outputs - 1] = ost;
980
981
2/2
✓ Branch 0 taken 38 times.
✓ Branch 1 taken 641 times.
679 return ost->enc ? ds->sch_idx_dec : ds->sch_idx_stream;
982 }
983
984 6400 int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple,
985 InputFilterOptions *opts)
986 {
987 6400 Demuxer *d = demuxer_from_ifile(ist->file);
988 6400 DemuxStream *ds = ds_from_ist(ist);
989 6400 int64_t tsoffset = 0;
990 int ret;
991
992
2/2
✓ Branch 0 taken 6269 times.
✓ Branch 1 taken 131 times.
6400 ret = ist_use(ist, is_simple ? DECODING_FOR_OST : DECODING_FOR_FILTER);
993
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6400 times.
6400 if (ret < 0)
994 return ret;
995
996 6400 ret = GROW_ARRAY(ist->filters, ist->nb_filters);
997
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6400 times.
6400 if (ret < 0)
998 return ret;
999
1000 6400 ist->filters[ist->nb_filters - 1] = ifilter;
1001
1002
2/2
✓ Branch 0 taken 5154 times.
✓ Branch 1 taken 1246 times.
6400 if (ist->par->codec_type == AVMEDIA_TYPE_VIDEO) {
1003
3/4
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 5129 times.
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
5154 if (ist->framerate.num > 0 && ist->framerate.den > 0) {
1004 25 opts->framerate = ist->framerate;
1005 25 opts->flags |= IFILTER_FLAG_CFR;
1006 } else
1007 5129 opts->framerate = av_guess_frame_rate(d->f.ctx, ist->st, NULL);
1008
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1242 times.
1246 } else if (ist->par->codec_type == AVMEDIA_TYPE_SUBTITLE) {
1009 /* Compute the size of the canvas for the subtitles stream.
1010 If the subtitles codecpar has set a size, use it. Otherwise use the
1011 maximum dimensions of the video streams in the same file. */
1012 4 opts->sub2video_width = ist->par->width;
1013 4 opts->sub2video_height = ist->par->height;
1014
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
4 if (!(opts->sub2video_width && opts->sub2video_height)) {
1015 for (int j = 0; j < d->f.nb_streams; j++) {
1016 AVCodecParameters *par1 = d->f.streams[j]->par;
1017 if (par1->codec_type == AVMEDIA_TYPE_VIDEO) {
1018 opts->sub2video_width = FFMAX(opts->sub2video_width, par1->width);
1019 opts->sub2video_height = FFMAX(opts->sub2video_height, par1->height);
1020 }
1021 }
1022 }
1023
1024
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
4 if (!(opts->sub2video_width && opts->sub2video_height)) {
1025 opts->sub2video_width = FFMAX(opts->sub2video_width, 720);
1026 opts->sub2video_height = FFMAX(opts->sub2video_height, 576);
1027 }
1028
1029
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (!d->pkt_heartbeat) {
1030 4 d->pkt_heartbeat = av_packet_alloc();
1031
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (!d->pkt_heartbeat)
1032 return AVERROR(ENOMEM);
1033 }
1034 4 ds->have_sub2video = 1;
1035 }
1036
1037 6400 ret = av_frame_copy_props(opts->fallback, ds->decoded_params);
1038
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6400 times.
6400 if (ret < 0)
1039 return ret;
1040 6400 opts->fallback->format = ds->decoded_params->format;
1041 6400 opts->fallback->width = ds->decoded_params->width;
1042 6400 opts->fallback->height = ds->decoded_params->height;
1043
1044 6400 ret = av_channel_layout_copy(&opts->fallback->ch_layout, &ds->decoded_params->ch_layout);
1045
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6400 times.
6400 if (ret < 0)
1046 return ret;
1047
1048
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6397 times.
6400 if (copy_ts) {
1049
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 tsoffset = d->f.start_time == AV_NOPTS_VALUE ? 0 : d->f.start_time;
1050
3/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 1 times.
3 if (!start_at_zero && d->f.ctx->start_time != AV_NOPTS_VALUE)
1051 2 tsoffset += d->f.ctx->start_time;
1052 }
1053
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 opts->trim_start_us = ((d->f.start_time == AV_NOPTS_VALUE) || !d->accurate_seek) ?
1054
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 6384 times.
6416 AV_NOPTS_VALUE : tsoffset;
1055 6400 opts->trim_end_us = d->recording_time;
1056
1057 6400 opts->name = av_strdup(ds->dec_name);
1058
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6400 times.
6400 if (!opts->name)
1059 return AVERROR(ENOMEM);
1060
1061 12800 opts->flags |= IFILTER_FLAG_AUTOROTATE * !!(ds->autorotate) |
1062
1/2
✓ Branch 0 taken 6400 times.
✗ Branch 1 not taken.
6400 IFILTER_FLAG_REINIT * !!(ds->reinit_filters);
1063
1064 6400 return ds->sch_idx_dec;
1065 }
1066
1067 14485 static int choose_decoder(const OptionsContext *o, AVFormatContext *s, AVStream *st,
1068 enum HWAccelID hwaccel_id, enum AVHWDeviceType hwaccel_device_type,
1069 const AVCodec **pcodec)
1070
1071 {
1072 14485 char *codec_name = NULL;
1073
1074
6/20
✓ Branch 1 taken 5513 times.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 10 times.
✓ Branch 5 taken 5523 times.
✓ Branch 6 taken 14485 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 14485 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
20008 MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, st);
1075
2/2
✓ Branch 0 taken 5513 times.
✓ Branch 1 taken 8972 times.
14485 if (codec_name) {
1076 5513 int ret = find_codec(NULL, codec_name, st->codecpar->codec_type, 0, pcodec);
1077
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5513 times.
5513 if (ret < 0)
1078 return ret;
1079 5513 st->codecpar->codec_id = (*pcodec)->id;
1080
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 5513 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
5513 if (recast_media && st->codecpar->codec_type != (*pcodec)->type)
1081 st->codecpar->codec_type = (*pcodec)->type;
1082 5513 return 0;
1083 } else {
1084
3/4
✓ Branch 0 taken 5557 times.
✓ Branch 1 taken 3415 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5557 times.
8972 if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
1085 hwaccel_id == HWACCEL_GENERIC &&
1086 hwaccel_device_type != AV_HWDEVICE_TYPE_NONE) {
1087 const AVCodec *c;
1088 void *i = NULL;
1089
1090 while ((c = av_codec_iterate(&i))) {
1091 const AVCodecHWConfig *config;
1092
1093 if (c->id != st->codecpar->codec_id ||
1094 !av_codec_is_decoder(c))
1095 continue;
1096
1097 for (int j = 0; config = avcodec_get_hw_config(c, j); j++) {
1098 if (config->device_type == hwaccel_device_type) {
1099 av_log(NULL, AV_LOG_VERBOSE, "Selecting decoder '%s' because of requested hwaccel method %s\n",
1100 c->name, av_hwdevice_get_type_name(hwaccel_device_type));
1101 *pcodec = c;
1102 return 0;
1103 }
1104 }
1105 }
1106 }
1107
1108 8972 *pcodec = avcodec_find_decoder(st->codecpar->codec_id);
1109 8972 return 0;
1110 }
1111 }
1112
1113 1636 static int guess_input_channel_layout(InputStream *ist, AVCodecParameters *par,
1114 int guess_layout_max)
1115 {
1116
2/2
✓ Branch 0 taken 764 times.
✓ Branch 1 taken 872 times.
1636 if (par->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) {
1117 char layout_name[256];
1118
1119
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 760 times.
764 if (par->ch_layout.nb_channels > guess_layout_max)
1120 12 return 0;
1121 760 av_channel_layout_default(&par->ch_layout, par->ch_layout.nb_channels);
1122
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 752 times.
760 if (par->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC)
1123 8 return 0;
1124 752 av_channel_layout_describe(&par->ch_layout, layout_name, sizeof(layout_name));
1125 752 av_log(ist, AV_LOG_WARNING, "Guessed Channel Layout: %s\n", layout_name);
1126 }
1127 1624 return 1;
1128 }
1129
1130 5526 static int add_display_matrix_to_stream(const OptionsContext *o,
1131 AVFormatContext *ctx, InputStream *ist)
1132 {
1133 5526 AVStream *st = ist->st;
1134 AVPacketSideData *sd;
1135 5526 double rotation = DBL_MAX;
1136 5526 int hflip = -1, vflip = -1;
1137 5526 int hflip_set = 0, vflip_set = 0, rotation_set = 0;
1138 int32_t *buf;
1139
1140
4/20
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 5526 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5526 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
5527 MATCH_PER_STREAM_OPT(display_rotations, dbl, rotation, ctx, st);
1141
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 5526 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5526 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
5526 MATCH_PER_STREAM_OPT(display_hflips, i, hflip, ctx, st);
1142
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 5526 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5526 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
5526 MATCH_PER_STREAM_OPT(display_vflips, i, vflip, ctx, st);
1143
1144 5526 rotation_set = rotation != DBL_MAX;
1145 5526 hflip_set = hflip != -1;
1146 5526 vflip_set = vflip != -1;
1147
1148
4/6
✓ Branch 0 taken 5525 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 5525 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5525 times.
✗ Branch 5 not taken.
5526 if (!rotation_set && !hflip_set && !vflip_set)
1149 5525 return 0;
1150
1151 1 sd = av_packet_side_data_new(&st->codecpar->coded_side_data,
1152 1 &st->codecpar->nb_coded_side_data,
1153 AV_PKT_DATA_DISPLAYMATRIX,
1154 sizeof(int32_t) * 9, 0);
1155
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!sd) {
1156 av_log(ist, AV_LOG_FATAL, "Failed to generate a display matrix!\n");
1157 return AVERROR(ENOMEM);
1158 }
1159
1160 1 buf = (int32_t *)sd->data;
1161
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 av_display_rotation_set(buf,
1162 rotation_set ? -(rotation) : -0.0f);
1163
1164
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 av_display_matrix_flip(buf,
1165 hflip_set ? hflip : 0,
1166 vflip_set ? vflip : 0);
1167
1168 1 return 0;
1169 }
1170
1171 1374 static const char *input_stream_item_name(void *obj)
1172 {
1173 1374 const DemuxStream *ds = obj;
1174
1175 1374 return ds->log_name;
1176 }
1177
1178 static const AVClass input_stream_class = {
1179 .class_name = "InputStream",
1180 .version = LIBAVUTIL_VERSION_INT,
1181 .item_name = input_stream_item_name,
1182 .category = AV_CLASS_CATEGORY_DEMUXER,
1183 };
1184
1185 7305 static DemuxStream *demux_stream_alloc(Demuxer *d, AVStream *st)
1186 {
1187 7305 const char *type_str = av_get_media_type_string(st->codecpar->codec_type);
1188 7305 InputFile *f = &d->f;
1189 DemuxStream *ds;
1190
1191 7305 ds = allocate_array_elem(&f->streams, sizeof(*ds), &f->nb_streams);
1192
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7305 times.
7305 if (!ds)
1193 return NULL;
1194
1195 7305 ds->sch_idx_stream = -1;
1196 7305 ds->sch_idx_dec = -1;
1197
1198 7305 ds->ist.st = st;
1199 7305 ds->ist.file = f;
1200 7305 ds->ist.index = st->index;
1201 7305 ds->ist.class = &input_stream_class;
1202
1203
1/2
✓ Branch 0 taken 7305 times.
✗ Branch 1 not taken.
7305 snprintf(ds->log_name, sizeof(ds->log_name), "%cist#%d:%d/%s",
1204 7305 type_str ? *type_str : '?', d->f.index, st->index,
1205 7305 avcodec_get_name(st->codecpar->codec_id));
1206
1207 7305 return ds;
1208 }
1209
1210 7305 static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st)
1211 {
1212 7305 AVFormatContext *ic = d->f.ctx;
1213 7305 AVCodecParameters *par = st->codecpar;
1214 DemuxStream *ds;
1215 InputStream *ist;
1216 7305 char *framerate = NULL, *hwaccel_device = NULL;
1217 7305 const char *hwaccel = NULL;
1218 7305 char *hwaccel_output_format = NULL;
1219 7305 char *codec_tag = NULL;
1220 7305 char *bsfs = NULL;
1221 char *next;
1222 7305 char *discard_str = NULL;
1223 int ret;
1224
1225 7305 ds = demux_stream_alloc(d, st);
1226
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7305 times.
7305 if (!ds)
1227 return AVERROR(ENOMEM);
1228
1229 7305 ist = &ds->ist;
1230
1231 7305 ds->discard = 1;
1232 7305 st->discard = AVDISCARD_ALL;
1233 7305 ds->first_dts = AV_NOPTS_VALUE;
1234 7305 ds->next_dts = AV_NOPTS_VALUE;
1235
1236 7305 ds->dec_opts.time_base = st->time_base;
1237
1238 7305 ds->ts_scale = 1.0;
1239
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 7305 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 7305 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
7305 MATCH_PER_STREAM_OPT(ts_scale, dbl, ds->ts_scale, ic, st);
1240
1241 7305 ds->autorotate = 1;
1242
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 7305 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 7305 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
7305 MATCH_PER_STREAM_OPT(autorotate, i, ds->autorotate, ic, st);
1243
1244
4/20
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 7305 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 7305 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
7307 MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, ic, st);
1245
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 7303 times.
7305 if (codec_tag) {
1246 2 uint32_t tag = strtol(codec_tag, &next, 0);
1247
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (*next) {
1248 2 uint8_t buf[4] = { 0 };
1249
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 memcpy(buf, codec_tag, FFMIN(sizeof(buf), strlen(codec_tag)));
1250 2 tag = AV_RL32(buf);
1251 }
1252
1253 2 st->codecpar->codec_tag = tag;
1254 }
1255
1256
2/2
✓ Branch 0 taken 5526 times.
✓ Branch 1 taken 1779 times.
7305 if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
1257 5526 ret = add_display_matrix_to_stream(o, ic, ist);
1258
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5526 times.
5526 if (ret < 0)
1259 return ret;
1260
1261
4/20
✓ Branch 1 taken 5236 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 5236 times.
✓ Branch 6 taken 5526 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5526 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
10762 MATCH_PER_STREAM_OPT(hwaccels, str, hwaccel, ic, st);
1262
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 5526 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5526 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
5526 MATCH_PER_STREAM_OPT(hwaccel_output_formats, str,
1263 hwaccel_output_format, ic, st);
1264
1265
4/6
✓ Branch 0 taken 5526 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5236 times.
✓ Branch 3 taken 290 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 5236 times.
5526 if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "cuvid")) {
1266 av_log(ist, AV_LOG_WARNING,
1267 "WARNING: defaulting hwaccel_output_format to cuda for compatibility "
1268 "with old commandlines. This behaviour is DEPRECATED and will be removed "
1269 "in the future. Please explicitly set \"-hwaccel_output_format cuda\".\n");
1270 ds->dec_opts.hwaccel_output_format = AV_PIX_FMT_CUDA;
1271
4/6
✓ Branch 0 taken 5526 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5236 times.
✓ Branch 3 taken 290 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 5236 times.
5526 } else if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "qsv")) {
1272 av_log(ist, AV_LOG_WARNING,
1273 "WARNING: defaulting hwaccel_output_format to qsv for compatibility "
1274 "with old commandlines. This behaviour is DEPRECATED and will be removed "
1275 "in the future. Please explicitly set \"-hwaccel_output_format qsv\".\n");
1276 ds->dec_opts.hwaccel_output_format = AV_PIX_FMT_QSV;
1277
4/6
✓ Branch 0 taken 5526 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5236 times.
✓ Branch 3 taken 290 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 5236 times.
5526 } else if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "mediacodec")) {
1278 // There is no real AVHWFrameContext implementation. Set
1279 // hwaccel_output_format to avoid av_hwframe_transfer_data error.
1280 ds->dec_opts.hwaccel_output_format = AV_PIX_FMT_MEDIACODEC;
1281
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5526 times.
5526 } else if (hwaccel_output_format) {
1282 ds->dec_opts.hwaccel_output_format = av_get_pix_fmt(hwaccel_output_format);
1283 if (ds->dec_opts.hwaccel_output_format == AV_PIX_FMT_NONE) {
1284 av_log(ist, AV_LOG_FATAL, "Unrecognised hwaccel output "
1285 "format: %s", hwaccel_output_format);
1286 }
1287 } else {
1288 5526 ds->dec_opts.hwaccel_output_format = AV_PIX_FMT_NONE;
1289 }
1290
1291
2/2
✓ Branch 0 taken 5236 times.
✓ Branch 1 taken 290 times.
5526 if (hwaccel) {
1292 // The NVDEC hwaccels use a CUDA device, so remap the name here.
1293
2/4
✓ Branch 0 taken 5236 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5236 times.
5236 if (!strcmp(hwaccel, "nvdec") || !strcmp(hwaccel, "cuvid"))
1294 hwaccel = "cuda";
1295
1296
1/2
✓ Branch 0 taken 5236 times.
✗ Branch 1 not taken.
5236 if (!strcmp(hwaccel, "none"))
1297 5236 ds->dec_opts.hwaccel_id = HWACCEL_NONE;
1298 else if (!strcmp(hwaccel, "auto"))
1299 ds->dec_opts.hwaccel_id = HWACCEL_AUTO;
1300 else {
1301 enum AVHWDeviceType type = av_hwdevice_find_type_by_name(hwaccel);
1302 if (type != AV_HWDEVICE_TYPE_NONE) {
1303 ds->dec_opts.hwaccel_id = HWACCEL_GENERIC;
1304 ds->dec_opts.hwaccel_device_type = type;
1305 }
1306
1307 if (!ds->dec_opts.hwaccel_id) {
1308 av_log(ist, AV_LOG_FATAL, "Unrecognized hwaccel: %s.\n",
1309 hwaccel);
1310 av_log(ist, AV_LOG_FATAL, "Supported hwaccels: ");
1311 type = AV_HWDEVICE_TYPE_NONE;
1312 while ((type = av_hwdevice_iterate_types(type)) !=
1313 AV_HWDEVICE_TYPE_NONE)
1314 av_log(ist, AV_LOG_FATAL, "%s ",
1315 av_hwdevice_get_type_name(type));
1316 av_log(ist, AV_LOG_FATAL, "\n");
1317 return AVERROR(EINVAL);
1318 }
1319 }
1320 }
1321
1322
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 5526 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5526 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
5526 MATCH_PER_STREAM_OPT(hwaccel_devices, str, hwaccel_device, ic, st);
1323
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5526 times.
5526 if (hwaccel_device) {
1324 ds->dec_opts.hwaccel_device = av_strdup(hwaccel_device);
1325 if (!ds->dec_opts.hwaccel_device)
1326 return AVERROR(ENOMEM);
1327 }
1328 }
1329
1330 7305 ret = choose_decoder(o, ic, st, ds->dec_opts.hwaccel_id,
1331 ds->dec_opts.hwaccel_device_type, &ist->dec);
1332
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7305 times.
7305 if (ret < 0)
1333 return ret;
1334
1335
2/2
✓ Branch 0 taken 7233 times.
✓ Branch 1 taken 72 times.
7305 if (ist->dec) {
1336 7233 ret = filter_codec_opts(o->g->codec_opts, ist->st->codecpar->codec_id,
1337 ic, st, ist->dec, &ds->decoder_opts);
1338
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7233 times.
7233 if (ret < 0)
1339 return ret;
1340 }
1341
1342 7305 ds->reinit_filters = -1;
1343
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 7305 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 7305 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
7305 MATCH_PER_STREAM_OPT(reinit_filters, i, ds->reinit_filters, ic, st);
1344
1345 7305 ist->user_set_discard = AVDISCARD_NONE;
1346
1347
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 7305 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
7305 if ((o->video_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) ||
1348
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7304 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
7305 (o->audio_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) ||
1349
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 7304 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
7304 (o->subtitle_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) ||
1350
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 7304 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
7304 (o->data_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_DATA))
1351 1 ist->user_set_discard = AVDISCARD_ALL;
1352
1353
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 7305 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 7305 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
7305 MATCH_PER_STREAM_OPT(discard, str, discard_str, ic, st);
1354
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7305 times.
7305 if (discard_str) {
1355 ret = av_opt_set(ist->st, "discard", discard_str, 0);
1356 if (ret < 0) {
1357 av_log(ist, AV_LOG_ERROR, "Error parsing discard %s.\n", discard_str);
1358 return ret;
1359 }
1360 ist->user_set_discard = ist->st->discard;
1361 }
1362
1363
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 7209 times.
7305 ds->dec_opts.flags |= DECODER_FLAG_BITEXACT * !!o->bitexact;
1364
1365 /* Attached pics are sparse, therefore we would not want to delay their decoding
1366 * till EOF. */
1367
2/2
✓ Branch 0 taken 37 times.
✓ Branch 1 taken 7268 times.
7305 if (ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC)
1368 37 av_dict_set(&ds->decoder_opts, "thread_type", "-frame", 0);
1369
1370
4/5
✓ Branch 0 taken 5526 times.
✓ Branch 1 taken 1637 times.
✓ Branch 2 taken 140 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
7305 switch (par->codec_type) {
1371 5526 case AVMEDIA_TYPE_VIDEO:
1372
4/20
✓ Branch 1 taken 26 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 26 times.
✓ Branch 6 taken 5526 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5526 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
5552 MATCH_PER_STREAM_OPT(frame_rates, str, framerate, ic, st);
1373
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 5500 times.
5526 if (framerate) {
1374 26 ret = av_parse_video_rate(&ist->framerate, framerate);
1375
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
26 if (ret < 0) {
1376 av_log(ist, AV_LOG_ERROR, "Error parsing framerate %s.\n",
1377 framerate);
1378 return ret;
1379 }
1380 }
1381
1382 #if FFMPEG_OPT_TOP
1383 5526 ist->top_field_first = -1;
1384
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 5526 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5526 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
5526 MATCH_PER_STREAM_OPT(top_field_first, i, ist->top_field_first, ic, st);
1385 #endif
1386
1387 5526 break;
1388 1637 case AVMEDIA_TYPE_AUDIO: {
1389 1637 char *ch_layout_str = NULL;
1390
4/20
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1637 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1637 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1638 MATCH_PER_STREAM_OPT(audio_ch_layouts, str, ch_layout_str, ic, st);
1391
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1636 times.
1637 if (ch_layout_str) {
1392 AVChannelLayout ch_layout;
1393 1 ret = av_channel_layout_from_string(&ch_layout, ch_layout_str);
1394
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ret < 0) {
1395 av_log(ist, AV_LOG_ERROR, "Error parsing channel layout %s.\n", ch_layout_str);
1396 return ret;
1397 }
1398
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if (par->ch_layout.nb_channels <= 0 || par->ch_layout.nb_channels == ch_layout.nb_channels) {
1399 1 av_channel_layout_uninit(&par->ch_layout);
1400 1 par->ch_layout = ch_layout;
1401 } else {
1402 av_log(ist, AV_LOG_ERROR,
1403 "Specified channel layout '%s' has %d channels, but input has %d channels.\n",
1404 ch_layout_str, ch_layout.nb_channels, par->ch_layout.nb_channels);
1405 av_channel_layout_uninit(&ch_layout);
1406 return AVERROR(EINVAL);
1407 }
1408 } else {
1409 1636 int guess_layout_max = INT_MAX;
1410
4/20
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 1636 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1636 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1640 MATCH_PER_STREAM_OPT(guess_layout_max, i, guess_layout_max, ic, st);
1411 1636 guess_input_channel_layout(ist, par, guess_layout_max);
1412 }
1413 1637 break;
1414 }
1415 140 case AVMEDIA_TYPE_DATA:
1416 case AVMEDIA_TYPE_SUBTITLE: {
1417 140 char *canvas_size = NULL;
1418
4/20
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 140 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 140 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
142 MATCH_PER_STREAM_OPT(fix_sub_duration, i, ist->fix_sub_duration, ic, st);
1419
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 140 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 140 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
140 MATCH_PER_STREAM_OPT(canvas_sizes, str, canvas_size, ic, st);
1420
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 140 times.
140 if (canvas_size) {
1421 ret = av_parse_video_size(&par->width, &par->height,
1422 canvas_size);
1423 if (ret < 0) {
1424 av_log(ist, AV_LOG_FATAL, "Invalid canvas size: %s.\n", canvas_size);
1425 return ret;
1426 }
1427 }
1428 140 break;
1429 }
1430 2 case AVMEDIA_TYPE_ATTACHMENT:
1431 case AVMEDIA_TYPE_UNKNOWN:
1432 2 break;
1433 default: av_assert0(0);
1434 }
1435
1436 7305 ist->par = avcodec_parameters_alloc();
1437
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7305 times.
7305 if (!ist->par)
1438 return AVERROR(ENOMEM);
1439
1440 7305 ret = avcodec_parameters_copy(ist->par, par);
1441
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7305 times.
7305 if (ret < 0) {
1442 av_log(ist, AV_LOG_ERROR, "Error exporting stream parameters.\n");
1443 return ret;
1444 }
1445
1446
2/2
✓ Branch 0 taken 428 times.
✓ Branch 1 taken 6877 times.
7305 if (ist->st->sample_aspect_ratio.num)
1447 428 ist->par->sample_aspect_ratio = ist->st->sample_aspect_ratio;
1448
1449
4/20
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 7305 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 7305 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
7306 MATCH_PER_STREAM_OPT(bitstream_filters, str, bsfs, ic, st);
1450
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7304 times.
7305 if (bsfs) {
1451 1 ret = av_bsf_list_parse_str(bsfs, &ds->bsf);
1452
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ret < 0) {
1453 av_log(ist, AV_LOG_ERROR,
1454 "Error parsing bitstream filter sequence '%s': %s\n",
1455 bsfs, av_err2str(ret));
1456 return ret;
1457 }
1458
1459 1 ret = avcodec_parameters_copy(ds->bsf->par_in, ist->par);
1460
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ret < 0)
1461 return ret;
1462 1 ds->bsf->time_base_in = ist->st->time_base;
1463
1464 1 ret = av_bsf_init(ds->bsf);
1465
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ret < 0) {
1466 av_log(ist, AV_LOG_ERROR, "Error initializing bitstream filters: %s\n",
1467 av_err2str(ret));
1468 return ret;
1469 }
1470
1471 1 ret = avcodec_parameters_copy(ist->par, ds->bsf->par_out);
1472
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ret < 0)
1473 return ret;
1474 }
1475
1476 7305 ds->codec_desc = avcodec_descriptor_get(ist->par->codec_id);
1477
1478 7305 return 0;
1479 }
1480
1481 static int dump_attachment(InputStream *ist, const char *filename)
1482 {
1483 AVStream *st = ist->st;
1484 int ret;
1485 AVIOContext *out = NULL;
1486 const AVDictionaryEntry *e;
1487
1488 if (!st->codecpar->extradata_size) {
1489 av_log(ist, AV_LOG_WARNING, "No extradata to dump.\n");
1490 return 0;
1491 }
1492 if (!*filename && (e = av_dict_get(st->metadata, "filename", NULL, 0)))
1493 filename = e->value;
1494 if (!*filename) {
1495 av_log(ist, AV_LOG_FATAL, "No filename specified and no 'filename' tag");
1496 return AVERROR(EINVAL);
1497 }
1498
1499 ret = assert_file_overwrite(filename);
1500 if (ret < 0)
1501 return ret;
1502
1503 if ((ret = avio_open2(&out, filename, AVIO_FLAG_WRITE, &int_cb, NULL)) < 0) {
1504 av_log(ist, AV_LOG_FATAL, "Could not open file %s for writing.\n",
1505 filename);
1506 return ret;
1507 }
1508
1509 avio_write(out, st->codecpar->extradata, st->codecpar->extradata_size);
1510 ret = avio_close(out);
1511
1512 if (ret >= 0)
1513 av_log(ist, AV_LOG_INFO, "Wrote attachment (%d bytes) to '%s'\n",
1514 st->codecpar->extradata_size, filename);
1515
1516 return ret;
1517 }
1518
1519 620 static const char *input_file_item_name(void *obj)
1520 {
1521 620 const Demuxer *d = obj;
1522
1523 620 return d->log_name;
1524 }
1525
1526 static const AVClass input_file_class = {
1527 .class_name = "InputFile",
1528 .version = LIBAVUTIL_VERSION_INT,
1529 .item_name = input_file_item_name,
1530 .category = AV_CLASS_CATEGORY_DEMUXER,
1531 };
1532
1533 6794 static Demuxer *demux_alloc(void)
1534 {
1535 6794 Demuxer *d = allocate_array_elem(&input_files, sizeof(*d), &nb_input_files);
1536
1537
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6794 times.
6794 if (!d)
1538 return NULL;
1539
1540 6794 d->f.class = &input_file_class;
1541 6794 d->f.index = nb_input_files - 1;
1542
1543 6794 snprintf(d->log_name, sizeof(d->log_name), "in#%d", d->f.index);
1544
1545 6794 return d;
1546 }
1547
1548 6794 int ifile_open(const OptionsContext *o, const char *filename, Scheduler *sch)
1549 {
1550 Demuxer *d;
1551 InputFile *f;
1552 AVFormatContext *ic;
1553 6794 const AVInputFormat *file_iformat = NULL;
1554 6794 int err, i, ret = 0;
1555 int64_t timestamp;
1556 6794 AVDictionary *unused_opts = NULL;
1557 6794 const AVDictionaryEntry *e = NULL;
1558 6794 const char* video_codec_name = NULL;
1559 6794 const char* audio_codec_name = NULL;
1560 6794 const char* subtitle_codec_name = NULL;
1561 6794 const char* data_codec_name = NULL;
1562 6794 int scan_all_pmts_set = 0;
1563
1564 6794 int64_t start_time = o->start_time;
1565 6794 int64_t start_time_eof = o->start_time_eof;
1566 6794 int64_t stop_time = o->stop_time;
1567 6794 int64_t recording_time = o->recording_time;
1568
1569 6794 d = demux_alloc();
1570
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6794 times.
6794 if (!d)
1571 return AVERROR(ENOMEM);
1572
1573 6794 f = &d->f;
1574
1575 6794 ret = sch_add_demux(sch, input_thread, d);
1576
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6794 times.
6794 if (ret < 0)
1577 return ret;
1578 6794 d->sch = sch;
1579
1580
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6794 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6794 if (stop_time != INT64_MAX && recording_time != INT64_MAX) {
1581 stop_time = INT64_MAX;
1582 av_log(d, AV_LOG_WARNING, "-t and -to cannot be used together; using -t.\n");
1583 }
1584
1585
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6794 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6794 if (stop_time != INT64_MAX && recording_time == INT64_MAX) {
1586 int64_t start = start_time == AV_NOPTS_VALUE ? 0 : start_time;
1587 if (stop_time <= start) {
1588 av_log(d, AV_LOG_ERROR, "-to value smaller than -ss; aborting.\n");
1589 return AVERROR(EINVAL);
1590 } else {
1591 recording_time = stop_time - start;
1592 }
1593 }
1594
1595
2/2
✓ Branch 0 taken 3343 times.
✓ Branch 1 taken 3451 times.
6794 if (o->format) {
1596
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3343 times.
3343 if (!(file_iformat = av_find_input_format(o->format))) {
1597 av_log(d, AV_LOG_FATAL, "Unknown input format: '%s'\n", o->format);
1598 return AVERROR(EINVAL);
1599 }
1600 }
1601
1602
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6794 times.
6794 if (!strcmp(filename, "-"))
1603 filename = "fd:";
1604
1605 20382 stdin_interaction &= strncmp(filename, "pipe:", 5) &&
1606
2/4
✓ Branch 0 taken 6794 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6794 times.
✗ Branch 3 not taken.
13588 strcmp(filename, "fd:") &&
1607
1/2
✓ Branch 0 taken 6794 times.
✗ Branch 1 not taken.
6794 strcmp(filename, "/dev/stdin");
1608
1609 /* get default parameters from command line */
1610 6794 ic = avformat_alloc_context();
1611
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6794 times.
6794 if (!ic)
1612 return AVERROR(ENOMEM);
1613
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 6728 times.
6794 if (o->audio_sample_rate.nb_opt) {
1614 66 av_dict_set_int(&o->g->format_opts, "sample_rate", o->audio_sample_rate.opt[o->audio_sample_rate.nb_opt - 1].u.i, 0);
1615 }
1616
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 6785 times.
6794 if (o->audio_channels.nb_opt) {
1617 const AVClass *priv_class;
1618
3/6
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
18 if (file_iformat && (priv_class = file_iformat->priv_class) &&
1619 9 av_opt_find(&priv_class, "ch_layout", NULL, 0,
1620 AV_OPT_SEARCH_FAKE_OBJ)) {
1621 char buf[32];
1622 9 snprintf(buf, sizeof(buf), "%dC", o->audio_channels.opt[o->audio_channels.nb_opt - 1].u.i);
1623 9 av_dict_set(&o->g->format_opts, "ch_layout", buf, 0);
1624 }
1625 }
1626
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6793 times.
6794 if (o->audio_ch_layouts.nb_opt) {
1627 const AVClass *priv_class;
1628
3/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 if (file_iformat && (priv_class = file_iformat->priv_class) &&
1629 1 av_opt_find(&priv_class, "ch_layout", NULL, 0,
1630 AV_OPT_SEARCH_FAKE_OBJ)) {
1631 1 av_dict_set(&o->g->format_opts, "ch_layout", o->audio_ch_layouts.opt[o->audio_ch_layouts.nb_opt - 1].u.str, 0);
1632 }
1633 }
1634
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 6768 times.
6794 if (o->frame_rates.nb_opt) {
1635 const AVClass *priv_class;
1636 /* set the format-level framerate option;
1637 * this is important for video grabbers, e.g. x11 */
1638
4/6
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 25 times.
✗ Branch 5 not taken.
51 if (file_iformat && (priv_class = file_iformat->priv_class) &&
1639 25 av_opt_find(&priv_class, "framerate", NULL, 0,
1640 AV_OPT_SEARCH_FAKE_OBJ)) {
1641 25 av_dict_set(&o->g->format_opts, "framerate",
1642 25 o->frame_rates.opt[o->frame_rates.nb_opt - 1].u.str, 0);
1643 }
1644 }
1645
2/2
✓ Branch 0 taken 538 times.
✓ Branch 1 taken 6256 times.
6794 if (o->frame_sizes.nb_opt) {
1646 538 av_dict_set(&o->g->format_opts, "video_size", o->frame_sizes.opt[o->frame_sizes.nb_opt - 1].u.str, 0);
1647 }
1648
2/2
✓ Branch 0 taken 547 times.
✓ Branch 1 taken 6247 times.
6794 if (o->frame_pix_fmts.nb_opt)
1649 547 av_dict_set(&o->g->format_opts, "pixel_format", o->frame_pix_fmts.opt[o->frame_pix_fmts.nb_opt - 1].u.str, 0);
1650
1651 6794 video_codec_name = opt_match_per_type_str(&o->codec_names, 'v');
1652 6794 audio_codec_name = opt_match_per_type_str(&o->codec_names, 'a');
1653 6794 subtitle_codec_name = opt_match_per_type_str(&o->codec_names, 's');
1654 6794 data_codec_name = opt_match_per_type_str(&o->codec_names, 'd');
1655
1656
2/2
✓ Branch 0 taken 2722 times.
✓ Branch 1 taken 4072 times.
6794 if (video_codec_name)
1657 2722 ret = err_merge(ret, find_codec(NULL, video_codec_name , AVMEDIA_TYPE_VIDEO , 0,
1658 2722 &ic->video_codec));
1659
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 6776 times.
6794 if (audio_codec_name)
1660 18 ret = err_merge(ret, find_codec(NULL, audio_codec_name , AVMEDIA_TYPE_AUDIO , 0,
1661 18 &ic->audio_codec));
1662
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6794 times.
6794 if (subtitle_codec_name)
1663 ret = err_merge(ret, find_codec(NULL, subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, 0,
1664 &ic->subtitle_codec));
1665
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6794 times.
6794 if (data_codec_name)
1666 ret = err_merge(ret, find_codec(NULL, data_codec_name , AVMEDIA_TYPE_DATA, 0,
1667 &ic->data_codec));
1668
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6794 times.
6794 if (ret < 0) {
1669 avformat_free_context(ic);
1670 return ret;
1671 }
1672
1673
2/2
✓ Branch 0 taken 2722 times.
✓ Branch 1 taken 4072 times.
6794 ic->video_codec_id = video_codec_name ? ic->video_codec->id : AV_CODEC_ID_NONE;
1674
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 6776 times.
6794 ic->audio_codec_id = audio_codec_name ? ic->audio_codec->id : AV_CODEC_ID_NONE;
1675
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6794 times.
6794 ic->subtitle_codec_id = subtitle_codec_name ? ic->subtitle_codec->id : AV_CODEC_ID_NONE;
1676
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6794 times.
6794 ic->data_codec_id = data_codec_name ? ic->data_codec->id : AV_CODEC_ID_NONE;
1677
1678 6794 ic->flags |= AVFMT_FLAG_NONBLOCK;
1679
2/2
✓ Branch 0 taken 85 times.
✓ Branch 1 taken 6709 times.
6794 if (o->bitexact)
1680 85 ic->flags |= AVFMT_FLAG_BITEXACT;
1681 6794 ic->interrupt_callback = int_cb;
1682
1683
1/2
✓ Branch 1 taken 6794 times.
✗ Branch 2 not taken.
6794 if (!av_dict_get(o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE)) {
1684 6794 av_dict_set(&o->g->format_opts, "scan_all_pmts", "1", AV_DICT_DONT_OVERWRITE);
1685 6794 scan_all_pmts_set = 1;
1686 }
1687 /* open the input file with generic avformat function */
1688 6794 err = avformat_open_input(&ic, filename, file_iformat, &o->g->format_opts);
1689
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6794 times.
6794 if (err < 0) {
1690 av_log(d, AV_LOG_ERROR,
1691 "Error opening input: %s\n", av_err2str(err));
1692 if (err == AVERROR_PROTOCOL_NOT_FOUND)
1693 av_log(d, AV_LOG_ERROR, "Did you mean file:%s?\n", filename);
1694 return err;
1695 }
1696 6794 f->ctx = ic;
1697
1698 6794 av_strlcat(d->log_name, "/", sizeof(d->log_name));
1699 6794 av_strlcat(d->log_name, ic->iformat->name, sizeof(d->log_name));
1700
1701
1/2
✓ Branch 0 taken 6794 times.
✗ Branch 1 not taken.
6794 if (scan_all_pmts_set)
1702 6794 av_dict_set(&o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
1703 6794 remove_avoptions(&o->g->format_opts, o->g->codec_opts);
1704
1705 6794 ret = check_avoptions(o->g->format_opts);
1706
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6794 times.
6794 if (ret < 0)
1707 return ret;
1708
1709 /* apply forced codec ids */
1710
2/2
✓ Branch 0 taken 7180 times.
✓ Branch 1 taken 6794 times.
13974 for (i = 0; i < ic->nb_streams; i++) {
1711 const AVCodec *dummy;
1712 7180 ret = choose_decoder(o, ic, ic->streams[i], HWACCEL_NONE, AV_HWDEVICE_TYPE_NONE,
1713 &dummy);
1714
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7180 times.
7180 if (ret < 0)
1715 return ret;
1716 }
1717
1718
2/2
✓ Branch 0 taken 6792 times.
✓ Branch 1 taken 2 times.
6794 if (o->find_stream_info) {
1719 AVDictionary **opts;
1720 6792 int orig_nb_streams = ic->nb_streams;
1721
1722 6792 ret = setup_find_stream_info_opts(ic, o->g->codec_opts, &opts);
1723
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6792 times.
6792 if (ret < 0)
1724 return ret;
1725
1726 /* If not enough info to get the stream parameters, we decode the
1727 first frames to get it. (used in mpeg case for example) */
1728 6792 ret = avformat_find_stream_info(ic, opts);
1729
1730
2/2
✓ Branch 0 taken 7178 times.
✓ Branch 1 taken 6792 times.
13970 for (i = 0; i < orig_nb_streams; i++)
1731 7178 av_dict_free(&opts[i]);
1732 6792 av_freep(&opts);
1733
1734
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6792 times.
6792 if (ret < 0) {
1735 av_log(d, AV_LOG_FATAL, "could not find codec parameters\n");
1736 if (ic->nb_streams == 0)
1737 return ret;
1738 }
1739 }
1740
1741
3/4
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 6773 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 21 times.
6794 if (start_time != AV_NOPTS_VALUE && start_time_eof != AV_NOPTS_VALUE) {
1742 av_log(d, AV_LOG_WARNING, "Cannot use -ss and -sseof both, using -ss\n");
1743 start_time_eof = AV_NOPTS_VALUE;
1744 }
1745
1746
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6794 times.
6794 if (start_time_eof != AV_NOPTS_VALUE) {
1747 if (start_time_eof >= 0) {
1748 av_log(d, AV_LOG_ERROR, "-sseof value must be negative; aborting\n");
1749 return AVERROR(EINVAL);
1750 }
1751 if (ic->duration > 0) {
1752 start_time = start_time_eof + ic->duration;
1753 if (start_time < 0) {
1754 av_log(d, AV_LOG_WARNING, "-sseof value seeks to before start of file; ignored\n");
1755 start_time = AV_NOPTS_VALUE;
1756 }
1757 } else
1758 av_log(d, AV_LOG_WARNING, "Cannot use -sseof, file duration not known\n");
1759 }
1760
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 6773 times.
6794 timestamp = (start_time == AV_NOPTS_VALUE) ? 0 : start_time;
1761 /* add the stream start time */
1762
4/4
✓ Branch 0 taken 6791 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 5099 times.
✓ Branch 3 taken 1692 times.
6794 if (!o->seek_timestamp && ic->start_time != AV_NOPTS_VALUE)
1763 5099 timestamp += ic->start_time;
1764
1765 /* if seeking requested, we execute it */
1766
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 6773 times.
6794 if (start_time != AV_NOPTS_VALUE) {
1767 21 int64_t seek_timestamp = timestamp;
1768
1769
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 if (!(ic->iformat->flags & AVFMT_SEEK_TO_PTS)) {
1770 21 int dts_heuristic = 0;
1771
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 21 times.
42 for (i=0; i<ic->nb_streams; i++) {
1772 21 const AVCodecParameters *par = ic->streams[i]->codecpar;
1773
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 if (par->video_delay) {
1774 dts_heuristic = 1;
1775 break;
1776 }
1777 }
1778
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 if (dts_heuristic) {
1779 seek_timestamp -= 3*AV_TIME_BASE / 23;
1780 }
1781 }
1782 21 ret = avformat_seek_file(ic, -1, INT64_MIN, seek_timestamp, seek_timestamp, 0);
1783
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 20 times.
21 if (ret < 0) {
1784 1 av_log(d, AV_LOG_WARNING, "could not seek to position %0.3f\n",
1785 1 (double)timestamp / AV_TIME_BASE);
1786 }
1787 }
1788
1789 6794 f->start_time = start_time;
1790 6794 d->recording_time = recording_time;
1791 6794 f->input_sync_ref = o->input_sync_ref;
1792 6794 f->input_ts_offset = o->input_ts_offset;
1793
3/6
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 6781 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 13 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
6794 f->ts_offset = o->input_ts_offset - (copy_ts ? (start_at_zero && ic->start_time != AV_NOPTS_VALUE ? ic->start_time : 0) : timestamp);
1794 6794 d->accurate_seek = o->accurate_seek;
1795 6794 d->loop = o->loop;
1796 6794 d->nb_streams_warn = ic->nb_streams;
1797
1798 6794 d->duration = (Timestamp){ .ts = 0, .tb = (AVRational){ 1, 1 } };
1799 6794 d->min_pts = (Timestamp){ .ts = AV_NOPTS_VALUE, .tb = (AVRational){ 1, 1 } };
1800 6794 d->max_pts = (Timestamp){ .ts = AV_NOPTS_VALUE, .tb = (AVRational){ 1, 1 } };
1801
1802 6794 d->readrate = o->readrate ? o->readrate : 0.0;
1803
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6794 times.
6794 if (d->readrate < 0.0f) {
1804 av_log(d, AV_LOG_ERROR, "Option -readrate is %0.3f; it must be non-negative.\n", d->readrate);
1805 return AVERROR(EINVAL);
1806 }
1807
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6793 times.
6794 if (o->rate_emu) {
1808
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (d->readrate) {
1809 av_log(d, AV_LOG_WARNING, "Both -readrate and -re set. Using -readrate %0.3f.\n", d->readrate);
1810 } else
1811 1 d->readrate = 1.0f;
1812 }
1813
1814
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6793 times.
6794 if (d->readrate) {
1815
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 d->readrate_initial_burst = o->readrate_initial_burst ? o->readrate_initial_burst : 0.5;
1816
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (d->readrate_initial_burst < 0.0) {
1817 av_log(d, AV_LOG_ERROR,
1818 "Option -readrate_initial_burst is %0.3f; it must be non-negative.\n",
1819 d->readrate_initial_burst);
1820 return AVERROR(EINVAL);
1821 }
1822
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6793 times.
6793 } else if (o->readrate_initial_burst) {
1823 av_log(d, AV_LOG_WARNING, "Option -readrate_initial_burst ignored "
1824 "since neither -readrate nor -re were given\n");
1825 }
1826
1827 /* Add all the streams from the given input file to the demuxer */
1828
2/2
✓ Branch 0 taken 7305 times.
✓ Branch 1 taken 6794 times.
14099 for (int i = 0; i < ic->nb_streams; i++) {
1829 7305 ret = ist_add(o, d, ic->streams[i]);
1830
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7305 times.
7305 if (ret < 0)
1831 return ret;
1832 }
1833
1834 /* dump the file content */
1835 6794 av_dump_format(ic, f->index, filename, 0);
1836
1837 /* check if all codec options have been used */
1838 6794 unused_opts = strip_specifiers(o->g->codec_opts);
1839
2/2
✓ Branch 0 taken 7305 times.
✓ Branch 1 taken 6794 times.
14099 for (i = 0; i < f->nb_streams; i++) {
1840 7305 DemuxStream *ds = ds_from_ist(f->streams[i]);
1841 7305 e = NULL;
1842
2/2
✓ Branch 1 taken 22269 times.
✓ Branch 2 taken 7305 times.
29574 while ((e = av_dict_iterate(ds->decoder_opts, e)))
1843 22269 av_dict_set(&unused_opts, e->key, NULL, 0);
1844 }
1845
1846 6794 e = NULL;
1847
2/2
✓ Branch 1 taken 453 times.
✓ Branch 2 taken 6794 times.
7247 while ((e = av_dict_iterate(unused_opts, e))) {
1848 453 const AVClass *class = avcodec_get_class();
1849 453 const AVOption *option = av_opt_find(&class, e->key, NULL, 0,
1850 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
1851 453 const AVClass *fclass = avformat_get_class();
1852 453 const AVOption *foption = av_opt_find(&fclass, e->key, NULL, 0,
1853 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
1854
2/4
✓ Branch 0 taken 453 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 453 times.
453 if (!option || foption)
1855 continue;
1856
1857
1858
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 453 times.
453 if (!(option->flags & AV_OPT_FLAG_DECODING_PARAM)) {
1859 av_log(d, AV_LOG_ERROR, "Codec AVOption %s (%s) is not a decoding "
1860 "option.\n", e->key, option->help ? option->help : "");
1861 return AVERROR(EINVAL);
1862 }
1863
1864 453 av_log(d, AV_LOG_WARNING, "Codec AVOption %s (%s) has not been used "
1865 "for any stream. The most likely reason is either wrong type "
1866 "(e.g. a video option with no video streams) or that it is a "
1867 "private option of some decoder which was not actually used "
1868
2/2
✓ Branch 0 taken 449 times.
✓ Branch 1 taken 4 times.
906 "for any stream.\n", e->key, option->help ? option->help : "");
1869 }
1870 6794 av_dict_free(&unused_opts);
1871
1872
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6794 times.
6794 for (i = 0; i < o->dump_attachment.nb_opt; i++) {
1873 int j;
1874
1875 for (j = 0; j < f->nb_streams; j++) {
1876 InputStream *ist = f->streams[j];
1877
1878 if (check_stream_specifier(ic, ist->st, o->dump_attachment.opt[i].specifier) == 1) {
1879 ret = dump_attachment(ist, o->dump_attachment.opt[i].u.str);
1880 if (ret < 0)
1881 return ret;
1882 }
1883 }
1884 }
1885
1886 6794 return 0;
1887 }
1888