FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/utils.c
Date: 2021-09-26 18:22:30
Exec Total Coverage
Lines: 405 555 73.0%
Branches: 300 422 71.1%

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/avstring.h"
31 #include "libavutil/channel_layout.h"
32 #include "libavutil/intreadwrite.h"
33 #include "libavutil/mem.h"
34 #include "libavutil/pixdesc.h"
35 #include "libavutil/imgutils.h"
36 #include "libavutil/pixfmt.h"
37 #include "avcodec.h"
38 #include "codec.h"
39 #include "hwconfig.h"
40 #include "thread.h"
41 #include "internal.h"
42 #include "put_bits.h"
43 #include "raw.h"
44 #include <stdlib.h>
45 #include <stdarg.h>
46 #include <stdatomic.h>
47 #include <limits.h>
48 #include <float.h>
49
50 94602 void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
51 {
52 94602 uint8_t **p = ptr;
53
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 94602 times.
94602 if (min_size > SIZE_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
54 av_freep(p);
55 *size = 0;
56 return;
57 }
58 94602 av_fast_mallocz(p, size, min_size + AV_INPUT_BUFFER_PADDING_SIZE);
59
1/2
✓ Branch 0 taken 94602 times.
✗ Branch 1 not taken.
94602 if (*p)
60 94602 memset(*p + min_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
61 }
62
63 653 void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size)
64 {
65 653 uint8_t **p = ptr;
66
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 653 times.
653 if (min_size > SIZE_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
67 av_freep(p);
68 *size = 0;
69 return;
70 }
71 653 av_fast_malloc(p, size, min_size + AV_INPUT_BUFFER_PADDING_SIZE);
72
1/2
✓ Branch 0 taken 653 times.
✗ Branch 1 not taken.
653 if (*p)
73 653 memset(*p, 0, min_size + AV_INPUT_BUFFER_PADDING_SIZE);
74 }
75
76 6378632 int av_codec_is_encoder(const AVCodec *codec)
77 {
78
8/8
✓ Branch 0 taken 6346308 times.
✓ Branch 1 taken 32324 times.
✓ Branch 2 taken 6277106 times.
✓ Branch 3 taken 69202 times.
✓ Branch 4 taken 3633112 times.
✓ Branch 5 taken 2643994 times.
✓ Branch 6 taken 68838 times.
✓ Branch 7 taken 3564274 times.
6378632 return codec && (codec->encode_sub || codec->encode2 || codec->receive_packet);
79 }
80
81 11681940 int av_codec_is_decoder(const AVCodec *codec)
82 {
83
6/6
✓ Branch 0 taken 11649616 times.
✓ Branch 1 taken 32324 times.
✓ Branch 2 taken 5204321 times.
✓ Branch 3 taken 6445295 times.
✓ Branch 4 taken 285507 times.
✓ Branch 5 taken 4918814 times.
11681940 return codec && (codec->decode || codec->receive_frame);
84 }
85
86 29625 int ff_set_dimensions(AVCodecContext *s, int width, int height)
87 {
88 29625 int ret = av_image_check_size2(width, height, s->max_pixels, AV_PIX_FMT_NONE, 0, s);
89
90
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 29624 times.
29625 if (ret < 0)
91 1 width = height = 0;
92
93 29625 s->coded_width = width;
94 29625 s->coded_height = height;
95 29625 s->width = AV_CEIL_RSHIFT(width, s->lowres);
96 29625 s->height = AV_CEIL_RSHIFT(height, s->lowres);
97
98 29625 return ret;
99 }
100
101 2519 int ff_set_sar(AVCodecContext *avctx, AVRational sar)
102 {
103 2519 int ret = av_image_check_sar(avctx->width, avctx->height, sar);
104
105
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2514 times.
2519 if (ret < 0) {
106 5 av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %d/%d\n",
107 sar.num, sar.den);
108 5 avctx->sample_aspect_ratio = (AVRational){ 0, 1 };
109 5 return ret;
110 } else {
111 2514 avctx->sample_aspect_ratio = sar;
112 }
113 2514 return 0;
114 }
115
116 20560 int ff_side_data_update_matrix_encoding(AVFrame *frame,
117 enum AVMatrixEncoding matrix_encoding)
118 {
119 AVFrameSideData *side_data;
120 enum AVMatrixEncoding *data;
121
122 20560 side_data = av_frame_get_side_data(frame, AV_FRAME_DATA_MATRIXENCODING);
123
1/2
✓ Branch 0 taken 20560 times.
✗ Branch 1 not taken.
20560 if (!side_data)
124 20560 side_data = av_frame_new_side_data(frame, AV_FRAME_DATA_MATRIXENCODING,
125 sizeof(enum AVMatrixEncoding));
126
127
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20560 times.
20560 if (!side_data)
128 return AVERROR(ENOMEM);
129
130 20560 data = (enum AVMatrixEncoding*)side_data->data;
131 20560 *data = matrix_encoding;
132
133 20560 return 0;
134 }
135
136 8549 void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height,
137 int linesize_align[AV_NUM_DATA_POINTERS])
138 {
139 int i;
140 8549 int w_align = 1;
141 8549 int h_align = 1;
142 8549 AVPixFmtDescriptor const *desc = av_pix_fmt_desc_get(s->pix_fmt);
143
144
1/2
✓ Branch 0 taken 8549 times.
✗ Branch 1 not taken.
8549 if (desc) {
145 8549 w_align = 1 << desc->log2_chroma_w;
146 8549 h_align = 1 << desc->log2_chroma_h;
147 }
148
149
9/9
✓ Branch 0 taken 7611 times.
✓ Branch 1 taken 26 times.
✓ Branch 2 taken 21 times.
✓ Branch 3 taken 34 times.
✓ Branch 4 taken 129 times.
✓ Branch 5 taken 77 times.
✓ Branch 6 taken 201 times.
✓ Branch 7 taken 27 times.
✓ Branch 8 taken 423 times.
8549 switch (s->pix_fmt) {
150 7611 case AV_PIX_FMT_YUV420P:
151 case AV_PIX_FMT_YUYV422:
152 case AV_PIX_FMT_YVYU422:
153 case AV_PIX_FMT_UYVY422:
154 case AV_PIX_FMT_YUV422P:
155 case AV_PIX_FMT_YUV440P:
156 case AV_PIX_FMT_YUV444P:
157 case AV_PIX_FMT_GBRP:
158 case AV_PIX_FMT_GBRAP:
159 case AV_PIX_FMT_GRAY8:
160 case AV_PIX_FMT_GRAY16BE:
161 case AV_PIX_FMT_GRAY16LE:
162 case AV_PIX_FMT_YUVJ420P:
163 case AV_PIX_FMT_YUVJ422P:
164 case AV_PIX_FMT_YUVJ440P:
165 case AV_PIX_FMT_YUVJ444P:
166 case AV_PIX_FMT_YUVA420P:
167 case AV_PIX_FMT_YUVA422P:
168 case AV_PIX_FMT_YUVA444P:
169 case AV_PIX_FMT_YUV420P9LE:
170 case AV_PIX_FMT_YUV420P9BE:
171 case AV_PIX_FMT_YUV420P10LE:
172 case AV_PIX_FMT_YUV420P10BE:
173 case AV_PIX_FMT_YUV420P12LE:
174 case AV_PIX_FMT_YUV420P12BE:
175 case AV_PIX_FMT_YUV420P14LE:
176 case AV_PIX_FMT_YUV420P14BE:
177 case AV_PIX_FMT_YUV420P16LE:
178 case AV_PIX_FMT_YUV420P16BE:
179 case AV_PIX_FMT_YUVA420P9LE:
180 case AV_PIX_FMT_YUVA420P9BE:
181 case AV_PIX_FMT_YUVA420P10LE:
182 case AV_PIX_FMT_YUVA420P10BE:
183 case AV_PIX_FMT_YUVA420P16LE:
184 case AV_PIX_FMT_YUVA420P16BE:
185 case AV_PIX_FMT_YUV422P9LE:
186 case AV_PIX_FMT_YUV422P9BE:
187 case AV_PIX_FMT_YUV422P10LE:
188 case AV_PIX_FMT_YUV422P10BE:
189 case AV_PIX_FMT_YUV422P12LE:
190 case AV_PIX_FMT_YUV422P12BE:
191 case AV_PIX_FMT_YUV422P14LE:
192 case AV_PIX_FMT_YUV422P14BE:
193 case AV_PIX_FMT_YUV422P16LE:
194 case AV_PIX_FMT_YUV422P16BE:
195 case AV_PIX_FMT_YUVA422P9LE:
196 case AV_PIX_FMT_YUVA422P9BE:
197 case AV_PIX_FMT_YUVA422P10LE:
198 case AV_PIX_FMT_YUVA422P10BE:
199 case AV_PIX_FMT_YUVA422P12LE:
200 case AV_PIX_FMT_YUVA422P12BE:
201 case AV_PIX_FMT_YUVA422P16LE:
202 case AV_PIX_FMT_YUVA422P16BE:
203 case AV_PIX_FMT_YUV440P10LE:
204 case AV_PIX_FMT_YUV440P10BE:
205 case AV_PIX_FMT_YUV440P12LE:
206 case AV_PIX_FMT_YUV440P12BE:
207 case AV_PIX_FMT_YUV444P9LE:
208 case AV_PIX_FMT_YUV444P9BE:
209 case AV_PIX_FMT_YUV444P10LE:
210 case AV_PIX_FMT_YUV444P10BE:
211 case AV_PIX_FMT_YUV444P12LE:
212 case AV_PIX_FMT_YUV444P12BE:
213 case AV_PIX_FMT_YUV444P14LE:
214 case AV_PIX_FMT_YUV444P14BE:
215 case AV_PIX_FMT_YUV444P16LE:
216 case AV_PIX_FMT_YUV444P16BE:
217 case AV_PIX_FMT_YUVA444P9LE:
218 case AV_PIX_FMT_YUVA444P9BE:
219 case AV_PIX_FMT_YUVA444P10LE:
220 case AV_PIX_FMT_YUVA444P10BE:
221 case AV_PIX_FMT_YUVA444P12LE:
222 case AV_PIX_FMT_YUVA444P12BE:
223 case AV_PIX_FMT_YUVA444P16LE:
224 case AV_PIX_FMT_YUVA444P16BE:
225 case AV_PIX_FMT_GBRP9LE:
226 case AV_PIX_FMT_GBRP9BE:
227 case AV_PIX_FMT_GBRP10LE:
228 case AV_PIX_FMT_GBRP10BE:
229 case AV_PIX_FMT_GBRP12LE:
230 case AV_PIX_FMT_GBRP12BE:
231 case AV_PIX_FMT_GBRP14LE:
232 case AV_PIX_FMT_GBRP14BE:
233 case AV_PIX_FMT_GBRP16LE:
234 case AV_PIX_FMT_GBRP16BE:
235 case AV_PIX_FMT_GBRAP12LE:
236 case AV_PIX_FMT_GBRAP12BE:
237 case AV_PIX_FMT_GBRAP16LE:
238 case AV_PIX_FMT_GBRAP16BE:
239 7611 w_align = 16; //FIXME assume 16 pixel per macroblock
240 7611 h_align = 16 * 2; // interlaced needs 2 macroblocks height
241 7611 break;
242 26 case AV_PIX_FMT_YUV411P:
243 case AV_PIX_FMT_YUVJ411P:
244 case AV_PIX_FMT_UYYVYY411:
245 26 w_align = 32;
246 26 h_align = 16 * 2;
247 26 break;
248 21 case AV_PIX_FMT_YUV410P:
249
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 11 times.
21 if (s->codec_id == AV_CODEC_ID_SVQ1) {
250 10 w_align = 64;
251 10 h_align = 64;
252 }
253 21 break;
254 34 case AV_PIX_FMT_RGB555:
255
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 33 times.
34 if (s->codec_id == AV_CODEC_ID_RPZA) {
256 1 w_align = 4;
257 1 h_align = 4;
258 }
259
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 33 times.
34 if (s->codec_id == AV_CODEC_ID_INTERPLAY_VIDEO) {
260 1 w_align = 8;
261 1 h_align = 8;
262 }
263 34 break;
264 129 case AV_PIX_FMT_PAL8:
265 case AV_PIX_FMT_BGR8:
266 case AV_PIX_FMT_RGB8:
267
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 1 times.
129 if (s->codec_id == AV_CODEC_ID_SMC ||
268
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 127 times.
128 s->codec_id == AV_CODEC_ID_CINEPAK) {
269 2 w_align = 4;
270 2 h_align = 4;
271 }
272
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 1 times.
129 if (s->codec_id == AV_CODEC_ID_JV ||
273
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 127 times.
128 s->codec_id == AV_CODEC_ID_INTERPLAY_VIDEO) {
274 2 w_align = 8;
275 2 h_align = 8;
276 }
277
1/2
✓ Branch 0 taken 129 times.
✗ Branch 1 not taken.
129 if (s->codec_id == AV_CODEC_ID_MJPEG ||
278
1/2
✓ Branch 0 taken 129 times.
✗ Branch 1 not taken.
129 s->codec_id == AV_CODEC_ID_MJPEGB ||
279
1/2
✓ Branch 0 taken 129 times.
✗ Branch 1 not taken.
129 s->codec_id == AV_CODEC_ID_LJPEG ||
280
1/2
✓ Branch 0 taken 129 times.
✗ Branch 1 not taken.
129 s->codec_id == AV_CODEC_ID_SMVJPEG ||
281
1/2
✓ Branch 0 taken 129 times.
✗ Branch 1 not taken.
129 s->codec_id == AV_CODEC_ID_AMV ||
282
1/2
✓ Branch 0 taken 129 times.
✗ Branch 1 not taken.
129 s->codec_id == AV_CODEC_ID_SP5X ||
283
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 121 times.
129 s->codec_id == AV_CODEC_ID_JPEGLS) {
284 8 w_align = 8;
285 8 h_align = 2*8;
286 }
287 129 break;
288 77 case AV_PIX_FMT_BGR24:
289
2/2
✓ Branch 0 taken 76 times.
✓ Branch 1 taken 1 times.
77 if ((s->codec_id == AV_CODEC_ID_MSZH) ||
290
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 71 times.
76 (s->codec_id == AV_CODEC_ID_ZLIB)) {
291 6 w_align = 4;
292 6 h_align = 4;
293 }
294 77 break;
295 201 case AV_PIX_FMT_RGB24:
296
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 195 times.
201 if (s->codec_id == AV_CODEC_ID_CINEPAK) {
297 6 w_align = 4;
298 6 h_align = 4;
299 }
300 201 break;
301 27 case AV_PIX_FMT_BGR0:
302
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
27 if (s->codec_id == AV_CODEC_ID_ARGO) {
303 w_align = 4;
304 h_align = 4;
305 }
306 27 break;
307 423 default:
308 423 break;
309 }
310
311
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8547 times.
8549 if (s->codec_id == AV_CODEC_ID_IFF_ILBM) {
312 2 w_align = FFMAX(w_align, 8);
313 }
314
315 8549 *width = FFALIGN(*width, w_align);
316 8549 *height = FFALIGN(*height, h_align);
317
4/4
✓ Branch 0 taken 8011 times.
✓ Branch 1 taken 538 times.
✓ Branch 2 taken 8010 times.
✓ Branch 3 taken 1 times.
8549 if (s->codec_id == AV_CODEC_ID_H264 || s->lowres ||
318
4/4
✓ Branch 0 taken 8009 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 8002 times.
✓ Branch 3 taken 7 times.
8010 s->codec_id == AV_CODEC_ID_VP5 || s->codec_id == AV_CODEC_ID_VP6 ||
319
4/4
✓ Branch 0 taken 8000 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 7998 times.
8002 s->codec_id == AV_CODEC_ID_VP6F || s->codec_id == AV_CODEC_ID_VP6A
320 ) {
321 // some of the optimized chroma MC reads one line too much
322 // which is also done in mpeg decoders with lowres > 0
323 551 *height += 2;
324
325 // H.264 uses edge emulation for out of frame motion vectors, for this
326 // it requires a temporary area large enough to hold a 21x21 block,
327 // increasing witdth ensure that the temporary area is large enough,
328 // the next rounded up width is 32
329 551 *width = FFMAX(*width, 32);
330 }
331
332
2/2
✓ Branch 0 taken 34196 times.
✓ Branch 1 taken 8549 times.
42745 for (i = 0; i < 4; i++)
333 34196 linesize_align[i] = STRIDE_ALIGN;
334 8549 }
335
336 void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height)
337 {
338 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->pix_fmt);
339 int chroma_shift = desc->log2_chroma_w;
340 int linesize_align[AV_NUM_DATA_POINTERS];
341 int align;
342
343 avcodec_align_dimensions2(s, width, height, linesize_align);
344 align = FFMAX(linesize_align[0], linesize_align[3]);
345 linesize_align[1] <<= chroma_shift;
346 linesize_align[2] <<= chroma_shift;
347 align = FFMAX3(align, linesize_align[1], linesize_align[2]);
348 *width = FFALIGN(*width, align);
349 }
350
351 14 int avcodec_enum_to_chroma_pos(int *xpos, int *ypos, enum AVChromaLocation pos)
352 {
353
2/4
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 14 times.
14 if (pos <= AVCHROMA_LOC_UNSPECIFIED || pos >= AVCHROMA_LOC_NB)
354 return AVERROR(EINVAL);
355 14 pos--;
356
357 14 *xpos = (pos&1) * 128;
358 14 *ypos = ((pos>>1)^(pos<4)) * 128;
359
360 14 return 0;
361 }
362
363 10 enum AVChromaLocation avcodec_chroma_pos_to_enum(int xpos, int ypos)
364 {
365 int pos, xout, yout;
366
367
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 for (pos = AVCHROMA_LOC_UNSPECIFIED + 1; pos < AVCHROMA_LOC_NB; pos++) {
368
3/6
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 10 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 10 times.
✗ Branch 6 not taken.
10 if (avcodec_enum_to_chroma_pos(&xout, &yout, pos) == 0 && xout == xpos && yout == ypos)
369 10 return pos;
370 }
371 return AVCHROMA_LOC_UNSPECIFIED;
372 }
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 17 void ff_color_frame(AVFrame *frame, const int c[4])
410 {
411 17 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
412 int p, y;
413
414
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 av_assert0(desc->flags & AV_PIX_FMT_FLAG_PLANAR);
415
416
2/2
✓ Branch 0 taken 51 times.
✓ Branch 1 taken 17 times.
68 for (p = 0; p<desc->nb_components; p++) {
417 51 uint8_t *dst = frame->data[p];
418
4/4
✓ Branch 0 taken 34 times.
✓ Branch 1 taken 17 times.
✓ Branch 2 taken 17 times.
✓ Branch 3 taken 17 times.
51 int is_chroma = p == 1 || p == 2;
419
2/2
✓ Branch 0 taken 34 times.
✓ Branch 1 taken 17 times.
51 int bytes = is_chroma ? AV_CEIL_RSHIFT(frame->width, desc->log2_chroma_w) : frame->width;
420
2/2
✓ Branch 0 taken 34 times.
✓ Branch 1 taken 17 times.
51 int height = is_chroma ? AV_CEIL_RSHIFT(frame->height, desc->log2_chroma_h) : frame->height;
421
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 51 times.
51 if (desc->comp[0].depth >= 9) {
422 ((uint16_t*)dst)[0] = c[p];
423 av_memcpy_backptr(dst + 2, 2, bytes - 2);
424 dst += frame->linesize[p];
425 for (y = 1; y < height; y++) {
426 memcpy(dst, frame->data[p], 2*bytes);
427 dst += frame->linesize[p];
428 }
429 } else {
430
2/2
✓ Branch 0 taken 25152 times.
✓ Branch 1 taken 51 times.
25203 for (y = 0; y < height; y++) {
431 25152 memset(dst, c[p], bytes);
432 25152 dst += frame->linesize[p];
433 }
434 }
435 }
436 17 }
437
438 1368 enum AVPixelFormat avpriv_find_pix_fmt(const PixelFormatTag *tags,
439 unsigned int fourcc)
440 {
441
2/2
✓ Branch 0 taken 12992 times.
✓ Branch 1 taken 198 times.
13190 while (tags->pix_fmt >= 0) {
442
2/2
✓ Branch 0 taken 1170 times.
✓ Branch 1 taken 11822 times.
12992 if (tags->fourcc == fourcc)
443 1170 return tags->pix_fmt;
444 11822 tags++;
445 }
446 198 return AV_PIX_FMT_NONE;
447 }
448
449 166815 int avpriv_codec_get_cap_skip_frame_fill_param(const AVCodec *codec){
450 166815 return !!(codec->caps_internal & FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM);
451 }
452
453 16505 const char *avcodec_get_name(enum AVCodecID id)
454 {
455 const AVCodecDescriptor *cd;
456 const AVCodec *codec;
457
458
2/2
✓ Branch 0 taken 164 times.
✓ Branch 1 taken 16341 times.
16505 if (id == AV_CODEC_ID_NONE)
459 164 return "none";
460 16341 cd = avcodec_descriptor_get(id);
461
2/2
✓ Branch 0 taken 16339 times.
✓ Branch 1 taken 2 times.
16341 if (cd)
462 16339 return cd->name;
463 2 av_log(NULL, AV_LOG_WARNING, "Codec 0x%x is not in the full list.\n", id);
464 2 codec = avcodec_find_decoder(id);
465
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (codec)
466 return codec->name;
467 2 codec = avcodec_find_encoder(id);
468
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (codec)
469 return codec->name;
470 2 return "unknown_codec";
471 }
472
473 const char *av_get_profile_name(const AVCodec *codec, int profile)
474 {
475 const AVProfile *p;
476 if (profile == FF_PROFILE_UNKNOWN || !codec->profiles)
477 return NULL;
478
479 for (p = codec->profiles; p->profile != FF_PROFILE_UNKNOWN; p++)
480 if (p->profile == profile)
481 return p->name;
482
483 return NULL;
484 }
485
486 12877 const char *avcodec_profile_name(enum AVCodecID codec_id, int profile)
487 {
488 12877 const AVCodecDescriptor *desc = avcodec_descriptor_get(codec_id);
489 const AVProfile *p;
490
491
5/6
✓ Branch 0 taken 1750 times.
✓ Branch 1 taken 11127 times.
✓ Branch 2 taken 1750 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 129 times.
✓ Branch 5 taken 1621 times.
12877 if (profile == FF_PROFILE_UNKNOWN || !desc || !desc->profiles)
492 11256 return NULL;
493
494
2/2
✓ Branch 0 taken 4331 times.
✓ Branch 1 taken 10 times.
4341 for (p = desc->profiles; p->profile != FF_PROFILE_UNKNOWN; p++)
495
2/2
✓ Branch 0 taken 1611 times.
✓ Branch 1 taken 2720 times.
4331 if (p->profile == profile)
496 1611 return p->name;
497
498 10 return NULL;
499 }
500
501 813121 int av_get_exact_bits_per_sample(enum AVCodecID codec_id)
502 {
503
7/7
✓ Branch 0 taken 11188 times.
✓ Branch 1 taken 11702 times.
✓ Branch 2 taken 545979 times.
✓ Branch 3 taken 45041 times.
✓ Branch 4 taken 28022 times.
✓ Branch 5 taken 21361 times.
✓ Branch 6 taken 149828 times.
813121 switch (codec_id) {
504 11188 case AV_CODEC_ID_8SVX_EXP:
505 case AV_CODEC_ID_8SVX_FIB:
506 case AV_CODEC_ID_ADPCM_ARGO:
507 case AV_CODEC_ID_ADPCM_CT:
508 case AV_CODEC_ID_ADPCM_IMA_ALP:
509 case AV_CODEC_ID_ADPCM_IMA_AMV:
510 case AV_CODEC_ID_ADPCM_IMA_APC:
511 case AV_CODEC_ID_ADPCM_IMA_APM:
512 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
513 case AV_CODEC_ID_ADPCM_IMA_OKI:
514 case AV_CODEC_ID_ADPCM_IMA_WS:
515 case AV_CODEC_ID_ADPCM_IMA_SSI:
516 case AV_CODEC_ID_ADPCM_G722:
517 case AV_CODEC_ID_ADPCM_YAMAHA:
518 case AV_CODEC_ID_ADPCM_AICA:
519 11188 return 4;
520 11702 case AV_CODEC_ID_DSD_LSBF:
521 case AV_CODEC_ID_DSD_MSBF:
522 case AV_CODEC_ID_DSD_LSBF_PLANAR:
523 case AV_CODEC_ID_DSD_MSBF_PLANAR:
524 case AV_CODEC_ID_PCM_ALAW:
525 case AV_CODEC_ID_PCM_MULAW:
526 case AV_CODEC_ID_PCM_VIDC:
527 case AV_CODEC_ID_PCM_S8:
528 case AV_CODEC_ID_PCM_S8_PLANAR:
529 case AV_CODEC_ID_PCM_SGA:
530 case AV_CODEC_ID_PCM_U8:
531 case AV_CODEC_ID_SDX2_DPCM:
532 case AV_CODEC_ID_DERF_DPCM:
533 11702 return 8;
534 545979 case AV_CODEC_ID_PCM_S16BE:
535 case AV_CODEC_ID_PCM_S16BE_PLANAR:
536 case AV_CODEC_ID_PCM_S16LE:
537 case AV_CODEC_ID_PCM_S16LE_PLANAR:
538 case AV_CODEC_ID_PCM_U16BE:
539 case AV_CODEC_ID_PCM_U16LE:
540 545979 return 16;
541 45041 case AV_CODEC_ID_PCM_S24DAUD:
542 case AV_CODEC_ID_PCM_S24BE:
543 case AV_CODEC_ID_PCM_S24LE:
544 case AV_CODEC_ID_PCM_S24LE_PLANAR:
545 case AV_CODEC_ID_PCM_U24BE:
546 case AV_CODEC_ID_PCM_U24LE:
547 45041 return 24;
548 28022 case AV_CODEC_ID_PCM_S32BE:
549 case AV_CODEC_ID_PCM_S32LE:
550 case AV_CODEC_ID_PCM_S32LE_PLANAR:
551 case AV_CODEC_ID_PCM_U32BE:
552 case AV_CODEC_ID_PCM_U32LE:
553 case AV_CODEC_ID_PCM_F32BE:
554 case AV_CODEC_ID_PCM_F32LE:
555 case AV_CODEC_ID_PCM_F24LE:
556 case AV_CODEC_ID_PCM_F16LE:
557 28022 return 32;
558 21361 case AV_CODEC_ID_PCM_F64BE:
559 case AV_CODEC_ID_PCM_F64LE:
560 case AV_CODEC_ID_PCM_S64BE:
561 case AV_CODEC_ID_PCM_S64LE:
562 21361 return 64;
563 149828 default:
564 149828 return 0;
565 }
566 }
567
568 17 enum AVCodecID av_get_pcm_codec(enum AVSampleFormat fmt, int be)
569 {
570 static const enum AVCodecID map[][2] = {
571 [AV_SAMPLE_FMT_U8 ] = { AV_CODEC_ID_PCM_U8, AV_CODEC_ID_PCM_U8 },
572 [AV_SAMPLE_FMT_S16 ] = { AV_CODEC_ID_PCM_S16LE, AV_CODEC_ID_PCM_S16BE },
573 [AV_SAMPLE_FMT_S32 ] = { AV_CODEC_ID_PCM_S32LE, AV_CODEC_ID_PCM_S32BE },
574 [AV_SAMPLE_FMT_FLT ] = { AV_CODEC_ID_PCM_F32LE, AV_CODEC_ID_PCM_F32BE },
575 [AV_SAMPLE_FMT_DBL ] = { AV_CODEC_ID_PCM_F64LE, AV_CODEC_ID_PCM_F64BE },
576 [AV_SAMPLE_FMT_U8P ] = { AV_CODEC_ID_PCM_U8, AV_CODEC_ID_PCM_U8 },
577 [AV_SAMPLE_FMT_S16P] = { AV_CODEC_ID_PCM_S16LE, AV_CODEC_ID_PCM_S16BE },
578 [AV_SAMPLE_FMT_S32P] = { AV_CODEC_ID_PCM_S32LE, AV_CODEC_ID_PCM_S32BE },
579 [AV_SAMPLE_FMT_S64P] = { AV_CODEC_ID_PCM_S64LE, AV_CODEC_ID_PCM_S64BE },
580 [AV_SAMPLE_FMT_FLTP] = { AV_CODEC_ID_PCM_F32LE, AV_CODEC_ID_PCM_F32BE },
581 [AV_SAMPLE_FMT_DBLP] = { AV_CODEC_ID_PCM_F64LE, AV_CODEC_ID_PCM_F64BE },
582 };
583
2/4
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 17 times.
17 if (fmt < 0 || fmt >= FF_ARRAY_ELEMS(map))
584 return AV_CODEC_ID_NONE;
585
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
17 if (be < 0 || be > 1)
586 17 be = AV_NE(1, 0);
587 17 return map[fmt][be];
588 }
589
590 324167 int av_get_bits_per_sample(enum AVCodecID codec_id)
591 {
592
4/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 64 times.
✓ Branch 3 taken 324097 times.
324167 switch (codec_id) {
593 3 case AV_CODEC_ID_ADPCM_SBPRO_2:
594 3 return 2;
595 3 case AV_CODEC_ID_ADPCM_SBPRO_3:
596 3 return 3;
597 64 case AV_CODEC_ID_ADPCM_SBPRO_4:
598 case AV_CODEC_ID_ADPCM_IMA_WAV:
599 case AV_CODEC_ID_ADPCM_IMA_QT:
600 case AV_CODEC_ID_ADPCM_SWF:
601 case AV_CODEC_ID_ADPCM_MS:
602 64 return 4;
603 324097 default:
604 324097 return av_get_exact_bits_per_sample(codec_id);
605 }
606 }
607
608 483121 static int get_audio_frame_duration(enum AVCodecID id, int sr, int ch, int ba,
609 uint32_t tag, int bits_per_coded_sample, int64_t bitrate,
610 uint8_t * extradata, int frame_size, int frame_bytes)
611 {
612 483121 int bps = av_get_exact_bits_per_sample(id);
613
4/4
✓ Branch 0 taken 366963 times.
✓ Branch 1 taken 116158 times.
✓ Branch 2 taken 366675 times.
✓ Branch 3 taken 288 times.
483121 int framecount = (ba > 0 && frame_bytes / ba > 0) ? frame_bytes / ba : 1;
614
615 /* codecs with an exact constant bits per sample */
616
7/10
✓ Branch 0 taken 340506 times.
✓ Branch 1 taken 142615 times.
✓ Branch 2 taken 340506 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 340479 times.
✓ Branch 5 taken 27 times.
✓ Branch 6 taken 340479 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 340479 times.
✗ Branch 9 not taken.
483121 if (bps > 0 && ch > 0 && frame_bytes > 0 && ch < 32768 && bps < 32768)
617 340479 return (frame_bytes * 8LL) / (bps * ch);
618 142642 bps = bits_per_coded_sample;
619
620 /* codecs with a fixed packet duration */
621
10/12
✓ Branch 0 taken 16542 times.
✓ Branch 1 taken 8274 times.
✓ Branch 2 taken 600 times.
✓ Branch 3 taken 4428 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 4319 times.
✓ Branch 7 taken 4114 times.
✓ Branch 8 taken 813 times.
✓ Branch 9 taken 18455 times.
✓ Branch 10 taken 1626 times.
✓ Branch 11 taken 83471 times.
142642 switch (id) {
622 16542 case AV_CODEC_ID_ADPCM_ADX: return 32;
623 8274 case AV_CODEC_ID_ADPCM_IMA_QT: return 64;
624 600 case AV_CODEC_ID_ADPCM_EA_XAS: return 128;
625 4428 case AV_CODEC_ID_AMR_NB:
626 case AV_CODEC_ID_EVRC:
627 case AV_CODEC_ID_GSM:
628 case AV_CODEC_ID_QCELP:
629 4428 case AV_CODEC_ID_RA_288: return 160;
630 case AV_CODEC_ID_AMR_WB:
631 case AV_CODEC_ID_GSM_MS: return 320;
632 case AV_CODEC_ID_MP1: return 384;
633 4319 case AV_CODEC_ID_ATRAC1: return 512;
634 4114 case AV_CODEC_ID_ATRAC9:
635 case AV_CODEC_ID_ATRAC3:
636
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4114 times.
4114 if (framecount > INT_MAX/1024)
637 return 0;
638 4114 return 1024 * framecount;
639 813 case AV_CODEC_ID_ATRAC3P: return 2048;
640 18455 case AV_CODEC_ID_MP2:
641 18455 case AV_CODEC_ID_MUSEPACK7: return 1152;
642 1626 case AV_CODEC_ID_AC3: return 1536;
643 }
644
645
2/2
✓ Branch 0 taken 80746 times.
✓ Branch 1 taken 2725 times.
83471 if (sr > 0) {
646 /* calc from sample rate */
647
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 80737 times.
80746 if (id == AV_CODEC_ID_TTA)
648 9 return 256 * sr / 245;
649
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 80737 times.
80737 else if (id == AV_CODEC_ID_DST)
650 return 588 * sr / 44100;
651
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 80671 times.
80737 else if (id == AV_CODEC_ID_BINKAUDIO_DCT) {
652
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
66 if (sr / 22050 > 22)
653 return 0;
654 66 return (480 << (sr / 22050));
655 }
656
657
2/2
✓ Branch 0 taken 5333 times.
✓ Branch 1 taken 75338 times.
80671 if (id == AV_CODEC_ID_MP3)
658
2/2
✓ Branch 0 taken 224 times.
✓ Branch 1 taken 5109 times.
5333 return sr <= 24000 ? 576 : 1152;
659 }
660
661
2/2
✓ Branch 0 taken 22263 times.
✓ Branch 1 taken 55800 times.
78063 if (ba > 0) {
662 /* calc from block_align */
663
2/2
✓ Branch 0 taken 7249 times.
✓ Branch 1 taken 15014 times.
22263 if (id == AV_CODEC_ID_SIPR) {
664
4/5
✓ Branch 0 taken 3250 times.
✓ Branch 1 taken 1983 times.
✓ Branch 2 taken 1680 times.
✓ Branch 3 taken 336 times.
✗ Branch 4 not taken.
7249 switch (ba) {
665 3250 case 20: return 160;
666 1983 case 19: return 144;
667 1680 case 29: return 288;
668 336 case 37: return 480;
669 }
670
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15014 times.
15014 } else if (id == AV_CODEC_ID_ILBC) {
671 switch (ba) {
672 case 38: return 160;
673 case 50: return 240;
674 }
675 }
676 }
677
678
2/2
✓ Branch 0 taken 68124 times.
✓ Branch 1 taken 2690 times.
70814 if (frame_bytes > 0) {
679 /* calc from frame_bytes only */
680
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 68112 times.
68124 if (id == AV_CODEC_ID_TRUESPEECH)
681 12 return 240 * (frame_bytes / 32);
682
2/2
✓ Branch 0 taken 2074 times.
✓ Branch 1 taken 66038 times.
68112 if (id == AV_CODEC_ID_NELLYMOSER)
683 2074 return 256 * (frame_bytes / 64);
684
2/2
✓ Branch 0 taken 1057 times.
✓ Branch 1 taken 64981 times.
66038 if (id == AV_CODEC_ID_RA_144)
685 1057 return 160 * (frame_bytes / 20);
686
687
2/2
✓ Branch 0 taken 20099 times.
✓ Branch 1 taken 44882 times.
64981 if (bps > 0) {
688 /* calc from frame_bytes and bits_per_coded_sample */
689
3/4
✓ Branch 0 taken 19993 times.
✓ Branch 1 taken 106 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 19993 times.
20099 if (id == AV_CODEC_ID_ADPCM_G726 || id == AV_CODEC_ID_ADPCM_G726LE)
690 106 return frame_bytes * 8 / bps;
691 }
692
693
3/4
✓ Branch 0 taken 64774 times.
✓ Branch 1 taken 101 times.
✓ Branch 2 taken 64774 times.
✗ Branch 3 not taken.
64875 if (ch > 0 && ch < INT_MAX/16) {
694 /* calc from frame_bytes and channels */
695
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 138 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 1311 times.
✓ Branch 16 taken 55920 times.
64774 switch (id) {
696 case AV_CODEC_ID_FASTAUDIO:
697 return frame_bytes / (40 * ch) * 256;
698 case AV_CODEC_ID_ADPCM_IMA_MOFLEX:
699 return (frame_bytes - 4 * ch) / (128 * ch) * 256;
700 48 case AV_CODEC_ID_ADPCM_AFC:
701 48 return frame_bytes / (9 * ch) * 16;
702 33 case AV_CODEC_ID_ADPCM_PSX:
703 case AV_CODEC_ID_ADPCM_DTK:
704 33 frame_bytes /= 16 * ch;
705
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
33 if (frame_bytes > INT_MAX / 28)
706 return 0;
707 33 return frame_bytes * 28;
708 452 case AV_CODEC_ID_ADPCM_4XM:
709 case AV_CODEC_ID_ADPCM_IMA_ACORN:
710 case AV_CODEC_ID_ADPCM_IMA_DAT4:
711 case AV_CODEC_ID_ADPCM_IMA_ISS:
712 452 return (frame_bytes - 4 * ch) * 2 / ch;
713 1951 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
714 1951 return (frame_bytes - 4) * 2 / ch;
715 case AV_CODEC_ID_ADPCM_IMA_AMV:
716 return (frame_bytes - 8) * 2;
717 3580 case AV_CODEC_ID_ADPCM_THP:
718 case AV_CODEC_ID_ADPCM_THP_LE:
719
2/2
✓ Branch 0 taken 3530 times.
✓ Branch 1 taken 50 times.
3580 if (extradata)
720 3530 return frame_bytes * 14LL / (8 * ch);
721 50 break;
722 222 case AV_CODEC_ID_ADPCM_XA:
723 222 return (frame_bytes / 128) * 224 / ch;
724 327 case AV_CODEC_ID_INTERPLAY_DPCM:
725 327 return (frame_bytes - 6 - ch) / ch;
726 680 case AV_CODEC_ID_ROQ_DPCM:
727 680 return (frame_bytes - 8) / ch;
728 112 case AV_CODEC_ID_XAN_DPCM:
729 112 return (frame_bytes - 2 * ch) / ch;
730 case AV_CODEC_ID_MACE3:
731 return 3 * frame_bytes / ch;
732 138 case AV_CODEC_ID_MACE6:
733 138 return 6 * frame_bytes / ch;
734 case AV_CODEC_ID_PCM_LXF:
735 return 2 * (frame_bytes / (5 * ch));
736 1311 case AV_CODEC_ID_IAC:
737 case AV_CODEC_ID_IMC:
738 1311 return 4 * frame_bytes / ch;
739 }
740
741
2/2
✓ Branch 0 taken 21716 times.
✓ Branch 1 taken 34254 times.
55970 if (tag) {
742 /* calc from frame_bytes, channels, and codec_tag */
743
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 21642 times.
21716 if (id == AV_CODEC_ID_SOL_DPCM) {
744
1/2
✓ Branch 0 taken 74 times.
✗ Branch 1 not taken.
74 if (tag == 3)
745 74 return frame_bytes / ch;
746 else
747 return frame_bytes * 2 / ch;
748 }
749 }
750
751
2/2
✓ Branch 0 taken 11885 times.
✓ Branch 1 taken 44011 times.
55896 if (ba > 0) {
752 /* calc from frame_bytes, channels, and block_align */
753 11885 int blocks = frame_bytes / ba;
754 11885 int64_t tmp = 0;
755
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 7669 times.
11885 switch (id) {
756 1007 case AV_CODEC_ID_ADPCM_IMA_WAV:
757
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)
758 return 0;
759 1007 tmp = blocks * (1LL + (ba - 4 * ch) / (bps * ch) * 8);
760 1007 break;
761 669 case AV_CODEC_ID_ADPCM_IMA_DK3:
762 669 tmp = blocks * (((ba - 16LL) * 2 / 3 * 4) / ch);
763 669 break;
764 649 case AV_CODEC_ID_ADPCM_IMA_DK4:
765 649 tmp = blocks * (1 + (ba - 4LL * ch) * 2 / ch);
766 649 break;
767 1001 case AV_CODEC_ID_ADPCM_IMA_RAD:
768 1001 tmp = blocks * ((ba - 4LL * ch) * 2 / ch);
769 1001 break;
770 890 case AV_CODEC_ID_ADPCM_MS:
771 890 tmp = blocks * (2 + (ba - 7LL * ch) * 2LL / ch);
772 890 break;
773 case AV_CODEC_ID_ADPCM_MTAF:
774 tmp = blocks * (ba - 16LL) * 2 / ch;
775 break;
776 }
777
2/2
✓ Branch 0 taken 4216 times.
✓ Branch 1 taken 7669 times.
11885 if (tmp) {
778
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4216 times.
4216 if (tmp != (int)tmp)
779 return 0;
780 4216 return tmp;
781 }
782 }
783
784
2/2
✓ Branch 0 taken 11980 times.
✓ Branch 1 taken 39700 times.
51680 if (bps > 0) {
785 /* calc from frame_bytes, channels, and bits_per_coded_sample */
786
2/4
✓ Branch 0 taken 742 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11238 times.
11980 switch (id) {
787 742 case AV_CODEC_ID_PCM_DVD:
788
2/4
✓ Branch 0 taken 742 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 742 times.
742 if(bps<4 || frame_bytes<3)
789 return 0;
790 742 return 2 * ((frame_bytes - 3) / ((bps * 2 / 8) * ch));
791 case AV_CODEC_ID_PCM_BLURAY:
792 if(bps<4 || frame_bytes<4)
793 return 0;
794 return (frame_bytes - 4) / ((FFALIGN(ch, 2) * bps) / 8);
795 case AV_CODEC_ID_S302M:
796 return 2 * (frame_bytes / ((bps + 4) / 4)) / ch;
797 }
798 }
799 }
800 }
801
802 /* Fall back on using frame_size */
803
4/4
✓ Branch 0 taken 27304 times.
✓ Branch 1 taken 26425 times.
✓ Branch 2 taken 27268 times.
✓ Branch 3 taken 36 times.
53729 if (frame_size > 1 && frame_bytes)
804 27268 return frame_size;
805
806 //For WMA we currently have no other means to calculate duration thus we
807 //do it here by assuming CBR, which is true for all known cases.
808
8/8
✓ Branch 0 taken 17953 times.
✓ Branch 1 taken 8508 times.
✓ Branch 2 taken 15275 times.
✓ Branch 3 taken 2678 times.
✓ Branch 4 taken 15245 times.
✓ Branch 5 taken 30 times.
✓ Branch 6 taken 7019 times.
✓ Branch 7 taken 8226 times.
26461 if (bitrate > 0 && frame_bytes > 0 && sr > 0 && ba > 1) {
809
4/4
✓ Branch 0 taken 6814 times.
✓ Branch 1 taken 205 times.
✓ Branch 2 taken 723 times.
✓ Branch 3 taken 6091 times.
7019 if (id == AV_CODEC_ID_WMAV1 || id == AV_CODEC_ID_WMAV2)
810 928 return (frame_bytes * 8LL * sr) / bitrate;
811 }
812
813 25533 return 0;
814 }
815
816 56961 int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
817 {
818 56961 int duration = get_audio_frame_duration(avctx->codec_id, avctx->sample_rate,
819 avctx->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 56961 return FFMAX(0, duration);
824 }
825
826 426160 int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
827 {
828 426160 int duration = get_audio_frame_duration(par->codec_id, par->sample_rate,
829 par->channels, par->block_align,
830 par->codec_tag, par->bits_per_coded_sample,
831 par->bit_rate, par->extradata, par->frame_size,
832 frame_bytes);
833 426160 return FFMAX(0, duration);
834 }
835
836 #if !HAVE_THREADS
837 int ff_thread_init(AVCodecContext *s)
838 {
839 return -1;
840 }
841
842 #endif
843
844 54 unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
845 {
846 54 unsigned int n = 0;
847
848
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 54 times.
54 while (v >= 0xff) {
849 *s++ = 0xff;
850 v -= 0xff;
851 n++;
852 }
853 54 *s = v;
854 54 n++;
855 54 return n;
856 }
857
858 476 int ff_match_2uint16(const uint16_t(*tab)[2], int size, int a, int b)
859 {
860 int i;
861
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++) ;
862 476 return i;
863 }
864
865 13311 const AVCodecHWConfig *avcodec_get_hw_config(const AVCodec *codec, int index)
866 {
867 int i;
868
3/4
✓ Branch 0 taken 2443 times.
✓ Branch 1 taken 10868 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2443 times.
13311 if (!codec->hw_configs || index < 0)
869 10868 return NULL;
870
2/2
✓ Branch 0 taken 4815 times.
✓ Branch 1 taken 1605 times.
6420 for (i = 0; i <= index; i++)
871
2/2
✓ Branch 0 taken 838 times.
✓ Branch 1 taken 3977 times.
4815 if (!codec->hw_configs[i])
872 838 return NULL;
873 1605 return &codec->hw_configs[index]->public;
874 }
875
876 641455 unsigned int avpriv_toupper4(unsigned int x)
877 {
878 641455 return av_toupper(x & 0xFF) +
879 641455 (av_toupper((x >> 8) & 0xFF) << 8) +
880 1282910 (av_toupper((x >> 16) & 0xFF) << 16) +
881 641455 ((unsigned)av_toupper((x >> 24) & 0xFF) << 24);
882 }
883
884 137683 int ff_thread_ref_frame(ThreadFrame *dst, const ThreadFrame *src)
885 {
886 int ret;
887
888 137683 dst->owner[0] = src->owner[0];
889 137683 dst->owner[1] = src->owner[1];
890
891 137683 ret = av_frame_ref(dst->f, src->f);
892
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 137677 times.
137683 if (ret < 0)
893 6 return ret;
894
895
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 137677 times.
137677 av_assert0(!dst->progress);
896
897
2/2
✓ Branch 0 taken 333 times.
✓ Branch 1 taken 137344 times.
137677 if (src->progress &&
898
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 333 times.
333 !(dst->progress = av_buffer_ref(src->progress))) {
899 ff_thread_release_buffer(dst->owner[0], dst);
900 return AVERROR(ENOMEM);
901 }
902
903 137677 return 0;
904 }
905
906 #if !HAVE_THREADS
907
908 enum AVPixelFormat ff_thread_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
909 {
910 return ff_get_format(avctx, fmt);
911 }
912
913 int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
914 {
915 f->owner[0] = f->owner[1] = avctx;
916 return ff_get_buffer(avctx, f->f, flags);
917 }
918
919 void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f)
920 {
921 if (f->f)
922 av_frame_unref(f->f);
923 }
924
925 void ff_thread_finish_setup(AVCodecContext *avctx)
926 {
927 }
928
929 void ff_thread_report_progress(ThreadFrame *f, int progress, int field)
930 {
931 }
932
933 void ff_thread_await_progress(ThreadFrame *f, int progress, int field)
934 {
935 }
936
937 int ff_thread_can_start_frame(AVCodecContext *avctx)
938 {
939 return 1;
940 }
941
942 int ff_alloc_entries(AVCodecContext *avctx, int count)
943 {
944 return 0;
945 }
946
947 void ff_reset_entries(AVCodecContext *avctx)
948 {
949 }
950
951 void ff_thread_await_progress2(AVCodecContext *avctx, int field, int thread, int shift)
952 {
953 }
954
955 void ff_thread_report_progress2(AVCodecContext *avctx, int field, int thread, int n)
956 {
957 }
958
959 #endif
960
961 554749 const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p,
962 const uint8_t *end,
963 uint32_t *av_restrict state)
964 {
965 int i;
966
967
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 554749 times.
554749 av_assert0(p <= end);
968
2/2
✓ Branch 0 taken 511 times.
✓ Branch 1 taken 554238 times.
554749 if (p >= end)
969 511 return end;
970
971
2/2
✓ Branch 0 taken 1657418 times.
✓ Branch 1 taken 550515 times.
2207933 for (i = 0; i < 3; i++) {
972 1657418 uint32_t tmp = *state << 8;
973 1657418 *state = tmp + *(p++);
974
4/4
✓ Branch 0 taken 1656559 times.
✓ Branch 1 taken 859 times.
✓ Branch 2 taken 2864 times.
✓ Branch 3 taken 1653695 times.
1657418 if (tmp == 0x100 || p == end)
975 3723 return p;
976 }
977
978
2/2
✓ Branch 0 taken 162052544 times.
✓ Branch 1 taken 54217 times.
162106761 while (p < end) {
979
2/2
✓ Branch 0 taken 140492359 times.
✓ Branch 1 taken 21560185 times.
162052544 if (p[-1] > 1 ) p += 3;
980
2/2
✓ Branch 0 taken 7973955 times.
✓ Branch 1 taken 13586230 times.
21560185 else if (p[-2] ) p += 2;
981
2/2
✓ Branch 0 taken 13089932 times.
✓ Branch 1 taken 496298 times.
13586230 else if (p[-3]|(p[-1]-1)) p++;
982 else {
983 496298 p++;
984 496298 break;
985 }
986 }
987
988
2/2
✓ Branch 0 taken 34719 times.
✓ Branch 1 taken 515796 times.
550515 p = FFMIN(p, end) - 4;
989 550515 *state = AV_RB32(p);
990
991 550515 return p + 4;
992 }
993
994 415 AVCPBProperties *av_cpb_properties_alloc(size_t *size)
995 {
996 415 AVCPBProperties *props = av_mallocz(sizeof(AVCPBProperties));
997
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 415 times.
415 if (!props)
998 return NULL;
999
1000
1/2
✓ Branch 0 taken 415 times.
✗ Branch 1 not taken.
415 if (size)
1001 415 *size = sizeof(*props);
1002
1003 415 props->vbv_delay = UINT64_MAX;
1004
1005 415 return props;
1006 }
1007
1008 816 AVCPBProperties *ff_add_cpb_side_data(AVCodecContext *avctx)
1009 {
1010 AVPacketSideData *tmp;
1011 AVCPBProperties *props;
1012 size_t size;
1013 int i;
1014
1015
2/2
✓ Branch 0 taken 426 times.
✓ Branch 1 taken 390 times.
816 for (i = 0; i < avctx->nb_coded_side_data; i++)
1016
1/2
✓ Branch 0 taken 426 times.
✗ Branch 1 not taken.
426 if (avctx->coded_side_data[i].type == AV_PKT_DATA_CPB_PROPERTIES)
1017 426 return (AVCPBProperties *)avctx->coded_side_data[i].data;
1018
1019 390 props = av_cpb_properties_alloc(&size);
1020
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 390 times.
390 if (!props)
1021 return NULL;
1022
1023 390 tmp = av_realloc_array(avctx->coded_side_data, avctx->nb_coded_side_data + 1, sizeof(*tmp));
1024
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 390 times.
390 if (!tmp) {
1025 av_freep(&props);
1026 return NULL;
1027 }
1028
1029 390 avctx->coded_side_data = tmp;
1030 390 avctx->nb_coded_side_data++;
1031
1032 390 avctx->coded_side_data[avctx->nb_coded_side_data - 1].type = AV_PKT_DATA_CPB_PROPERTIES;
1033 390 avctx->coded_side_data[avctx->nb_coded_side_data - 1].data = (uint8_t*)props;
1034 390 avctx->coded_side_data[avctx->nb_coded_side_data - 1].size = size;
1035
1036 390 return props;
1037 }
1038
1039 static unsigned bcd2uint(uint8_t bcd)
1040 {
1041 unsigned low = bcd & 0xf;
1042 unsigned high = bcd >> 4;
1043 if (low > 9 || high > 9)
1044 return 0;
1045 return low + 10*high;
1046 }
1047
1048 int ff_alloc_timecode_sei(const AVFrame *frame, AVRational rate, size_t prefix_len,
1049 void **data, size_t *sei_size)
1050 {
1051 AVFrameSideData *sd = NULL;
1052 uint8_t *sei_data;
1053 PutBitContext pb;
1054 uint32_t *tc;
1055 int m;
1056
1057 if (frame)
1058 sd = av_frame_get_side_data(frame, AV_FRAME_DATA_S12M_TIMECODE);
1059
1060 if (!sd) {
1061 *data = NULL;
1062 return 0;
1063 }
1064 tc = (uint32_t*)sd->data;
1065 m = tc[0] & 3;
1066
1067 *sei_size = sizeof(uint32_t) * 4;
1068 *data = av_mallocz(*sei_size + prefix_len);
1069 if (!*data)
1070 return AVERROR(ENOMEM);
1071 sei_data = (uint8_t*)*data + prefix_len;
1072
1073 init_put_bits(&pb, sei_data, *sei_size);
1074 put_bits(&pb, 2, m); // num_clock_ts
1075
1076 for (int j = 1; j <= m; j++) {
1077 uint32_t tcsmpte = tc[j];
1078 unsigned hh = bcd2uint(tcsmpte & 0x3f); // 6-bit hours
1079 unsigned mm = bcd2uint(tcsmpte>>8 & 0x7f); // 7-bit minutes
1080 unsigned ss = bcd2uint(tcsmpte>>16 & 0x7f); // 7-bit seconds
1081 unsigned ff = bcd2uint(tcsmpte>>24 & 0x3f); // 6-bit frames
1082 unsigned drop = tcsmpte & 1<<30 && !0; // 1-bit drop if not arbitrary bit
1083
1084 /* Calculate frame number of HEVC by SMPTE ST 12-1:2014 Sec 12.2 if rate > 30FPS */
1085 if (av_cmp_q(rate, (AVRational) {30, 1}) == 1) {
1086 unsigned pc;
1087 ff *= 2;
1088 if (av_cmp_q(rate, (AVRational) {50, 1}) == 0)
1089 pc = !!(tcsmpte & 1 << 7);
1090 else
1091 pc = !!(tcsmpte & 1 << 23);
1092 ff = (ff + pc) & 0x7f;
1093 }
1094
1095 put_bits(&pb, 1, 1); // clock_timestamp_flag
1096 put_bits(&pb, 1, 1); // units_field_based_flag
1097 put_bits(&pb, 5, 0); // counting_type
1098 put_bits(&pb, 1, 1); // full_timestamp_flag
1099 put_bits(&pb, 1, 0); // discontinuity_flag
1100 put_bits(&pb, 1, drop);
1101 put_bits(&pb, 9, ff);
1102 put_bits(&pb, 6, ss);
1103 put_bits(&pb, 6, mm);
1104 put_bits(&pb, 5, hh);
1105 put_bits(&pb, 5, 0);
1106 }
1107 flush_put_bits(&pb);
1108
1109 return 0;
1110 }
1111
1112 4152 int64_t ff_guess_coded_bitrate(AVCodecContext *avctx)
1113 {
1114 4152 AVRational framerate = avctx->framerate;
1115 4152 int bits_per_coded_sample = avctx->bits_per_coded_sample;
1116 int64_t bitrate;
1117
1118
3/4
✓ Branch 0 taken 4152 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 4151 times.
4152 if (!(framerate.num && framerate.den))
1119 1 framerate = av_inv_q(avctx->time_base);
1120
2/4
✓ Branch 0 taken 4152 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4152 times.
4152 if (!(framerate.num && framerate.den))
1121 return 0;
1122
1123
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4152 times.
4152 if (!bits_per_coded_sample) {
1124 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
1125 bits_per_coded_sample = av_get_bits_per_pixel(desc);
1126 }
1127 4152 bitrate = (int64_t)bits_per_coded_sample * avctx->width * avctx->height *
1128 4152 framerate.num / framerate.den;
1129
1130 4152 return bitrate;
1131 }
1132
1133 2400 int ff_int_from_list_or_default(void *ctx, const char * val_name, int val,
1134 const int * array_valid_values, int default_value)
1135 {
1136 2400 int i = 0, ref_val;
1137
1138 while (1) {
1139 6400 ref_val = array_valid_values[i];
1140
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6400 times.
6400 if (ref_val == INT_MAX)
1141 break;
1142
2/2
✓ Branch 0 taken 2400 times.
✓ Branch 1 taken 4000 times.
6400 if (val == ref_val)
1143 2400 return val;
1144 4000 i++;
1145 }
1146 /* val is not a valid value */
1147 av_log(ctx, AV_LOG_DEBUG,
1148 "%s %d are not supported. Set to default value : %d\n", val_name, val, default_value);
1149 return default_value;
1150 }
1151