FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/fftools/ffmpeg_demux.c
Date: 2023-01-27 00:32:08
Exec Total Coverage
Lines: 470 651 72.2%
Functions: 16 18 88.9%
Branches: 340 825 41.2%

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
24 #include "libavutil/avassert.h"
25 #include "libavutil/avstring.h"
26 #include "libavutil/display.h"
27 #include "libavutil/error.h"
28 #include "libavutil/intreadwrite.h"
29 #include "libavutil/opt.h"
30 #include "libavutil/parseutils.h"
31 #include "libavutil/pixdesc.h"
32 #include "libavutil/time.h"
33 #include "libavutil/timestamp.h"
34 #include "libavutil/thread.h"
35 #include "libavutil/threadmessage.h"
36
37 #include "libavcodec/packet.h"
38
39 #include "libavformat/avformat.h"
40
41 static const char *const opt_name_discard[] = {"discard", NULL};
42 static const char *const opt_name_reinit_filters[] = {"reinit_filter", NULL};
43 static const char *const opt_name_fix_sub_duration[] = {"fix_sub_duration", NULL};
44 static const char *const opt_name_canvas_sizes[] = {"canvas_size", NULL};
45 static const char *const opt_name_guess_layout_max[] = {"guess_layout_max", NULL};
46 static const char *const opt_name_ts_scale[] = {"itsscale", NULL};
47 static const char *const opt_name_hwaccels[] = {"hwaccel", NULL};
48 static const char *const opt_name_hwaccel_devices[] = {"hwaccel_device", NULL};
49 static const char *const opt_name_hwaccel_output_formats[] = {"hwaccel_output_format", NULL};
50 static const char *const opt_name_autorotate[] = {"autorotate", NULL};
51 static const char *const opt_name_display_rotations[] = {"display_rotation", NULL};
52 static const char *const opt_name_display_hflips[] = {"display_hflip", NULL};
53 static const char *const opt_name_display_vflips[] = {"display_vflip", NULL};
54
55 typedef struct Demuxer {
56 InputFile f;
57
58 /* number of times input stream should be looped */
59 int loop;
60 /* actual duration of the longest stream in a file at the moment when
61 * looping happens */
62 int64_t duration;
63 /* time base of the duration */
64 AVRational time_base;
65
66 /* number of streams that the user was warned of */
67 int nb_streams_warn;
68
69 AVThreadMessageQueue *in_thread_queue;
70 int thread_queue_size;
71 pthread_t thread;
72 int non_blocking;
73 } Demuxer;
74
75 typedef struct DemuxMsg {
76 AVPacket *pkt;
77 int looping;
78
79 // repeat_pict from the demuxer-internal parser
80 int repeat_pict;
81 } DemuxMsg;
82
83 460441 static Demuxer *demuxer_from_ifile(InputFile *f)
84 {
85 460441 return (Demuxer*)f;
86 }
87
88 static void report_new_stream(Demuxer *d, const AVPacket *pkt)
89 {
90 AVStream *st = d->f.ctx->streams[pkt->stream_index];
91
92 if (pkt->stream_index < d->nb_streams_warn)
93 return;
94 av_log(NULL, AV_LOG_WARNING,
95 "New %s stream %d:%d at pos:%"PRId64" and DTS:%ss\n",
96 av_get_media_type_string(st->codecpar->codec_type),
97 d->f.index, pkt->stream_index,
98 pkt->pos, av_ts2timestr(pkt->dts, &st->time_base));
99 d->nb_streams_warn = pkt->stream_index + 1;
100 }
101
102 6 static void ifile_duration_update(Demuxer *d, InputStream *ist,
103 int64_t last_duration)
104 {
105 /* the total duration of the stream, max_pts - min_pts is
106 * the duration of the stream without the last frame */
107
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (ist->max_pts > ist->min_pts &&
108
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 ist->max_pts - (uint64_t)ist->min_pts < INT64_MAX - last_duration)
109 6 last_duration += ist->max_pts - ist->min_pts;
110
111
3/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
10 if (!d->duration ||
112 4 av_compare_ts(d->duration, d->time_base,
113 4 last_duration, ist->st->time_base) < 0) {
114 6 d->duration = last_duration;
115 6 d->time_base = ist->st->time_base;
116 }
117 6 }
118
119 6 static int seek_to_start(Demuxer *d)
120 {
121 6 InputFile *ifile = &d->f;
122 6 AVFormatContext *is = ifile->ctx;
123 InputStream *ist;
124 int ret;
125
126 6 ret = avformat_seek_file(is, -1, INT64_MIN, is->start_time, is->start_time, 0);
127
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (ret < 0)
128 return ret;
129
130
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (ifile->audio_duration_queue_size) {
131 /* duration is the length of the last frame in a stream
132 * when audio stream is present we don't care about
133 * last video frame length because it's not defined exactly */
134 int got_durations = 0;
135
136 while (got_durations < ifile->audio_duration_queue_size) {
137 LastFrameDuration dur;
138 ret = av_thread_message_queue_recv(ifile->audio_duration_queue, &dur, 0);
139 if (ret < 0)
140 return ret;
141 got_durations++;
142
143 ist = ifile->streams[dur.stream_idx];
144 ifile_duration_update(d, ist, dur.duration);
145 }
146 } else {
147
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 for (int i = 0; i < ifile->nb_streams; i++) {
148 6 int64_t duration = 0;
149 6 ist = ifile->streams[i];
150
151
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (ist->framerate.num) {
152 duration = av_rescale_q(1, av_inv_q(ist->framerate), ist->st->time_base);
153
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
6 } else if (ist->st->avg_frame_rate.num) {
154 2 duration = av_rescale_q(1, av_inv_q(ist->st->avg_frame_rate), ist->st->time_base);
155 } else {
156 4 duration = 1;
157 }
158
159 6 ifile_duration_update(d, ist, duration);
160 }
161 }
162
163
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (d->loop > 0)
164 6 d->loop--;
165
166 6 return ret;
167 }
168
169 456070 static void ts_fixup(Demuxer *d, AVPacket *pkt, int *repeat_pict)
170 {
171 456070 InputFile *ifile = &d->f;
172 456070 InputStream *ist = ifile->streams[pkt->stream_index];
173 456070 const int64_t start_time = ifile->start_time_effective;
174 int64_t duration;
175
176
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 456070 times.
456070 if (debug_ts) {
177 av_log(NULL, AV_LOG_INFO, "demuxer -> ist_index:%d:%d type:%s "
178 "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s duration:%s duration_time:%s\n",
179 ifile->index, pkt->stream_index,
180 av_get_media_type_string(ist->st->codecpar->codec_type),
181 av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &ist->st->time_base),
182 av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &ist->st->time_base),
183 av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &ist->st->time_base));
184 }
185
186
4/4
✓ Branch 0 taken 403370 times.
✓ Branch 1 taken 52700 times.
✓ Branch 2 taken 270516 times.
✓ Branch 3 taken 132854 times.
456070 if (!ist->wrap_correction_done && start_time != AV_NOPTS_VALUE &&
187
2/2
✓ Branch 0 taken 365 times.
✓ Branch 1 taken 270151 times.
270516 ist->st->pts_wrap_bits < 64) {
188 int64_t stime, stime2;
189
190 365 stime = av_rescale_q(start_time, AV_TIME_BASE_Q, ist->st->time_base);
191 365 stime2= stime + (1ULL<<ist->st->pts_wrap_bits);
192 365 ist->wrap_correction_done = 1;
193
194
5/6
✓ Branch 0 taken 333 times.
✓ Branch 1 taken 32 times.
✓ Branch 2 taken 296 times.
✓ Branch 3 taken 37 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 296 times.
365 if(stime2 > stime && pkt->dts != AV_NOPTS_VALUE && pkt->dts > stime + (1LL<<(ist->st->pts_wrap_bits-1))) {
195 pkt->dts -= 1ULL<<ist->st->pts_wrap_bits;
196 ist->wrap_correction_done = 0;
197 }
198
5/6
✓ Branch 0 taken 333 times.
✓ Branch 1 taken 32 times.
✓ Branch 2 taken 289 times.
✓ Branch 3 taken 44 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 289 times.
365 if(stime2 > stime && pkt->pts != AV_NOPTS_VALUE && pkt->pts > stime + (1LL<<(ist->st->pts_wrap_bits-1))) {
199 pkt->pts -= 1ULL<<ist->st->pts_wrap_bits;
200 ist->wrap_correction_done = 0;
201 }
202 }
203
204
2/2
✓ Branch 0 taken 417591 times.
✓ Branch 1 taken 38479 times.
456070 if (pkt->dts != AV_NOPTS_VALUE)
205 417591 pkt->dts += av_rescale_q(ifile->ts_offset, AV_TIME_BASE_Q, ist->st->time_base);
206
2/2
✓ Branch 0 taken 415485 times.
✓ Branch 1 taken 40585 times.
456070 if (pkt->pts != AV_NOPTS_VALUE)
207 415485 pkt->pts += av_rescale_q(ifile->ts_offset, AV_TIME_BASE_Q, ist->st->time_base);
208
209
2/2
✓ Branch 0 taken 415485 times.
✓ Branch 1 taken 40585 times.
456070 if (pkt->pts != AV_NOPTS_VALUE)
210 415485 pkt->pts *= ist->ts_scale;
211
2/2
✓ Branch 0 taken 417591 times.
✓ Branch 1 taken 38479 times.
456070 if (pkt->dts != AV_NOPTS_VALUE)
212 417591 pkt->dts *= ist->ts_scale;
213
214 456070 duration = av_rescale_q(d->duration, d->time_base, ist->st->time_base);
215
2/2
✓ Branch 0 taken 415485 times.
✓ Branch 1 taken 40585 times.
456070 if (pkt->pts != AV_NOPTS_VALUE) {
216 415485 pkt->pts += duration;
217 415485 ist->max_pts = FFMAX(pkt->pts, ist->max_pts);
218 415485 ist->min_pts = FFMIN(pkt->pts, ist->min_pts);
219 }
220
221
2/2
✓ Branch 0 taken 417591 times.
✓ Branch 1 taken 38479 times.
456070 if (pkt->dts != AV_NOPTS_VALUE)
222 417591 pkt->dts += duration;
223
224 456070 *repeat_pict = -1;
225
4/4
✓ Branch 0 taken 129282 times.
✓ Branch 1 taken 326788 times.
✓ Branch 2 taken 57389 times.
✓ Branch 3 taken 71893 times.
585352 if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
226 129282 av_stream_get_parser(ist->st))
227 57389 *repeat_pict = av_stream_get_parser(ist->st)->repeat_pict;
228 456070 }
229
230 6481 static void thread_set_name(InputFile *f)
231 {
232 char name[16];
233 6481 snprintf(name, sizeof(name), "dmx%d:%s", f->index, f->ctx->iformat->name);
234 6481 ff_thread_setname(name);
235 6481 }
236
237 6481 static void *input_thread(void *arg)
238 {
239 6481 Demuxer *d = arg;
240 6481 InputFile *f = &d->f;
241 AVPacket *pkt;
242 6481 unsigned flags = d->non_blocking ? AV_THREAD_MESSAGE_NONBLOCK : 0;
243 6481 int ret = 0;
244
245 6481 pkt = av_packet_alloc();
246
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6481 times.
6481 if (!pkt) {
247 ret = AVERROR(ENOMEM);
248 goto finish;
249 }
250
251 6481 thread_set_name(f);
252
253 453004 while (1) {
254 459485 DemuxMsg msg = { NULL };
255
256 459485 ret = av_read_frame(f->ctx, pkt);
257
258
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 459484 times.
459485 if (ret == AVERROR(EAGAIN)) {
259 1 av_usleep(10000);
260 7 continue;
261 }
262
2/2
✓ Branch 0 taken 3414 times.
✓ Branch 1 taken 456070 times.
459484 if (ret < 0) {
263
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3408 times.
3414 if (d->loop) {
264 /* signal looping to the consumer thread */
265 6 msg.looping = 1;
266 6 ret = av_thread_message_queue_send(d->in_thread_queue, &msg, 0);
267
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (ret >= 0)
268 6 ret = seek_to_start(d);
269
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (ret >= 0)
270 6 continue;
271
272 /* fallthrough to the error path */
273 }
274
275
2/2
✓ Branch 0 taken 3338 times.
✓ Branch 1 taken 70 times.
3408 if (ret == AVERROR_EOF)
276 3338 av_log(NULL, AV_LOG_VERBOSE, "EOF in input file %d\n", f->index);
277 else
278 70 av_log(NULL, AV_LOG_ERROR, "Error demuxing input file %d: %s\n",
279 70 f->index, av_err2str(ret));
280
281 6481 break;
282 }
283
284
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 456070 times.
456070 if (do_pkt_dump) {
285 av_pkt_dump_log2(NULL, AV_LOG_INFO, pkt, do_hex_dump,
286 f->ctx->streams[pkt->stream_index]);
287 }
288
289 /* the following test is needed in case new streams appear
290 dynamically in stream : we ignore them */
291
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 456070 times.
456070 if (pkt->stream_index >= f->nb_streams) {
292 report_new_stream(d, pkt);
293 av_packet_unref(pkt);
294 continue;
295 }
296
297
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 455962 times.
456070 if (pkt->flags & AV_PKT_FLAG_CORRUPT) {
298 108 av_log(NULL, exit_on_error ? AV_LOG_FATAL : AV_LOG_WARNING,
299 "%s: corrupt input packet in stream %d\n",
300
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 f->ctx->url, pkt->stream_index);
301
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 if (exit_on_error) {
302 av_packet_unref(pkt);
303 ret = AVERROR_INVALIDDATA;
304 break;
305 }
306 }
307
308 456070 ts_fixup(d, pkt, &msg.repeat_pict);
309
310 456070 msg.pkt = av_packet_alloc();
311
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 456070 times.
456070 if (!msg.pkt) {
312 av_packet_unref(pkt);
313 ret = AVERROR(ENOMEM);
314 break;
315 }
316 456070 av_packet_move_ref(msg.pkt, pkt);
317 456070 ret = av_thread_message_queue_send(d->in_thread_queue, &msg, flags);
318
4/4
✓ Branch 0 taken 495 times.
✓ Branch 1 taken 455575 times.
✓ Branch 2 taken 55 times.
✓ Branch 3 taken 440 times.
456070 if (flags && ret == AVERROR(EAGAIN)) {
319 55 flags = 0;
320 55 ret = av_thread_message_queue_send(d->in_thread_queue, &msg, flags);
321 55 av_log(f->ctx, AV_LOG_WARNING,
322 "Thread message queue blocking; consider raising the "
323 "thread_queue_size option (current value: %d)\n",
324 d->thread_queue_size);
325 }
326
2/2
✓ Branch 0 taken 3073 times.
✓ Branch 1 taken 452997 times.
456070 if (ret < 0) {
327
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3073 times.
3073 if (ret != AVERROR_EOF)
328 av_log(f->ctx, AV_LOG_ERROR,
329 "Unable to send packet to main thread: %s\n",
330 av_err2str(ret));
331 3073 av_packet_free(&msg.pkt);
332 3073 break;
333 }
334 }
335
336 6481 finish:
337
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6481 times.
6481 av_assert0(ret < 0);
338 6481 av_thread_message_queue_set_err_recv(d->in_thread_queue, ret);
339
340 6481 av_packet_free(&pkt);
341
342 6481 av_log(NULL, AV_LOG_VERBOSE, "Terminating demuxer thread %d\n", f->index);
343
344 6481 return NULL;
345 }
346
347 6494 static void thread_stop(Demuxer *d)
348 {
349 6494 InputFile *f = &d->f;
350 DemuxMsg msg;
351
352
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 6481 times.
6494 if (!d->in_thread_queue)
353 13 return;
354 6481 av_thread_message_queue_set_err_send(d->in_thread_queue, AVERROR_EOF);
355
2/2
✓ Branch 1 taken 3651 times.
✓ Branch 2 taken 6481 times.
10132 while (av_thread_message_queue_recv(d->in_thread_queue, &msg, 0) >= 0)
356 3651 av_packet_free(&msg.pkt);
357
358 6481 pthread_join(d->thread, NULL);
359 6481 av_thread_message_queue_free(&d->in_thread_queue);
360 6481 av_thread_message_queue_free(&f->audio_duration_queue);
361 }
362
363 6481 static int thread_start(Demuxer *d)
364 {
365 int ret;
366 6481 InputFile *f = &d->f;
367
368
1/2
✓ Branch 0 taken 6481 times.
✗ Branch 1 not taken.
6481 if (d->thread_queue_size <= 0)
369
2/2
✓ Branch 0 taken 146 times.
✓ Branch 1 taken 6335 times.
6481 d->thread_queue_size = (nb_input_files > 1 ? 8 : 1);
370
371
4/4
✓ Branch 0 taken 146 times.
✓ Branch 1 taken 6335 times.
✓ Branch 2 taken 55 times.
✓ Branch 3 taken 91 times.
6627 if (nb_input_files > 1 &&
372
2/2
✓ Branch 0 taken 84 times.
✓ Branch 1 taken 62 times.
146 (f->ctx->pb ? !f->ctx->pb->seekable :
373 62 strcmp(f->ctx->iformat->name, "lavfi")))
374 55 d->non_blocking = 1;
375 6481 ret = av_thread_message_queue_alloc(&d->in_thread_queue,
376 6481 d->thread_queue_size, sizeof(DemuxMsg));
377
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6481 times.
6481 if (ret < 0)
378 return ret;
379
380
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6479 times.
6481 if (d->loop) {
381 2 int nb_audio_dec = 0;
382
383
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 for (int i = 0; i < f->nb_streams; i++) {
384 2 InputStream *ist = f->streams[i];
385
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 nb_audio_dec += !!(ist->decoding_needed &&
386 ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO);
387 }
388
389
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (nb_audio_dec) {
390 ret = av_thread_message_queue_alloc(&f->audio_duration_queue,
391 nb_audio_dec, sizeof(LastFrameDuration));
392 if (ret < 0)
393 goto fail;
394 f->audio_duration_queue_size = nb_audio_dec;
395 }
396 }
397
398
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6481 times.
6481 if ((ret = pthread_create(&d->thread, NULL, input_thread, d))) {
399 av_log(NULL, AV_LOG_ERROR, "pthread_create failed: %s. Try to increase `ulimit -v` or decrease `ulimit -s`.\n", strerror(ret));
400 ret = AVERROR(ret);
401 goto fail;
402 }
403
404 6481 return 0;
405 fail:
406 av_thread_message_queue_free(&d->in_thread_queue);
407 return ret;
408 }
409
410 453947 int ifile_get_packet(InputFile *f, AVPacket **pkt)
411 {
412 453947 Demuxer *d = demuxer_from_ifile(f);
413 InputStream *ist;
414 DemuxMsg msg;
415 int ret;
416
417
2/2
✓ Branch 0 taken 6481 times.
✓ Branch 1 taken 447466 times.
453947 if (!d->in_thread_queue) {
418 6481 ret = thread_start(d);
419
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6481 times.
6481 if (ret < 0)
420 return ret;
421 }
422
423
3/4
✓ Branch 0 taken 453947 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 704 times.
✓ Branch 3 taken 453243 times.
453947 if (f->readrate || f->rate_emu) {
424 int i;
425 1408 int64_t file_start = copy_ts * (
426
1/2
✓ Branch 0 taken 704 times.
✗ Branch 1 not taken.
704 (f->start_time_effective != AV_NOPTS_VALUE ? f->start_time_effective * !start_at_zero : 0) +
427
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 704 times.
704 (f->start_time != AV_NOPTS_VALUE ? f->start_time : 0)
428 );
429
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 704 times.
704 float scale = f->rate_emu ? 1.0 : f->readrate;
430
2/2
✓ Branch 0 taken 704 times.
✓ Branch 1 taken 217 times.
921 for (i = 0; i < f->nb_streams; i++) {
431 704 InputStream *ist = f->streams[i];
432 int64_t stream_ts_offset, pts, now;
433
4/6
✓ Branch 0 taken 703 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 703 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 703 times.
704 if (!ist->nb_packets || (ist->decoding_needed && !ist->got_output)) continue;
434
1/2
✓ Branch 0 taken 703 times.
✗ Branch 1 not taken.
703 stream_ts_offset = FFMAX(ist->first_dts != AV_NOPTS_VALUE ? ist->first_dts : 0, file_start);
435 703 pts = av_rescale(ist->dts, 1000000, AV_TIME_BASE);
436 703 now = (av_gettime_relative() - ist->start) * scale + stream_ts_offset;
437
2/2
✓ Branch 0 taken 487 times.
✓ Branch 1 taken 216 times.
703 if (pts > now)
438 487 return AVERROR(EAGAIN);
439 }
440 }
441
442 453460 ret = av_thread_message_queue_recv(d->in_thread_queue, &msg,
443 453460 d->non_blocking ?
444 AV_THREAD_MESSAGE_NONBLOCK : 0);
445
2/2
✓ Branch 0 taken 4108 times.
✓ Branch 1 taken 449352 times.
453460 if (ret < 0)
446 4108 return ret;
447
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 449346 times.
449352 if (msg.looping)
448 6 return 1;
449
450 449346 ist = f->streams[msg.pkt->stream_index];
451 449346 ist->last_pkt_repeat_pict = msg.repeat_pict;
452
453 449346 *pkt = msg.pkt;
454 449346 return 0;
455 }
456
457 6937 static void ist_free(InputStream **pist)
458 {
459 6937 InputStream *ist = *pist;
460
461
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6937 times.
6937 if (!ist)
462 return;
463
464 6937 av_frame_free(&ist->decoded_frame);
465 6937 av_packet_free(&ist->pkt);
466 6937 av_dict_free(&ist->decoder_opts);
467 6937 avsubtitle_free(&ist->prev_sub.subtitle);
468 6937 av_frame_free(&ist->sub2video.frame);
469 6937 av_freep(&ist->filters);
470 6937 av_freep(&ist->hwaccel_device);
471 6937 av_freep(&ist->dts_buffer);
472
473 6937 avcodec_free_context(&ist->dec_ctx);
474 6937 avcodec_parameters_free(&ist->par);
475
476 6937 av_freep(pist);
477 }
478
479 6494 void ifile_close(InputFile **pf)
480 {
481 6494 InputFile *f = *pf;
482 6494 Demuxer *d = demuxer_from_ifile(f);
483
484
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6494 times.
6494 if (!f)
485 return;
486
487 6494 thread_stop(d);
488
489
2/2
✓ Branch 0 taken 6937 times.
✓ Branch 1 taken 6494 times.
13431 for (int i = 0; i < f->nb_streams; i++)
490 6937 ist_free(&f->streams[i]);
491 6494 av_freep(&f->streams);
492
493 6494 avformat_close_input(&f->ctx);
494
495 6494 av_freep(pf);
496 }
497
498 13754 static const AVCodec *choose_decoder(const OptionsContext *o, AVFormatContext *s, AVStream *st,
499 enum HWAccelID hwaccel_id, enum AVHWDeviceType hwaccel_device_type)
500
501 {
502 13754 char *codec_name = NULL;
503
504
6/20
✓ Branch 1 taken 5302 times.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8 times.
✓ Branch 6 taken 5310 times.
✓ Branch 7 taken 13754 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 13754 times.
✗ 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 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
19064 MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, st);
505
2/2
✓ Branch 0 taken 5302 times.
✓ Branch 1 taken 8452 times.
13754 if (codec_name) {
506 5302 const AVCodec *codec = find_codec_or_die(codec_name, st->codecpar->codec_type, 0);
507 5302 st->codecpar->codec_id = codec->id;
508
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 5302 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
5302 if (recast_media && st->codecpar->codec_type != codec->type)
509 st->codecpar->codec_type = codec->type;
510 5302 return codec;
511 } else {
512
3/4
✓ Branch 0 taken 5230 times.
✓ Branch 1 taken 3222 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5230 times.
8452 if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
513 hwaccel_id == HWACCEL_GENERIC &&
514 hwaccel_device_type != AV_HWDEVICE_TYPE_NONE) {
515 const AVCodec *c;
516 void *i = NULL;
517
518 while ((c = av_codec_iterate(&i))) {
519 const AVCodecHWConfig *config;
520
521 if (c->id != st->codecpar->codec_id ||
522 !av_codec_is_decoder(c))
523 continue;
524
525 for (int j = 0; config = avcodec_get_hw_config(c, j); j++) {
526 if (config->device_type == hwaccel_device_type) {
527 av_log(NULL, AV_LOG_VERBOSE, "Selecting decoder '%s' because of requested hwaccel method %s\n",
528 c->name, av_hwdevice_get_type_name(hwaccel_device_type));
529 return c;
530 }
531 }
532 }
533 }
534
535 8452 return avcodec_find_decoder(st->codecpar->codec_id);
536 }
537 }
538
539 1549 static int guess_input_channel_layout(InputStream *ist)
540 {
541 1549 AVCodecContext *dec = ist->dec_ctx;
542
543
2/2
✓ Branch 0 taken 800 times.
✓ Branch 1 taken 749 times.
1549 if (dec->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) {
544 char layout_name[256];
545
546
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 796 times.
800 if (dec->ch_layout.nb_channels > ist->guess_layout_max)
547 12 return 0;
548 796 av_channel_layout_default(&dec->ch_layout, dec->ch_layout.nb_channels);
549
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 788 times.
796 if (dec->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC)
550 8 return 0;
551 788 av_channel_layout_describe(&dec->ch_layout, layout_name, sizeof(layout_name));
552 788 av_log(NULL, AV_LOG_WARNING, "Guessed Channel Layout for Input Stream "
553 788 "#%d.%d : %s\n", ist->file_index, ist->st->index, layout_name);
554 }
555 1537 return 1;
556 }
557
558 5256 static void add_display_matrix_to_stream(const OptionsContext *o,
559 AVFormatContext *ctx, AVStream *st)
560 {
561 5256 double rotation = DBL_MAX;
562 5256 int hflip = -1, vflip = -1;
563 5256 int hflip_set = 0, vflip_set = 0, rotation_set = 0;
564 int32_t *buf;
565
566
4/20
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 5256 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 5256 times.
✗ 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 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
5257 MATCH_PER_STREAM_OPT(display_rotations, dbl, rotation, ctx, st);
567
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 5256 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 5256 times.
✗ 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 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
5256 MATCH_PER_STREAM_OPT(display_hflips, i, hflip, ctx, st);
568
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 5256 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 5256 times.
✗ 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 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
5256 MATCH_PER_STREAM_OPT(display_vflips, i, vflip, ctx, st);
569
570 5256 rotation_set = rotation != DBL_MAX;
571 5256 hflip_set = hflip != -1;
572 5256 vflip_set = vflip != -1;
573
574
4/6
✓ Branch 0 taken 5255 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 5255 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5255 times.
✗ Branch 5 not taken.
5256 if (!rotation_set && !hflip_set && !vflip_set)
575 5255 return;
576
577 1 buf = (int32_t *)av_stream_new_side_data(st, AV_PKT_DATA_DISPLAYMATRIX, sizeof(int32_t) * 9);
578
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!buf) {
579 av_log(NULL, AV_LOG_FATAL, "Failed to generate a display matrix!\n");
580 exit_program(1);
581 }
582
583
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 av_display_rotation_set(buf,
584 rotation_set ? -(rotation) : -0.0f);
585
586
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,
587 hflip_set ? hflip : 0,
588 vflip_set ? vflip : 0);
589 }
590
591 /* Add all the streams from the given input file to the demuxer */
592 6494 static void add_input_streams(const OptionsContext *o, Demuxer *d)
593 {
594 6494 InputFile *f = &d->f;
595 6494 AVFormatContext *ic = f->ctx;
596 int i, ret;
597
598
2/2
✓ Branch 0 taken 6937 times.
✓ Branch 1 taken 6494 times.
13431 for (i = 0; i < ic->nb_streams; i++) {
599 6937 AVStream *st = ic->streams[i];
600 6937 AVCodecParameters *par = st->codecpar;
601 InputStream *ist;
602 6937 char *framerate = NULL, *hwaccel_device = NULL;
603 6937 const char *hwaccel = NULL;
604 6937 char *hwaccel_output_format = NULL;
605 6937 char *codec_tag = NULL;
606 char *next;
607 6937 char *discard_str = NULL;
608 6937 const AVClass *cc = avcodec_get_class();
609 6937 const AVOption *discard_opt = av_opt_find(&cc, "skip_frame", NULL,
610 0, AV_OPT_SEARCH_FAKE_OBJ);
611
612 6937 ist = ALLOC_ARRAY_ELEM(f->streams, f->nb_streams);
613 6937 ist->st = st;
614 6937 ist->file_index = f->index;
615 6937 ist->discard = 1;
616 6937 st->discard = AVDISCARD_ALL;
617 6937 ist->nb_samples = 0;
618 6937 ist->first_dts = AV_NOPTS_VALUE;
619 6937 ist->min_pts = INT64_MAX;
620 6937 ist->max_pts = INT64_MIN;
621
622 6937 ist->ts_scale = 1.0;
623
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 6937 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 6937 times.
✗ 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 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
6937 MATCH_PER_STREAM_OPT(ts_scale, dbl, ist->ts_scale, ic, st);
624
625 6937 ist->autorotate = 1;
626
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 6937 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 6937 times.
✗ 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 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
6937 MATCH_PER_STREAM_OPT(autorotate, i, ist->autorotate, ic, st);
627
628
4/20
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 6937 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 6937 times.
✗ 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 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
6939 MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, ic, st);
629
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6935 times.
6937 if (codec_tag) {
630 2 uint32_t tag = strtol(codec_tag, &next, 0);
631
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (*next)
632 2 tag = AV_RL32(codec_tag);
633 2 st->codecpar->codec_tag = tag;
634 }
635
636
2/2
✓ Branch 0 taken 5256 times.
✓ Branch 1 taken 1681 times.
6937 if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
637 5256 add_display_matrix_to_stream(o, ic, st);
638
639
4/20
✓ Branch 1 taken 4976 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 6 taken 4976 times.
✓ Branch 7 taken 5256 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 5256 times.
✗ 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 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
10232 MATCH_PER_STREAM_OPT(hwaccels, str, hwaccel, ic, st);
640
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 5256 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 5256 times.
✗ 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 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
5256 MATCH_PER_STREAM_OPT(hwaccel_output_formats, str,
641 hwaccel_output_format, ic, st);
642
643
4/6
✓ Branch 0 taken 5256 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4976 times.
✓ Branch 3 taken 280 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4976 times.
5256 if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "cuvid")) {
644 av_log(NULL, AV_LOG_WARNING,
645 "WARNING: defaulting hwaccel_output_format to cuda for compatibility "
646 "with old commandlines. This behaviour is DEPRECATED and will be removed "
647 "in the future. Please explicitly set \"-hwaccel_output_format cuda\".\n");
648 ist->hwaccel_output_format = AV_PIX_FMT_CUDA;
649
4/6
✓ Branch 0 taken 5256 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4976 times.
✓ Branch 3 taken 280 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4976 times.
5256 } else if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "qsv")) {
650 av_log(NULL, AV_LOG_WARNING,
651 "WARNING: defaulting hwaccel_output_format to qsv for compatibility "
652 "with old commandlines. This behaviour is DEPRECATED and will be removed "
653 "in the future. Please explicitly set \"-hwaccel_output_format qsv\".\n");
654 ist->hwaccel_output_format = AV_PIX_FMT_QSV;
655
4/6
✓ Branch 0 taken 5256 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4976 times.
✓ Branch 3 taken 280 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4976 times.
5256 } else if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "mediacodec")) {
656 // There is no real AVHWFrameContext implementation. Set
657 // hwaccel_output_format to avoid av_hwframe_transfer_data error.
658 ist->hwaccel_output_format = AV_PIX_FMT_MEDIACODEC;
659
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5256 times.
5256 } else if (hwaccel_output_format) {
660 ist->hwaccel_output_format = av_get_pix_fmt(hwaccel_output_format);
661 if (ist->hwaccel_output_format == AV_PIX_FMT_NONE) {
662 av_log(NULL, AV_LOG_FATAL, "Unrecognised hwaccel output "
663 "format: %s", hwaccel_output_format);
664 }
665 } else {
666 5256 ist->hwaccel_output_format = AV_PIX_FMT_NONE;
667 }
668
669
2/2
✓ Branch 0 taken 4976 times.
✓ Branch 1 taken 280 times.
5256 if (hwaccel) {
670 // The NVDEC hwaccels use a CUDA device, so remap the name here.
671
2/4
✓ Branch 0 taken 4976 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4976 times.
4976 if (!strcmp(hwaccel, "nvdec") || !strcmp(hwaccel, "cuvid"))
672 hwaccel = "cuda";
673
674
1/2
✓ Branch 0 taken 4976 times.
✗ Branch 1 not taken.
4976 if (!strcmp(hwaccel, "none"))
675 4976 ist->hwaccel_id = HWACCEL_NONE;
676 else if (!strcmp(hwaccel, "auto"))
677 ist->hwaccel_id = HWACCEL_AUTO;
678 else {
679 enum AVHWDeviceType type = av_hwdevice_find_type_by_name(hwaccel);
680 if (type != AV_HWDEVICE_TYPE_NONE) {
681 ist->hwaccel_id = HWACCEL_GENERIC;
682 ist->hwaccel_device_type = type;
683 }
684
685 if (!ist->hwaccel_id) {
686 av_log(NULL, AV_LOG_FATAL, "Unrecognized hwaccel: %s.\n",
687 hwaccel);
688 av_log(NULL, AV_LOG_FATAL, "Supported hwaccels: ");
689 type = AV_HWDEVICE_TYPE_NONE;
690 while ((type = av_hwdevice_iterate_types(type)) !=
691 AV_HWDEVICE_TYPE_NONE)
692 av_log(NULL, AV_LOG_FATAL, "%s ",
693 av_hwdevice_get_type_name(type));
694 av_log(NULL, AV_LOG_FATAL, "\n");
695 exit_program(1);
696 }
697 }
698 }
699
700
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 5256 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 5256 times.
✗ 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 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
5256 MATCH_PER_STREAM_OPT(hwaccel_devices, str, hwaccel_device, ic, st);
701
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5256 times.
5256 if (hwaccel_device) {
702 ist->hwaccel_device = av_strdup(hwaccel_device);
703 if (!ist->hwaccel_device)
704 report_and_exit(AVERROR(ENOMEM));
705 }
706
707 5256 ist->hwaccel_pix_fmt = AV_PIX_FMT_NONE;
708 }
709
710 6937 ist->dec = choose_decoder(o, ic, st, ist->hwaccel_id, ist->hwaccel_device_type);
711 6937 ist->decoder_opts = filter_codec_opts(o->g->codec_opts, ist->st->codecpar->codec_id, ic, st, ist->dec);
712
713 6937 ist->reinit_filters = -1;
714
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 6937 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 6937 times.
✗ 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 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
6937 MATCH_PER_STREAM_OPT(reinit_filters, i, ist->reinit_filters, ic, st);
715
716
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 6937 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 6937 times.
✗ 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 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
6937 MATCH_PER_STREAM_OPT(discard, str, discard_str, ic, st);
717 6937 ist->user_set_discard = AVDISCARD_NONE;
718
719
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6937 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6937 if ((o->video_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) ||
720
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6937 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6937 (o->audio_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) ||
721
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6937 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6937 (o->subtitle_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) ||
722
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6937 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6937 (o->data_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_DATA))
723 ist->user_set_discard = AVDISCARD_ALL;
724
725
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6937 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
6937 if (discard_str && av_opt_eval_int(&cc, discard_opt, discard_str, &ist->user_set_discard) < 0) {
726 av_log(NULL, AV_LOG_ERROR, "Error parsing discard %s.\n",
727 discard_str);
728 exit_program(1);
729 }
730
731 6937 ist->filter_in_rescale_delta_last = AV_NOPTS_VALUE;
732 6937 ist->prev_pkt_pts = AV_NOPTS_VALUE;
733
734 6937 ist->dec_ctx = avcodec_alloc_context3(ist->dec);
735
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6937 times.
6937 if (!ist->dec_ctx)
736 report_and_exit(AVERROR(ENOMEM));
737
738 6937 ret = avcodec_parameters_to_context(ist->dec_ctx, par);
739
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6937 times.
6937 if (ret < 0) {
740 av_log(NULL, AV_LOG_ERROR, "Error initializing the decoder context.\n");
741 exit_program(1);
742 }
743
744 6937 ist->decoded_frame = av_frame_alloc();
745
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6937 times.
6937 if (!ist->decoded_frame)
746 report_and_exit(AVERROR(ENOMEM));
747
748 6937 ist->pkt = av_packet_alloc();
749
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6937 times.
6937 if (!ist->pkt)
750 report_and_exit(AVERROR(ENOMEM));
751
752
2/2
✓ Branch 0 taken 91 times.
✓ Branch 1 taken 6846 times.
6937 if (o->bitexact)
753 91 ist->dec_ctx->flags |= AV_CODEC_FLAG_BITEXACT;
754
755
4/5
✓ Branch 0 taken 5256 times.
✓ Branch 1 taken 1549 times.
✓ Branch 2 taken 131 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
6937 switch (par->codec_type) {
756 5256 case AVMEDIA_TYPE_VIDEO:
757 // avformat_find_stream_info() doesn't set this for us anymore.
758 5256 ist->dec_ctx->framerate = st->avg_frame_rate;
759
760
4/20
✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 6 taken 25 times.
✓ Branch 7 taken 5256 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 5256 times.
✗ 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 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
5281 MATCH_PER_STREAM_OPT(frame_rates, str, framerate, ic, st);
761
3/4
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 5231 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 25 times.
5256 if (framerate && av_parse_video_rate(&ist->framerate,
762 framerate) < 0) {
763 av_log(NULL, AV_LOG_ERROR, "Error parsing framerate %s.\n",
764 framerate);
765 exit_program(1);
766 }
767
768 5256 ist->top_field_first = -1;
769
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 5256 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 5256 times.
✗ 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 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
5256 MATCH_PER_STREAM_OPT(top_field_first, i, ist->top_field_first, ic, st);
770
771 5256 ist->framerate_guessed = av_guess_frame_rate(ic, st, NULL);
772
773 5256 break;
774 1549 case AVMEDIA_TYPE_AUDIO:
775 1549 ist->guess_layout_max = INT_MAX;
776
4/20
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 6 taken 4 times.
✓ Branch 7 taken 1549 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 1549 times.
✗ 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 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
1553 MATCH_PER_STREAM_OPT(guess_layout_max, i, ist->guess_layout_max, ic, st);
777 1549 guess_input_channel_layout(ist);
778 1549 break;
779 131 case AVMEDIA_TYPE_DATA:
780 case AVMEDIA_TYPE_SUBTITLE: {
781 131 char *canvas_size = NULL;
782
4/20
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 131 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 131 times.
✗ 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 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
132 MATCH_PER_STREAM_OPT(fix_sub_duration, i, ist->fix_sub_duration, ic, st);
783
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 131 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 131 times.
✗ 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 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
131 MATCH_PER_STREAM_OPT(canvas_sizes, str, canvas_size, ic, st);
784
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 131 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
131 if (canvas_size &&
785 av_parse_video_size(&ist->dec_ctx->width, &ist->dec_ctx->height, canvas_size) < 0) {
786 av_log(NULL, AV_LOG_FATAL, "Invalid canvas size: %s.\n", canvas_size);
787 exit_program(1);
788 }
789 131 break;
790 }
791 1 case AVMEDIA_TYPE_ATTACHMENT:
792 case AVMEDIA_TYPE_UNKNOWN:
793 1 break;
794 default:
795 abort();
796 }
797
798 6937 ist->par = avcodec_parameters_alloc();
799
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6937 times.
6937 if (!ist->par)
800 report_and_exit(AVERROR(ENOMEM));
801
802 6937 ret = avcodec_parameters_from_context(ist->par, ist->dec_ctx);
803
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6937 times.
6937 if (ret < 0) {
804 av_log(NULL, AV_LOG_ERROR, "Error initializing the decoder context.\n");
805 exit_program(1);
806 }
807 }
808 6494 }
809
810 static void dump_attachment(AVStream *st, const char *filename)
811 {
812 int ret;
813 AVIOContext *out = NULL;
814 const AVDictionaryEntry *e;
815
816 if (!st->codecpar->extradata_size) {
817 av_log(NULL, AV_LOG_WARNING, "No extradata to dump in stream #%d:%d.\n",
818 nb_input_files - 1, st->index);
819 return;
820 }
821 if (!*filename && (e = av_dict_get(st->metadata, "filename", NULL, 0)))
822 filename = e->value;
823 if (!*filename) {
824 av_log(NULL, AV_LOG_FATAL, "No filename specified and no 'filename' tag"
825 "in stream #%d:%d.\n", nb_input_files - 1, st->index);
826 exit_program(1);
827 }
828
829 assert_file_overwrite(filename);
830
831 if ((ret = avio_open2(&out, filename, AVIO_FLAG_WRITE, &int_cb, NULL)) < 0) {
832 av_log(NULL, AV_LOG_FATAL, "Could not open file %s for writing.\n",
833 filename);
834 exit_program(1);
835 }
836
837 avio_write(out, st->codecpar->extradata, st->codecpar->extradata_size);
838 avio_flush(out);
839 avio_close(out);
840 }
841
842 6494 int ifile_open(const OptionsContext *o, const char *filename)
843 {
844 Demuxer *d;
845 InputFile *f;
846 AVFormatContext *ic;
847 6494 const AVInputFormat *file_iformat = NULL;
848 int err, i, ret;
849 int64_t timestamp;
850 6494 AVDictionary *unused_opts = NULL;
851 6494 const AVDictionaryEntry *e = NULL;
852 6494 char * video_codec_name = NULL;
853 6494 char * audio_codec_name = NULL;
854 6494 char *subtitle_codec_name = NULL;
855 6494 char * data_codec_name = NULL;
856 6494 int scan_all_pmts_set = 0;
857
858 6494 int64_t start_time = o->start_time;
859 6494 int64_t start_time_eof = o->start_time_eof;
860 6494 int64_t stop_time = o->stop_time;
861 6494 int64_t recording_time = o->recording_time;
862
863
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6494 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6494 if (stop_time != INT64_MAX && recording_time != INT64_MAX) {
864 stop_time = INT64_MAX;
865 av_log(NULL, AV_LOG_WARNING, "-t and -to cannot be used together; using -t.\n");
866 }
867
868
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6494 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6494 if (stop_time != INT64_MAX && recording_time == INT64_MAX) {
869 int64_t start = start_time == AV_NOPTS_VALUE ? 0 : start_time;
870 if (stop_time <= start) {
871 av_log(NULL, AV_LOG_ERROR, "-to value smaller than -ss; aborting.\n");
872 exit_program(1);
873 } else {
874 recording_time = stop_time - start;
875 }
876 }
877
878
2/2
✓ Branch 0 taken 3216 times.
✓ Branch 1 taken 3278 times.
6494 if (o->format) {
879
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3216 times.
3216 if (!(file_iformat = av_find_input_format(o->format))) {
880 av_log(NULL, AV_LOG_FATAL, "Unknown input format: '%s'\n", o->format);
881 exit_program(1);
882 }
883 }
884
885
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6494 times.
6494 if (!strcmp(filename, "-"))
886 filename = "fd:";
887
888 19482 stdin_interaction &= strncmp(filename, "pipe:", 5) &&
889
2/4
✓ Branch 0 taken 6494 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6494 times.
✗ Branch 3 not taken.
12988 strcmp(filename, "fd:") &&
890
1/2
✓ Branch 0 taken 6494 times.
✗ Branch 1 not taken.
6494 strcmp(filename, "/dev/stdin");
891
892 /* get default parameters from command line */
893 6494 ic = avformat_alloc_context();
894
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6494 times.
6494 if (!ic)
895 report_and_exit(AVERROR(ENOMEM));
896
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 6430 times.
6494 if (o->nb_audio_sample_rate) {
897 64 av_dict_set_int(&o->g->format_opts, "sample_rate", o->audio_sample_rate[o->nb_audio_sample_rate - 1].u.i, 0);
898 }
899
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 6486 times.
6494 if (o->nb_audio_channels) {
900 const AVClass *priv_class;
901
3/6
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
16 if (file_iformat && (priv_class = file_iformat->priv_class) &&
902 8 av_opt_find(&priv_class, "ch_layout", NULL, 0,
903 AV_OPT_SEARCH_FAKE_OBJ)) {
904 char buf[32];
905 8 snprintf(buf, sizeof(buf), "%dC", o->audio_channels[o->nb_audio_channels - 1].u.i);
906 8 av_dict_set(&o->g->format_opts, "ch_layout", buf, 0);
907 }
908 }
909
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6493 times.
6494 if (o->nb_audio_ch_layouts) {
910 const AVClass *priv_class;
911
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) &&
912 1 av_opt_find(&priv_class, "ch_layout", NULL, 0,
913 AV_OPT_SEARCH_FAKE_OBJ)) {
914 1 av_dict_set(&o->g->format_opts, "ch_layout", o->audio_ch_layouts[o->nb_audio_ch_layouts - 1].u.str, 0);
915 }
916 }
917
2/2
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 6469 times.
6494 if (o->nb_frame_rates) {
918 const AVClass *priv_class;
919 /* set the format-level framerate option;
920 * this is important for video grabbers, e.g. x11 */
921
3/6
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 25 times.
✗ Branch 5 not taken.
50 if (file_iformat && (priv_class = file_iformat->priv_class) &&
922 25 av_opt_find(&priv_class, "framerate", NULL, 0,
923 AV_OPT_SEARCH_FAKE_OBJ)) {
924 25 av_dict_set(&o->g->format_opts, "framerate",
925 25 o->frame_rates[o->nb_frame_rates - 1].u.str, 0);
926 }
927 }
928
2/2
✓ Branch 0 taken 514 times.
✓ Branch 1 taken 5980 times.
6494 if (o->nb_frame_sizes) {
929 514 av_dict_set(&o->g->format_opts, "video_size", o->frame_sizes[o->nb_frame_sizes - 1].u.str, 0);
930 }
931
2/2
✓ Branch 0 taken 523 times.
✓ Branch 1 taken 5971 times.
6494 if (o->nb_frame_pix_fmts)
932 523 av_dict_set(&o->g->format_opts, "pixel_format", o->frame_pix_fmts[o->nb_frame_pix_fmts - 1].u.str, 0);
933
934
4/4
✓ Branch 0 taken 2617 times.
✓ Branch 1 taken 34 times.
✓ Branch 2 taken 2651 times.
✓ Branch 3 taken 6494 times.
9145 MATCH_PER_TYPE_OPT(codec_names, str, video_codec_name, ic, "v");
935
4/4
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 2634 times.
✓ Branch 2 taken 2651 times.
✓ Branch 3 taken 6494 times.
9145 MATCH_PER_TYPE_OPT(codec_names, str, audio_codec_name, ic, "a");
936
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2651 times.
✓ Branch 2 taken 2651 times.
✓ Branch 3 taken 6494 times.
9145 MATCH_PER_TYPE_OPT(codec_names, str, subtitle_codec_name, ic, "s");
937
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2651 times.
✓ Branch 2 taken 2651 times.
✓ Branch 3 taken 6494 times.
9145 MATCH_PER_TYPE_OPT(codec_names, str, data_codec_name, ic, "d");
938
939
2/2
✓ Branch 0 taken 2617 times.
✓ Branch 1 taken 3877 times.
6494 if (video_codec_name)
940 2617 ic->video_codec = find_codec_or_die(video_codec_name , AVMEDIA_TYPE_VIDEO , 0);
941
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 6477 times.
6494 if (audio_codec_name)
942 17 ic->audio_codec = find_codec_or_die(audio_codec_name , AVMEDIA_TYPE_AUDIO , 0);
943
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6494 times.
6494 if (subtitle_codec_name)
944 ic->subtitle_codec = find_codec_or_die(subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, 0);
945
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6494 times.
6494 if (data_codec_name)
946 ic->data_codec = find_codec_or_die(data_codec_name , AVMEDIA_TYPE_DATA , 0);
947
948
2/2
✓ Branch 0 taken 2617 times.
✓ Branch 1 taken 3877 times.
6494 ic->video_codec_id = video_codec_name ? ic->video_codec->id : AV_CODEC_ID_NONE;
949
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 6477 times.
6494 ic->audio_codec_id = audio_codec_name ? ic->audio_codec->id : AV_CODEC_ID_NONE;
950
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6494 times.
6494 ic->subtitle_codec_id = subtitle_codec_name ? ic->subtitle_codec->id : AV_CODEC_ID_NONE;
951
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6494 times.
6494 ic->data_codec_id = data_codec_name ? ic->data_codec->id : AV_CODEC_ID_NONE;
952
953 6494 ic->flags |= AVFMT_FLAG_NONBLOCK;
954
2/2
✓ Branch 0 taken 81 times.
✓ Branch 1 taken 6413 times.
6494 if (o->bitexact)
955 81 ic->flags |= AVFMT_FLAG_BITEXACT;
956 6494 ic->interrupt_callback = int_cb;
957
958
1/2
✓ Branch 1 taken 6494 times.
✗ Branch 2 not taken.
6494 if (!av_dict_get(o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE)) {
959 6494 av_dict_set(&o->g->format_opts, "scan_all_pmts", "1", AV_DICT_DONT_OVERWRITE);
960 6494 scan_all_pmts_set = 1;
961 }
962 /* open the input file with generic avformat function */
963 6494 err = avformat_open_input(&ic, filename, file_iformat, &o->g->format_opts);
964
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6494 times.
6494 if (err < 0) {
965 print_error(filename, err);
966 if (err == AVERROR_PROTOCOL_NOT_FOUND)
967 av_log(NULL, AV_LOG_ERROR, "Did you mean file:%s?\n", filename);
968 exit_program(1);
969 }
970
1/2
✓ Branch 0 taken 6494 times.
✗ Branch 1 not taken.
6494 if (scan_all_pmts_set)
971 6494 av_dict_set(&o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
972 6494 remove_avoptions(&o->g->format_opts, o->g->codec_opts);
973 6494 assert_avoptions(o->g->format_opts);
974
975 /* apply forced codec ids */
976
2/2
✓ Branch 0 taken 6817 times.
✓ Branch 1 taken 6494 times.
13311 for (i = 0; i < ic->nb_streams; i++)
977 6817 choose_decoder(o, ic, ic->streams[i], HWACCEL_NONE, AV_HWDEVICE_TYPE_NONE);
978
979
2/2
✓ Branch 0 taken 6492 times.
✓ Branch 1 taken 2 times.
6494 if (o->find_stream_info) {
980 6492 AVDictionary **opts = setup_find_stream_info_opts(ic, o->g->codec_opts);
981 6492 int orig_nb_streams = ic->nb_streams;
982
983 /* If not enough info to get the stream parameters, we decode the
984 first frames to get it. (used in mpeg case for example) */
985 6492 ret = avformat_find_stream_info(ic, opts);
986
987
2/2
✓ Branch 0 taken 6815 times.
✓ Branch 1 taken 6492 times.
13307 for (i = 0; i < orig_nb_streams; i++)
988 6815 av_dict_free(&opts[i]);
989 6492 av_freep(&opts);
990
991
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6492 times.
6492 if (ret < 0) {
992 av_log(NULL, AV_LOG_FATAL, "%s: could not find codec parameters\n", filename);
993 if (ic->nb_streams == 0) {
994 avformat_close_input(&ic);
995 exit_program(1);
996 }
997 }
998 }
999
1000
3/4
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 6473 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 21 times.
6494 if (start_time != AV_NOPTS_VALUE && start_time_eof != AV_NOPTS_VALUE) {
1001 av_log(NULL, AV_LOG_WARNING, "Cannot use -ss and -sseof both, using -ss for %s\n", filename);
1002 start_time_eof = AV_NOPTS_VALUE;
1003 }
1004
1005
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6494 times.
6494 if (start_time_eof != AV_NOPTS_VALUE) {
1006 if (start_time_eof >= 0) {
1007 av_log(NULL, AV_LOG_ERROR, "-sseof value must be negative; aborting\n");
1008 exit_program(1);
1009 }
1010 if (ic->duration > 0) {
1011 start_time = start_time_eof + ic->duration;
1012 if (start_time < 0) {
1013 av_log(NULL, AV_LOG_WARNING, "-sseof value seeks to before start of file %s; ignored\n", filename);
1014 start_time = AV_NOPTS_VALUE;
1015 }
1016 } else
1017 av_log(NULL, AV_LOG_WARNING, "Cannot use -sseof, duration of %s not known\n", filename);
1018 }
1019
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 6473 times.
6494 timestamp = (start_time == AV_NOPTS_VALUE) ? 0 : start_time;
1020 /* add the stream start time */
1021
4/4
✓ Branch 0 taken 6491 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 4930 times.
✓ Branch 3 taken 1561 times.
6494 if (!o->seek_timestamp && ic->start_time != AV_NOPTS_VALUE)
1022 4930 timestamp += ic->start_time;
1023
1024 /* if seeking requested, we execute it */
1025
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 6473 times.
6494 if (start_time != AV_NOPTS_VALUE) {
1026 21 int64_t seek_timestamp = timestamp;
1027
1028
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 if (!(ic->iformat->flags & AVFMT_SEEK_TO_PTS)) {
1029 21 int dts_heuristic = 0;
1030
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 21 times.
42 for (i=0; i<ic->nb_streams; i++) {
1031 21 const AVCodecParameters *par = ic->streams[i]->codecpar;
1032
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 if (par->video_delay) {
1033 dts_heuristic = 1;
1034 break;
1035 }
1036 }
1037
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 if (dts_heuristic) {
1038 seek_timestamp -= 3*AV_TIME_BASE / 23;
1039 }
1040 }
1041 21 ret = avformat_seek_file(ic, -1, INT64_MIN, seek_timestamp, seek_timestamp, 0);
1042
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 20 times.
21 if (ret < 0) {
1043 1 av_log(NULL, AV_LOG_WARNING, "%s: could not seek to position %0.3f\n",
1044 1 filename, (double)timestamp / AV_TIME_BASE);
1045 }
1046 }
1047
1048 6494 d = allocate_array_elem(&input_files, sizeof(*d), &nb_input_files);
1049 6494 f = &d->f;
1050
1051 6494 f->ctx = ic;
1052 6494 f->index = nb_input_files - 1;
1053 6494 f->start_time = start_time;
1054 6494 f->recording_time = recording_time;
1055 6494 f->input_sync_ref = o->input_sync_ref;
1056 6494 f->input_ts_offset = o->input_ts_offset;
1057
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6482 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
6494 f->ts_offset = o->input_ts_offset - (copy_ts ? (start_at_zero && ic->start_time != AV_NOPTS_VALUE ? ic->start_time : 0) : timestamp);
1058 6494 f->rate_emu = o->rate_emu;
1059 6494 f->accurate_seek = o->accurate_seek;
1060 6494 d->loop = o->loop;
1061 6494 d->duration = 0;
1062 6494 d->time_base = (AVRational){ 1, 1 };
1063
1064 6494 f->readrate = o->readrate ? o->readrate : 0.0;
1065
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6494 times.
6494 if (f->readrate < 0.0f) {
1066 av_log(NULL, AV_LOG_ERROR, "Option -readrate for Input #%d is %0.3f; it must be non-negative.\n", f->index, f->readrate);
1067 exit_program(1);
1068 }
1069
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6494 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6494 if (f->readrate && f->rate_emu) {
1070 av_log(NULL, AV_LOG_WARNING, "Both -readrate and -re set for Input #%d. Using -readrate %0.3f.\n", f->index, f->readrate);
1071 f->rate_emu = 0;
1072 }
1073
1074 6494 d->thread_queue_size = o->thread_queue_size;
1075
1076 /* update the current parameters so that they match the one of the input stream */
1077 6494 add_input_streams(o, d);
1078
1079 /* dump the file content */
1080 6494 av_dump_format(ic, f->index, filename, 0);
1081
1082 /* check if all codec options have been used */
1083 6494 unused_opts = strip_specifiers(o->g->codec_opts);
1084
2/2
✓ Branch 0 taken 6937 times.
✓ Branch 1 taken 6494 times.
13431 for (i = 0; i < f->nb_streams; i++) {
1085 6937 e = NULL;
1086
2/2
✓ Branch 1 taken 21484 times.
✓ Branch 2 taken 6937 times.
28421 while ((e = av_dict_iterate(f->streams[i]->decoder_opts, e)))
1087 21484 av_dict_set(&unused_opts, e->key, NULL, 0);
1088 }
1089
1090 6494 e = NULL;
1091
2/2
✓ Branch 1 taken 395 times.
✓ Branch 2 taken 6494 times.
6889 while ((e = av_dict_iterate(unused_opts, e))) {
1092 395 const AVClass *class = avcodec_get_class();
1093 395 const AVOption *option = av_opt_find(&class, e->key, NULL, 0,
1094 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
1095 395 const AVClass *fclass = avformat_get_class();
1096 395 const AVOption *foption = av_opt_find(&fclass, e->key, NULL, 0,
1097 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
1098
2/4
✓ Branch 0 taken 395 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 395 times.
395 if (!option || foption)
1099 continue;
1100
1101
1102
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 395 times.
395 if (!(option->flags & AV_OPT_FLAG_DECODING_PARAM)) {
1103 av_log(NULL, AV_LOG_ERROR, "Codec AVOption %s (%s) specified for "
1104 "input file #%d (%s) is not a decoding option.\n", e->key,
1105 option->help ? option->help : "", f->index,
1106 filename);
1107 exit_program(1);
1108 }
1109
1110 395 av_log(NULL, AV_LOG_WARNING, "Codec AVOption %s (%s) specified for "
1111 "input file #%d (%s) has not been used for any stream. The most "
1112 "likely reason is either wrong type (e.g. a video option with "
1113 "no video streams) or that it is a private option of some decoder "
1114 395 "which was not actually used for any stream.\n", e->key,
1115
1/2
✓ Branch 0 taken 395 times.
✗ Branch 1 not taken.
395 option->help ? option->help : "", f->index, filename);
1116 }
1117 6494 av_dict_free(&unused_opts);
1118
1119
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6494 times.
6494 for (i = 0; i < o->nb_dump_attachment; i++) {
1120 int j;
1121
1122 for (j = 0; j < ic->nb_streams; j++) {
1123 AVStream *st = ic->streams[j];
1124
1125 if (check_stream_specifier(ic, st, o->dump_attachment[i].specifier) == 1)
1126 dump_attachment(st, o->dump_attachment[i].u.str);
1127 }
1128 }
1129
1130 6494 return 0;
1131 }
1132