FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/fftools/ffmpeg_demux.c
Date: 2024-02-29 09:57:37
Exec Total Coverage
Lines: 794 1031 77.0%
Functions: 34 35 97.1%
Branches: 545 1114 48.9%

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