FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/utils.c
Date: 2025-04-25 22:50:00
Exec Total Coverage
Lines: 382 507 75.3%
Functions: 25 29 86.2%
Branches: 280 385 72.7%

Line Branch Exec Source
1 /*
2 * utils for libavcodec
3 * Copyright (c) 2001 Fabrice Bellard
4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 /**
24 * @file
25 * utils.
26 */
27
28 #include "config.h"
29 #include "libavutil/avassert.h"
30 #include "libavutil/channel_layout.h"
31 #include "libavutil/intreadwrite.h"
32 #include "libavutil/mem.h"
33 #include "libavutil/pixdesc.h"
34 #include "libavutil/imgutils.h"
35 #include "libavutil/pixfmt.h"
36 #include "libavutil/timecode_internal.h"
37 #include "avcodec.h"
38 #include "codec.h"
39 #include "codec_desc.h"
40 #include "codec_internal.h"
41 #include "codec_par.h"
42 #include "decode.h"
43 #include "hwconfig.h"
44 #include "libavutil/refstruct.h"
45 #include "thread.h"
46 #include "threadframe.h"
47 #include "internal.h"
48 #include "put_bits.h"
49 #include "startcode.h"
50 #include <stdlib.h>
51 #include <limits.h>
52
53 192531 void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
54 {
55 192531 uint8_t **p = ptr;
56
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 192531 times.
192531 if (min_size > SIZE_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
57 av_freep(p);
58 *size = 0;
59 return;
60 }
61 192531 av_fast_mallocz(p, size, min_size + AV_INPUT_BUFFER_PADDING_SIZE);
62
1/2
✓ Branch 0 taken 192531 times.
✗ Branch 1 not taken.
192531 if (*p)
63 192531 memset(*p + min_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
64 }
65
66 697 void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size)
67 {
68 697 uint8_t **p = ptr;
69
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 697 times.
697 if (min_size > SIZE_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
70 av_freep(p);
71 *size = 0;
72 return;
73 }
74 697 av_fast_malloc(p, size, min_size + AV_INPUT_BUFFER_PADDING_SIZE);
75
1/2
✓ Branch 0 taken 697 times.
✗ Branch 1 not taken.
697 if (*p)
76 697 memset(*p, 0, min_size + AV_INPUT_BUFFER_PADDING_SIZE);
77 }
78
79 2356442 int av_codec_is_encoder(const AVCodec *avcodec)
80 {
81 2356442 const FFCodec *const codec = ffcodec(avcodec);
82
4/4
✓ Branch 0 taken 2346744 times.
✓ Branch 1 taken 9698 times.
✓ Branch 2 taken 1384839 times.
✓ Branch 3 taken 961905 times.
2356442 return codec && !codec->is_decoder;
83 }
84
85 470758 int av_codec_is_decoder(const AVCodec *avcodec)
86 {
87 470758 const FFCodec *const codec = ffcodec(avcodec);
88
4/4
✓ Branch 0 taken 461060 times.
✓ Branch 1 taken 9698 times.
✓ Branch 2 taken 439702 times.
✓ Branch 3 taken 21358 times.
470758 return codec && codec->is_decoder;
89 }
90
91 75484 int ff_set_dimensions(AVCodecContext *s, int width, int height)
92 {
93 75484 int ret = av_image_check_size2(width, height, s->max_pixels, AV_PIX_FMT_NONE, 0, s);
94
95
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 75483 times.
75484 if (ret < 0)
96 1 width = height = 0;
97
98 75484 s->coded_width = width;
99 75484 s->coded_height = height;
100 75484 s->width = AV_CEIL_RSHIFT(width, s->lowres);
101 75484 s->height = AV_CEIL_RSHIFT(height, s->lowres);
102
103 75484 return ret;
104 }
105
106 2909 int ff_set_sar(AVCodecContext *avctx, AVRational sar)
107 {
108 2909 int ret = av_image_check_sar(avctx->width, avctx->height, sar);
109
110
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2904 times.
2909 if (ret < 0) {
111 5 av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %d/%d\n",
112 sar.num, sar.den);
113 5 avctx->sample_aspect_ratio = (AVRational){ 0, 1 };
114 5 return ret;
115 } else {
116 2904 avctx->sample_aspect_ratio = sar;
117 }
118 2904 return 0;
119 }
120
121 2977 int ff_side_data_update_matrix_encoding(AVFrame *frame,
122 enum AVMatrixEncoding matrix_encoding)
123 {
124 AVFrameSideData *side_data;
125 enum AVMatrixEncoding *data;
126
127 2977 side_data = av_frame_get_side_data(frame, AV_FRAME_DATA_MATRIXENCODING);
128
1/2
✓ Branch 0 taken 2977 times.
✗ Branch 1 not taken.
2977 if (!side_data)
129 2977 side_data = av_frame_new_side_data(frame, AV_FRAME_DATA_MATRIXENCODING,
130 sizeof(enum AVMatrixEncoding));
131
132
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2977 times.
2977 if (!side_data)
133 return AVERROR(ENOMEM);
134
135 2977 data = (enum AVMatrixEncoding*)side_data->data;
136 2977 *data = matrix_encoding;
137
138 2977 return 0;
139 }
140
141 10431 void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height,
142 int linesize_align[AV_NUM_DATA_POINTERS])
143 {
144 int i;
145 10431 int w_align = 1;
146 10431 int h_align = 1;
147 10431 AVPixFmtDescriptor const *desc = av_pix_fmt_desc_get(s->pix_fmt);
148
149
1/2
✓ Branch 0 taken 10431 times.
✗ Branch 1 not taken.
10431 if (desc) {
150 10431 w_align = 1 << desc->log2_chroma_w;
151 10431 h_align = 1 << desc->log2_chroma_h;
152 }
153
154
9/9
✓ Branch 0 taken 9509 times.
✓ Branch 1 taken 26 times.
✓ Branch 2 taken 21 times.
✓ Branch 3 taken 38 times.
✓ Branch 4 taken 133 times.
✓ Branch 5 taken 81 times.
✓ Branch 6 taken 214 times.
✓ Branch 7 taken 23 times.
✓ Branch 8 taken 386 times.
10431 switch (s->pix_fmt) {
155 9509 case AV_PIX_FMT_YUV420P:
156 case AV_PIX_FMT_YUYV422:
157 case AV_PIX_FMT_YVYU422:
158 case AV_PIX_FMT_UYVY422:
159 case AV_PIX_FMT_YUV422P:
160 case AV_PIX_FMT_YUV440P:
161 case AV_PIX_FMT_YUV444P:
162 case AV_PIX_FMT_GBRP:
163 case AV_PIX_FMT_GBRAP:
164 case AV_PIX_FMT_GRAY8:
165 case AV_PIX_FMT_GRAY16BE:
166 case AV_PIX_FMT_GRAY16LE:
167 case AV_PIX_FMT_YUVJ420P:
168 case AV_PIX_FMT_YUVJ422P:
169 case AV_PIX_FMT_YUVJ440P:
170 case AV_PIX_FMT_YUVJ444P:
171 case AV_PIX_FMT_YUVA420P:
172 case AV_PIX_FMT_YUVA422P:
173 case AV_PIX_FMT_YUVA444P:
174 case AV_PIX_FMT_YUV420P9LE:
175 case AV_PIX_FMT_YUV420P9BE:
176 case AV_PIX_FMT_YUV420P10LE:
177 case AV_PIX_FMT_YUV420P10BE:
178 case AV_PIX_FMT_YUV420P12LE:
179 case AV_PIX_FMT_YUV420P12BE:
180 case AV_PIX_FMT_YUV420P14LE:
181 case AV_PIX_FMT_YUV420P14BE:
182 case AV_PIX_FMT_YUV420P16LE:
183 case AV_PIX_FMT_YUV420P16BE:
184 case AV_PIX_FMT_YUVA420P9LE:
185 case AV_PIX_FMT_YUVA420P9BE:
186 case AV_PIX_FMT_YUVA420P10LE:
187 case AV_PIX_FMT_YUVA420P10BE:
188 case AV_PIX_FMT_YUVA420P16LE:
189 case AV_PIX_FMT_YUVA420P16BE:
190 case AV_PIX_FMT_YUV422P9LE:
191 case AV_PIX_FMT_YUV422P9BE:
192 case AV_PIX_FMT_YUV422P10LE:
193 case AV_PIX_FMT_YUV422P10BE:
194 case AV_PIX_FMT_YUV422P12LE:
195 case AV_PIX_FMT_YUV422P12BE:
196 case AV_PIX_FMT_YUV422P14LE:
197 case AV_PIX_FMT_YUV422P14BE:
198 case AV_PIX_FMT_YUV422P16LE:
199 case AV_PIX_FMT_YUV422P16BE:
200 case AV_PIX_FMT_YUVA422P9LE:
201 case AV_PIX_FMT_YUVA422P9BE:
202 case AV_PIX_FMT_YUVA422P10LE:
203 case AV_PIX_FMT_YUVA422P10BE:
204 case AV_PIX_FMT_YUVA422P12LE:
205 case AV_PIX_FMT_YUVA422P12BE:
206 case AV_PIX_FMT_YUVA422P16LE:
207 case AV_PIX_FMT_YUVA422P16BE:
208 case AV_PIX_FMT_YUV440P10LE:
209 case AV_PIX_FMT_YUV440P10BE:
210 case AV_PIX_FMT_YUV440P12LE:
211 case AV_PIX_FMT_YUV440P12BE:
212 case AV_PIX_FMT_YUV444P9LE:
213 case AV_PIX_FMT_YUV444P9BE:
214 case AV_PIX_FMT_YUV444P10LE:
215 case AV_PIX_FMT_YUV444P10BE:
216 case AV_PIX_FMT_YUV444P12LE:
217 case AV_PIX_FMT_YUV444P12BE:
218 case AV_PIX_FMT_YUV444P14LE:
219 case AV_PIX_FMT_YUV444P14BE:
220 case AV_PIX_FMT_YUV444P16LE:
221 case AV_PIX_FMT_YUV444P16BE:
222 case AV_PIX_FMT_YUVA444P9LE:
223 case AV_PIX_FMT_YUVA444P9BE:
224 case AV_PIX_FMT_YUVA444P10LE:
225 case AV_PIX_FMT_YUVA444P10BE:
226 case AV_PIX_FMT_YUVA444P12LE:
227 case AV_PIX_FMT_YUVA444P12BE:
228 case AV_PIX_FMT_YUVA444P16LE:
229 case AV_PIX_FMT_YUVA444P16BE:
230 case AV_PIX_FMT_GBRP9LE:
231 case AV_PIX_FMT_GBRP9BE:
232 case AV_PIX_FMT_GBRP10LE:
233 case AV_PIX_FMT_GBRP10BE:
234 case AV_PIX_FMT_GBRP12LE:
235 case AV_PIX_FMT_GBRP12BE:
236 case AV_PIX_FMT_GBRP14LE:
237 case AV_PIX_FMT_GBRP14BE:
238 case AV_PIX_FMT_GBRP16LE:
239 case AV_PIX_FMT_GBRP16BE:
240 case AV_PIX_FMT_GBRAP12LE:
241 case AV_PIX_FMT_GBRAP12BE:
242 case AV_PIX_FMT_GBRAP16LE:
243 case AV_PIX_FMT_GBRAP16BE:
244 9509 w_align = 16; //FIXME assume 16 pixel per macroblock
245 9509 h_align = 16 * 2; // interlaced needs 2 macroblocks height
246
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 9506 times.
9509 if (s->codec_id == AV_CODEC_ID_BINKVIDEO)
247 3 w_align = 16*2;
248 9509 break;
249 26 case AV_PIX_FMT_YUV411P:
250 case AV_PIX_FMT_YUVJ411P:
251 case AV_PIX_FMT_UYYVYY411:
252 26 w_align = 32;
253 26 h_align = 16 * 2;
254 26 break;
255 21 case AV_PIX_FMT_YUV410P:
256
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 11 times.
21 if (s->codec_id == AV_CODEC_ID_SVQ1) {
257 10 w_align = 64;
258 10 h_align = 64;
259
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 } else if (s->codec_id == AV_CODEC_ID_SNOW) {
260 w_align = 16;
261 h_align = 16;
262 }
263 21 break;
264 38 case AV_PIX_FMT_RGB555:
265
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 33 times.
38 if (s->codec_id == AV_CODEC_ID_RPZA) {
266 5 w_align = 4;
267 5 h_align = 4;
268 }
269
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 37 times.
38 if (s->codec_id == AV_CODEC_ID_INTERPLAY_VIDEO) {
270 1 w_align = 8;
271 1 h_align = 8;
272 }
273 38 break;
274 133 case AV_PIX_FMT_PAL8:
275 case AV_PIX_FMT_BGR8:
276 case AV_PIX_FMT_RGB8:
277
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 5 times.
133 if (s->codec_id == AV_CODEC_ID_SMC ||
278
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 127 times.
128 s->codec_id == AV_CODEC_ID_CINEPAK) {
279 6 w_align = 4;
280 6 h_align = 4;
281 }
282
2/2
✓ Branch 0 taken 132 times.
✓ Branch 1 taken 1 times.
133 if (s->codec_id == AV_CODEC_ID_JV ||
283
1/2
✓ Branch 0 taken 132 times.
✗ Branch 1 not taken.
132 s->codec_id == AV_CODEC_ID_ARGO ||
284
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 131 times.
132 s->codec_id == AV_CODEC_ID_INTERPLAY_VIDEO) {
285 2 w_align = 8;
286 2 h_align = 8;
287 }
288
1/2
✓ Branch 0 taken 133 times.
✗ Branch 1 not taken.
133 if (s->codec_id == AV_CODEC_ID_MJPEG ||
289
1/2
✓ Branch 0 taken 133 times.
✗ Branch 1 not taken.
133 s->codec_id == AV_CODEC_ID_MJPEGB ||
290
1/2
✓ Branch 0 taken 133 times.
✗ Branch 1 not taken.
133 s->codec_id == AV_CODEC_ID_LJPEG ||
291
1/2
✓ Branch 0 taken 133 times.
✗ Branch 1 not taken.
133 s->codec_id == AV_CODEC_ID_SMVJPEG ||
292
1/2
✓ Branch 0 taken 133 times.
✗ Branch 1 not taken.
133 s->codec_id == AV_CODEC_ID_AMV ||
293
1/2
✓ Branch 0 taken 133 times.
✗ Branch 1 not taken.
133 s->codec_id == AV_CODEC_ID_SP5X ||
294
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 125 times.
133 s->codec_id == AV_CODEC_ID_JPEGLS) {
295 8 w_align = 8;
296 8 h_align = 2*8;
297 }
298 133 break;
299 81 case AV_PIX_FMT_BGR24:
300
2/2
✓ Branch 0 taken 80 times.
✓ Branch 1 taken 1 times.
81 if ((s->codec_id == AV_CODEC_ID_MSZH) ||
301
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 75 times.
80 (s->codec_id == AV_CODEC_ID_ZLIB)) {
302 6 w_align = 4;
303 6 h_align = 4;
304 }
305 81 break;
306 214 case AV_PIX_FMT_RGB24:
307
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 207 times.
214 if (s->codec_id == AV_CODEC_ID_CINEPAK) {
308 7 w_align = 4;
309 7 h_align = 4;
310 }
311 214 break;
312 23 case AV_PIX_FMT_BGR0:
313
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
23 if (s->codec_id == AV_CODEC_ID_ARGO) {
314 w_align = 8;
315 h_align = 8;
316 }
317 23 break;
318 386 default:
319 386 break;
320 }
321
322
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 10429 times.
10431 if (s->codec_id == AV_CODEC_ID_IFF_ILBM) {
323 2 w_align = FFMAX(w_align, 16);
324 }
325
326 10431 *width = FFALIGN(*width, w_align);
327 10431 *height = FFALIGN(*height, h_align);
328
4/4
✓ Branch 0 taken 9839 times.
✓ Branch 1 taken 592 times.
✓ Branch 2 taken 9838 times.
✓ Branch 3 taken 1 times.
10431 if (s->codec_id == AV_CODEC_ID_H264 || s->lowres ||
329
4/4
✓ Branch 0 taken 9823 times.
✓ Branch 1 taken 15 times.
✓ Branch 2 taken 9816 times.
✓ Branch 3 taken 7 times.
9838 s->codec_id == AV_CODEC_ID_VC1 || s->codec_id == AV_CODEC_ID_WMV3 ||
330
4/4
✓ Branch 0 taken 9815 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 9806 times.
✓ Branch 3 taken 9 times.
9816 s->codec_id == AV_CODEC_ID_VP5 || s->codec_id == AV_CODEC_ID_VP6 ||
331
4/4
✓ Branch 0 taken 9804 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 9802 times.
9806 s->codec_id == AV_CODEC_ID_VP6F || s->codec_id == AV_CODEC_ID_VP6A
332 ) {
333 // some of the optimized chroma MC reads one line too much
334 // which is also done in mpeg decoders with lowres > 0
335 629 *height += 2;
336
337 // H.264 uses edge emulation for out of frame motion vectors, for this
338 // it requires a temporary area large enough to hold a 21x21 block,
339 // increasing witdth ensure that the temporary area is large enough,
340 // the next rounded up width is 32
341 629 *width = FFMAX(*width, 32);
342 }
343
2/2
✓ Branch 0 taken 2618 times.
✓ Branch 1 taken 7813 times.
10431 if (s->codec_id == AV_CODEC_ID_SVQ3) {
344 2618 *width = FFMAX(*width, 32);
345 }
346
347
2/2
✓ Branch 0 taken 41724 times.
✓ Branch 1 taken 10431 times.
52155 for (i = 0; i < 4; i++)
348 41724 linesize_align[i] = STRIDE_ALIGN;
349 10431 }
350
351 void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height)
352 {
353 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->pix_fmt);
354 int chroma_shift = desc->log2_chroma_w;
355 int linesize_align[AV_NUM_DATA_POINTERS];
356 int align;
357
358 avcodec_align_dimensions2(s, width, height, linesize_align);
359 align = FFMAX(linesize_align[0], linesize_align[3]);
360 linesize_align[1] <<= chroma_shift;
361 linesize_align[2] <<= chroma_shift;
362 align = FFMAX3(align, linesize_align[1], linesize_align[2]);
363 *width = FFALIGN(*width, align);
364 }
365
366 int avcodec_fill_audio_frame(AVFrame *frame, int nb_channels,
367 enum AVSampleFormat sample_fmt, const uint8_t *buf,
368 int buf_size, int align)
369 {
370 int ch, planar, needed_size, ret = 0;
371
372 needed_size = av_samples_get_buffer_size(NULL, nb_channels,
373 frame->nb_samples, sample_fmt,
374 align);
375 if (buf_size < needed_size)
376 return AVERROR(EINVAL);
377
378 planar = av_sample_fmt_is_planar(sample_fmt);
379 if (planar && nb_channels > AV_NUM_DATA_POINTERS) {
380 if (!FF_ALLOCZ_TYPED_ARRAY(frame->extended_data, nb_channels))
381 return AVERROR(ENOMEM);
382 } else {
383 frame->extended_data = frame->data;
384 }
385
386 if ((ret = av_samples_fill_arrays(frame->extended_data, &frame->linesize[0],
387 (uint8_t *)(intptr_t)buf, nb_channels, frame->nb_samples,
388 sample_fmt, align)) < 0) {
389 if (frame->extended_data != frame->data)
390 av_freep(&frame->extended_data);
391 return ret;
392 }
393 if (frame->extended_data != frame->data) {
394 for (ch = 0; ch < AV_NUM_DATA_POINTERS; ch++)
395 frame->data[ch] = frame->extended_data[ch];
396 }
397
398 return ret;
399 }
400
401
402 196047 int avpriv_codec_get_cap_skip_frame_fill_param(const AVCodec *codec){
403 196047 return !!(ffcodec(codec)->caps_internal & FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM);
404 }
405
406 28992 const char *avcodec_get_name(enum AVCodecID id)
407 {
408 const AVCodecDescriptor *cd;
409 const AVCodec *codec;
410
411
2/2
✓ Branch 0 taken 243 times.
✓ Branch 1 taken 28749 times.
28992 if (id == AV_CODEC_ID_NONE)
412 243 return "none";
413 28749 cd = avcodec_descriptor_get(id);
414
2/2
✓ Branch 0 taken 28745 times.
✓ Branch 1 taken 4 times.
28749 if (cd)
415 28745 return cd->name;
416 4 av_log(NULL, AV_LOG_WARNING, "Codec 0x%x is not in the full list.\n", id);
417 4 codec = avcodec_find_decoder(id);
418
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (codec)
419 return codec->name;
420 4 codec = avcodec_find_encoder(id);
421
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (codec)
422 return codec->name;
423 4 return "unknown_codec";
424 }
425
426 const char *av_get_profile_name(const AVCodec *codec, int profile)
427 {
428 const AVProfile *p;
429 if (profile == AV_PROFILE_UNKNOWN || !codec->profiles)
430 return NULL;
431
432 for (p = codec->profiles; p->profile != AV_PROFILE_UNKNOWN; p++)
433 if (p->profile == profile)
434 return p->name;
435
436 return NULL;
437 }
438
439 17018 const char *avcodec_profile_name(enum AVCodecID codec_id, int profile)
440 {
441 17018 const AVCodecDescriptor *desc = avcodec_descriptor_get(codec_id);
442 const AVProfile *p;
443
444
5/6
✓ Branch 0 taken 2161 times.
✓ Branch 1 taken 14857 times.
✓ Branch 2 taken 2161 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 132 times.
✓ Branch 5 taken 2029 times.
17018 if (profile == AV_PROFILE_UNKNOWN || !desc || !desc->profiles)
445 14989 return NULL;
446
447
2/2
✓ Branch 0 taken 5169 times.
✓ Branch 1 taken 34 times.
5203 for (p = desc->profiles; p->profile != AV_PROFILE_UNKNOWN; p++)
448
2/2
✓ Branch 0 taken 1995 times.
✓ Branch 1 taken 3174 times.
5169 if (p->profile == profile)
449 1995 return p->name;
450
451 34 return NULL;
452 }
453
454 768987 int av_get_exact_bits_per_sample(enum AVCodecID codec_id)
455 {
456
8/8
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 11408 times.
✓ Branch 2 taken 5185 times.
✓ Branch 3 taken 478843 times.
✓ Branch 4 taken 15505 times.
✓ Branch 5 taken 23077 times.
✓ Branch 6 taken 9512 times.
✓ Branch 7 taken 225433 times.
768987 switch (codec_id) {
457 24 case AV_CODEC_ID_DFPWM:
458 24 return 1;
459 11408 case AV_CODEC_ID_8SVX_EXP:
460 case AV_CODEC_ID_8SVX_FIB:
461 case AV_CODEC_ID_ADPCM_ARGO:
462 case AV_CODEC_ID_ADPCM_CT:
463 case AV_CODEC_ID_ADPCM_IMA_ALP:
464 case AV_CODEC_ID_ADPCM_IMA_AMV:
465 case AV_CODEC_ID_ADPCM_IMA_APC:
466 case AV_CODEC_ID_ADPCM_IMA_APM:
467 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
468 case AV_CODEC_ID_ADPCM_IMA_OKI:
469 case AV_CODEC_ID_ADPCM_IMA_WS:
470 case AV_CODEC_ID_ADPCM_IMA_SSI:
471 case AV_CODEC_ID_ADPCM_G722:
472 case AV_CODEC_ID_ADPCM_YAMAHA:
473 case AV_CODEC_ID_ADPCM_AICA:
474 11408 return 4;
475 5185 case AV_CODEC_ID_DSD_LSBF:
476 case AV_CODEC_ID_DSD_MSBF:
477 case AV_CODEC_ID_DSD_LSBF_PLANAR:
478 case AV_CODEC_ID_DSD_MSBF_PLANAR:
479 case AV_CODEC_ID_PCM_ALAW:
480 case AV_CODEC_ID_PCM_MULAW:
481 case AV_CODEC_ID_PCM_VIDC:
482 case AV_CODEC_ID_PCM_S8:
483 case AV_CODEC_ID_PCM_S8_PLANAR:
484 case AV_CODEC_ID_PCM_SGA:
485 case AV_CODEC_ID_PCM_U8:
486 case AV_CODEC_ID_SDX2_DPCM:
487 case AV_CODEC_ID_CBD2_DPCM:
488 case AV_CODEC_ID_DERF_DPCM:
489 case AV_CODEC_ID_WADY_DPCM:
490 5185 return 8;
491 478843 case AV_CODEC_ID_PCM_S16BE:
492 case AV_CODEC_ID_PCM_S16BE_PLANAR:
493 case AV_CODEC_ID_PCM_S16LE:
494 case AV_CODEC_ID_PCM_S16LE_PLANAR:
495 case AV_CODEC_ID_PCM_U16BE:
496 case AV_CODEC_ID_PCM_U16LE:
497 478843 return 16;
498 15505 case AV_CODEC_ID_PCM_S24DAUD:
499 case AV_CODEC_ID_PCM_S24BE:
500 case AV_CODEC_ID_PCM_S24LE:
501 case AV_CODEC_ID_PCM_S24LE_PLANAR:
502 case AV_CODEC_ID_PCM_U24BE:
503 case AV_CODEC_ID_PCM_U24LE:
504 15505 return 24;
505 23077 case AV_CODEC_ID_PCM_S32BE:
506 case AV_CODEC_ID_PCM_S32LE:
507 case AV_CODEC_ID_PCM_S32LE_PLANAR:
508 case AV_CODEC_ID_PCM_U32BE:
509 case AV_CODEC_ID_PCM_U32LE:
510 case AV_CODEC_ID_PCM_F32BE:
511 case AV_CODEC_ID_PCM_F32LE:
512 case AV_CODEC_ID_PCM_F24LE:
513 case AV_CODEC_ID_PCM_F16LE:
514 23077 return 32;
515 9512 case AV_CODEC_ID_PCM_F64BE:
516 case AV_CODEC_ID_PCM_F64LE:
517 case AV_CODEC_ID_PCM_S64BE:
518 case AV_CODEC_ID_PCM_S64LE:
519 9512 return 64;
520 225433 default:
521 225433 return 0;
522 }
523 }
524
525 24 enum AVCodecID av_get_pcm_codec(enum AVSampleFormat fmt, int be)
526 {
527 static const enum AVCodecID map[][2] = {
528 [AV_SAMPLE_FMT_U8 ] = { AV_CODEC_ID_PCM_U8, AV_CODEC_ID_PCM_U8 },
529 [AV_SAMPLE_FMT_S16 ] = { AV_CODEC_ID_PCM_S16LE, AV_CODEC_ID_PCM_S16BE },
530 [AV_SAMPLE_FMT_S32 ] = { AV_CODEC_ID_PCM_S32LE, AV_CODEC_ID_PCM_S32BE },
531 [AV_SAMPLE_FMT_FLT ] = { AV_CODEC_ID_PCM_F32LE, AV_CODEC_ID_PCM_F32BE },
532 [AV_SAMPLE_FMT_DBL ] = { AV_CODEC_ID_PCM_F64LE, AV_CODEC_ID_PCM_F64BE },
533 [AV_SAMPLE_FMT_U8P ] = { AV_CODEC_ID_PCM_U8, AV_CODEC_ID_PCM_U8 },
534 [AV_SAMPLE_FMT_S16P] = { AV_CODEC_ID_PCM_S16LE, AV_CODEC_ID_PCM_S16BE },
535 [AV_SAMPLE_FMT_S32P] = { AV_CODEC_ID_PCM_S32LE, AV_CODEC_ID_PCM_S32BE },
536 [AV_SAMPLE_FMT_S64P] = { AV_CODEC_ID_PCM_S64LE, AV_CODEC_ID_PCM_S64BE },
537 [AV_SAMPLE_FMT_FLTP] = { AV_CODEC_ID_PCM_F32LE, AV_CODEC_ID_PCM_F32BE },
538 [AV_SAMPLE_FMT_DBLP] = { AV_CODEC_ID_PCM_F64LE, AV_CODEC_ID_PCM_F64BE },
539 };
540
2/4
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
24 if (fmt < 0 || fmt >= FF_ARRAY_ELEMS(map))
541 return AV_CODEC_ID_NONE;
542
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
24 if (be < 0 || be > 1)
543 24 be = AV_NE(1, 0);
544 24 return map[fmt][be];
545 }
546
547 247279 int av_get_bits_per_sample(enum AVCodecID codec_id)
548 {
549
5/5
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 74 times.
✓ Branch 4 taken 247182 times.
247279 switch (codec_id) {
550 17 case AV_CODEC_ID_DFPWM:
551 17 return 1;
552 3 case AV_CODEC_ID_ADPCM_SBPRO_2:
553 3 return 2;
554 3 case AV_CODEC_ID_ADPCM_SBPRO_3:
555 3 return 3;
556 74 case AV_CODEC_ID_ADPCM_SBPRO_4:
557 case AV_CODEC_ID_ADPCM_IMA_WAV:
558 case AV_CODEC_ID_ADPCM_IMA_XBOX:
559 case AV_CODEC_ID_ADPCM_IMA_QT:
560 case AV_CODEC_ID_ADPCM_SWF:
561 case AV_CODEC_ID_ADPCM_MS:
562 74 return 4;
563 247182 default:
564 247182 return av_get_exact_bits_per_sample(codec_id);
565 }
566 }
567
568 512491 static int get_audio_frame_duration(enum AVCodecID id, int sr, int ch, int ba,
569 uint32_t tag, int bits_per_coded_sample, int64_t bitrate,
570 uint8_t * extradata, int frame_size, int frame_bytes)
571 {
572 512491 int bps = av_get_exact_bits_per_sample(id);
573
4/4
✓ Branch 0 taken 355540 times.
✓ Branch 1 taken 156951 times.
✓ Branch 2 taken 355235 times.
✓ Branch 3 taken 305 times.
512491 int framecount = (ba > 0 && frame_bytes / ba > 0) ? frame_bytes / ba : 1;
574
575 /* codecs with an exact constant bits per sample */
576
7/10
✓ Branch 0 taken 297986 times.
✓ Branch 1 taken 214505 times.
✓ Branch 2 taken 297986 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 297950 times.
✓ Branch 5 taken 36 times.
✓ Branch 6 taken 297950 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 297950 times.
✗ Branch 9 not taken.
512491 if (bps > 0 && ch > 0 && frame_bytes > 0 && ch < 32768 && bps < 32768)
577 297950 return (frame_bytes * 8LL) / (bps * ch);
578 214541 bps = bits_per_coded_sample;
579
580 /* codecs with a fixed packet duration */
581
11/13
✓ Branch 0 taken 12407 times.
✓ Branch 1 taken 8274 times.
✓ Branch 2 taken 600 times.
✓ Branch 3 taken 5701 times.
✓ Branch 4 taken 1124 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 8594 times.
✓ Branch 7 taken 4331 times.
✓ Branch 8 taken 2191 times.
✓ Branch 9 taken 18574 times.
✓ Branch 10 taken 2515 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 150230 times.
214541 switch (id) {
582 12407 case AV_CODEC_ID_ADPCM_ADX: return 32;
583 8274 case AV_CODEC_ID_ADPCM_IMA_QT: return 64;
584 600 case AV_CODEC_ID_ADPCM_EA_XAS: return 128;
585 5701 case AV_CODEC_ID_AMR_NB:
586 case AV_CODEC_ID_EVRC:
587 case AV_CODEC_ID_GSM:
588 case AV_CODEC_ID_QCELP:
589 5701 case AV_CODEC_ID_RA_288: return 160;
590 1124 case AV_CODEC_ID_AMR_WB:
591 1124 case AV_CODEC_ID_GSM_MS: return 320;
592 case AV_CODEC_ID_MP1: return 384;
593 8594 case AV_CODEC_ID_ATRAC1: return 512;
594 4331 case AV_CODEC_ID_ATRAC9:
595 case AV_CODEC_ID_ATRAC3:
596
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4331 times.
4331 if (framecount > INT_MAX/1024)
597 return 0;
598 4331 return 1024 * framecount;
599 2191 case AV_CODEC_ID_ATRAC3P: return 2048;
600 18574 case AV_CODEC_ID_MP2:
601 18574 case AV_CODEC_ID_MUSEPACK7: return 1152;
602 2515 case AV_CODEC_ID_AC3: return 1536;
603 case AV_CODEC_ID_FTR: return 1024;
604 }
605
606
2/2
✓ Branch 0 taken 146811 times.
✓ Branch 1 taken 3419 times.
150230 if (sr > 0) {
607 /* calc from sample rate */
608
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 146794 times.
146811 if (id == AV_CODEC_ID_TTA)
609 17 return 256ll * sr / 245;
610
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 146794 times.
146794 else if (id == AV_CODEC_ID_DST)
611 return 588ll * sr / 44100;
612
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 146728 times.
146794 else if (id == AV_CODEC_ID_BINKAUDIO_DCT) {
613
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
66 if (sr / 22050 > 22)
614 return 0;
615 66 return (480 << (sr / 22050));
616 }
617
618
2/2
✓ Branch 0 taken 6703 times.
✓ Branch 1 taken 140025 times.
146728 if (id == AV_CODEC_ID_MP3)
619
2/2
✓ Branch 0 taken 224 times.
✓ Branch 1 taken 6479 times.
6703 return sr <= 24000 ? 576 : 1152;
620 }
621
622
2/2
✓ Branch 0 taken 41686 times.
✓ Branch 1 taken 101758 times.
143444 if (ba > 0) {
623 /* calc from block_align */
624
2/2
✓ Branch 0 taken 7260 times.
✓ Branch 1 taken 34426 times.
41686 if (id == AV_CODEC_ID_SIPR) {
625
4/5
✓ Branch 0 taken 3261 times.
✓ Branch 1 taken 1983 times.
✓ Branch 2 taken 1680 times.
✓ Branch 3 taken 336 times.
✗ Branch 4 not taken.
7260 switch (ba) {
626 3261 case 20: return 160;
627 1983 case 19: return 144;
628 1680 case 29: return 288;
629 336 case 37: return 480;
630 }
631
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 34426 times.
34426 } else if (id == AV_CODEC_ID_ILBC) {
632 switch (ba) {
633 case 38: return 160;
634 case 50: return 240;
635 }
636 }
637 }
638
639
2/2
✓ Branch 0 taken 132693 times.
✓ Branch 1 taken 3491 times.
136184 if (frame_bytes > 0) {
640 /* calc from frame_bytes only */
641
2/2
✓ Branch 0 taken 721 times.
✓ Branch 1 taken 131972 times.
132693 if (id == AV_CODEC_ID_TRUESPEECH)
642 721 return 240 * (frame_bytes / 32);
643
2/2
✓ Branch 0 taken 2074 times.
✓ Branch 1 taken 129898 times.
131972 if (id == AV_CODEC_ID_NELLYMOSER)
644 2074 return 256 * (frame_bytes / 64);
645
2/2
✓ Branch 0 taken 1057 times.
✓ Branch 1 taken 128841 times.
129898 if (id == AV_CODEC_ID_RA_144)
646 1057 return 160 * (frame_bytes / 20);
647
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 128381 times.
128841 if (id == AV_CODEC_ID_APTX)
648 460 return 4 * (frame_bytes / 4);
649
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 127921 times.
128381 if (id == AV_CODEC_ID_APTX_HD)
650 460 return 4 * (frame_bytes / 6);
651
652
2/2
✓ Branch 0 taken 45998 times.
✓ Branch 1 taken 81923 times.
127921 if (bps > 0) {
653 /* calc from frame_bytes and bits_per_coded_sample */
654
3/4
✓ Branch 0 taken 45538 times.
✓ Branch 1 taken 460 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 45538 times.
45998 if (id == AV_CODEC_ID_ADPCM_G726 || id == AV_CODEC_ID_ADPCM_G726LE)
655 460 return frame_bytes * 8 / bps;
656 }
657
658
3/4
✓ Branch 0 taken 127335 times.
✓ Branch 1 taken 126 times.
✓ Branch 2 taken 127335 times.
✗ Branch 3 not taken.
127461 if (ch > 0 && ch < INT_MAX/16) {
659 /* calc from frame_bytes and channels */
660
12/17
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
✓ Branch 3 taken 33 times.
✓ Branch 4 taken 452 times.
✓ Branch 5 taken 1951 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 3580 times.
✓ Branch 8 taken 222 times.
✓ Branch 9 taken 327 times.
✓ Branch 10 taken 680 times.
✓ Branch 11 taken 112 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 314 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 1311 times.
✓ Branch 16 taken 118305 times.
127335 switch (id) {
661 case AV_CODEC_ID_FASTAUDIO:
662 return frame_bytes / (40 * ch) * 256;
663 case AV_CODEC_ID_ADPCM_IMA_MOFLEX:
664 return (frame_bytes - 4 * ch) / (128 * ch) * 256;
665 48 case AV_CODEC_ID_ADPCM_AFC:
666 48 return frame_bytes / (9 * ch) * 16;
667 33 case AV_CODEC_ID_ADPCM_PSX:
668 case AV_CODEC_ID_ADPCM_DTK:
669 33 frame_bytes /= 16 * ch;
670
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
33 if (frame_bytes > INT_MAX / 28)
671 return 0;
672 33 return frame_bytes * 28;
673 452 case AV_CODEC_ID_ADPCM_4XM:
674 case AV_CODEC_ID_ADPCM_IMA_ACORN:
675 case AV_CODEC_ID_ADPCM_IMA_DAT4:
676 case AV_CODEC_ID_ADPCM_IMA_ISS:
677 452 return (frame_bytes - 4 * ch) * 2 / ch;
678 1951 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
679 1951 return (frame_bytes - 4) * 2 / ch;
680 case AV_CODEC_ID_ADPCM_IMA_AMV:
681 return (frame_bytes - 8) * 2;
682 3580 case AV_CODEC_ID_ADPCM_THP:
683 case AV_CODEC_ID_ADPCM_THP_LE:
684
2/2
✓ Branch 0 taken 3530 times.
✓ Branch 1 taken 50 times.
3580 if (extradata)
685 3530 return frame_bytes * 14LL / (8 * ch);
686 50 break;
687 222 case AV_CODEC_ID_ADPCM_XA:
688 222 return (frame_bytes / 128) * 224 / ch;
689 327 case AV_CODEC_ID_INTERPLAY_DPCM:
690 327 return (frame_bytes - 6 - ch) / ch;
691 680 case AV_CODEC_ID_ROQ_DPCM:
692 680 return (frame_bytes - 8) / ch;
693 112 case AV_CODEC_ID_XAN_DPCM:
694 112 return (frame_bytes - 2 * ch) / ch;
695 case AV_CODEC_ID_MACE3:
696 return 3 * frame_bytes / ch;
697 314 case AV_CODEC_ID_MACE6:
698 314 return 6 * frame_bytes / ch;
699 case AV_CODEC_ID_PCM_LXF:
700 return 2 * (frame_bytes / (5 * ch));
701 1311 case AV_CODEC_ID_IAC:
702 case AV_CODEC_ID_IMC:
703 1311 return 4 * frame_bytes / ch;
704 }
705
706
2/2
✓ Branch 0 taken 28779 times.
✓ Branch 1 taken 89576 times.
118355 if (tag) {
707 /* calc from frame_bytes, channels, and codec_tag */
708
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 28705 times.
28779 if (id == AV_CODEC_ID_SOL_DPCM) {
709
1/2
✓ Branch 0 taken 74 times.
✗ Branch 1 not taken.
74 if (tag == 3)
710 74 return frame_bytes / ch;
711 else
712 return frame_bytes * 2 / ch;
713 }
714 }
715
716
2/2
✓ Branch 0 taken 29948 times.
✓ Branch 1 taken 88333 times.
118281 if (ba > 0) {
717 /* calc from frame_bytes, channels, and block_align */
718 29948 int blocks = frame_bytes / ba;
719 29948 int64_t tmp = 0;
720
7/9
✓ Branch 0 taken 182 times.
✓ Branch 1 taken 873 times.
✓ Branch 2 taken 669 times.
✓ Branch 3 taken 649 times.
✓ Branch 4 taken 1001 times.
✓ Branch 5 taken 890 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 25684 times.
29948 switch (id) {
721 182 case AV_CODEC_ID_ADPCM_IMA_XBOX:
722
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 182 times.
182 if (bps != 4)
723 return 0;
724 182 tmp = blocks * ((ba - 4 * ch) / (bps * ch) * 8);
725 182 break;
726 873 case AV_CODEC_ID_ADPCM_IMA_WAV:
727
2/4
✓ Branch 0 taken 873 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 873 times.
873 if (bps < 2 || bps > 5)
728 return 0;
729 873 tmp = blocks * (1LL + (ba - 4 * ch) / (bps * ch) * 8LL);
730 873 break;
731 669 case AV_CODEC_ID_ADPCM_IMA_DK3:
732 669 tmp = blocks * (((ba - 16LL) * 2 / 3 * 4) / ch);
733 669 break;
734 649 case AV_CODEC_ID_ADPCM_IMA_DK4:
735 649 tmp = blocks * (1 + (ba - 4LL * ch) * 2 / ch);
736 649 break;
737 1001 case AV_CODEC_ID_ADPCM_IMA_RAD:
738 1001 tmp = blocks * ((ba - 4LL * ch) * 2 / ch);
739 1001 break;
740 890 case AV_CODEC_ID_ADPCM_MS:
741 890 tmp = blocks * (2 + (ba - 7LL * ch) * 2LL / ch);
742 890 break;
743 case AV_CODEC_ID_ADPCM_MTAF:
744 tmp = blocks * (ba - 16LL) * 2 / ch;
745 break;
746 case AV_CODEC_ID_ADPCM_XMD:
747 tmp = blocks * 32;
748 break;
749 }
750
2/2
✓ Branch 0 taken 4264 times.
✓ Branch 1 taken 25684 times.
29948 if (tmp) {
751
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4264 times.
4264 if (tmp != (int)tmp)
752 return 0;
753 4264 return tmp;
754 }
755 }
756
757
2/2
✓ Branch 0 taken 37339 times.
✓ Branch 1 taken 76678 times.
114017 if (bps > 0) {
758 /* calc from frame_bytes, channels, and bits_per_coded_sample */
759
2/4
✓ Branch 0 taken 20832 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 16507 times.
37339 switch (id) {
760 20832 case AV_CODEC_ID_PCM_DVD:
761
2/4
✓ Branch 0 taken 20832 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 20832 times.
20832 if(bps<4 || frame_bytes<3)
762 return 0;
763 20832 return 2 * ((frame_bytes - 3) / ((bps * 2 / 8) * ch));
764 case AV_CODEC_ID_PCM_BLURAY:
765 if(bps<4 || frame_bytes<4)
766 return 0;
767 return (frame_bytes - 4) / ((FFALIGN(ch, 2) * bps) / 8);
768 case AV_CODEC_ID_S302M:
769 return 2 * (frame_bytes / ((bps + 4) / 4)) / ch;
770 }
771 }
772 }
773 }
774
775 /* Fall back on using frame_size */
776
4/4
✓ Branch 0 taken 52905 times.
✓ Branch 1 taken 43897 times.
✓ Branch 2 taken 52744 times.
✓ Branch 3 taken 161 times.
96802 if (frame_size > 1 && frame_bytes)
777 52744 return frame_size;
778
779 //For WMA we currently have no other means to calculate duration thus we
780 //do it here by assuming CBR, which is true for all known cases.
781
8/8
✓ Branch 0 taken 29165 times.
✓ Branch 1 taken 14893 times.
✓ Branch 2 taken 25690 times.
✓ Branch 3 taken 3475 times.
✓ Branch 4 taken 25660 times.
✓ Branch 5 taken 30 times.
✓ Branch 6 taken 9696 times.
✓ Branch 7 taken 15964 times.
44058 if (bitrate > 0 && frame_bytes > 0 && sr > 0 && ba > 1) {
782
4/4
✓ Branch 0 taken 9491 times.
✓ Branch 1 taken 205 times.
✓ Branch 2 taken 795 times.
✓ Branch 3 taken 8696 times.
9696 if (id == AV_CODEC_ID_WMAV1 || id == AV_CODEC_ID_WMAV2)
783 1000 return (frame_bytes * 8LL * sr) / bitrate;
784 }
785
786 43058 return 0;
787 }
788
789 45099 int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
790 {
791 45099 int channels = avctx->ch_layout.nb_channels;
792 int duration;
793
794 45099 duration = get_audio_frame_duration(avctx->codec_id, avctx->sample_rate,
795 channels, avctx->block_align,
796 avctx->codec_tag, avctx->bits_per_coded_sample,
797 avctx->bit_rate, avctx->extradata, avctx->frame_size,
798 frame_bytes);
799 45099 return FFMAX(0, duration);
800 }
801
802 467392 int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
803 {
804 467392 int channels = par->ch_layout.nb_channels;
805 int duration;
806
807 467392 duration = get_audio_frame_duration(par->codec_id, par->sample_rate,
808 channels, par->block_align,
809 par->codec_tag, par->bits_per_coded_sample,
810 par->bit_rate, par->extradata, par->frame_size,
811 frame_bytes);
812 467392 return FFMAX(0, duration);
813 }
814
815 56 unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
816 {
817 56 unsigned int n = 0;
818
819
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
56 while (v >= 0xff) {
820 *s++ = 0xff;
821 v -= 0xff;
822 n++;
823 }
824 56 *s = v;
825 56 n++;
826 56 return n;
827 }
828
829 476 int ff_match_2uint16(const uint16_t(*tab)[2], int size, int a, int b)
830 {
831 int i;
832
5/6
✓ Branch 0 taken 1919 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 1448 times.
✓ Branch 3 taken 471 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 471 times.
1924 for (i = 0; i < size && !(tab[i][0] == a && tab[i][1] == b); i++) ;
833 476 return i;
834 }
835
836 16515 const AVCodecHWConfig *avcodec_get_hw_config(const AVCodec *avcodec, int index)
837 {
838 16515 const FFCodec *const codec = ffcodec(avcodec);
839 int i;
840
3/4
✓ Branch 0 taken 2656 times.
✓ Branch 1 taken 13859 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2656 times.
16515 if (!codec->hw_configs || index < 0)
841 13859 return NULL;
842
2/2
✓ Branch 0 taken 5160 times.
✓ Branch 1 taken 1706 times.
6866 for (i = 0; i <= index; i++)
843
2/2
✓ Branch 0 taken 950 times.
✓ Branch 1 taken 4210 times.
5160 if (!codec->hw_configs[i])
844 950 return NULL;
845 1706 return &codec->hw_configs[index]->public;
846 }
847
848 27466 int ff_thread_ref_frame(ThreadFrame *dst, const ThreadFrame *src)
849 {
850 int ret;
851
852 27466 dst->owner[0] = src->owner[0];
853 27466 dst->owner[1] = src->owner[1];
854
855 27466 ret = av_frame_ref(dst->f, src->f);
856
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27466 times.
27466 if (ret < 0)
857 return ret;
858
859
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27466 times.
27466 av_assert0(!dst->progress);
860
861
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 27406 times.
27466 if (src->progress)
862 60 dst->progress = av_refstruct_ref(src->progress);
863
864 27466 return 0;
865 }
866
867 298 int ff_thread_replace_frame(ThreadFrame *dst, const ThreadFrame *src)
868 {
869 int ret;
870
871 298 dst->owner[0] = src->owner[0];
872 298 dst->owner[1] = src->owner[1];
873
874 298 ret = av_frame_replace(dst->f, src->f);
875
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 298 times.
298 if (ret < 0)
876 return ret;
877
878 298 av_refstruct_replace(&dst->progress, src->progress);
879
880 298 return 0;
881 }
882
883 #if !HAVE_THREADS
884
885 int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f, int flags)
886 {
887 return ff_get_buffer(avctx, f, flags);
888 }
889
890 int ff_thread_get_ext_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
891 {
892 f->owner[0] = f->owner[1] = avctx;
893 return ff_get_buffer(avctx, f->f, flags);
894 }
895
896 void ff_thread_release_ext_buffer(ThreadFrame *f)
897 {
898 f->owner[0] = f->owner[1] = NULL;
899 if (f->f)
900 av_frame_unref(f->f);
901 }
902
903 void ff_thread_finish_setup(AVCodecContext *avctx)
904 {
905 }
906
907 void ff_thread_report_progress(ThreadFrame *f, int progress, int field)
908 {
909 }
910
911 void ff_thread_await_progress(const ThreadFrame *f, int progress, int field)
912 {
913 }
914
915 int ff_thread_can_start_frame(AVCodecContext *avctx)
916 {
917 return 1;
918 }
919 #endif
920
921 664108 const uint8_t *avpriv_find_start_code(const uint8_t *restrict p,
922 const uint8_t *end,
923 uint32_t *restrict state)
924 {
925 int i;
926
927
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 664108 times.
664108 av_assert0(p <= end);
928
2/2
✓ Branch 0 taken 910 times.
✓ Branch 1 taken 663198 times.
664108 if (p >= end)
929 910 return end;
930
931
2/2
✓ Branch 0 taken 1983979 times.
✓ Branch 1 taken 659295 times.
2643274 for (i = 0; i < 3; i++) {
932 1983979 uint32_t tmp = *state << 8;
933 1983979 *state = tmp + *(p++);
934
4/4
✓ Branch 0 taken 1983111 times.
✓ Branch 1 taken 868 times.
✓ Branch 2 taken 3035 times.
✓ Branch 3 taken 1980076 times.
1983979 if (tmp == 0x100 || p == end)
935 3903 return p;
936 }
937
938
2/2
✓ Branch 0 taken 393531952 times.
✓ Branch 1 taken 66985 times.
393598937 while (p < end) {
939
2/2
✓ Branch 0 taken 356389204 times.
✓ Branch 1 taken 37142748 times.
393531952 if (p[-1] > 1 ) p += 3;
940
2/2
✓ Branch 0 taken 15917319 times.
✓ Branch 1 taken 21225429 times.
37142748 else if (p[-2] ) p += 2;
941
2/2
✓ Branch 0 taken 20633119 times.
✓ Branch 1 taken 592310 times.
21225429 else if (p[-3]|(p[-1]-1)) p++;
942 else {
943 592310 p++;
944 592310 break;
945 }
946 }
947
948
2/2
✓ Branch 0 taken 42037 times.
✓ Branch 1 taken 617258 times.
659295 p = FFMIN(p, end) - 4;
949 659295 *state = AV_RB32(p);
950
951 659295 return p + 4;
952 }
953
954 413 AVCPBProperties *av_cpb_properties_alloc(size_t *size)
955 {
956 413 AVCPBProperties *props = av_mallocz(sizeof(AVCPBProperties));
957
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 413 times.
413 if (!props)
958 return NULL;
959
960
1/2
✓ Branch 0 taken 413 times.
✗ Branch 1 not taken.
413 if (size)
961 413 *size = sizeof(*props);
962
963 413 props->vbv_delay = UINT64_MAX;
964
965 413 return props;
966 }
967
968 int ff_alloc_timecode_sei(const AVFrame *frame, AVRational rate, size_t prefix_len,
969 void **data, size_t *sei_size)
970 {
971 AVFrameSideData *sd = NULL;
972 uint8_t *sei_data;
973 PutBitContext pb;
974 uint32_t *tc;
975 int m;
976
977 if (frame)
978 sd = av_frame_get_side_data(frame, AV_FRAME_DATA_S12M_TIMECODE);
979
980 if (!sd) {
981 *data = NULL;
982 return 0;
983 }
984 tc = (uint32_t*)sd->data;
985 m = tc[0] & 3;
986
987 *sei_size = sizeof(uint32_t) * 4;
988 *data = av_mallocz(*sei_size + prefix_len);
989 if (!*data)
990 return AVERROR(ENOMEM);
991 sei_data = (uint8_t*)*data + prefix_len;
992
993 init_put_bits(&pb, sei_data, *sei_size);
994 put_bits(&pb, 2, m); // num_clock_ts
995
996 for (int j = 1; j <= m; j++) {
997 unsigned hh, mm, ss, ff, drop;
998 ff_timecode_set_smpte(&drop, &hh, &mm, &ss, &ff, rate, tc[j], 0, 0);
999
1000 put_bits(&pb, 1, 1); // clock_timestamp_flag
1001 put_bits(&pb, 1, 1); // units_field_based_flag
1002 put_bits(&pb, 5, 0); // counting_type
1003 put_bits(&pb, 1, 1); // full_timestamp_flag
1004 put_bits(&pb, 1, 0); // discontinuity_flag
1005 put_bits(&pb, 1, drop);
1006 put_bits(&pb, 9, ff);
1007 put_bits(&pb, 6, ss);
1008 put_bits(&pb, 6, mm);
1009 put_bits(&pb, 5, hh);
1010 put_bits(&pb, 5, 0);
1011 }
1012 flush_put_bits(&pb);
1013
1014 return 0;
1015 }
1016
1017 18984 int64_t ff_guess_coded_bitrate(AVCodecContext *avctx)
1018 {
1019 18984 AVRational framerate = avctx->framerate;
1020 18984 int bits_per_coded_sample = avctx->bits_per_coded_sample;
1021 int64_t bitrate;
1022
1023
3/4
✓ Branch 0 taken 18865 times.
✓ Branch 1 taken 119 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18865 times.
18984 if (!(framerate.num && framerate.den))
1024 119 framerate = av_inv_q(avctx->time_base);
1025
2/4
✓ Branch 0 taken 18984 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18984 times.
18984 if (!(framerate.num && framerate.den))
1026 return 0;
1027
1028
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18984 times.
18984 if (!bits_per_coded_sample) {
1029 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
1030 bits_per_coded_sample = av_get_bits_per_pixel(desc);
1031 }
1032 18984 bitrate = (int64_t)bits_per_coded_sample * avctx->width * avctx->height *
1033 18984 framerate.num / framerate.den;
1034
1035 18984 return bitrate;
1036 }
1037