FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/utils.c
Date: 2026-07-19 01:11:25
Exec Total Coverage
Lines: 379 513 73.9%
Functions: 25 29 86.2%
Branches: 282 390 72.3%

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 184994 void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
54 {
55 184994 uint8_t **p = ptr;
56
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 184994 times.
184994 if (min_size > SIZE_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
57 av_freep(p);
58 *size = 0;
59 return;
60 }
61 184994 av_fast_mallocz(p, size, min_size + AV_INPUT_BUFFER_PADDING_SIZE);
62
1/2
✓ Branch 0 taken 184994 times.
✗ Branch 1 not taken.
184994 if (*p)
63 184994 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 2628815 int av_codec_is_encoder(const AVCodec *avcodec)
80 {
81 2628815 const FFCodec *const codec = ffcodec(avcodec);
82
4/4
✓ Branch 0 taken 2618424 times.
✓ Branch 1 taken 10391 times.
✓ Branch 2 taken 1654418 times.
✓ Branch 3 taken 964006 times.
2628815 return codec && !codec->is_decoder;
83 }
84
85 515104 int av_codec_is_decoder(const AVCodec *avcodec)
86 {
87 515104 const FFCodec *const codec = ffcodec(avcodec);
88
4/4
✓ Branch 0 taken 504713 times.
✓ Branch 1 taken 10391 times.
✓ Branch 2 taken 482591 times.
✓ Branch 3 taken 22122 times.
515104 return codec && codec->is_decoder;
89 }
90
91 63075 int ff_set_dimensions(AVCodecContext *s, int width, int height)
92 {
93 63075 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 63074 times.
63075 if (ret < 0)
96 1 width = height = 0;
97
98 63075 s->coded_width = width;
99 63075 s->coded_height = height;
100 63075 s->width = AV_CEIL_RSHIFT(width, s->lowres);
101 63075 s->height = AV_CEIL_RSHIFT(height, s->lowres);
102
103 63075 return ret;
104 }
105
106 3069 int ff_set_sar(AVCodecContext *avctx, AVRational sar)
107 {
108 3069 int ret = av_image_check_sar(avctx->width, avctx->height, sar);
109
110
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 3064 times.
3069 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 3064 avctx->sample_aspect_ratio = sar;
117 }
118 3064 return 0;
119 }
120
121 4247 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 4247 side_data = av_frame_get_side_data(frame, AV_FRAME_DATA_MATRIXENCODING);
128
1/2
✓ Branch 0 taken 4247 times.
✗ Branch 1 not taken.
4247 if (!side_data)
129 4247 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 4247 times.
4247 if (!side_data)
133 return AVERROR(ENOMEM);
134
135 4247 data = (enum AVMatrixEncoding*)side_data->data;
136 4247 *data = matrix_encoding;
137
138 4247 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 9966 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 227 times.
✓ Branch 7 taken 23 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 488 times.
11003 switch (s->pix_fmt) {
155 9966 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 9966 w_align = 16; //FIXME assume 16 pixel per macroblock
245 9966 h_align = 16 * 2; // interlaced needs 2 macroblocks height
246
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 9963 times.
9966 if (s->codec_id == AV_CODEC_ID_BINKVIDEO)
247 3 w_align = 16*2;
248 9966 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 227 case AV_PIX_FMT_RGB24:
307
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 220 times.
227 if (s->codec_id == AV_CODEC_ID_CINEPAK) {
308 7 w_align = 4;
309 7 h_align = 4;
310 }
311 227 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 10391 times.
✓ Branch 1 taken 612 times.
✓ Branch 2 taken 10390 times.
✓ Branch 3 taken 1 times.
11003 if (s->codec_id == AV_CODEC_ID_H264 || s->lowres ||
344
4/4
✓ Branch 0 taken 10375 times.
✓ Branch 1 taken 15 times.
✓ Branch 2 taken 10368 times.
✓ Branch 3 taken 7 times.
10390 s->codec_id == AV_CODEC_ID_VC1 || s->codec_id == AV_CODEC_ID_WMV3 ||
345
4/4
✓ Branch 0 taken 10367 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 10358 times.
✓ Branch 3 taken 9 times.
10368 s->codec_id == AV_CODEC_ID_VP5 || s->codec_id == AV_CODEC_ID_VP6 ||
346
4/4
✓ Branch 0 taken 10356 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 10354 times.
10358 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 649 *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 649 *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 203823 int avpriv_codec_get_cap_skip_frame_fill_param(const AVCodec *codec){
418 203823 return !!(ffcodec(codec)->caps_internal & FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM);
419 }
420
421 30780 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 30509 times.
30780 if (id == AV_CODEC_ID_NONE)
426 271 return "none";
427 30509 cd = avcodec_descriptor_get(id);
428
2/2
✓ Branch 0 taken 30505 times.
✓ Branch 1 taken 4 times.
30509 if (cd)
429 30505 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 18141 const char *avcodec_profile_name(enum AVCodecID codec_id, int profile)
447 {
448 18141 const AVCodecDescriptor *desc = avcodec_descriptor_get(codec_id);
449 const AVProfile *p;
450
451
5/6
✓ Branch 0 taken 2500 times.
✓ Branch 1 taken 15641 times.
✓ Branch 2 taken 2500 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 163 times.
✓ Branch 5 taken 2337 times.
18141 if (profile == AV_PROFILE_UNKNOWN || !desc || !desc->profiles)
452 15804 return NULL;
453
454
2/2
✓ Branch 0 taken 6036 times.
✓ Branch 1 taken 34 times.
6070 for (p = desc->profiles; p->profile != AV_PROFILE_UNKNOWN; p++)
455
2/2
✓ Branch 0 taken 2303 times.
✓ Branch 1 taken 3733 times.
6036 if (p->profile == profile)
456 2303 return p->name;
457
458 34 return NULL;
459 }
460
461 917630 int av_get_exact_bits_per_sample(enum AVCodecID codec_id)
462 {
463
8/8
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 11201 times.
✓ Branch 2 taken 6763 times.
✓ Branch 3 taken 577321 times.
✓ Branch 4 taken 18493 times.
✓ Branch 5 taken 23632 times.
✓ Branch 6 taken 10639 times.
✓ Branch 7 taken 269557 times.
917630 switch (codec_id) {
464 24 case AV_CODEC_ID_DFPWM:
465 24 return 1;
466 11201 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 11201 return 4;
483 6763 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 6763 return 8;
500 577321 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 577321 return 16;
507 18493 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 18493 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 10639 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 10639 return 64;
529 269557 default:
530 269557 return 0;
531 }
532 }
533
534 28 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 28 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 28 times.
28 if (fmt < 0 || fmt >= FF_ARRAY_ELEMS(map))
550 return AV_CODEC_ID_NONE;
551
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
28 if (be < 0 || be > 1)
552 28 be = AV_NE(1, 0);
553 28 return map[fmt][be];
554 }
555
556 297695 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 297580 times.
297695 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 297580 default:
574 297580 return av_get_exact_bits_per_sample(codec_id);
575 }
576 }
577
578 610299 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 610299 int bps = av_get_exact_bits_per_sample(id);
583
4/4
✓ Branch 0 taken 410130 times.
✓ Branch 1 taken 200169 times.
✓ Branch 2 taken 409825 times.
✓ Branch 3 taken 305 times.
610299 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 352862 times.
✓ Branch 1 taken 257437 times.
✓ Branch 2 taken 352862 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 352826 times.
✓ Branch 5 taken 36 times.
✓ Branch 6 taken 352826 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 352826 times.
✗ Branch 9 not taken.
610299 if (bps > 0 && ch > 0 && frame_bytes > 0 && ch < 32768 && bps < 32768)
587 352826 return (frame_bytes * 8LL) / (bps * ch);
588 257473 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 2185 times.
✓ Branch 9 taken 20567 times.
✓ Branch 10 taken 2403 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 191308 times.
257473 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 2185 case AV_CODEC_ID_ATRAC3P: return 2048;
610 20567 case AV_CODEC_ID_MP2:
611 20567 case AV_CODEC_ID_MUSEPACK7: return 1152;
612 2403 case AV_CODEC_ID_AC3: return 1536;
613 case AV_CODEC_ID_FTR: return 1024;
614 }
615
616
2/2
✓ Branch 0 taken 187782 times.
✓ Branch 1 taken 3526 times.
191308 if (sr > 0) {
617 /* calc from sample rate */
618
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 187765 times.
187782 if (id == AV_CODEC_ID_TTA)
619 17 return 256ll * sr / 245;
620
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 187765 times.
187765 else if (id == AV_CODEC_ID_DST)
621 return 588ll * sr / 44100;
622
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 187699 times.
187765 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 9315 times.
✓ Branch 1 taken 178384 times.
187699 if (id == AV_CODEC_ID_MP3)
629
2/2
✓ Branch 0 taken 232 times.
✓ Branch 1 taken 9083 times.
9315 return sr <= 24000 ? 576 : 1152;
630 }
631
632
2/2
✓ Branch 0 taken 42603 times.
✓ Branch 1 taken 139307 times.
181910 if (ba > 0) {
633 /* calc from block_align */
634
2/2
✓ Branch 0 taken 7261 times.
✓ Branch 1 taken 35342 times.
42603 if (id == AV_CODEC_ID_SIPR) {
635
4/5
✓ Branch 0 taken 3262 times.
✓ Branch 1 taken 1983 times.
✓ Branch 2 taken 1680 times.
✓ Branch 3 taken 336 times.
✗ Branch 4 not taken.
7261 switch (ba) {
636 3262 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 35342 times.
35342 } 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 170999 times.
✓ Branch 1 taken 3650 times.
174649 if (frame_bytes > 0) {
650 /* calc from frame_bytes only */
651 170999 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 166841 times.
170999 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 166841 times.
170999 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 50225 times.
✓ Branch 1 taken 116616 times.
166841 if (bps > 0) {
663 /* calc from frame_bytes and bits_per_coded_sample */
664
4/4
✓ Branch 0 taken 49765 times.
✓ Branch 1 taken 460 times.
✓ Branch 2 taken 48 times.
✓ Branch 3 taken 49717 times.
50225 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 166204 times.
✓ Branch 1 taken 129 times.
✓ Branch 2 taken 166204 times.
✗ Branch 3 not taken.
166333 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 157188 times.
166204 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 37750 times.
✓ Branch 1 taken 119488 times.
157238 if (tag) {
728 /* calc from frame_bytes, channels, and codec_tag */
729
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 37676 times.
37750 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 30878 times.
✓ Branch 1 taken 126286 times.
157164 if (ba > 0) {
738 /* calc from frame_bytes, channels, and block_align */
739 30878 int blocks = frame_bytes / ba;
740 30878 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 25885 times.
30878 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 25885 times.
30878 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 40789 times.
✓ Branch 1 taken 111382 times.
152171 if (bps > 0) {
779 /* calc from frame_bytes, channels, and bits_per_coded_sample */
780
3/4
✓ Branch 0 taken 20814 times.
✓ Branch 1 taken 2794 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 17181 times.
40789 switch (id) {
781 20814 case AV_CODEC_ID_PCM_DVD:
782
2/4
✓ Branch 0 taken 20814 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 20814 times.
20814 if(bps<4 || frame_bytes<3)
783 return 0;
784 20814 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 88102 times.
✓ Branch 1 taken 44240 times.
✓ Branch 2 taken 87888 times.
✓ Branch 3 taken 214 times.
132342 if (frame_size > 1 && frame_bytes)
798 87888 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 29503 times.
✓ Branch 1 taken 14951 times.
✓ Branch 2 taken 25871 times.
✓ Branch 3 taken 3632 times.
✓ Branch 4 taken 25846 times.
✓ Branch 5 taken 25 times.
✓ Branch 6 taken 9867 times.
✓ Branch 7 taken 15979 times.
44454 if (bitrate > 0 && frame_bytes > 0 && sr > 0 && ba > 1) {
803
4/4
✓ Branch 0 taken 9595 times.
✓ Branch 1 taken 272 times.
✓ Branch 2 taken 797 times.
✓ Branch 3 taken 8798 times.
9867 if (id == AV_CODEC_ID_WMAV1 || id == AV_CODEC_ID_WMAV2)
804 1069 return (frame_bytes * 8LL * sr) / bitrate;
805 }
806
807 43385 return 0;
808 }
809
810 45735 int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
811 {
812 45735 int channels = avctx->ch_layout.nb_channels;
813 int duration;
814
815 45735 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 45735 return FFMAX(0, duration);
821 }
822
823 564564 int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
824 {
825 564564 int channels = par->ch_layout.nb_channels;
826 int duration;
827
828 564564 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 564564 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 17214 const AVCodecHWConfig *avcodec_get_hw_config(const AVCodec *avcodec, int index)
858 {
859 17214 const FFCodec *const codec = ffcodec(avcodec);
860 int i;
861
3/4
✓ Branch 0 taken 2779 times.
✓ Branch 1 taken 14435 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2779 times.
17214 if (!codec->hw_configs || index < 0)
862 14435 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 28250 int ff_thread_ref_frame(ThreadFrame *dst, const ThreadFrame *src)
870 {
871 int ret;
872
873 28250 dst->owner[0] = src->owner[0];
874 28250 dst->owner[1] = src->owner[1];
875
876 28250 ret = av_frame_ref(dst->f, src->f);
877
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28250 times.
28250 if (ret < 0)
878 return ret;
879
880
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28250 times.
28250 av_assert0(!dst->progress);
881
882
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 28190 times.
28250 if (src->progress)
883 60 dst->progress = av_refstruct_ref(src->progress);
884
885 28250 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 702959 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 702959 times.
702959 av_assert0(p <= end);
949
2/2
✓ Branch 0 taken 932 times.
✓ Branch 1 taken 702027 times.
702959 if (p >= end)
950 932 return end;
951
952
2/2
✓ Branch 0 taken 2100454 times.
✓ Branch 1 taken 698015 times.
2798469 for (i = 0; i < 3; i++) {
953 2100454 uint32_t tmp = *state << 8;
954 2100454 *state = tmp + *(p++);
955
4/4
✓ Branch 0 taken 2099507 times.
✓ Branch 1 taken 947 times.
✓ Branch 2 taken 3065 times.
✓ Branch 3 taken 2096442 times.
2100454 if (tmp == 0x100 || p == end)
956 4012 return p;
957 }
958
959
2/2
✓ Branch 0 taken 446389714 times.
✓ Branch 1 taken 71055 times.
446460769 while (p < end) {
960
2/2
✓ Branch 0 taken 407337819 times.
✓ Branch 1 taken 39051895 times.
446389714 if (p[-1] > 1 ) p += 3;
961
2/2
✓ Branch 0 taken 17451507 times.
✓ Branch 1 taken 21600388 times.
39051895 else if (p[-2] ) p += 2;
962
2/2
✓ Branch 0 taken 20973428 times.
✓ Branch 1 taken 626960 times.
21600388 else if (p[-3]|(p[-1]-1)) p++;
963 else {
964 626960 p++;
965 626960 break;
966 }
967 }
968
969
2/2
✓ Branch 0 taken 44466 times.
✓ Branch 1 taken 653549 times.
698015 p = FFMIN(p, end) - 4;
970 698015 *state = AV_RB32(p);
971
972 698015 return p + 4;
973 }
974
975 465 AVCPBProperties *av_cpb_properties_alloc(size_t *size)
976 {
977 465 AVCPBProperties *props = av_mallocz(sizeof(AVCPBProperties));
978
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 465 times.
465 if (!props)
979 return NULL;
980
981
1/2
✓ Branch 0 taken 465 times.
✗ Branch 1 not taken.
465 if (size)
982 465 *size = sizeof(*props);
983
984 465 props->vbv_delay = UINT64_MAX;
985
986 465 return props;
987 }
988
989 int ff_alloc_timecode_sei(const AVFrame *frame, AVRational rate, size_t prefix_len,
990 void **data, size_t *sei_size)
991 {
992 AVFrameSideData *sd = NULL;
993 uint8_t *sei_data;
994 PutBitContext pb;
995 uint32_t *tc;
996 int m;
997
998 if (frame)
999 sd = av_frame_get_side_data(frame, AV_FRAME_DATA_S12M_TIMECODE);
1000
1001 if (!sd) {
1002 *data = NULL;
1003 return 0;
1004 }
1005 tc = (uint32_t*)sd->data;
1006 m = tc[0] & 3;
1007
1008 *sei_size = sizeof(uint32_t) * 4;
1009 *data = av_mallocz(*sei_size + prefix_len);
1010 if (!*data)
1011 return AVERROR(ENOMEM);
1012 sei_data = (uint8_t*)*data + prefix_len;
1013
1014 init_put_bits(&pb, sei_data, *sei_size);
1015 put_bits(&pb, 2, m); // num_clock_ts
1016
1017 for (int j = 1; j <= m; j++) {
1018 unsigned hh, mm, ss, ff, drop;
1019 ff_timecode_set_smpte(&drop, &hh, &mm, &ss, &ff, rate, tc[j], 0, 0);
1020
1021 put_bits(&pb, 1, 1); // clock_timestamp_flag
1022 put_bits(&pb, 1, 1); // units_field_based_flag
1023 put_bits(&pb, 5, 0); // counting_type
1024 put_bits(&pb, 1, 1); // full_timestamp_flag
1025 put_bits(&pb, 1, 0); // discontinuity_flag
1026 put_bits(&pb, 1, drop);
1027 put_bits(&pb, 9, ff);
1028 put_bits(&pb, 6, ss);
1029 put_bits(&pb, 6, mm);
1030 put_bits(&pb, 5, hh);
1031 put_bits(&pb, 5, 0);
1032 }
1033 flush_put_bits(&pb);
1034
1035 return 0;
1036 }
1037
1038 19608 int64_t ff_guess_coded_bitrate(AVCodecContext *avctx)
1039 {
1040 19608 AVRational framerate = avctx->framerate;
1041 19608 int bits_per_coded_sample = avctx->bits_per_coded_sample;
1042 int64_t bitrate;
1043
1044
3/4
✓ Branch 0 taken 19489 times.
✓ Branch 1 taken 119 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 19489 times.
19608 if (!(framerate.num && framerate.den))
1045 119 framerate = av_inv_q(avctx->time_base);
1046
2/4
✓ Branch 0 taken 19608 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 19608 times.
19608 if (!(framerate.num && framerate.den))
1047 return 0;
1048
1049
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19608 times.
19608 if (!bits_per_coded_sample) {
1050 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
1051 bits_per_coded_sample = av_get_bits_per_pixel(desc);
1052 }
1053 19608 bitrate = (int64_t)bits_per_coded_sample * avctx->width * avctx->height *
1054 19608 framerate.num / framerate.den;
1055
1056 19608 return bitrate;
1057 }
1058