FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/utils.c
Date: 2026-09-28 11:37:26
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 185391 void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
54 {
55 185391 uint8_t **p = ptr;
56
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 185391 times.
185391 if (min_size > SIZE_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
57 ✗ av_freep(p);
58 ✗ *size = 0;
59 ✗ return;
60 }
61 185391 av_fast_mallocz(p, size, min_size + AV_INPUT_BUFFER_PADDING_SIZE);
62
1/2
✓ Branch 0 taken 185391 times.
✗ Branch 1 not taken.
185391 if (*p)
63 185391 memset(*p + min_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
64 }
65
66 715 void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size)
67 {
68 715 uint8_t **p = ptr;
69
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 715 times.
715 if (min_size > SIZE_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
70 ✗ av_freep(p);
71 ✗ *size = 0;
72 ✗ return;
73 }
74 715 av_fast_malloc(p, size, min_size + AV_INPUT_BUFFER_PADDING_SIZE);
75
1/2
✓ Branch 0 taken 715 times.
✗ Branch 1 not taken.
715 if (*p)
76 715 memset(*p, 0, min_size + AV_INPUT_BUFFER_PADDING_SIZE);
77 }
78
79 2638969 int av_codec_is_encoder(const AVCodec *avcodec)
80 {
81 2638969 const FFCodec *const codec = ffcodec(avcodec);
82
4/4
✓ Branch 0 taken 2628208 times.
✓ Branch 1 taken 10761 times.
✓ Branch 2 taken 1663219 times.
✓ Branch 3 taken 964989 times.
2638969 return codec && !codec->is_decoder;
83 }
84
85 520602 int av_codec_is_decoder(const AVCodec *avcodec)
86 {
87 520602 const FFCodec *const codec = ffcodec(avcodec);
88
4/4
✓ Branch 0 taken 509841 times.
✓ Branch 1 taken 10761 times.
✓ Branch 2 taken 487528 times.
✓ Branch 3 taken 22313 times.
520602 return codec && codec->is_decoder;
89 }
90
91 63379 int ff_set_dimensions(AVCodecContext *s, int width, int height)
92 {
93 63379 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 63378 times.
63379 if (ret < 0)
96 1 width = height = 0;
97
98 63379 s->coded_width = width;
99 63379 s->coded_height = height;
100 63379 s->width = AV_CEIL_RSHIFT(width, s->lowres);
101 63379 s->height = AV_CEIL_RSHIFT(height, s->lowres);
102
103 63379 return ret;
104 }
105
106 3130 int ff_set_sar(AVCodecContext *avctx, AVRational sar)
107 {
108 3130 int ret = av_image_check_sar(avctx->width, avctx->height, sar);
109
110
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 3125 times.
3130 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 3125 avctx->sample_aspect_ratio = sar;
117 }
118 3125 return 0;
119 }
120
121 4737 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 4737 side_data = av_frame_get_side_data(frame, AV_FRAME_DATA_MATRIXENCODING);
128
1/2
✓ Branch 0 taken 4737 times.
✗ Branch 1 not taken.
4737 if (!side_data)
129 4737 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 4737 times.
4737 if (!side_data)
133 ✗ return AVERROR(ENOMEM);
134
135 4737 data = (enum AVMatrixEncoding*)side_data->data;
136 4737 *data = matrix_encoding;
137
138 4737 return 0;
139 }
140
141 10834 void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height,
142 int linesize_align[AV_NUM_DATA_POINTERS])
143 {
144 int i;
145 10834 int w_align = 1;
146 10834 int h_align = 1;
147 10834 AVPixFmtDescriptor const *desc = av_pix_fmt_desc_get(s->pix_fmt);
148
149
1/2
✓ Branch 0 taken 10834 times.
✗ Branch 1 not taken.
10834 if (desc) {
150 10834 w_align = 1 << desc->log2_chroma_w;
151 10834 h_align = 1 << desc->log2_chroma_h;
152 }
153
154
9/10
✓ Branch 0 taken 9791 times.
✓ Branch 1 taken 29 times.
✓ Branch 2 taken 21 times.
✓ Branch 3 taken 38 times.
✓ Branch 4 taken 133 times.
✓ Branch 5 taken 81 times.
✓ Branch 6 taken 230 times.
✓ Branch 7 taken 23 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 488 times.
10834 switch (s->pix_fmt) {
155 9791 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 9791 w_align = 16; //FIXME assume 16 pixel per macroblock
245 9791 h_align = 16 * 2; // interlaced needs 2 macroblocks height
246
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 9788 times.
9791 if (s->codec_id == AV_CODEC_ID_BINKVIDEO)
247 3 w_align = 16*2;
248 9791 break;
249 29 case AV_PIX_FMT_YUV411P:
250 case AV_PIX_FMT_YUVJ411P:
251 case AV_PIX_FMT_UYYVYY411:
252 29 w_align = 32;
253 29 h_align = 16 * 2;
254 29 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 230 case AV_PIX_FMT_RGB24:
307
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 223 times.
230 if (s->codec_id == AV_CODEC_ID_CINEPAK) {
308 7 w_align = 4;
309 7 h_align = 4;
310 }
311 230 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 10832 times.
10834 if (s->codec_id == AV_CODEC_ID_IFF_ILBM) {
338 2 w_align = FFMAX(w_align, 16);
339 }
340
341 10834 *width = FFALIGN(*width, w_align);
342 10834 *height = FFALIGN(*height, h_align);
343
4/4
✓ Branch 0 taken 10195 times.
✓ Branch 1 taken 639 times.
✓ Branch 2 taken 10194 times.
✓ Branch 3 taken 1 times.
10834 if (s->codec_id == AV_CODEC_ID_H264 || s->lowres ||
344
4/4
✓ Branch 0 taken 10179 times.
✓ Branch 1 taken 15 times.
✓ Branch 2 taken 10172 times.
✓ Branch 3 taken 7 times.
10194 s->codec_id == AV_CODEC_ID_VC1 || s->codec_id == AV_CODEC_ID_WMV3 ||
345
4/4
✓ Branch 0 taken 10171 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 10162 times.
✓ Branch 3 taken 9 times.
10172 s->codec_id == AV_CODEC_ID_VP5 || s->codec_id == AV_CODEC_ID_VP6 ||
346
4/4
✓ Branch 0 taken 10160 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 10158 times.
10162 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 676 *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 676 *width = FFMAX(*width, 32);
357 }
358
2/2
✓ Branch 0 taken 2618 times.
✓ Branch 1 taken 8216 times.
10834 if (s->codec_id == AV_CODEC_ID_SVQ3) {
359 2618 *width = FFMAX(*width, 32);
360 }
361
362
2/2
✓ Branch 0 taken 43336 times.
✓ Branch 1 taken 10834 times.
54170 for (i = 0; i < 4; i++)
363 43336 linesize_align[i] = STRIDE_ALIGN;
364 10834 }
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 206952 int avpriv_codec_get_cap_skip_frame_fill_param(const AVCodec *codec){
418 206952 return !!(ffcodec(codec)->caps_internal & FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM);
419 }
420
421 31632 const char *avcodec_get_name(enum AVCodecID id)
422 {
423 const AVCodecDescriptor *cd;
424
425
2/2
✓ Branch 0 taken 289 times.
✓ Branch 1 taken 31343 times.
31632 if (id == AV_CODEC_ID_NONE)
426 289 return "none";
427 31343 cd = avcodec_descriptor_get(id);
428
2/2
✓ Branch 0 taken 31339 times.
✓ Branch 1 taken 4 times.
31343 if (cd)
429 31339 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 18647 const char *avcodec_profile_name(enum AVCodecID codec_id, int profile)
447 {
448 18647 const AVCodecDescriptor *desc = avcodec_descriptor_get(codec_id);
449 const AVProfile *p;
450
451
5/6
✓ Branch 0 taken 2662 times.
✓ Branch 1 taken 15985 times.
✓ Branch 2 taken 2662 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 166 times.
✓ Branch 5 taken 2496 times.
18647 if (profile == AV_PROFILE_UNKNOWN || !desc || !desc->profiles)
452 16151 return NULL;
453
454
2/2
✓ Branch 0 taken 6367 times.
✓ Branch 1 taken 34 times.
6401 for (p = desc->profiles; p->profile != AV_PROFILE_UNKNOWN; p++)
455
2/2
✓ Branch 0 taken 2462 times.
✓ Branch 1 taken 3905 times.
6367 if (p->profile == profile)
456 2462 return p->name;
457
458 34 return NULL;
459 }
460
461 937404 int av_get_exact_bits_per_sample(enum AVCodecID codec_id)
462 {
463
8/8
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 11241 times.
✓ Branch 2 taken 6971 times.
✓ Branch 3 taken 588888 times.
✓ Branch 4 taken 18119 times.
✓ Branch 5 taken 24386 times.
✓ Branch 6 taken 10696 times.
✓ Branch 7 taken 277079 times.
937404 switch (codec_id) {
464 24 case AV_CODEC_ID_DFPWM:
465 24 return 1;
466 11241 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 case AV_CODEC_ID_ADPCM_RHETOREX:
483 11241 return 4;
484 6971 case AV_CODEC_ID_DSD_LSBF:
485 case AV_CODEC_ID_DSD_MSBF:
486 case AV_CODEC_ID_DSD_LSBF_PLANAR:
487 case AV_CODEC_ID_DSD_MSBF_PLANAR:
488 case AV_CODEC_ID_PCM_ALAW:
489 case AV_CODEC_ID_PCM_MULAW:
490 case AV_CODEC_ID_PCM_VIDC:
491 case AV_CODEC_ID_PCM_S8:
492 case AV_CODEC_ID_PCM_S8_PLANAR:
493 case AV_CODEC_ID_PCM_SGA:
494 case AV_CODEC_ID_PCM_U8:
495 case AV_CODEC_ID_SDX2_DPCM:
496 case AV_CODEC_ID_CBD2_DPCM:
497 case AV_CODEC_ID_DERF_DPCM:
498 case AV_CODEC_ID_WADY_DPCM:
499 case AV_CODEC_ID_ADPCM_CIRCUS:
500 6971 return 8;
501 588888 case AV_CODEC_ID_PCM_S16BE:
502 case AV_CODEC_ID_PCM_S16BE_PLANAR:
503 case AV_CODEC_ID_PCM_S16LE:
504 case AV_CODEC_ID_PCM_S16LE_PLANAR:
505 case AV_CODEC_ID_PCM_U16BE:
506 case AV_CODEC_ID_PCM_U16LE:
507 588888 return 16;
508 18119 case AV_CODEC_ID_PCM_S24DAUD:
509 case AV_CODEC_ID_PCM_S24BE:
510 case AV_CODEC_ID_PCM_S24LE:
511 case AV_CODEC_ID_PCM_S24LE_PLANAR:
512 case AV_CODEC_ID_PCM_U24BE:
513 case AV_CODEC_ID_PCM_U24LE:
514 18119 return 24;
515 24386 case AV_CODEC_ID_PCM_S32BE:
516 case AV_CODEC_ID_PCM_S32LE:
517 case AV_CODEC_ID_PCM_S32LE_PLANAR:
518 case AV_CODEC_ID_PCM_U32BE:
519 case AV_CODEC_ID_PCM_U32LE:
520 case AV_CODEC_ID_PCM_F32BE:
521 case AV_CODEC_ID_PCM_F32LE:
522 case AV_CODEC_ID_PCM_F24LE:
523 case AV_CODEC_ID_PCM_F16LE:
524 24386 return 32;
525 10696 case AV_CODEC_ID_PCM_F64BE:
526 case AV_CODEC_ID_PCM_F64LE:
527 case AV_CODEC_ID_PCM_S64BE:
528 case AV_CODEC_ID_PCM_S64LE:
529 10696 return 64;
530 277079 default:
531 277079 return 0;
532 }
533 }
534
535 34 enum AVCodecID av_get_pcm_codec(enum AVSampleFormat fmt, int be)
536 {
537 static const enum AVCodecID map[][2] = {
538 [AV_SAMPLE_FMT_U8 ] = { AV_CODEC_ID_PCM_U8, AV_CODEC_ID_PCM_U8 },
539 [AV_SAMPLE_FMT_S16 ] = { AV_CODEC_ID_PCM_S16LE, AV_CODEC_ID_PCM_S16BE },
540 [AV_SAMPLE_FMT_S32 ] = { AV_CODEC_ID_PCM_S32LE, AV_CODEC_ID_PCM_S32BE },
541 [AV_SAMPLE_FMT_FLT ] = { AV_CODEC_ID_PCM_F32LE, AV_CODEC_ID_PCM_F32BE },
542 [AV_SAMPLE_FMT_DBL ] = { AV_CODEC_ID_PCM_F64LE, AV_CODEC_ID_PCM_F64BE },
543 [AV_SAMPLE_FMT_U8P ] = { AV_CODEC_ID_PCM_U8, AV_CODEC_ID_PCM_U8 },
544 [AV_SAMPLE_FMT_S16P] = { AV_CODEC_ID_PCM_S16LE, AV_CODEC_ID_PCM_S16BE },
545 [AV_SAMPLE_FMT_S32P] = { AV_CODEC_ID_PCM_S32LE, AV_CODEC_ID_PCM_S32BE },
546 [AV_SAMPLE_FMT_S64P] = { AV_CODEC_ID_PCM_S64LE, AV_CODEC_ID_PCM_S64BE },
547 [AV_SAMPLE_FMT_FLTP] = { AV_CODEC_ID_PCM_F32LE, AV_CODEC_ID_PCM_F32BE },
548 [AV_SAMPLE_FMT_DBLP] = { AV_CODEC_ID_PCM_F64LE, AV_CODEC_ID_PCM_F64BE },
549 };
550
2/4
✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 34 times.
34 if (fmt < 0 || fmt >= FF_ARRAY_ELEMS(map))
551 ✗ return AV_CODEC_ID_NONE;
552
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 34 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
34 if (be < 0 || be > 1)
553 34 be = AV_NE(1, 0);
554 34 return map[fmt][be];
555 }
556
557 298793 int av_get_bits_per_sample(enum AVCodecID codec_id)
558 {
559
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 298678 times.
298793 switch (codec_id) {
560 17 case AV_CODEC_ID_DFPWM:
561 17 return 1;
562 5 case AV_CODEC_ID_ADPCM_SBPRO_2:
563 case AV_CODEC_ID_G728:
564 5 return 2;
565 3 case AV_CODEC_ID_ADPCM_SBPRO_3:
566 3 return 3;
567 90 case AV_CODEC_ID_ADPCM_SBPRO_4:
568 case AV_CODEC_ID_ADPCM_IMA_WAV:
569 case AV_CODEC_ID_ADPCM_IMA_XBOX:
570 case AV_CODEC_ID_ADPCM_IMA_QT:
571 case AV_CODEC_ID_ADPCM_SWF:
572 case AV_CODEC_ID_ADPCM_MS:
573 90 return 4;
574 298678 default:
575 298678 return av_get_exact_bits_per_sample(codec_id);
576 }
577 }
578
579 628870 static int get_audio_frame_duration(enum AVCodecID id, int sr, int ch, int ba,
580 uint32_t tag, int bits_per_coded_sample, int64_t bitrate,
581 uint8_t * extradata, int frame_size, int frame_bytes)
582 {
583 628870 int bps = av_get_exact_bits_per_sample(id);
584
4/4
✓ Branch 0 taken 417492 times.
✓ Branch 1 taken 211378 times.
✓ Branch 2 taken 417187 times.
✓ Branch 3 taken 305 times.
628870 int framecount = (ba > 0 && frame_bytes / ba > 0) ? frame_bytes / ba : 1;
585
586 /* codecs with an exact constant bits per sample */
587
7/10
✓ Branch 0 taken 364306 times.
✓ Branch 1 taken 264564 times.
✓ Branch 2 taken 364306 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 364270 times.
✓ Branch 5 taken 36 times.
✓ Branch 6 taken 364270 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 364270 times.
✗ Branch 9 not taken.
628870 if (bps > 0 && ch > 0 && frame_bytes > 0 && ch < 32768 && bps < 32768)
588 364270 return (frame_bytes * 8LL) / (bps * ch);
589 264600 bps = bits_per_coded_sample;
590
591 /* codecs with a fixed packet duration */
592
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 4331 times.
✓ Branch 8 taken 2184 times.
✓ Branch 9 taken 20676 times.
✓ Branch 10 taken 2669 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 198063 times.
264600 switch (id) {
593 12407 case AV_CODEC_ID_ADPCM_ADX: return 32;
594 8274 case AV_CODEC_ID_ADPCM_IMA_QT: return 64;
595 600 case AV_CODEC_ID_ADPCM_EA_XAS: return 128;
596 5684 case AV_CODEC_ID_AMR_NB:
597 case AV_CODEC_ID_EVRC:
598 case AV_CODEC_ID_GSM:
599 case AV_CODEC_ID_QCELP:
600 5684 case AV_CODEC_ID_RA_288: return 160;
601 1124 case AV_CODEC_ID_AMR_WB:
602 1124 case AV_CODEC_ID_GSM_MS: return 320;
603 ✗ case AV_CODEC_ID_MP1: return 384;
604 8588 case AV_CODEC_ID_ATRAC1: return 512;
605 4331 case AV_CODEC_ID_ATRAC9:
606 case AV_CODEC_ID_ATRAC3:
607
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4331 times.
4331 if (framecount > INT_MAX/1024)
608 ✗ return 0;
609 4331 return 1024 * framecount;
610 2184 case AV_CODEC_ID_ATRAC3P: return 2048;
611 20676 case AV_CODEC_ID_MP2:
612 20676 case AV_CODEC_ID_MUSEPACK7: return 1152;
613 2669 case AV_CODEC_ID_AC3: return 1536;
614 ✗ case AV_CODEC_ID_FTR: return 1024;
615 }
616
617
2/2
✓ Branch 0 taken 194498 times.
✓ Branch 1 taken 3565 times.
198063 if (sr > 0) {
618 /* calc from sample rate */
619
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 194481 times.
194498 if (id == AV_CODEC_ID_TTA)
620 17 return 256ll * sr / 245;
621
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 194481 times.
194481 else if (id == AV_CODEC_ID_DST)
622 ✗ return 588ll * sr / 44100;
623
2/2
✓ Branch 0 taken 73 times.
✓ Branch 1 taken 194408 times.
194481 else if (id == AV_CODEC_ID_BINKAUDIO_DCT) {
624
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 73 times.
73 if (sr / 22050 > 22)
625 ✗ return 0;
626 73 return (480 << (sr / 22050));
627 }
628
629
2/2
✓ Branch 0 taken 13635 times.
✓ Branch 1 taken 180773 times.
194408 if (id == AV_CODEC_ID_MP3)
630
2/2
✓ Branch 0 taken 232 times.
✓ Branch 1 taken 13403 times.
13635 return sr <= 24000 ? 576 : 1152;
631 }
632
633
2/2
✓ Branch 0 taken 42591 times.
✓ Branch 1 taken 141747 times.
184338 if (ba > 0) {
634 /* calc from block_align */
635
2/2
✓ Branch 0 taken 7255 times.
✓ Branch 1 taken 35336 times.
42591 if (id == AV_CODEC_ID_SIPR) {
636
4/5
✓ Branch 0 taken 3256 times.
✓ Branch 1 taken 1983 times.
✓ Branch 2 taken 1680 times.
✓ Branch 3 taken 336 times.
✗ Branch 4 not taken.
7255 switch (ba) {
637 3256 case 20: return 160;
638 1983 case 19: return 144;
639 1680 case 29: return 288;
640 336 case 37: return 480;
641 }
642
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35336 times.
35336 } else if (id == AV_CODEC_ID_ILBC) {
643 ✗ switch (ba) {
644 ✗ case 38: return 160;
645 ✗ case 50: return 240;
646 }
647 }
648 }
649
650
2/2
✓ Branch 0 taken 173431 times.
✓ Branch 1 taken 3652 times.
177083 if (frame_bytes > 0) {
651 /* calc from frame_bytes only */
652 173431 int64_t d = INT64_MIN;
653
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 169273 times.
173431 switch(id) {
654 721 case AV_CODEC_ID_TRUESPEECH : d = 240LL * (frame_bytes / 32); break;
655 2074 case AV_CODEC_ID_NELLYMOSER : d = 256LL * (frame_bytes / 64); break;
656 1057 case AV_CODEC_ID_RA_144 : d = 160LL * (frame_bytes / 20); break;
657 153 case AV_CODEC_ID_APTX : d = 4LL * (frame_bytes / 4); break;
658 153 case AV_CODEC_ID_APTX_HD : d = 4LL * (frame_bytes / 6); break;
659 }
660
2/2
✓ Branch 0 taken 4158 times.
✓ Branch 1 taken 169273 times.
173431 if (d > INT64_MIN)
661
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;
662
663
2/2
✓ Branch 0 taken 50756 times.
✓ Branch 1 taken 118517 times.
169273 if (bps > 0) {
664 /* calc from frame_bytes and bits_per_coded_sample */
665
4/4
✓ Branch 0 taken 50296 times.
✓ Branch 1 taken 460 times.
✓ Branch 2 taken 48 times.
✓ Branch 3 taken 50248 times.
50756 if (id == AV_CODEC_ID_ADPCM_G726 || id == AV_CODEC_ID_ADPCM_G726LE)
666 508 return frame_bytes * 8 / bps;
667 }
668
669
3/4
✓ Branch 0 taken 168599 times.
✓ Branch 1 taken 166 times.
✓ Branch 2 taken 168599 times.
✗ Branch 3 not taken.
168765 if (ch > 0 && ch < INT_MAX/16) {
670 /* calc from frame_bytes and channels */
671
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 159583 times.
168599 switch (id) {
672 ✗ case AV_CODEC_ID_FASTAUDIO:
673 ✗ return frame_bytes / (40 * ch) * 256;
674 ✗ case AV_CODEC_ID_ADPCM_IMA_MOFLEX:
675 ✗ return (frame_bytes - 4 * ch) / (128 * ch) * 256;
676 48 case AV_CODEC_ID_ADPCM_AFC:
677 48 return frame_bytes / (9 * ch) * 16;
678 ✗ case AV_CODEC_ID_ADPCM_N64:
679 ✗ frame_bytes /= 9 * ch;
680 ✗ if (frame_bytes > INT_MAX / 16)
681 ✗ return 0;
682 ✗ return frame_bytes * 16;
683 33 case AV_CODEC_ID_ADPCM_PSX:
684 case AV_CODEC_ID_ADPCM_DTK:
685 33 frame_bytes /= 16 * ch;
686
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
33 if (frame_bytes > INT_MAX / 28)
687 ✗ return 0;
688 33 return frame_bytes * 28;
689 ✗ case AV_CODEC_ID_ADPCM_PSXC:
690 ✗ frame_bytes = (frame_bytes - 1) / ch;
691 ✗ if (frame_bytes > INT_MAX / 2)
692 ✗ return 0;
693 ✗ return frame_bytes * 2;
694 452 case AV_CODEC_ID_ADPCM_4XM:
695 case AV_CODEC_ID_ADPCM_IMA_ACORN:
696 case AV_CODEC_ID_ADPCM_IMA_DAT4:
697 case AV_CODEC_ID_ADPCM_IMA_ISS:
698 case AV_CODEC_ID_ADPCM_IMA_PDA:
699 452 return (frame_bytes - 4 * ch) * 2 / ch;
700 1951 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
701 1951 return (frame_bytes - 4) * 2 / ch;
702 ✗ case AV_CODEC_ID_ADPCM_IMA_AMV:
703 ✗ return (frame_bytes - 8) * 2;
704 3580 case AV_CODEC_ID_ADPCM_THP:
705 case AV_CODEC_ID_ADPCM_THP_LE:
706
2/2
✓ Branch 0 taken 3530 times.
✓ Branch 1 taken 50 times.
3580 if (extradata)
707 3530 return frame_bytes * 14LL / (8 * ch);
708 50 break;
709 222 case AV_CODEC_ID_ADPCM_XA:
710 222 return (frame_bytes / 128) * 224 / ch;
711 327 case AV_CODEC_ID_INTERPLAY_DPCM:
712 327 return (frame_bytes - 6 - ch) / ch;
713 680 case AV_CODEC_ID_ROQ_DPCM:
714 680 return (frame_bytes - 8) / ch;
715 112 case AV_CODEC_ID_XAN_DPCM:
716 112 return (frame_bytes - 2 * ch) / ch;
717 ✗ case AV_CODEC_ID_MACE3:
718 ✗ return 3 * frame_bytes / ch;
719 300 case AV_CODEC_ID_MACE6:
720 300 return 6 * frame_bytes / ch;
721 ✗ case AV_CODEC_ID_PCM_LXF:
722 ✗ return 2 * (frame_bytes / (5 * ch));
723 1311 case AV_CODEC_ID_IAC:
724 case AV_CODEC_ID_IMC:
725 1311 return 4 * frame_bytes / ch;
726 }
727
728
2/2
✓ Branch 0 taken 38682 times.
✓ Branch 1 taken 120951 times.
159633 if (tag) {
729 /* calc from frame_bytes, channels, and codec_tag */
730
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 38608 times.
38682 if (id == AV_CODEC_ID_SOL_DPCM) {
731
1/2
✓ Branch 0 taken 74 times.
✗ Branch 1 not taken.
74 if (tag == 3)
732 74 return frame_bytes / ch;
733 else
734 ✗ return frame_bytes * 2 / ch;
735 }
736 }
737
738
2/2
✓ Branch 0 taken 30872 times.
✓ Branch 1 taken 128687 times.
159559 if (ba > 0) {
739 /* calc from frame_bytes, channels, and block_align */
740 30872 int blocks = frame_bytes / ba;
741 30872 int64_t tmp = 0;
742
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 25879 times.
30872 switch (id) {
743 273 case AV_CODEC_ID_ADPCM_IMA_XBOX:
744
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 273 times.
273 if (bps != 4)
745 ✗ return 0;
746 273 tmp = blocks * ((ba - 4 * ch) / (bps * ch) * 8);
747 273 break;
748 1191 case AV_CODEC_ID_ADPCM_IMA_WAV:
749
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)
750 ✗ return 0;
751 1191 tmp = blocks * (1LL + (ba - 4 * ch) / (bps * ch) * 8LL);
752 1191 break;
753 669 case AV_CODEC_ID_ADPCM_IMA_DK3:
754 669 tmp = blocks * (((ba - 16LL) * 2 / 3 * 4) / ch);
755 669 break;
756 649 case AV_CODEC_ID_ADPCM_IMA_DK4:
757 649 tmp = blocks * (1 + (ba - 4LL * ch) * 2 / ch);
758 649 break;
759 1001 case AV_CODEC_ID_ADPCM_IMA_RAD:
760 1001 tmp = blocks * ((ba - 4LL * ch) * 2 / ch);
761 1001 break;
762 1210 case AV_CODEC_ID_ADPCM_MS:
763 1210 tmp = blocks * (2 + (ba - 7LL * ch) * 2LL / ch);
764 1210 break;
765 ✗ case AV_CODEC_ID_ADPCM_MTAF:
766 ✗ tmp = blocks * (ba - 16LL) * 2 / ch;
767 ✗ break;
768 ✗ case AV_CODEC_ID_ADPCM_XMD:
769 ✗ tmp = blocks * 32;
770 ✗ break;
771 }
772
2/2
✓ Branch 0 taken 4993 times.
✓ Branch 1 taken 25879 times.
30872 if (tmp) {
773
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4993 times.
4993 if (tmp != (int)tmp)
774 ✗ return 0;
775 4993 return tmp;
776 }
777 }
778
779
2/2
✓ Branch 0 taken 41320 times.
✓ Branch 1 taken 113246 times.
154566 if (bps > 0) {
780 /* calc from frame_bytes, channels, and bits_per_coded_sample */
781
3/4
✓ Branch 0 taken 20793 times.
✓ Branch 1 taken 2794 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 17733 times.
41320 switch (id) {
782 20793 case AV_CODEC_ID_PCM_DVD:
783
2/4
✓ Branch 0 taken 20793 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 20793 times.
20793 if(bps<4 || frame_bytes<3)
784 ✗ return 0;
785 20793 return 2 * ((frame_bytes - 3) / ((bps * 2 / 8) * ch));
786 2794 case AV_CODEC_ID_PCM_BLURAY:
787
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)
788 ✗ return 0;
789 2794 return (frame_bytes - 4) / ((FFALIGN(ch, 2) * bps) / 8);
790 ✗ case AV_CODEC_ID_S302M:
791 ✗ return 2 * (frame_bytes / ((bps + 4) / 4)) / ch;
792 }
793 }
794 }
795 }
796
797 /* Fall back on using frame_size */
798
4/4
✓ Branch 0 taken 89783 times.
✓ Branch 1 taken 45014 times.
✓ Branch 2 taken 89569 times.
✓ Branch 3 taken 214 times.
134797 if (frame_size > 1 && frame_bytes)
799 89569 return frame_size;
800
801 //For WMA we currently have no other means to calculate duration thus we
802 //do it here by assuming CBR, which is true for all known cases.
803
8/8
✓ Branch 0 taken 30239 times.
✓ Branch 1 taken 14989 times.
✓ Branch 2 taken 26605 times.
✓ Branch 3 taken 3634 times.
✓ Branch 4 taken 26556 times.
✓ Branch 5 taken 49 times.
✓ Branch 6 taken 9861 times.
✓ Branch 7 taken 16695 times.
45228 if (bitrate > 0 && frame_bytes > 0 && sr > 0 && ba > 1) {
804
4/4
✓ Branch 0 taken 9589 times.
✓ Branch 1 taken 272 times.
✓ Branch 2 taken 798 times.
✓ Branch 3 taken 8791 times.
9861 if (id == AV_CODEC_ID_WMAV1 || id == AV_CODEC_ID_WMAV2)
805 1070 return (frame_bytes * 8LL * sr) / bitrate;
806 }
807
808 44158 return 0;
809 }
810
811 47128 int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
812 {
813 47128 int channels = avctx->ch_layout.nb_channels;
814 int duration;
815
816 47128 duration = get_audio_frame_duration(avctx->codec_id, avctx->sample_rate,
817 channels, avctx->block_align,
818 avctx->codec_tag, avctx->bits_per_coded_sample,
819 avctx->bit_rate, avctx->extradata, avctx->frame_size,
820 frame_bytes);
821 47128 return FFMAX(0, duration);
822 }
823
824 581742 int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
825 {
826 581742 int channels = par->ch_layout.nb_channels;
827 int duration;
828
829 581742 duration = get_audio_frame_duration(par->codec_id, par->sample_rate,
830 channels, par->block_align,
831 par->codec_tag, par->bits_per_coded_sample,
832 par->bit_rate, par->extradata, par->frame_size,
833 frame_bytes);
834 581742 return FFMAX(0, duration);
835 }
836
837 70 unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
838 {
839 70 unsigned int n = 0;
840
841
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 70 times.
70 while (v >= 0xff) {
842 ✗ *s++ = 0xff;
843 ✗ v -= 0xff;
844 ✗ n++;
845 }
846 70 *s = v;
847 70 n++;
848 70 return n;
849 }
850
851 476 int ff_match_2uint16(const uint16_t(*tab)[2], int size, int a, int b)
852 {
853 int i;
854
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++) ;
855 476 return i;
856 }
857
858 17359 const AVCodecHWConfig *avcodec_get_hw_config(const AVCodec *avcodec, int index)
859 {
860 17359 const FFCodec *const codec = ffcodec(avcodec);
861 int i;
862
3/4
✓ Branch 0 taken 2805 times.
✓ Branch 1 taken 14554 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2805 times.
17359 if (!codec->hw_configs || index < 0)
863 14554 return NULL;
864
2/2
✓ Branch 0 taken 5440 times.
✓ Branch 1 taken 1796 times.
7236 for (i = 0; i <= index; i++)
865
2/2
✓ Branch 0 taken 1009 times.
✓ Branch 1 taken 4431 times.
5440 if (!codec->hw_configs[i])
866 1009 return NULL;
867 1796 return &codec->hw_configs[index]->public;
868 }
869
870 28477 int ff_thread_ref_frame(ThreadFrame *dst, const ThreadFrame *src)
871 {
872 int ret;
873
874 28477 dst->owner[0] = src->owner[0];
875 28477 dst->owner[1] = src->owner[1];
876
877 28477 ret = av_frame_ref(dst->f, src->f);
878
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28477 times.
28477 if (ret < 0)
879 ✗ return ret;
880
881
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28477 times.
28477 av_assert0(!dst->progress);
882
883
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 28417 times.
28477 if (src->progress)
884 60 dst->progress = av_refstruct_ref(src->progress);
885
886 28477 return 0;
887 }
888
889 298 int ff_thread_replace_frame(ThreadFrame *dst, const ThreadFrame *src)
890 {
891 int ret;
892
893 298 dst->owner[0] = src->owner[0];
894 298 dst->owner[1] = src->owner[1];
895
896 298 ret = av_frame_replace(dst->f, src->f);
897
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 298 times.
298 if (ret < 0)
898 ✗ return ret;
899
900 298 av_refstruct_replace(&dst->progress, src->progress);
901
902 298 return 0;
903 }
904
905 #if !HAVE_THREADS
906
907 int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f, int flags)
908 {
909 return ff_get_buffer(avctx, f, flags);
910 }
911
912 int ff_thread_get_ext_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
913 {
914 f->owner[0] = f->owner[1] = avctx;
915 return ff_get_buffer(avctx, f->f, flags);
916 }
917
918 void ff_thread_release_ext_buffer(ThreadFrame *f)
919 {
920 f->owner[0] = f->owner[1] = NULL;
921 if (f->f)
922 av_frame_unref(f->f);
923 }
924
925 void ff_thread_finish_setup(AVCodecContext *avctx)
926 {
927 }
928
929 void ff_thread_report_progress(ThreadFrame *f, int progress, int field)
930 {
931 }
932
933 void ff_thread_await_progress(const ThreadFrame *f, int progress, int field)
934 {
935 }
936
937 int ff_thread_can_start_frame(AVCodecContext *avctx)
938 {
939 return 1;
940 }
941 #endif
942
943 708921 const uint8_t *avpriv_find_start_code(const uint8_t *restrict p,
944 const uint8_t *end,
945 uint32_t *restrict state)
946 {
947 int i;
948
949
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 708921 times.
708921 av_assert0(p <= end);
950
2/2
✓ Branch 0 taken 932 times.
✓ Branch 1 taken 707989 times.
708921 if (p >= end)
951 932 return end;
952
953
2/2
✓ Branch 0 taken 2118345 times.
✓ Branch 1 taken 703841 times.
2822186 for (i = 0; i < 3; i++) {
954 2118345 uint32_t tmp = *state << 8;
955 2118345 *state = tmp + *(p++);
956
4/4
✓ Branch 0 taken 2117263 times.
✓ Branch 1 taken 1082 times.
✓ Branch 2 taken 3066 times.
✓ Branch 3 taken 2114197 times.
2118345 if (tmp == 0x100 || p == end)
957 4148 return p;
958 }
959
960
2/2
✓ Branch 0 taken 499058308 times.
✓ Branch 1 taken 71882 times.
499130190 while (p < end) {
961
2/2
✓ Branch 0 taken 457349828 times.
✓ Branch 1 taken 41708480 times.
499058308 if (p[-1] > 1 ) p += 3;
962
2/2
✓ Branch 0 taken 19514691 times.
✓ Branch 1 taken 22193789 times.
41708480 else if (p[-2] ) p += 2;
963
2/2
✓ Branch 0 taken 21561830 times.
✓ Branch 1 taken 631959 times.
22193789 else if (p[-3]|(p[-1]-1)) p++;
964 else {
965 631959 p++;
966 631959 break;
967 }
968 }
969
970
2/2
✓ Branch 0 taken 44990 times.
✓ Branch 1 taken 658851 times.
703841 p = FFMIN(p, end) - 4;
971 703841 *state = AV_RB32(p);
972
973 703841 return p + 4;
974 }
975
976 479 AVCPBProperties *av_cpb_properties_alloc(size_t *size)
977 {
978 479 AVCPBProperties *props = av_mallocz(sizeof(AVCPBProperties));
979
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 479 times.
479 if (!props)
980 ✗ return NULL;
981
982
1/2
✓ Branch 0 taken 479 times.
✗ Branch 1 not taken.
479 if (size)
983 479 *size = sizeof(*props);
984
985 479 props->vbv_delay = UINT64_MAX;
986
987 479 return props;
988 }
989
990 ✗ static void put_timecode_fields(PutBitContext *pb, AVRational rate, uint32_t tc)
991 {
992 unsigned hours, minutes, seconds, frames, drop;
993
994 ✗ ff_timecode_set_smpte(&drop, &hours, &minutes, &seconds, &frames, rate, tc, 0, 0);
995
996 ✗ put_bits(pb, 5, 0); // counting_type
997 ✗ put_bits(pb, 1, 1); // full_timestamp_flag
998 ✗ put_bits(pb, 1, 0); // discontinuity_flag
999 ✗ put_bits(pb, 1, drop); // cnt_dropped_flag
1000 ✗ put_bits(pb, 9, frames);
1001 ✗ put_bits(pb, 6, seconds);
1002 ✗ put_bits(pb, 6, minutes);
1003 ✗ put_bits(pb, 5, hours);
1004 ✗ }
1005
1006 ✗ int ff_alloc_timecode_sei(const AVFrame *frame, AVRational rate, size_t prefix_len,
1007 void **data, size_t *sei_size)
1008 {
1009 ✗ AVFrameSideData *sd = NULL;
1010 uint8_t *sei_data;
1011 PutBitContext pb;
1012 uint32_t *tc;
1013 int m;
1014
1015 ✗ if (frame)
1016 ✗ sd = av_frame_get_side_data(frame, AV_FRAME_DATA_S12M_TIMECODE);
1017
1018 ✗ if (!sd) {
1019 ✗ *data = NULL;
1020 ✗ return 0;
1021 }
1022 ✗ tc = (uint32_t*)sd->data;
1023 ✗ m = tc[0] & 3;
1024
1025 ✗ *sei_size = sizeof(uint32_t) * 4;
1026 ✗ *data = av_mallocz(*sei_size + prefix_len);
1027 ✗ if (!*data)
1028 ✗ return AVERROR(ENOMEM);
1029 ✗ sei_data = (uint8_t*)*data + prefix_len;
1030
1031 ✗ init_put_bits(&pb, sei_data, *sei_size);
1032 ✗ put_bits(&pb, 2, m); // num_clock_ts
1033
1034 ✗ for (int j = 1; j <= m; j++) {
1035 ✗ put_bits(&pb, 1, 1); // clock_timestamp_flag
1036 ✗ put_bits(&pb, 1, 1); // units_field_based_flag
1037 ✗ put_timecode_fields(&pb, rate, tc[j]);
1038 ✗ put_bits(&pb, 5, 0); // time_offset_length
1039 }
1040 ✗ flush_put_bits(&pb);
1041
1042 ✗ return 0;
1043 }
1044
1045 ✗ int ff_alloc_timecode_metadata_av1(const AVFrame *frame, AVRational rate,
1046 void **data, size_t *size)
1047 {
1048 ✗ AVFrameSideData *sd = NULL;
1049 PutBitContext pb;
1050 uint32_t *tc;
1051
1052 ✗ if (frame)
1053 ✗ sd = av_frame_get_side_data(frame, AV_FRAME_DATA_S12M_TIMECODE);
1054
1055 ✗ *data = NULL;
1056 ✗ if (!sd)
1057 ✗ return 0;
1058 ✗ tc = (uint32_t*)sd->data;
1059 ✗ if (!(tc[0] & 3)) // num_clock_ts
1060 ✗ return 0;
1061
1062 ✗ *size = 5;
1063 ✗ *data = av_mallocz(*size);
1064 ✗ if (!*data)
1065 ✗ return AVERROR(ENOMEM);
1066
1067 ✗ init_put_bits(&pb, *data, *size);
1068 ✗ put_timecode_fields(&pb, rate, tc[1]);
1069 ✗ put_bits(&pb, 5, 1); // time_offset_length
1070 ✗ put_bits(&pb, 1, 0); // time_offset_value
1071 ✗ flush_put_bits(&pb);
1072
1073 ✗ return 0;
1074 }
1075
1076 19745 int64_t ff_guess_coded_bitrate(AVCodecContext *avctx)
1077 {
1078 19745 AVRational framerate = avctx->framerate;
1079 19745 int bits_per_coded_sample = avctx->bits_per_coded_sample;
1080 int64_t bitrate;
1081
1082
3/4
✓ Branch 0 taken 19626 times.
✓ Branch 1 taken 119 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 19626 times.
19745 if (!(framerate.num && framerate.den))
1083 119 framerate = av_inv_q(avctx->time_base);
1084
2/4
✓ Branch 0 taken 19745 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 19745 times.
19745 if (!(framerate.num && framerate.den))
1085 ✗ return 0;
1086
1087
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19745 times.
19745 if (!bits_per_coded_sample) {
1088 ✗ const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
1089 ✗ bits_per_coded_sample = av_get_bits_per_pixel(desc);
1090 }
1091 19745 bitrate = (int64_t)bits_per_coded_sample * avctx->width * avctx->height *
1092 19745 framerate.num / framerate.den;
1093
1094 19745 return bitrate;
1095 }
1096