FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/utils.c
Date: 2022-12-09 07:38:14
Exec Total Coverage
Lines: 407 559 72.8%
Functions: 27 34 79.4%
Branches: 303 421 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 195251 void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
50 {
51 195251 uint8_t **p = ptr;
52
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 195251 times.
195251 if (min_size > SIZE_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
53 av_freep(p);
54 *size = 0;
55 return;
56 }
57 195251 av_fast_mallocz(p, size, min_size + AV_INPUT_BUFFER_PADDING_SIZE);
58
1/2
✓ Branch 0 taken 195251 times.
✗ Branch 1 not taken.
195251 if (*p)
59 195251 memset(*p + min_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
60 }
61
62 692 void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size)
63 {
64 692 uint8_t **p = ptr;
65
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 692 times.
692 if (min_size > SIZE_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
66 av_freep(p);
67 *size = 0;
68 return;
69 }
70 692 av_fast_malloc(p, size, min_size + AV_INPUT_BUFFER_PADDING_SIZE);
71
1/2
✓ Branch 0 taken 692 times.
✗ Branch 1 not taken.
692 if (*p)
72 692 memset(*p, 0, min_size + AV_INPUT_BUFFER_PADDING_SIZE);
73 }
74
75 6968717 int av_codec_is_encoder(const AVCodec *avcodec)
76 {
77 6968717 const FFCodec *const codec = ffcodec(avcodec);
78
4/4
✓ Branch 0 taken 6939968 times.
✓ Branch 1 taken 28749 times.
✓ Branch 2 taken 4029386 times.
✓ Branch 3 taken 2910582 times.
10998103 return codec && (codec->cb_type == FF_CODEC_CB_TYPE_ENCODE ||
79
2/2
✓ Branch 0 taken 3954403 times.
✓ Branch 1 taken 74983 times.
4029386 codec->cb_type == FF_CODEC_CB_TYPE_ENCODE_SUB ||
80
2/2
✓ Branch 0 taken 74591 times.
✓ Branch 1 taken 3879812 times.
3954403 codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_PACKET);
81 }
82
83 14151613 int av_codec_is_decoder(const AVCodec *avcodec)
84 {
85 14151613 const FFCodec *const codec = ffcodec(avcodec);
86
4/4
✓ Branch 0 taken 14122864 times.
✓ Branch 1 taken 28749 times.
✓ Branch 2 taken 5881930 times.
✓ Branch 3 taken 8240934 times.
20033543 return codec && (codec->cb_type == FF_CODEC_CB_TYPE_DECODE ||
87
2/2
✓ Branch 0 taken 5867419 times.
✓ Branch 1 taken 14511 times.
5881930 codec->cb_type == FF_CODEC_CB_TYPE_DECODE_SUB ||
88
2/2
✓ Branch 0 taken 316356 times.
✓ Branch 1 taken 5551063 times.
5867419 codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_FRAME);
89 }
90
91 43648 int ff_set_dimensions(AVCodecContext *s, int width, int height)
92 {
93 43648 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 43647 times.
43648 if (ret < 0)
96 1 width = height = 0;
97
98 43648 s->coded_width = width;
99 43648 s->coded_height = height;
100 43648 s->width = AV_CEIL_RSHIFT(width, s->lowres);
101 43648 s->height = AV_CEIL_RSHIFT(height, s->lowres);
102
103 43648 return ret;
104 }
105
106 2743 int ff_set_sar(AVCodecContext *avctx, AVRational sar)
107 {
108 2743 int ret = av_image_check_sar(avctx->width, avctx->height, sar);
109
110
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2738 times.
2743 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 2738 avctx->sample_aspect_ratio = sar;
117 }
118 2738 return 0;
119 }
120
121 4789 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 4789 side_data = av_frame_get_side_data(frame, AV_FRAME_DATA_MATRIXENCODING);
128
1/2
✓ Branch 0 taken 4789 times.
✗ Branch 1 not taken.
4789 if (!side_data)
129 4789 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 4789 times.
4789 if (!side_data)
133 return AVERROR(ENOMEM);
134
135 4789 data = (enum AVMatrixEncoding*)side_data->data;
136 4789 *data = matrix_encoding;
137
138 4789 return 0;
139 }
140
141 6437 void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height,
142 int linesize_align[AV_NUM_DATA_POINTERS])
143 {
144 int i;
145 6437 int w_align = 1;
146 6437 int h_align = 1;
147 6437 AVPixFmtDescriptor const *desc = av_pix_fmt_desc_get(s->pix_fmt);
148
149
1/2
✓ Branch 0 taken 6437 times.
✗ Branch 1 not taken.
6437 if (desc) {
150 6437 w_align = 1 << desc->log2_chroma_w;
151 6437 h_align = 1 << desc->log2_chroma_h;
152 }
153
154
9/9
✓ Branch 0 taken 5541 times.
✓ Branch 1 taken 26 times.
✓ Branch 2 taken 21 times.
✓ Branch 3 taken 34 times.
✓ Branch 4 taken 125 times.
✓ Branch 5 taken 81 times.
✓ Branch 6 taken 207 times.
✓ Branch 7 taken 27 times.
✓ Branch 8 taken 375 times.
6437 switch (s->pix_fmt) {
155 5541 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 5541 w_align = 16; //FIXME assume 16 pixel per macroblock
245 5541 h_align = 16 * 2; // interlaced needs 2 macroblocks height
246 5541 break;
247 26 case AV_PIX_FMT_YUV411P:
248 case AV_PIX_FMT_YUVJ411P:
249 case AV_PIX_FMT_UYYVYY411:
250 26 w_align = 32;
251 26 h_align = 16 * 2;
252 26 break;
253 21 case AV_PIX_FMT_YUV410P:
254
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 11 times.
21 if (s->codec_id == AV_CODEC_ID_SVQ1) {
255 10 w_align = 64;
256 10 h_align = 64;
257 }
258 21 break;
259 34 case AV_PIX_FMT_RGB555:
260
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 33 times.
34 if (s->codec_id == AV_CODEC_ID_RPZA) {
261 1 w_align = 4;
262 1 h_align = 4;
263 }
264
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 33 times.
34 if (s->codec_id == AV_CODEC_ID_INTERPLAY_VIDEO) {
265 1 w_align = 8;
266 1 h_align = 8;
267 }
268 34 break;
269 125 case AV_PIX_FMT_PAL8:
270 case AV_PIX_FMT_BGR8:
271 case AV_PIX_FMT_RGB8:
272
2/2
✓ Branch 0 taken 124 times.
✓ Branch 1 taken 1 times.
125 if (s->codec_id == AV_CODEC_ID_SMC ||
273
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 123 times.
124 s->codec_id == AV_CODEC_ID_CINEPAK) {
274 2 w_align = 4;
275 2 h_align = 4;
276 }
277
2/2
✓ Branch 0 taken 124 times.
✓ Branch 1 taken 1 times.
125 if (s->codec_id == AV_CODEC_ID_JV ||
278
1/2
✓ Branch 0 taken 124 times.
✗ Branch 1 not taken.
124 s->codec_id == AV_CODEC_ID_ARGO ||
279
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 123 times.
124 s->codec_id == AV_CODEC_ID_INTERPLAY_VIDEO) {
280 2 w_align = 8;
281 2 h_align = 8;
282 }
283
1/2
✓ Branch 0 taken 125 times.
✗ Branch 1 not taken.
125 if (s->codec_id == AV_CODEC_ID_MJPEG ||
284
1/2
✓ Branch 0 taken 125 times.
✗ Branch 1 not taken.
125 s->codec_id == AV_CODEC_ID_MJPEGB ||
285
1/2
✓ Branch 0 taken 125 times.
✗ Branch 1 not taken.
125 s->codec_id == AV_CODEC_ID_LJPEG ||
286
1/2
✓ Branch 0 taken 125 times.
✗ Branch 1 not taken.
125 s->codec_id == AV_CODEC_ID_SMVJPEG ||
287
1/2
✓ Branch 0 taken 125 times.
✗ Branch 1 not taken.
125 s->codec_id == AV_CODEC_ID_AMV ||
288
1/2
✓ Branch 0 taken 125 times.
✗ Branch 1 not taken.
125 s->codec_id == AV_CODEC_ID_SP5X ||
289
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 117 times.
125 s->codec_id == AV_CODEC_ID_JPEGLS) {
290 8 w_align = 8;
291 8 h_align = 2*8;
292 }
293 125 break;
294 81 case AV_PIX_FMT_BGR24:
295
2/2
✓ Branch 0 taken 80 times.
✓ Branch 1 taken 1 times.
81 if ((s->codec_id == AV_CODEC_ID_MSZH) ||
296
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 75 times.
80 (s->codec_id == AV_CODEC_ID_ZLIB)) {
297 6 w_align = 4;
298 6 h_align = 4;
299 }
300 81 break;
301 207 case AV_PIX_FMT_RGB24:
302
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 200 times.
207 if (s->codec_id == AV_CODEC_ID_CINEPAK) {
303 7 w_align = 4;
304 7 h_align = 4;
305 }
306 207 break;
307 27 case AV_PIX_FMT_BGR0:
308
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
27 if (s->codec_id == AV_CODEC_ID_ARGO) {
309 w_align = 8;
310 h_align = 8;
311 }
312 27 break;
313 375 default:
314 375 break;
315 }
316
317
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6435 times.
6437 if (s->codec_id == AV_CODEC_ID_IFF_ILBM) {
318 2 w_align = FFMAX(w_align, 8);
319 }
320
321 6437 *width = FFALIGN(*width, w_align);
322 6437 *height = FFALIGN(*height, h_align);
323
4/4
✓ Branch 0 taken 5879 times.
✓ Branch 1 taken 558 times.
✓ Branch 2 taken 5878 times.
✓ Branch 3 taken 1 times.
6437 if (s->codec_id == AV_CODEC_ID_H264 || s->lowres ||
324
4/4
✓ Branch 0 taken 5877 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 5870 times.
✓ Branch 3 taken 7 times.
5878 s->codec_id == AV_CODEC_ID_VP5 || s->codec_id == AV_CODEC_ID_VP6 ||
325
4/4
✓ Branch 0 taken 5868 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 5866 times.
5870 s->codec_id == AV_CODEC_ID_VP6F || s->codec_id == AV_CODEC_ID_VP6A
326 ) {
327 // some of the optimized chroma MC reads one line too much
328 // which is also done in mpeg decoders with lowres > 0
329 571 *height += 2;
330
331 // H.264 uses edge emulation for out of frame motion vectors, for this
332 // it requires a temporary area large enough to hold a 21x21 block,
333 // increasing witdth ensure that the temporary area is large enough,
334 // the next rounded up width is 32
335 571 *width = FFMAX(*width, 32);
336 }
337
338
2/2
✓ Branch 0 taken 25748 times.
✓ Branch 1 taken 6437 times.
32185 for (i = 0; i < 4; i++)
339 25748 linesize_align[i] = STRIDE_ALIGN;
340 6437 }
341
342 void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height)
343 {
344 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->pix_fmt);
345 int chroma_shift = desc->log2_chroma_w;
346 int linesize_align[AV_NUM_DATA_POINTERS];
347 int align;
348
349 avcodec_align_dimensions2(s, width, height, linesize_align);
350 align = FFMAX(linesize_align[0], linesize_align[3]);
351 linesize_align[1] <<= chroma_shift;
352 linesize_align[2] <<= chroma_shift;
353 align = FFMAX3(align, linesize_align[1], linesize_align[2]);
354 *width = FFALIGN(*width, align);
355 }
356 #if FF_API_AVCODEC_CHROMA_POS
357 int avcodec_enum_to_chroma_pos(int *xpos, int *ypos, enum AVChromaLocation pos)
358 {
359 return av_chroma_location_enum_to_pos(xpos, ypos, pos);
360 }
361
362 enum AVChromaLocation avcodec_chroma_pos_to_enum(int xpos, int ypos)
363 {
364 return av_chroma_location_pos_to_enum(xpos, ypos);
365 }
366 #endif
367
368 int avcodec_fill_audio_frame(AVFrame *frame, int nb_channels,
369 enum AVSampleFormat sample_fmt, const uint8_t *buf,
370 int buf_size, int align)
371 {
372 int ch, planar, needed_size, ret = 0;
373
374 needed_size = av_samples_get_buffer_size(NULL, nb_channels,
375 frame->nb_samples, sample_fmt,
376 align);
377 if (buf_size < needed_size)
378 return AVERROR(EINVAL);
379
380 planar = av_sample_fmt_is_planar(sample_fmt);
381 if (planar && nb_channels > AV_NUM_DATA_POINTERS) {
382 if (!FF_ALLOCZ_TYPED_ARRAY(frame->extended_data, nb_channels))
383 return AVERROR(ENOMEM);
384 } else {
385 frame->extended_data = frame->data;
386 }
387
388 if ((ret = av_samples_fill_arrays(frame->extended_data, &frame->linesize[0],
389 (uint8_t *)(intptr_t)buf, nb_channels, frame->nb_samples,
390 sample_fmt, align)) < 0) {
391 if (frame->extended_data != frame->data)
392 av_freep(&frame->extended_data);
393 return ret;
394 }
395 if (frame->extended_data != frame->data) {
396 for (ch = 0; ch < AV_NUM_DATA_POINTERS; ch++)
397 frame->data[ch] = frame->extended_data[ch];
398 }
399
400 return ret;
401 }
402
403 18 void ff_color_frame(AVFrame *frame, const int c[4])
404 {
405 18 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
406 int p, y;
407
408
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 av_assert0(desc->flags & AV_PIX_FMT_FLAG_PLANAR);
409
410
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 18 times.
72 for (p = 0; p<desc->nb_components; p++) {
411 54 uint8_t *dst = frame->data[p];
412
4/4
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 18 times.
✓ Branch 3 taken 18 times.
54 int is_chroma = p == 1 || p == 2;
413
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 18 times.
54 int bytes = is_chroma ? AV_CEIL_RSHIFT(frame->width, desc->log2_chroma_w) : frame->width;
414
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 18 times.
54 int height = is_chroma ? AV_CEIL_RSHIFT(frame->height, desc->log2_chroma_h) : frame->height;
415
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 54 times.
54 if (desc->comp[0].depth >= 9) {
416 ((uint16_t*)dst)[0] = c[p];
417 av_memcpy_backptr(dst + 2, 2, bytes - 2);
418 dst += frame->linesize[p];
419 for (y = 1; y < height; y++) {
420 memcpy(dst, frame->data[p], 2*bytes);
421 dst += frame->linesize[p];
422 }
423 } else {
424
2/2
✓ Branch 0 taken 27328 times.
✓ Branch 1 taken 54 times.
27382 for (y = 0; y < height; y++) {
425 27328 memset(dst, c[p], bytes);
426 27328 dst += frame->linesize[p];
427 }
428 }
429 }
430 18 }
431
432 182934 int avpriv_codec_get_cap_skip_frame_fill_param(const AVCodec *codec){
433 182934 return !!(ffcodec(codec)->caps_internal & FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM);
434 }
435
436 17818 const char *avcodec_get_name(enum AVCodecID id)
437 {
438 const AVCodecDescriptor *cd;
439 const AVCodec *codec;
440
441
2/2
✓ Branch 0 taken 186 times.
✓ Branch 1 taken 17632 times.
17818 if (id == AV_CODEC_ID_NONE)
442 186 return "none";
443 17632 cd = avcodec_descriptor_get(id);
444
2/2
✓ Branch 0 taken 17630 times.
✓ Branch 1 taken 2 times.
17632 if (cd)
445 17630 return cd->name;
446 2 av_log(NULL, AV_LOG_WARNING, "Codec 0x%x is not in the full list.\n", id);
447 2 codec = avcodec_find_decoder(id);
448
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (codec)
449 return codec->name;
450 2 codec = avcodec_find_encoder(id);
451
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (codec)
452 return codec->name;
453 2 return "unknown_codec";
454 }
455
456 const char *av_get_profile_name(const AVCodec *codec, int profile)
457 {
458 const AVProfile *p;
459 if (profile == FF_PROFILE_UNKNOWN || !codec->profiles)
460 return NULL;
461
462 for (p = codec->profiles; p->profile != FF_PROFILE_UNKNOWN; p++)
463 if (p->profile == profile)
464 return p->name;
465
466 return NULL;
467 }
468
469 13899 const char *avcodec_profile_name(enum AVCodecID codec_id, int profile)
470 {
471 13899 const AVCodecDescriptor *desc = avcodec_descriptor_get(codec_id);
472 const AVProfile *p;
473
474
5/6
✓ Branch 0 taken 1846 times.
✓ Branch 1 taken 12053 times.
✓ Branch 2 taken 1846 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 130 times.
✓ Branch 5 taken 1716 times.
13899 if (profile == FF_PROFILE_UNKNOWN || !desc || !desc->profiles)
475 12183 return NULL;
476
477
2/2
✓ Branch 0 taken 4532 times.
✓ Branch 1 taken 12 times.
4544 for (p = desc->profiles; p->profile != FF_PROFILE_UNKNOWN; p++)
478
2/2
✓ Branch 0 taken 1704 times.
✓ Branch 1 taken 2828 times.
4532 if (p->profile == profile)
479 1704 return p->name;
480
481 12 return NULL;
482 }
483
484 923243 int av_get_exact_bits_per_sample(enum AVCodecID codec_id)
485 {
486
8/8
✓ Branch 0 taken 51 times.
✓ Branch 1 taken 11190 times.
✓ Branch 2 taken 13417 times.
✓ Branch 3 taken 554750 times.
✓ Branch 4 taken 83039 times.
✓ Branch 5 taken 29660 times.
✓ Branch 6 taken 21361 times.
✓ Branch 7 taken 209775 times.
923243 switch (codec_id) {
487 51 case AV_CODEC_ID_DFPWM:
488 51 return 1;
489 11190 case AV_CODEC_ID_8SVX_EXP:
490 case AV_CODEC_ID_8SVX_FIB:
491 case AV_CODEC_ID_ADPCM_ARGO:
492 case AV_CODEC_ID_ADPCM_CT:
493 case AV_CODEC_ID_ADPCM_IMA_ALP:
494 case AV_CODEC_ID_ADPCM_IMA_AMV:
495 case AV_CODEC_ID_ADPCM_IMA_APC:
496 case AV_CODEC_ID_ADPCM_IMA_APM:
497 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
498 case AV_CODEC_ID_ADPCM_IMA_OKI:
499 case AV_CODEC_ID_ADPCM_IMA_WS:
500 case AV_CODEC_ID_ADPCM_IMA_SSI:
501 case AV_CODEC_ID_ADPCM_G722:
502 case AV_CODEC_ID_ADPCM_YAMAHA:
503 case AV_CODEC_ID_ADPCM_AICA:
504 11190 return 4;
505 13417 case AV_CODEC_ID_DSD_LSBF:
506 case AV_CODEC_ID_DSD_MSBF:
507 case AV_CODEC_ID_DSD_LSBF_PLANAR:
508 case AV_CODEC_ID_DSD_MSBF_PLANAR:
509 case AV_CODEC_ID_PCM_ALAW:
510 case AV_CODEC_ID_PCM_MULAW:
511 case AV_CODEC_ID_PCM_VIDC:
512 case AV_CODEC_ID_PCM_S8:
513 case AV_CODEC_ID_PCM_S8_PLANAR:
514 case AV_CODEC_ID_PCM_SGA:
515 case AV_CODEC_ID_PCM_U8:
516 case AV_CODEC_ID_SDX2_DPCM:
517 case AV_CODEC_ID_DERF_DPCM:
518 13417 return 8;
519 554750 case AV_CODEC_ID_PCM_S16BE:
520 case AV_CODEC_ID_PCM_S16BE_PLANAR:
521 case AV_CODEC_ID_PCM_S16LE:
522 case AV_CODEC_ID_PCM_S16LE_PLANAR:
523 case AV_CODEC_ID_PCM_U16BE:
524 case AV_CODEC_ID_PCM_U16LE:
525 554750 return 16;
526 83039 case AV_CODEC_ID_PCM_S24DAUD:
527 case AV_CODEC_ID_PCM_S24BE:
528 case AV_CODEC_ID_PCM_S24LE:
529 case AV_CODEC_ID_PCM_S24LE_PLANAR:
530 case AV_CODEC_ID_PCM_U24BE:
531 case AV_CODEC_ID_PCM_U24LE:
532 83039 return 24;
533 29660 case AV_CODEC_ID_PCM_S32BE:
534 case AV_CODEC_ID_PCM_S32LE:
535 case AV_CODEC_ID_PCM_S32LE_PLANAR:
536 case AV_CODEC_ID_PCM_U32BE:
537 case AV_CODEC_ID_PCM_U32LE:
538 case AV_CODEC_ID_PCM_F32BE:
539 case AV_CODEC_ID_PCM_F32LE:
540 case AV_CODEC_ID_PCM_F24LE:
541 case AV_CODEC_ID_PCM_F16LE:
542 29660 return 32;
543 21361 case AV_CODEC_ID_PCM_F64BE:
544 case AV_CODEC_ID_PCM_F64LE:
545 case AV_CODEC_ID_PCM_S64BE:
546 case AV_CODEC_ID_PCM_S64LE:
547 21361 return 64;
548 209775 default:
549 209775 return 0;
550 }
551 }
552
553 23 enum AVCodecID av_get_pcm_codec(enum AVSampleFormat fmt, int be)
554 {
555 static const enum AVCodecID map[][2] = {
556 [AV_SAMPLE_FMT_U8 ] = { AV_CODEC_ID_PCM_U8, AV_CODEC_ID_PCM_U8 },
557 [AV_SAMPLE_FMT_S16 ] = { AV_CODEC_ID_PCM_S16LE, AV_CODEC_ID_PCM_S16BE },
558 [AV_SAMPLE_FMT_S32 ] = { AV_CODEC_ID_PCM_S32LE, AV_CODEC_ID_PCM_S32BE },
559 [AV_SAMPLE_FMT_FLT ] = { AV_CODEC_ID_PCM_F32LE, AV_CODEC_ID_PCM_F32BE },
560 [AV_SAMPLE_FMT_DBL ] = { AV_CODEC_ID_PCM_F64LE, AV_CODEC_ID_PCM_F64BE },
561 [AV_SAMPLE_FMT_U8P ] = { AV_CODEC_ID_PCM_U8, AV_CODEC_ID_PCM_U8 },
562 [AV_SAMPLE_FMT_S16P] = { AV_CODEC_ID_PCM_S16LE, AV_CODEC_ID_PCM_S16BE },
563 [AV_SAMPLE_FMT_S32P] = { AV_CODEC_ID_PCM_S32LE, AV_CODEC_ID_PCM_S32BE },
564 [AV_SAMPLE_FMT_S64P] = { AV_CODEC_ID_PCM_S64LE, AV_CODEC_ID_PCM_S64BE },
565 [AV_SAMPLE_FMT_FLTP] = { AV_CODEC_ID_PCM_F32LE, AV_CODEC_ID_PCM_F32BE },
566 [AV_SAMPLE_FMT_DBLP] = { AV_CODEC_ID_PCM_F64LE, AV_CODEC_ID_PCM_F64BE },
567 };
568
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))
569 return AV_CODEC_ID_NONE;
570
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)
571 23 be = AV_NE(1, 0);
572 23 return map[fmt][be];
573 }
574
575 341611 int av_get_bits_per_sample(enum AVCodecID codec_id)
576 {
577
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 341537 times.
341611 switch (codec_id) {
578 4 case AV_CODEC_ID_DFPWM:
579 4 return 1;
580 3 case AV_CODEC_ID_ADPCM_SBPRO_2:
581 3 return 2;
582 3 case AV_CODEC_ID_ADPCM_SBPRO_3:
583 3 return 3;
584 64 case AV_CODEC_ID_ADPCM_SBPRO_4:
585 case AV_CODEC_ID_ADPCM_IMA_WAV:
586 case AV_CODEC_ID_ADPCM_IMA_QT:
587 case AV_CODEC_ID_ADPCM_SWF:
588 case AV_CODEC_ID_ADPCM_MS:
589 64 return 4;
590 341537 default:
591 341537 return av_get_exact_bits_per_sample(codec_id);
592 }
593 }
594
595 575449 static int get_audio_frame_duration(enum AVCodecID id, int sr, int ch, int ba,
596 uint32_t tag, int bits_per_coded_sample, int64_t bitrate,
597 uint8_t * extradata, int frame_size, int frame_bytes)
598 {
599 575449 int bps = av_get_exact_bits_per_sample(id);
600
4/4
✓ Branch 0 taken 422598 times.
✓ Branch 1 taken 152851 times.
✓ Branch 2 taken 422303 times.
✓ Branch 3 taken 295 times.
575449 int framecount = (ba > 0 && frame_bytes / ba > 0) ? frame_bytes / ba : 1;
601
602 /* codecs with an exact constant bits per sample */
603
7/10
✓ Branch 0 taken 373597 times.
✓ Branch 1 taken 201852 times.
✓ Branch 2 taken 373597 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 373568 times.
✓ Branch 5 taken 29 times.
✓ Branch 6 taken 373568 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 373568 times.
✗ Branch 9 not taken.
575449 if (bps > 0 && ch > 0 && frame_bytes > 0 && ch < 32768 && bps < 32768)
604 373568 return (frame_bytes * 8LL) / (bps * ch);
605 201881 bps = bits_per_coded_sample;
606
607 /* codecs with a fixed packet duration */
608
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 4174 times.
✓ Branch 8 taken 2185 times.
✓ Branch 9 taken 18570 times.
✓ Branch 10 taken 2235 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 142296 times.
201881 switch (id) {
609 12407 case AV_CODEC_ID_ADPCM_ADX: return 32;
610 8274 case AV_CODEC_ID_ADPCM_IMA_QT: return 64;
611 600 case AV_CODEC_ID_ADPCM_EA_XAS: return 128;
612 5697 case AV_CODEC_ID_AMR_NB:
613 case AV_CODEC_ID_EVRC:
614 case AV_CODEC_ID_GSM:
615 case AV_CODEC_ID_QCELP:
616 5697 case AV_CODEC_ID_RA_288: return 160;
617 1124 case AV_CODEC_ID_AMR_WB:
618 1124 case AV_CODEC_ID_GSM_MS: return 320;
619 case AV_CODEC_ID_MP1: return 384;
620 4319 case AV_CODEC_ID_ATRAC1: return 512;
621 4174 case AV_CODEC_ID_ATRAC9:
622 case AV_CODEC_ID_ATRAC3:
623
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4174 times.
4174 if (framecount > INT_MAX/1024)
624 return 0;
625 4174 return 1024 * framecount;
626 2185 case AV_CODEC_ID_ATRAC3P: return 2048;
627 18570 case AV_CODEC_ID_MP2:
628 18570 case AV_CODEC_ID_MUSEPACK7: return 1152;
629 2235 case AV_CODEC_ID_AC3: return 1536;
630 case AV_CODEC_ID_FTR: return 1024;
631 }
632
633
2/2
✓ Branch 0 taken 139323 times.
✓ Branch 1 taken 2973 times.
142296 if (sr > 0) {
634 /* calc from sample rate */
635
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 139314 times.
139323 if (id == AV_CODEC_ID_TTA)
636 9 return 256 * sr / 245;
637
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 139314 times.
139314 else if (id == AV_CODEC_ID_DST)
638 return 588 * sr / 44100;
639
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 139248 times.
139314 else if (id == AV_CODEC_ID_BINKAUDIO_DCT) {
640
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
66 if (sr / 22050 > 22)
641 return 0;
642 66 return (480 << (sr / 22050));
643 }
644
645
2/2
✓ Branch 0 taken 6741 times.
✓ Branch 1 taken 132507 times.
139248 if (id == AV_CODEC_ID_MP3)
646
2/2
✓ Branch 0 taken 224 times.
✓ Branch 1 taken 6517 times.
6741 return sr <= 24000 ? 576 : 1152;
647 }
648
649
2/2
✓ Branch 0 taken 40886 times.
✓ Branch 1 taken 94594 times.
135480 if (ba > 0) {
650 /* calc from block_align */
651
2/2
✓ Branch 0 taken 7251 times.
✓ Branch 1 taken 33635 times.
40886 if (id == AV_CODEC_ID_SIPR) {
652
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) {
653 3252 case 20: return 160;
654 1983 case 19: return 144;
655 1680 case 29: return 288;
656 336 case 37: return 480;
657 }
658
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33635 times.
33635 } else if (id == AV_CODEC_ID_ILBC) {
659 switch (ba) {
660 case 38: return 160;
661 case 50: return 240;
662 }
663 }
664 }
665
666
2/2
✓ Branch 0 taken 125312 times.
✓ Branch 1 taken 2917 times.
128229 if (frame_bytes > 0) {
667 /* calc from frame_bytes only */
668
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 125300 times.
125312 if (id == AV_CODEC_ID_TRUESPEECH)
669 12 return 240 * (frame_bytes / 32);
670
2/2
✓ Branch 0 taken 2074 times.
✓ Branch 1 taken 123226 times.
125300 if (id == AV_CODEC_ID_NELLYMOSER)
671 2074 return 256 * (frame_bytes / 64);
672
2/2
✓ Branch 0 taken 1057 times.
✓ Branch 1 taken 122169 times.
123226 if (id == AV_CODEC_ID_RA_144)
673 1057 return 160 * (frame_bytes / 20);
674
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 121709 times.
122169 if (id == AV_CODEC_ID_APTX)
675 460 return 4 * (frame_bytes / 4);
676
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 121249 times.
121709 if (id == AV_CODEC_ID_APTX_HD)
677 460 return 4 * (frame_bytes / 6);
678
679
2/2
✓ Branch 0 taken 44105 times.
✓ Branch 1 taken 77144 times.
121249 if (bps > 0) {
680 /* calc from frame_bytes and bits_per_coded_sample */
681
3/4
✓ Branch 0 taken 43999 times.
✓ Branch 1 taken 106 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 43999 times.
44105 if (id == AV_CODEC_ID_ADPCM_G726 || id == AV_CODEC_ID_ADPCM_G726LE)
682 106 return frame_bytes * 8 / bps;
683 }
684
685
3/4
✓ Branch 0 taken 121015 times.
✓ Branch 1 taken 128 times.
✓ Branch 2 taken 121015 times.
✗ Branch 3 not taken.
121143 if (ch > 0 && ch < INT_MAX/16) {
686 /* calc from frame_bytes and channels */
687
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 111984 times.
121015 switch (id) {
688 case AV_CODEC_ID_FASTAUDIO:
689 return frame_bytes / (40 * ch) * 256;
690 case AV_CODEC_ID_ADPCM_IMA_MOFLEX:
691 return (frame_bytes - 4 * ch) / (128 * ch) * 256;
692 48 case AV_CODEC_ID_ADPCM_AFC:
693 48 return frame_bytes / (9 * ch) * 16;
694 33 case AV_CODEC_ID_ADPCM_PSX:
695 case AV_CODEC_ID_ADPCM_DTK:
696 33 frame_bytes /= 16 * ch;
697
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
33 if (frame_bytes > INT_MAX / 28)
698 return 0;
699 33 return frame_bytes * 28;
700 452 case AV_CODEC_ID_ADPCM_4XM:
701 case AV_CODEC_ID_ADPCM_IMA_ACORN:
702 case AV_CODEC_ID_ADPCM_IMA_DAT4:
703 case AV_CODEC_ID_ADPCM_IMA_ISS:
704 452 return (frame_bytes - 4 * ch) * 2 / ch;
705 1951 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
706 1951 return (frame_bytes - 4) * 2 / ch;
707 case AV_CODEC_ID_ADPCM_IMA_AMV:
708 return (frame_bytes - 8) * 2;
709 3580 case AV_CODEC_ID_ADPCM_THP:
710 case AV_CODEC_ID_ADPCM_THP_LE:
711
2/2
✓ Branch 0 taken 3530 times.
✓ Branch 1 taken 50 times.
3580 if (extradata)
712 3530 return frame_bytes * 14LL / (8 * ch);
713 50 break;
714 222 case AV_CODEC_ID_ADPCM_XA:
715 222 return (frame_bytes / 128) * 224 / ch;
716 327 case AV_CODEC_ID_INTERPLAY_DPCM:
717 327 return (frame_bytes - 6 - ch) / ch;
718 680 case AV_CODEC_ID_ROQ_DPCM:
719 680 return (frame_bytes - 8) / ch;
720 112 case AV_CODEC_ID_XAN_DPCM:
721 112 return (frame_bytes - 2 * ch) / ch;
722 case AV_CODEC_ID_MACE3:
723 return 3 * frame_bytes / ch;
724 315 case AV_CODEC_ID_MACE6:
725 315 return 6 * frame_bytes / ch;
726 case AV_CODEC_ID_PCM_LXF:
727 return 2 * (frame_bytes / (5 * ch));
728 1311 case AV_CODEC_ID_IAC:
729 case AV_CODEC_ID_IMC:
730 1311 return 4 * frame_bytes / ch;
731 }
732
733
2/2
✓ Branch 0 taken 26071 times.
✓ Branch 1 taken 85963 times.
112034 if (tag) {
734 /* calc from frame_bytes, channels, and codec_tag */
735
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 25997 times.
26071 if (id == AV_CODEC_ID_SOL_DPCM) {
736
1/2
✓ Branch 0 taken 74 times.
✗ Branch 1 not taken.
74 if (tag == 3)
737 74 return frame_bytes / ch;
738 else
739 return frame_bytes * 2 / ch;
740 }
741 }
742
743
2/2
✓ Branch 0 taken 30227 times.
✓ Branch 1 taken 81733 times.
111960 if (ba > 0) {
744 /* calc from frame_bytes, channels, and block_align */
745 30227 int blocks = frame_bytes / ba;
746 30227 int64_t tmp = 0;
747
6/7
✓ 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 taken 26011 times.
30227 switch (id) {
748 1007 case AV_CODEC_ID_ADPCM_IMA_WAV:
749
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)
750 return 0;
751 1007 tmp = blocks * (1LL + (ba - 4 * ch) / (bps * ch) * 8);
752 1007 break;
753 669 case AV_CODEC_ID_ADPCM_IMA_DK3:
754 669 tmp = blocks * (((ba - 16LL) * 2 / 3 * 4) / ch);
755 669 break;
756 649 case AV_CODEC_ID_ADPCM_IMA_DK4:
757 649 tmp = blocks * (1 + (ba - 4LL * ch) * 2 / ch);
758 649 break;
759 1001 case AV_CODEC_ID_ADPCM_IMA_RAD:
760 1001 tmp = blocks * ((ba - 4LL * ch) * 2 / ch);
761 1001 break;
762 890 case AV_CODEC_ID_ADPCM_MS:
763 890 tmp = blocks * (2 + (ba - 7LL * ch) * 2LL / ch);
764 890 break;
765 case AV_CODEC_ID_ADPCM_MTAF:
766 tmp = blocks * (ba - 16LL) * 2 / ch;
767 break;
768 }
769
2/2
✓ Branch 0 taken 4216 times.
✓ Branch 1 taken 26011 times.
30227 if (tmp) {
770
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4216 times.
4216 if (tmp != (int)tmp)
771 return 0;
772 4216 return tmp;
773 }
774 }
775
776
2/2
✓ Branch 0 taken 35848 times.
✓ Branch 1 taken 71896 times.
107744 if (bps > 0) {
777 /* calc from frame_bytes, channels, and bits_per_coded_sample */
778
2/4
✓ Branch 0 taken 20781 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 15067 times.
35848 switch (id) {
779 20781 case AV_CODEC_ID_PCM_DVD:
780
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)
781 return 0;
782 20781 return 2 * ((frame_bytes - 3) / ((bps * 2 / 8) * ch));
783 case AV_CODEC_ID_PCM_BLURAY:
784 if(bps<4 || frame_bytes<4)
785 return 0;
786 return (frame_bytes - 4) / ((FFALIGN(ch, 2) * bps) / 8);
787 case AV_CODEC_ID_S302M:
788 return 2 * (frame_bytes / ((bps + 4) / 4)) / ch;
789 }
790 }
791 }
792 }
793
794 /* Fall back on using frame_size */
795
4/4
✓ Branch 0 taken 46359 times.
✓ Branch 1 taken 43649 times.
✓ Branch 2 taken 46319 times.
✓ Branch 3 taken 40 times.
90008 if (frame_size > 1 && frame_bytes)
796 46319 return frame_size;
797
798 //For WMA we currently have no other means to calculate duration thus we
799 //do it here by assuming CBR, which is true for all known cases.
800
8/8
✓ Branch 0 taken 27805 times.
✓ Branch 1 taken 15884 times.
✓ Branch 2 taken 24900 times.
✓ Branch 3 taken 2905 times.
✓ Branch 4 taken 24869 times.
✓ Branch 5 taken 31 times.
✓ Branch 6 taken 10023 times.
✓ Branch 7 taken 14846 times.
43689 if (bitrate > 0 && frame_bytes > 0 && sr > 0 && ba > 1) {
801
4/4
✓ Branch 0 taken 9818 times.
✓ Branch 1 taken 205 times.
✓ Branch 2 taken 723 times.
✓ Branch 3 taken 9095 times.
10023 if (id == AV_CODEC_ID_WMAV1 || id == AV_CODEC_ID_WMAV2)
802 928 return (frame_bytes * 8LL * sr) / bitrate;
803 }
804
805 42761 return 0;
806 }
807
808 41363 int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
809 {
810 41363 int channels = avctx->ch_layout.nb_channels;
811 int duration;
812 #if FF_API_OLD_CHANNEL_LAYOUT
813 FF_DISABLE_DEPRECATION_WARNINGS
814
2/2
✓ Branch 0 taken 834 times.
✓ Branch 1 taken 40529 times.
41363 if (!channels)
815 834 channels = avctx->channels;
816 FF_ENABLE_DEPRECATION_WARNINGS
817 #endif
818 41363 duration = get_audio_frame_duration(avctx->codec_id, avctx->sample_rate,
819 channels, avctx->block_align,
820 avctx->codec_tag, avctx->bits_per_coded_sample,
821 avctx->bit_rate, avctx->extradata, avctx->frame_size,
822 frame_bytes);
823 41363 return FFMAX(0, duration);
824 }
825
826 534086 int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
827 {
828 534086 int channels = par->ch_layout.nb_channels;
829 int duration;
830 #if FF_API_OLD_CHANNEL_LAYOUT
831 FF_DISABLE_DEPRECATION_WARNINGS
832
2/2
✓ Branch 0 taken 2894 times.
✓ Branch 1 taken 531192 times.
534086 if (!channels)
833 2894 channels = par->channels;
834 FF_ENABLE_DEPRECATION_WARNINGS
835 #endif
836 534086 duration = get_audio_frame_duration(par->codec_id, par->sample_rate,
837 channels, par->block_align,
838 par->codec_tag, par->bits_per_coded_sample,
839 par->bit_rate, par->extradata, par->frame_size,
840 frame_bytes);
841 534086 return FFMAX(0, duration);
842 }
843
844 #if !HAVE_THREADS
845 int ff_thread_init(AVCodecContext *s)
846 {
847 return -1;
848 }
849
850 #endif
851
852 56 unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
853 {
854 56 unsigned int n = 0;
855
856
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
56 while (v >= 0xff) {
857 *s++ = 0xff;
858 v -= 0xff;
859 n++;
860 }
861 56 *s = v;
862 56 n++;
863 56 return n;
864 }
865
866 476 int ff_match_2uint16(const uint16_t(*tab)[2], int size, int a, int b)
867 {
868 int i;
869
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++) ;
870 476 return i;
871 }
872
873 14022 const AVCodecHWConfig *avcodec_get_hw_config(const AVCodec *avcodec, int index)
874 {
875 14022 const FFCodec *const codec = ffcodec(avcodec);
876 int i;
877
3/4
✓ Branch 0 taken 2498 times.
✓ Branch 1 taken 11524 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2498 times.
14022 if (!codec->hw_configs || index < 0)
878 11524 return NULL;
879
2/2
✓ Branch 0 taken 4893 times.
✓ Branch 1 taken 1621 times.
6514 for (i = 0; i <= index; i++)
880
2/2
✓ Branch 0 taken 877 times.
✓ Branch 1 taken 4016 times.
4893 if (!codec->hw_configs[i])
881 877 return NULL;
882 1621 return &codec->hw_configs[index]->public;
883 }
884
885 124299 int ff_thread_ref_frame(ThreadFrame *dst, const ThreadFrame *src)
886 {
887 int ret;
888
889 124299 dst->owner[0] = src->owner[0];
890 124299 dst->owner[1] = src->owner[1];
891
892 124299 ret = av_frame_ref(dst->f, src->f);
893
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 124299 times.
124299 if (ret < 0)
894 return ret;
895
896
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 124299 times.
124299 av_assert0(!dst->progress);
897
898
2/2
✓ Branch 0 taken 562 times.
✓ Branch 1 taken 123737 times.
124299 if (src->progress &&
899
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 562 times.
562 !(dst->progress = av_buffer_ref(src->progress))) {
900 ff_thread_release_ext_buffer(dst->owner[0], dst);
901 return AVERROR(ENOMEM);
902 }
903
904 124299 return 0;
905 }
906
907 #if !HAVE_THREADS
908
909 enum AVPixelFormat ff_thread_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
910 {
911 return ff_get_format(avctx, fmt);
912 }
913
914 int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f, int flags)
915 {
916 return ff_get_buffer(avctx, f, flags);
917 }
918
919 int ff_thread_get_ext_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
920 {
921 f->owner[0] = f->owner[1] = avctx;
922 return ff_get_buffer(avctx, f->f, flags);
923 }
924
925 void ff_thread_release_buffer(AVCodecContext *avctx, AVFrame *f)
926 {
927 if (f)
928 av_frame_unref(f);
929 }
930
931 void ff_thread_release_ext_buffer(AVCodecContext *avctx, ThreadFrame *f)
932 {
933 f->owner[0] = f->owner[1] = NULL;
934 if (f->f)
935 av_frame_unref(f->f);
936 }
937
938 void ff_thread_finish_setup(AVCodecContext *avctx)
939 {
940 }
941
942 void ff_thread_report_progress(ThreadFrame *f, int progress, int field)
943 {
944 }
945
946 void ff_thread_await_progress(const ThreadFrame *f, int progress, int field)
947 {
948 }
949
950 int ff_thread_can_start_frame(AVCodecContext *avctx)
951 {
952 return 1;
953 }
954
955 int ff_slice_thread_init_progress(AVCodecContext *avctx)
956 {
957 return 0;
958 }
959
960 int ff_slice_thread_allocz_entries(AVCodecContext *avctx, int count)
961 {
962 return 0;
963 }
964
965 void ff_thread_await_progress2(AVCodecContext *avctx, int field, int thread, int shift)
966 {
967 }
968
969 void ff_thread_report_progress2(AVCodecContext *avctx, int field, int thread, int n)
970 {
971 }
972
973 #endif
974
975 596720 const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p,
976 const uint8_t *end,
977 uint32_t *av_restrict state)
978 {
979 int i;
980
981
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 596720 times.
596720 av_assert0(p <= end);
982
2/2
✓ Branch 0 taken 648 times.
✓ Branch 1 taken 596072 times.
596720 if (p >= end)
983 648 return end;
984
985
2/2
✓ Branch 0 taken 1782850 times.
✓ Branch 1 taken 592301 times.
2375151 for (i = 0; i < 3; i++) {
986 1782850 uint32_t tmp = *state << 8;
987 1782850 *state = tmp + *(p++);
988
4/4
✓ Branch 0 taken 1781973 times.
✓ Branch 1 taken 877 times.
✓ Branch 2 taken 2894 times.
✓ Branch 3 taken 1779079 times.
1782850 if (tmp == 0x100 || p == end)
989 3771 return p;
990 }
991
992
2/2
✓ Branch 0 taken 168337453 times.
✓ Branch 1 taken 57180 times.
168394633 while (p < end) {
993
2/2
✓ Branch 0 taken 145197582 times.
✓ Branch 1 taken 23139871 times.
168337453 if (p[-1] > 1 ) p += 3;
994
2/2
✓ Branch 0 taken 8360372 times.
✓ Branch 1 taken 14779499 times.
23139871 else if (p[-2] ) p += 2;
995
2/2
✓ Branch 0 taken 14244378 times.
✓ Branch 1 taken 535121 times.
14779499 else if (p[-3]|(p[-1]-1)) p++;
996 else {
997 535121 p++;
998 535121 break;
999 }
1000 }
1001
1002
2/2
✓ Branch 0 taken 36320 times.
✓ Branch 1 taken 555981 times.
592301 p = FFMIN(p, end) - 4;
1003 592301 *state = AV_RB32(p);
1004
1005 592301 return p + 4;
1006 }
1007
1008 440 AVCPBProperties *av_cpb_properties_alloc(size_t *size)
1009 {
1010 440 AVCPBProperties *props = av_mallocz(sizeof(AVCPBProperties));
1011
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 440 times.
440 if (!props)
1012 return NULL;
1013
1014
1/2
✓ Branch 0 taken 440 times.
✗ Branch 1 not taken.
440 if (size)
1015 440 *size = sizeof(*props);
1016
1017 440 props->vbv_delay = UINT64_MAX;
1018
1019 440 return props;
1020 }
1021
1022 862 AVCPBProperties *ff_add_cpb_side_data(AVCodecContext *avctx)
1023 {
1024 AVPacketSideData *tmp;
1025 AVCPBProperties *props;
1026 size_t size;
1027 int i;
1028
1029
2/2
✓ Branch 0 taken 447 times.
✓ Branch 1 taken 415 times.
862 for (i = 0; i < avctx->nb_coded_side_data; i++)
1030
1/2
✓ Branch 0 taken 447 times.
✗ Branch 1 not taken.
447 if (avctx->coded_side_data[i].type == AV_PKT_DATA_CPB_PROPERTIES)
1031 447 return (AVCPBProperties *)avctx->coded_side_data[i].data;
1032
1033 415 props = av_cpb_properties_alloc(&size);
1034
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 415 times.
415 if (!props)
1035 return NULL;
1036
1037 415 tmp = av_realloc_array(avctx->coded_side_data, avctx->nb_coded_side_data + 1, sizeof(*tmp));
1038
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 415 times.
415 if (!tmp) {
1039 av_freep(&props);
1040 return NULL;
1041 }
1042
1043 415 avctx->coded_side_data = tmp;
1044 415 avctx->nb_coded_side_data++;
1045
1046 415 avctx->coded_side_data[avctx->nb_coded_side_data - 1].type = AV_PKT_DATA_CPB_PROPERTIES;
1047 415 avctx->coded_side_data[avctx->nb_coded_side_data - 1].data = (uint8_t*)props;
1048 415 avctx->coded_side_data[avctx->nb_coded_side_data - 1].size = size;
1049
1050 415 return props;
1051 }
1052
1053 static unsigned bcd2uint(uint8_t bcd)
1054 {
1055 unsigned low = bcd & 0xf;
1056 unsigned high = bcd >> 4;
1057 if (low > 9 || high > 9)
1058 return 0;
1059 return low + 10*high;
1060 }
1061
1062 int ff_alloc_timecode_sei(const AVFrame *frame, AVRational rate, size_t prefix_len,
1063 void **data, size_t *sei_size)
1064 {
1065 AVFrameSideData *sd = NULL;
1066 uint8_t *sei_data;
1067 PutBitContext pb;
1068 uint32_t *tc;
1069 int m;
1070
1071 if (frame)
1072 sd = av_frame_get_side_data(frame, AV_FRAME_DATA_S12M_TIMECODE);
1073
1074 if (!sd) {
1075 *data = NULL;
1076 return 0;
1077 }
1078 tc = (uint32_t*)sd->data;
1079 m = tc[0] & 3;
1080
1081 *sei_size = sizeof(uint32_t) * 4;
1082 *data = av_mallocz(*sei_size + prefix_len);
1083 if (!*data)
1084 return AVERROR(ENOMEM);
1085 sei_data = (uint8_t*)*data + prefix_len;
1086
1087 init_put_bits(&pb, sei_data, *sei_size);
1088 put_bits(&pb, 2, m); // num_clock_ts
1089
1090 for (int j = 1; j <= m; j++) {
1091 uint32_t tcsmpte = tc[j];
1092 unsigned hh = bcd2uint(tcsmpte & 0x3f); // 6-bit hours
1093 unsigned mm = bcd2uint(tcsmpte>>8 & 0x7f); // 7-bit minutes
1094 unsigned ss = bcd2uint(tcsmpte>>16 & 0x7f); // 7-bit seconds
1095 unsigned ff = bcd2uint(tcsmpte>>24 & 0x3f); // 6-bit frames
1096 unsigned drop = tcsmpte & 1<<30 && !0; // 1-bit drop if not arbitrary bit
1097
1098 /* Calculate frame number of HEVC by SMPTE ST 12-1:2014 Sec 12.2 if rate > 30FPS */
1099 if (av_cmp_q(rate, (AVRational) {30, 1}) == 1) {
1100 unsigned pc;
1101 ff *= 2;
1102 if (av_cmp_q(rate, (AVRational) {50, 1}) == 0)
1103 pc = !!(tcsmpte & 1 << 7);
1104 else
1105 pc = !!(tcsmpte & 1 << 23);
1106 ff = (ff + pc) & 0x7f;
1107 }
1108
1109 put_bits(&pb, 1, 1); // clock_timestamp_flag
1110 put_bits(&pb, 1, 1); // units_field_based_flag
1111 put_bits(&pb, 5, 0); // counting_type
1112 put_bits(&pb, 1, 1); // full_timestamp_flag
1113 put_bits(&pb, 1, 0); // discontinuity_flag
1114 put_bits(&pb, 1, drop);
1115 put_bits(&pb, 9, ff);
1116 put_bits(&pb, 6, ss);
1117 put_bits(&pb, 6, mm);
1118 put_bits(&pb, 5, hh);
1119 put_bits(&pb, 5, 0);
1120 }
1121 flush_put_bits(&pb);
1122
1123 return 0;
1124 }
1125
1126 16483 int64_t ff_guess_coded_bitrate(AVCodecContext *avctx)
1127 {
1128 16483 AVRational framerate = avctx->framerate;
1129 16483 int bits_per_coded_sample = avctx->bits_per_coded_sample;
1130 int64_t bitrate;
1131
1132
3/4
✓ Branch 0 taken 16483 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 16474 times.
16483 if (!(framerate.num && framerate.den))
1133 9 framerate = av_inv_q(avctx->time_base);
1134
2/4
✓ Branch 0 taken 16483 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 16483 times.
16483 if (!(framerate.num && framerate.den))
1135 return 0;
1136
1137
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16483 times.
16483 if (!bits_per_coded_sample) {
1138 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
1139 bits_per_coded_sample = av_get_bits_per_pixel(desc);
1140 }
1141 16483 bitrate = (int64_t)bits_per_coded_sample * avctx->width * avctx->height *
1142 16483 framerate.num / framerate.den;
1143
1144 16483 return bitrate;
1145 }
1146
1147 2400 int ff_int_from_list_or_default(void *ctx, const char * val_name, int val,
1148 const int * array_valid_values, int default_value)
1149 {
1150 2400 int i = 0, ref_val;
1151
1152 while (1) {
1153 6400 ref_val = array_valid_values[i];
1154
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6400 times.
6400 if (ref_val == INT_MAX)
1155 break;
1156
2/2
✓ Branch 0 taken 2400 times.
✓ Branch 1 taken 4000 times.
6400 if (val == ref_val)
1157 2400 return val;
1158 4000 i++;
1159 }
1160 /* val is not a valid value */
1161 av_log(ctx, AV_LOG_DEBUG,
1162 "%s %d are not supported. Set to default value : %d\n", val_name, val, default_value);
1163 return default_value;
1164 }
1165