FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/utils.c
Date: 2026-08-15 14:54:27
Exec Total Coverage
Lines: 379 536 70.7%
Functions: 25 31 80.6%
Branches: 282 398 70.9%

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 185012 void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
54 {
55 185012 uint8_t **p = ptr;
56
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 185012 times.
185012 if (min_size > SIZE_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
57 av_freep(p);
58 *size = 0;
59 return;
60 }
61 185012 av_fast_mallocz(p, size, min_size + AV_INPUT_BUFFER_PADDING_SIZE);
62
1/2
✓ Branch 0 taken 185012 times.
✗ Branch 1 not taken.
185012 if (*p)
63 185012 memset(*p + min_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
64 }
65
66 711 void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size)
67 {
68 711 uint8_t **p = ptr;
69
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 711 times.
711 if (min_size > SIZE_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
70 av_freep(p);
71 *size = 0;
72 return;
73 }
74 711 av_fast_malloc(p, size, min_size + AV_INPUT_BUFFER_PADDING_SIZE);
75
1/2
✓ Branch 0 taken 711 times.
✗ Branch 1 not taken.
711 if (*p)
76 711 memset(*p, 0, min_size + AV_INPUT_BUFFER_PADDING_SIZE);
77 }
78
79 2628837 int av_codec_is_encoder(const AVCodec *avcodec)
80 {
81 2628837 const FFCodec *const codec = ffcodec(avcodec);
82
4/4
✓ Branch 0 taken 2618431 times.
✓ Branch 1 taken 10406 times.
✓ Branch 2 taken 1654369 times.
✓ Branch 3 taken 964062 times.
2628837 return codec && !codec->is_decoder;
83 }
84
85 515263 int av_codec_is_decoder(const AVCodec *avcodec)
86 {
87 515263 const FFCodec *const codec = ffcodec(avcodec);
88
4/4
✓ Branch 0 taken 504857 times.
✓ Branch 1 taken 10406 times.
✓ Branch 2 taken 482704 times.
✓ Branch 3 taken 22153 times.
515263 return codec && codec->is_decoder;
89 }
90
91 63111 int ff_set_dimensions(AVCodecContext *s, int width, int height)
92 {
93 63111 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 63110 times.
63111 if (ret < 0)
96 1 width = height = 0;
97
98 63111 s->coded_width = width;
99 63111 s->coded_height = height;
100 63111 s->width = AV_CEIL_RSHIFT(width, s->lowres);
101 63111 s->height = AV_CEIL_RSHIFT(height, s->lowres);
102
103 63111 return ret;
104 }
105
106 3071 int ff_set_sar(AVCodecContext *avctx, AVRational sar)
107 {
108 3071 int ret = av_image_check_sar(avctx->width, avctx->height, sar);
109
110
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 3066 times.
3071 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 3066 avctx->sample_aspect_ratio = sar;
117 }
118 3066 return 0;
119 }
120
121 4248 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 4248 side_data = av_frame_get_side_data(frame, AV_FRAME_DATA_MATRIXENCODING);
128
1/2
✓ Branch 0 taken 4248 times.
✗ Branch 1 not taken.
4248 if (!side_data)
129 4248 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 4248 times.
4248 if (!side_data)
133 return AVERROR(ENOMEM);
134
135 4248 data = (enum AVMatrixEncoding*)side_data->data;
136 4248 *data = matrix_encoding;
137
138 4248 return 0;
139 }
140
141 11003 void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height,
142 int linesize_align[AV_NUM_DATA_POINTERS])
143 {
144 int i;
145 11003 int w_align = 1;
146 11003 int h_align = 1;
147 11003 AVPixFmtDescriptor const *desc = av_pix_fmt_desc_get(s->pix_fmt);
148
149
1/2
✓ Branch 0 taken 11003 times.
✗ Branch 1 not taken.
11003 if (desc) {
150 11003 w_align = 1 << desc->log2_chroma_w;
151 11003 h_align = 1 << desc->log2_chroma_h;
152 }
153
154
9/10
✓ Branch 0 taken 9967 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 226 times.
✓ Branch 7 taken 23 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 488 times.
11003 switch (s->pix_fmt) {
155 9967 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 9967 w_align = 16; //FIXME assume 16 pixel per macroblock
245 9967 h_align = 16 * 2; // interlaced needs 2 macroblocks height
246
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 9964 times.
9967 if (s->codec_id == AV_CODEC_ID_BINKVIDEO)
247 3 w_align = 16*2;
248 9967 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 226 case AV_PIX_FMT_RGB24:
307
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 219 times.
226 if (s->codec_id == AV_CODEC_ID_CINEPAK) {
308 7 w_align = 4;
309 7 h_align = 4;
310 }
311 226 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 case AV_PIX_FMT_BAYER_BGGR8:
319 case AV_PIX_FMT_BAYER_RGGB8:
320 case AV_PIX_FMT_BAYER_GBRG8:
321 case AV_PIX_FMT_BAYER_GRBG8:
322 case AV_PIX_FMT_BAYER_BGGR16LE:
323 case AV_PIX_FMT_BAYER_BGGR16BE:
324 case AV_PIX_FMT_BAYER_RGGB16LE:
325 case AV_PIX_FMT_BAYER_RGGB16BE:
326 case AV_PIX_FMT_BAYER_GBRG16LE:
327 case AV_PIX_FMT_BAYER_GBRG16BE:
328 case AV_PIX_FMT_BAYER_GRBG16LE:
329 case AV_PIX_FMT_BAYER_GRBG16BE:
330 w_align = FFMAX(w_align, 2);
331 h_align = FFMAX(h_align, 2);
332 break;
333 488 default:
334 488 break;
335 }
336
337
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 11001 times.
11003 if (s->codec_id == AV_CODEC_ID_IFF_ILBM) {
338 2 w_align = FFMAX(w_align, 16);
339 }
340
341 11003 *width = FFALIGN(*width, w_align);
342 11003 *height = FFALIGN(*height, h_align);
343
4/4
✓ Branch 0 taken 10390 times.
✓ Branch 1 taken 613 times.
✓ Branch 2 taken 10389 times.
✓ Branch 3 taken 1 times.
11003 if (s->codec_id == AV_CODEC_ID_H264 || s->lowres ||
344
4/4
✓ Branch 0 taken 10374 times.
✓ Branch 1 taken 15 times.
✓ Branch 2 taken 10367 times.
✓ Branch 3 taken 7 times.
10389 s->codec_id == AV_CODEC_ID_VC1 || s->codec_id == AV_CODEC_ID_WMV3 ||
345
4/4
✓ Branch 0 taken 10366 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 10357 times.
✓ Branch 3 taken 9 times.
10367 s->codec_id == AV_CODEC_ID_VP5 || s->codec_id == AV_CODEC_ID_VP6 ||
346
4/4
✓ Branch 0 taken 10355 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 10353 times.
10357 s->codec_id == AV_CODEC_ID_VP6F || s->codec_id == AV_CODEC_ID_VP6A
347 ) {
348 // some of the optimized chroma MC reads one line too much
349 // which is also done in mpeg decoders with lowres > 0
350 650 *height += 2;
351
352 // H.264 uses edge emulation for out of frame motion vectors, for this
353 // it requires a temporary area large enough to hold a 21x21 block,
354 // increasing width ensure that the temporary area is large enough,
355 // the next rounded up width is 32
356 650 *width = FFMAX(*width, 32);
357 }
358
2/2
✓ Branch 0 taken 2618 times.
✓ Branch 1 taken 8385 times.
11003 if (s->codec_id == AV_CODEC_ID_SVQ3) {
359 2618 *width = FFMAX(*width, 32);
360 }
361
362
2/2
✓ Branch 0 taken 44012 times.
✓ Branch 1 taken 11003 times.
55015 for (i = 0; i < 4; i++)
363 44012 linesize_align[i] = STRIDE_ALIGN;
364 11003 }
365
366 void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height)
367 {
368 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->pix_fmt);
369 int chroma_shift = desc->log2_chroma_w;
370 int linesize_align[AV_NUM_DATA_POINTERS];
371 int align;
372
373 avcodec_align_dimensions2(s, width, height, linesize_align);
374 align = FFMAX(linesize_align[0], linesize_align[3]);
375 linesize_align[1] <<= chroma_shift;
376 linesize_align[2] <<= chroma_shift;
377 align = FFMAX3(align, linesize_align[1], linesize_align[2]);
378 *width = FFALIGN(*width, align);
379 }
380
381 int avcodec_fill_audio_frame(AVFrame *frame, int nb_channels,
382 enum AVSampleFormat sample_fmt, const uint8_t *buf,
383 int buf_size, int align)
384 {
385 int ch, planar, needed_size, ret = 0;
386
387 needed_size = av_samples_get_buffer_size(NULL, nb_channels,
388 frame->nb_samples, sample_fmt,
389 align);
390 if (buf_size < needed_size)
391 return AVERROR(EINVAL);
392
393 planar = av_sample_fmt_is_planar(sample_fmt);
394 if (planar && nb_channels > AV_NUM_DATA_POINTERS) {
395 if (!FF_ALLOCZ_TYPED_ARRAY(frame->extended_data, nb_channels))
396 return AVERROR(ENOMEM);
397 } else {
398 frame->extended_data = frame->data;
399 }
400
401 if ((ret = av_samples_fill_arrays(frame->extended_data, &frame->linesize[0],
402 (uint8_t *)(intptr_t)buf, nb_channels, frame->nb_samples,
403 sample_fmt, align)) < 0) {
404 if (frame->extended_data != frame->data)
405 av_freep(&frame->extended_data);
406 return ret;
407 }
408 if (frame->extended_data != frame->data) {
409 for (ch = 0; ch < AV_NUM_DATA_POINTERS; ch++)
410 frame->data[ch] = frame->extended_data[ch];
411 }
412
413 return ret;
414 }
415
416
417 204146 int avpriv_codec_get_cap_skip_frame_fill_param(const AVCodec *codec){
418 204146 return !!(ffcodec(codec)->caps_internal & FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM);
419 }
420
421 30825 const char *avcodec_get_name(enum AVCodecID id)
422 {
423 const AVCodecDescriptor *cd;
424
425
2/2
✓ Branch 0 taken 271 times.
✓ Branch 1 taken 30554 times.
30825 if (id == AV_CODEC_ID_NONE)
426 271 return "none";
427 30554 cd = avcodec_descriptor_get(id);
428
2/2
✓ Branch 0 taken 30550 times.
✓ Branch 1 taken 4 times.
30554 if (cd)
429 30550 return cd->name;
430 4 return "unknown_codec";
431 }
432
433 const char *av_get_profile_name(const AVCodec *codec, int profile)
434 {
435 const AVProfile *p;
436 if (profile == AV_PROFILE_UNKNOWN || !codec->profiles)
437 return NULL;
438
439 for (p = codec->profiles; p->profile != AV_PROFILE_UNKNOWN; p++)
440 if (p->profile == profile)
441 return p->name;
442
443 return NULL;
444 }
445
446 18167 const char *avcodec_profile_name(enum AVCodecID codec_id, int profile)
447 {
448 18167 const AVCodecDescriptor *desc = avcodec_descriptor_get(codec_id);
449 const AVProfile *p;
450
451
5/6
✓ Branch 0 taken 2501 times.
✓ Branch 1 taken 15666 times.
✓ Branch 2 taken 2501 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 163 times.
✓ Branch 5 taken 2338 times.
18167 if (profile == AV_PROFILE_UNKNOWN || !desc || !desc->profiles)
452 15829 return NULL;
453
454
2/2
✓ Branch 0 taken 6056 times.
✓ Branch 1 taken 34 times.
6090 for (p = desc->profiles; p->profile != AV_PROFILE_UNKNOWN; p++)
455
2/2
✓ Branch 0 taken 2304 times.
✓ Branch 1 taken 3752 times.
6056 if (p->profile == profile)
456 2304 return p->name;
457
458 34 return NULL;
459 }
460
461 920420 int av_get_exact_bits_per_sample(enum AVCodecID codec_id)
462 {
463
8/8
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 11202 times.
✓ Branch 2 taken 6779 times.
✓ Branch 3 taken 577762 times.
✓ Branch 4 taken 18086 times.
✓ Branch 5 taken 23632 times.
✓ Branch 6 taken 10646 times.
✓ Branch 7 taken 272289 times.
920420 switch (codec_id) {
464 24 case AV_CODEC_ID_DFPWM:
465 24 return 1;
466 11202 case AV_CODEC_ID_8SVX_EXP:
467 case AV_CODEC_ID_8SVX_FIB:
468 case AV_CODEC_ID_ADPCM_ARGO:
469 case AV_CODEC_ID_ADPCM_CT:
470 case AV_CODEC_ID_ADPCM_IMA_ALP:
471 case AV_CODEC_ID_ADPCM_IMA_AMV:
472 case AV_CODEC_ID_ADPCM_IMA_APC:
473 case AV_CODEC_ID_ADPCM_IMA_APM:
474 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
475 case AV_CODEC_ID_ADPCM_IMA_MAGIX:
476 case AV_CODEC_ID_ADPCM_IMA_OKI:
477 case AV_CODEC_ID_ADPCM_IMA_WS:
478 case AV_CODEC_ID_ADPCM_IMA_SSI:
479 case AV_CODEC_ID_ADPCM_G722:
480 case AV_CODEC_ID_ADPCM_YAMAHA:
481 case AV_CODEC_ID_ADPCM_AICA:
482 11202 return 4;
483 6779 case AV_CODEC_ID_DSD_LSBF:
484 case AV_CODEC_ID_DSD_MSBF:
485 case AV_CODEC_ID_DSD_LSBF_PLANAR:
486 case AV_CODEC_ID_DSD_MSBF_PLANAR:
487 case AV_CODEC_ID_PCM_ALAW:
488 case AV_CODEC_ID_PCM_MULAW:
489 case AV_CODEC_ID_PCM_VIDC:
490 case AV_CODEC_ID_PCM_S8:
491 case AV_CODEC_ID_PCM_S8_PLANAR:
492 case AV_CODEC_ID_PCM_SGA:
493 case AV_CODEC_ID_PCM_U8:
494 case AV_CODEC_ID_SDX2_DPCM:
495 case AV_CODEC_ID_CBD2_DPCM:
496 case AV_CODEC_ID_DERF_DPCM:
497 case AV_CODEC_ID_WADY_DPCM:
498 case AV_CODEC_ID_ADPCM_CIRCUS:
499 6779 return 8;
500 577762 case AV_CODEC_ID_PCM_S16BE:
501 case AV_CODEC_ID_PCM_S16BE_PLANAR:
502 case AV_CODEC_ID_PCM_S16LE:
503 case AV_CODEC_ID_PCM_S16LE_PLANAR:
504 case AV_CODEC_ID_PCM_U16BE:
505 case AV_CODEC_ID_PCM_U16LE:
506 577762 return 16;
507 18086 case AV_CODEC_ID_PCM_S24DAUD:
508 case AV_CODEC_ID_PCM_S24BE:
509 case AV_CODEC_ID_PCM_S24LE:
510 case AV_CODEC_ID_PCM_S24LE_PLANAR:
511 case AV_CODEC_ID_PCM_U24BE:
512 case AV_CODEC_ID_PCM_U24LE:
513 18086 return 24;
514 23632 case AV_CODEC_ID_PCM_S32BE:
515 case AV_CODEC_ID_PCM_S32LE:
516 case AV_CODEC_ID_PCM_S32LE_PLANAR:
517 case AV_CODEC_ID_PCM_U32BE:
518 case AV_CODEC_ID_PCM_U32LE:
519 case AV_CODEC_ID_PCM_F32BE:
520 case AV_CODEC_ID_PCM_F32LE:
521 case AV_CODEC_ID_PCM_F24LE:
522 case AV_CODEC_ID_PCM_F16LE:
523 23632 return 32;
524 10646 case AV_CODEC_ID_PCM_F64BE:
525 case AV_CODEC_ID_PCM_F64LE:
526 case AV_CODEC_ID_PCM_S64BE:
527 case AV_CODEC_ID_PCM_S64LE:
528 10646 return 64;
529 272289 default:
530 272289 return 0;
531 }
532 }
533
534 31 enum AVCodecID av_get_pcm_codec(enum AVSampleFormat fmt, int be)
535 {
536 static const enum AVCodecID map[][2] = {
537 [AV_SAMPLE_FMT_U8 ] = { AV_CODEC_ID_PCM_U8, AV_CODEC_ID_PCM_U8 },
538 [AV_SAMPLE_FMT_S16 ] = { AV_CODEC_ID_PCM_S16LE, AV_CODEC_ID_PCM_S16BE },
539 [AV_SAMPLE_FMT_S32 ] = { AV_CODEC_ID_PCM_S32LE, AV_CODEC_ID_PCM_S32BE },
540 [AV_SAMPLE_FMT_FLT ] = { AV_CODEC_ID_PCM_F32LE, AV_CODEC_ID_PCM_F32BE },
541 [AV_SAMPLE_FMT_DBL ] = { AV_CODEC_ID_PCM_F64LE, AV_CODEC_ID_PCM_F64BE },
542 [AV_SAMPLE_FMT_U8P ] = { AV_CODEC_ID_PCM_U8, AV_CODEC_ID_PCM_U8 },
543 [AV_SAMPLE_FMT_S16P] = { AV_CODEC_ID_PCM_S16LE, AV_CODEC_ID_PCM_S16BE },
544 [AV_SAMPLE_FMT_S32P] = { AV_CODEC_ID_PCM_S32LE, AV_CODEC_ID_PCM_S32BE },
545 [AV_SAMPLE_FMT_S64P] = { AV_CODEC_ID_PCM_S64LE, AV_CODEC_ID_PCM_S64BE },
546 [AV_SAMPLE_FMT_FLTP] = { AV_CODEC_ID_PCM_F32LE, AV_CODEC_ID_PCM_F32BE },
547 [AV_SAMPLE_FMT_DBLP] = { AV_CODEC_ID_PCM_F64LE, AV_CODEC_ID_PCM_F64BE },
548 };
549
2/4
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 31 times.
31 if (fmt < 0 || fmt >= FF_ARRAY_ELEMS(map))
550 return AV_CODEC_ID_NONE;
551
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
31 if (be < 0 || be > 1)
552 31 be = AV_NE(1, 0);
553 31 return map[fmt][be];
554 }
555
556 297737 int av_get_bits_per_sample(enum AVCodecID codec_id)
557 {
558
5/5
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 90 times.
✓ Branch 4 taken 297622 times.
297737 switch (codec_id) {
559 17 case AV_CODEC_ID_DFPWM:
560 17 return 1;
561 5 case AV_CODEC_ID_ADPCM_SBPRO_2:
562 case AV_CODEC_ID_G728:
563 5 return 2;
564 3 case AV_CODEC_ID_ADPCM_SBPRO_3:
565 3 return 3;
566 90 case AV_CODEC_ID_ADPCM_SBPRO_4:
567 case AV_CODEC_ID_ADPCM_IMA_WAV:
568 case AV_CODEC_ID_ADPCM_IMA_XBOX:
569 case AV_CODEC_ID_ADPCM_IMA_QT:
570 case AV_CODEC_ID_ADPCM_SWF:
571 case AV_CODEC_ID_ADPCM_MS:
572 90 return 4;
573 297622 default:
574 297622 return av_get_exact_bits_per_sample(codec_id);
575 }
576 }
577
578 613036 static int get_audio_frame_duration(enum AVCodecID id, int sr, int ch, int ba,
579 uint32_t tag, int bits_per_coded_sample, int64_t bitrate,
580 uint8_t * extradata, int frame_size, int frame_bytes)
581 {
582 613036 int bps = av_get_exact_bits_per_sample(id);
583
4/4
✓ Branch 0 taken 410101 times.
✓ Branch 1 taken 202935 times.
✓ Branch 2 taken 409796 times.
✓ Branch 3 taken 305 times.
613036 int framecount = (ba > 0 && frame_bytes / ba > 0) ? frame_bytes / ba : 1;
584
585 /* codecs with an exact constant bits per sample */
586
7/10
✓ Branch 0 taken 352902 times.
✓ Branch 1 taken 260134 times.
✓ Branch 2 taken 352902 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 352866 times.
✓ Branch 5 taken 36 times.
✓ Branch 6 taken 352866 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 352866 times.
✗ Branch 9 not taken.
613036 if (bps > 0 && ch > 0 && frame_bytes > 0 && ch < 32768 && bps < 32768)
587 352866 return (frame_bytes * 8LL) / (bps * ch);
588 260170 bps = bits_per_coded_sample;
589
590 /* codecs with a fixed packet duration */
591
11/13
✓ Branch 0 taken 12407 times.
✓ Branch 1 taken 8274 times.
✓ Branch 2 taken 600 times.
✓ Branch 3 taken 5684 times.
✓ Branch 4 taken 1124 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 8588 times.
✓ Branch 7 taken 4333 times.
✓ Branch 8 taken 2186 times.
✓ Branch 9 taken 20567 times.
✓ Branch 10 taken 2576 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 193831 times.
260170 switch (id) {
592 12407 case AV_CODEC_ID_ADPCM_ADX: return 32;
593 8274 case AV_CODEC_ID_ADPCM_IMA_QT: return 64;
594 600 case AV_CODEC_ID_ADPCM_EA_XAS: return 128;
595 5684 case AV_CODEC_ID_AMR_NB:
596 case AV_CODEC_ID_EVRC:
597 case AV_CODEC_ID_GSM:
598 case AV_CODEC_ID_QCELP:
599 5684 case AV_CODEC_ID_RA_288: return 160;
600 1124 case AV_CODEC_ID_AMR_WB:
601 1124 case AV_CODEC_ID_GSM_MS: return 320;
602 case AV_CODEC_ID_MP1: return 384;
603 8588 case AV_CODEC_ID_ATRAC1: return 512;
604 4333 case AV_CODEC_ID_ATRAC9:
605 case AV_CODEC_ID_ATRAC3:
606
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4333 times.
4333 if (framecount > INT_MAX/1024)
607 return 0;
608 4333 return 1024 * framecount;
609 2186 case AV_CODEC_ID_ATRAC3P: return 2048;
610 20567 case AV_CODEC_ID_MP2:
611 20567 case AV_CODEC_ID_MUSEPACK7: return 1152;
612 2576 case AV_CODEC_ID_AC3: return 1536;
613 case AV_CODEC_ID_FTR: return 1024;
614 }
615
616
2/2
✓ Branch 0 taken 190304 times.
✓ Branch 1 taken 3527 times.
193831 if (sr > 0) {
617 /* calc from sample rate */
618
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 190287 times.
190304 if (id == AV_CODEC_ID_TTA)
619 17 return 256ll * sr / 245;
620
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 190287 times.
190287 else if (id == AV_CODEC_ID_DST)
621 return 588ll * sr / 44100;
622
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 190221 times.
190287 else if (id == AV_CODEC_ID_BINKAUDIO_DCT) {
623
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
66 if (sr / 22050 > 22)
624 return 0;
625 66 return (480 << (sr / 22050));
626 }
627
628
2/2
✓ Branch 0 taken 11695 times.
✓ Branch 1 taken 178526 times.
190221 if (id == AV_CODEC_ID_MP3)
629
2/2
✓ Branch 0 taken 232 times.
✓ Branch 1 taken 11463 times.
11695 return sr <= 24000 ? 576 : 1152;
630 }
631
632
2/2
✓ Branch 0 taken 42603 times.
✓ Branch 1 taken 139450 times.
182053 if (ba > 0) {
633 /* calc from block_align */
634
2/2
✓ Branch 0 taken 7259 times.
✓ Branch 1 taken 35344 times.
42603 if (id == AV_CODEC_ID_SIPR) {
635
4/5
✓ Branch 0 taken 3260 times.
✓ Branch 1 taken 1983 times.
✓ Branch 2 taken 1680 times.
✓ Branch 3 taken 336 times.
✗ Branch 4 not taken.
7259 switch (ba) {
636 3260 case 20: return 160;
637 1983 case 19: return 144;
638 1680 case 29: return 288;
639 336 case 37: return 480;
640 }
641
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35344 times.
35344 } else if (id == AV_CODEC_ID_ILBC) {
642 switch (ba) {
643 case 38: return 160;
644 case 50: return 240;
645 }
646 }
647 }
648
649
2/2
✓ Branch 0 taken 171144 times.
✓ Branch 1 taken 3650 times.
174794 if (frame_bytes > 0) {
650 /* calc from frame_bytes only */
651 171144 int64_t d = INT64_MIN;
652
6/6
✓ Branch 0 taken 721 times.
✓ Branch 1 taken 2074 times.
✓ Branch 2 taken 1057 times.
✓ Branch 3 taken 153 times.
✓ Branch 4 taken 153 times.
✓ Branch 5 taken 166986 times.
171144 switch(id) {
653 721 case AV_CODEC_ID_TRUESPEECH : d = 240LL * (frame_bytes / 32); break;
654 2074 case AV_CODEC_ID_NELLYMOSER : d = 256LL * (frame_bytes / 64); break;
655 1057 case AV_CODEC_ID_RA_144 : d = 160LL * (frame_bytes / 20); break;
656 153 case AV_CODEC_ID_APTX : d = 4LL * (frame_bytes / 4); break;
657 153 case AV_CODEC_ID_APTX_HD : d = 4LL * (frame_bytes / 6); break;
658 }
659
2/2
✓ Branch 0 taken 4158 times.
✓ Branch 1 taken 166986 times.
171144 if (d > INT64_MIN)
660
2/4
✓ Branch 0 taken 4158 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4158 times.
✗ Branch 3 not taken.
4158 return ((int)d == d && d > 0) ? d : 0;
661
662
2/2
✓ Branch 0 taken 50224 times.
✓ Branch 1 taken 116762 times.
166986 if (bps > 0) {
663 /* calc from frame_bytes and bits_per_coded_sample */
664
4/4
✓ Branch 0 taken 49764 times.
✓ Branch 1 taken 460 times.
✓ Branch 2 taken 48 times.
✓ Branch 3 taken 49716 times.
50224 if (id == AV_CODEC_ID_ADPCM_G726 || id == AV_CODEC_ID_ADPCM_G726LE)
665 508 return frame_bytes * 8 / bps;
666 }
667
668
3/4
✓ Branch 0 taken 166348 times.
✓ Branch 1 taken 130 times.
✓ Branch 2 taken 166348 times.
✗ Branch 3 not taken.
166478 if (ch > 0 && ch < INT_MAX/16) {
669 /* calc from frame_bytes and channels */
670
12/19
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 33 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 452 times.
✓ Branch 7 taken 1951 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 3580 times.
✓ Branch 10 taken 222 times.
✓ Branch 11 taken 327 times.
✓ Branch 12 taken 680 times.
✓ Branch 13 taken 112 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 300 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 1311 times.
✓ Branch 18 taken 157332 times.
166348 switch (id) {
671 case AV_CODEC_ID_FASTAUDIO:
672 return frame_bytes / (40 * ch) * 256;
673 case AV_CODEC_ID_ADPCM_IMA_MOFLEX:
674 return (frame_bytes - 4 * ch) / (128 * ch) * 256;
675 48 case AV_CODEC_ID_ADPCM_AFC:
676 48 return frame_bytes / (9 * ch) * 16;
677 case AV_CODEC_ID_ADPCM_N64:
678 frame_bytes /= 9 * ch;
679 if (frame_bytes > INT_MAX / 16)
680 return 0;
681 return frame_bytes * 16;
682 33 case AV_CODEC_ID_ADPCM_PSX:
683 case AV_CODEC_ID_ADPCM_DTK:
684 33 frame_bytes /= 16 * ch;
685
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
33 if (frame_bytes > INT_MAX / 28)
686 return 0;
687 33 return frame_bytes * 28;
688 case AV_CODEC_ID_ADPCM_PSXC:
689 frame_bytes = (frame_bytes - 1) / ch;
690 if (frame_bytes > INT_MAX / 2)
691 return 0;
692 return frame_bytes * 2;
693 452 case AV_CODEC_ID_ADPCM_4XM:
694 case AV_CODEC_ID_ADPCM_IMA_ACORN:
695 case AV_CODEC_ID_ADPCM_IMA_DAT4:
696 case AV_CODEC_ID_ADPCM_IMA_ISS:
697 case AV_CODEC_ID_ADPCM_IMA_PDA:
698 452 return (frame_bytes - 4 * ch) * 2 / ch;
699 1951 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
700 1951 return (frame_bytes - 4) * 2 / ch;
701 case AV_CODEC_ID_ADPCM_IMA_AMV:
702 return (frame_bytes - 8) * 2;
703 3580 case AV_CODEC_ID_ADPCM_THP:
704 case AV_CODEC_ID_ADPCM_THP_LE:
705
2/2
✓ Branch 0 taken 3530 times.
✓ Branch 1 taken 50 times.
3580 if (extradata)
706 3530 return frame_bytes * 14LL / (8 * ch);
707 50 break;
708 222 case AV_CODEC_ID_ADPCM_XA:
709 222 return (frame_bytes / 128) * 224 / ch;
710 327 case AV_CODEC_ID_INTERPLAY_DPCM:
711 327 return (frame_bytes - 6 - ch) / ch;
712 680 case AV_CODEC_ID_ROQ_DPCM:
713 680 return (frame_bytes - 8) / ch;
714 112 case AV_CODEC_ID_XAN_DPCM:
715 112 return (frame_bytes - 2 * ch) / ch;
716 case AV_CODEC_ID_MACE3:
717 return 3 * frame_bytes / ch;
718 300 case AV_CODEC_ID_MACE6:
719 300 return 6 * frame_bytes / ch;
720 case AV_CODEC_ID_PCM_LXF:
721 return 2 * (frame_bytes / (5 * ch));
722 1311 case AV_CODEC_ID_IAC:
723 case AV_CODEC_ID_IMC:
724 1311 return 4 * frame_bytes / ch;
725 }
726
727
2/2
✓ Branch 0 taken 37742 times.
✓ Branch 1 taken 119640 times.
157382 if (tag) {
728 /* calc from frame_bytes, channels, and codec_tag */
729
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 37668 times.
37742 if (id == AV_CODEC_ID_SOL_DPCM) {
730
1/2
✓ Branch 0 taken 74 times.
✗ Branch 1 not taken.
74 if (tag == 3)
731 74 return frame_bytes / ch;
732 else
733 return frame_bytes * 2 / ch;
734 }
735 }
736
737
2/2
✓ Branch 0 taken 30880 times.
✓ Branch 1 taken 126428 times.
157308 if (ba > 0) {
738 /* calc from frame_bytes, channels, and block_align */
739 30880 int blocks = frame_bytes / ba;
740 30880 int64_t tmp = 0;
741
7/9
✓ Branch 0 taken 273 times.
✓ Branch 1 taken 1191 times.
✓ Branch 2 taken 669 times.
✓ Branch 3 taken 649 times.
✓ Branch 4 taken 1001 times.
✓ Branch 5 taken 1210 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 25887 times.
30880 switch (id) {
742 273 case AV_CODEC_ID_ADPCM_IMA_XBOX:
743
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 273 times.
273 if (bps != 4)
744 return 0;
745 273 tmp = blocks * ((ba - 4 * ch) / (bps * ch) * 8);
746 273 break;
747 1191 case AV_CODEC_ID_ADPCM_IMA_WAV:
748
2/4
✓ Branch 0 taken 1191 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1191 times.
1191 if (bps < 2 || bps > 5)
749 return 0;
750 1191 tmp = blocks * (1LL + (ba - 4 * ch) / (bps * ch) * 8LL);
751 1191 break;
752 669 case AV_CODEC_ID_ADPCM_IMA_DK3:
753 669 tmp = blocks * (((ba - 16LL) * 2 / 3 * 4) / ch);
754 669 break;
755 649 case AV_CODEC_ID_ADPCM_IMA_DK4:
756 649 tmp = blocks * (1 + (ba - 4LL * ch) * 2 / ch);
757 649 break;
758 1001 case AV_CODEC_ID_ADPCM_IMA_RAD:
759 1001 tmp = blocks * ((ba - 4LL * ch) * 2 / ch);
760 1001 break;
761 1210 case AV_CODEC_ID_ADPCM_MS:
762 1210 tmp = blocks * (2 + (ba - 7LL * ch) * 2LL / ch);
763 1210 break;
764 case AV_CODEC_ID_ADPCM_MTAF:
765 tmp = blocks * (ba - 16LL) * 2 / ch;
766 break;
767 case AV_CODEC_ID_ADPCM_XMD:
768 tmp = blocks * 32;
769 break;
770 }
771
2/2
✓ Branch 0 taken 4993 times.
✓ Branch 1 taken 25887 times.
30880 if (tmp) {
772
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4993 times.
4993 if (tmp != (int)tmp)
773 return 0;
774 4993 return tmp;
775 }
776 }
777
778
2/2
✓ Branch 0 taken 40788 times.
✓ Branch 1 taken 111527 times.
152315 if (bps > 0) {
779 /* calc from frame_bytes, channels, and bits_per_coded_sample */
780
3/4
✓ Branch 0 taken 20821 times.
✓ Branch 1 taken 2794 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 17173 times.
40788 switch (id) {
781 20821 case AV_CODEC_ID_PCM_DVD:
782
2/4
✓ Branch 0 taken 20821 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 20821 times.
20821 if(bps<4 || frame_bytes<3)
783 return 0;
784 20821 return 2 * ((frame_bytes - 3) / ((bps * 2 / 8) * ch));
785 2794 case AV_CODEC_ID_PCM_BLURAY:
786
2/4
✓ Branch 0 taken 2794 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2794 times.
2794 if(bps<4 || frame_bytes<4)
787 return 0;
788 2794 return (frame_bytes - 4) / ((FFALIGN(ch, 2) * bps) / 8);
789 case AV_CODEC_ID_S302M:
790 return 2 * (frame_bytes / ((bps + 4) / 4)) / ch;
791 }
792 }
793 }
794 }
795
796 /* Fall back on using frame_size */
797
4/4
✓ Branch 0 taken 88176 times.
✓ Branch 1 taken 44304 times.
✓ Branch 2 taken 87962 times.
✓ Branch 3 taken 214 times.
132480 if (frame_size > 1 && frame_bytes)
798 87962 return frame_size;
799
800 //For WMA we currently have no other means to calculate duration thus we
801 //do it here by assuming CBR, which is true for all known cases.
802
8/8
✓ Branch 0 taken 29566 times.
✓ Branch 1 taken 14952 times.
✓ Branch 2 taken 25934 times.
✓ Branch 3 taken 3632 times.
✓ Branch 4 taken 25909 times.
✓ Branch 5 taken 25 times.
✓ Branch 6 taken 9869 times.
✓ Branch 7 taken 16040 times.
44518 if (bitrate > 0 && frame_bytes > 0 && sr > 0 && ba > 1) {
803
4/4
✓ Branch 0 taken 9597 times.
✓ Branch 1 taken 272 times.
✓ Branch 2 taken 798 times.
✓ Branch 3 taken 8799 times.
9869 if (id == AV_CODEC_ID_WMAV1 || id == AV_CODEC_ID_WMAV2)
804 1070 return (frame_bytes * 8LL * sr) / bitrate;
805 }
806
807 43448 return 0;
808 }
809
810 45835 int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
811 {
812 45835 int channels = avctx->ch_layout.nb_channels;
813 int duration;
814
815 45835 duration = get_audio_frame_duration(avctx->codec_id, avctx->sample_rate,
816 channels, avctx->block_align,
817 avctx->codec_tag, avctx->bits_per_coded_sample,
818 avctx->bit_rate, avctx->extradata, avctx->frame_size,
819 frame_bytes);
820 45835 return FFMAX(0, duration);
821 }
822
823 567201 int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
824 {
825 567201 int channels = par->ch_layout.nb_channels;
826 int duration;
827
828 567201 duration = get_audio_frame_duration(par->codec_id, par->sample_rate,
829 channels, par->block_align,
830 par->codec_tag, par->bits_per_coded_sample,
831 par->bit_rate, par->extradata, par->frame_size,
832 frame_bytes);
833 567201 return FFMAX(0, duration);
834 }
835
836 70 unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
837 {
838 70 unsigned int n = 0;
839
840
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 70 times.
70 while (v >= 0xff) {
841 *s++ = 0xff;
842 v -= 0xff;
843 n++;
844 }
845 70 *s = v;
846 70 n++;
847 70 return n;
848 }
849
850 476 int ff_match_2uint16(const uint16_t(*tab)[2], int size, int a, int b)
851 {
852 int i;
853
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++) ;
854 476 return i;
855 }
856
857 17225 const AVCodecHWConfig *avcodec_get_hw_config(const AVCodec *avcodec, int index)
858 {
859 17225 const FFCodec *const codec = ffcodec(avcodec);
860 int i;
861
3/4
✓ Branch 0 taken 2779 times.
✓ Branch 1 taken 14446 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2779 times.
17225 if (!codec->hw_configs || index < 0)
862 14446 return NULL;
863
2/2
✓ Branch 0 taken 5389 times.
✓ Branch 1 taken 1779 times.
7168 for (i = 0; i <= index; i++)
864
2/2
✓ Branch 0 taken 1000 times.
✓ Branch 1 taken 4389 times.
5389 if (!codec->hw_configs[i])
865 1000 return NULL;
866 1779 return &codec->hw_configs[index]->public;
867 }
868
869 28251 int ff_thread_ref_frame(ThreadFrame *dst, const ThreadFrame *src)
870 {
871 int ret;
872
873 28251 dst->owner[0] = src->owner[0];
874 28251 dst->owner[1] = src->owner[1];
875
876 28251 ret = av_frame_ref(dst->f, src->f);
877
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28251 times.
28251 if (ret < 0)
878 return ret;
879
880
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28251 times.
28251 av_assert0(!dst->progress);
881
882
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 28191 times.
28251 if (src->progress)
883 60 dst->progress = av_refstruct_ref(src->progress);
884
885 28251 return 0;
886 }
887
888 298 int ff_thread_replace_frame(ThreadFrame *dst, const ThreadFrame *src)
889 {
890 int ret;
891
892 298 dst->owner[0] = src->owner[0];
893 298 dst->owner[1] = src->owner[1];
894
895 298 ret = av_frame_replace(dst->f, src->f);
896
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 298 times.
298 if (ret < 0)
897 return ret;
898
899 298 av_refstruct_replace(&dst->progress, src->progress);
900
901 298 return 0;
902 }
903
904 #if !HAVE_THREADS
905
906 int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f, int flags)
907 {
908 return ff_get_buffer(avctx, f, flags);
909 }
910
911 int ff_thread_get_ext_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
912 {
913 f->owner[0] = f->owner[1] = avctx;
914 return ff_get_buffer(avctx, f->f, flags);
915 }
916
917 void ff_thread_release_ext_buffer(ThreadFrame *f)
918 {
919 f->owner[0] = f->owner[1] = NULL;
920 if (f->f)
921 av_frame_unref(f->f);
922 }
923
924 void ff_thread_finish_setup(AVCodecContext *avctx)
925 {
926 }
927
928 void ff_thread_report_progress(ThreadFrame *f, int progress, int field)
929 {
930 }
931
932 void ff_thread_await_progress(const ThreadFrame *f, int progress, int field)
933 {
934 }
935
936 int ff_thread_can_start_frame(AVCodecContext *avctx)
937 {
938 return 1;
939 }
940 #endif
941
942 703038 const uint8_t *avpriv_find_start_code(const uint8_t *restrict p,
943 const uint8_t *end,
944 uint32_t *restrict state)
945 {
946 int i;
947
948
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 703038 times.
703038 av_assert0(p <= end);
949
2/2
✓ Branch 0 taken 933 times.
✓ Branch 1 taken 702105 times.
703038 if (p >= end)
950 933 return end;
951
952
2/2
✓ Branch 0 taken 2100688 times.
✓ Branch 1 taken 698094 times.
2798782 for (i = 0; i < 3; i++) {
953 2100688 uint32_t tmp = *state << 8;
954 2100688 *state = tmp + *(p++);
955
4/4
✓ Branch 0 taken 2099740 times.
✓ Branch 1 taken 948 times.
✓ Branch 2 taken 3063 times.
✓ Branch 3 taken 2096677 times.
2100688 if (tmp == 0x100 || p == end)
956 4011 return p;
957 }
958
959
2/2
✓ Branch 0 taken 447373904 times.
✓ Branch 1 taken 71082 times.
447444986 while (p < end) {
960
2/2
✓ Branch 0 taken 408292399 times.
✓ Branch 1 taken 39081505 times.
447373904 if (p[-1] > 1 ) p += 3;
961
2/2
✓ Branch 0 taken 17473734 times.
✓ Branch 1 taken 21607771 times.
39081505 else if (p[-2] ) p += 2;
962
2/2
✓ Branch 0 taken 20980759 times.
✓ Branch 1 taken 627012 times.
21607771 else if (p[-3]|(p[-1]-1)) p++;
963 else {
964 627012 p++;
965 627012 break;
966 }
967 }
968
969
2/2
✓ Branch 0 taken 44473 times.
✓ Branch 1 taken 653621 times.
698094 p = FFMIN(p, end) - 4;
970 698094 *state = AV_RB32(p);
971
972 698094 return p + 4;
973 }
974
975 466 AVCPBProperties *av_cpb_properties_alloc(size_t *size)
976 {
977 466 AVCPBProperties *props = av_mallocz(sizeof(AVCPBProperties));
978
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 466 times.
466 if (!props)
979 return NULL;
980
981
1/2
✓ Branch 0 taken 466 times.
✗ Branch 1 not taken.
466 if (size)
982 466 *size = sizeof(*props);
983
984 466 props->vbv_delay = UINT64_MAX;
985
986 466 return props;
987 }
988
989 static void put_timecode_fields(PutBitContext *pb, AVRational rate, uint32_t tc)
990 {
991 unsigned hours, minutes, seconds, frames, drop;
992
993 ff_timecode_set_smpte(&drop, &hours, &minutes, &seconds, &frames, rate, tc, 0, 0);
994
995 put_bits(pb, 5, 0); // counting_type
996 put_bits(pb, 1, 1); // full_timestamp_flag
997 put_bits(pb, 1, 0); // discontinuity_flag
998 put_bits(pb, 1, drop); // cnt_dropped_flag
999 put_bits(pb, 9, frames);
1000 put_bits(pb, 6, seconds);
1001 put_bits(pb, 6, minutes);
1002 put_bits(pb, 5, hours);
1003 }
1004
1005 int ff_alloc_timecode_sei(const AVFrame *frame, AVRational rate, size_t prefix_len,
1006 void **data, size_t *sei_size)
1007 {
1008 AVFrameSideData *sd = NULL;
1009 uint8_t *sei_data;
1010 PutBitContext pb;
1011 uint32_t *tc;
1012 int m;
1013
1014 if (frame)
1015 sd = av_frame_get_side_data(frame, AV_FRAME_DATA_S12M_TIMECODE);
1016
1017 if (!sd) {
1018 *data = NULL;
1019 return 0;
1020 }
1021 tc = (uint32_t*)sd->data;
1022 m = tc[0] & 3;
1023
1024 *sei_size = sizeof(uint32_t) * 4;
1025 *data = av_mallocz(*sei_size + prefix_len);
1026 if (!*data)
1027 return AVERROR(ENOMEM);
1028 sei_data = (uint8_t*)*data + prefix_len;
1029
1030 init_put_bits(&pb, sei_data, *sei_size);
1031 put_bits(&pb, 2, m); // num_clock_ts
1032
1033 for (int j = 1; j <= m; j++) {
1034 put_bits(&pb, 1, 1); // clock_timestamp_flag
1035 put_bits(&pb, 1, 1); // units_field_based_flag
1036 put_timecode_fields(&pb, rate, tc[j]);
1037 put_bits(&pb, 5, 0); // time_offset_length
1038 }
1039 flush_put_bits(&pb);
1040
1041 return 0;
1042 }
1043
1044 int ff_alloc_timecode_metadata_av1(const AVFrame *frame, AVRational rate,
1045 void **data, size_t *size)
1046 {
1047 AVFrameSideData *sd = NULL;
1048 PutBitContext pb;
1049 uint32_t *tc;
1050
1051 if (frame)
1052 sd = av_frame_get_side_data(frame, AV_FRAME_DATA_S12M_TIMECODE);
1053
1054 *data = NULL;
1055 if (!sd)
1056 return 0;
1057 tc = (uint32_t*)sd->data;
1058 if (!(tc[0] & 3)) // num_clock_ts
1059 return 0;
1060
1061 *size = 5;
1062 *data = av_mallocz(*size);
1063 if (!*data)
1064 return AVERROR(ENOMEM);
1065
1066 init_put_bits(&pb, *data, *size);
1067 put_timecode_fields(&pb, rate, tc[1]);
1068 put_bits(&pb, 5, 1); // time_offset_length
1069 put_bits(&pb, 1, 0); // time_offset_value
1070 flush_put_bits(&pb);
1071
1072 return 0;
1073 }
1074
1075 19635 int64_t ff_guess_coded_bitrate(AVCodecContext *avctx)
1076 {
1077 19635 AVRational framerate = avctx->framerate;
1078 19635 int bits_per_coded_sample = avctx->bits_per_coded_sample;
1079 int64_t bitrate;
1080
1081
3/4
✓ Branch 0 taken 19516 times.
✓ Branch 1 taken 119 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 19516 times.
19635 if (!(framerate.num && framerate.den))
1082 119 framerate = av_inv_q(avctx->time_base);
1083
2/4
✓ Branch 0 taken 19635 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 19635 times.
19635 if (!(framerate.num && framerate.den))
1084 return 0;
1085
1086
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19635 times.
19635 if (!bits_per_coded_sample) {
1087 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
1088 bits_per_coded_sample = av_get_bits_per_pixel(desc);
1089 }
1090 19635 bitrate = (int64_t)bits_per_coded_sample * avctx->width * avctx->height *
1091 19635 framerate.num / framerate.den;
1092
1093 19635 return bitrate;
1094 }
1095