FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/utils.c
Date: 2025-03-08 20:38:41
Exec Total Coverage
Lines: 386 511 75.5%
Functions: 25 29 86.2%
Branches: 288 393 73.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 200679 void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
54 {
55 200679 uint8_t **p = ptr;
56
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 200679 times.
200679 if (min_size > SIZE_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
57 av_freep(p);
58 *size = 0;
59 return;
60 }
61 200679 av_fast_mallocz(p, size, min_size + AV_INPUT_BUFFER_PADDING_SIZE);
62
1/2
✓ Branch 0 taken 200679 times.
✗ Branch 1 not taken.
200679 if (*p)
63 200679 memset(*p + min_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
64 }
65
66 697 void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size)
67 {
68 697 uint8_t **p = ptr;
69
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 697 times.
697 if (min_size > SIZE_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
70 av_freep(p);
71 *size = 0;
72 return;
73 }
74 697 av_fast_malloc(p, size, min_size + AV_INPUT_BUFFER_PADDING_SIZE);
75
1/2
✓ Branch 0 taken 697 times.
✗ Branch 1 not taken.
697 if (*p)
76 697 memset(*p, 0, min_size + AV_INPUT_BUFFER_PADDING_SIZE);
77 }
78
79 8286970 int av_codec_is_encoder(const AVCodec *avcodec)
80 {
81 8286970 const FFCodec *const codec = ffcodec(avcodec);
82
4/4
✓ Branch 0 taken 8277587 times.
✓ Branch 1 taken 9383 times.
✓ Branch 2 taken 5063895 times.
✓ Branch 3 taken 3213692 times.
13350865 return codec && (codec->cb_type == FF_CODEC_CB_TYPE_ENCODE ||
83
2/2
✓ Branch 0 taken 4978651 times.
✓ Branch 1 taken 85244 times.
5063895 codec->cb_type == FF_CODEC_CB_TYPE_ENCODE_SUB ||
84
2/2
✓ Branch 0 taken 92532 times.
✓ Branch 1 taken 4886119 times.
4978651 codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_PACKET);
85 }
86
87 12568055 int av_codec_is_decoder(const AVCodec *avcodec)
88 {
89 12568055 const FFCodec *const codec = ffcodec(avcodec);
90
4/4
✓ Branch 0 taken 12558672 times.
✓ Branch 1 taken 9383 times.
✓ Branch 2 taken 5107585 times.
✓ Branch 3 taken 7451087 times.
17675640 return codec && (codec->cb_type == FF_CODEC_CB_TYPE_DECODE ||
91
2/2
✓ Branch 0 taken 5095008 times.
✓ Branch 1 taken 12577 times.
5107585 codec->cb_type == FF_CODEC_CB_TYPE_DECODE_SUB ||
92
2/2
✓ Branch 0 taken 272427 times.
✓ Branch 1 taken 4822581 times.
5095008 codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_FRAME);
93 }
94
95 74571 int ff_set_dimensions(AVCodecContext *s, int width, int height)
96 {
97 74571 int ret = av_image_check_size2(width, height, s->max_pixels, AV_PIX_FMT_NONE, 0, s);
98
99
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 74570 times.
74571 if (ret < 0)
100 1 width = height = 0;
101
102 74571 s->coded_width = width;
103 74571 s->coded_height = height;
104 74571 s->width = AV_CEIL_RSHIFT(width, s->lowres);
105 74571 s->height = AV_CEIL_RSHIFT(height, s->lowres);
106
107 74571 return ret;
108 }
109
110 2904 int ff_set_sar(AVCodecContext *avctx, AVRational sar)
111 {
112 2904 int ret = av_image_check_sar(avctx->width, avctx->height, sar);
113
114
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2899 times.
2904 if (ret < 0) {
115 5 av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %d/%d\n",
116 sar.num, sar.den);
117 5 avctx->sample_aspect_ratio = (AVRational){ 0, 1 };
118 5 return ret;
119 } else {
120 2899 avctx->sample_aspect_ratio = sar;
121 }
122 2899 return 0;
123 }
124
125 2977 int ff_side_data_update_matrix_encoding(AVFrame *frame,
126 enum AVMatrixEncoding matrix_encoding)
127 {
128 AVFrameSideData *side_data;
129 enum AVMatrixEncoding *data;
130
131 2977 side_data = av_frame_get_side_data(frame, AV_FRAME_DATA_MATRIXENCODING);
132
1/2
✓ Branch 0 taken 2977 times.
✗ Branch 1 not taken.
2977 if (!side_data)
133 2977 side_data = av_frame_new_side_data(frame, AV_FRAME_DATA_MATRIXENCODING,
134 sizeof(enum AVMatrixEncoding));
135
136
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2977 times.
2977 if (!side_data)
137 return AVERROR(ENOMEM);
138
139 2977 data = (enum AVMatrixEncoding*)side_data->data;
140 2977 *data = matrix_encoding;
141
142 2977 return 0;
143 }
144
145 10443 void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height,
146 int linesize_align[AV_NUM_DATA_POINTERS])
147 {
148 int i;
149 10443 int w_align = 1;
150 10443 int h_align = 1;
151 10443 AVPixFmtDescriptor const *desc = av_pix_fmt_desc_get(s->pix_fmt);
152
153
1/2
✓ Branch 0 taken 10443 times.
✗ Branch 1 not taken.
10443 if (desc) {
154 10443 w_align = 1 << desc->log2_chroma_w;
155 10443 h_align = 1 << desc->log2_chroma_h;
156 }
157
158
9/9
✓ Branch 0 taken 9516 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 215 times.
✓ Branch 7 taken 27 times.
✓ Branch 8 taken 386 times.
10443 switch (s->pix_fmt) {
159 9516 case AV_PIX_FMT_YUV420P:
160 case AV_PIX_FMT_YUYV422:
161 case AV_PIX_FMT_YVYU422:
162 case AV_PIX_FMT_UYVY422:
163 case AV_PIX_FMT_YUV422P:
164 case AV_PIX_FMT_YUV440P:
165 case AV_PIX_FMT_YUV444P:
166 case AV_PIX_FMT_GBRP:
167 case AV_PIX_FMT_GBRAP:
168 case AV_PIX_FMT_GRAY8:
169 case AV_PIX_FMT_GRAY16BE:
170 case AV_PIX_FMT_GRAY16LE:
171 case AV_PIX_FMT_YUVJ420P:
172 case AV_PIX_FMT_YUVJ422P:
173 case AV_PIX_FMT_YUVJ440P:
174 case AV_PIX_FMT_YUVJ444P:
175 case AV_PIX_FMT_YUVA420P:
176 case AV_PIX_FMT_YUVA422P:
177 case AV_PIX_FMT_YUVA444P:
178 case AV_PIX_FMT_YUV420P9LE:
179 case AV_PIX_FMT_YUV420P9BE:
180 case AV_PIX_FMT_YUV420P10LE:
181 case AV_PIX_FMT_YUV420P10BE:
182 case AV_PIX_FMT_YUV420P12LE:
183 case AV_PIX_FMT_YUV420P12BE:
184 case AV_PIX_FMT_YUV420P14LE:
185 case AV_PIX_FMT_YUV420P14BE:
186 case AV_PIX_FMT_YUV420P16LE:
187 case AV_PIX_FMT_YUV420P16BE:
188 case AV_PIX_FMT_YUVA420P9LE:
189 case AV_PIX_FMT_YUVA420P9BE:
190 case AV_PIX_FMT_YUVA420P10LE:
191 case AV_PIX_FMT_YUVA420P10BE:
192 case AV_PIX_FMT_YUVA420P16LE:
193 case AV_PIX_FMT_YUVA420P16BE:
194 case AV_PIX_FMT_YUV422P9LE:
195 case AV_PIX_FMT_YUV422P9BE:
196 case AV_PIX_FMT_YUV422P10LE:
197 case AV_PIX_FMT_YUV422P10BE:
198 case AV_PIX_FMT_YUV422P12LE:
199 case AV_PIX_FMT_YUV422P12BE:
200 case AV_PIX_FMT_YUV422P14LE:
201 case AV_PIX_FMT_YUV422P14BE:
202 case AV_PIX_FMT_YUV422P16LE:
203 case AV_PIX_FMT_YUV422P16BE:
204 case AV_PIX_FMT_YUVA422P9LE:
205 case AV_PIX_FMT_YUVA422P9BE:
206 case AV_PIX_FMT_YUVA422P10LE:
207 case AV_PIX_FMT_YUVA422P10BE:
208 case AV_PIX_FMT_YUVA422P12LE:
209 case AV_PIX_FMT_YUVA422P12BE:
210 case AV_PIX_FMT_YUVA422P16LE:
211 case AV_PIX_FMT_YUVA422P16BE:
212 case AV_PIX_FMT_YUV440P10LE:
213 case AV_PIX_FMT_YUV440P10BE:
214 case AV_PIX_FMT_YUV440P12LE:
215 case AV_PIX_FMT_YUV440P12BE:
216 case AV_PIX_FMT_YUV444P9LE:
217 case AV_PIX_FMT_YUV444P9BE:
218 case AV_PIX_FMT_YUV444P10LE:
219 case AV_PIX_FMT_YUV444P10BE:
220 case AV_PIX_FMT_YUV444P12LE:
221 case AV_PIX_FMT_YUV444P12BE:
222 case AV_PIX_FMT_YUV444P14LE:
223 case AV_PIX_FMT_YUV444P14BE:
224 case AV_PIX_FMT_YUV444P16LE:
225 case AV_PIX_FMT_YUV444P16BE:
226 case AV_PIX_FMT_YUVA444P9LE:
227 case AV_PIX_FMT_YUVA444P9BE:
228 case AV_PIX_FMT_YUVA444P10LE:
229 case AV_PIX_FMT_YUVA444P10BE:
230 case AV_PIX_FMT_YUVA444P12LE:
231 case AV_PIX_FMT_YUVA444P12BE:
232 case AV_PIX_FMT_YUVA444P16LE:
233 case AV_PIX_FMT_YUVA444P16BE:
234 case AV_PIX_FMT_GBRP9LE:
235 case AV_PIX_FMT_GBRP9BE:
236 case AV_PIX_FMT_GBRP10LE:
237 case AV_PIX_FMT_GBRP10BE:
238 case AV_PIX_FMT_GBRP12LE:
239 case AV_PIX_FMT_GBRP12BE:
240 case AV_PIX_FMT_GBRP14LE:
241 case AV_PIX_FMT_GBRP14BE:
242 case AV_PIX_FMT_GBRP16LE:
243 case AV_PIX_FMT_GBRP16BE:
244 case AV_PIX_FMT_GBRAP12LE:
245 case AV_PIX_FMT_GBRAP12BE:
246 case AV_PIX_FMT_GBRAP16LE:
247 case AV_PIX_FMT_GBRAP16BE:
248 9516 w_align = 16; //FIXME assume 16 pixel per macroblock
249 9516 h_align = 16 * 2; // interlaced needs 2 macroblocks height
250
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 9513 times.
9516 if (s->codec_id == AV_CODEC_ID_BINKVIDEO)
251 3 w_align = 16*2;
252 9516 break;
253 26 case AV_PIX_FMT_YUV411P:
254 case AV_PIX_FMT_YUVJ411P:
255 case AV_PIX_FMT_UYYVYY411:
256 26 w_align = 32;
257 26 h_align = 16 * 2;
258 26 break;
259 21 case AV_PIX_FMT_YUV410P:
260
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 11 times.
21 if (s->codec_id == AV_CODEC_ID_SVQ1) {
261 10 w_align = 64;
262 10 h_align = 64;
263
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 } else if (s->codec_id == AV_CODEC_ID_SNOW) {
264 w_align = 16;
265 h_align = 16;
266 }
267 21 break;
268 38 case AV_PIX_FMT_RGB555:
269
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 33 times.
38 if (s->codec_id == AV_CODEC_ID_RPZA) {
270 5 w_align = 4;
271 5 h_align = 4;
272 }
273
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 37 times.
38 if (s->codec_id == AV_CODEC_ID_INTERPLAY_VIDEO) {
274 1 w_align = 8;
275 1 h_align = 8;
276 }
277 38 break;
278 133 case AV_PIX_FMT_PAL8:
279 case AV_PIX_FMT_BGR8:
280 case AV_PIX_FMT_RGB8:
281
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 5 times.
133 if (s->codec_id == AV_CODEC_ID_SMC ||
282
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 127 times.
128 s->codec_id == AV_CODEC_ID_CINEPAK) {
283 6 w_align = 4;
284 6 h_align = 4;
285 }
286
2/2
✓ Branch 0 taken 132 times.
✓ Branch 1 taken 1 times.
133 if (s->codec_id == AV_CODEC_ID_JV ||
287
1/2
✓ Branch 0 taken 132 times.
✗ Branch 1 not taken.
132 s->codec_id == AV_CODEC_ID_ARGO ||
288
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 131 times.
132 s->codec_id == AV_CODEC_ID_INTERPLAY_VIDEO) {
289 2 w_align = 8;
290 2 h_align = 8;
291 }
292
1/2
✓ Branch 0 taken 133 times.
✗ Branch 1 not taken.
133 if (s->codec_id == AV_CODEC_ID_MJPEG ||
293
1/2
✓ Branch 0 taken 133 times.
✗ Branch 1 not taken.
133 s->codec_id == AV_CODEC_ID_MJPEGB ||
294
1/2
✓ Branch 0 taken 133 times.
✗ Branch 1 not taken.
133 s->codec_id == AV_CODEC_ID_LJPEG ||
295
1/2
✓ Branch 0 taken 133 times.
✗ Branch 1 not taken.
133 s->codec_id == AV_CODEC_ID_SMVJPEG ||
296
1/2
✓ Branch 0 taken 133 times.
✗ Branch 1 not taken.
133 s->codec_id == AV_CODEC_ID_AMV ||
297
1/2
✓ Branch 0 taken 133 times.
✗ Branch 1 not taken.
133 s->codec_id == AV_CODEC_ID_SP5X ||
298
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 125 times.
133 s->codec_id == AV_CODEC_ID_JPEGLS) {
299 8 w_align = 8;
300 8 h_align = 2*8;
301 }
302 133 break;
303 81 case AV_PIX_FMT_BGR24:
304
2/2
✓ Branch 0 taken 80 times.
✓ Branch 1 taken 1 times.
81 if ((s->codec_id == AV_CODEC_ID_MSZH) ||
305
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 75 times.
80 (s->codec_id == AV_CODEC_ID_ZLIB)) {
306 6 w_align = 4;
307 6 h_align = 4;
308 }
309 81 break;
310 215 case AV_PIX_FMT_RGB24:
311
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 208 times.
215 if (s->codec_id == AV_CODEC_ID_CINEPAK) {
312 7 w_align = 4;
313 7 h_align = 4;
314 }
315 215 break;
316 27 case AV_PIX_FMT_BGR0:
317
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
27 if (s->codec_id == AV_CODEC_ID_ARGO) {
318 w_align = 8;
319 h_align = 8;
320 }
321 27 break;
322 386 default:
323 386 break;
324 }
325
326
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 10441 times.
10443 if (s->codec_id == AV_CODEC_ID_IFF_ILBM) {
327 2 w_align = FFMAX(w_align, 16);
328 }
329
330 10443 *width = FFALIGN(*width, w_align);
331 10443 *height = FFALIGN(*height, h_align);
332
4/4
✓ Branch 0 taken 9851 times.
✓ Branch 1 taken 592 times.
✓ Branch 2 taken 9850 times.
✓ Branch 3 taken 1 times.
10443 if (s->codec_id == AV_CODEC_ID_H264 || s->lowres ||
333
4/4
✓ Branch 0 taken 9835 times.
✓ Branch 1 taken 15 times.
✓ Branch 2 taken 9828 times.
✓ Branch 3 taken 7 times.
9850 s->codec_id == AV_CODEC_ID_VC1 || s->codec_id == AV_CODEC_ID_WMV3 ||
334
4/4
✓ Branch 0 taken 9827 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 9818 times.
✓ Branch 3 taken 9 times.
9828 s->codec_id == AV_CODEC_ID_VP5 || s->codec_id == AV_CODEC_ID_VP6 ||
335
4/4
✓ Branch 0 taken 9816 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 9814 times.
9818 s->codec_id == AV_CODEC_ID_VP6F || s->codec_id == AV_CODEC_ID_VP6A
336 ) {
337 // some of the optimized chroma MC reads one line too much
338 // which is also done in mpeg decoders with lowres > 0
339 629 *height += 2;
340
341 // H.264 uses edge emulation for out of frame motion vectors, for this
342 // it requires a temporary area large enough to hold a 21x21 block,
343 // increasing witdth ensure that the temporary area is large enough,
344 // the next rounded up width is 32
345 629 *width = FFMAX(*width, 32);
346 }
347
2/2
✓ Branch 0 taken 2618 times.
✓ Branch 1 taken 7825 times.
10443 if (s->codec_id == AV_CODEC_ID_SVQ3) {
348 2618 *width = FFMAX(*width, 32);
349 }
350
351
2/2
✓ Branch 0 taken 41772 times.
✓ Branch 1 taken 10443 times.
52215 for (i = 0; i < 4; i++)
352 41772 linesize_align[i] = STRIDE_ALIGN;
353 10443 }
354
355 void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height)
356 {
357 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->pix_fmt);
358 int chroma_shift = desc->log2_chroma_w;
359 int linesize_align[AV_NUM_DATA_POINTERS];
360 int align;
361
362 avcodec_align_dimensions2(s, width, height, linesize_align);
363 align = FFMAX(linesize_align[0], linesize_align[3]);
364 linesize_align[1] <<= chroma_shift;
365 linesize_align[2] <<= chroma_shift;
366 align = FFMAX3(align, linesize_align[1], linesize_align[2]);
367 *width = FFALIGN(*width, align);
368 }
369
370 int avcodec_fill_audio_frame(AVFrame *frame, int nb_channels,
371 enum AVSampleFormat sample_fmt, const uint8_t *buf,
372 int buf_size, int align)
373 {
374 int ch, planar, needed_size, ret = 0;
375
376 needed_size = av_samples_get_buffer_size(NULL, nb_channels,
377 frame->nb_samples, sample_fmt,
378 align);
379 if (buf_size < needed_size)
380 return AVERROR(EINVAL);
381
382 planar = av_sample_fmt_is_planar(sample_fmt);
383 if (planar && nb_channels > AV_NUM_DATA_POINTERS) {
384 if (!FF_ALLOCZ_TYPED_ARRAY(frame->extended_data, nb_channels))
385 return AVERROR(ENOMEM);
386 } else {
387 frame->extended_data = frame->data;
388 }
389
390 if ((ret = av_samples_fill_arrays(frame->extended_data, &frame->linesize[0],
391 (uint8_t *)(intptr_t)buf, nb_channels, frame->nb_samples,
392 sample_fmt, align)) < 0) {
393 if (frame->extended_data != frame->data)
394 av_freep(&frame->extended_data);
395 return ret;
396 }
397 if (frame->extended_data != frame->data) {
398 for (ch = 0; ch < AV_NUM_DATA_POINTERS; ch++)
399 frame->data[ch] = frame->extended_data[ch];
400 }
401
402 return ret;
403 }
404
405
406 195234 int avpriv_codec_get_cap_skip_frame_fill_param(const AVCodec *codec){
407 195234 return !!(ffcodec(codec)->caps_internal & FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM);
408 }
409
410 28594 const char *avcodec_get_name(enum AVCodecID id)
411 {
412 const AVCodecDescriptor *cd;
413 const AVCodec *codec;
414
415
2/2
✓ Branch 0 taken 243 times.
✓ Branch 1 taken 28351 times.
28594 if (id == AV_CODEC_ID_NONE)
416 243 return "none";
417 28351 cd = avcodec_descriptor_get(id);
418
2/2
✓ Branch 0 taken 28347 times.
✓ Branch 1 taken 4 times.
28351 if (cd)
419 28347 return cd->name;
420 4 av_log(NULL, AV_LOG_WARNING, "Codec 0x%x is not in the full list.\n", id);
421 4 codec = avcodec_find_decoder(id);
422
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (codec)
423 return codec->name;
424 4 codec = avcodec_find_encoder(id);
425
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (codec)
426 return codec->name;
427 4 return "unknown_codec";
428 }
429
430 const char *av_get_profile_name(const AVCodec *codec, int profile)
431 {
432 const AVProfile *p;
433 if (profile == AV_PROFILE_UNKNOWN || !codec->profiles)
434 return NULL;
435
436 for (p = codec->profiles; p->profile != AV_PROFILE_UNKNOWN; p++)
437 if (p->profile == profile)
438 return p->name;
439
440 return NULL;
441 }
442
443 16670 const char *avcodec_profile_name(enum AVCodecID codec_id, int profile)
444 {
445 16670 const AVCodecDescriptor *desc = avcodec_descriptor_get(codec_id);
446 const AVProfile *p;
447
448
5/6
✓ Branch 0 taken 2155 times.
✓ Branch 1 taken 14515 times.
✓ Branch 2 taken 2155 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 132 times.
✓ Branch 5 taken 2023 times.
16670 if (profile == AV_PROFILE_UNKNOWN || !desc || !desc->profiles)
449 14647 return NULL;
450
451
2/2
✓ Branch 0 taken 5158 times.
✓ Branch 1 taken 34 times.
5192 for (p = desc->profiles; p->profile != AV_PROFILE_UNKNOWN; p++)
452
2/2
✓ Branch 0 taken 1989 times.
✓ Branch 1 taken 3169 times.
5158 if (p->profile == profile)
453 1989 return p->name;
454
455 34 return NULL;
456 }
457
458 807632 int av_get_exact_bits_per_sample(enum AVCodecID codec_id)
459 {
460
8/8
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 11410 times.
✓ Branch 2 taken 9945 times.
✓ Branch 3 taken 501813 times.
✓ Branch 4 taken 17034 times.
✓ Branch 5 taken 23894 times.
✓ Branch 6 taken 18405 times.
✓ Branch 7 taken 225107 times.
807632 switch (codec_id) {
461 24 case AV_CODEC_ID_DFPWM:
462 24 return 1;
463 11410 case AV_CODEC_ID_8SVX_EXP:
464 case AV_CODEC_ID_8SVX_FIB:
465 case AV_CODEC_ID_ADPCM_ARGO:
466 case AV_CODEC_ID_ADPCM_CT:
467 case AV_CODEC_ID_ADPCM_IMA_ALP:
468 case AV_CODEC_ID_ADPCM_IMA_AMV:
469 case AV_CODEC_ID_ADPCM_IMA_APC:
470 case AV_CODEC_ID_ADPCM_IMA_APM:
471 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
472 case AV_CODEC_ID_ADPCM_IMA_OKI:
473 case AV_CODEC_ID_ADPCM_IMA_WS:
474 case AV_CODEC_ID_ADPCM_IMA_SSI:
475 case AV_CODEC_ID_ADPCM_G722:
476 case AV_CODEC_ID_ADPCM_YAMAHA:
477 case AV_CODEC_ID_ADPCM_AICA:
478 11410 return 4;
479 9945 case AV_CODEC_ID_DSD_LSBF:
480 case AV_CODEC_ID_DSD_MSBF:
481 case AV_CODEC_ID_DSD_LSBF_PLANAR:
482 case AV_CODEC_ID_DSD_MSBF_PLANAR:
483 case AV_CODEC_ID_PCM_ALAW:
484 case AV_CODEC_ID_PCM_MULAW:
485 case AV_CODEC_ID_PCM_VIDC:
486 case AV_CODEC_ID_PCM_S8:
487 case AV_CODEC_ID_PCM_S8_PLANAR:
488 case AV_CODEC_ID_PCM_SGA:
489 case AV_CODEC_ID_PCM_U8:
490 case AV_CODEC_ID_SDX2_DPCM:
491 case AV_CODEC_ID_CBD2_DPCM:
492 case AV_CODEC_ID_DERF_DPCM:
493 case AV_CODEC_ID_WADY_DPCM:
494 9945 return 8;
495 501813 case AV_CODEC_ID_PCM_S16BE:
496 case AV_CODEC_ID_PCM_S16BE_PLANAR:
497 case AV_CODEC_ID_PCM_S16LE:
498 case AV_CODEC_ID_PCM_S16LE_PLANAR:
499 case AV_CODEC_ID_PCM_U16BE:
500 case AV_CODEC_ID_PCM_U16LE:
501 501813 return 16;
502 17034 case AV_CODEC_ID_PCM_S24DAUD:
503 case AV_CODEC_ID_PCM_S24BE:
504 case AV_CODEC_ID_PCM_S24LE:
505 case AV_CODEC_ID_PCM_S24LE_PLANAR:
506 case AV_CODEC_ID_PCM_U24BE:
507 case AV_CODEC_ID_PCM_U24LE:
508 17034 return 24;
509 23894 case AV_CODEC_ID_PCM_S32BE:
510 case AV_CODEC_ID_PCM_S32LE:
511 case AV_CODEC_ID_PCM_S32LE_PLANAR:
512 case AV_CODEC_ID_PCM_U32BE:
513 case AV_CODEC_ID_PCM_U32LE:
514 case AV_CODEC_ID_PCM_F32BE:
515 case AV_CODEC_ID_PCM_F32LE:
516 case AV_CODEC_ID_PCM_F24LE:
517 case AV_CODEC_ID_PCM_F16LE:
518 23894 return 32;
519 18405 case AV_CODEC_ID_PCM_F64BE:
520 case AV_CODEC_ID_PCM_F64LE:
521 case AV_CODEC_ID_PCM_S64BE:
522 case AV_CODEC_ID_PCM_S64LE:
523 18405 return 64;
524 225107 default:
525 225107 return 0;
526 }
527 }
528
529 24 enum AVCodecID av_get_pcm_codec(enum AVSampleFormat fmt, int be)
530 {
531 static const enum AVCodecID map[][2] = {
532 [AV_SAMPLE_FMT_U8 ] = { AV_CODEC_ID_PCM_U8, AV_CODEC_ID_PCM_U8 },
533 [AV_SAMPLE_FMT_S16 ] = { AV_CODEC_ID_PCM_S16LE, AV_CODEC_ID_PCM_S16BE },
534 [AV_SAMPLE_FMT_S32 ] = { AV_CODEC_ID_PCM_S32LE, AV_CODEC_ID_PCM_S32BE },
535 [AV_SAMPLE_FMT_FLT ] = { AV_CODEC_ID_PCM_F32LE, AV_CODEC_ID_PCM_F32BE },
536 [AV_SAMPLE_FMT_DBL ] = { AV_CODEC_ID_PCM_F64LE, AV_CODEC_ID_PCM_F64BE },
537 [AV_SAMPLE_FMT_U8P ] = { AV_CODEC_ID_PCM_U8, AV_CODEC_ID_PCM_U8 },
538 [AV_SAMPLE_FMT_S16P] = { AV_CODEC_ID_PCM_S16LE, AV_CODEC_ID_PCM_S16BE },
539 [AV_SAMPLE_FMT_S32P] = { AV_CODEC_ID_PCM_S32LE, AV_CODEC_ID_PCM_S32BE },
540 [AV_SAMPLE_FMT_S64P] = { AV_CODEC_ID_PCM_S64LE, AV_CODEC_ID_PCM_S64BE },
541 [AV_SAMPLE_FMT_FLTP] = { AV_CODEC_ID_PCM_F32LE, AV_CODEC_ID_PCM_F32BE },
542 [AV_SAMPLE_FMT_DBLP] = { AV_CODEC_ID_PCM_F64LE, AV_CODEC_ID_PCM_F64BE },
543 };
544
2/4
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
24 if (fmt < 0 || fmt >= FF_ARRAY_ELEMS(map))
545 return AV_CODEC_ID_NONE;
546
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
24 if (be < 0 || be > 1)
547 24 be = AV_NE(1, 0);
548 24 return map[fmt][be];
549 }
550
551 286225 int av_get_bits_per_sample(enum AVCodecID codec_id)
552 {
553
5/5
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 74 times.
✓ Branch 4 taken 286128 times.
286225 switch (codec_id) {
554 17 case AV_CODEC_ID_DFPWM:
555 17 return 1;
556 3 case AV_CODEC_ID_ADPCM_SBPRO_2:
557 3 return 2;
558 3 case AV_CODEC_ID_ADPCM_SBPRO_3:
559 3 return 3;
560 74 case AV_CODEC_ID_ADPCM_SBPRO_4:
561 case AV_CODEC_ID_ADPCM_IMA_WAV:
562 case AV_CODEC_ID_ADPCM_IMA_XBOX:
563 case AV_CODEC_ID_ADPCM_IMA_QT:
564 case AV_CODEC_ID_ADPCM_SWF:
565 case AV_CODEC_ID_ADPCM_MS:
566 74 return 4;
567 286128 default:
568 286128 return av_get_exact_bits_per_sample(codec_id);
569 }
570 }
571
572 512501 static int get_audio_frame_duration(enum AVCodecID id, int sr, int ch, int ba,
573 uint32_t tag, int bits_per_coded_sample, int64_t bitrate,
574 uint8_t * extradata, int frame_size, int frame_bytes)
575 {
576 512501 int bps = av_get_exact_bits_per_sample(id);
577
4/4
✓ Branch 0 taken 355554 times.
✓ Branch 1 taken 156947 times.
✓ Branch 2 taken 355249 times.
✓ Branch 3 taken 305 times.
512501 int framecount = (ba > 0 && frame_bytes / ba > 0) ? frame_bytes / ba : 1;
578
579 /* codecs with an exact constant bits per sample */
580
7/10
✓ Branch 0 taken 298011 times.
✓ Branch 1 taken 214490 times.
✓ Branch 2 taken 298011 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 297975 times.
✓ Branch 5 taken 36 times.
✓ Branch 6 taken 297975 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 297975 times.
✗ Branch 9 not taken.
512501 if (bps > 0 && ch > 0 && frame_bytes > 0 && ch < 32768 && bps < 32768)
581 297975 return (frame_bytes * 8LL) / (bps * ch);
582 214526 bps = bits_per_coded_sample;
583
584 /* codecs with a fixed packet duration */
585
11/13
✓ Branch 0 taken 12407 times.
✓ Branch 1 taken 8274 times.
✓ Branch 2 taken 600 times.
✓ Branch 3 taken 5701 times.
✓ Branch 4 taken 1124 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 8595 times.
✓ Branch 7 taken 4337 times.
✓ Branch 8 taken 2185 times.
✓ Branch 9 taken 18574 times.
✓ Branch 10 taken 2515 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 150214 times.
214526 switch (id) {
586 12407 case AV_CODEC_ID_ADPCM_ADX: return 32;
587 8274 case AV_CODEC_ID_ADPCM_IMA_QT: return 64;
588 600 case AV_CODEC_ID_ADPCM_EA_XAS: return 128;
589 5701 case AV_CODEC_ID_AMR_NB:
590 case AV_CODEC_ID_EVRC:
591 case AV_CODEC_ID_GSM:
592 case AV_CODEC_ID_QCELP:
593 5701 case AV_CODEC_ID_RA_288: return 160;
594 1124 case AV_CODEC_ID_AMR_WB:
595 1124 case AV_CODEC_ID_GSM_MS: return 320;
596 case AV_CODEC_ID_MP1: return 384;
597 8595 case AV_CODEC_ID_ATRAC1: return 512;
598 4337 case AV_CODEC_ID_ATRAC9:
599 case AV_CODEC_ID_ATRAC3:
600
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4337 times.
4337 if (framecount > INT_MAX/1024)
601 return 0;
602 4337 return 1024 * framecount;
603 2185 case AV_CODEC_ID_ATRAC3P: return 2048;
604 18574 case AV_CODEC_ID_MP2:
605 18574 case AV_CODEC_ID_MUSEPACK7: return 1152;
606 2515 case AV_CODEC_ID_AC3: return 1536;
607 case AV_CODEC_ID_FTR: return 1024;
608 }
609
610
2/2
✓ Branch 0 taken 146826 times.
✓ Branch 1 taken 3388 times.
150214 if (sr > 0) {
611 /* calc from sample rate */
612
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 146809 times.
146826 if (id == AV_CODEC_ID_TTA)
613 17 return 256ll * sr / 245;
614
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 146809 times.
146809 else if (id == AV_CODEC_ID_DST)
615 return 588ll * sr / 44100;
616
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 146743 times.
146809 else if (id == AV_CODEC_ID_BINKAUDIO_DCT) {
617
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
66 if (sr / 22050 > 22)
618 return 0;
619 66 return (480 << (sr / 22050));
620 }
621
622
2/2
✓ Branch 0 taken 6703 times.
✓ Branch 1 taken 140040 times.
146743 if (id == AV_CODEC_ID_MP3)
623
2/2
✓ Branch 0 taken 224 times.
✓ Branch 1 taken 6479 times.
6703 return sr <= 24000 ? 576 : 1152;
624 }
625
626
2/2
✓ Branch 0 taken 41697 times.
✓ Branch 1 taken 101731 times.
143428 if (ba > 0) {
627 /* calc from block_align */
628
2/2
✓ Branch 0 taken 7267 times.
✓ Branch 1 taken 34430 times.
41697 if (id == AV_CODEC_ID_SIPR) {
629
4/5
✓ Branch 0 taken 3268 times.
✓ Branch 1 taken 1983 times.
✓ Branch 2 taken 1680 times.
✓ Branch 3 taken 336 times.
✗ Branch 4 not taken.
7267 switch (ba) {
630 3268 case 20: return 160;
631 1983 case 19: return 144;
632 1680 case 29: return 288;
633 336 case 37: return 480;
634 }
635
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 34430 times.
34430 } else if (id == AV_CODEC_ID_ILBC) {
636 switch (ba) {
637 case 38: return 160;
638 case 50: return 240;
639 }
640 }
641 }
642
643
2/2
✓ Branch 0 taken 132701 times.
✓ Branch 1 taken 3460 times.
136161 if (frame_bytes > 0) {
644 /* calc from frame_bytes only */
645
2/2
✓ Branch 0 taken 721 times.
✓ Branch 1 taken 131980 times.
132701 if (id == AV_CODEC_ID_TRUESPEECH)
646 721 return 240 * (frame_bytes / 32);
647
2/2
✓ Branch 0 taken 2074 times.
✓ Branch 1 taken 129906 times.
131980 if (id == AV_CODEC_ID_NELLYMOSER)
648 2074 return 256 * (frame_bytes / 64);
649
2/2
✓ Branch 0 taken 1057 times.
✓ Branch 1 taken 128849 times.
129906 if (id == AV_CODEC_ID_RA_144)
650 1057 return 160 * (frame_bytes / 20);
651
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 128389 times.
128849 if (id == AV_CODEC_ID_APTX)
652 460 return 4 * (frame_bytes / 4);
653
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 127929 times.
128389 if (id == AV_CODEC_ID_APTX_HD)
654 460 return 4 * (frame_bytes / 6);
655
656
2/2
✓ Branch 0 taken 46004 times.
✓ Branch 1 taken 81925 times.
127929 if (bps > 0) {
657 /* calc from frame_bytes and bits_per_coded_sample */
658
3/4
✓ Branch 0 taken 45544 times.
✓ Branch 1 taken 460 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 45544 times.
46004 if (id == AV_CODEC_ID_ADPCM_G726 || id == AV_CODEC_ID_ADPCM_G726LE)
659 460 return frame_bytes * 8 / bps;
660 }
661
662
3/4
✓ Branch 0 taken 127343 times.
✓ Branch 1 taken 126 times.
✓ Branch 2 taken 127343 times.
✗ Branch 3 not taken.
127469 if (ch > 0 && ch < INT_MAX/16) {
663 /* calc from frame_bytes and channels */
664
12/17
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
✓ Branch 3 taken 33 times.
✓ Branch 4 taken 452 times.
✓ Branch 5 taken 1951 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 3580 times.
✓ Branch 8 taken 222 times.
✓ Branch 9 taken 327 times.
✓ Branch 10 taken 680 times.
✓ Branch 11 taken 112 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 318 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 1311 times.
✓ Branch 16 taken 118309 times.
127343 switch (id) {
665 case AV_CODEC_ID_FASTAUDIO:
666 return frame_bytes / (40 * ch) * 256;
667 case AV_CODEC_ID_ADPCM_IMA_MOFLEX:
668 return (frame_bytes - 4 * ch) / (128 * ch) * 256;
669 48 case AV_CODEC_ID_ADPCM_AFC:
670 48 return frame_bytes / (9 * ch) * 16;
671 33 case AV_CODEC_ID_ADPCM_PSX:
672 case AV_CODEC_ID_ADPCM_DTK:
673 33 frame_bytes /= 16 * ch;
674
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
33 if (frame_bytes > INT_MAX / 28)
675 return 0;
676 33 return frame_bytes * 28;
677 452 case AV_CODEC_ID_ADPCM_4XM:
678 case AV_CODEC_ID_ADPCM_IMA_ACORN:
679 case AV_CODEC_ID_ADPCM_IMA_DAT4:
680 case AV_CODEC_ID_ADPCM_IMA_ISS:
681 452 return (frame_bytes - 4 * ch) * 2 / ch;
682 1951 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
683 1951 return (frame_bytes - 4) * 2 / ch;
684 case AV_CODEC_ID_ADPCM_IMA_AMV:
685 return (frame_bytes - 8) * 2;
686 3580 case AV_CODEC_ID_ADPCM_THP:
687 case AV_CODEC_ID_ADPCM_THP_LE:
688
2/2
✓ Branch 0 taken 3530 times.
✓ Branch 1 taken 50 times.
3580 if (extradata)
689 3530 return frame_bytes * 14LL / (8 * ch);
690 50 break;
691 222 case AV_CODEC_ID_ADPCM_XA:
692 222 return (frame_bytes / 128) * 224 / ch;
693 327 case AV_CODEC_ID_INTERPLAY_DPCM:
694 327 return (frame_bytes - 6 - ch) / ch;
695 680 case AV_CODEC_ID_ROQ_DPCM:
696 680 return (frame_bytes - 8) / ch;
697 112 case AV_CODEC_ID_XAN_DPCM:
698 112 return (frame_bytes - 2 * ch) / ch;
699 case AV_CODEC_ID_MACE3:
700 return 3 * frame_bytes / ch;
701 318 case AV_CODEC_ID_MACE6:
702 318 return 6 * frame_bytes / ch;
703 case AV_CODEC_ID_PCM_LXF:
704 return 2 * (frame_bytes / (5 * ch));
705 1311 case AV_CODEC_ID_IAC:
706 case AV_CODEC_ID_IMC:
707 1311 return 4 * frame_bytes / ch;
708 }
709
710
2/2
✓ Branch 0 taken 28778 times.
✓ Branch 1 taken 89581 times.
118359 if (tag) {
711 /* calc from frame_bytes, channels, and codec_tag */
712
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 28704 times.
28778 if (id == AV_CODEC_ID_SOL_DPCM) {
713
1/2
✓ Branch 0 taken 74 times.
✗ Branch 1 not taken.
74 if (tag == 3)
714 74 return frame_bytes / ch;
715 else
716 return frame_bytes * 2 / ch;
717 }
718 }
719
720
2/2
✓ Branch 0 taken 29948 times.
✓ Branch 1 taken 88337 times.
118285 if (ba > 0) {
721 /* calc from frame_bytes, channels, and block_align */
722 29948 int blocks = frame_bytes / ba;
723 29948 int64_t tmp = 0;
724
7/9
✓ Branch 0 taken 182 times.
✓ Branch 1 taken 873 times.
✓ Branch 2 taken 669 times.
✓ Branch 3 taken 649 times.
✓ Branch 4 taken 1001 times.
✓ Branch 5 taken 890 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 25684 times.
29948 switch (id) {
725 182 case AV_CODEC_ID_ADPCM_IMA_XBOX:
726
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 182 times.
182 if (bps != 4)
727 return 0;
728 182 tmp = blocks * ((ba - 4 * ch) / (bps * ch) * 8);
729 182 break;
730 873 case AV_CODEC_ID_ADPCM_IMA_WAV:
731
2/4
✓ Branch 0 taken 873 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 873 times.
873 if (bps < 2 || bps > 5)
732 return 0;
733 873 tmp = blocks * (1LL + (ba - 4 * ch) / (bps * ch) * 8LL);
734 873 break;
735 669 case AV_CODEC_ID_ADPCM_IMA_DK3:
736 669 tmp = blocks * (((ba - 16LL) * 2 / 3 * 4) / ch);
737 669 break;
738 649 case AV_CODEC_ID_ADPCM_IMA_DK4:
739 649 tmp = blocks * (1 + (ba - 4LL * ch) * 2 / ch);
740 649 break;
741 1001 case AV_CODEC_ID_ADPCM_IMA_RAD:
742 1001 tmp = blocks * ((ba - 4LL * ch) * 2 / ch);
743 1001 break;
744 890 case AV_CODEC_ID_ADPCM_MS:
745 890 tmp = blocks * (2 + (ba - 7LL * ch) * 2LL / ch);
746 890 break;
747 case AV_CODEC_ID_ADPCM_MTAF:
748 tmp = blocks * (ba - 16LL) * 2 / ch;
749 break;
750 case AV_CODEC_ID_ADPCM_XMD:
751 tmp = blocks * 32;
752 break;
753 }
754
2/2
✓ Branch 0 taken 4264 times.
✓ Branch 1 taken 25684 times.
29948 if (tmp) {
755
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4264 times.
4264 if (tmp != (int)tmp)
756 return 0;
757 4264 return tmp;
758 }
759 }
760
761
2/2
✓ Branch 0 taken 37345 times.
✓ Branch 1 taken 76676 times.
114021 if (bps > 0) {
762 /* calc from frame_bytes, channels, and bits_per_coded_sample */
763
2/4
✓ Branch 0 taken 20835 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 16510 times.
37345 switch (id) {
764 20835 case AV_CODEC_ID_PCM_DVD:
765
2/4
✓ Branch 0 taken 20835 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 20835 times.
20835 if(bps<4 || frame_bytes<3)
766 return 0;
767 20835 return 2 * ((frame_bytes - 3) / ((bps * 2 / 8) * ch));
768 case AV_CODEC_ID_PCM_BLURAY:
769 if(bps<4 || frame_bytes<4)
770 return 0;
771 return (frame_bytes - 4) / ((FFALIGN(ch, 2) * bps) / 8);
772 case AV_CODEC_ID_S302M:
773 return 2 * (frame_bytes / ((bps + 4) / 4)) / ch;
774 }
775 }
776 }
777 }
778
779 /* Fall back on using frame_size */
780
4/4
✓ Branch 0 taken 52907 times.
✓ Branch 1 taken 43865 times.
✓ Branch 2 taken 52746 times.
✓ Branch 3 taken 161 times.
96772 if (frame_size > 1 && frame_bytes)
781 52746 return frame_size;
782
783 //For WMA we currently have no other means to calculate duration thus we
784 //do it here by assuming CBR, which is true for all known cases.
785
8/8
✓ Branch 0 taken 29133 times.
✓ Branch 1 taken 14893 times.
✓ Branch 2 taken 25689 times.
✓ Branch 3 taken 3444 times.
✓ Branch 4 taken 25659 times.
✓ Branch 5 taken 30 times.
✓ Branch 6 taken 9696 times.
✓ Branch 7 taken 15963 times.
44026 if (bitrate > 0 && frame_bytes > 0 && sr > 0 && ba > 1) {
786
4/4
✓ Branch 0 taken 9491 times.
✓ Branch 1 taken 205 times.
✓ Branch 2 taken 795 times.
✓ Branch 3 taken 8696 times.
9696 if (id == AV_CODEC_ID_WMAV1 || id == AV_CODEC_ID_WMAV2)
787 1000 return (frame_bytes * 8LL * sr) / bitrate;
788 }
789
790 43026 return 0;
791 }
792
793 45099 int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
794 {
795 45099 int channels = avctx->ch_layout.nb_channels;
796 int duration;
797
798 45099 duration = get_audio_frame_duration(avctx->codec_id, avctx->sample_rate,
799 channels, avctx->block_align,
800 avctx->codec_tag, avctx->bits_per_coded_sample,
801 avctx->bit_rate, avctx->extradata, avctx->frame_size,
802 frame_bytes);
803 45099 return FFMAX(0, duration);
804 }
805
806 467402 int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
807 {
808 467402 int channels = par->ch_layout.nb_channels;
809 int duration;
810
811 467402 duration = get_audio_frame_duration(par->codec_id, par->sample_rate,
812 channels, par->block_align,
813 par->codec_tag, par->bits_per_coded_sample,
814 par->bit_rate, par->extradata, par->frame_size,
815 frame_bytes);
816 467402 return FFMAX(0, duration);
817 }
818
819 56 unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
820 {
821 56 unsigned int n = 0;
822
823
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
56 while (v >= 0xff) {
824 *s++ = 0xff;
825 v -= 0xff;
826 n++;
827 }
828 56 *s = v;
829 56 n++;
830 56 return n;
831 }
832
833 476 int ff_match_2uint16(const uint16_t(*tab)[2], int size, int a, int b)
834 {
835 int i;
836
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++) ;
837 476 return i;
838 }
839
840 16171 const AVCodecHWConfig *avcodec_get_hw_config(const AVCodec *avcodec, int index)
841 {
842 16171 const FFCodec *const codec = ffcodec(avcodec);
843 int i;
844
3/4
✓ Branch 0 taken 2612 times.
✓ Branch 1 taken 13559 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2612 times.
16171 if (!codec->hw_configs || index < 0)
845 13559 return NULL;
846
2/2
✓ Branch 0 taken 5115 times.
✓ Branch 1 taken 1705 times.
6820 for (i = 0; i <= index; i++)
847
2/2
✓ Branch 0 taken 907 times.
✓ Branch 1 taken 4208 times.
5115 if (!codec->hw_configs[i])
848 907 return NULL;
849 1705 return &codec->hw_configs[index]->public;
850 }
851
852 27463 int ff_thread_ref_frame(ThreadFrame *dst, const ThreadFrame *src)
853 {
854 int ret;
855
856 27463 dst->owner[0] = src->owner[0];
857 27463 dst->owner[1] = src->owner[1];
858
859 27463 ret = av_frame_ref(dst->f, src->f);
860
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27463 times.
27463 if (ret < 0)
861 return ret;
862
863
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27463 times.
27463 av_assert0(!dst->progress);
864
865
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 27403 times.
27463 if (src->progress)
866 60 dst->progress = av_refstruct_ref(src->progress);
867
868 27463 return 0;
869 }
870
871 298 int ff_thread_replace_frame(ThreadFrame *dst, const ThreadFrame *src)
872 {
873 int ret;
874
875 298 dst->owner[0] = src->owner[0];
876 298 dst->owner[1] = src->owner[1];
877
878 298 ret = av_frame_replace(dst->f, src->f);
879
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 298 times.
298 if (ret < 0)
880 return ret;
881
882 298 av_refstruct_replace(&dst->progress, src->progress);
883
884 298 return 0;
885 }
886
887 #if !HAVE_THREADS
888
889 int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f, int flags)
890 {
891 return ff_get_buffer(avctx, f, flags);
892 }
893
894 int ff_thread_get_ext_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
895 {
896 f->owner[0] = f->owner[1] = avctx;
897 return ff_get_buffer(avctx, f->f, flags);
898 }
899
900 void ff_thread_release_ext_buffer(ThreadFrame *f)
901 {
902 f->owner[0] = f->owner[1] = NULL;
903 if (f->f)
904 av_frame_unref(f->f);
905 }
906
907 void ff_thread_finish_setup(AVCodecContext *avctx)
908 {
909 }
910
911 void ff_thread_report_progress(ThreadFrame *f, int progress, int field)
912 {
913 }
914
915 void ff_thread_await_progress(const ThreadFrame *f, int progress, int field)
916 {
917 }
918
919 int ff_thread_can_start_frame(AVCodecContext *avctx)
920 {
921 return 1;
922 }
923 #endif
924
925 664191 const uint8_t *avpriv_find_start_code(const uint8_t *restrict p,
926 const uint8_t *end,
927 uint32_t *restrict state)
928 {
929 int i;
930
931
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 664191 times.
664191 av_assert0(p <= end);
932
2/2
✓ Branch 0 taken 910 times.
✓ Branch 1 taken 663281 times.
664191 if (p >= end)
933 910 return end;
934
935
2/2
✓ Branch 0 taken 1984226 times.
✓ Branch 1 taken 659377 times.
2643603 for (i = 0; i < 3; i++) {
936 1984226 uint32_t tmp = *state << 8;
937 1984226 *state = tmp + *(p++);
938
4/4
✓ Branch 0 taken 1983358 times.
✓ Branch 1 taken 868 times.
✓ Branch 2 taken 3036 times.
✓ Branch 3 taken 1980322 times.
1984226 if (tmp == 0x100 || p == end)
939 3904 return p;
940 }
941
942
2/2
✓ Branch 0 taken 393507576 times.
✓ Branch 1 taken 66981 times.
393574557 while (p < end) {
943
2/2
✓ Branch 0 taken 356387753 times.
✓ Branch 1 taken 37119823 times.
393507576 if (p[-1] > 1 ) p += 3;
944
2/2
✓ Branch 0 taken 15917259 times.
✓ Branch 1 taken 21202564 times.
37119823 else if (p[-2] ) p += 2;
945
2/2
✓ Branch 0 taken 20610168 times.
✓ Branch 1 taken 592396 times.
21202564 else if (p[-3]|(p[-1]-1)) p++;
946 else {
947 592396 p++;
948 592396 break;
949 }
950 }
951
952
2/2
✓ Branch 0 taken 42051 times.
✓ Branch 1 taken 617326 times.
659377 p = FFMIN(p, end) - 4;
953 659377 *state = AV_RB32(p);
954
955 659377 return p + 4;
956 }
957
958 413 AVCPBProperties *av_cpb_properties_alloc(size_t *size)
959 {
960 413 AVCPBProperties *props = av_mallocz(sizeof(AVCPBProperties));
961
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 413 times.
413 if (!props)
962 return NULL;
963
964
1/2
✓ Branch 0 taken 413 times.
✗ Branch 1 not taken.
413 if (size)
965 413 *size = sizeof(*props);
966
967 413 props->vbv_delay = UINT64_MAX;
968
969 413 return props;
970 }
971
972 int ff_alloc_timecode_sei(const AVFrame *frame, AVRational rate, size_t prefix_len,
973 void **data, size_t *sei_size)
974 {
975 AVFrameSideData *sd = NULL;
976 uint8_t *sei_data;
977 PutBitContext pb;
978 uint32_t *tc;
979 int m;
980
981 if (frame)
982 sd = av_frame_get_side_data(frame, AV_FRAME_DATA_S12M_TIMECODE);
983
984 if (!sd) {
985 *data = NULL;
986 return 0;
987 }
988 tc = (uint32_t*)sd->data;
989 m = tc[0] & 3;
990
991 *sei_size = sizeof(uint32_t) * 4;
992 *data = av_mallocz(*sei_size + prefix_len);
993 if (!*data)
994 return AVERROR(ENOMEM);
995 sei_data = (uint8_t*)*data + prefix_len;
996
997 init_put_bits(&pb, sei_data, *sei_size);
998 put_bits(&pb, 2, m); // num_clock_ts
999
1000 for (int j = 1; j <= m; j++) {
1001 unsigned hh, mm, ss, ff, drop;
1002 ff_timecode_set_smpte(&drop, &hh, &mm, &ss, &ff, rate, tc[j], 0, 0);
1003
1004 put_bits(&pb, 1, 1); // clock_timestamp_flag
1005 put_bits(&pb, 1, 1); // units_field_based_flag
1006 put_bits(&pb, 5, 0); // counting_type
1007 put_bits(&pb, 1, 1); // full_timestamp_flag
1008 put_bits(&pb, 1, 0); // discontinuity_flag
1009 put_bits(&pb, 1, drop);
1010 put_bits(&pb, 9, ff);
1011 put_bits(&pb, 6, ss);
1012 put_bits(&pb, 6, mm);
1013 put_bits(&pb, 5, hh);
1014 put_bits(&pb, 5, 0);
1015 }
1016 flush_put_bits(&pb);
1017
1018 return 0;
1019 }
1020
1021 18621 int64_t ff_guess_coded_bitrate(AVCodecContext *avctx)
1022 {
1023 18621 AVRational framerate = avctx->framerate;
1024 18621 int bits_per_coded_sample = avctx->bits_per_coded_sample;
1025 int64_t bitrate;
1026
1027
3/4
✓ Branch 0 taken 18502 times.
✓ Branch 1 taken 119 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18502 times.
18621 if (!(framerate.num && framerate.den))
1028 119 framerate = av_inv_q(avctx->time_base);
1029
2/4
✓ Branch 0 taken 18621 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18621 times.
18621 if (!(framerate.num && framerate.den))
1030 return 0;
1031
1032
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18621 times.
18621 if (!bits_per_coded_sample) {
1033 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
1034 bits_per_coded_sample = av_get_bits_per_pixel(desc);
1035 }
1036 18621 bitrate = (int64_t)bits_per_coded_sample * avctx->width * avctx->height *
1037 18621 framerate.num / framerate.den;
1038
1039 18621 return bitrate;
1040 }
1041