FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/avformat.c
Date: 2025-04-25 22:50:00
Exec Total Coverage
Lines: 365 551 66.2%
Functions: 23 26 88.5%
Branches: 239 535 44.7%

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/frame.h"
27 #include "libavutil/iamf.h"
28 #include "libavutil/intreadwrite.h"
29 #include "libavutil/mem.h"
30 #include "libavutil/opt.h"
31 #include "libavutil/pixfmt.h"
32 #include "libavutil/samplefmt.h"
33 #include "libavcodec/avcodec.h"
34 #include "libavcodec/codec.h"
35 #include "libavcodec/bsf.h"
36 #include "libavcodec/codec_desc.h"
37 #include "libavcodec/packet_internal.h"
38 #include "avformat.h"
39 #include "avformat_internal.h"
40 #include "avio.h"
41 #include "demux.h"
42 #include "mux.h"
43 #include "internal.h"
44
45 17218 void ff_free_stream(AVStream **pst)
46 {
47 17218 AVStream *st = *pst;
48 17218 FFStream *const sti = ffstream(st);
49
50
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17218 times.
17218 if (!st)
51 return;
52
53
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 17162 times.
17218 if (st->attached_pic.data)
54 56 av_packet_unref(&st->attached_pic);
55
56 17218 av_parser_close(sti->parser);
57 17218 avcodec_free_context(&sti->avctx);
58 17218 av_bsf_free(&sti->bsfc);
59 17218 av_freep(&sti->index_entries);
60 17218 av_freep(&sti->probe_data.buf);
61
62 17218 av_bsf_free(&sti->extract_extradata.bsf);
63
64
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 17190 times.
17218 if (sti->info) {
65 28 av_freep(&sti->info->duration_error);
66 28 av_freep(&sti->info);
67 }
68
69 17218 av_dict_free(&st->metadata);
70 17218 avcodec_parameters_free(&st->codecpar);
71 17218 av_freep(&st->priv_data);
72
73 17218 av_freep(pst);
74 }
75
76 85 void ff_free_stream_group(AVStreamGroup **pstg)
77 {
78 85 AVStreamGroup *stg = *pstg;
79
80
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 85 times.
85 if (!stg)
81 return;
82
83 85 av_freep(&stg->streams);
84 85 av_dict_free(&stg->metadata);
85 85 av_freep(&stg->priv_data);
86
3/5
✓ Branch 0 taken 41 times.
✓ Branch 1 taken 38 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
85 switch (stg->type) {
87 41 case AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT: {
88 41 av_iamf_audio_element_free(&stg->params.iamf_audio_element);
89 41 break;
90 }
91 38 case AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION: {
92 38 av_iamf_mix_presentation_free(&stg->params.iamf_mix_presentation);
93 38 break;
94 }
95 6 case AV_STREAM_GROUP_PARAMS_TILE_GRID:
96 6 av_opt_free(stg->params.tile_grid);
97 6 av_freep(&stg->params.tile_grid->offsets);
98 6 av_packet_side_data_free(&stg->params.tile_grid->coded_side_data,
99 6 &stg->params.tile_grid->nb_coded_side_data);
100 6 av_freep(&stg->params.tile_grid);
101 6 break;
102 case AV_STREAM_GROUP_PARAMS_LCEVC:
103 av_opt_free(stg->params.lcevc);
104 av_freep(&stg->params.lcevc);
105 break;
106 default:
107 break;
108 }
109
110 85 av_freep(pstg);
111 }
112
113 10 void ff_remove_stream(AVFormatContext *s, AVStream *st)
114 {
115
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 av_assert0(s->nb_streams>0);
116
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 av_assert0(s->streams[ s->nb_streams - 1 ] == st);
117
118 10 ff_free_stream(&s->streams[ --s->nb_streams ]);
119 10 }
120
121 void ff_remove_stream_group(AVFormatContext *s, AVStreamGroup *stg)
122 {
123 av_assert0(s->nb_stream_groups > 0);
124 av_assert0(s->stream_groups[ s->nb_stream_groups - 1 ] == stg);
125
126 ff_free_stream_group(&s->stream_groups[ --s->nb_stream_groups ]);
127 }
128
129 /* XXX: suppress the packet queue */
130 12444 void ff_flush_packet_queue(AVFormatContext *s)
131 {
132 12444 FormatContextInternal *const fci = ff_fc_internal(s);
133 12444 FFFormatContext *const si = &fci->fc;
134 12444 avpriv_packet_list_free(&fci->parse_queue);
135 12444 avpriv_packet_list_free(&si->packet_buffer);
136 12444 avpriv_packet_list_free(&fci->raw_packet_buffer);
137
138 12444 fci->raw_packet_buffer_size = 0;
139 12444 }
140
141 16398 void avformat_free_context(AVFormatContext *s)
142 {
143 FormatContextInternal *fci;
144 FFFormatContext *si;
145
146
2/2
✓ Branch 0 taken 503 times.
✓ Branch 1 taken 15895 times.
16398 if (!s)
147 503 return;
148 15895 fci = ff_fc_internal(s);
149 15895 si = &fci->fc;
150
151
5/6
✓ Branch 0 taken 8304 times.
✓ Branch 1 taken 7591 times.
✓ Branch 3 taken 4231 times.
✓ Branch 4 taken 4073 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4231 times.
15895 if (s->oformat && ffofmt(s->oformat)->deinit && fci->initialized)
152 ffofmt(s->oformat)->deinit(s);
153
154 15895 av_opt_free(s);
155
5/6
✓ Branch 0 taken 7591 times.
✓ Branch 1 taken 8304 times.
✓ Branch 2 taken 6605 times.
✓ Branch 3 taken 986 times.
✓ Branch 4 taken 6605 times.
✗ Branch 5 not taken.
15895 if (s->iformat && s->iformat->priv_class && s->priv_data)
156 6605 av_opt_free(s->priv_data);
157
5/6
✓ Branch 0 taken 8304 times.
✓ Branch 1 taken 7591 times.
✓ Branch 2 taken 4300 times.
✓ Branch 3 taken 4004 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4300 times.
15895 if (s->oformat && s->oformat->priv_class && s->priv_data)
158 av_opt_free(s->priv_data);
159
160
2/2
✓ Branch 0 taken 17208 times.
✓ Branch 1 taken 15895 times.
33103 for (unsigned i = 0; i < s->nb_streams; i++)
161 17208 ff_free_stream(&s->streams[i]);
162
2/2
✓ Branch 0 taken 85 times.
✓ Branch 1 taken 15895 times.
15980 for (unsigned i = 0; i < s->nb_stream_groups; i++)
163 85 ff_free_stream_group(&s->stream_groups[i]);
164 15895 s->nb_stream_groups = 0;
165 15895 s->nb_streams = 0;
166
167
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 15895 times.
15962 for (unsigned i = 0; i < s->nb_programs; i++) {
168 67 av_dict_free(&s->programs[i]->metadata);
169 67 av_freep(&s->programs[i]->stream_index);
170 67 av_freep(&s->programs[i]);
171 }
172 15895 s->nb_programs = 0;
173
174 15895 av_freep(&s->programs);
175 15895 av_freep(&s->priv_data);
176
2/2
✓ Branch 0 taken 105 times.
✓ Branch 1 taken 15895 times.
16000 while (s->nb_chapters--) {
177 105 av_dict_free(&s->chapters[s->nb_chapters]->metadata);
178 105 av_freep(&s->chapters[s->nb_chapters]);
179 }
180 15895 av_freep(&s->chapters);
181 15895 av_dict_free(&s->metadata);
182 15895 av_dict_free(&si->id3v2_meta);
183 15895 av_packet_free(&si->pkt);
184 15895 av_packet_free(&si->parse_pkt);
185 15895 avpriv_packet_list_free(&si->packet_buffer);
186 15895 av_freep(&s->streams);
187 15895 av_freep(&s->stream_groups);
188
2/2
✓ Branch 0 taken 7591 times.
✓ Branch 1 taken 8304 times.
15895 if (s->iformat)
189 7591 ff_flush_packet_queue(s);
190 15895 av_freep(&s->url);
191 15895 av_free(s);
192 }
193
194 /**
195 * Copy all stream parameters from source to destination stream, with the
196 * exception of the index field, which is usually set by avformat_new_stream().
197 *
198 * @param dst pointer to destination AVStream
199 * @param src pointer to source AVStream
200 * @return >=0 on success, AVERROR code on error
201 */
202 20 static int stream_params_copy(AVStream *dst, const AVStream *src)
203 {
204 int ret;
205
206 20 dst->id = src->id;
207 20 dst->time_base = src->time_base;
208 20 dst->start_time = src->start_time;
209 20 dst->duration = src->duration;
210 20 dst->nb_frames = src->nb_frames;
211 20 dst->disposition = src->disposition;
212 20 dst->discard = src->discard;
213 20 dst->sample_aspect_ratio = src->sample_aspect_ratio;
214 20 dst->avg_frame_rate = src->avg_frame_rate;
215 20 dst->event_flags = src->event_flags;
216 20 dst->r_frame_rate = src->r_frame_rate;
217 20 dst->pts_wrap_bits = src->pts_wrap_bits;
218
219 20 av_dict_free(&dst->metadata);
220 20 ret = av_dict_copy(&dst->metadata, src->metadata, 0);
221
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if (ret < 0)
222 return ret;
223
224 20 ret = avcodec_parameters_copy(dst->codecpar, src->codecpar);
225
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if (ret < 0)
226 return ret;
227
228 20 av_packet_unref(&dst->attached_pic);
229
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if (src->attached_pic.data) {
230 ret = av_packet_ref(&dst->attached_pic, &src->attached_pic);
231 if (ret < 0)
232 return ret;
233 }
234
235 20 return 0;
236 }
237
238 20 AVStream *ff_stream_clone(AVFormatContext *dst_ctx, const AVStream *src)
239 {
240 AVStream *st;
241 int ret;
242
243 20 st = avformat_new_stream(dst_ctx, NULL);
244
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if (!st)
245 return NULL;
246
247 20 ret = stream_params_copy(st, src);
248
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if (ret < 0) {
249 ff_remove_stream(dst_ctx, st);
250 return NULL;
251 }
252
253 20 return st;
254 }
255
256 30 const char *avformat_stream_group_name(enum AVStreamGroupParamsType type)
257 {
258
3/5
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 13 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
30 switch(type) {
259 14 case AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT: return "IAMF Audio Element";
260 13 case AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION: return "IAMF Mix Presentation";
261 3 case AV_STREAM_GROUP_PARAMS_TILE_GRID: return "Tile Grid";
262 case AV_STREAM_GROUP_PARAMS_LCEVC: return "LCEVC (Split video and enhancement)";
263 }
264 return NULL;
265 }
266
267 325 AVProgram *av_new_program(AVFormatContext *ac, int id)
268 {
269 325 AVProgram *program = NULL;
270 int ret;
271
272 325 av_log(ac, AV_LOG_TRACE, "new_program: id=0x%04x\n", id);
273
274
2/2
✓ Branch 0 taken 258 times.
✓ Branch 1 taken 325 times.
583 for (unsigned i = 0; i < ac->nb_programs; i++)
275
1/2
✓ Branch 0 taken 258 times.
✗ Branch 1 not taken.
258 if (ac->programs[i]->id == id)
276 258 program = ac->programs[i];
277
278
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 258 times.
325 if (!program) {
279 67 program = av_mallocz(sizeof(*program));
280
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 67 times.
67 if (!program)
281 return NULL;
282 67 ret = av_dynarray_add_nofree(&ac->programs, &ac->nb_programs, program);
283
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 67 times.
67 if (ret < 0) {
284 av_free(program);
285 return NULL;
286 }
287 67 program->discard = AVDISCARD_NONE;
288 67 program->pmt_version = -1;
289 67 program->id = id;
290 67 program->pts_wrap_reference = AV_NOPTS_VALUE;
291 67 program->pts_wrap_behavior = AV_PTS_WRAP_IGNORE;
292 67 program->start_time =
293 67 program->end_time = AV_NOPTS_VALUE;
294 }
295 325 return program;
296 }
297
298 571 void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned idx)
299 {
300 571 AVProgram *program = NULL;
301 void *tmp;
302
303
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 571 times.
571 if (idx >= ac->nb_streams) {
304 av_log(ac, AV_LOG_ERROR, "stream index %d is not valid\n", idx);
305 return;
306 }
307
308
1/2
✓ Branch 0 taken 571 times.
✗ Branch 1 not taken.
571 for (unsigned i = 0; i < ac->nb_programs; i++) {
309
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 571 times.
571 if (ac->programs[i]->id != progid)
310 continue;
311 571 program = ac->programs[i];
312
2/2
✓ Branch 0 taken 939 times.
✓ Branch 1 taken 351 times.
1290 for (unsigned j = 0; j < program->nb_stream_indexes; j++)
313
2/2
✓ Branch 0 taken 220 times.
✓ Branch 1 taken 719 times.
939 if (program->stream_index[j] == idx)
314 220 return;
315
316 351 tmp = av_realloc_array(program->stream_index, program->nb_stream_indexes+1, sizeof(unsigned int));
317
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 351 times.
351 if (!tmp)
318 return;
319 351 program->stream_index = tmp;
320 351 program->stream_index[program->nb_stream_indexes++] = idx;
321 351 return;
322 }
323 }
324
325 13511 AVProgram *av_find_program_from_stream(AVFormatContext *ic, AVProgram *last, int s)
326 {
327
2/2
✓ Branch 0 taken 1205 times.
✓ Branch 1 taken 12943 times.
14148 for (unsigned i = 0; i < ic->nb_programs; i++) {
328
2/2
✓ Branch 0 taken 634 times.
✓ Branch 1 taken 571 times.
1205 if (ic->programs[i] == last) {
329 634 last = NULL;
330 } else {
331
1/2
✓ Branch 0 taken 571 times.
✗ Branch 1 not taken.
571 if (!last)
332
2/2
✓ Branch 0 taken 1685 times.
✓ Branch 1 taken 3 times.
1688 for (unsigned j = 0; j < ic->programs[i]->nb_stream_indexes; j++)
333
2/2
✓ Branch 0 taken 568 times.
✓ Branch 1 taken 1117 times.
1685 if (ic->programs[i]->stream_index[j] == s)
334 568 return ic->programs[i];
335 }
336 }
337 12943 return NULL;
338 }
339
340 1944 int av_find_default_stream_index(AVFormatContext *s)
341 {
342 1944 int best_stream = 0;
343 1944 int best_score = INT_MIN;
344
345
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1944 times.
1944 if (s->nb_streams <= 0)
346 return -1;
347
2/2
✓ Branch 0 taken 2335 times.
✓ Branch 1 taken 1944 times.
4279 for (unsigned i = 0; i < s->nb_streams; i++) {
348 2335 const AVStream *const st = s->streams[i];
349 2335 const FFStream *const sti = cffstream(st);
350 2335 int score = 0;
351
2/2
✓ Branch 0 taken 1354 times.
✓ Branch 1 taken 981 times.
2335 if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
352
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1350 times.
1354 if (st->disposition & AV_DISPOSITION_ATTACHED_PIC)
353 4 score -= 400;
354
3/4
✓ Branch 0 taken 1267 times.
✓ Branch 1 taken 87 times.
✓ Branch 2 taken 1267 times.
✗ Branch 3 not taken.
1354 if (st->codecpar->width && st->codecpar->height)
355 1267 score += 50;
356 1354 score+= 25;
357 }
358
2/2
✓ Branch 0 taken 951 times.
✓ Branch 1 taken 1384 times.
2335 if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
359
2/2
✓ Branch 0 taken 919 times.
✓ Branch 1 taken 32 times.
951 if (st->codecpar->sample_rate)
360 919 score += 50;
361 }
362
2/2
✓ Branch 0 taken 1982 times.
✓ Branch 1 taken 353 times.
2335 if (sti->codec_info_nb_frames)
363 1982 score += 12;
364
365
2/2
✓ Branch 0 taken 2331 times.
✓ Branch 1 taken 4 times.
2335 if (st->discard != AVDISCARD_ALL)
366 2331 score += 200;
367
368
2/2
✓ Branch 0 taken 1983 times.
✓ Branch 1 taken 352 times.
2335 if (score > best_score) {
369 1983 best_score = score;
370 1983 best_stream = i;
371 }
372 }
373 1944 return best_stream;
374 }
375
376 18 int av_find_best_stream(AVFormatContext *ic, enum AVMediaType type,
377 int wanted_stream_nb, int related_stream,
378 const AVCodec **decoder_ret, int flags)
379 {
380 18 int nb_streams = ic->nb_streams;
381 18 int ret = AVERROR_STREAM_NOT_FOUND;
382 18 int best_count = -1, best_multiframe = -1, best_disposition = -1;
383 int count, multiframe, disposition;
384 18 int64_t best_bitrate = -1;
385 int64_t bitrate;
386 18 unsigned *program = NULL;
387 18 const AVCodec *decoder = NULL, *best_decoder = NULL;
388
389
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18 if (related_stream >= 0 && wanted_stream_nb < 0) {
390 AVProgram *p = av_find_program_from_stream(ic, NULL, related_stream);
391 if (p) {
392 program = p->stream_index;
393 nb_streams = p->nb_stream_indexes;
394 }
395 }
396
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 18 times.
39 for (unsigned i = 0; i < nb_streams; i++) {
397
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 int real_stream_index = program ? program[i] : i;
398 21 AVStream *st = ic->streams[real_stream_index];
399 21 AVCodecParameters *par = st->codecpar;
400
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 18 times.
21 if (par->codec_type != type)
401 3 continue;
402
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18 if (wanted_stream_nb >= 0 && real_stream_index != wanted_stream_nb)
403 continue;
404
4/6
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 15 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3 times.
18 if (type == AVMEDIA_TYPE_AUDIO && !(par->ch_layout.nb_channels && par->sample_rate))
405 continue;
406
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (decoder_ret) {
407 decoder = ff_find_decoder(ic, st, par->codec_id);
408 if (!decoder) {
409 if (ret < 0)
410 ret = AVERROR_DECODER_NOT_FOUND;
411 continue;
412 }
413 }
414 18 disposition = !(st->disposition & (AV_DISPOSITION_HEARING_IMPAIRED | AV_DISPOSITION_VISUAL_IMPAIRED))
415 18 + !! (st->disposition & AV_DISPOSITION_DEFAULT);
416 18 count = ffstream(st)->codec_info_nb_frames;
417 18 bitrate = par->bit_rate;
418 18 multiframe = FFMIN(5, count);
419
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18 times.
18 if ((best_disposition > disposition) ||
420
1/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18 times.
18 (best_disposition == disposition && best_multiframe > multiframe) ||
421
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 18 times.
18 (best_disposition == disposition && best_multiframe == multiframe && best_bitrate > bitrate) ||
422 (best_disposition == disposition && best_multiframe == multiframe && best_bitrate == bitrate && best_count >= count))
423 continue;
424 18 best_disposition = disposition;
425 18 best_count = count;
426 18 best_bitrate = bitrate;
427 18 best_multiframe = multiframe;
428 18 ret = real_stream_index;
429 18 best_decoder = decoder;
430
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
18 if (program && i == nb_streams - 1 && ret < 0) {
431 program = NULL;
432 nb_streams = ic->nb_streams;
433 /* no related stream found, try again with everything */
434 i = 0;
435 }
436 }
437
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (decoder_ret)
438 *decoder_ret = best_decoder;
439 18 return ret;
440 }
441
442 /**
443 * Matches a stream specifier (but ignores requested index).
444 *
445 * @param indexptr set to point to the requested stream index if there is one
446 *
447 * @return <0 on error
448 * 0 if st is NOT a matching stream
449 * >0 if st is a matching stream
450 */
451 54 static int match_stream_specifier(const AVFormatContext *s, const AVStream *st,
452 const char *spec, const char **indexptr,
453 const AVStreamGroup **g, const AVProgram **p)
454 {
455 54 int match = 1; /* Stores if the specifier matches so far. */
456
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 32 times.
106 while (*spec) {
457
3/4
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 52 times.
✓ Branch 2 taken 22 times.
✗ Branch 3 not taken.
74 if (*spec <= '9' && *spec >= '0') { /* opt:index */
458
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 7 times.
22 if (indexptr)
459 15 *indexptr = spec;
460 22 return match;
461
6/8
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 31 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 15 times.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
52 } else if (*spec == 'v' || *spec == 'a' || *spec == 's' || *spec == 'd' ||
462
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
52 *spec == 't' || *spec == 'V') { /* opt:[vasdtV] */
463 enum AVMediaType type;
464 46 int nopic = 0;
465
466
2/7
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
46 switch (*spec++) {
467 31 case 'v': type = AVMEDIA_TYPE_VIDEO; break;
468 15 case 'a': type = AVMEDIA_TYPE_AUDIO; break;
469 case 's': type = AVMEDIA_TYPE_SUBTITLE; break;
470 case 'd': type = AVMEDIA_TYPE_DATA; break;
471 case 't': type = AVMEDIA_TYPE_ATTACHMENT; break;
472 case 'V': type = AVMEDIA_TYPE_VIDEO; nopic = 1; break;
473 default: av_assert0(0);
474 }
475
3/4
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 14 times.
46 if (*spec && *spec++ != ':') /* If we are not at the end, then another specifier must follow. */
476 return AVERROR(EINVAL);
477
478
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 35 times.
46 if (type != st->codecpar->codec_type)
479 11 match = 0;
480
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
46 if (nopic && (st->disposition & AV_DISPOSITION_ATTACHED_PIC))
481 match = 0;
482
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 } else if (*spec == 'g' && *(spec + 1) == ':') {
483 int64_t group_idx = -1, group_id = -1;
484 int found = 0;
485 char *endptr;
486 spec += 2;
487 if (*spec == '#' || (*spec == 'i' && *(spec + 1) == ':')) {
488 spec += 1 + (*spec == 'i');
489 group_id = strtol(spec, &endptr, 0);
490 if (spec == endptr || (*endptr && *endptr++ != ':'))
491 return AVERROR(EINVAL);
492 spec = endptr;
493 } else {
494 group_idx = strtol(spec, &endptr, 0);
495 /* Disallow empty id and make sure that if we are not at the end, then another specifier must follow. */
496 if (spec == endptr || (*endptr && *endptr++ != ':'))
497 return AVERROR(EINVAL);
498 spec = endptr;
499 }
500 if (match) {
501 if (group_id > 0) {
502 for (unsigned i = 0; i < s->nb_stream_groups; i++) {
503 if (group_id == s->stream_groups[i]->id) {
504 group_idx = i;
505 break;
506 }
507 }
508 }
509 if (group_idx < 0 || group_idx >= s->nb_stream_groups)
510 return AVERROR(EINVAL);
511 for (unsigned j = 0; j < s->stream_groups[group_idx]->nb_streams; j++) {
512 if (st->index == s->stream_groups[group_idx]->streams[j]->index) {
513 found = 1;
514 if (g)
515 *g = s->stream_groups[group_idx];
516 break;
517 }
518 }
519 }
520 if (!found)
521 match = 0;
522
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) == ':') {
523 int prog_id;
524 6 int found = 0;
525 char *endptr;
526 6 spec += 2;
527 6 prog_id = strtol(spec, &endptr, 0);
528 /* Disallow empty id and make sure that if we are not at the end, then another specifier must follow. */
529
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++ != ':'))
530 return AVERROR(EINVAL);
531 6 spec = endptr;
532
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (match) {
533
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 for (unsigned i = 0; i < s->nb_programs; i++) {
534
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (s->programs[i]->id != prog_id)
535 continue;
536
537
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++) {
538
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 3 times.
8 if (st->index == s->programs[i]->stream_index[j]) {
539 5 found = 1;
540
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3 times.
5 if (p)
541 2 *p = s->programs[i];
542 5 i = s->nb_programs;
543 5 break;
544 }
545 }
546 }
547 }
548
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 5 times.
6 if (!found)
549 1 match = 0;
550 } else if (*spec == '#' ||
551 (*spec == 'i' && *(spec + 1) == ':')) {
552 int stream_id;
553 char *endptr;
554 spec += 1 + (*spec == 'i');
555 stream_id = strtol(spec, &endptr, 0);
556 if (spec == endptr || *endptr) /* Disallow empty id and make sure we are at the end. */
557 return AVERROR(EINVAL);
558 return match && (stream_id == st->id);
559 } else if (*spec == 'm' && *(spec + 1) == ':') {
560 const AVDictionaryEntry *tag;
561 char *key, *val;
562 int ret;
563
564 if (match) {
565 spec += 2;
566 val = strchr(spec, ':');
567
568 key = val ? av_strndup(spec, val - spec) : av_strdup(spec);
569 if (!key)
570 return AVERROR(ENOMEM);
571
572 tag = av_dict_get(st->metadata, key, NULL, 0);
573 if (tag) {
574 if (!val || !strcmp(tag->value, val + 1))
575 ret = 1;
576 else
577 ret = 0;
578 } else
579 ret = 0;
580
581 av_freep(&key);
582 }
583 return match && ret;
584 } else if (*spec == 'u' && *(spec + 1) == '\0') {
585 const AVCodecParameters *par = st->codecpar;
586 int val;
587 switch (par->codec_type) {
588 case AVMEDIA_TYPE_AUDIO:
589 val = par->sample_rate && par->ch_layout.nb_channels;
590 if (par->format == AV_SAMPLE_FMT_NONE)
591 return 0;
592 break;
593 case AVMEDIA_TYPE_VIDEO:
594 val = par->width && par->height;
595 if (par->format == AV_PIX_FMT_NONE)
596 return 0;
597 break;
598 case AVMEDIA_TYPE_UNKNOWN:
599 val = 0;
600 break;
601 default:
602 val = 1;
603 break;
604 }
605 return match && (par->codec_id != AV_CODEC_ID_NONE && val != 0);
606 } else {
607 return AVERROR(EINVAL);
608 }
609 }
610
611 32 return match;
612 }
613
614 47 int avformat_match_stream_specifier(AVFormatContext *s, AVStream *st,
615 const char *spec)
616 {
617 int ret, index;
618 char *endptr;
619 47 const char *indexptr = NULL;
620 47 const AVStreamGroup *g = NULL;
621 47 const AVProgram *p = NULL;
622 int nb_streams;
623
624 47 ret = match_stream_specifier(s, st, spec, &indexptr, &g, &p);
625
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 47 times.
47 if (ret < 0)
626 goto error;
627
628
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 15 times.
47 if (!indexptr)
629 32 return ret;
630
631 15 index = strtol(indexptr, &endptr, 0);
632
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
15 if (*endptr) { /* We can't have anything after the requested index. */
633 ret = AVERROR(EINVAL);
634 goto error;
635 }
636
637 /* This is not really needed but saves us a loop for simple stream index specifiers. */
638
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 7 times.
15 if (spec == indexptr)
639 8 return (index == st->index);
640
641 /* If we requested a matching stream index, we have to ensure st is that. */
642
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 5 times.
7 nb_streams = g ? g->nb_streams : (p ? p->nb_stream_indexes : s->nb_streams);
643
3/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 4 times.
11 for (int i = 0; i < nb_streams && index >= 0; i++) {
644
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 5 times.
7 unsigned idx = g ? g->streams[i]->index : (p ? p->stream_index[i] : i);
645 7 const AVStream *candidate = s->streams[idx];
646 7 ret = match_stream_specifier(s, candidate, spec, NULL, NULL, NULL);
647
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if (ret < 0)
648 goto error;
649
4/6
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 4 times.
7 if (ret > 0 && index-- == 0 && st == candidate)
650 3 return 1;
651 }
652 4 return 0;
653
654 error:
655 if (ret == AVERROR(EINVAL))
656 av_log(s, AV_LOG_ERROR, "Invalid stream specifier: %s.\n", spec);
657 return ret;
658 }
659
660 675 AVRational av_guess_sample_aspect_ratio(AVFormatContext *format, AVStream *stream, AVFrame *frame)
661 {
662 675 AVRational undef = {0, 1};
663
1/2
✓ Branch 0 taken 675 times.
✗ Branch 1 not taken.
675 AVRational stream_sample_aspect_ratio = stream ? stream->sample_aspect_ratio : undef;
664
2/4
✓ Branch 0 taken 675 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 675 times.
✗ Branch 3 not taken.
675 AVRational codec_sample_aspect_ratio = stream && stream->codecpar ? stream->codecpar->sample_aspect_ratio : undef;
665
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 99 times.
675 AVRational frame_sample_aspect_ratio = frame ? frame->sample_aspect_ratio : codec_sample_aspect_ratio;
666
667 675 av_reduce(&stream_sample_aspect_ratio.num, &stream_sample_aspect_ratio.den,
668 675 stream_sample_aspect_ratio.num, stream_sample_aspect_ratio.den, INT_MAX);
669
3/4
✓ Branch 0 taken 538 times.
✓ Branch 1 taken 137 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 538 times.
675 if (stream_sample_aspect_ratio.num <= 0 || stream_sample_aspect_ratio.den <= 0)
670 137 stream_sample_aspect_ratio = undef;
671
672 675 av_reduce(&frame_sample_aspect_ratio.num, &frame_sample_aspect_ratio.den,
673 675 frame_sample_aspect_ratio.num, frame_sample_aspect_ratio.den, INT_MAX);
674
3/4
✓ Branch 0 taken 456 times.
✓ Branch 1 taken 219 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 456 times.
675 if (frame_sample_aspect_ratio.num <= 0 || frame_sample_aspect_ratio.den <= 0)
675 219 frame_sample_aspect_ratio = undef;
676
677
2/2
✓ Branch 0 taken 538 times.
✓ Branch 1 taken 137 times.
675 if (stream_sample_aspect_ratio.num)
678 538 return stream_sample_aspect_ratio;
679 else
680 137 return frame_sample_aspect_ratio;
681 }
682
683 5520 AVRational av_guess_frame_rate(AVFormatContext *format, AVStream *st, AVFrame *frame)
684 {
685 5520 AVRational fr = st->r_frame_rate;
686 5520 const AVCodecDescriptor *desc = cffstream(st)->codec_desc;
687 5520 AVRational avg_fr = st->avg_frame_rate;
688
689
7/10
✓ Branch 0 taken 4877 times.
✓ Branch 1 taken 643 times.
✓ Branch 2 taken 4877 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4877 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4877 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4852 times.
✓ Branch 9 taken 25 times.
10397 if (avg_fr.num > 0 && avg_fr.den > 0 && fr.num > 0 && fr.den > 0 &&
690
2/2
✓ Branch 2 taken 385 times.
✓ Branch 3 taken 4467 times.
9729 av_q2d(avg_fr) < 70 && av_q2d(fr) > 210) {
691 385 fr = avg_fr;
692 }
693
694
3/4
✓ Branch 0 taken 5520 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 319 times.
✓ Branch 3 taken 5201 times.
5520 if (desc && (desc->props & AV_CODEC_PROP_FIELDS)) {
695 319 const AVCodecContext *const avctx = ffstream(st)->avctx;
696 319 AVRational codec_fr = avctx->framerate;
697
698
3/4
✓ Branch 0 taken 123 times.
✓ Branch 1 taken 196 times.
✓ Branch 2 taken 123 times.
✗ Branch 3 not taken.
319 if ( codec_fr.num > 0 && codec_fr.den > 0 &&
699
5/6
✓ Branch 0 taken 123 times.
✗ Branch 1 not taken.
✓ Branch 4 taken 36 times.
✓ Branch 5 taken 87 times.
✓ Branch 7 taken 34 times.
✓ Branch 8 taken 2 times.
123 (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))
700 34 fr = codec_fr;
701 }
702
703 5520 return fr;
704 }
705
706 #if FF_API_INTERNAL_TIMING
707 int avformat_transfer_internal_stream_timing_info(const AVOutputFormat *ofmt,
708 AVStream *ost, const AVStream *ist,
709 enum AVTimebaseSource copy_tb)
710 {
711 const AVCodecDescriptor *desc = cffstream(ist)->codec_desc;
712 const AVCodecContext *const dec_ctx = cffstream(ist)->avctx;
713
714 AVRational mul = (AVRational){ desc && (desc->props & AV_CODEC_PROP_FIELDS) ? 2 : 1, 1 };
715 AVRational dec_ctx_framerate = dec_ctx ? dec_ctx->framerate : (AVRational){ 0, 0 };
716 AVRational dec_ctx_tb = dec_ctx_framerate.num ? av_inv_q(av_mul_q(dec_ctx_framerate, mul))
717 : (ist->codecpar->codec_type == AVMEDIA_TYPE_AUDIO ? (AVRational){0, 1}
718 : ist->time_base);
719 AVRational enc_tb = ist->time_base;
720
721 /*
722 * Avi is a special case here because it supports variable fps but
723 * having the fps and timebase differe significantly adds quite some
724 * overhead
725 */
726 if (!strcmp(ofmt->name, "avi")) {
727 #if FF_API_R_FRAME_RATE
728 if (copy_tb == AVFMT_TBCF_AUTO && ist->r_frame_rate.num
729 && av_q2d(ist->r_frame_rate) >= av_q2d(ist->avg_frame_rate)
730 && 0.5/av_q2d(ist->r_frame_rate) > av_q2d(ist->time_base)
731 && 0.5/av_q2d(ist->r_frame_rate) > av_q2d(dec_ctx_tb)
732 && av_q2d(ist->time_base) < 1.0/500 && av_q2d(dec_ctx_tb) < 1.0/500
733 || copy_tb == AVFMT_TBCF_R_FRAMERATE) {
734 enc_tb.num = ist->r_frame_rate.den;
735 enc_tb.den = 2*ist->r_frame_rate.num;
736 } else
737 #endif
738 if (copy_tb == AVFMT_TBCF_AUTO && dec_ctx_framerate.num &&
739 av_q2d(av_inv_q(dec_ctx_framerate)) > 2*av_q2d(ist->time_base)
740 && av_q2d(ist->time_base) < 1.0/500
741 || (copy_tb == AVFMT_TBCF_DECODER &&
742 (dec_ctx_framerate.num || ist->codecpar->codec_type == AVMEDIA_TYPE_AUDIO))) {
743 enc_tb = dec_ctx_tb;
744 enc_tb.den *= 2;
745 }
746 } else if (!(ofmt->flags & AVFMT_VARIABLE_FPS)
747 && !av_match_name(ofmt->name, "mov,mp4,3gp,3g2,psp,ipod,ismv,f4v")) {
748 if (copy_tb == AVFMT_TBCF_AUTO && dec_ctx_framerate.num
749 && av_q2d(av_inv_q(dec_ctx_framerate)) > av_q2d(ist->time_base)
750 && av_q2d(ist->time_base) < 1.0/500
751 || (copy_tb == AVFMT_TBCF_DECODER &&
752 (dec_ctx_framerate.num || ist->codecpar->codec_type == AVMEDIA_TYPE_AUDIO))) {
753 enc_tb = dec_ctx_tb;
754 }
755 }
756
757 if (ost->codecpar->codec_tag == AV_RL32("tmcd")
758 && dec_ctx_tb.num < dec_ctx_tb.den
759 && dec_ctx_tb.num > 0
760 && 121LL*dec_ctx_tb.num > dec_ctx_tb.den) {
761 enc_tb = dec_ctx_tb;
762 }
763
764 av_reduce(&ffstream(ost)->transferred_mux_tb.num,
765 &ffstream(ost)->transferred_mux_tb.den,
766 enc_tb.num, enc_tb.den, INT_MAX);
767
768 return 0;
769 }
770
771 AVRational av_stream_get_codec_timebase(const AVStream *st)
772 {
773 return cffstream(st)->avctx ? cffstream(st)->avctx->time_base : cffstream(st)->transferred_mux_tb;
774 }
775 #endif
776
777 20822 void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits,
778 unsigned int pts_num, unsigned int pts_den)
779 {
780 20822 FFStream *const sti = ffstream(st);
781 AVRational new_tb;
782
1/2
✓ Branch 1 taken 20822 times.
✗ Branch 2 not taken.
20822 if (av_reduce(&new_tb.num, &new_tb.den, pts_num, pts_den, INT_MAX)) {
783
2/2
✓ Branch 0 taken 538 times.
✓ Branch 1 taken 20284 times.
20822 if (new_tb.num != pts_num)
784 538 av_log(NULL, AV_LOG_DEBUG,
785 "st:%d removing common factor %d from timebase\n",
786 538 st->index, pts_num / new_tb.num);
787 } else
788 av_log(NULL, AV_LOG_WARNING,
789 "st:%d has too large timebase, reducing\n", st->index);
790
791
3/4
✓ Branch 0 taken 20821 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 20821 times.
20822 if (new_tb.num <= 0 || new_tb.den <= 0) {
792 1 av_log(NULL, AV_LOG_ERROR,
793 "Ignoring attempt to set invalid timebase %d/%d for st:%d\n",
794 new_tb.num, new_tb.den,
795 st->index);
796 1 return;
797 }
798 20821 st->time_base = new_tb;
799
2/2
✓ Branch 0 taken 16785 times.
✓ Branch 1 taken 4036 times.
20821 if (sti->avctx)
800 16785 sti->avctx->pkt_timebase = new_tb;
801 20821 st->pts_wrap_bits = pts_wrap_bits;
802 }
803
804 9325 const AVCodec *ff_find_decoder(AVFormatContext *s, const AVStream *st,
805 enum AVCodecID codec_id)
806 {
807
4/4
✓ Branch 0 taken 6554 times.
✓ Branch 1 taken 2531 times.
✓ Branch 2 taken 92 times.
✓ Branch 3 taken 148 times.
9325 switch (st->codecpar->codec_type) {
808 6554 case AVMEDIA_TYPE_VIDEO:
809
2/2
✓ Branch 0 taken 3040 times.
✓ Branch 1 taken 3514 times.
6554 if (s->video_codec) return s->video_codec;
810 3514 break;
811 2531 case AVMEDIA_TYPE_AUDIO:
812
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 2513 times.
2531 if (s->audio_codec) return s->audio_codec;
813 2513 break;
814 92 case AVMEDIA_TYPE_SUBTITLE:
815
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 92 times.
92 if (s->subtitle_codec) return s->subtitle_codec;
816 92 break;
817 }
818
819 6267 return avcodec_find_decoder(codec_id);
820 }
821
822 83 int ff_copy_whiteblacklists(AVFormatContext *dst, const AVFormatContext *src)
823 {
824 #define OFF(field) offsetof(AVFormatContext, field)
825 static const unsigned offsets[] = {
826 OFF(codec_whitelist), OFF(format_whitelist),
827 OFF(protocol_whitelist), OFF(protocol_blacklist),
828 };
829 #undef OFF
830
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 &&
831 !dst->format_whitelist &&
832 !dst->protocol_whitelist &&
833 !dst->protocol_blacklist);
834
2/2
✓ Branch 0 taken 332 times.
✓ Branch 1 taken 83 times.
415 for (unsigned i = 0; i < FF_ARRAY_ELEMS(offsets); i++) {
835 332 const char *src_str = *(char *const*)((const char*)src + offsets[i]);
836
837
2/2
✓ Branch 0 taken 83 times.
✓ Branch 1 taken 249 times.
332 if (src_str) {
838 83 char *dst_str = av_strdup(src_str);
839
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 83 times.
83 if (!dst_str) {
840 av_log(dst, AV_LOG_ERROR, "Failed to duplicate black/whitelist\n");
841 return AVERROR(ENOMEM);
842 }
843
844 83 *(char **)((char*)dst + offsets[i]) = dst_str;
845 }
846 }
847 83 return 0;
848 }
849
850 578674 int ff_is_intra_only(enum AVCodecID id)
851 {
852 578674 const AVCodecDescriptor *d = avcodec_descriptor_get(id);
853
2/2
✓ Branch 0 taken 65 times.
✓ Branch 1 taken 578609 times.
578674 if (!d)
854 65 return 0;
855
4/4
✓ Branch 0 taken 327484 times.
✓ Branch 1 taken 251125 times.
✓ Branch 2 taken 324553 times.
✓ Branch 3 taken 2931 times.
578609 if ((d->type == AVMEDIA_TYPE_VIDEO || d->type == AVMEDIA_TYPE_AUDIO) &&
856
2/2
✓ Branch 0 taken 196631 times.
✓ Branch 1 taken 379047 times.
575678 !(d->props & AV_CODEC_PROP_INTRA_ONLY))
857 196631 return 0;
858 381978 return 1;
859 }
860
861 68 void ff_format_set_url(AVFormatContext *s, char *url)
862 {
863
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 68 times.
68 av_assert0(url);
864 68 av_freep(&s->url);
865 68 s->url = url;
866 68 }
867
868 100715 int ff_format_io_close(AVFormatContext *s, AVIOContext **pb)
869 {
870 100715 int ret = 0;
871
2/2
✓ Branch 0 taken 100478 times.
✓ Branch 1 taken 237 times.
100715 if (*pb)
872 100478 ret = s->io_close2(s, *pb);
873 100715 *pb = NULL;
874 100715 return ret;
875 }
876