FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/utils.c
Date: 2026-10-15 08:01:34
Exec Total Coverage
Lines: 383 541 70.8%
Functions: 25 31 80.6%
Branches: 289 409 70.7%

Line Branch Exec Source
1 /*
2 * utils for libavcodec
3 * Copyright (c) 2001 Fabrice Bellard
4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 /**
24 * @file
25 * utils.
26 */
27
28 #include "config.h"
29 #include "libavutil/avassert.h"
30 #include "libavutil/channel_layout.h"
31 #include "libavutil/intreadwrite.h"
32 #include "libavutil/mem.h"
33 #include "libavutil/pixdesc.h"
34 #include "libavutil/imgutils.h"
35 #include "libavutil/pixfmt.h"
36 #include "libavutil/timecode_internal.h"
37 #include "avcodec.h"
38 #include "codec.h"
39 #include "codec_desc.h"
40 #include "codec_internal.h"
41 #include "codec_par.h"
42 #include "decode.h"
43 #include "hwconfig.h"
44 #include "libavutil/refstruct.h"
45 #include "thread.h"
46 #include "threadframe.h"
47 #include "internal.h"
48 #include "put_bits.h"
49 #include "startcode.h"
50 #include <stdlib.h>
51 #include <limits.h>
52
53 189427 void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
54 {
55 189427 uint8_t **p = ptr;
56
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 189427 times.
189427 if (min_size > SIZE_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
57 ✗ av_freep(p);
58 ✗ *size = 0;
59 ✗ return;
60 }
61 189427 av_fast_mallocz(p, size, min_size + AV_INPUT_BUFFER_PADDING_SIZE);
62
1/2
✓ Branch 0 taken 189427 times.
✗ Branch 1 not taken.
189427 if (*p)
63 189427 memset(*p + min_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
64 }
65
66 716 void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size)
67 {
68 716 uint8_t **p = ptr;
69
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 716 times.
716 if (min_size > SIZE_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
70 ✗ av_freep(p);
71 ✗ *size = 0;
72 ✗ return;
73 }
74 716 av_fast_malloc(p, size, min_size + AV_INPUT_BUFFER_PADDING_SIZE);
75
1/2
✓ Branch 0 taken 716 times.
✗ Branch 1 not taken.
716 if (*p)
76 716 memset(*p, 0, min_size + AV_INPUT_BUFFER_PADDING_SIZE);
77 }
78
79 2650295 int av_codec_is_encoder(const AVCodec *avcodec)
80 {
81 2650295 const FFCodec *const codec = ffcodec(avcodec);
82
4/4
✓ Branch 0 taken 2639231 times.
✓ Branch 1 taken 11064 times.
✓ Branch 2 taken 1673707 times.
✓ Branch 3 taken 965524 times.
2650295 return codec && !codec->is_decoder;
83 }
84
85 525133 int av_codec_is_decoder(const AVCodec *avcodec)
86 {
87 525133 const FFCodec *const codec = ffcodec(avcodec);
88
4/4
✓ Branch 0 taken 514069 times.
✓ Branch 1 taken 11064 times.
✓ Branch 2 taken 491314 times.
✓ Branch 3 taken 22755 times.
525133 return codec && codec->is_decoder;
89 }
90
91 63757 int ff_set_dimensions(AVCodecContext *s, int width, int height)
92 {
93 63757 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 63756 times.
63757 if (ret < 0)
96 1 width = height = 0;
97
98 63757 s->coded_width = width;
99 63757 s->coded_height = height;
100 63757 s->width = AV_CEIL_RSHIFT(width, s->lowres);
101 63757 s->height = AV_CEIL_RSHIFT(height, s->lowres);
102
103 63757 return ret;
104 }
105
106 3171 int ff_set_sar(AVCodecContext *avctx, AVRational sar)
107 {
108 3171 int ret = av_image_check_sar(avctx->width, avctx->height, sar);
109
110
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 3166 times.
3171 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 3166 avctx->sample_aspect_ratio = sar;
117 }
118 3166 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 10863 void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height,
142 int linesize_align[AV_NUM_DATA_POINTERS])
143 {
144 int i;
145 10863 int w_align = 1;
146 10863 int h_align = 1;
147 10863 AVPixFmtDescriptor const *desc = av_pix_fmt_desc_get(s->pix_fmt);
148
149
1/2
✓ Branch 0 taken 10863 times.
✗ Branch 1 not taken.
10863 if (desc) {
150 10863 w_align = 1 << desc->log2_chroma_w;
151 10863 h_align = 1 << desc->log2_chroma_h;
152 }
153
154
9/10
✓ Branch 0 taken 9824 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 228 times.
✓ Branch 7 taken 23 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 486 times.
10863 switch (s->pix_fmt) {
155 9824 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 9824 w_align = 16; //FIXME assume 16 pixel per macroblock
245 9824 h_align = 16 * 2; // interlaced needs 2 macroblocks height
246
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 9821 times.
9824 if (s->codec_id == AV_CODEC_ID_BINKVIDEO)
247 3 w_align = 16*2;
248 9824 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 228 case AV_PIX_FMT_RGB24:
307
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 221 times.
228 if (s->codec_id == AV_CODEC_ID_CINEPAK) {
308 7 w_align = 4;
309 7 h_align = 4;
310 }
311 228 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 486 default:
334 486 break;
335 }
336
337
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 10861 times.
10863 if (s->codec_id == AV_CODEC_ID_IFF_ILBM) {
338 2 w_align = FFMAX(w_align, 16);
339 }
340
341 10863 *width = FFALIGN(*width, w_align);
342 10863 *height = FFALIGN(*height, h_align);
343
4/4
✓ Branch 0 taken 10217 times.
✓ Branch 1 taken 646 times.
✓ Branch 2 taken 10216 times.
✓ Branch 3 taken 1 times.
10863 if (s->codec_id == AV_CODEC_ID_H264 || s->lowres ||
344
4/4
✓ Branch 0 taken 10201 times.
✓ Branch 1 taken 15 times.
✓ Branch 2 taken 10194 times.
✓ Branch 3 taken 7 times.
10216 s->codec_id == AV_CODEC_ID_VC1 || s->codec_id == AV_CODEC_ID_WMV3 ||
345
4/4
✓ Branch 0 taken 10193 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 10184 times.
✓ Branch 3 taken 9 times.
10194 s->codec_id == AV_CODEC_ID_VP5 || s->codec_id == AV_CODEC_ID_VP6 ||
346
4/4
✓ Branch 0 taken 10182 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 10180 times.
10184 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 683 *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 683 *width = FFMAX(*width, 32);
357 }
358
2/2
✓ Branch 0 taken 2618 times.
✓ Branch 1 taken 8245 times.
10863 if (s->codec_id == AV_CODEC_ID_SVQ3) {
359 2618 *width = FFMAX(*width, 32);
360 }
361
362
2/2
✓ Branch 0 taken 43452 times.
✓ Branch 1 taken 10863 times.
54315 for (i = 0; i < 4; i++)
363 43452 linesize_align[i] = STRIDE_ALIGN;
364 10863 }
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 210243 int avpriv_codec_get_cap_skip_frame_fill_param(const AVCodec *codec){
418 210243 return !!(ffcodec(codec)->caps_internal & FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM);
419 }
420
421 32168 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 31879 times.
32168 if (id == AV_CODEC_ID_NONE)
426 289 return "none";
427 31879 cd = avcodec_descriptor_get(id);
428
2/2
✓ Branch 0 taken 31875 times.
✓ Branch 1 taken 4 times.
31879 if (cd)
429 31875 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 18987 const char *avcodec_profile_name(enum AVCodecID codec_id, int profile)
447 {
448 18987 const AVCodecDescriptor *desc = avcodec_descriptor_get(codec_id);
449 const AVProfile *p;
450
451
5/6
✓ Branch 0 taken 2712 times.
✓ Branch 1 taken 16275 times.
✓ Branch 2 taken 2712 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 166 times.
✓ Branch 5 taken 2546 times.
18987 if (profile == AV_PROFILE_UNKNOWN || !desc || !desc->profiles)
452 16441 return NULL;
453
454
2/2
✓ Branch 0 taken 6465 times.
✓ Branch 1 taken 34 times.
6499 for (p = desc->profiles; p->profile != AV_PROFILE_UNKNOWN; p++)
455
2/2
✓ Branch 0 taken 2512 times.
✓ Branch 1 taken 3953 times.
6465 if (p->profile == profile)
456 2512 return p->name;
457
458 34 return NULL;
459 }
460
461 952470 int av_get_exact_bits_per_sample(enum AVCodecID codec_id)
462 {
463
8/8
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 11239 times.
✓ Branch 2 taken 6967 times.
✓ Branch 3 taken 592654 times.
✓ Branch 4 taken 18122 times.
✓ Branch 5 taken 24434 times.
✓ Branch 6 taken 10958 times.
✓ Branch 7 taken 288072 times.
952470 switch (codec_id) {
464 24 case AV_CODEC_ID_DFPWM:
465 24 return 1;
466 11239 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 11239 return 4;
484 6967 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 6967 return 8;
501 592654 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 592654 return 16;
508 18122 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 18122 return 24;
515 24434 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 24434 return 32;
525 10958 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 10958 return 64;
530 288072 default:
531 288072 return 0;
532 }
533 }
534
535 35 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 35 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 35 times.
35 if (fmt < 0 || fmt >= FF_ARRAY_ELEMS(map))
551 ✗ return AV_CODEC_ID_NONE;
552
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
35 if (be < 0 || be > 1)
553 35 be = AV_NE(1, 0);
554 35 return map[fmt][be];
555 }
556
557 301061 int av_get_bits_per_sample(enum AVCodecID codec_id)
558 {
559
5/5
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 90 times.
✓ Branch 4 taken 300942 times.
301061 switch (codec_id) {
560 17 case AV_CODEC_ID_DFPWM:
561 17 return 1;
562 9 case AV_CODEC_ID_ADPCM_IMA_CITRIX:
563 case AV_CODEC_ID_ADPCM_SBPRO_2:
564 case AV_CODEC_ID_G728:
565 9 return 2;
566 3 case AV_CODEC_ID_ADPCM_SBPRO_3:
567 3 return 3;
568 90 case AV_CODEC_ID_ADPCM_SBPRO_4:
569 case AV_CODEC_ID_ADPCM_IMA_WAV:
570 case AV_CODEC_ID_ADPCM_IMA_XBOX:
571 case AV_CODEC_ID_ADPCM_IMA_QT:
572 case AV_CODEC_ID_ADPCM_SWF:
573 case AV_CODEC_ID_ADPCM_MS:
574 90 return 4;
575 300942 default:
576 300942 return av_get_exact_bits_per_sample(codec_id);
577 }
578 }
579
580 641397 static int get_audio_frame_duration(enum AVCodecID id, int sr, int ch, int ba,
581 uint32_t tag, int bits_per_coded_sample, int64_t bitrate,
582 uint8_t * extradata, int frame_size, int frame_bytes)
583 {
584 641397 int bps = av_get_exact_bits_per_sample(id);
585
4/4
✓ Branch 0 taken 420052 times.
✓ Branch 1 taken 221345 times.
✓ Branch 2 taken 419747 times.
✓ Branch 3 taken 305 times.
641397 int framecount = (ba > 0 && frame_bytes / ba > 0) ? frame_bytes / ba : 1;
586
587 /* codecs with an exact constant bits per sample */
588
7/10
✓ Branch 0 taken 366671 times.
✓ Branch 1 taken 274726 times.
✓ Branch 2 taken 366671 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 366635 times.
✓ Branch 5 taken 36 times.
✓ Branch 6 taken 366635 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 366635 times.
✗ Branch 9 not taken.
641397 if (bps > 0 && ch > 0 && frame_bytes > 0 && ch < 32768 && bps < 32768)
589 366635 return (frame_bytes * 8LL) / (bps * ch);
590 274762 bps = bits_per_coded_sample;
591
592 /* codecs with a fixed packet duration */
593
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 4332 times.
✓ Branch 8 taken 2184 times.
✓ Branch 9 taken 26737 times.
✓ Branch 10 taken 2669 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 202163 times.
274762 switch (id) {
594 12407 case AV_CODEC_ID_ADPCM_ADX: return 32;
595 8274 case AV_CODEC_ID_ADPCM_IMA_QT: return 64;
596 600 case AV_CODEC_ID_ADPCM_EA_XAS: return 128;
597 5684 case AV_CODEC_ID_AMR_NB:
598 case AV_CODEC_ID_EVRC:
599 case AV_CODEC_ID_GSM:
600 case AV_CODEC_ID_QCELP:
601 5684 case AV_CODEC_ID_RA_288: return 160;
602 1124 case AV_CODEC_ID_AMR_WB:
603 1124 case AV_CODEC_ID_GSM_MS: return 320;
604 ✗ case AV_CODEC_ID_MP1: return 384;
605 8588 case AV_CODEC_ID_ATRAC1: return 512;
606 4332 case AV_CODEC_ID_ATRAC9:
607 case AV_CODEC_ID_ATRAC3:
608
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4332 times.
4332 if (framecount > INT_MAX/1024)
609 ✗ return 0;
610 4332 return 1024 * framecount;
611 2184 case AV_CODEC_ID_ATRAC3P: return 2048;
612 26737 case AV_CODEC_ID_MP2:
613 26737 case AV_CODEC_ID_MUSEPACK7: return 1152;
614 2669 case AV_CODEC_ID_AC3: return 1536;
615 ✗ case AV_CODEC_ID_FTR: return 1024;
616 }
617
618
2/2
✓ Branch 0 taken 198579 times.
✓ Branch 1 taken 3584 times.
202163 if (sr > 0) {
619 /* calc from sample rate */
620
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 198562 times.
198579 if (id == AV_CODEC_ID_TTA)
621 17 return 256ll * sr / 245;
622
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 198562 times.
198562 else if (id == AV_CODEC_ID_DST)
623 ✗ return 588ll * sr / 44100;
624
2/2
✓ Branch 0 taken 73 times.
✓ Branch 1 taken 198489 times.
198562 else if (id == AV_CODEC_ID_BINKAUDIO_DCT) {
625
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 73 times.
73 if (sr / 22050 > 22)
626 ✗ return 0;
627 73 return (480 << (sr / 22050));
628 }
629
630
2/2
✓ Branch 0 taken 14152 times.
✓ Branch 1 taken 184337 times.
198489 if (id == AV_CODEC_ID_MP3)
631
2/2
✓ Branch 0 taken 288 times.
✓ Branch 1 taken 13864 times.
14152 return sr <= 24000 ? 576 : 1152;
632 }
633
634
2/2
✓ Branch 0 taken 43041 times.
✓ Branch 1 taken 144880 times.
187921 if (ba > 0) {
635 /* calc from block_align */
636
2/2
✓ Branch 0 taken 7256 times.
✓ Branch 1 taken 35785 times.
43041 if (id == AV_CODEC_ID_SIPR) {
637
4/5
✓ Branch 0 taken 3257 times.
✓ Branch 1 taken 1983 times.
✓ Branch 2 taken 1680 times.
✓ Branch 3 taken 336 times.
✗ Branch 4 not taken.
7256 switch (ba) {
638 3257 case 20: return 160;
639 1983 case 19: return 144;
640 1680 case 29: return 288;
641 336 case 37: return 480;
642 }
643
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35785 times.
35785 } else if (id == AV_CODEC_ID_ILBC) {
644 ✗ switch (ba) {
645 ✗ case 38: return 160;
646 ✗ case 50: return 240;
647 }
648 }
649 }
650
651
2/2
✓ Branch 0 taken 177005 times.
✓ Branch 1 taken 3660 times.
180665 if (frame_bytes > 0) {
652 /* calc from frame_bytes only */
653 177005 int64_t d = INT64_MIN;
654
6/6
✓ Branch 0 taken 721 times.
✓ Branch 1 taken 2826 times.
✓ Branch 2 taken 1057 times.
✓ Branch 3 taken 153 times.
✓ Branch 4 taken 153 times.
✓ Branch 5 taken 172095 times.
177005 switch(id) {
655 721 case AV_CODEC_ID_TRUESPEECH : d = 240LL * (frame_bytes / 32); break;
656 2826 case AV_CODEC_ID_NELLYMOSER : d = 256LL * (frame_bytes / 64); break;
657 1057 case AV_CODEC_ID_RA_144 : d = 160LL * (frame_bytes / 20); break;
658 153 case AV_CODEC_ID_APTX : d = 4LL * (frame_bytes / 4); break;
659 153 case AV_CODEC_ID_APTX_HD : d = 4LL * (frame_bytes / 6); break;
660 }
661
2/2
✓ Branch 0 taken 4910 times.
✓ Branch 1 taken 172095 times.
177005 if (d > INT64_MIN)
662
2/4
✓ Branch 0 taken 4910 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4910 times.
✗ Branch 3 not taken.
4910 return ((int)d == d && d > 0) ? d : 0;
663
664
2/2
✓ Branch 0 taken 52158 times.
✓ Branch 1 taken 119937 times.
172095 if (bps > 0) {
665 /* calc from frame_bytes and bits_per_coded_sample */
666
4/4
✓ Branch 0 taken 51698 times.
✓ Branch 1 taken 460 times.
✓ Branch 2 taken 48 times.
✓ Branch 3 taken 51650 times.
52158 if (id == AV_CODEC_ID_ADPCM_G726 || id == AV_CODEC_ID_ADPCM_G726LE)
667 508 return frame_bytes * 8 / bps;
668 }
669
670
3/4
✓ Branch 0 taken 171410 times.
✓ Branch 1 taken 177 times.
✓ Branch 2 taken 171410 times.
✗ Branch 3 not taken.
171587 if (ch > 0 && ch < INT_MAX/16) {
671 /* calc from frame_bytes and channels */
672
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 2904 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 161441 times.
171410 switch (id) {
673 ✗ case AV_CODEC_ID_FASTAUDIO:
674 ✗ return frame_bytes / (40 * ch) * 256;
675 ✗ case AV_CODEC_ID_ADPCM_IMA_MOFLEX:
676 ✗ return (frame_bytes - 4 * ch) / (128 * ch) * 256;
677 48 case AV_CODEC_ID_ADPCM_AFC:
678 48 return frame_bytes / (9 * ch) * 16;
679 ✗ case AV_CODEC_ID_ADPCM_N64:
680 ✗ frame_bytes /= 9 * ch;
681 ✗ if (frame_bytes > INT_MAX / 16)
682 ✗ return 0;
683 ✗ return frame_bytes * 16;
684 33 case AV_CODEC_ID_ADPCM_PSX:
685 case AV_CODEC_ID_ADPCM_DTK:
686 33 frame_bytes /= 16 * ch;
687
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
33 if (frame_bytes > INT_MAX / 28)
688 ✗ return 0;
689 33 return frame_bytes * 28;
690 ✗ case AV_CODEC_ID_ADPCM_PSXC:
691 ✗ frame_bytes = (frame_bytes - 1) / ch;
692 ✗ if (frame_bytes > INT_MAX / 2)
693 ✗ return 0;
694 ✗ return frame_bytes * 2;
695 452 case AV_CODEC_ID_ADPCM_4XM:
696 case AV_CODEC_ID_ADPCM_IMA_ACORN:
697 case AV_CODEC_ID_ADPCM_IMA_DAT4:
698 case AV_CODEC_ID_ADPCM_IMA_ISS:
699 case AV_CODEC_ID_ADPCM_IMA_PDA:
700 452 return (frame_bytes - 4 * ch) * 2 / ch;
701 2904 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
702 2904 return (frame_bytes - 4) * 2 / ch;
703 ✗ case AV_CODEC_ID_ADPCM_IMA_AMV:
704 ✗ return (frame_bytes - 8) * 2;
705 3580 case AV_CODEC_ID_ADPCM_THP:
706 case AV_CODEC_ID_ADPCM_THP_LE:
707
2/2
✓ Branch 0 taken 3530 times.
✓ Branch 1 taken 50 times.
3580 if (extradata)
708 3530 return frame_bytes * 14LL / (8 * ch);
709 50 break;
710 222 case AV_CODEC_ID_ADPCM_XA:
711 222 return (frame_bytes / 128) * 224 / ch;
712 327 case AV_CODEC_ID_INTERPLAY_DPCM:
713 327 return (frame_bytes - 6 - ch) / ch;
714 680 case AV_CODEC_ID_ROQ_DPCM:
715 680 return (frame_bytes - 8) / ch;
716 112 case AV_CODEC_ID_XAN_DPCM:
717 112 return (frame_bytes - 2 * ch) / ch;
718 ✗ case AV_CODEC_ID_MACE3:
719 ✗ return 3 * frame_bytes / ch;
720 300 case AV_CODEC_ID_MACE6:
721 300 return 6 * frame_bytes / ch;
722 ✗ case AV_CODEC_ID_PCM_LXF:
723 ✗ return 2 * (frame_bytes / (5 * ch));
724 1311 case AV_CODEC_ID_IAC:
725 case AV_CODEC_ID_IMC:
726 1311 return 4 * frame_bytes / ch;
727 }
728
729
2/2
✓ Branch 0 taken 39968 times.
✓ Branch 1 taken 121523 times.
161491 if (tag) {
730 /* calc from frame_bytes, channels, and codec_tag */
731
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 39894 times.
39968 if (id == AV_CODEC_ID_SOL_DPCM) {
732
1/2
✓ Branch 0 taken 74 times.
✗ Branch 1 not taken.
74 if (tag == 3)
733 74 return frame_bytes / ch;
734 else
735 ✗ return frame_bytes * 2 / ch;
736 }
737 }
738
739
2/2
✓ Branch 0 taken 31321 times.
✓ Branch 1 taken 130096 times.
161417 if (ba > 0) {
740 /* calc from frame_bytes, channels, and block_align */
741 31321 int blocks = frame_bytes / ba;
742 31321 int64_t tmp = 0;
743
8/10
✓ 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 449 times.
✓ Branch 9 taken 25879 times.
31321 switch (id) {
744 273 case AV_CODEC_ID_ADPCM_IMA_XBOX:
745
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 273 times.
273 if (bps != 4)
746 ✗ return 0;
747 273 tmp = blocks * ((ba - 4 * ch) / (bps * ch) * 8);
748 273 break;
749 1191 case AV_CODEC_ID_ADPCM_IMA_WAV:
750
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)
751 ✗ return 0;
752 1191 tmp = blocks * (1LL + (ba - 4 * ch) / (bps * ch) * 8LL);
753 1191 break;
754 669 case AV_CODEC_ID_ADPCM_IMA_DK3:
755 669 tmp = blocks * (((ba - 16LL) * 2 / 3 * 4) / ch);
756 669 break;
757 649 case AV_CODEC_ID_ADPCM_IMA_DK4:
758 649 tmp = blocks * (1 + (ba - 4LL * ch) * 2 / ch);
759 649 break;
760 1001 case AV_CODEC_ID_ADPCM_IMA_RAD:
761 1001 tmp = blocks * ((ba - 4LL * ch) * 2 / ch);
762 1001 break;
763 1210 case AV_CODEC_ID_ADPCM_MS:
764 1210 tmp = blocks * (2 + (ba - 7LL * ch) * 2LL / ch);
765 1210 break;
766 ✗ case AV_CODEC_ID_ADPCM_MTAF:
767 ✗ tmp = blocks * (ba - 16LL) * 2 / ch;
768 ✗ break;
769 ✗ case AV_CODEC_ID_ADPCM_XMD:
770 ✗ tmp = blocks * 32;
771 ✗ break;
772 449 case AV_CODEC_ID_ADPCM_IMA_CITRIX:
773
6/10
✓ Branch 0 taken 449 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 449 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 449 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 407 times.
✓ Branch 7 taken 42 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 407 times.
449 if (bps != 2 || ch > 2 || ba < 4 * ch || (ch == 2 && ba % 8))
774 ✗ return 0;
775 449 tmp = blocks * (1LL + (ba / ch - 4) * 4LL);
776 449 break;
777 }
778
2/2
✓ Branch 0 taken 5442 times.
✓ Branch 1 taken 25879 times.
31321 if (tmp) {
779
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5442 times.
5442 if (tmp != (int)tmp)
780 ✗ return 0;
781 5442 return tmp;
782 }
783 }
784
785
2/2
✓ Branch 0 taken 41320 times.
✓ Branch 1 taken 114655 times.
155975 if (bps > 0) {
786 /* calc from frame_bytes, channels, and bits_per_coded_sample */
787
3/4
✓ Branch 0 taken 20792 times.
✓ Branch 1 taken 2794 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 17734 times.
41320 switch (id) {
788 20792 case AV_CODEC_ID_PCM_DVD:
789
2/4
✓ Branch 0 taken 20792 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 20792 times.
20792 if(bps<4 || frame_bytes<3)
790 ✗ return 0;
791 20792 return 2 * ((frame_bytes - 3) / ((bps * 2 / 8) * ch));
792 2794 case AV_CODEC_ID_PCM_BLURAY:
793
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)
794 ✗ return 0;
795 2794 return (frame_bytes - 4) / ((FFALIGN(ch, 2) * bps) / 8);
796 ✗ case AV_CODEC_ID_S302M:
797 ✗ return 2 * (frame_bytes / ((bps + 4) / 4)) / ch;
798 }
799 }
800 }
801 }
802
803 /* Fall back on using frame_size */
804
4/4
✓ Branch 0 taken 91177 times.
✓ Branch 1 taken 45049 times.
✓ Branch 2 taken 90963 times.
✓ Branch 3 taken 214 times.
136226 if (frame_size > 1 && frame_bytes)
805 90963 return frame_size;
806
807 //For WMA we currently have no other means to calculate duration thus we
808 //do it here by assuming CBR, which is true for all known cases.
809
8/8
✓ Branch 0 taken 30250 times.
✓ Branch 1 taken 15013 times.
✓ Branch 2 taken 26608 times.
✓ Branch 3 taken 3642 times.
✓ Branch 4 taken 26557 times.
✓ Branch 5 taken 51 times.
✓ Branch 6 taken 9861 times.
✓ Branch 7 taken 16696 times.
45263 if (bitrate > 0 && frame_bytes > 0 && sr > 0 && ba > 1) {
810
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)
811 1070 return (frame_bytes * 8LL * sr) / bitrate;
812 }
813
814 44193 return 0;
815 }
816
817 48666 int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
818 {
819 48666 int channels = avctx->ch_layout.nb_channels;
820 int duration;
821
822 48666 duration = get_audio_frame_duration(avctx->codec_id, avctx->sample_rate,
823 channels, avctx->block_align,
824 avctx->codec_tag, avctx->bits_per_coded_sample,
825 avctx->bit_rate, avctx->extradata, avctx->frame_size,
826 frame_bytes);
827 48666 return FFMAX(0, duration);
828 }
829
830 592731 int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
831 {
832 592731 int channels = par->ch_layout.nb_channels;
833 int duration;
834
835 592731 duration = get_audio_frame_duration(par->codec_id, par->sample_rate,
836 channels, par->block_align,
837 par->codec_tag, par->bits_per_coded_sample,
838 par->bit_rate, par->extradata, par->frame_size,
839 frame_bytes);
840 592731 return FFMAX(0, duration);
841 }
842
843 70 unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
844 {
845 70 unsigned int n = 0;
846
847
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 70 times.
70 while (v >= 0xff) {
848 ✗ *s++ = 0xff;
849 ✗ v -= 0xff;
850 ✗ n++;
851 }
852 70 *s = v;
853 70 n++;
854 70 return n;
855 }
856
857 476 int ff_match_2uint16(const uint16_t(*tab)[2], int size, int a, int b)
858 {
859 int i;
860
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++) ;
861 476 return i;
862 }
863
864 17553 const AVCodecHWConfig *avcodec_get_hw_config(const AVCodec *avcodec, int index)
865 {
866 17553 const FFCodec *const codec = ffcodec(avcodec);
867 int i;
868
3/4
✓ Branch 0 taken 2821 times.
✓ Branch 1 taken 14732 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2821 times.
17553 if (!codec->hw_configs || index < 0)
869 14732 return NULL;
870
2/2
✓ Branch 0 taken 5467 times.
✓ Branch 1 taken 1805 times.
7272 for (i = 0; i <= index; i++)
871
2/2
✓ Branch 0 taken 1016 times.
✓ Branch 1 taken 4451 times.
5467 if (!codec->hw_configs[i])
872 1016 return NULL;
873 1805 return &codec->hw_configs[index]->public;
874 }
875
876 28533 int ff_thread_ref_frame(ThreadFrame *dst, const ThreadFrame *src)
877 {
878 int ret;
879
880 28533 dst->owner[0] = src->owner[0];
881 28533 dst->owner[1] = src->owner[1];
882
883 28533 ret = av_frame_ref(dst->f, src->f);
884
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28533 times.
28533 if (ret < 0)
885 ✗ return ret;
886
887
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28533 times.
28533 av_assert0(!dst->progress);
888
889
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 28473 times.
28533 if (src->progress)
890 60 dst->progress = av_refstruct_ref(src->progress);
891
892 28533 return 0;
893 }
894
895 298 int ff_thread_replace_frame(ThreadFrame *dst, const ThreadFrame *src)
896 {
897 int ret;
898
899 298 dst->owner[0] = src->owner[0];
900 298 dst->owner[1] = src->owner[1];
901
902 298 ret = av_frame_replace(dst->f, src->f);
903
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 298 times.
298 if (ret < 0)
904 ✗ return ret;
905
906 298 av_refstruct_replace(&dst->progress, src->progress);
907
908 298 return 0;
909 }
910
911 #if !HAVE_THREADS
912
913 int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f, int flags)
914 {
915 return ff_get_buffer(avctx, f, flags);
916 }
917
918 int ff_thread_get_ext_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
919 {
920 f->owner[0] = f->owner[1] = avctx;
921 return ff_get_buffer(avctx, f->f, flags);
922 }
923
924 void ff_thread_release_ext_buffer(ThreadFrame *f)
925 {
926 f->owner[0] = f->owner[1] = NULL;
927 if (f->f)
928 av_frame_unref(f->f);
929 }
930
931 void ff_thread_finish_setup(AVCodecContext *avctx)
932 {
933 }
934
935 void ff_thread_report_progress(ThreadFrame *f, int progress, int field)
936 {
937 }
938
939 void ff_thread_await_progress(const ThreadFrame *f, int progress, int field)
940 {
941 }
942
943 int ff_thread_can_start_frame(AVCodecContext *avctx)
944 {
945 return 1;
946 }
947 #endif
948
949 709917 const uint8_t *avpriv_find_start_code(const uint8_t *restrict p,
950 const uint8_t *end,
951 uint32_t *restrict state)
952 {
953 int i;
954
955
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 709917 times.
709917 av_assert0(p <= end);
956
2/2
✓ Branch 0 taken 931 times.
✓ Branch 1 taken 708986 times.
709917 if (p >= end)
957 931 return end;
958
959
2/2
✓ Branch 0 taken 2121316 times.
✓ Branch 1 taken 704837 times.
2826153 for (i = 0; i < 3; i++) {
960 2121316 uint32_t tmp = *state << 8;
961 2121316 *state = tmp + *(p++);
962
4/4
✓ Branch 0 taken 2120225 times.
✓ Branch 1 taken 1091 times.
✓ Branch 2 taken 3058 times.
✓ Branch 3 taken 2117167 times.
2121316 if (tmp == 0x100 || p == end)
963 4149 return p;
964 }
965
966
2/2
✓ Branch 0 taken 519285158 times.
✓ Branch 1 taken 71922 times.
519357080 while (p < end) {
967
2/2
✓ Branch 0 taken 476328128 times.
✓ Branch 1 taken 42957030 times.
519285158 if (p[-1] > 1 ) p += 3;
968
2/2
✓ Branch 0 taken 20646927 times.
✓ Branch 1 taken 22310103 times.
42957030 else if (p[-2] ) p += 2;
969
2/2
✓ Branch 0 taken 21677188 times.
✓ Branch 1 taken 632915 times.
22310103 else if (p[-3]|(p[-1]-1)) p++;
970 else {
971 632915 p++;
972 632915 break;
973 }
974 }
975
976
2/2
✓ Branch 0 taken 45125 times.
✓ Branch 1 taken 659712 times.
704837 p = FFMIN(p, end) - 4;
977 704837 *state = AV_RB32(p);
978
979 704837 return p + 4;
980 }
981
982 487 AVCPBProperties *av_cpb_properties_alloc(size_t *size)
983 {
984 487 AVCPBProperties *props = av_mallocz(sizeof(AVCPBProperties));
985
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 487 times.
487 if (!props)
986 ✗ return NULL;
987
988
1/2
✓ Branch 0 taken 487 times.
✗ Branch 1 not taken.
487 if (size)
989 487 *size = sizeof(*props);
990
991 487 props->vbv_delay = UINT64_MAX;
992
993 487 return props;
994 }
995
996 ✗ static void put_timecode_fields(PutBitContext *pb, AVRational rate, uint32_t tc)
997 {
998 unsigned hours, minutes, seconds, frames, drop;
999
1000 ✗ ff_timecode_set_smpte(&drop, &hours, &minutes, &seconds, &frames, rate, tc, 0, 0);
1001
1002 ✗ put_bits(pb, 5, 0); // counting_type
1003 ✗ put_bits(pb, 1, 1); // full_timestamp_flag
1004 ✗ put_bits(pb, 1, 0); // discontinuity_flag
1005 ✗ put_bits(pb, 1, drop); // cnt_dropped_flag
1006 ✗ put_bits(pb, 9, frames);
1007 ✗ put_bits(pb, 6, seconds);
1008 ✗ put_bits(pb, 6, minutes);
1009 ✗ put_bits(pb, 5, hours);
1010 ✗ }
1011
1012 ✗ int ff_alloc_timecode_sei(const AVFrame *frame, AVRational rate, size_t prefix_len,
1013 void **data, size_t *sei_size)
1014 {
1015 ✗ AVFrameSideData *sd = NULL;
1016 uint8_t *sei_data;
1017 PutBitContext pb;
1018 uint32_t *tc;
1019 int m;
1020
1021 ✗ if (frame)
1022 ✗ sd = av_frame_get_side_data(frame, AV_FRAME_DATA_S12M_TIMECODE);
1023
1024 ✗ if (!sd) {
1025 ✗ *data = NULL;
1026 ✗ return 0;
1027 }
1028 ✗ tc = (uint32_t*)sd->data;
1029 ✗ m = tc[0] & 3;
1030
1031 ✗ *sei_size = sizeof(uint32_t) * 4;
1032 ✗ *data = av_mallocz(*sei_size + prefix_len);
1033 ✗ if (!*data)
1034 ✗ return AVERROR(ENOMEM);
1035 ✗ sei_data = (uint8_t*)*data + prefix_len;
1036
1037 ✗ init_put_bits(&pb, sei_data, *sei_size);
1038 ✗ put_bits(&pb, 2, m); // num_clock_ts
1039
1040 ✗ for (int j = 1; j <= m; j++) {
1041 ✗ put_bits(&pb, 1, 1); // clock_timestamp_flag
1042 ✗ put_bits(&pb, 1, 1); // units_field_based_flag
1043 ✗ put_timecode_fields(&pb, rate, tc[j]);
1044 ✗ put_bits(&pb, 5, 0); // time_offset_length
1045 }
1046 ✗ flush_put_bits(&pb);
1047
1048 ✗ return 0;
1049 }
1050
1051 ✗ int ff_alloc_timecode_metadata_av1(const AVFrame *frame, AVRational rate,
1052 void **data, size_t *size)
1053 {
1054 ✗ AVFrameSideData *sd = NULL;
1055 PutBitContext pb;
1056 uint32_t *tc;
1057
1058 ✗ if (frame)
1059 ✗ sd = av_frame_get_side_data(frame, AV_FRAME_DATA_S12M_TIMECODE);
1060
1061 ✗ *data = NULL;
1062 ✗ if (!sd)
1063 ✗ return 0;
1064 ✗ tc = (uint32_t*)sd->data;
1065 ✗ if (!(tc[0] & 3)) // num_clock_ts
1066 ✗ return 0;
1067
1068 ✗ *size = 5;
1069 ✗ *data = av_mallocz(*size);
1070 ✗ if (!*data)
1071 ✗ return AVERROR(ENOMEM);
1072
1073 ✗ init_put_bits(&pb, *data, *size);
1074 ✗ put_timecode_fields(&pb, rate, tc[1]);
1075 ✗ put_bits(&pb, 5, 1); // time_offset_length
1076 ✗ put_bits(&pb, 1, 0); // time_offset_value
1077 ✗ flush_put_bits(&pb);
1078
1079 ✗ return 0;
1080 }
1081
1082 20064 int64_t ff_guess_coded_bitrate(AVCodecContext *avctx)
1083 {
1084 20064 AVRational framerate = avctx->framerate;
1085 20064 int bits_per_coded_sample = avctx->bits_per_coded_sample;
1086 int64_t bitrate;
1087
1088
3/4
✓ Branch 0 taken 19945 times.
✓ Branch 1 taken 119 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 19945 times.
20064 if (!(framerate.num && framerate.den))
1089 119 framerate = av_inv_q(avctx->time_base);
1090
2/4
✓ Branch 0 taken 20064 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 20064 times.
20064 if (!(framerate.num && framerate.den))
1091 ✗ return 0;
1092
1093
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20064 times.
20064 if (!bits_per_coded_sample) {
1094 ✗ const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
1095 ✗ bits_per_coded_sample = av_get_bits_per_pixel(desc);
1096 }
1097 20064 bitrate = (int64_t)bits_per_coded_sample * avctx->width * avctx->height *
1098 20064 framerate.num / framerate.den;
1099
1100 20064 return bitrate;
1101 }
1102