FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/utils.c
Date: 2024-02-29 09:57:37
Exec Total Coverage
Lines: 385 528 72.9%
Functions: 25 32 78.1%
Branches: 289 400 72.2%

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 "avcodec.h"
37 #include "codec.h"
38 #include "codec_desc.h"
39 #include "codec_internal.h"
40 #include "codec_par.h"
41 #include "decode.h"
42 #include "hwconfig.h"
43 #include "refstruct.h"
44 #include "thread.h"
45 #include "threadframe.h"
46 #include "internal.h"
47 #include "put_bits.h"
48 #include "startcode.h"
49 #include <stdlib.h>
50 #include <limits.h>
51
52 199890 void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
53 {
54 199890 uint8_t **p = ptr;
55
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 199890 times.
199890 if (min_size > SIZE_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
56 av_freep(p);
57 *size = 0;
58 return;
59 }
60 199890 av_fast_mallocz(p, size, min_size + AV_INPUT_BUFFER_PADDING_SIZE);
61
1/2
✓ Branch 0 taken 199890 times.
✗ Branch 1 not taken.
199890 if (*p)
62 199890 memset(*p + min_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
63 }
64
65 693 void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size)
66 {
67 693 uint8_t **p = ptr;
68
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 693 times.
693 if (min_size > SIZE_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
69 av_freep(p);
70 *size = 0;
71 return;
72 }
73 693 av_fast_malloc(p, size, min_size + AV_INPUT_BUFFER_PADDING_SIZE);
74
1/2
✓ Branch 0 taken 693 times.
✗ Branch 1 not taken.
693 if (*p)
75 693 memset(*p, 0, min_size + AV_INPUT_BUFFER_PADDING_SIZE);
76 }
77
78 8013460 int av_codec_is_encoder(const AVCodec *avcodec)
79 {
80 8013460 const FFCodec *const codec = ffcodec(avcodec);
81
4/4
✓ Branch 0 taken 8005397 times.
✓ Branch 1 taken 8063 times.
✓ Branch 2 taken 4942858 times.
✓ Branch 3 taken 3062539 times.
12956318 return codec && (codec->cb_type == FF_CODEC_CB_TYPE_ENCODE ||
82
2/2
✓ Branch 0 taken 4863413 times.
✓ Branch 1 taken 79445 times.
4942858 codec->cb_type == FF_CODEC_CB_TYPE_ENCODE_SUB ||
83
2/2
✓ Branch 0 taken 86208 times.
✓ Branch 1 taken 4777205 times.
4863413 codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_PACKET);
84 }
85
86 15255325 int av_codec_is_decoder(const AVCodec *avcodec)
87 {
88 15255325 const FFCodec *const codec = ffcodec(avcodec);
89
4/4
✓ Branch 0 taken 15247262 times.
✓ Branch 1 taken 8063 times.
✓ Branch 2 taken 6250504 times.
✓ Branch 3 taken 8996758 times.
21505829 return codec && (codec->cb_type == FF_CODEC_CB_TYPE_DECODE ||
90
2/2
✓ Branch 0 taken 6233938 times.
✓ Branch 1 taken 16566 times.
6250504 codec->cb_type == FF_CODEC_CB_TYPE_DECODE_SUB ||
91
2/2
✓ Branch 0 taken 228609 times.
✓ Branch 1 taken 6005329 times.
6233938 codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_FRAME);
92 }
93
94 67331 int ff_set_dimensions(AVCodecContext *s, int width, int height)
95 {
96 67331 int ret = av_image_check_size2(width, height, s->max_pixels, AV_PIX_FMT_NONE, 0, s);
97
98
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 67330 times.
67331 if (ret < 0)
99 1 width = height = 0;
100
101 67331 s->coded_width = width;
102 67331 s->coded_height = height;
103 67331 s->width = AV_CEIL_RSHIFT(width, s->lowres);
104 67331 s->height = AV_CEIL_RSHIFT(height, s->lowres);
105
106 67331 return ret;
107 }
108
109 2812 int ff_set_sar(AVCodecContext *avctx, AVRational sar)
110 {
111 2812 int ret = av_image_check_sar(avctx->width, avctx->height, sar);
112
113
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2807 times.
2812 if (ret < 0) {
114 5 av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %d/%d\n",
115 sar.num, sar.den);
116 5 avctx->sample_aspect_ratio = (AVRational){ 0, 1 };
117 5 return ret;
118 } else {
119 2807 avctx->sample_aspect_ratio = sar;
120 }
121 2807 return 0;
122 }
123
124 4791 int ff_side_data_update_matrix_encoding(AVFrame *frame,
125 enum AVMatrixEncoding matrix_encoding)
126 {
127 AVFrameSideData *side_data;
128 enum AVMatrixEncoding *data;
129
130 4791 side_data = av_frame_get_side_data(frame, AV_FRAME_DATA_MATRIXENCODING);
131
1/2
✓ Branch 0 taken 4791 times.
✗ Branch 1 not taken.
4791 if (!side_data)
132 4791 side_data = av_frame_new_side_data(frame, AV_FRAME_DATA_MATRIXENCODING,
133 sizeof(enum AVMatrixEncoding));
134
135
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4791 times.
4791 if (!side_data)
136 return AVERROR(ENOMEM);
137
138 4791 data = (enum AVMatrixEncoding*)side_data->data;
139 4791 *data = matrix_encoding;
140
141 4791 return 0;
142 }
143
144 10068 void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height,
145 int linesize_align[AV_NUM_DATA_POINTERS])
146 {
147 int i;
148 10068 int w_align = 1;
149 10068 int h_align = 1;
150 10068 AVPixFmtDescriptor const *desc = av_pix_fmt_desc_get(s->pix_fmt);
151
152
1/2
✓ Branch 0 taken 10068 times.
✗ Branch 1 not taken.
10068 if (desc) {
153 10068 w_align = 1 << desc->log2_chroma_w;
154 10068 h_align = 1 << desc->log2_chroma_h;
155 }
156
157
9/9
✓ Branch 0 taken 9147 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 209 times.
✓ Branch 7 taken 27 times.
✓ Branch 8 taken 386 times.
10068 switch (s->pix_fmt) {
158 9147 case AV_PIX_FMT_YUV420P:
159 case AV_PIX_FMT_YUYV422:
160 case AV_PIX_FMT_YVYU422:
161 case AV_PIX_FMT_UYVY422:
162 case AV_PIX_FMT_YUV422P:
163 case AV_PIX_FMT_YUV440P:
164 case AV_PIX_FMT_YUV444P:
165 case AV_PIX_FMT_GBRP:
166 case AV_PIX_FMT_GBRAP:
167 case AV_PIX_FMT_GRAY8:
168 case AV_PIX_FMT_GRAY16BE:
169 case AV_PIX_FMT_GRAY16LE:
170 case AV_PIX_FMT_YUVJ420P:
171 case AV_PIX_FMT_YUVJ422P:
172 case AV_PIX_FMT_YUVJ440P:
173 case AV_PIX_FMT_YUVJ444P:
174 case AV_PIX_FMT_YUVA420P:
175 case AV_PIX_FMT_YUVA422P:
176 case AV_PIX_FMT_YUVA444P:
177 case AV_PIX_FMT_YUV420P9LE:
178 case AV_PIX_FMT_YUV420P9BE:
179 case AV_PIX_FMT_YUV420P10LE:
180 case AV_PIX_FMT_YUV420P10BE:
181 case AV_PIX_FMT_YUV420P12LE:
182 case AV_PIX_FMT_YUV420P12BE:
183 case AV_PIX_FMT_YUV420P14LE:
184 case AV_PIX_FMT_YUV420P14BE:
185 case AV_PIX_FMT_YUV420P16LE:
186 case AV_PIX_FMT_YUV420P16BE:
187 case AV_PIX_FMT_YUVA420P9LE:
188 case AV_PIX_FMT_YUVA420P9BE:
189 case AV_PIX_FMT_YUVA420P10LE:
190 case AV_PIX_FMT_YUVA420P10BE:
191 case AV_PIX_FMT_YUVA420P16LE:
192 case AV_PIX_FMT_YUVA420P16BE:
193 case AV_PIX_FMT_YUV422P9LE:
194 case AV_PIX_FMT_YUV422P9BE:
195 case AV_PIX_FMT_YUV422P10LE:
196 case AV_PIX_FMT_YUV422P10BE:
197 case AV_PIX_FMT_YUV422P12LE:
198 case AV_PIX_FMT_YUV422P12BE:
199 case AV_PIX_FMT_YUV422P14LE:
200 case AV_PIX_FMT_YUV422P14BE:
201 case AV_PIX_FMT_YUV422P16LE:
202 case AV_PIX_FMT_YUV422P16BE:
203 case AV_PIX_FMT_YUVA422P9LE:
204 case AV_PIX_FMT_YUVA422P9BE:
205 case AV_PIX_FMT_YUVA422P10LE:
206 case AV_PIX_FMT_YUVA422P10BE:
207 case AV_PIX_FMT_YUVA422P12LE:
208 case AV_PIX_FMT_YUVA422P12BE:
209 case AV_PIX_FMT_YUVA422P16LE:
210 case AV_PIX_FMT_YUVA422P16BE:
211 case AV_PIX_FMT_YUV440P10LE:
212 case AV_PIX_FMT_YUV440P10BE:
213 case AV_PIX_FMT_YUV440P12LE:
214 case AV_PIX_FMT_YUV440P12BE:
215 case AV_PIX_FMT_YUV444P9LE:
216 case AV_PIX_FMT_YUV444P9BE:
217 case AV_PIX_FMT_YUV444P10LE:
218 case AV_PIX_FMT_YUV444P10BE:
219 case AV_PIX_FMT_YUV444P12LE:
220 case AV_PIX_FMT_YUV444P12BE:
221 case AV_PIX_FMT_YUV444P14LE:
222 case AV_PIX_FMT_YUV444P14BE:
223 case AV_PIX_FMT_YUV444P16LE:
224 case AV_PIX_FMT_YUV444P16BE:
225 case AV_PIX_FMT_YUVA444P9LE:
226 case AV_PIX_FMT_YUVA444P9BE:
227 case AV_PIX_FMT_YUVA444P10LE:
228 case AV_PIX_FMT_YUVA444P10BE:
229 case AV_PIX_FMT_YUVA444P12LE:
230 case AV_PIX_FMT_YUVA444P12BE:
231 case AV_PIX_FMT_YUVA444P16LE:
232 case AV_PIX_FMT_YUVA444P16BE:
233 case AV_PIX_FMT_GBRP9LE:
234 case AV_PIX_FMT_GBRP9BE:
235 case AV_PIX_FMT_GBRP10LE:
236 case AV_PIX_FMT_GBRP10BE:
237 case AV_PIX_FMT_GBRP12LE:
238 case AV_PIX_FMT_GBRP12BE:
239 case AV_PIX_FMT_GBRP14LE:
240 case AV_PIX_FMT_GBRP14BE:
241 case AV_PIX_FMT_GBRP16LE:
242 case AV_PIX_FMT_GBRP16BE:
243 case AV_PIX_FMT_GBRAP12LE:
244 case AV_PIX_FMT_GBRAP12BE:
245 case AV_PIX_FMT_GBRAP16LE:
246 case AV_PIX_FMT_GBRAP16BE:
247 9147 w_align = 16; //FIXME assume 16 pixel per macroblock
248 9147 h_align = 16 * 2; // interlaced needs 2 macroblocks height
249
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 9144 times.
9147 if (s->codec_id == AV_CODEC_ID_BINKVIDEO)
250 3 w_align = 16*2;
251 9147 break;
252 26 case AV_PIX_FMT_YUV411P:
253 case AV_PIX_FMT_YUVJ411P:
254 case AV_PIX_FMT_UYYVYY411:
255 26 w_align = 32;
256 26 h_align = 16 * 2;
257 26 break;
258 21 case AV_PIX_FMT_YUV410P:
259
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 11 times.
21 if (s->codec_id == AV_CODEC_ID_SVQ1) {
260 10 w_align = 64;
261 10 h_align = 64;
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 209 case AV_PIX_FMT_RGB24:
307
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 202 times.
209 if (s->codec_id == AV_CODEC_ID_CINEPAK) {
308 7 w_align = 4;
309 7 h_align = 4;
310 }
311 209 break;
312 27 case AV_PIX_FMT_BGR0:
313
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
27 if (s->codec_id == AV_CODEC_ID_ARGO) {
314 w_align = 8;
315 h_align = 8;
316 }
317 27 break;
318 386 default:
319 386 break;
320 }
321
322
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 10066 times.
10068 if (s->codec_id == AV_CODEC_ID_IFF_ILBM) {
323 2 w_align = FFMAX(w_align, 16);
324 }
325
326 10068 *width = FFALIGN(*width, w_align);
327 10068 *height = FFALIGN(*height, h_align);
328
4/4
✓ Branch 0 taken 9486 times.
✓ Branch 1 taken 582 times.
✓ Branch 2 taken 9485 times.
✓ Branch 3 taken 1 times.
10068 if (s->codec_id == AV_CODEC_ID_H264 || s->lowres ||
329
4/4
✓ Branch 0 taken 9470 times.
✓ Branch 1 taken 15 times.
✓ Branch 2 taken 9463 times.
✓ Branch 3 taken 7 times.
9485 s->codec_id == AV_CODEC_ID_VC1 || s->codec_id == AV_CODEC_ID_WMV3 ||
330
4/4
✓ Branch 0 taken 9462 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 9455 times.
✓ Branch 3 taken 7 times.
9463 s->codec_id == AV_CODEC_ID_VP5 || s->codec_id == AV_CODEC_ID_VP6 ||
331
4/4
✓ Branch 0 taken 9453 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 9451 times.
9455 s->codec_id == AV_CODEC_ID_VP6F || s->codec_id == AV_CODEC_ID_VP6A
332 ) {
333 // some of the optimized chroma MC reads one line too much
334 // which is also done in mpeg decoders with lowres > 0
335 617 *height += 2;
336
337 // H.264 uses edge emulation for out of frame motion vectors, for this
338 // it requires a temporary area large enough to hold a 21x21 block,
339 // increasing witdth ensure that the temporary area is large enough,
340 // the next rounded up width is 32
341 617 *width = FFMAX(*width, 32);
342 }
343
2/2
✓ Branch 0 taken 2618 times.
✓ Branch 1 taken 7450 times.
10068 if (s->codec_id == AV_CODEC_ID_SVQ3) {
344 2618 *width = FFMAX(*width, 32);
345 }
346
347
2/2
✓ Branch 0 taken 40272 times.
✓ Branch 1 taken 10068 times.
50340 for (i = 0; i < 4; i++)
348 40272 linesize_align[i] = STRIDE_ALIGN;
349 10068 }
350
351 void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height)
352 {
353 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->pix_fmt);
354 int chroma_shift = desc->log2_chroma_w;
355 int linesize_align[AV_NUM_DATA_POINTERS];
356 int align;
357
358 avcodec_align_dimensions2(s, width, height, linesize_align);
359 align = FFMAX(linesize_align[0], linesize_align[3]);
360 linesize_align[1] <<= chroma_shift;
361 linesize_align[2] <<= chroma_shift;
362 align = FFMAX3(align, linesize_align[1], linesize_align[2]);
363 *width = FFALIGN(*width, align);
364 }
365 #if FF_API_AVCODEC_CHROMA_POS
366 int avcodec_enum_to_chroma_pos(int *xpos, int *ypos, enum AVChromaLocation pos)
367 {
368 return av_chroma_location_enum_to_pos(xpos, ypos, pos);
369 }
370
371 enum AVChromaLocation avcodec_chroma_pos_to_enum(int xpos, int ypos)
372 {
373 return av_chroma_location_pos_to_enum(xpos, ypos);
374 }
375 #endif
376
377 int avcodec_fill_audio_frame(AVFrame *frame, int nb_channels,
378 enum AVSampleFormat sample_fmt, const uint8_t *buf,
379 int buf_size, int align)
380 {
381 int ch, planar, needed_size, ret = 0;
382
383 needed_size = av_samples_get_buffer_size(NULL, nb_channels,
384 frame->nb_samples, sample_fmt,
385 align);
386 if (buf_size < needed_size)
387 return AVERROR(EINVAL);
388
389 planar = av_sample_fmt_is_planar(sample_fmt);
390 if (planar && nb_channels > AV_NUM_DATA_POINTERS) {
391 if (!FF_ALLOCZ_TYPED_ARRAY(frame->extended_data, nb_channels))
392 return AVERROR(ENOMEM);
393 } else {
394 frame->extended_data = frame->data;
395 }
396
397 if ((ret = av_samples_fill_arrays(frame->extended_data, &frame->linesize[0],
398 (uint8_t *)(intptr_t)buf, nb_channels, frame->nb_samples,
399 sample_fmt, align)) < 0) {
400 if (frame->extended_data != frame->data)
401 av_freep(&frame->extended_data);
402 return ret;
403 }
404 if (frame->extended_data != frame->data) {
405 for (ch = 0; ch < AV_NUM_DATA_POINTERS; ch++)
406 frame->data[ch] = frame->extended_data[ch];
407 }
408
409 return ret;
410 }
411
412
413 179974 int avpriv_codec_get_cap_skip_frame_fill_param(const AVCodec *codec){
414 179974 return !!(ffcodec(codec)->caps_internal & FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM);
415 }
416
417 26163 const char *avcodec_get_name(enum AVCodecID id)
418 {
419 const AVCodecDescriptor *cd;
420 const AVCodec *codec;
421
422
2/2
✓ Branch 0 taken 232 times.
✓ Branch 1 taken 25931 times.
26163 if (id == AV_CODEC_ID_NONE)
423 232 return "none";
424 25931 cd = avcodec_descriptor_get(id);
425
2/2
✓ Branch 0 taken 25927 times.
✓ Branch 1 taken 4 times.
25931 if (cd)
426 25927 return cd->name;
427 4 av_log(NULL, AV_LOG_WARNING, "Codec 0x%x is not in the full list.\n", id);
428 4 codec = avcodec_find_decoder(id);
429
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (codec)
430 return codec->name;
431 4 codec = avcodec_find_encoder(id);
432
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (codec)
433 return codec->name;
434 4 return "unknown_codec";
435 }
436
437 const char *av_get_profile_name(const AVCodec *codec, int profile)
438 {
439 const AVProfile *p;
440 if (profile == AV_PROFILE_UNKNOWN || !codec->profiles)
441 return NULL;
442
443 for (p = codec->profiles; p->profile != AV_PROFILE_UNKNOWN; p++)
444 if (p->profile == profile)
445 return p->name;
446
447 return NULL;
448 }
449
450 14753 const char *avcodec_profile_name(enum AVCodecID codec_id, int profile)
451 {
452 14753 const AVCodecDescriptor *desc = avcodec_descriptor_get(codec_id);
453 const AVProfile *p;
454
455
5/6
✓ Branch 0 taken 2074 times.
✓ Branch 1 taken 12679 times.
✓ Branch 2 taken 2074 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 132 times.
✓ Branch 5 taken 1942 times.
14753 if (profile == AV_PROFILE_UNKNOWN || !desc || !desc->profiles)
456 12811 return NULL;
457
458
2/2
✓ Branch 0 taken 5013 times.
✓ Branch 1 taken 30 times.
5043 for (p = desc->profiles; p->profile != AV_PROFILE_UNKNOWN; p++)
459
2/2
✓ Branch 0 taken 1912 times.
✓ Branch 1 taken 3101 times.
5013 if (p->profile == profile)
460 1912 return p->name;
461
462 30 return NULL;
463 }
464
465 948855 int av_get_exact_bits_per_sample(enum AVCodecID codec_id)
466 {
467
8/8
✓ Branch 0 taken 51 times.
✓ Branch 1 taken 11198 times.
✓ Branch 2 taken 13429 times.
✓ Branch 3 taken 571566 times.
✓ Branch 4 taken 83051 times.
✓ Branch 5 taken 30334 times.
✓ Branch 6 taken 21361 times.
✓ Branch 7 taken 217865 times.
948855 switch (codec_id) {
468 51 case AV_CODEC_ID_DFPWM:
469 51 return 1;
470 11198 case AV_CODEC_ID_8SVX_EXP:
471 case AV_CODEC_ID_8SVX_FIB:
472 case AV_CODEC_ID_ADPCM_ARGO:
473 case AV_CODEC_ID_ADPCM_CT:
474 case AV_CODEC_ID_ADPCM_IMA_ALP:
475 case AV_CODEC_ID_ADPCM_IMA_AMV:
476 case AV_CODEC_ID_ADPCM_IMA_APC:
477 case AV_CODEC_ID_ADPCM_IMA_APM:
478 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
479 case AV_CODEC_ID_ADPCM_IMA_OKI:
480 case AV_CODEC_ID_ADPCM_IMA_WS:
481 case AV_CODEC_ID_ADPCM_IMA_SSI:
482 case AV_CODEC_ID_ADPCM_G722:
483 case AV_CODEC_ID_ADPCM_YAMAHA:
484 case AV_CODEC_ID_ADPCM_AICA:
485 11198 return 4;
486 13429 case AV_CODEC_ID_DSD_LSBF:
487 case AV_CODEC_ID_DSD_MSBF:
488 case AV_CODEC_ID_DSD_LSBF_PLANAR:
489 case AV_CODEC_ID_DSD_MSBF_PLANAR:
490 case AV_CODEC_ID_PCM_ALAW:
491 case AV_CODEC_ID_PCM_MULAW:
492 case AV_CODEC_ID_PCM_VIDC:
493 case AV_CODEC_ID_PCM_S8:
494 case AV_CODEC_ID_PCM_S8_PLANAR:
495 case AV_CODEC_ID_PCM_SGA:
496 case AV_CODEC_ID_PCM_U8:
497 case AV_CODEC_ID_SDX2_DPCM:
498 case AV_CODEC_ID_CBD2_DPCM:
499 case AV_CODEC_ID_DERF_DPCM:
500 case AV_CODEC_ID_WADY_DPCM:
501 13429 return 8;
502 571566 case AV_CODEC_ID_PCM_S16BE:
503 case AV_CODEC_ID_PCM_S16BE_PLANAR:
504 case AV_CODEC_ID_PCM_S16LE:
505 case AV_CODEC_ID_PCM_S16LE_PLANAR:
506 case AV_CODEC_ID_PCM_U16BE:
507 case AV_CODEC_ID_PCM_U16LE:
508 571566 return 16;
509 83051 case AV_CODEC_ID_PCM_S24DAUD:
510 case AV_CODEC_ID_PCM_S24BE:
511 case AV_CODEC_ID_PCM_S24LE:
512 case AV_CODEC_ID_PCM_S24LE_PLANAR:
513 case AV_CODEC_ID_PCM_U24BE:
514 case AV_CODEC_ID_PCM_U24LE:
515 83051 return 24;
516 30334 case AV_CODEC_ID_PCM_S32BE:
517 case AV_CODEC_ID_PCM_S32LE:
518 case AV_CODEC_ID_PCM_S32LE_PLANAR:
519 case AV_CODEC_ID_PCM_U32BE:
520 case AV_CODEC_ID_PCM_U32LE:
521 case AV_CODEC_ID_PCM_F32BE:
522 case AV_CODEC_ID_PCM_F32LE:
523 case AV_CODEC_ID_PCM_F24LE:
524 case AV_CODEC_ID_PCM_F16LE:
525 30334 return 32;
526 21361 case AV_CODEC_ID_PCM_F64BE:
527 case AV_CODEC_ID_PCM_F64LE:
528 case AV_CODEC_ID_PCM_S64BE:
529 case AV_CODEC_ID_PCM_S64LE:
530 21361 return 64;
531 217865 default:
532 217865 return 0;
533 }
534 }
535
536 24 enum AVCodecID av_get_pcm_codec(enum AVSampleFormat fmt, int be)
537 {
538 static const enum AVCodecID map[][2] = {
539 [AV_SAMPLE_FMT_U8 ] = { AV_CODEC_ID_PCM_U8, AV_CODEC_ID_PCM_U8 },
540 [AV_SAMPLE_FMT_S16 ] = { AV_CODEC_ID_PCM_S16LE, AV_CODEC_ID_PCM_S16BE },
541 [AV_SAMPLE_FMT_S32 ] = { AV_CODEC_ID_PCM_S32LE, AV_CODEC_ID_PCM_S32BE },
542 [AV_SAMPLE_FMT_FLT ] = { AV_CODEC_ID_PCM_F32LE, AV_CODEC_ID_PCM_F32BE },
543 [AV_SAMPLE_FMT_DBL ] = { AV_CODEC_ID_PCM_F64LE, AV_CODEC_ID_PCM_F64BE },
544 [AV_SAMPLE_FMT_U8P ] = { AV_CODEC_ID_PCM_U8, AV_CODEC_ID_PCM_U8 },
545 [AV_SAMPLE_FMT_S16P] = { AV_CODEC_ID_PCM_S16LE, AV_CODEC_ID_PCM_S16BE },
546 [AV_SAMPLE_FMT_S32P] = { AV_CODEC_ID_PCM_S32LE, AV_CODEC_ID_PCM_S32BE },
547 [AV_SAMPLE_FMT_S64P] = { AV_CODEC_ID_PCM_S64LE, AV_CODEC_ID_PCM_S64BE },
548 [AV_SAMPLE_FMT_FLTP] = { AV_CODEC_ID_PCM_F32LE, AV_CODEC_ID_PCM_F32BE },
549 [AV_SAMPLE_FMT_DBLP] = { AV_CODEC_ID_PCM_F64LE, AV_CODEC_ID_PCM_F64BE },
550 };
551
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))
552 return AV_CODEC_ID_NONE;
553
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)
554 24 be = AV_NE(1, 0);
555 24 return map[fmt][be];
556 }
557
558 351829 int av_get_bits_per_sample(enum AVCodecID codec_id)
559 {
560
5/5
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 64 times.
✓ Branch 4 taken 351755 times.
351829 switch (codec_id) {
561 4 case AV_CODEC_ID_DFPWM:
562 4 return 1;
563 3 case AV_CODEC_ID_ADPCM_SBPRO_2:
564 3 return 2;
565 3 case AV_CODEC_ID_ADPCM_SBPRO_3:
566 3 return 3;
567 64 case AV_CODEC_ID_ADPCM_SBPRO_4:
568 case AV_CODEC_ID_ADPCM_IMA_WAV:
569 case AV_CODEC_ID_ADPCM_IMA_QT:
570 case AV_CODEC_ID_ADPCM_SWF:
571 case AV_CODEC_ID_ADPCM_MS:
572 64 return 4;
573 351755 default:
574 351755 return av_get_exact_bits_per_sample(codec_id);
575 }
576 }
577
578 590587 static int get_audio_frame_duration(enum AVCodecID id, int sr, int ch, int ba,
579 uint32_t tag, int bits_per_coded_sample, int64_t bitrate,
580 uint8_t * extradata, int frame_size, int frame_bytes)
581 {
582 590587 int bps = av_get_exact_bits_per_sample(id);
583
4/4
✓ Branch 0 taken 430647 times.
✓ Branch 1 taken 159940 times.
✓ Branch 2 taken 430344 times.
✓ Branch 3 taken 303 times.
590587 int framecount = (ba > 0 && frame_bytes / ba > 0) ? frame_bytes / ba : 1;
584
585 /* codecs with an exact constant bits per sample */
586
7/10
✓ Branch 0 taken 381299 times.
✓ Branch 1 taken 209288 times.
✓ Branch 2 taken 381299 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 381263 times.
✓ Branch 5 taken 36 times.
✓ Branch 6 taken 381263 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 381263 times.
✗ Branch 9 not taken.
590587 if (bps > 0 && ch > 0 && frame_bytes > 0 && ch < 32768 && bps < 32768)
587 381263 return (frame_bytes * 8LL) / (bps * ch);
588 209324 bps = bits_per_coded_sample;
589
590 /* codecs with a fixed packet duration */
591
11/13
✓ Branch 0 taken 12407 times.
✓ Branch 1 taken 8274 times.
✓ Branch 2 taken 600 times.
✓ Branch 3 taken 5703 times.
✓ Branch 4 taken 1124 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4319 times.
✓ Branch 7 taken 4181 times.
✓ Branch 8 taken 2185 times.
✓ Branch 9 taken 18574 times.
✓ Branch 10 taken 2236 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 149721 times.
209324 switch (id) {
592 12407 case AV_CODEC_ID_ADPCM_ADX: return 32;
593 8274 case AV_CODEC_ID_ADPCM_IMA_QT: return 64;
594 600 case AV_CODEC_ID_ADPCM_EA_XAS: return 128;
595 5703 case AV_CODEC_ID_AMR_NB:
596 case AV_CODEC_ID_EVRC:
597 case AV_CODEC_ID_GSM:
598 case AV_CODEC_ID_QCELP:
599 5703 case AV_CODEC_ID_RA_288: return 160;
600 1124 case AV_CODEC_ID_AMR_WB:
601 1124 case AV_CODEC_ID_GSM_MS: return 320;
602 case AV_CODEC_ID_MP1: return 384;
603 4319 case AV_CODEC_ID_ATRAC1: return 512;
604 4181 case AV_CODEC_ID_ATRAC9:
605 case AV_CODEC_ID_ATRAC3:
606
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4181 times.
4181 if (framecount > INT_MAX/1024)
607 return 0;
608 4181 return 1024 * framecount;
609 2185 case AV_CODEC_ID_ATRAC3P: return 2048;
610 18574 case AV_CODEC_ID_MP2:
611 18574 case AV_CODEC_ID_MUSEPACK7: return 1152;
612 2236 case AV_CODEC_ID_AC3: return 1536;
613 case AV_CODEC_ID_FTR: return 1024;
614 }
615
616
2/2
✓ Branch 0 taken 146650 times.
✓ Branch 1 taken 3071 times.
149721 if (sr > 0) {
617 /* calc from sample rate */
618
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 146633 times.
146650 if (id == AV_CODEC_ID_TTA)
619 17 return 256ll * sr / 245;
620
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 146633 times.
146633 else if (id == AV_CODEC_ID_DST)
621 return 588ll * sr / 44100;
622
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 146567 times.
146633 else if (id == AV_CODEC_ID_BINKAUDIO_DCT) {
623
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
66 if (sr / 22050 > 22)
624 return 0;
625 66 return (480 << (sr / 22050));
626 }
627
628
2/2
✓ Branch 0 taken 6742 times.
✓ Branch 1 taken 139825 times.
146567 if (id == AV_CODEC_ID_MP3)
629
2/2
✓ Branch 0 taken 224 times.
✓ Branch 1 taken 6518 times.
6742 return sr <= 24000 ? 576 : 1152;
630 }
631
632
2/2
✓ Branch 0 taken 40481 times.
✓ Branch 1 taken 102415 times.
142896 if (ba > 0) {
633 /* calc from block_align */
634
2/2
✓ Branch 0 taken 7259 times.
✓ Branch 1 taken 33222 times.
40481 if (id == AV_CODEC_ID_SIPR) {
635
4/5
✓ Branch 0 taken 3260 times.
✓ Branch 1 taken 1983 times.
✓ Branch 2 taken 1680 times.
✓ Branch 3 taken 336 times.
✗ Branch 4 not taken.
7259 switch (ba) {
636 3260 case 20: return 160;
637 1983 case 19: return 144;
638 1680 case 29: return 288;
639 336 case 37: return 480;
640 }
641
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33222 times.
33222 } else if (id == AV_CODEC_ID_ILBC) {
642 switch (ba) {
643 case 38: return 160;
644 case 50: return 240;
645 }
646 }
647 }
648
649
2/2
✓ Branch 0 taken 132527 times.
✓ Branch 1 taken 3110 times.
135637 if (frame_bytes > 0) {
650 /* calc from frame_bytes only */
651
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 132515 times.
132527 if (id == AV_CODEC_ID_TRUESPEECH)
652 12 return 240 * (frame_bytes / 32);
653
2/2
✓ Branch 0 taken 2074 times.
✓ Branch 1 taken 130441 times.
132515 if (id == AV_CODEC_ID_NELLYMOSER)
654 2074 return 256 * (frame_bytes / 64);
655
2/2
✓ Branch 0 taken 1057 times.
✓ Branch 1 taken 129384 times.
130441 if (id == AV_CODEC_ID_RA_144)
656 1057 return 160 * (frame_bytes / 20);
657
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 128924 times.
129384 if (id == AV_CODEC_ID_APTX)
658 460 return 4 * (frame_bytes / 4);
659
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 128464 times.
128924 if (id == AV_CODEC_ID_APTX_HD)
660 460 return 4 * (frame_bytes / 6);
661
662
2/2
✓ Branch 0 taken 45241 times.
✓ Branch 1 taken 83223 times.
128464 if (bps > 0) {
663 /* calc from frame_bytes and bits_per_coded_sample */
664
3/4
✓ Branch 0 taken 45135 times.
✓ Branch 1 taken 106 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 45135 times.
45241 if (id == AV_CODEC_ID_ADPCM_G726 || id == AV_CODEC_ID_ADPCM_G726LE)
665 106 return frame_bytes * 8 / bps;
666 }
667
668
3/4
✓ Branch 0 taken 128228 times.
✓ Branch 1 taken 130 times.
✓ Branch 2 taken 128228 times.
✗ Branch 3 not taken.
128358 if (ch > 0 && ch < INT_MAX/16) {
669 /* calc from frame_bytes and channels */
670
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 321 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 1311 times.
✓ Branch 16 taken 119191 times.
128228 switch (id) {
671 case AV_CODEC_ID_FASTAUDIO:
672 return frame_bytes / (40 * ch) * 256;
673 case AV_CODEC_ID_ADPCM_IMA_MOFLEX:
674 return (frame_bytes - 4 * ch) / (128 * ch) * 256;
675 48 case AV_CODEC_ID_ADPCM_AFC:
676 48 return frame_bytes / (9 * ch) * 16;
677 33 case AV_CODEC_ID_ADPCM_PSX:
678 case AV_CODEC_ID_ADPCM_DTK:
679 33 frame_bytes /= 16 * ch;
680
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
33 if (frame_bytes > INT_MAX / 28)
681 return 0;
682 33 return frame_bytes * 28;
683 452 case AV_CODEC_ID_ADPCM_4XM:
684 case AV_CODEC_ID_ADPCM_IMA_ACORN:
685 case AV_CODEC_ID_ADPCM_IMA_DAT4:
686 case AV_CODEC_ID_ADPCM_IMA_ISS:
687 452 return (frame_bytes - 4 * ch) * 2 / ch;
688 1951 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
689 1951 return (frame_bytes - 4) * 2 / ch;
690 case AV_CODEC_ID_ADPCM_IMA_AMV:
691 return (frame_bytes - 8) * 2;
692 3580 case AV_CODEC_ID_ADPCM_THP:
693 case AV_CODEC_ID_ADPCM_THP_LE:
694
2/2
✓ Branch 0 taken 3530 times.
✓ Branch 1 taken 50 times.
3580 if (extradata)
695 3530 return frame_bytes * 14LL / (8 * ch);
696 50 break;
697 222 case AV_CODEC_ID_ADPCM_XA:
698 222 return (frame_bytes / 128) * 224 / ch;
699 327 case AV_CODEC_ID_INTERPLAY_DPCM:
700 327 return (frame_bytes - 6 - ch) / ch;
701 680 case AV_CODEC_ID_ROQ_DPCM:
702 680 return (frame_bytes - 8) / ch;
703 112 case AV_CODEC_ID_XAN_DPCM:
704 112 return (frame_bytes - 2 * ch) / ch;
705 case AV_CODEC_ID_MACE3:
706 return 3 * frame_bytes / ch;
707 321 case AV_CODEC_ID_MACE6:
708 321 return 6 * frame_bytes / ch;
709 case AV_CODEC_ID_PCM_LXF:
710 return 2 * (frame_bytes / (5 * ch));
711 1311 case AV_CODEC_ID_IAC:
712 case AV_CODEC_ID_IMC:
713 1311 return 4 * frame_bytes / ch;
714 }
715
716
2/2
✓ Branch 0 taken 28140 times.
✓ Branch 1 taken 91101 times.
119241 if (tag) {
717 /* calc from frame_bytes, channels, and codec_tag */
718
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 28066 times.
28140 if (id == AV_CODEC_ID_SOL_DPCM) {
719
1/2
✓ Branch 0 taken 74 times.
✗ Branch 1 not taken.
74 if (tag == 3)
720 74 return frame_bytes / ch;
721 else
722 return frame_bytes * 2 / ch;
723 }
724 }
725
726
2/2
✓ Branch 0 taken 29800 times.
✓ Branch 1 taken 89367 times.
119167 if (ba > 0) {
727 /* calc from frame_bytes, channels, and block_align */
728 29800 int blocks = frame_bytes / ba;
729 29800 int64_t tmp = 0;
730
6/8
✓ Branch 0 taken 1007 times.
✓ Branch 1 taken 669 times.
✓ Branch 2 taken 649 times.
✓ Branch 3 taken 1001 times.
✓ Branch 4 taken 890 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 25584 times.
29800 switch (id) {
731 1007 case AV_CODEC_ID_ADPCM_IMA_WAV:
732
2/4
✓ Branch 0 taken 1007 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1007 times.
1007 if (bps < 2 || bps > 5)
733 return 0;
734 1007 tmp = blocks * (1LL + (ba - 4 * ch) / (bps * ch) * 8);
735 1007 break;
736 669 case AV_CODEC_ID_ADPCM_IMA_DK3:
737 669 tmp = blocks * (((ba - 16LL) * 2 / 3 * 4) / ch);
738 669 break;
739 649 case AV_CODEC_ID_ADPCM_IMA_DK4:
740 649 tmp = blocks * (1 + (ba - 4LL * ch) * 2 / ch);
741 649 break;
742 1001 case AV_CODEC_ID_ADPCM_IMA_RAD:
743 1001 tmp = blocks * ((ba - 4LL * ch) * 2 / ch);
744 1001 break;
745 890 case AV_CODEC_ID_ADPCM_MS:
746 890 tmp = blocks * (2 + (ba - 7LL * ch) * 2LL / ch);
747 890 break;
748 case AV_CODEC_ID_ADPCM_MTAF:
749 tmp = blocks * (ba - 16LL) * 2 / ch;
750 break;
751 case AV_CODEC_ID_ADPCM_XMD:
752 tmp = blocks * 32;
753 break;
754 }
755
2/2
✓ Branch 0 taken 4216 times.
✓ Branch 1 taken 25584 times.
29800 if (tmp) {
756
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4216 times.
4216 if (tmp != (int)tmp)
757 return 0;
758 4216 return tmp;
759 }
760 }
761
762
2/2
✓ Branch 0 taken 36984 times.
✓ Branch 1 taken 77967 times.
114951 if (bps > 0) {
763 /* calc from frame_bytes, channels, and bits_per_coded_sample */
764
2/4
✓ Branch 0 taken 20842 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 16142 times.
36984 switch (id) {
765 20842 case AV_CODEC_ID_PCM_DVD:
766
2/4
✓ Branch 0 taken 20842 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 20842 times.
20842 if(bps<4 || frame_bytes<3)
767 return 0;
768 20842 return 2 * ((frame_bytes - 3) / ((bps * 2 / 8) * ch));
769 case AV_CODEC_ID_PCM_BLURAY:
770 if(bps<4 || frame_bytes<4)
771 return 0;
772 return (frame_bytes - 4) / ((FFALIGN(ch, 2) * bps) / 8);
773 case AV_CODEC_ID_S302M:
774 return 2 * (frame_bytes / ((bps + 4) / 4)) / ch;
775 }
776 }
777 }
778 }
779
780 /* Fall back on using frame_size */
781
4/4
✓ Branch 0 taken 48428 times.
✓ Branch 1 taken 48921 times.
✓ Branch 2 taken 48305 times.
✓ Branch 3 taken 123 times.
97349 if (frame_size > 1 && frame_bytes)
782 48305 return frame_size;
783
784 //For WMA we currently have no other means to calculate duration thus we
785 //do it here by assuming CBR, which is true for all known cases.
786
8/8
✓ Branch 0 taken 31615 times.
✓ Branch 1 taken 17429 times.
✓ Branch 2 taken 28521 times.
✓ Branch 3 taken 3094 times.
✓ Branch 4 taken 28490 times.
✓ Branch 5 taken 31 times.
✓ Branch 6 taken 9596 times.
✓ Branch 7 taken 18894 times.
49044 if (bitrate > 0 && frame_bytes > 0 && sr > 0 && ba > 1) {
787
4/4
✓ Branch 0 taken 9391 times.
✓ Branch 1 taken 205 times.
✓ Branch 2 taken 723 times.
✓ Branch 3 taken 8668 times.
9596 if (id == AV_CODEC_ID_WMAV1 || id == AV_CODEC_ID_WMAV2)
788 928 return (frame_bytes * 8LL * sr) / bitrate;
789 }
790
791 48116 return 0;
792 }
793
794 41565 int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
795 {
796 41565 int channels = avctx->ch_layout.nb_channels;
797 int duration;
798 #if FF_API_OLD_CHANNEL_LAYOUT
799 FF_DISABLE_DEPRECATION_WARNINGS
800
2/2
✓ Branch 0 taken 82 times.
✓ Branch 1 taken 41483 times.
41565 if (!channels)
801 82 channels = avctx->channels;
802 FF_ENABLE_DEPRECATION_WARNINGS
803 #endif
804 41565 duration = get_audio_frame_duration(avctx->codec_id, avctx->sample_rate,
805 channels, avctx->block_align,
806 avctx->codec_tag, avctx->bits_per_coded_sample,
807 avctx->bit_rate, avctx->extradata, avctx->frame_size,
808 frame_bytes);
809 41565 return FFMAX(0, duration);
810 }
811
812 549022 int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
813 {
814 549022 int channels = par->ch_layout.nb_channels;
815 int duration;
816 #if FF_API_OLD_CHANNEL_LAYOUT
817 FF_DISABLE_DEPRECATION_WARNINGS
818
2/2
✓ Branch 0 taken 2991 times.
✓ Branch 1 taken 546031 times.
549022 if (!channels)
819 2991 channels = par->channels;
820 FF_ENABLE_DEPRECATION_WARNINGS
821 #endif
822 549022 duration = get_audio_frame_duration(par->codec_id, par->sample_rate,
823 channels, par->block_align,
824 par->codec_tag, par->bits_per_coded_sample,
825 par->bit_rate, par->extradata, par->frame_size,
826 frame_bytes);
827 549022 return FFMAX(0, duration);
828 }
829
830 #if !HAVE_THREADS
831 int ff_thread_init(AVCodecContext *s)
832 {
833 return -1;
834 }
835
836 #endif
837
838 56 unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
839 {
840 56 unsigned int n = 0;
841
842
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
56 while (v >= 0xff) {
843 *s++ = 0xff;
844 v -= 0xff;
845 n++;
846 }
847 56 *s = v;
848 56 n++;
849 56 return n;
850 }
851
852 476 int ff_match_2uint16(const uint16_t(*tab)[2], int size, int a, int b)
853 {
854 int i;
855
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++) ;
856 476 return i;
857 }
858
859 14517 const AVCodecHWConfig *avcodec_get_hw_config(const AVCodec *avcodec, int index)
860 {
861 14517 const FFCodec *const codec = ffcodec(avcodec);
862 int i;
863
3/4
✓ Branch 0 taken 2547 times.
✓ Branch 1 taken 11970 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2547 times.
14517 if (!codec->hw_configs || index < 0)
864 11970 return NULL;
865
2/2
✓ Branch 0 taken 4983 times.
✓ Branch 1 taken 1651 times.
6634 for (i = 0; i <= index; i++)
866
2/2
✓ Branch 0 taken 896 times.
✓ Branch 1 taken 4087 times.
4983 if (!codec->hw_configs[i])
867 896 return NULL;
868 1651 return &codec->hw_configs[index]->public;
869 }
870
871 129927 int ff_thread_ref_frame(ThreadFrame *dst, const ThreadFrame *src)
872 {
873 int ret;
874
875 129927 dst->owner[0] = src->owner[0];
876 129927 dst->owner[1] = src->owner[1];
877
878 129927 ret = av_frame_ref(dst->f, src->f);
879
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 129927 times.
129927 if (ret < 0)
880 return ret;
881
882
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 129927 times.
129927 av_assert0(!dst->progress);
883
884
2/2
✓ Branch 0 taken 244 times.
✓ Branch 1 taken 129683 times.
129927 if (src->progress)
885 244 dst->progress = ff_refstruct_ref(src->progress);
886
887 129927 return 0;
888 }
889
890 318 int ff_thread_replace_frame(ThreadFrame *dst, const ThreadFrame *src)
891 {
892 int ret;
893
894 318 dst->owner[0] = src->owner[0];
895 318 dst->owner[1] = src->owner[1];
896
897 318 ret = av_frame_replace(dst->f, src->f);
898
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 318 times.
318 if (ret < 0)
899 return ret;
900
901 318 ff_refstruct_replace(&dst->progress, src->progress);
902
903 318 return 0;
904 }
905
906 #if !HAVE_THREADS
907
908 int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f, int flags)
909 {
910 return ff_get_buffer(avctx, f, flags);
911 }
912
913 int ff_thread_get_ext_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
914 {
915 f->owner[0] = f->owner[1] = avctx;
916 return ff_get_buffer(avctx, f->f, flags);
917 }
918
919 void ff_thread_release_ext_buffer(ThreadFrame *f)
920 {
921 f->owner[0] = f->owner[1] = NULL;
922 if (f->f)
923 av_frame_unref(f->f);
924 }
925
926 void ff_thread_finish_setup(AVCodecContext *avctx)
927 {
928 }
929
930 void ff_thread_report_progress(ThreadFrame *f, int progress, int field)
931 {
932 }
933
934 void ff_thread_await_progress(const ThreadFrame *f, int progress, int field)
935 {
936 }
937
938 int ff_thread_can_start_frame(AVCodecContext *avctx)
939 {
940 return 1;
941 }
942
943 int ff_slice_thread_init_progress(AVCodecContext *avctx)
944 {
945 return 0;
946 }
947
948 int ff_slice_thread_allocz_entries(AVCodecContext *avctx, int count)
949 {
950 return 0;
951 }
952
953 void ff_thread_await_progress2(AVCodecContext *avctx, int field, int thread, int shift)
954 {
955 }
956
957 void ff_thread_report_progress2(AVCodecContext *avctx, int field, int thread, int n)
958 {
959 }
960
961 #endif
962
963 654655 const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p,
964 const uint8_t *end,
965 uint32_t *av_restrict state)
966 {
967 int i;
968
969
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 654655 times.
654655 av_assert0(p <= end);
970
2/2
✓ Branch 0 taken 913 times.
✓ Branch 1 taken 653742 times.
654655 if (p >= end)
971 913 return end;
972
973
2/2
✓ Branch 0 taken 1955712 times.
✓ Branch 1 taken 649891 times.
2605603 for (i = 0; i < 3; i++) {
974 1955712 uint32_t tmp = *state << 8;
975 1955712 *state = tmp + *(p++);
976
4/4
✓ Branch 0 taken 1954844 times.
✓ Branch 1 taken 868 times.
✓ Branch 2 taken 2983 times.
✓ Branch 3 taken 1951861 times.
1955712 if (tmp == 0x100 || p == end)
977 3851 return p;
978 }
979
980
2/2
✓ Branch 0 taken 180917385 times.
✓ Branch 1 taken 67296 times.
180984681 while (p < end) {
981
2/2
✓ Branch 0 taken 152664896 times.
✓ Branch 1 taken 28252489 times.
180917385 if (p[-1] > 1 ) p += 3;
982
2/2
✓ Branch 0 taken 8502605 times.
✓ Branch 1 taken 19749884 times.
28252489 else if (p[-2] ) p += 2;
983
2/2
✓ Branch 0 taken 19167289 times.
✓ Branch 1 taken 582595 times.
19749884 else if (p[-3]|(p[-1]-1)) p++;
984 else {
985 582595 p++;
986 582595 break;
987 }
988 }
989
990
2/2
✓ Branch 0 taken 42538 times.
✓ Branch 1 taken 607353 times.
649891 p = FFMIN(p, end) - 4;
991 649891 *state = AV_RB32(p);
992
993 649891 return p + 4;
994 }
995
996 409 AVCPBProperties *av_cpb_properties_alloc(size_t *size)
997 {
998 409 AVCPBProperties *props = av_mallocz(sizeof(AVCPBProperties));
999
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 409 times.
409 if (!props)
1000 return NULL;
1001
1002
1/2
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
409 if (size)
1003 409 *size = sizeof(*props);
1004
1005 409 props->vbv_delay = UINT64_MAX;
1006
1007 409 return props;
1008 }
1009
1010 static unsigned bcd2uint(uint8_t bcd)
1011 {
1012 unsigned low = bcd & 0xf;
1013 unsigned high = bcd >> 4;
1014 if (low > 9 || high > 9)
1015 return 0;
1016 return low + 10*high;
1017 }
1018
1019 int ff_alloc_timecode_sei(const AVFrame *frame, AVRational rate, size_t prefix_len,
1020 void **data, size_t *sei_size)
1021 {
1022 AVFrameSideData *sd = NULL;
1023 uint8_t *sei_data;
1024 PutBitContext pb;
1025 uint32_t *tc;
1026 int m;
1027
1028 if (frame)
1029 sd = av_frame_get_side_data(frame, AV_FRAME_DATA_S12M_TIMECODE);
1030
1031 if (!sd) {
1032 *data = NULL;
1033 return 0;
1034 }
1035 tc = (uint32_t*)sd->data;
1036 m = tc[0] & 3;
1037
1038 *sei_size = sizeof(uint32_t) * 4;
1039 *data = av_mallocz(*sei_size + prefix_len);
1040 if (!*data)
1041 return AVERROR(ENOMEM);
1042 sei_data = (uint8_t*)*data + prefix_len;
1043
1044 init_put_bits(&pb, sei_data, *sei_size);
1045 put_bits(&pb, 2, m); // num_clock_ts
1046
1047 for (int j = 1; j <= m; j++) {
1048 uint32_t tcsmpte = tc[j];
1049 unsigned hh = bcd2uint(tcsmpte & 0x3f); // 6-bit hours
1050 unsigned mm = bcd2uint(tcsmpte>>8 & 0x7f); // 7-bit minutes
1051 unsigned ss = bcd2uint(tcsmpte>>16 & 0x7f); // 7-bit seconds
1052 unsigned ff = bcd2uint(tcsmpte>>24 & 0x3f); // 6-bit frames
1053 unsigned drop = tcsmpte & 1<<30 && !0; // 1-bit drop if not arbitrary bit
1054
1055 /* Calculate frame number of HEVC by SMPTE ST 12-1:2014 Sec 12.2 if rate > 30FPS */
1056 if (av_cmp_q(rate, (AVRational) {30, 1}) == 1) {
1057 unsigned pc;
1058 ff *= 2;
1059 if (av_cmp_q(rate, (AVRational) {50, 1}) == 0)
1060 pc = !!(tcsmpte & 1 << 7);
1061 else
1062 pc = !!(tcsmpte & 1 << 23);
1063 ff = (ff + pc) & 0x7f;
1064 }
1065
1066 put_bits(&pb, 1, 1); // clock_timestamp_flag
1067 put_bits(&pb, 1, 1); // units_field_based_flag
1068 put_bits(&pb, 5, 0); // counting_type
1069 put_bits(&pb, 1, 1); // full_timestamp_flag
1070 put_bits(&pb, 1, 0); // discontinuity_flag
1071 put_bits(&pb, 1, drop);
1072 put_bits(&pb, 9, ff);
1073 put_bits(&pb, 6, ss);
1074 put_bits(&pb, 6, mm);
1075 put_bits(&pb, 5, hh);
1076 put_bits(&pb, 5, 0);
1077 }
1078 flush_put_bits(&pb);
1079
1080 return 0;
1081 }
1082
1083 17161 int64_t ff_guess_coded_bitrate(AVCodecContext *avctx)
1084 {
1085 17161 AVRational framerate = avctx->framerate;
1086 17161 int bits_per_coded_sample = avctx->bits_per_coded_sample;
1087 int64_t bitrate;
1088
1089
3/4
✓ Branch 0 taken 17132 times.
✓ Branch 1 taken 29 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 17132 times.
17161 if (!(framerate.num && framerate.den))
1090 29 framerate = av_inv_q(avctx->time_base);
1091
2/4
✓ Branch 0 taken 17161 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 17161 times.
17161 if (!(framerate.num && framerate.den))
1092 return 0;
1093
1094
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17161 times.
17161 if (!bits_per_coded_sample) {
1095 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
1096 bits_per_coded_sample = av_get_bits_per_pixel(desc);
1097 }
1098 17161 bitrate = (int64_t)bits_per_coded_sample * avctx->width * avctx->height *
1099 17161 framerate.num / framerate.den;
1100
1101 17161 return bitrate;
1102 }
1103