FFmpeg coverage


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