FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/utils.c
Date: 2024-07-14 13:34:57
Exec Total Coverage
Lines: 381 520 73.3%
Functions: 25 30 83.3%
Branches: 285 396 72.0%

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 200014 void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
53 {
54 200014 uint8_t **p = ptr;
55
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 200014 times.
200014 if (min_size > SIZE_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
56 av_freep(p);
57 *size = 0;
58 return;
59 }
60 200014 av_fast_mallocz(p, size, min_size + AV_INPUT_BUFFER_PADDING_SIZE);
61
1/2
✓ Branch 0 taken 200014 times.
✗ Branch 1 not taken.
200014 if (*p)
62 200014 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 7519947 int av_codec_is_encoder(const AVCodec *avcodec)
79 {
80 7519947 const FFCodec *const codec = ffcodec(avcodec);
81
4/4
✓ Branch 0 taken 7511729 times.
✓ Branch 1 taken 8218 times.
✓ Branch 2 taken 4617052 times.
✓ Branch 3 taken 2894677 times.
12136999 return codec && (codec->cb_type == FF_CODEC_CB_TYPE_ENCODE ||
82
2/2
✓ Branch 0 taken 4544261 times.
✓ Branch 1 taken 72791 times.
4617052 codec->cb_type == FF_CODEC_CB_TYPE_ENCODE_SUB ||
83
2/2
✓ Branch 0 taken 78948 times.
✓ Branch 1 taken 4465313 times.
4544261 codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_PACKET);
84 }
85
86 12121578 int av_codec_is_decoder(const AVCodec *avcodec)
87 {
88 12121578 const FFCodec *const codec = ffcodec(avcodec);
89
4/4
✓ Branch 0 taken 12113360 times.
✓ Branch 1 taken 8218 times.
✓ Branch 2 taken 4810844 times.
✓ Branch 3 taken 7302516 times.
16932422 return codec && (codec->cb_type == FF_CODEC_CB_TYPE_DECODE ||
90
2/2
✓ Branch 0 taken 4795075 times.
✓ Branch 1 taken 15769 times.
4810844 codec->cb_type == FF_CODEC_CB_TYPE_DECODE_SUB ||
91
2/2
✓ Branch 0 taken 179541 times.
✓ Branch 1 taken 4615534 times.
4795075 codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_FRAME);
92 }
93
94 67672 int ff_set_dimensions(AVCodecContext *s, int width, int height)
95 {
96 67672 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 67671 times.
67672 if (ret < 0)
99 1 width = height = 0;
100
101 67672 s->coded_width = width;
102 67672 s->coded_height = height;
103 67672 s->width = AV_CEIL_RSHIFT(width, s->lowres);
104 67672 s->height = AV_CEIL_RSHIFT(height, s->lowres);
105
106 67672 return ret;
107 }
108
109 2837 int ff_set_sar(AVCodecContext *avctx, AVRational sar)
110 {
111 2837 int ret = av_image_check_sar(avctx->width, avctx->height, sar);
112
113
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2832 times.
2837 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 2832 avctx->sample_aspect_ratio = sar;
120 }
121 2832 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 10060 void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height,
145 int linesize_align[AV_NUM_DATA_POINTERS])
146 {
147 int i;
148 10060 int w_align = 1;
149 10060 int h_align = 1;
150 10060 AVPixFmtDescriptor const *desc = av_pix_fmt_desc_get(s->pix_fmt);
151
152
1/2
✓ Branch 0 taken 10060 times.
✗ Branch 1 not taken.
10060 if (desc) {
153 10060 w_align = 1 << desc->log2_chroma_w;
154 10060 h_align = 1 << desc->log2_chroma_h;
155 }
156
157
9/9
✓ Branch 0 taken 9138 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 211 times.
✓ Branch 7 taken 27 times.
✓ Branch 8 taken 385 times.
10060 switch (s->pix_fmt) {
158 9138 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 9138 w_align = 16; //FIXME assume 16 pixel per macroblock
248 9138 h_align = 16 * 2; // interlaced needs 2 macroblocks height
249
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 9135 times.
9138 if (s->codec_id == AV_CODEC_ID_BINKVIDEO)
250 3 w_align = 16*2;
251 9138 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 211 case AV_PIX_FMT_RGB24:
307
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 204 times.
211 if (s->codec_id == AV_CODEC_ID_CINEPAK) {
308 7 w_align = 4;
309 7 h_align = 4;
310 }
311 211 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 385 default:
319 385 break;
320 }
321
322
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 10058 times.
10060 if (s->codec_id == AV_CODEC_ID_IFF_ILBM) {
323 2 w_align = FFMAX(w_align, 16);
324 }
325
326 10060 *width = FFALIGN(*width, w_align);
327 10060 *height = FFALIGN(*height, h_align);
328
4/4
✓ Branch 0 taken 9478 times.
✓ Branch 1 taken 582 times.
✓ Branch 2 taken 9477 times.
✓ Branch 3 taken 1 times.
10060 if (s->codec_id == AV_CODEC_ID_H264 || s->lowres ||
329
4/4
✓ Branch 0 taken 9462 times.
✓ Branch 1 taken 15 times.
✓ Branch 2 taken 9455 times.
✓ Branch 3 taken 7 times.
9477 s->codec_id == AV_CODEC_ID_VC1 || s->codec_id == AV_CODEC_ID_WMV3 ||
330
4/4
✓ Branch 0 taken 9454 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 9447 times.
✓ Branch 3 taken 7 times.
9455 s->codec_id == AV_CODEC_ID_VP5 || s->codec_id == AV_CODEC_ID_VP6 ||
331
4/4
✓ Branch 0 taken 9445 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 9443 times.
9447 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 7442 times.
10060 if (s->codec_id == AV_CODEC_ID_SVQ3) {
344 2618 *width = FFMAX(*width, 32);
345 }
346
347
2/2
✓ Branch 0 taken 40240 times.
✓ Branch 1 taken 10060 times.
50300 for (i = 0; i < 4; i++)
348 40240 linesize_align[i] = STRIDE_ALIGN;
349 10060 }
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
366 int avcodec_fill_audio_frame(AVFrame *frame, int nb_channels,
367 enum AVSampleFormat sample_fmt, const uint8_t *buf,
368 int buf_size, int align)
369 {
370 int ch, planar, needed_size, ret = 0;
371
372 needed_size = av_samples_get_buffer_size(NULL, nb_channels,
373 frame->nb_samples, sample_fmt,
374 align);
375 if (buf_size < needed_size)
376 return AVERROR(EINVAL);
377
378 planar = av_sample_fmt_is_planar(sample_fmt);
379 if (planar && nb_channels > AV_NUM_DATA_POINTERS) {
380 if (!FF_ALLOCZ_TYPED_ARRAY(frame->extended_data, nb_channels))
381 return AVERROR(ENOMEM);
382 } else {
383 frame->extended_data = frame->data;
384 }
385
386 if ((ret = av_samples_fill_arrays(frame->extended_data, &frame->linesize[0],
387 (uint8_t *)(intptr_t)buf, nb_channels, frame->nb_samples,
388 sample_fmt, align)) < 0) {
389 if (frame->extended_data != frame->data)
390 av_freep(&frame->extended_data);
391 return ret;
392 }
393 if (frame->extended_data != frame->data) {
394 for (ch = 0; ch < AV_NUM_DATA_POINTERS; ch++)
395 frame->data[ch] = frame->extended_data[ch];
396 }
397
398 return ret;
399 }
400
401
402 183151 int avpriv_codec_get_cap_skip_frame_fill_param(const AVCodec *codec){
403 183151 return !!(ffcodec(codec)->caps_internal & FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM);
404 }
405
406 26349 const char *avcodec_get_name(enum AVCodecID id)
407 {
408 const AVCodecDescriptor *cd;
409 const AVCodec *codec;
410
411
2/2
✓ Branch 0 taken 239 times.
✓ Branch 1 taken 26110 times.
26349 if (id == AV_CODEC_ID_NONE)
412 239 return "none";
413 26110 cd = avcodec_descriptor_get(id);
414
2/2
✓ Branch 0 taken 26106 times.
✓ Branch 1 taken 4 times.
26110 if (cd)
415 26106 return cd->name;
416 4 av_log(NULL, AV_LOG_WARNING, "Codec 0x%x is not in the full list.\n", id);
417 4 codec = avcodec_find_decoder(id);
418
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (codec)
419 return codec->name;
420 4 codec = avcodec_find_encoder(id);
421
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (codec)
422 return codec->name;
423 4 return "unknown_codec";
424 }
425
426 const char *av_get_profile_name(const AVCodec *codec, int profile)
427 {
428 const AVProfile *p;
429 if (profile == AV_PROFILE_UNKNOWN || !codec->profiles)
430 return NULL;
431
432 for (p = codec->profiles; p->profile != AV_PROFILE_UNKNOWN; p++)
433 if (p->profile == profile)
434 return p->name;
435
436 return NULL;
437 }
438
439 14911 const char *avcodec_profile_name(enum AVCodecID codec_id, int profile)
440 {
441 14911 const AVCodecDescriptor *desc = avcodec_descriptor_get(codec_id);
442 const AVProfile *p;
443
444
5/6
✓ Branch 0 taken 2085 times.
✓ Branch 1 taken 12826 times.
✓ Branch 2 taken 2085 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 132 times.
✓ Branch 5 taken 1953 times.
14911 if (profile == AV_PROFILE_UNKNOWN || !desc || !desc->profiles)
445 12958 return NULL;
446
447
2/2
✓ Branch 0 taken 5052 times.
✓ Branch 1 taken 30 times.
5082 for (p = desc->profiles; p->profile != AV_PROFILE_UNKNOWN; p++)
448
2/2
✓ Branch 0 taken 1923 times.
✓ Branch 1 taken 3129 times.
5052 if (p->profile == profile)
449 1923 return p->name;
450
451 30 return NULL;
452 }
453
454 806769 int av_get_exact_bits_per_sample(enum AVCodecID codec_id)
455 {
456
8/8
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 11407 times.
✓ Branch 2 taken 10029 times.
✓ Branch 3 taken 502036 times.
✓ Branch 4 taken 17029 times.
✓ Branch 5 taken 23894 times.
✓ Branch 6 taken 18405 times.
✓ Branch 7 taken 223945 times.
806769 switch (codec_id) {
457 24 case AV_CODEC_ID_DFPWM:
458 24 return 1;
459 11407 case AV_CODEC_ID_8SVX_EXP:
460 case AV_CODEC_ID_8SVX_FIB:
461 case AV_CODEC_ID_ADPCM_ARGO:
462 case AV_CODEC_ID_ADPCM_CT:
463 case AV_CODEC_ID_ADPCM_IMA_ALP:
464 case AV_CODEC_ID_ADPCM_IMA_AMV:
465 case AV_CODEC_ID_ADPCM_IMA_APC:
466 case AV_CODEC_ID_ADPCM_IMA_APM:
467 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
468 case AV_CODEC_ID_ADPCM_IMA_OKI:
469 case AV_CODEC_ID_ADPCM_IMA_WS:
470 case AV_CODEC_ID_ADPCM_IMA_SSI:
471 case AV_CODEC_ID_ADPCM_G722:
472 case AV_CODEC_ID_ADPCM_YAMAHA:
473 case AV_CODEC_ID_ADPCM_AICA:
474 11407 return 4;
475 10029 case AV_CODEC_ID_DSD_LSBF:
476 case AV_CODEC_ID_DSD_MSBF:
477 case AV_CODEC_ID_DSD_LSBF_PLANAR:
478 case AV_CODEC_ID_DSD_MSBF_PLANAR:
479 case AV_CODEC_ID_PCM_ALAW:
480 case AV_CODEC_ID_PCM_MULAW:
481 case AV_CODEC_ID_PCM_VIDC:
482 case AV_CODEC_ID_PCM_S8:
483 case AV_CODEC_ID_PCM_S8_PLANAR:
484 case AV_CODEC_ID_PCM_SGA:
485 case AV_CODEC_ID_PCM_U8:
486 case AV_CODEC_ID_SDX2_DPCM:
487 case AV_CODEC_ID_CBD2_DPCM:
488 case AV_CODEC_ID_DERF_DPCM:
489 case AV_CODEC_ID_WADY_DPCM:
490 10029 return 8;
491 502036 case AV_CODEC_ID_PCM_S16BE:
492 case AV_CODEC_ID_PCM_S16BE_PLANAR:
493 case AV_CODEC_ID_PCM_S16LE:
494 case AV_CODEC_ID_PCM_S16LE_PLANAR:
495 case AV_CODEC_ID_PCM_U16BE:
496 case AV_CODEC_ID_PCM_U16LE:
497 502036 return 16;
498 17029 case AV_CODEC_ID_PCM_S24DAUD:
499 case AV_CODEC_ID_PCM_S24BE:
500 case AV_CODEC_ID_PCM_S24LE:
501 case AV_CODEC_ID_PCM_S24LE_PLANAR:
502 case AV_CODEC_ID_PCM_U24BE:
503 case AV_CODEC_ID_PCM_U24LE:
504 17029 return 24;
505 23894 case AV_CODEC_ID_PCM_S32BE:
506 case AV_CODEC_ID_PCM_S32LE:
507 case AV_CODEC_ID_PCM_S32LE_PLANAR:
508 case AV_CODEC_ID_PCM_U32BE:
509 case AV_CODEC_ID_PCM_U32LE:
510 case AV_CODEC_ID_PCM_F32BE:
511 case AV_CODEC_ID_PCM_F32LE:
512 case AV_CODEC_ID_PCM_F24LE:
513 case AV_CODEC_ID_PCM_F16LE:
514 23894 return 32;
515 18405 case AV_CODEC_ID_PCM_F64BE:
516 case AV_CODEC_ID_PCM_F64LE:
517 case AV_CODEC_ID_PCM_S64BE:
518 case AV_CODEC_ID_PCM_S64LE:
519 18405 return 64;
520 223945 default:
521 223945 return 0;
522 }
523 }
524
525 24 enum AVCodecID av_get_pcm_codec(enum AVSampleFormat fmt, int be)
526 {
527 static const enum AVCodecID map[][2] = {
528 [AV_SAMPLE_FMT_U8 ] = { AV_CODEC_ID_PCM_U8, AV_CODEC_ID_PCM_U8 },
529 [AV_SAMPLE_FMT_S16 ] = { AV_CODEC_ID_PCM_S16LE, AV_CODEC_ID_PCM_S16BE },
530 [AV_SAMPLE_FMT_S32 ] = { AV_CODEC_ID_PCM_S32LE, AV_CODEC_ID_PCM_S32BE },
531 [AV_SAMPLE_FMT_FLT ] = { AV_CODEC_ID_PCM_F32LE, AV_CODEC_ID_PCM_F32BE },
532 [AV_SAMPLE_FMT_DBL ] = { AV_CODEC_ID_PCM_F64LE, AV_CODEC_ID_PCM_F64BE },
533 [AV_SAMPLE_FMT_U8P ] = { AV_CODEC_ID_PCM_U8, AV_CODEC_ID_PCM_U8 },
534 [AV_SAMPLE_FMT_S16P] = { AV_CODEC_ID_PCM_S16LE, AV_CODEC_ID_PCM_S16BE },
535 [AV_SAMPLE_FMT_S32P] = { AV_CODEC_ID_PCM_S32LE, AV_CODEC_ID_PCM_S32BE },
536 [AV_SAMPLE_FMT_S64P] = { AV_CODEC_ID_PCM_S64LE, AV_CODEC_ID_PCM_S64BE },
537 [AV_SAMPLE_FMT_FLTP] = { AV_CODEC_ID_PCM_F32LE, AV_CODEC_ID_PCM_F32BE },
538 [AV_SAMPLE_FMT_DBLP] = { AV_CODEC_ID_PCM_F64LE, AV_CODEC_ID_PCM_F64BE },
539 };
540
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))
541 return AV_CODEC_ID_NONE;
542
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)
543 24 be = AV_NE(1, 0);
544 24 return map[fmt][be];
545 }
546
547 285950 int av_get_bits_per_sample(enum AVCodecID codec_id)
548 {
549
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 285853 times.
285950 switch (codec_id) {
550 17 case AV_CODEC_ID_DFPWM:
551 17 return 1;
552 3 case AV_CODEC_ID_ADPCM_SBPRO_2:
553 3 return 2;
554 3 case AV_CODEC_ID_ADPCM_SBPRO_3:
555 3 return 3;
556 74 case AV_CODEC_ID_ADPCM_SBPRO_4:
557 case AV_CODEC_ID_ADPCM_IMA_WAV:
558 case AV_CODEC_ID_ADPCM_IMA_QT:
559 case AV_CODEC_ID_ADPCM_SWF:
560 case AV_CODEC_ID_ADPCM_MS:
561 74 return 4;
562 285853 default:
563 285853 return av_get_exact_bits_per_sample(codec_id);
564 }
565 }
566
567 513220 static int get_audio_frame_duration(enum AVCodecID id, int sr, int ch, int ba,
568 uint32_t tag, int bits_per_coded_sample, int64_t bitrate,
569 uint8_t * extradata, int frame_size, int frame_bytes)
570 {
571 513220 int bps = av_get_exact_bits_per_sample(id);
572
4/4
✓ Branch 0 taken 355734 times.
✓ Branch 1 taken 157486 times.
✓ Branch 2 taken 355429 times.
✓ Branch 3 taken 305 times.
513220 int framecount = (ba > 0 && frame_bytes / ba > 0) ? frame_bytes / ba : 1;
573
574 /* codecs with an exact constant bits per sample */
575
7/10
✓ Branch 0 taken 298364 times.
✓ Branch 1 taken 214856 times.
✓ Branch 2 taken 298364 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 298328 times.
✓ Branch 5 taken 36 times.
✓ Branch 6 taken 298328 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 298328 times.
✗ Branch 9 not taken.
513220 if (bps > 0 && ch > 0 && frame_bytes > 0 && ch < 32768 && bps < 32768)
576 298328 return (frame_bytes * 8LL) / (bps * ch);
577 214892 bps = bits_per_coded_sample;
578
579 /* codecs with a fixed packet duration */
580
11/13
✓ Branch 0 taken 12407 times.
✓ Branch 1 taken 8274 times.
✓ Branch 2 taken 600 times.
✓ Branch 3 taken 5704 times.
✓ Branch 4 taken 1124 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 8595 times.
✓ Branch 7 taken 4339 times.
✓ Branch 8 taken 2184 times.
✓ Branch 9 taken 18574 times.
✓ Branch 10 taken 2236 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 150855 times.
214892 switch (id) {
581 12407 case AV_CODEC_ID_ADPCM_ADX: return 32;
582 8274 case AV_CODEC_ID_ADPCM_IMA_QT: return 64;
583 600 case AV_CODEC_ID_ADPCM_EA_XAS: return 128;
584 5704 case AV_CODEC_ID_AMR_NB:
585 case AV_CODEC_ID_EVRC:
586 case AV_CODEC_ID_GSM:
587 case AV_CODEC_ID_QCELP:
588 5704 case AV_CODEC_ID_RA_288: return 160;
589 1124 case AV_CODEC_ID_AMR_WB:
590 1124 case AV_CODEC_ID_GSM_MS: return 320;
591 case AV_CODEC_ID_MP1: return 384;
592 8595 case AV_CODEC_ID_ATRAC1: return 512;
593 4339 case AV_CODEC_ID_ATRAC9:
594 case AV_CODEC_ID_ATRAC3:
595
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4339 times.
4339 if (framecount > INT_MAX/1024)
596 return 0;
597 4339 return 1024 * framecount;
598 2184 case AV_CODEC_ID_ATRAC3P: return 2048;
599 18574 case AV_CODEC_ID_MP2:
600 18574 case AV_CODEC_ID_MUSEPACK7: return 1152;
601 2236 case AV_CODEC_ID_AC3: return 1536;
602 case AV_CODEC_ID_FTR: return 1024;
603 }
604
605
2/2
✓ Branch 0 taken 147783 times.
✓ Branch 1 taken 3072 times.
150855 if (sr > 0) {
606 /* calc from sample rate */
607
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 147766 times.
147783 if (id == AV_CODEC_ID_TTA)
608 17 return 256ll * sr / 245;
609
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 147766 times.
147766 else if (id == AV_CODEC_ID_DST)
610 return 588ll * sr / 44100;
611
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 147700 times.
147766 else if (id == AV_CODEC_ID_BINKAUDIO_DCT) {
612
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
66 if (sr / 22050 > 22)
613 return 0;
614 66 return (480 << (sr / 22050));
615 }
616
617
2/2
✓ Branch 0 taken 6742 times.
✓ Branch 1 taken 140958 times.
147700 if (id == AV_CODEC_ID_MP3)
618
2/2
✓ Branch 0 taken 224 times.
✓ Branch 1 taken 6518 times.
6742 return sr <= 24000 ? 576 : 1152;
619 }
620
621
2/2
✓ Branch 0 taken 41707 times.
✓ Branch 1 taken 102323 times.
144030 if (ba > 0) {
622 /* calc from block_align */
623
2/2
✓ Branch 0 taken 7259 times.
✓ Branch 1 taken 34448 times.
41707 if (id == AV_CODEC_ID_SIPR) {
624
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) {
625 3260 case 20: return 160;
626 1983 case 19: return 144;
627 1680 case 29: return 288;
628 336 case 37: return 480;
629 }
630
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 34448 times.
34448 } else if (id == AV_CODEC_ID_ILBC) {
631 switch (ba) {
632 case 38: return 160;
633 case 50: return 240;
634 }
635 }
636 }
637
638
2/2
✓ Branch 0 taken 133660 times.
✓ Branch 1 taken 3111 times.
136771 if (frame_bytes > 0) {
639 /* calc from frame_bytes only */
640
2/2
✓ Branch 0 taken 721 times.
✓ Branch 1 taken 132939 times.
133660 if (id == AV_CODEC_ID_TRUESPEECH)
641 721 return 240 * (frame_bytes / 32);
642
2/2
✓ Branch 0 taken 2074 times.
✓ Branch 1 taken 130865 times.
132939 if (id == AV_CODEC_ID_NELLYMOSER)
643 2074 return 256 * (frame_bytes / 64);
644
2/2
✓ Branch 0 taken 1057 times.
✓ Branch 1 taken 129808 times.
130865 if (id == AV_CODEC_ID_RA_144)
645 1057 return 160 * (frame_bytes / 20);
646
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 129348 times.
129808 if (id == AV_CODEC_ID_APTX)
647 460 return 4 * (frame_bytes / 4);
648
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 128888 times.
129348 if (id == AV_CODEC_ID_APTX_HD)
649 460 return 4 * (frame_bytes / 6);
650
651
2/2
✓ Branch 0 taken 45750 times.
✓ Branch 1 taken 83138 times.
128888 if (bps > 0) {
652 /* calc from frame_bytes and bits_per_coded_sample */
653
3/4
✓ Branch 0 taken 45290 times.
✓ Branch 1 taken 460 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 45290 times.
45750 if (id == AV_CODEC_ID_ADPCM_G726 || id == AV_CODEC_ID_ADPCM_G726LE)
654 460 return frame_bytes * 8 / bps;
655 }
656
657
3/4
✓ Branch 0 taken 128298 times.
✓ Branch 1 taken 130 times.
✓ Branch 2 taken 128298 times.
✗ Branch 3 not taken.
128428 if (ch > 0 && ch < INT_MAX/16) {
658 /* calc from frame_bytes and channels */
659
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 314 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 1311 times.
✓ Branch 16 taken 119268 times.
128298 switch (id) {
660 case AV_CODEC_ID_FASTAUDIO:
661 return frame_bytes / (40 * ch) * 256;
662 case AV_CODEC_ID_ADPCM_IMA_MOFLEX:
663 return (frame_bytes - 4 * ch) / (128 * ch) * 256;
664 48 case AV_CODEC_ID_ADPCM_AFC:
665 48 return frame_bytes / (9 * ch) * 16;
666 33 case AV_CODEC_ID_ADPCM_PSX:
667 case AV_CODEC_ID_ADPCM_DTK:
668 33 frame_bytes /= 16 * ch;
669
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
33 if (frame_bytes > INT_MAX / 28)
670 return 0;
671 33 return frame_bytes * 28;
672 452 case AV_CODEC_ID_ADPCM_4XM:
673 case AV_CODEC_ID_ADPCM_IMA_ACORN:
674 case AV_CODEC_ID_ADPCM_IMA_DAT4:
675 case AV_CODEC_ID_ADPCM_IMA_ISS:
676 452 return (frame_bytes - 4 * ch) * 2 / ch;
677 1951 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
678 1951 return (frame_bytes - 4) * 2 / ch;
679 case AV_CODEC_ID_ADPCM_IMA_AMV:
680 return (frame_bytes - 8) * 2;
681 3580 case AV_CODEC_ID_ADPCM_THP:
682 case AV_CODEC_ID_ADPCM_THP_LE:
683
2/2
✓ Branch 0 taken 3530 times.
✓ Branch 1 taken 50 times.
3580 if (extradata)
684 3530 return frame_bytes * 14LL / (8 * ch);
685 50 break;
686 222 case AV_CODEC_ID_ADPCM_XA:
687 222 return (frame_bytes / 128) * 224 / ch;
688 327 case AV_CODEC_ID_INTERPLAY_DPCM:
689 327 return (frame_bytes - 6 - ch) / ch;
690 680 case AV_CODEC_ID_ROQ_DPCM:
691 680 return (frame_bytes - 8) / ch;
692 112 case AV_CODEC_ID_XAN_DPCM:
693 112 return (frame_bytes - 2 * ch) / ch;
694 case AV_CODEC_ID_MACE3:
695 return 3 * frame_bytes / ch;
696 314 case AV_CODEC_ID_MACE6:
697 314 return 6 * frame_bytes / ch;
698 case AV_CODEC_ID_PCM_LXF:
699 return 2 * (frame_bytes / (5 * ch));
700 1311 case AV_CODEC_ID_IAC:
701 case AV_CODEC_ID_IMC:
702 1311 return 4 * frame_bytes / ch;
703 }
704
705
2/2
✓ Branch 0 taken 28301 times.
✓ Branch 1 taken 91017 times.
119318 if (tag) {
706 /* calc from frame_bytes, channels, and codec_tag */
707
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 28227 times.
28301 if (id == AV_CODEC_ID_SOL_DPCM) {
708
1/2
✓ Branch 0 taken 74 times.
✗ Branch 1 not taken.
74 if (tag == 3)
709 74 return frame_bytes / ch;
710 else
711 return frame_bytes * 2 / ch;
712 }
713 }
714
715
2/2
✓ Branch 0 taken 29970 times.
✓ Branch 1 taken 89274 times.
119244 if (ba > 0) {
716 /* calc from frame_bytes, channels, and block_align */
717 29970 int blocks = frame_bytes / ba;
718 29970 int64_t tmp = 0;
719
6/8
✓ Branch 0 taken 1055 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 25706 times.
29970 switch (id) {
720 1055 case AV_CODEC_ID_ADPCM_IMA_WAV:
721
2/4
✓ Branch 0 taken 1055 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1055 times.
1055 if (bps < 2 || bps > 5)
722 return 0;
723 1055 tmp = blocks * (1LL + (ba - 4 * ch) / (bps * ch) * 8);
724 1055 break;
725 669 case AV_CODEC_ID_ADPCM_IMA_DK3:
726 669 tmp = blocks * (((ba - 16LL) * 2 / 3 * 4) / ch);
727 669 break;
728 649 case AV_CODEC_ID_ADPCM_IMA_DK4:
729 649 tmp = blocks * (1 + (ba - 4LL * ch) * 2 / ch);
730 649 break;
731 1001 case AV_CODEC_ID_ADPCM_IMA_RAD:
732 1001 tmp = blocks * ((ba - 4LL * ch) * 2 / ch);
733 1001 break;
734 890 case AV_CODEC_ID_ADPCM_MS:
735 890 tmp = blocks * (2 + (ba - 7LL * ch) * 2LL / ch);
736 890 break;
737 case AV_CODEC_ID_ADPCM_MTAF:
738 tmp = blocks * (ba - 16LL) * 2 / ch;
739 break;
740 case AV_CODEC_ID_ADPCM_XMD:
741 tmp = blocks * 32;
742 break;
743 }
744
2/2
✓ Branch 0 taken 4264 times.
✓ Branch 1 taken 25706 times.
29970 if (tmp) {
745
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4264 times.
4264 if (tmp != (int)tmp)
746 return 0;
747 4264 return tmp;
748 }
749 }
750
751
2/2
✓ Branch 0 taken 37091 times.
✓ Branch 1 taken 77889 times.
114980 if (bps > 0) {
752 /* calc from frame_bytes, channels, and bits_per_coded_sample */
753
2/4
✓ Branch 0 taken 20831 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 16260 times.
37091 switch (id) {
754 20831 case AV_CODEC_ID_PCM_DVD:
755
2/4
✓ Branch 0 taken 20831 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 20831 times.
20831 if(bps<4 || frame_bytes<3)
756 return 0;
757 20831 return 2 * ((frame_bytes - 3) / ((bps * 2 / 8) * ch));
758 case AV_CODEC_ID_PCM_BLURAY:
759 if(bps<4 || frame_bytes<4)
760 return 0;
761 return (frame_bytes - 4) / ((FFALIGN(ch, 2) * bps) / 8);
762 case AV_CODEC_ID_S302M:
763 return 2 * (frame_bytes / ((bps + 4) / 4)) / ch;
764 }
765 }
766 }
767 }
768
769 /* Fall back on using frame_size */
770
4/4
✓ Branch 0 taken 52295 times.
✓ Branch 1 taken 45095 times.
✓ Branch 2 taken 52168 times.
✓ Branch 3 taken 127 times.
97390 if (frame_size > 1 && frame_bytes)
771 52168 return frame_size;
772
773 //For WMA we currently have no other means to calculate duration thus we
774 //do it here by assuming CBR, which is true for all known cases.
775
8/8
✓ Branch 0 taken 31156 times.
✓ Branch 1 taken 14066 times.
✓ Branch 2 taken 28061 times.
✓ Branch 3 taken 3095 times.
✓ Branch 4 taken 28030 times.
✓ Branch 5 taken 31 times.
✓ Branch 6 taken 9718 times.
✓ Branch 7 taken 18312 times.
45222 if (bitrate > 0 && frame_bytes > 0 && sr > 0 && ba > 1) {
776
4/4
✓ Branch 0 taken 9513 times.
✓ Branch 1 taken 205 times.
✓ Branch 2 taken 795 times.
✓ Branch 3 taken 8718 times.
9718 if (id == AV_CODEC_ID_WMAV1 || id == AV_CODEC_ID_WMAV2)
777 1000 return (frame_bytes * 8LL * sr) / bitrate;
778 }
779
780 44222 return 0;
781 }
782
783 45503 int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
784 {
785 45503 int channels = avctx->ch_layout.nb_channels;
786 int duration;
787
788 45503 duration = get_audio_frame_duration(avctx->codec_id, avctx->sample_rate,
789 channels, avctx->block_align,
790 avctx->codec_tag, avctx->bits_per_coded_sample,
791 avctx->bit_rate, avctx->extradata, avctx->frame_size,
792 frame_bytes);
793 45503 return FFMAX(0, duration);
794 }
795
796 467717 int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
797 {
798 467717 int channels = par->ch_layout.nb_channels;
799 int duration;
800
801 467717 duration = get_audio_frame_duration(par->codec_id, par->sample_rate,
802 channels, par->block_align,
803 par->codec_tag, par->bits_per_coded_sample,
804 par->bit_rate, par->extradata, par->frame_size,
805 frame_bytes);
806 467717 return FFMAX(0, duration);
807 }
808
809 #if !HAVE_THREADS
810 int ff_thread_init(AVCodecContext *s)
811 {
812 return -1;
813 }
814
815 #endif
816
817 56 unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
818 {
819 56 unsigned int n = 0;
820
821
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
56 while (v >= 0xff) {
822 *s++ = 0xff;
823 v -= 0xff;
824 n++;
825 }
826 56 *s = v;
827 56 n++;
828 56 return n;
829 }
830
831 476 int ff_match_2uint16(const uint16_t(*tab)[2], int size, int a, int b)
832 {
833 int i;
834
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++) ;
835 476 return i;
836 }
837
838 14543 const AVCodecHWConfig *avcodec_get_hw_config(const AVCodec *avcodec, int index)
839 {
840 14543 const FFCodec *const codec = ffcodec(avcodec);
841 int i;
842
3/4
✓ Branch 0 taken 2553 times.
✓ Branch 1 taken 11990 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2553 times.
14543 if (!codec->hw_configs || index < 0)
843 11990 return NULL;
844
2/2
✓ Branch 0 taken 4995 times.
✓ Branch 1 taken 1655 times.
6650 for (i = 0; i <= index; i++)
845
2/2
✓ Branch 0 taken 898 times.
✓ Branch 1 taken 4097 times.
4995 if (!codec->hw_configs[i])
846 898 return NULL;
847 1655 return &codec->hw_configs[index]->public;
848 }
849
850 27390 int ff_thread_ref_frame(ThreadFrame *dst, const ThreadFrame *src)
851 {
852 int ret;
853
854 27390 dst->owner[0] = src->owner[0];
855 27390 dst->owner[1] = src->owner[1];
856
857 27390 ret = av_frame_ref(dst->f, src->f);
858
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27390 times.
27390 if (ret < 0)
859 return ret;
860
861
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27390 times.
27390 av_assert0(!dst->progress);
862
863
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 27330 times.
27390 if (src->progress)
864 60 dst->progress = ff_refstruct_ref(src->progress);
865
866 27390 return 0;
867 }
868
869 318 int ff_thread_replace_frame(ThreadFrame *dst, const ThreadFrame *src)
870 {
871 int ret;
872
873 318 dst->owner[0] = src->owner[0];
874 318 dst->owner[1] = src->owner[1];
875
876 318 ret = av_frame_replace(dst->f, src->f);
877
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 318 times.
318 if (ret < 0)
878 return ret;
879
880 318 ff_refstruct_replace(&dst->progress, src->progress);
881
882 318 return 0;
883 }
884
885 #if !HAVE_THREADS
886
887 int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f, int flags)
888 {
889 return ff_get_buffer(avctx, f, flags);
890 }
891
892 int ff_thread_get_ext_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
893 {
894 f->owner[0] = f->owner[1] = avctx;
895 return ff_get_buffer(avctx, f->f, flags);
896 }
897
898 void ff_thread_release_ext_buffer(ThreadFrame *f)
899 {
900 f->owner[0] = f->owner[1] = NULL;
901 if (f->f)
902 av_frame_unref(f->f);
903 }
904
905 void ff_thread_finish_setup(AVCodecContext *avctx)
906 {
907 }
908
909 void ff_thread_report_progress(ThreadFrame *f, int progress, int field)
910 {
911 }
912
913 void ff_thread_await_progress(const ThreadFrame *f, int progress, int field)
914 {
915 }
916
917 int ff_thread_can_start_frame(AVCodecContext *avctx)
918 {
919 return 1;
920 }
921
922 int ff_slice_thread_init_progress(AVCodecContext *avctx)
923 {
924 return 0;
925 }
926
927 int ff_slice_thread_allocz_entries(AVCodecContext *avctx, int count)
928 {
929 return 0;
930 }
931
932 void ff_thread_await_progress2(AVCodecContext *avctx, int field, int thread, int shift)
933 {
934 }
935
936 void ff_thread_report_progress2(AVCodecContext *avctx, int field, int thread, int n)
937 {
938 }
939
940 #endif
941
942 662395 const uint8_t *avpriv_find_start_code(const uint8_t *restrict p,
943 const uint8_t *end,
944 uint32_t *restrict state)
945 {
946 int i;
947
948
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 662395 times.
662395 av_assert0(p <= end);
949
2/2
✓ Branch 0 taken 907 times.
✓ Branch 1 taken 661488 times.
662395 if (p >= end)
950 907 return end;
951
952
2/2
✓ Branch 0 taken 1978850 times.
✓ Branch 1 taken 657592 times.
2636442 for (i = 0; i < 3; i++) {
953 1978850 uint32_t tmp = *state << 8;
954 1978850 *state = tmp + *(p++);
955
4/4
✓ Branch 0 taken 1977985 times.
✓ Branch 1 taken 865 times.
✓ Branch 2 taken 3031 times.
✓ Branch 3 taken 1974954 times.
1978850 if (tmp == 0x100 || p == end)
956 3896 return p;
957 }
958
959
2/2
✓ Branch 0 taken 375495754 times.
✓ Branch 1 taken 66716 times.
375562470 while (p < end) {
960
2/2
✓ Branch 0 taken 338955102 times.
✓ Branch 1 taken 36540652 times.
375495754 if (p[-1] > 1 ) p += 3;
961
2/2
✓ Branch 0 taken 15378037 times.
✓ Branch 1 taken 21162615 times.
36540652 else if (p[-2] ) p += 2;
962
2/2
✓ Branch 0 taken 20571739 times.
✓ Branch 1 taken 590876 times.
21162615 else if (p[-3]|(p[-1]-1)) p++;
963 else {
964 590876 p++;
965 590876 break;
966 }
967 }
968
969
2/2
✓ Branch 0 taken 41887 times.
✓ Branch 1 taken 615705 times.
657592 p = FFMIN(p, end) - 4;
970 657592 *state = AV_RB32(p);
971
972 657592 return p + 4;
973 }
974
975 411 AVCPBProperties *av_cpb_properties_alloc(size_t *size)
976 {
977 411 AVCPBProperties *props = av_mallocz(sizeof(AVCPBProperties));
978
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 411 times.
411 if (!props)
979 return NULL;
980
981
1/2
✓ Branch 0 taken 411 times.
✗ Branch 1 not taken.
411 if (size)
982 411 *size = sizeof(*props);
983
984 411 props->vbv_delay = UINT64_MAX;
985
986 411 return props;
987 }
988
989 static unsigned bcd2uint(uint8_t bcd)
990 {
991 unsigned low = bcd & 0xf;
992 unsigned high = bcd >> 4;
993 if (low > 9 || high > 9)
994 return 0;
995 return low + 10*high;
996 }
997
998 int ff_alloc_timecode_sei(const AVFrame *frame, AVRational rate, size_t prefix_len,
999 void **data, size_t *sei_size)
1000 {
1001 AVFrameSideData *sd = NULL;
1002 uint8_t *sei_data;
1003 PutBitContext pb;
1004 uint32_t *tc;
1005 int m;
1006
1007 if (frame)
1008 sd = av_frame_get_side_data(frame, AV_FRAME_DATA_S12M_TIMECODE);
1009
1010 if (!sd) {
1011 *data = NULL;
1012 return 0;
1013 }
1014 tc = (uint32_t*)sd->data;
1015 m = tc[0] & 3;
1016
1017 *sei_size = sizeof(uint32_t) * 4;
1018 *data = av_mallocz(*sei_size + prefix_len);
1019 if (!*data)
1020 return AVERROR(ENOMEM);
1021 sei_data = (uint8_t*)*data + prefix_len;
1022
1023 init_put_bits(&pb, sei_data, *sei_size);
1024 put_bits(&pb, 2, m); // num_clock_ts
1025
1026 for (int j = 1; j <= m; j++) {
1027 uint32_t tcsmpte = tc[j];
1028 unsigned hh = bcd2uint(tcsmpte & 0x3f); // 6-bit hours
1029 unsigned mm = bcd2uint(tcsmpte>>8 & 0x7f); // 7-bit minutes
1030 unsigned ss = bcd2uint(tcsmpte>>16 & 0x7f); // 7-bit seconds
1031 unsigned ff = bcd2uint(tcsmpte>>24 & 0x3f); // 6-bit frames
1032 unsigned drop = tcsmpte & 1<<30 && !0; // 1-bit drop if not arbitrary bit
1033
1034 /* Calculate frame number of HEVC by SMPTE ST 12-1:2014 Sec 12.2 if rate > 30FPS */
1035 if (av_cmp_q(rate, (AVRational) {30, 1}) == 1) {
1036 unsigned pc;
1037 ff *= 2;
1038 if (av_cmp_q(rate, (AVRational) {50, 1}) == 0)
1039 pc = !!(tcsmpte & 1 << 7);
1040 else
1041 pc = !!(tcsmpte & 1 << 23);
1042 ff = (ff + pc) & 0x7f;
1043 }
1044
1045 put_bits(&pb, 1, 1); // clock_timestamp_flag
1046 put_bits(&pb, 1, 1); // units_field_based_flag
1047 put_bits(&pb, 5, 0); // counting_type
1048 put_bits(&pb, 1, 1); // full_timestamp_flag
1049 put_bits(&pb, 1, 0); // discontinuity_flag
1050 put_bits(&pb, 1, drop);
1051 put_bits(&pb, 9, ff);
1052 put_bits(&pb, 6, ss);
1053 put_bits(&pb, 6, mm);
1054 put_bits(&pb, 5, hh);
1055 put_bits(&pb, 5, 0);
1056 }
1057 flush_put_bits(&pb);
1058
1059 return 0;
1060 }
1061
1062 17225 int64_t ff_guess_coded_bitrate(AVCodecContext *avctx)
1063 {
1064 17225 AVRational framerate = avctx->framerate;
1065 17225 int bits_per_coded_sample = avctx->bits_per_coded_sample;
1066 int64_t bitrate;
1067
1068
3/4
✓ Branch 0 taken 17178 times.
✓ Branch 1 taken 47 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 17178 times.
17225 if (!(framerate.num && framerate.den))
1069 47 framerate = av_inv_q(avctx->time_base);
1070
2/4
✓ Branch 0 taken 17225 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 17225 times.
17225 if (!(framerate.num && framerate.den))
1071 return 0;
1072
1073
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17225 times.
17225 if (!bits_per_coded_sample) {
1074 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
1075 bits_per_coded_sample = av_get_bits_per_pixel(desc);
1076 }
1077 17225 bitrate = (int64_t)bits_per_coded_sample * avctx->width * avctx->height *
1078 17225 framerate.num / framerate.den;
1079
1080 17225 return bitrate;
1081 }
1082