FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/avformat.c
Date: 2022-12-05 03:11:11
Exec Total Coverage
Lines: 418 532 78.6%
Functions: 27 27 100.0%
Branches: 286 491 58.2%

Line Branch Exec Source
1 /*
2 * Various functions used by both muxers and demuxers
3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include <math.h>
23 #include "libavutil/avassert.h"
24 #include "libavutil/avstring.h"
25 #include "libavutil/channel_layout.h"
26 #include "libavutil/intreadwrite.h"
27 #include "libavutil/mem.h"
28 #include "libavutil/opt.h"
29 #include "libavutil/pixfmt.h"
30 #include "libavutil/samplefmt.h"
31 #include "libavcodec/avcodec.h"
32 #include "libavcodec/bsf.h"
33 #include "libavcodec/codec_desc.h"
34 #include "libavcodec/packet_internal.h"
35 #include "avformat.h"
36 #include "avio.h"
37 #include "demux.h"
38 #include "internal.h"
39
40 14262 void ff_free_stream(AVStream **pst)
41 {
42 14262 AVStream *st = *pst;
43 14262 FFStream *const sti = ffstream(st);
44
45
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14262 times.
14262 if (!st)
46 return;
47
48
2/2
✓ Branch 0 taken 905 times.
✓ Branch 1 taken 14262 times.
15167 for (int i = 0; i < st->nb_side_data; i++)
49 905 av_freep(&st->side_data[i].data);
50 14262 av_freep(&st->side_data);
51
52
2/2
✓ Branch 0 taken 55 times.
✓ Branch 1 taken 14207 times.
14262 if (st->attached_pic.data)
53 55 av_packet_unref(&st->attached_pic);
54
55 14262 av_parser_close(sti->parser);
56 14262 avcodec_free_context(&sti->avctx);
57 14262 av_bsf_free(&sti->bsfc);
58 14262 av_freep(&sti->priv_pts);
59 14262 av_freep(&sti->index_entries);
60 14262 av_freep(&sti->probe_data.buf);
61
62 14262 av_bsf_free(&sti->extract_extradata.bsf);
63
64
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 14234 times.
14262 if (sti->info) {
65 28 av_freep(&sti->info->duration_error);
66 28 av_freep(&sti->info);
67 }
68
69 14262 av_dict_free(&st->metadata);
70 14262 avcodec_parameters_free(&st->codecpar);
71 14262 av_freep(&st->priv_data);
72
73 14262 av_freep(pst);
74 }
75
76 10 void ff_remove_stream(AVFormatContext *s, AVStream *st)
77 {
78
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 av_assert0(s->nb_streams>0);
79
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 av_assert0(s->streams[ s->nb_streams - 1 ] == st);
80
81 10 ff_free_stream(&s->streams[ --s->nb_streams ]);
82 10 }
83
84 /* XXX: suppress the packet queue */
85 18208 void ff_flush_packet_queue(AVFormatContext *s)
86 {
87 18208 FFFormatContext *const si = ffformatcontext(s);
88 18208 avpriv_packet_list_free(&si->parse_queue);
89 18208 avpriv_packet_list_free(&si->packet_buffer);
90 18208 avpriv_packet_list_free(&si->raw_packet_buffer);
91
92 18208 si->raw_packet_buffer_size = 0;
93 18208 }
94
95 13803 void avformat_free_context(AVFormatContext *s)
96 {
97 FFFormatContext *si;
98
99
2/2
✓ Branch 0 taken 441 times.
✓ Branch 1 taken 13362 times.
13803 if (!s)
100 441 return;
101 13362 si = ffformatcontext(s);
102
103
5/6
✓ Branch 0 taken 6521 times.
✓ Branch 1 taken 6841 times.
✓ Branch 2 taken 3769 times.
✓ Branch 3 taken 2752 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 3769 times.
13362 if (s->oformat && s->oformat->deinit && si->initialized)
104 s->oformat->deinit(s);
105
106 13362 av_opt_free(s);
107
5/6
✓ Branch 0 taken 6841 times.
✓ Branch 1 taken 6521 times.
✓ Branch 2 taken 5912 times.
✓ Branch 3 taken 929 times.
✓ Branch 4 taken 5912 times.
✗ Branch 5 not taken.
13362 if (s->iformat && s->iformat->priv_class && s->priv_data)
108 5912 av_opt_free(s->priv_data);
109
5/6
✓ Branch 0 taken 6521 times.
✓ Branch 1 taken 6841 times.
✓ Branch 2 taken 3845 times.
✓ Branch 3 taken 2676 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 3845 times.
13362 if (s->oformat && s->oformat->priv_class && s->priv_data)
110 av_opt_free(s->priv_data);
111
112
2/2
✓ Branch 0 taken 14252 times.
✓ Branch 1 taken 13362 times.
27614 for (unsigned i = 0; i < s->nb_streams; i++)
113 14252 ff_free_stream(&s->streams[i]);
114 13362 s->nb_streams = 0;
115
116
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 13362 times.
13422 for (unsigned i = 0; i < s->nb_programs; i++) {
117 60 av_dict_free(&s->programs[i]->metadata);
118 60 av_freep(&s->programs[i]->stream_index);
119 60 av_freep(&s->programs[i]);
120 }
121 13362 s->nb_programs = 0;
122
123 13362 av_freep(&s->programs);
124 13362 av_freep(&s->priv_data);
125
2/2
✓ Branch 0 taken 97 times.
✓ Branch 1 taken 13362 times.
13459 while (s->nb_chapters--) {
126 97 av_dict_free(&s->chapters[s->nb_chapters]->metadata);
127 97 av_freep(&s->chapters[s->nb_chapters]);
128 }
129 13362 av_freep(&s->chapters);
130 13362 av_dict_free(&s->metadata);
131 13362 av_dict_free(&si->id3v2_meta);
132 13362 av_packet_free(&si->pkt);
133 13362 av_packet_free(&si->parse_pkt);
134 13362 av_freep(&s->streams);
135 13362 ff_flush_packet_queue(s);
136 13362 av_freep(&s->url);
137 13362 av_free(s);
138 }
139
140 6521 uint8_t *av_stream_get_side_data(const AVStream *st,
141 enum AVPacketSideDataType type, size_t *size)
142 {
143
2/2
✓ Branch 0 taken 520 times.
✓ Branch 1 taken 6469 times.
6989 for (int i = 0; i < st->nb_side_data; i++) {
144
2/2
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 468 times.
520 if (st->side_data[i].type == type) {
145
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 50 times.
52 if (size)
146 2 *size = st->side_data[i].size;
147 52 return st->side_data[i].data;
148 }
149 }
150
2/2
✓ Branch 0 taken 378 times.
✓ Branch 1 taken 6091 times.
6469 if (size)
151 378 *size = 0;
152 6469 return NULL;
153 }
154
155 901 int av_stream_add_side_data(AVStream *st, enum AVPacketSideDataType type,
156 uint8_t *data, size_t size)
157 {
158 AVPacketSideData *sd, *tmp;
159
160
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 900 times.
928 for (int i = 0; i < st->nb_side_data; i++) {
161 28 sd = &st->side_data[i];
162
163
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 27 times.
28 if (sd->type == type) {
164 1 av_freep(&sd->data);
165 1 sd->data = data;
166 1 sd->size = size;
167 1 return 0;
168 }
169 }
170
171
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 900 times.
900 if (st->nb_side_data + 1U > FFMIN(INT_MAX, SIZE_MAX / sizeof(*tmp)))
172 return AVERROR(ERANGE);
173
174 900 tmp = av_realloc_array(st->side_data, st->nb_side_data + 1, sizeof(*tmp));
175
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 900 times.
900 if (!tmp) {
176 return AVERROR(ENOMEM);
177 }
178
179 900 st->side_data = tmp;
180 900 st->nb_side_data++;
181
182 900 sd = &st->side_data[st->nb_side_data - 1];
183 900 sd->type = type;
184 900 sd->data = data;
185 900 sd->size = size;
186
187 900 return 0;
188 }
189
190 639 uint8_t *av_stream_new_side_data(AVStream *st, enum AVPacketSideDataType type,
191 size_t size)
192 {
193 int ret;
194 639 uint8_t *data = av_malloc(size);
195
196
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 639 times.
639 if (!data)
197 return NULL;
198
199 639 ret = av_stream_add_side_data(st, type, data, size);
200
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 639 times.
639 if (ret < 0) {
201 av_freep(&data);
202 return NULL;
203 }
204
205 639 return data;
206 }
207
208 30 int ff_stream_side_data_copy(AVStream *dst, const AVStream *src)
209 {
210 /* Free existing side data*/
211
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 for (int i = 0; i < dst->nb_side_data; i++)
212 av_free(dst->side_data[i].data);
213 30 av_freep(&dst->side_data);
214 30 dst->nb_side_data = 0;
215
216 /* Copy side data if present */
217
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 25 times.
30 if (src->nb_side_data) {
218 5 dst->side_data = av_calloc(src->nb_side_data,
219 sizeof(*dst->side_data));
220
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (!dst->side_data)
221 return AVERROR(ENOMEM);
222 5 dst->nb_side_data = src->nb_side_data;
223
224
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
10 for (int i = 0; i < src->nb_side_data; i++) {
225 5 uint8_t *data = av_memdup(src->side_data[i].data,
226 5 src->side_data[i].size);
227
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (!data)
228 return AVERROR(ENOMEM);
229 5 dst->side_data[i].type = src->side_data[i].type;
230 5 dst->side_data[i].size = src->side_data[i].size;
231 5 dst->side_data[i].data = data;
232 }
233 }
234
235 30 return 0;
236 }
237
238 /**
239 * Copy all stream parameters from source to destination stream, with the
240 * exception of the index field, which is usually set by avformat_new_stream().
241 *
242 * @param dst pointer to destination AVStream
243 * @param src pointer to source AVStream
244 * @return >=0 on success, AVERROR code on error
245 */
246 20 static int stream_params_copy(AVStream *dst, const AVStream *src)
247 {
248 int ret;
249
250 20 dst->id = src->id;
251 20 dst->time_base = src->time_base;
252 20 dst->start_time = src->start_time;
253 20 dst->duration = src->duration;
254 20 dst->nb_frames = src->nb_frames;
255 20 dst->disposition = src->disposition;
256 20 dst->discard = src->discard;
257 20 dst->sample_aspect_ratio = src->sample_aspect_ratio;
258 20 dst->avg_frame_rate = src->avg_frame_rate;
259 20 dst->event_flags = src->event_flags;
260 20 dst->r_frame_rate = src->r_frame_rate;
261 20 dst->pts_wrap_bits = src->pts_wrap_bits;
262
263 20 av_dict_free(&dst->metadata);
264 20 ret = av_dict_copy(&dst->metadata, src->metadata, 0);
265
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if (ret < 0)
266 return ret;
267
268 20 ret = avcodec_parameters_copy(dst->codecpar, src->codecpar);
269
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if (ret < 0)
270 return ret;
271
272 20 ret = ff_stream_side_data_copy(dst, src);
273
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if (ret < 0)
274 return ret;
275
276 20 av_packet_unref(&dst->attached_pic);
277
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if (src->attached_pic.data) {
278 ret = av_packet_ref(&dst->attached_pic, &src->attached_pic);
279 if (ret < 0)
280 return ret;
281 }
282
283 20 return 0;
284 }
285
286 20 AVStream *ff_stream_clone(AVFormatContext *dst_ctx, const AVStream *src)
287 {
288 AVStream *st;
289 int ret;
290
291 20 st = avformat_new_stream(dst_ctx, NULL);
292
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if (!st)
293 return NULL;
294
295 20 ret = stream_params_copy(st, src);
296
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if (ret < 0) {
297 ff_remove_stream(dst_ctx, st);
298 return NULL;
299 }
300
301 20 return st;
302 }
303
304 301 AVProgram *av_new_program(AVFormatContext *ac, int id)
305 {
306 301 AVProgram *program = NULL;
307 int ret;
308
309 301 av_log(ac, AV_LOG_TRACE, "new_program: id=0x%04x\n", id);
310
311
2/2
✓ Branch 0 taken 241 times.
✓ Branch 1 taken 301 times.
542 for (unsigned i = 0; i < ac->nb_programs; i++)
312
1/2
✓ Branch 0 taken 241 times.
✗ Branch 1 not taken.
241 if (ac->programs[i]->id == id)
313 241 program = ac->programs[i];
314
315
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 241 times.
301 if (!program) {
316 60 program = av_mallocz(sizeof(*program));
317
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 60 times.
60 if (!program)
318 return NULL;
319 60 ret = av_dynarray_add_nofree(&ac->programs, &ac->nb_programs, program);
320
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 60 times.
60 if (ret < 0) {
321 av_free(program);
322 return NULL;
323 }
324 60 program->discard = AVDISCARD_NONE;
325 60 program->pmt_version = -1;
326 60 program->id = id;
327 60 program->pts_wrap_reference = AV_NOPTS_VALUE;
328 60 program->pts_wrap_behavior = AV_PTS_WRAP_IGNORE;
329 60 program->start_time =
330 60 program->end_time = AV_NOPTS_VALUE;
331 }
332 301 return program;
333 }
334
335 507 void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned idx)
336 {
337 507 AVProgram *program = NULL;
338 void *tmp;
339
340
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 507 times.
507 if (idx >= ac->nb_streams) {
341 av_log(ac, AV_LOG_ERROR, "stream index %d is not valid\n", idx);
342 return;
343 }
344
345
1/2
✓ Branch 0 taken 507 times.
✗ Branch 1 not taken.
507 for (unsigned i = 0; i < ac->nb_programs; i++) {
346
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 507 times.
507 if (ac->programs[i]->id != progid)
347 continue;
348 507 program = ac->programs[i];
349
2/2
✓ Branch 0 taken 752 times.
✓ Branch 1 taken 319 times.
1071 for (unsigned j = 0; j < program->nb_stream_indexes; j++)
350
2/2
✓ Branch 0 taken 188 times.
✓ Branch 1 taken 564 times.
752 if (program->stream_index[j] == idx)
351 188 return;
352
353 319 tmp = av_realloc_array(program->stream_index, program->nb_stream_indexes+1, sizeof(unsigned int));
354
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 319 times.
319 if (!tmp)
355 return;
356 319 program->stream_index = tmp;
357 319 program->stream_index[program->nb_stream_indexes++] = idx;
358 319 return;
359 }
360 }
361
362 11944 AVProgram *av_find_program_from_stream(AVFormatContext *ic, AVProgram *last, int s)
363 {
364
2/2
✓ Branch 0 taken 1100 times.
✓ Branch 1 taken 11425 times.
12525 for (unsigned i = 0; i < ic->nb_programs; i++) {
365
2/2
✓ Branch 0 taken 578 times.
✓ Branch 1 taken 522 times.
1100 if (ic->programs[i] == last) {
366 578 last = NULL;
367 } else {
368
1/2
✓ Branch 0 taken 522 times.
✗ Branch 1 not taken.
522 if (!last)
369
2/2
✓ Branch 0 taken 1463 times.
✓ Branch 1 taken 3 times.
1466 for (unsigned j = 0; j < ic->programs[i]->nb_stream_indexes; j++)
370
2/2
✓ Branch 0 taken 519 times.
✓ Branch 1 taken 944 times.
1463 if (ic->programs[i]->stream_index[j] == s)
371 519 return ic->programs[i];
372 }
373 }
374 11425 return NULL;
375 }
376
377 1909 int av_find_default_stream_index(AVFormatContext *s)
378 {
379 1909 int best_stream = 0;
380 1909 int best_score = INT_MIN;
381
382
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1909 times.
1909 if (s->nb_streams <= 0)
383 return -1;
384
2/2
✓ Branch 0 taken 2213 times.
✓ Branch 1 taken 1909 times.
4122 for (unsigned i = 0; i < s->nb_streams; i++) {
385 2213 const AVStream *const st = s->streams[i];
386 2213 const FFStream *const sti = cffstream(st);
387 2213 int score = 0;
388
2/2
✓ Branch 0 taken 1300 times.
✓ Branch 1 taken 913 times.
2213 if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
389
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1296 times.
1300 if (st->disposition & AV_DISPOSITION_ATTACHED_PIC)
390 4 score -= 400;
391
3/4
✓ Branch 0 taken 1238 times.
✓ Branch 1 taken 62 times.
✓ Branch 2 taken 1238 times.
✗ Branch 3 not taken.
1300 if (st->codecpar->width && st->codecpar->height)
392 1238 score += 50;
393 1300 score+= 25;
394 }
395
2/2
✓ Branch 0 taken 884 times.
✓ Branch 1 taken 1329 times.
2213 if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
396
2/2
✓ Branch 0 taken 861 times.
✓ Branch 1 taken 23 times.
884 if (st->codecpar->sample_rate)
397 861 score += 50;
398 }
399
2/2
✓ Branch 0 taken 1971 times.
✓ Branch 1 taken 242 times.
2213 if (sti->codec_info_nb_frames)
400 1971 score += 12;
401
402
2/2
✓ Branch 0 taken 2209 times.
✓ Branch 1 taken 4 times.
2213 if (st->discard != AVDISCARD_ALL)
403 2209 score += 200;
404
405
2/2
✓ Branch 0 taken 1939 times.
✓ Branch 1 taken 274 times.
2213 if (score > best_score) {
406 1939 best_score = score;
407 1939 best_stream = i;
408 }
409 }
410 1909 return best_stream;
411 }
412
413 17 int av_find_best_stream(AVFormatContext *ic, enum AVMediaType type,
414 int wanted_stream_nb, int related_stream,
415 const AVCodec **decoder_ret, int flags)
416 {
417 17 int nb_streams = ic->nb_streams;
418 17 int ret = AVERROR_STREAM_NOT_FOUND;
419 17 int best_count = -1, best_multiframe = -1, best_disposition = -1;
420 int count, multiframe, disposition;
421 17 int64_t best_bitrate = -1;
422 int64_t bitrate;
423 17 unsigned *program = NULL;
424 17 const AVCodec *decoder = NULL, *best_decoder = NULL;
425
426
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
17 if (related_stream >= 0 && wanted_stream_nb < 0) {
427 AVProgram *p = av_find_program_from_stream(ic, NULL, related_stream);
428 if (p) {
429 program = p->stream_index;
430 nb_streams = p->nb_stream_indexes;
431 }
432 }
433
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 17 times.
37 for (unsigned i = 0; i < nb_streams; i++) {
434
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 int real_stream_index = program ? program[i] : i;
435 20 AVStream *st = ic->streams[real_stream_index];
436 20 AVCodecParameters *par = st->codecpar;
437
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 17 times.
20 if (par->codec_type != type)
438 3 continue;
439
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
17 if (wanted_stream_nb >= 0 && real_stream_index != wanted_stream_nb)
440 continue;
441
4/6
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3 times.
17 if (type == AVMEDIA_TYPE_AUDIO && !(par->ch_layout.nb_channels && par->sample_rate))
442 continue;
443
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if (decoder_ret) {
444 decoder = ff_find_decoder(ic, st, par->codec_id);
445 if (!decoder) {
446 if (ret < 0)
447 ret = AVERROR_DECODER_NOT_FOUND;
448 continue;
449 }
450 }
451 17 disposition = !(st->disposition & (AV_DISPOSITION_HEARING_IMPAIRED | AV_DISPOSITION_VISUAL_IMPAIRED))
452 17 + !! (st->disposition & AV_DISPOSITION_DEFAULT);
453 17 count = ffstream(st)->codec_info_nb_frames;
454 17 bitrate = par->bit_rate;
455 17 multiframe = FFMIN(5, count);
456
2/4
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 17 times.
17 if ((best_disposition > disposition) ||
457
1/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 17 times.
17 (best_disposition == disposition && best_multiframe > multiframe) ||
458
1/6
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 17 times.
17 (best_disposition == disposition && best_multiframe == multiframe && best_bitrate > bitrate) ||
459 (best_disposition == disposition && best_multiframe == multiframe && best_bitrate == bitrate && best_count >= count))
460 continue;
461 17 best_disposition = disposition;
462 17 best_count = count;
463 17 best_bitrate = bitrate;
464 17 best_multiframe = multiframe;
465 17 ret = real_stream_index;
466 17 best_decoder = decoder;
467
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 if (program && i == nb_streams - 1 && ret < 0) {
468 program = NULL;
469 nb_streams = ic->nb_streams;
470 /* no related stream found, try again with everything */
471 i = 0;
472 }
473 }
474
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if (decoder_ret)
475 *decoder_ret = best_decoder;
476 17 return ret;
477 }
478
479 /**
480 * Matches a stream specifier (but ignores requested index).
481 *
482 * @param indexptr set to point to the requested stream index if there is one
483 *
484 * @return <0 on error
485 * 0 if st is NOT a matching stream
486 * >0 if st is a matching stream
487 */
488 28417 static int match_stream_specifier(const AVFormatContext *s, const AVStream *st,
489 const char *spec, const char **indexptr,
490 const AVProgram **p)
491 {
492 28417 int match = 1; /* Stores if the specifier matches so far. */
493
2/2
✓ Branch 0 taken 19367 times.
✓ Branch 1 taken 27189 times.
46556 while (*spec) {
494
3/4
✓ Branch 0 taken 1228 times.
✓ Branch 1 taken 18139 times.
✓ Branch 2 taken 1228 times.
✗ Branch 3 not taken.
19367 if (*spec <= '9' && *spec >= '0') { /* opt:index */
495
2/2
✓ Branch 0 taken 467 times.
✓ Branch 1 taken 761 times.
1228 if (indexptr)
496 467 *indexptr = spec;
497 1228 return match;
498
7/8
✓ Branch 0 taken 1816 times.
✓ Branch 1 taken 16323 times.
✓ Branch 2 taken 78 times.
✓ Branch 3 taken 1738 times.
✓ Branch 4 taken 9 times.
✓ Branch 5 taken 69 times.
✓ Branch 6 taken 9 times.
✗ Branch 7 not taken.
18139 } else if (*spec == 'v' || *spec == 'a' || *spec == 's' || *spec == 'd' ||
499
3/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
18142 *spec == 't' || *spec == 'V') { /* opt:[vasdtV] */
500 enum AVMediaType type;
501 18133 int nopic = 0;
502
503
4/7
✓ Branch 0 taken 16323 times.
✓ Branch 1 taken 1738 times.
✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
18133 switch (*spec++) {
504 16323 case 'v': type = AVMEDIA_TYPE_VIDEO; break;
505 1738 case 'a': type = AVMEDIA_TYPE_AUDIO; break;
506 69 case 's': type = AVMEDIA_TYPE_SUBTITLE; break;
507 case 'd': type = AVMEDIA_TYPE_DATA; break;
508 3 case 't': type = AVMEDIA_TYPE_ATTACHMENT; break;
509 case 'V': type = AVMEDIA_TYPE_VIDEO; nopic = 1; break;
510 default: av_assert0(0);
511 }
512
3/4
✓ Branch 0 taken 1077 times.
✓ Branch 1 taken 17056 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1077 times.
18133 if (*spec && *spec++ != ':') /* If we are not at the end, then another specifier must follow. */
513 return AVERROR(EINVAL);
514
515
2/2
✓ Branch 0 taken 644 times.
✓ Branch 1 taken 17489 times.
18133 if (type != st->codecpar->codec_type)
516 644 match = 0;
517
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18133 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18133 if (nopic && (st->disposition & AV_DISPOSITION_ATTACHED_PIC))
518 match = 0;
519
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
12 } else if (*spec == 'p' && *(spec + 1) == ':') {
520 int prog_id;
521 6 int found = 0;
522 char *endptr;
523 6 spec += 2;
524 6 prog_id = strtol(spec, &endptr, 0);
525 /* Disallow empty id and make sure that if we are not at the end, then another specifier must follow. */
526
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 6 times.
6 if (spec == endptr || (*endptr && *endptr++ != ':'))
527 return AVERROR(EINVAL);
528 6 spec = endptr;
529
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (match) {
530
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 for (unsigned i = 0; i < s->nb_programs; i++) {
531
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (s->programs[i]->id != prog_id)
532 continue;
533
534
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
9 for (unsigned j = 0; j < s->programs[i]->nb_stream_indexes; j++) {
535
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 3 times.
8 if (st->index == s->programs[i]->stream_index[j]) {
536 5 found = 1;
537
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3 times.
5 if (p)
538 2 *p = s->programs[i];
539 5 i = s->nb_programs;
540 5 break;
541 }
542 }
543 }
544 }
545
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 5 times.
6 if (!found)
546 1 match = 0;
547 } else if (*spec == '#' ||
548 (*spec == 'i' && *(spec + 1) == ':')) {
549 int stream_id;
550 char *endptr;
551 spec += 1 + (*spec == 'i');
552 stream_id = strtol(spec, &endptr, 0);
553 if (spec == endptr || *endptr) /* Disallow empty id and make sure we are at the end. */
554 return AVERROR(EINVAL);
555 return match && (stream_id == st->id);
556 } else if (*spec == 'm' && *(spec + 1) == ':') {
557 const AVDictionaryEntry *tag;
558 char *key, *val;
559 int ret;
560
561 if (match) {
562 spec += 2;
563 val = strchr(spec, ':');
564
565 key = val ? av_strndup(spec, val - spec) : av_strdup(spec);
566 if (!key)
567 return AVERROR(ENOMEM);
568
569 tag = av_dict_get(st->metadata, key, NULL, 0);
570 if (tag) {
571 if (!val || !strcmp(tag->value, val + 1))
572 ret = 1;
573 else
574 ret = 0;
575 } else
576 ret = 0;
577
578 av_freep(&key);
579 }
580 return match && ret;
581 } else if (*spec == 'u' && *(spec + 1) == '\0') {
582 const AVCodecParameters *par = st->codecpar;
583 int val;
584 switch (par->codec_type) {
585 case AVMEDIA_TYPE_AUDIO:
586 val = par->sample_rate && par->ch_layout.nb_channels;
587 if (par->format == AV_SAMPLE_FMT_NONE)
588 return 0;
589 break;
590 case AVMEDIA_TYPE_VIDEO:
591 val = par->width && par->height;
592 if (par->format == AV_PIX_FMT_NONE)
593 return 0;
594 break;
595 case AVMEDIA_TYPE_UNKNOWN:
596 val = 0;
597 break;
598 default:
599 val = 1;
600 break;
601 }
602 return match && (par->codec_id != AV_CODEC_ID_NONE && val != 0);
603 } else {
604 return AVERROR(EINVAL);
605 }
606 }
607
608 27189 return match;
609 }
610
611 27656 int avformat_match_stream_specifier(AVFormatContext *s, AVStream *st,
612 const char *spec)
613 {
614 int ret, index;
615 char *endptr;
616 27656 const char *indexptr = NULL;
617 27656 const AVProgram *p = NULL;
618 int nb_streams;
619
620 27656 ret = match_stream_specifier(s, st, spec, &indexptr, &p);
621
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27656 times.
27656 if (ret < 0)
622 goto error;
623
624
2/2
✓ Branch 0 taken 27189 times.
✓ Branch 1 taken 467 times.
27656 if (!indexptr)
625 27189 return ret;
626
627 467 index = strtol(indexptr, &endptr, 0);
628
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 467 times.
467 if (*endptr) { /* We can't have anything after the requested index. */
629 ret = AVERROR(EINVAL);
630 goto error;
631 }
632
633 /* This is not really needed but saves us a loop for simple stream index specifiers. */
634
2/2
✓ Branch 0 taken 151 times.
✓ Branch 1 taken 316 times.
467 if (spec == indexptr)
635 151 return (index == st->index);
636
637 /* If we requested a matching stream index, we have to ensure st is that. */
638
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 314 times.
316 nb_streams = p ? p->nb_stream_indexes : s->nb_streams;
639
4/4
✓ Branch 0 taken 883 times.
✓ Branch 1 taken 95 times.
✓ Branch 2 taken 761 times.
✓ Branch 3 taken 122 times.
978 for (int i = 0; i < nb_streams && index >= 0; i++) {
640
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 759 times.
761 const AVStream *candidate = s->streams[p ? p->stream_index[i] : i];
641 761 ret = match_stream_specifier(s, candidate, spec, NULL, NULL);
642
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 761 times.
761 if (ret < 0)
643 goto error;
644
6/6
✓ Branch 0 taken 495 times.
✓ Branch 1 taken 266 times.
✓ Branch 2 taken 243 times.
✓ Branch 3 taken 252 times.
✓ Branch 4 taken 99 times.
✓ Branch 5 taken 144 times.
761 if (ret > 0 && index-- == 0 && st == candidate)
645 99 return 1;
646 }
647 217 return 0;
648
649 error:
650 if (ret == AVERROR(EINVAL))
651 av_log(s, AV_LOG_ERROR, "Invalid stream specifier: %s.\n", spec);
652 return ret;
653 }
654
655 625 AVRational av_guess_sample_aspect_ratio(AVFormatContext *format, AVStream *stream, AVFrame *frame)
656 {
657 625 AVRational undef = {0, 1};
658
1/2
✓ Branch 0 taken 625 times.
✗ Branch 1 not taken.
625 AVRational stream_sample_aspect_ratio = stream ? stream->sample_aspect_ratio : undef;
659
2/4
✓ Branch 0 taken 625 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 625 times.
✗ Branch 3 not taken.
625 AVRational codec_sample_aspect_ratio = stream && stream->codecpar ? stream->codecpar->sample_aspect_ratio : undef;
660
2/2
✓ Branch 0 taken 551 times.
✓ Branch 1 taken 74 times.
625 AVRational frame_sample_aspect_ratio = frame ? frame->sample_aspect_ratio : codec_sample_aspect_ratio;
661
662 625 av_reduce(&stream_sample_aspect_ratio.num, &stream_sample_aspect_ratio.den,
663 625 stream_sample_aspect_ratio.num, stream_sample_aspect_ratio.den, INT_MAX);
664
3/4
✓ Branch 0 taken 509 times.
✓ Branch 1 taken 116 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 509 times.
625 if (stream_sample_aspect_ratio.num <= 0 || stream_sample_aspect_ratio.den <= 0)
665 116 stream_sample_aspect_ratio = undef;
666
667 625 av_reduce(&frame_sample_aspect_ratio.num, &frame_sample_aspect_ratio.den,
668 625 frame_sample_aspect_ratio.num, frame_sample_aspect_ratio.den, INT_MAX);
669
3/4
✓ Branch 0 taken 450 times.
✓ Branch 1 taken 175 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 450 times.
625 if (frame_sample_aspect_ratio.num <= 0 || frame_sample_aspect_ratio.den <= 0)
670 175 frame_sample_aspect_ratio = undef;
671
672
2/2
✓ Branch 0 taken 509 times.
✓ Branch 1 taken 116 times.
625 if (stream_sample_aspect_ratio.num)
673 509 return stream_sample_aspect_ratio;
674 else
675 116 return frame_sample_aspect_ratio;
676 }
677
678 5255 AVRational av_guess_frame_rate(AVFormatContext *format, AVStream *st, AVFrame *frame)
679 {
680 5255 AVRational fr = st->r_frame_rate;
681 5255 AVCodecContext *const avctx = ffstream(st)->avctx;
682 5255 AVRational codec_fr = avctx->framerate;
683 5255 AVRational avg_fr = st->avg_frame_rate;
684
685
7/10
✓ Branch 0 taken 4557 times.
✓ Branch 1 taken 698 times.
✓ Branch 2 taken 4557 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4557 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4557 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4550 times.
✓ Branch 9 taken 7 times.
9812 if (avg_fr.num > 0 && avg_fr.den > 0 && fr.num > 0 && fr.den > 0 &&
686
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 4550 times.
9107 av_q2d(avg_fr) < 70 && av_q2d(fr) > 210) {
687 fr = avg_fr;
688 }
689
690
2/2
✓ Branch 0 taken 359 times.
✓ Branch 1 taken 4896 times.
5255 if (avctx->ticks_per_frame > 1) {
691
3/4
✓ Branch 0 taken 345 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 345 times.
✗ Branch 3 not taken.
359 if ( codec_fr.num > 0 && codec_fr.den > 0 &&
692
5/6
✓ Branch 0 taken 345 times.
✗ Branch 1 not taken.
✓ Branch 4 taken 7 times.
✓ Branch 5 taken 338 times.
✓ Branch 7 taken 5 times.
✓ Branch 8 taken 2 times.
345 (fr.num == 0 || av_q2d(codec_fr) < av_q2d(fr)*0.7 && fabs(1.0 - av_q2d(av_div_q(avg_fr, fr))) > 0.1))
693 5 fr = codec_fr;
694 }
695
696 5255 return fr;
697 }
698
699 482 int avformat_transfer_internal_stream_timing_info(const AVOutputFormat *ofmt,
700 AVStream *ost, const AVStream *ist,
701 enum AVTimebaseSource copy_tb)
702 {
703 482 const AVCodecContext *const dec_ctx = cffstream(ist)->avctx;
704 482 AVCodecContext *const enc_ctx = ffstream(ost)->avctx;
705
706 482 enc_ctx->time_base = ist->time_base;
707 /*
708 * Avi is a special case here because it supports variable fps but
709 * having the fps and timebase differe significantly adds quite some
710 * overhead
711 */
712
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 475 times.
482 if (!strcmp(ofmt->name, "avi")) {
713 #if FF_API_R_FRAME_RATE
714
3/4
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 2 times.
7 if (copy_tb == AVFMT_TBCF_AUTO && ist->r_frame_rate.num
715
1/2
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 && av_q2d(ist->r_frame_rate) >= av_q2d(ist->avg_frame_rate)
716
2/2
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 3 times.
5 && 0.5/av_q2d(ist->r_frame_rate) > av_q2d(ist->time_base)
717
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 && 0.5/av_q2d(ist->r_frame_rate) > av_q2d(dec_ctx->time_base)
718 && av_q2d(ist->time_base) < 1.0/500 && av_q2d(dec_ctx->time_base) < 1.0/500
719
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 || copy_tb == AVFMT_TBCF_R_FRAMERATE) {
720 enc_ctx->time_base.num = ist->r_frame_rate.den;
721 enc_ctx->time_base.den = 2*ist->r_frame_rate.num;
722 enc_ctx->ticks_per_frame = 2;
723 } else
724 #endif
725
3/4
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 4 times.
7 if (copy_tb == AVFMT_TBCF_AUTO && av_q2d(dec_ctx->time_base)*dec_ctx->ticks_per_frame > 2*av_q2d(ist->time_base)
726
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
3 && av_q2d(ist->time_base) < 1.0/500
727
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 || copy_tb == AVFMT_TBCF_DECODER) {
728 3 enc_ctx->time_base = dec_ctx->time_base;
729 3 enc_ctx->time_base.num *= dec_ctx->ticks_per_frame;
730 3 enc_ctx->time_base.den *= 2;
731 3 enc_ctx->ticks_per_frame = 2;
732 }
733
2/2
✓ Branch 0 taken 223 times.
✓ Branch 1 taken 252 times.
475 } else if (!(ofmt->flags & AVFMT_VARIABLE_FPS)
734
2/2
✓ Branch 1 taken 197 times.
✓ Branch 2 taken 26 times.
223 && !av_match_name(ofmt->name, "mov,mp4,3gp,3g2,psp,ipod,ismv,f4v")) {
735
3/4
✓ Branch 0 taken 197 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 175 times.
✓ Branch 3 taken 22 times.
197 if (copy_tb == AVFMT_TBCF_AUTO && dec_ctx->time_base.den
736
2/2
✓ Branch 2 taken 47 times.
✓ Branch 3 taken 128 times.
175 && av_q2d(dec_ctx->time_base)*dec_ctx->ticks_per_frame > av_q2d(ist->time_base)
737
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 47 times.
47 && av_q2d(ist->time_base) < 1.0/500
738
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 150 times.
150 || copy_tb == AVFMT_TBCF_DECODER) {
739 47 enc_ctx->time_base = dec_ctx->time_base;
740 47 enc_ctx->time_base.num *= dec_ctx->ticks_per_frame;
741 }
742 }
743
744
3/4
✓ Branch 0 taken 482 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 479 times.
482 if ((enc_ctx->codec_tag == AV_RL32("tmcd") || ost->codecpar->codec_tag == AV_RL32("tmcd"))
745
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 && dec_ctx->time_base.num < dec_ctx->time_base.den
746
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 && dec_ctx->time_base.num > 0
747 && 121LL*dec_ctx->time_base.num > dec_ctx->time_base.den) {
748 enc_ctx->time_base = dec_ctx->time_base;
749 }
750
751 482 av_reduce(&enc_ctx->time_base.num, &enc_ctx->time_base.den,
752 482 enc_ctx->time_base.num, enc_ctx->time_base.den, INT_MAX);
753
754 482 return 0;
755 }
756
757 480 AVRational av_stream_get_codec_timebase(const AVStream *st)
758 {
759 // See avformat_transfer_internal_stream_timing_info() TODO.
760 480 return cffstream(st)->avctx->time_base;
761 }
762
763 19579 void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits,
764 unsigned int pts_num, unsigned int pts_den)
765 {
766 19579 FFStream *const sti = ffstream(st);
767 AVRational new_tb;
768
1/2
✓ Branch 1 taken 19579 times.
✗ Branch 2 not taken.
19579 if (av_reduce(&new_tb.num, &new_tb.den, pts_num, pts_den, INT_MAX)) {
769
2/2
✓ Branch 0 taken 498 times.
✓ Branch 1 taken 19081 times.
19579 if (new_tb.num != pts_num)
770 498 av_log(NULL, AV_LOG_DEBUG,
771 "st:%d removing common factor %d from timebase\n",
772 498 st->index, pts_num / new_tb.num);
773 } else
774 av_log(NULL, AV_LOG_WARNING,
775 "st:%d has too large timebase, reducing\n", st->index);
776
777
3/4
✓ Branch 0 taken 19578 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 19578 times.
19579 if (new_tb.num <= 0 || new_tb.den <= 0) {
778 1 av_log(NULL, AV_LOG_ERROR,
779 "Ignoring attempt to set invalid timebase %d/%d for st:%d\n",
780 new_tb.num, new_tb.den,
781 st->index);
782 1 return;
783 }
784 19578 st->time_base = new_tb;
785 19578 sti->avctx->pkt_timebase = new_tb;
786 19578 st->pts_wrap_bits = pts_wrap_bits;
787 }
788
789 8353 const AVCodec *ff_find_decoder(AVFormatContext *s, const AVStream *st,
790 enum AVCodecID codec_id)
791 {
792
4/4
✓ Branch 0 taken 5813 times.
✓ Branch 1 taken 2321 times.
✓ Branch 2 taken 82 times.
✓ Branch 3 taken 137 times.
8353 switch (st->codecpar->codec_type) {
793 5813 case AVMEDIA_TYPE_VIDEO:
794
2/2
✓ Branch 0 taken 2618 times.
✓ Branch 1 taken 3195 times.
5813 if (s->video_codec) return s->video_codec;
795 3195 break;
796 2321 case AVMEDIA_TYPE_AUDIO:
797
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 2304 times.
2321 if (s->audio_codec) return s->audio_codec;
798 2304 break;
799 82 case AVMEDIA_TYPE_SUBTITLE:
800
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 82 times.
82 if (s->subtitle_codec) return s->subtitle_codec;
801 82 break;
802 }
803
804 5718 return avcodec_find_decoder(codec_id);
805 }
806
807 83 int ff_copy_whiteblacklists(AVFormatContext *dst, const AVFormatContext *src)
808 {
809
4/8
✓ Branch 0 taken 83 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 83 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 83 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 83 times.
83 av_assert0(!dst->codec_whitelist &&
810 !dst->format_whitelist &&
811 !dst->protocol_whitelist &&
812 !dst->protocol_blacklist);
813 83 dst-> codec_whitelist = av_strdup(src->codec_whitelist);
814 83 dst->format_whitelist = av_strdup(src->format_whitelist);
815 83 dst->protocol_whitelist = av_strdup(src->protocol_whitelist);
816 83 dst->protocol_blacklist = av_strdup(src->protocol_blacklist);
817
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 83 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
83 if ( (src-> codec_whitelist && !dst-> codec_whitelist)
818
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 83 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
83 || (src-> format_whitelist && !dst-> format_whitelist)
819
2/4
✓ Branch 0 taken 83 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 83 times.
✗ Branch 3 not taken.
83 || (src->protocol_whitelist && !dst->protocol_whitelist)
820
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 83 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
83 || (src->protocol_blacklist && !dst->protocol_blacklist)) {
821 av_log(dst, AV_LOG_ERROR, "Failed to duplicate black/whitelist\n");
822 return AVERROR(ENOMEM);
823 }
824 83 return 0;
825 }
826
827 585566 int ff_is_intra_only(enum AVCodecID id)
828 {
829 585566 const AVCodecDescriptor *d = avcodec_descriptor_get(id);
830
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 585499 times.
585566 if (!d)
831 67 return 0;
832
4/4
✓ Branch 0 taken 365608 times.
✓ Branch 1 taken 219891 times.
✓ Branch 2 taken 362942 times.
✓ Branch 3 taken 2666 times.
585499 if ((d->type == AVMEDIA_TYPE_VIDEO || d->type == AVMEDIA_TYPE_AUDIO) &&
833
2/2
✓ Branch 0 taken 122704 times.
✓ Branch 1 taken 460129 times.
582833 !(d->props & AV_CODEC_PROP_INTRA_ONLY))
834 122704 return 0;
835 462795 return 1;
836 }
837
838 68 void ff_format_set_url(AVFormatContext *s, char *url)
839 {
840
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 68 times.
68 av_assert0(url);
841 68 av_freep(&s->url);
842 68 s->url = url;
843 68 }
844
845 86486 int ff_format_io_close(AVFormatContext *s, AVIOContext **pb)
846 {
847 86486 int ret = 0;
848
2/2
✓ Branch 0 taken 86260 times.
✓ Branch 1 taken 226 times.
86486 if (*pb) {
849
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 86260 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
86260 if (s->io_close == ff_format_io_close_default || s->io_close == NULL)
850 86260 ret = s->io_close2(s, *pb);
851 else
852 s->io_close(s, *pb);
853 }
854 86486 *pb = NULL;
855 86486 return ret;
856 }
857