FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/utils.c
Date: 2022-01-28 07:56:06
Exec Total Coverage
Lines: 396 545 72.7%
Branches: 299 420 71.2%

Line Branch Exec Source
1 /*
2 * utils for libavcodec
3 * Copyright (c) 2001 Fabrice Bellard
4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 /**
24 * @file
25 * utils.
26 */
27
28 #include "config.h"
29 #include "libavutil/avassert.h"
30 #include "libavutil/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 95078 void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
51 {
52 95078 uint8_t **p = ptr;
53
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 95078 times.
95078 if (min_size > SIZE_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
54 av_freep(p);
55 *size = 0;
56 return;
57 }
58 95078 av_fast_mallocz(p, size, min_size + AV_INPUT_BUFFER_PADDING_SIZE);
59
1/2
✓ Branch 0 taken 95078 times.
✗ Branch 1 not taken.
95078 if (*p)
60 95078 memset(*p + min_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
61 }
62
63 661 void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size)
64 {
65 661 uint8_t **p = ptr;
66
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 661 times.
661 if (min_size > SIZE_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
67 av_freep(p);
68 *size = 0;
69 return;
70 }
71 661 av_fast_malloc(p, size, min_size + AV_INPUT_BUFFER_PADDING_SIZE);
72
1/2
✓ Branch 0 taken 661 times.
✗ Branch 1 not taken.
661 if (*p)
73 661 memset(*p, 0, min_size + AV_INPUT_BUFFER_PADDING_SIZE);
74 }
75
76 6583126 int av_codec_is_encoder(const AVCodec *codec)
77 {
78
8/8
✓ Branch 0 taken 6549870 times.
✓ Branch 1 taken 33256 times.
✓ Branch 2 taken 6478709 times.
✓ Branch 3 taken 71161 times.
✓ Branch 4 taken 3732254 times.
✓ Branch 5 taken 2746455 times.
✓ Branch 6 taken 70752 times.
✓ Branch 7 taken 3661502 times.
6583126 return codec && (codec->encode_sub || codec->encode2 || codec->receive_packet);
79 }
80
81 12093889 int av_codec_is_decoder(const AVCodec *codec)
82 {
83
6/6
✓ Branch 0 taken 12060633 times.
✓ Branch 1 taken 33256 times.
✓ Branch 2 taken 5397191 times.
✓ Branch 3 taken 6663442 times.
✓ Branch 4 taken 294230 times.
✓ Branch 5 taken 5102961 times.
12093889 return codec && (codec->decode || codec->receive_frame);
84 }
85
86 41914 int ff_set_dimensions(AVCodecContext *s, int width, int height)
87 {
88 41914 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 41913 times.
41914 if (ret < 0)
91 1 width = height = 0;
92
93 41914 s->coded_width = width;
94 41914 s->coded_height = height;
95 41914 s->width = AV_CEIL_RSHIFT(width, s->lowres);
96 41914 s->height = AV_CEIL_RSHIFT(height, s->lowres);
97
98 41914 return ret;
99 }
100
101 2538 int ff_set_sar(AVCodecContext *avctx, AVRational sar)
102 {
103 2538 int ret = av_image_check_sar(avctx->width, avctx->height, sar);
104
105
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2533 times.
2538 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 2533 avctx->sample_aspect_ratio = sar;
112 }
113 2533 return 0;
114 }
115
116 4779 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 4779 side_data = av_frame_get_side_data(frame, AV_FRAME_DATA_MATRIXENCODING);
123
1/2
✓ Branch 0 taken 4779 times.
✗ Branch 1 not taken.
4779 if (!side_data)
124 4779 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 4779 times.
4779 if (!side_data)
128 return AVERROR(ENOMEM);
129
130 4779 data = (enum AVMatrixEncoding*)side_data->data;
131 4779 *data = matrix_encoding;
132
133 4779 return 0;
134 }
135
136 8749 void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height,
137 int linesize_align[AV_NUM_DATA_POINTERS])
138 {
139 int i;
140 8749 int w_align = 1;
141 8749 int h_align = 1;
142 8749 AVPixFmtDescriptor const *desc = av_pix_fmt_desc_get(s->pix_fmt);
143
144
1/2
✓ Branch 0 taken 8749 times.
✗ Branch 1 not taken.
8749 if (desc) {
145 8749 w_align = 1 << desc->log2_chroma_w;
146 8749 h_align = 1 << desc->log2_chroma_h;
147 }
148
149
9/9
✓ Branch 0 taken 7799 times.
✓ Branch 1 taken 26 times.
✓ Branch 2 taken 21 times.
✓ Branch 3 taken 34 times.
✓ Branch 4 taken 129 times.
✓ Branch 5 taken 81 times.
✓ Branch 6 taken 207 times.
✓ Branch 7 taken 27 times.
✓ Branch 8 taken 425 times.
8749 switch (s->pix_fmt) {
150 7799 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 7799 w_align = 16; //FIXME assume 16 pixel per macroblock
240 7799 h_align = 16 * 2; // interlaced needs 2 macroblocks height
241 7799 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
1/2
✓ Branch 0 taken 128 times.
✗ Branch 1 not taken.
128 s->codec_id == AV_CODEC_ID_ARGO ||
274
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 127 times.
128 s->codec_id == AV_CODEC_ID_INTERPLAY_VIDEO) {
275 2 w_align = 8;
276 2 h_align = 8;
277 }
278
1/2
✓ Branch 0 taken 129 times.
✗ Branch 1 not taken.
129 if (s->codec_id == AV_CODEC_ID_MJPEG ||
279
1/2
✓ Branch 0 taken 129 times.
✗ Branch 1 not taken.
129 s->codec_id == AV_CODEC_ID_MJPEGB ||
280
1/2
✓ Branch 0 taken 129 times.
✗ Branch 1 not taken.
129 s->codec_id == AV_CODEC_ID_LJPEG ||
281
1/2
✓ Branch 0 taken 129 times.
✗ Branch 1 not taken.
129 s->codec_id == AV_CODEC_ID_SMVJPEG ||
282
1/2
✓ Branch 0 taken 129 times.
✗ Branch 1 not taken.
129 s->codec_id == AV_CODEC_ID_AMV ||
283
1/2
✓ Branch 0 taken 129 times.
✗ Branch 1 not taken.
129 s->codec_id == AV_CODEC_ID_SP5X ||
284
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 121 times.
129 s->codec_id == AV_CODEC_ID_JPEGLS) {
285 8 w_align = 8;
286 8 h_align = 2*8;
287 }
288 129 break;
289 81 case AV_PIX_FMT_BGR24:
290
2/2
✓ Branch 0 taken 80 times.
✓ Branch 1 taken 1 times.
81 if ((s->codec_id == AV_CODEC_ID_MSZH) ||
291
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 75 times.
80 (s->codec_id == AV_CODEC_ID_ZLIB)) {
292 6 w_align = 4;
293 6 h_align = 4;
294 }
295 81 break;
296 207 case AV_PIX_FMT_RGB24:
297
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 201 times.
207 if (s->codec_id == AV_CODEC_ID_CINEPAK) {
298 6 w_align = 4;
299 6 h_align = 4;
300 }
301 207 break;
302 27 case AV_PIX_FMT_BGR0:
303
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
27 if (s->codec_id == AV_CODEC_ID_ARGO) {
304 w_align = 8;
305 h_align = 8;
306 }
307 27 break;
308 425 default:
309 425 break;
310 }
311
312
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8747 times.
8749 if (s->codec_id == AV_CODEC_ID_IFF_ILBM) {
313 2 w_align = FFMAX(w_align, 8);
314 }
315
316 8749 *width = FFALIGN(*width, w_align);
317 8749 *height = FFALIGN(*height, h_align);
318
4/4
✓ Branch 0 taken 8207 times.
✓ Branch 1 taken 542 times.
✓ Branch 2 taken 8206 times.
✓ Branch 3 taken 1 times.
8749 if (s->codec_id == AV_CODEC_ID_H264 || s->lowres ||
319
4/4
✓ Branch 0 taken 8205 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 8198 times.
✓ Branch 3 taken 7 times.
8206 s->codec_id == AV_CODEC_ID_VP5 || s->codec_id == AV_CODEC_ID_VP6 ||
320
4/4
✓ Branch 0 taken 8196 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 8194 times.
8198 s->codec_id == AV_CODEC_ID_VP6F || s->codec_id == AV_CODEC_ID_VP6A
321 ) {
322 // some of the optimized chroma MC reads one line too much
323 // which is also done in mpeg decoders with lowres > 0
324 555 *height += 2;
325
326 // H.264 uses edge emulation for out of frame motion vectors, for this
327 // it requires a temporary area large enough to hold a 21x21 block,
328 // increasing witdth ensure that the temporary area is large enough,
329 // the next rounded up width is 32
330 555 *width = FFMAX(*width, 32);
331 }
332
333
2/2
✓ Branch 0 taken 34996 times.
✓ Branch 1 taken 8749 times.
43745 for (i = 0; i < 4; i++)
334 34996 linesize_align[i] = STRIDE_ALIGN;
335 8749 }
336
337 void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height)
338 {
339 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->pix_fmt);
340 int chroma_shift = desc->log2_chroma_w;
341 int linesize_align[AV_NUM_DATA_POINTERS];
342 int align;
343
344 avcodec_align_dimensions2(s, width, height, linesize_align);
345 align = FFMAX(linesize_align[0], linesize_align[3]);
346 linesize_align[1] <<= chroma_shift;
347 linesize_align[2] <<= chroma_shift;
348 align = FFMAX3(align, linesize_align[1], linesize_align[2]);
349 *width = FFALIGN(*width, align);
350 }
351
352 33 int avcodec_enum_to_chroma_pos(int *xpos, int *ypos, enum AVChromaLocation pos)
353 {
354
2/4
✓ Branch 0 taken 33 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 33 times.
33 if (pos <= AVCHROMA_LOC_UNSPECIFIED || pos >= AVCHROMA_LOC_NB)
355 return AVERROR(EINVAL);
356 33 pos--;
357
358 33 *xpos = (pos&1) * 128;
359 33 *ypos = ((pos>>1)^(pos<4)) * 128;
360
361 33 return 0;
362 }
363
364 17 enum AVChromaLocation avcodec_chroma_pos_to_enum(int xpos, int ypos)
365 {
366 int pos, xout, yout;
367
368
1/2
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
25 for (pos = AVCHROMA_LOC_UNSPECIFIED + 1; pos < AVCHROMA_LOC_NB; pos++) {
369
5/6
✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 21 times.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 17 times.
✓ Branch 6 taken 4 times.
25 if (avcodec_enum_to_chroma_pos(&xout, &yout, pos) == 0 && xout == xpos && yout == ypos)
370 17 return pos;
371 }
372 return AVCHROMA_LOC_UNSPECIFIED;
373 }
374
375 int avcodec_fill_audio_frame(AVFrame *frame, int nb_channels,
376 enum AVSampleFormat sample_fmt, const uint8_t *buf,
377 int buf_size, int align)
378 {
379 int ch, planar, needed_size, ret = 0;
380
381 needed_size = av_samples_get_buffer_size(NULL, nb_channels,
382 frame->nb_samples, sample_fmt,
383 align);
384 if (buf_size < needed_size)
385 return AVERROR(EINVAL);
386
387 planar = av_sample_fmt_is_planar(sample_fmt);
388 if (planar && nb_channels > AV_NUM_DATA_POINTERS) {
389 if (!FF_ALLOCZ_TYPED_ARRAY(frame->extended_data, nb_channels))
390 return AVERROR(ENOMEM);
391 } else {
392 frame->extended_data = frame->data;
393 }
394
395 if ((ret = av_samples_fill_arrays(frame->extended_data, &frame->linesize[0],
396 (uint8_t *)(intptr_t)buf, nb_channels, frame->nb_samples,
397 sample_fmt, align)) < 0) {
398 if (frame->extended_data != frame->data)
399 av_freep(&frame->extended_data);
400 return ret;
401 }
402 if (frame->extended_data != frame->data) {
403 for (ch = 0; ch < AV_NUM_DATA_POINTERS; ch++)
404 frame->data[ch] = frame->extended_data[ch];
405 }
406
407 return ret;
408 }
409
410 17 void ff_color_frame(AVFrame *frame, const int c[4])
411 {
412 17 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
413 int p, y;
414
415
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 av_assert0(desc->flags & AV_PIX_FMT_FLAG_PLANAR);
416
417
2/2
✓ Branch 0 taken 51 times.
✓ Branch 1 taken 17 times.
68 for (p = 0; p<desc->nb_components; p++) {
418 51 uint8_t *dst = frame->data[p];
419
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;
420
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;
421
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;
422
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 51 times.
51 if (desc->comp[0].depth >= 9) {
423 ((uint16_t*)dst)[0] = c[p];
424 av_memcpy_backptr(dst + 2, 2, bytes - 2);
425 dst += frame->linesize[p];
426 for (y = 1; y < height; y++) {
427 memcpy(dst, frame->data[p], 2*bytes);
428 dst += frame->linesize[p];
429 }
430 } else {
431
2/2
✓ Branch 0 taken 25152 times.
✓ Branch 1 taken 51 times.
25203 for (y = 0; y < height; y++) {
432 25152 memset(dst, c[p], bytes);
433 25152 dst += frame->linesize[p];
434 }
435 }
436 }
437 17 }
438
439 170888 int avpriv_codec_get_cap_skip_frame_fill_param(const AVCodec *codec){
440 170888 return !!(codec->caps_internal & FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM);
441 }
442
443 16952 const char *avcodec_get_name(enum AVCodecID id)
444 {
445 const AVCodecDescriptor *cd;
446 const AVCodec *codec;
447
448
2/2
✓ Branch 0 taken 170 times.
✓ Branch 1 taken 16782 times.
16952 if (id == AV_CODEC_ID_NONE)
449 170 return "none";
450 16782 cd = avcodec_descriptor_get(id);
451
2/2
✓ Branch 0 taken 16780 times.
✓ Branch 1 taken 2 times.
16782 if (cd)
452 16780 return cd->name;
453 2 av_log(NULL, AV_LOG_WARNING, "Codec 0x%x is not in the full list.\n", id);
454 2 codec = avcodec_find_decoder(id);
455
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (codec)
456 return codec->name;
457 2 codec = avcodec_find_encoder(id);
458
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (codec)
459 return codec->name;
460 2 return "unknown_codec";
461 }
462
463 const char *av_get_profile_name(const AVCodec *codec, int profile)
464 {
465 const AVProfile *p;
466 if (profile == FF_PROFILE_UNKNOWN || !codec->profiles)
467 return NULL;
468
469 for (p = codec->profiles; p->profile != FF_PROFILE_UNKNOWN; p++)
470 if (p->profile == profile)
471 return p->name;
472
473 return NULL;
474 }
475
476 13267 const char *avcodec_profile_name(enum AVCodecID codec_id, int profile)
477 {
478 13267 const AVCodecDescriptor *desc = avcodec_descriptor_get(codec_id);
479 const AVProfile *p;
480
481
5/6
✓ Branch 0 taken 1805 times.
✓ Branch 1 taken 11462 times.
✓ Branch 2 taken 1805 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 131 times.
✓ Branch 5 taken 1674 times.
13267 if (profile == FF_PROFILE_UNKNOWN || !desc || !desc->profiles)
482 11593 return NULL;
483
484
2/2
✓ Branch 0 taken 4449 times.
✓ Branch 1 taken 10 times.
4459 for (p = desc->profiles; p->profile != FF_PROFILE_UNKNOWN; p++)
485
2/2
✓ Branch 0 taken 1664 times.
✓ Branch 1 taken 2785 times.
4449 if (p->profile == profile)
486 1664 return p->name;
487
488 10 return NULL;
489 }
490
491 861603 int av_get_exact_bits_per_sample(enum AVCodecID codec_id)
492 {
493
7/7
✓ Branch 0 taken 11188 times.
✓ Branch 1 taken 13275 times.
✓ Branch 2 taken 547021 times.
✓ Branch 3 taken 81962 times.
✓ Branch 4 taken 28022 times.
✓ Branch 5 taken 21361 times.
✓ Branch 6 taken 158774 times.
861603 switch (codec_id) {
494 11188 case AV_CODEC_ID_8SVX_EXP:
495 case AV_CODEC_ID_8SVX_FIB:
496 case AV_CODEC_ID_ADPCM_ARGO:
497 case AV_CODEC_ID_ADPCM_CT:
498 case AV_CODEC_ID_ADPCM_IMA_ALP:
499 case AV_CODEC_ID_ADPCM_IMA_AMV:
500 case AV_CODEC_ID_ADPCM_IMA_APC:
501 case AV_CODEC_ID_ADPCM_IMA_APM:
502 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
503 case AV_CODEC_ID_ADPCM_IMA_OKI:
504 case AV_CODEC_ID_ADPCM_IMA_WS:
505 case AV_CODEC_ID_ADPCM_IMA_SSI:
506 case AV_CODEC_ID_ADPCM_G722:
507 case AV_CODEC_ID_ADPCM_YAMAHA:
508 case AV_CODEC_ID_ADPCM_AICA:
509 11188 return 4;
510 13275 case AV_CODEC_ID_DSD_LSBF:
511 case AV_CODEC_ID_DSD_MSBF:
512 case AV_CODEC_ID_DSD_LSBF_PLANAR:
513 case AV_CODEC_ID_DSD_MSBF_PLANAR:
514 case AV_CODEC_ID_PCM_ALAW:
515 case AV_CODEC_ID_PCM_MULAW:
516 case AV_CODEC_ID_PCM_VIDC:
517 case AV_CODEC_ID_PCM_S8:
518 case AV_CODEC_ID_PCM_S8_PLANAR:
519 case AV_CODEC_ID_PCM_SGA:
520 case AV_CODEC_ID_PCM_U8:
521 case AV_CODEC_ID_SDX2_DPCM:
522 case AV_CODEC_ID_DERF_DPCM:
523 13275 return 8;
524 547021 case AV_CODEC_ID_PCM_S16BE:
525 case AV_CODEC_ID_PCM_S16BE_PLANAR:
526 case AV_CODEC_ID_PCM_S16LE:
527 case AV_CODEC_ID_PCM_S16LE_PLANAR:
528 case AV_CODEC_ID_PCM_U16BE:
529 case AV_CODEC_ID_PCM_U16LE:
530 547021 return 16;
531 81962 case AV_CODEC_ID_PCM_S24DAUD:
532 case AV_CODEC_ID_PCM_S24BE:
533 case AV_CODEC_ID_PCM_S24LE:
534 case AV_CODEC_ID_PCM_S24LE_PLANAR:
535 case AV_CODEC_ID_PCM_U24BE:
536 case AV_CODEC_ID_PCM_U24LE:
537 81962 return 24;
538 28022 case AV_CODEC_ID_PCM_S32BE:
539 case AV_CODEC_ID_PCM_S32LE:
540 case AV_CODEC_ID_PCM_S32LE_PLANAR:
541 case AV_CODEC_ID_PCM_U32BE:
542 case AV_CODEC_ID_PCM_U32LE:
543 case AV_CODEC_ID_PCM_F32BE:
544 case AV_CODEC_ID_PCM_F32LE:
545 case AV_CODEC_ID_PCM_F24LE:
546 case AV_CODEC_ID_PCM_F16LE:
547 28022 return 32;
548 21361 case AV_CODEC_ID_PCM_F64BE:
549 case AV_CODEC_ID_PCM_F64LE:
550 case AV_CODEC_ID_PCM_S64BE:
551 case AV_CODEC_ID_PCM_S64LE:
552 21361 return 64;
553 158774 default:
554 158774 return 0;
555 }
556 }
557
558 23 enum AVCodecID av_get_pcm_codec(enum AVSampleFormat fmt, int be)
559 {
560 static const enum AVCodecID map[][2] = {
561 [AV_SAMPLE_FMT_U8 ] = { AV_CODEC_ID_PCM_U8, AV_CODEC_ID_PCM_U8 },
562 [AV_SAMPLE_FMT_S16 ] = { AV_CODEC_ID_PCM_S16LE, AV_CODEC_ID_PCM_S16BE },
563 [AV_SAMPLE_FMT_S32 ] = { AV_CODEC_ID_PCM_S32LE, AV_CODEC_ID_PCM_S32BE },
564 [AV_SAMPLE_FMT_FLT ] = { AV_CODEC_ID_PCM_F32LE, AV_CODEC_ID_PCM_F32BE },
565 [AV_SAMPLE_FMT_DBL ] = { AV_CODEC_ID_PCM_F64LE, AV_CODEC_ID_PCM_F64BE },
566 [AV_SAMPLE_FMT_U8P ] = { AV_CODEC_ID_PCM_U8, AV_CODEC_ID_PCM_U8 },
567 [AV_SAMPLE_FMT_S16P] = { AV_CODEC_ID_PCM_S16LE, AV_CODEC_ID_PCM_S16BE },
568 [AV_SAMPLE_FMT_S32P] = { AV_CODEC_ID_PCM_S32LE, AV_CODEC_ID_PCM_S32BE },
569 [AV_SAMPLE_FMT_S64P] = { AV_CODEC_ID_PCM_S64LE, AV_CODEC_ID_PCM_S64BE },
570 [AV_SAMPLE_FMT_FLTP] = { AV_CODEC_ID_PCM_F32LE, AV_CODEC_ID_PCM_F32BE },
571 [AV_SAMPLE_FMT_DBLP] = { AV_CODEC_ID_PCM_F64LE, AV_CODEC_ID_PCM_F64BE },
572 };
573
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))
574 return AV_CODEC_ID_NONE;
575
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)
576 23 be = AV_NE(1, 0);
577 23 return map[fmt][be];
578 }
579
580 336167 int av_get_bits_per_sample(enum AVCodecID codec_id)
581 {
582
4/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 64 times.
✓ Branch 3 taken 336097 times.
336167 switch (codec_id) {
583 3 case AV_CODEC_ID_ADPCM_SBPRO_2:
584 3 return 2;
585 3 case AV_CODEC_ID_ADPCM_SBPRO_3:
586 3 return 3;
587 64 case AV_CODEC_ID_ADPCM_SBPRO_4:
588 case AV_CODEC_ID_ADPCM_IMA_WAV:
589 case AV_CODEC_ID_ADPCM_IMA_QT:
590 case AV_CODEC_ID_ADPCM_SWF:
591 case AV_CODEC_ID_ADPCM_MS:
592 64 return 4;
593 336097 default:
594 336097 return av_get_exact_bits_per_sample(codec_id);
595 }
596 }
597
598 519493 static int get_audio_frame_duration(enum AVCodecID id, int sr, int ch, int ba,
599 uint32_t tag, int bits_per_coded_sample, int64_t bitrate,
600 uint8_t * extradata, int frame_size, int frame_bytes)
601 {
602 519493 int bps = av_get_exact_bits_per_sample(id);
603
4/4
✓ Branch 0 taken 397405 times.
✓ Branch 1 taken 122088 times.
✓ Branch 2 taken 397112 times.
✓ Branch 3 taken 293 times.
519493 int framecount = (ba > 0 && frame_bytes / ba > 0) ? frame_bytes / ba : 1;
604
605 /* codecs with an exact constant bits per sample */
606
7/10
✓ Branch 0 taken 368202 times.
✓ Branch 1 taken 151291 times.
✓ Branch 2 taken 368202 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 368173 times.
✓ Branch 5 taken 29 times.
✓ Branch 6 taken 368173 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 368173 times.
✗ Branch 9 not taken.
519493 if (bps > 0 && ch > 0 && frame_bytes > 0 && ch < 32768 && bps < 32768)
607 368173 return (frame_bytes * 8LL) / (bps * ch);
608 151320 bps = bits_per_coded_sample;
609
610 /* codecs with a fixed packet duration */
611
11/12
✓ Branch 0 taken 16542 times.
✓ Branch 1 taken 8274 times.
✓ Branch 2 taken 600 times.
✓ Branch 3 taken 5695 times.
✓ Branch 4 taken 1124 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4319 times.
✓ Branch 7 taken 4172 times.
✓ Branch 8 taken 2183 times.
✓ Branch 9 taken 18455 times.
✓ Branch 10 taken 1957 times.
✓ Branch 11 taken 87999 times.
151320 switch (id) {
612 16542 case AV_CODEC_ID_ADPCM_ADX: return 32;
613 8274 case AV_CODEC_ID_ADPCM_IMA_QT: return 64;
614 600 case AV_CODEC_ID_ADPCM_EA_XAS: return 128;
615 5695 case AV_CODEC_ID_AMR_NB:
616 case AV_CODEC_ID_EVRC:
617 case AV_CODEC_ID_GSM:
618 case AV_CODEC_ID_QCELP:
619 5695 case AV_CODEC_ID_RA_288: return 160;
620 1124 case AV_CODEC_ID_AMR_WB:
621 1124 case AV_CODEC_ID_GSM_MS: return 320;
622 case AV_CODEC_ID_MP1: return 384;
623 4319 case AV_CODEC_ID_ATRAC1: return 512;
624 4172 case AV_CODEC_ID_ATRAC9:
625 case AV_CODEC_ID_ATRAC3:
626
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4172 times.
4172 if (framecount > INT_MAX/1024)
627 return 0;
628 4172 return 1024 * framecount;
629 2183 case AV_CODEC_ID_ATRAC3P: return 2048;
630 18455 case AV_CODEC_ID_MP2:
631 18455 case AV_CODEC_ID_MUSEPACK7: return 1152;
632 1957 case AV_CODEC_ID_AC3: return 1536;
633 }
634
635
2/2
✓ Branch 0 taken 85183 times.
✓ Branch 1 taken 2816 times.
87999 if (sr > 0) {
636 /* calc from sample rate */
637
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 85174 times.
85183 if (id == AV_CODEC_ID_TTA)
638 9 return 256 * sr / 245;
639
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 85174 times.
85174 else if (id == AV_CODEC_ID_DST)
640 return 588 * sr / 44100;
641
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 85108 times.
85174 else if (id == AV_CODEC_ID_BINKAUDIO_DCT) {
642
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
66 if (sr / 22050 > 22)
643 return 0;
644 66 return (480 << (sr / 22050));
645 }
646
647
2/2
✓ Branch 0 taken 6417 times.
✓ Branch 1 taken 78691 times.
85108 if (id == AV_CODEC_ID_MP3)
648
2/2
✓ Branch 0 taken 224 times.
✓ Branch 1 taken 6193 times.
6417 return sr <= 24000 ? 576 : 1152;
649 }
650
651
2/2
✓ Branch 0 taken 24987 times.
✓ Branch 1 taken 56520 times.
81507 if (ba > 0) {
652 /* calc from block_align */
653
2/2
✓ Branch 0 taken 7249 times.
✓ Branch 1 taken 17738 times.
24987 if (id == AV_CODEC_ID_SIPR) {
654
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) {
655 3250 case 20: return 160;
656 1983 case 19: return 144;
657 1680 case 29: return 288;
658 336 case 37: return 480;
659 }
660
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17738 times.
17738 } else if (id == AV_CODEC_ID_ILBC) {
661 switch (ba) {
662 case 38: return 160;
663 case 50: return 240;
664 }
665 }
666 }
667
668
2/2
✓ Branch 0 taken 71475 times.
✓ Branch 1 taken 2783 times.
74258 if (frame_bytes > 0) {
669 /* calc from frame_bytes only */
670
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 71463 times.
71475 if (id == AV_CODEC_ID_TRUESPEECH)
671 12 return 240 * (frame_bytes / 32);
672
2/2
✓ Branch 0 taken 2074 times.
✓ Branch 1 taken 69389 times.
71463 if (id == AV_CODEC_ID_NELLYMOSER)
673 2074 return 256 * (frame_bytes / 64);
674
2/2
✓ Branch 0 taken 1057 times.
✓ Branch 1 taken 68332 times.
69389 if (id == AV_CODEC_ID_RA_144)
675 1057 return 160 * (frame_bytes / 20);
676
677
2/2
✓ Branch 0 taken 23372 times.
✓ Branch 1 taken 44960 times.
68332 if (bps > 0) {
678 /* calc from frame_bytes and bits_per_coded_sample */
679
3/4
✓ Branch 0 taken 23266 times.
✓ Branch 1 taken 106 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 23266 times.
23372 if (id == AV_CODEC_ID_ADPCM_G726 || id == AV_CODEC_ID_ADPCM_G726LE)
680 106 return frame_bytes * 8 / bps;
681 }
682
683
3/4
✓ Branch 0 taken 68123 times.
✓ Branch 1 taken 103 times.
✓ Branch 2 taken 68123 times.
✗ Branch 3 not taken.
68226 if (ch > 0 && ch < INT_MAX/16) {
684 /* calc from frame_bytes and channels */
685
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 313 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 1311 times.
✓ Branch 16 taken 59094 times.
68123 switch (id) {
686 case AV_CODEC_ID_FASTAUDIO:
687 return frame_bytes / (40 * ch) * 256;
688 case AV_CODEC_ID_ADPCM_IMA_MOFLEX:
689 return (frame_bytes - 4 * ch) / (128 * ch) * 256;
690 48 case AV_CODEC_ID_ADPCM_AFC:
691 48 return frame_bytes / (9 * ch) * 16;
692 33 case AV_CODEC_ID_ADPCM_PSX:
693 case AV_CODEC_ID_ADPCM_DTK:
694 33 frame_bytes /= 16 * ch;
695
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
33 if (frame_bytes > INT_MAX / 28)
696 return 0;
697 33 return frame_bytes * 28;
698 452 case AV_CODEC_ID_ADPCM_4XM:
699 case AV_CODEC_ID_ADPCM_IMA_ACORN:
700 case AV_CODEC_ID_ADPCM_IMA_DAT4:
701 case AV_CODEC_ID_ADPCM_IMA_ISS:
702 452 return (frame_bytes - 4 * ch) * 2 / ch;
703 1951 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
704 1951 return (frame_bytes - 4) * 2 / ch;
705 case AV_CODEC_ID_ADPCM_IMA_AMV:
706 return (frame_bytes - 8) * 2;
707 3580 case AV_CODEC_ID_ADPCM_THP:
708 case AV_CODEC_ID_ADPCM_THP_LE:
709
2/2
✓ Branch 0 taken 3530 times.
✓ Branch 1 taken 50 times.
3580 if (extradata)
710 3530 return frame_bytes * 14LL / (8 * ch);
711 50 break;
712 222 case AV_CODEC_ID_ADPCM_XA:
713 222 return (frame_bytes / 128) * 224 / ch;
714 327 case AV_CODEC_ID_INTERPLAY_DPCM:
715 327 return (frame_bytes - 6 - ch) / ch;
716 680 case AV_CODEC_ID_ROQ_DPCM:
717 680 return (frame_bytes - 8) / ch;
718 112 case AV_CODEC_ID_XAN_DPCM:
719 112 return (frame_bytes - 2 * ch) / ch;
720 case AV_CODEC_ID_MACE3:
721 return 3 * frame_bytes / ch;
722 313 case AV_CODEC_ID_MACE6:
723 313 return 6 * frame_bytes / ch;
724 case AV_CODEC_ID_PCM_LXF:
725 return 2 * (frame_bytes / (5 * ch));
726 1311 case AV_CODEC_ID_IAC:
727 case AV_CODEC_ID_IMC:
728 1311 return 4 * frame_bytes / ch;
729 }
730
731
2/2
✓ Branch 0 taken 24821 times.
✓ Branch 1 taken 34323 times.
59144 if (tag) {
732 /* calc from frame_bytes, channels, and codec_tag */
733
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 24747 times.
24821 if (id == AV_CODEC_ID_SOL_DPCM) {
734
1/2
✓ Branch 0 taken 74 times.
✗ Branch 1 not taken.
74 if (tag == 3)
735 74 return frame_bytes / ch;
736 else
737 return frame_bytes * 2 / ch;
738 }
739 }
740
741
2/2
✓ Branch 0 taken 14432 times.
✓ Branch 1 taken 44638 times.
59070 if (ba > 0) {
742 /* calc from frame_bytes, channels, and block_align */
743 14432 int blocks = frame_bytes / ba;
744 14432 int64_t tmp = 0;
745
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 10216 times.
14432 switch (id) {
746 1007 case AV_CODEC_ID_ADPCM_IMA_WAV:
747
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)
748 return 0;
749 1007 tmp = blocks * (1LL + (ba - 4 * ch) / (bps * ch) * 8);
750 1007 break;
751 669 case AV_CODEC_ID_ADPCM_IMA_DK3:
752 669 tmp = blocks * (((ba - 16LL) * 2 / 3 * 4) / ch);
753 669 break;
754 649 case AV_CODEC_ID_ADPCM_IMA_DK4:
755 649 tmp = blocks * (1 + (ba - 4LL * ch) * 2 / ch);
756 649 break;
757 1001 case AV_CODEC_ID_ADPCM_IMA_RAD:
758 1001 tmp = blocks * ((ba - 4LL * ch) * 2 / ch);
759 1001 break;
760 890 case AV_CODEC_ID_ADPCM_MS:
761 890 tmp = blocks * (2 + (ba - 7LL * ch) * 2LL / ch);
762 890 break;
763 case AV_CODEC_ID_ADPCM_MTAF:
764 tmp = blocks * (ba - 16LL) * 2 / ch;
765 break;
766 }
767
2/2
✓ Branch 0 taken 4216 times.
✓ Branch 1 taken 10216 times.
14432 if (tmp) {
768
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4216 times.
4216 if (tmp != (int)tmp)
769 return 0;
770 4216 return tmp;
771 }
772 }
773
774
2/2
✓ Branch 0 taken 15115 times.
✓ Branch 1 taken 39739 times.
54854 if (bps > 0) {
775 /* calc from frame_bytes, channels, and bits_per_coded_sample */
776
2/4
✓ Branch 0 taken 742 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 14373 times.
15115 switch (id) {
777 742 case AV_CODEC_ID_PCM_DVD:
778
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)
779 return 0;
780 742 return 2 * ((frame_bytes - 3) / ((bps * 2 / 8) * ch));
781 case AV_CODEC_ID_PCM_BLURAY:
782 if(bps<4 || frame_bytes<4)
783 return 0;
784 return (frame_bytes - 4) / ((FFALIGN(ch, 2) * bps) / 8);
785 case AV_CODEC_ID_S302M:
786 return 2 * (frame_bytes / ((bps + 4) / 4)) / ch;
787 }
788 }
789 }
790 }
791
792 /* Fall back on using frame_size */
793
4/4
✓ Branch 0 taken 27653 times.
✓ Branch 1 taken 29345 times.
✓ Branch 2 taken 27615 times.
✓ Branch 3 taken 38 times.
56998 if (frame_size > 1 && frame_bytes)
794 27615 return frame_size;
795
796 //For WMA we currently have no other means to calculate duration thus we
797 //do it here by assuming CBR, which is true for all known cases.
798
8/8
✓ Branch 0 taken 20863 times.
✓ Branch 1 taken 8520 times.
✓ Branch 2 taken 18092 times.
✓ Branch 3 taken 2771 times.
✓ Branch 4 taken 18062 times.
✓ Branch 5 taken 30 times.
✓ Branch 6 taken 9566 times.
✓ Branch 7 taken 8496 times.
29383 if (bitrate > 0 && frame_bytes > 0 && sr > 0 && ba > 1) {
799
4/4
✓ Branch 0 taken 9361 times.
✓ Branch 1 taken 205 times.
✓ Branch 2 taken 723 times.
✓ Branch 3 taken 8638 times.
9566 if (id == AV_CODEC_ID_WMAV1 || id == AV_CODEC_ID_WMAV2)
800 928 return (frame_bytes * 8LL * sr) / bitrate;
801 }
802
803 28455 return 0;
804 }
805
806 66984 int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
807 {
808 66984 int duration = get_audio_frame_duration(avctx->codec_id, avctx->sample_rate,
809 avctx->channels, avctx->block_align,
810 avctx->codec_tag, avctx->bits_per_coded_sample,
811 avctx->bit_rate, avctx->extradata, avctx->frame_size,
812 frame_bytes);
813 66984 return FFMAX(0, duration);
814 }
815
816 452509 int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
817 {
818 452509 int duration = get_audio_frame_duration(par->codec_id, par->sample_rate,
819 par->channels, par->block_align,
820 par->codec_tag, par->bits_per_coded_sample,
821 par->bit_rate, par->extradata, par->frame_size,
822 frame_bytes);
823 452509 return FFMAX(0, duration);
824 }
825
826 #if !HAVE_THREADS
827 int ff_thread_init(AVCodecContext *s)
828 {
829 return -1;
830 }
831
832 #endif
833
834 54 unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
835 {
836 54 unsigned int n = 0;
837
838
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 54 times.
54 while (v >= 0xff) {
839 *s++ = 0xff;
840 v -= 0xff;
841 n++;
842 }
843 54 *s = v;
844 54 n++;
845 54 return n;
846 }
847
848 476 int ff_match_2uint16(const uint16_t(*tab)[2], int size, int a, int b)
849 {
850 int i;
851
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++) ;
852 476 return i;
853 }
854
855 13533 const AVCodecHWConfig *avcodec_get_hw_config(const AVCodec *codec, int index)
856 {
857 int i;
858
3/4
✓ Branch 0 taken 2481 times.
✓ Branch 1 taken 11052 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2481 times.
13533 if (!codec->hw_configs || index < 0)
859 11052 return NULL;
860
2/2
✓ Branch 0 taken 4860 times.
✓ Branch 1 taken 1610 times.
6470 for (i = 0; i <= index; i++)
861
2/2
✓ Branch 0 taken 871 times.
✓ Branch 1 taken 3989 times.
4860 if (!codec->hw_configs[i])
862 871 return NULL;
863 1610 return &codec->hw_configs[index]->public;
864 }
865
866 139296 int ff_thread_ref_frame(ThreadFrame *dst, const ThreadFrame *src)
867 {
868 int ret;
869
870 139296 dst->owner[0] = src->owner[0];
871 139296 dst->owner[1] = src->owner[1];
872
873 139296 ret = av_frame_ref(dst->f, src->f);
874
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 139296 times.
139296 if (ret < 0)
875 return ret;
876
877
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 139296 times.
139296 av_assert0(!dst->progress);
878
879
2/2
✓ Branch 0 taken 333 times.
✓ Branch 1 taken 138963 times.
139296 if (src->progress &&
880
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 333 times.
333 !(dst->progress = av_buffer_ref(src->progress))) {
881 ff_thread_release_buffer(dst->owner[0], dst);
882 return AVERROR(ENOMEM);
883 }
884
885 139296 return 0;
886 }
887
888 #if !HAVE_THREADS
889
890 enum AVPixelFormat ff_thread_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
891 {
892 return ff_get_format(avctx, fmt);
893 }
894
895 int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
896 {
897 f->owner[0] = f->owner[1] = avctx;
898 return ff_get_buffer(avctx, f->f, flags);
899 }
900
901 void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f)
902 {
903 if (f->f)
904 av_frame_unref(f->f);
905 }
906
907 void ff_thread_finish_setup(AVCodecContext *avctx)
908 {
909 }
910
911 void ff_thread_report_progress(ThreadFrame *f, int progress, int field)
912 {
913 }
914
915 void ff_thread_await_progress(ThreadFrame *f, int progress, int field)
916 {
917 }
918
919 int ff_thread_can_start_frame(AVCodecContext *avctx)
920 {
921 return 1;
922 }
923
924 int ff_alloc_entries(AVCodecContext *avctx, int count)
925 {
926 return 0;
927 }
928
929 void ff_reset_entries(AVCodecContext *avctx)
930 {
931 }
932
933 void ff_thread_await_progress2(AVCodecContext *avctx, int field, int thread, int shift)
934 {
935 }
936
937 void ff_thread_report_progress2(AVCodecContext *avctx, int field, int thread, int n)
938 {
939 }
940
941 #endif
942
943 583571 const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p,
944 const uint8_t *end,
945 uint32_t *av_restrict state)
946 {
947 int i;
948
949
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 583571 times.
583571 av_assert0(p <= end);
950
2/2
✓ Branch 0 taken 648 times.
✓ Branch 1 taken 582923 times.
583571 if (p >= end)
951 648 return end;
952
953
2/2
✓ Branch 0 taken 1743447 times.
✓ Branch 1 taken 579176 times.
2322623 for (i = 0; i < 3; i++) {
954 1743447 uint32_t tmp = *state << 8;
955 1743447 *state = tmp + *(p++);
956
4/4
✓ Branch 0 taken 1742572 times.
✓ Branch 1 taken 875 times.
✓ Branch 2 taken 2872 times.
✓ Branch 3 taken 1739700 times.
1743447 if (tmp == 0x100 || p == end)
957 3747 return p;
958 }
959
960
2/2
✓ Branch 0 taken 163725177 times.
✓ Branch 1 taken 56458 times.
163781635 while (p < end) {
961
2/2
✓ Branch 0 taken 142050235 times.
✓ Branch 1 taken 21674942 times.
163725177 if (p[-1] > 1 ) p += 3;
962
2/2
✓ Branch 0 taken 8011510 times.
✓ Branch 1 taken 13663432 times.
21674942 else if (p[-2] ) p += 2;
963
2/2
✓ Branch 0 taken 13140714 times.
✓ Branch 1 taken 522718 times.
13663432 else if (p[-3]|(p[-1]-1)) p++;
964 else {
965 522718 p++;
966 522718 break;
967 }
968 }
969
970
2/2
✓ Branch 0 taken 36005 times.
✓ Branch 1 taken 543171 times.
579176 p = FFMIN(p, end) - 4;
971 579176 *state = AV_RB32(p);
972
973 579176 return p + 4;
974 }
975
976 424 AVCPBProperties *av_cpb_properties_alloc(size_t *size)
977 {
978 424 AVCPBProperties *props = av_mallocz(sizeof(AVCPBProperties));
979
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 424 times.
424 if (!props)
980 return NULL;
981
982
1/2
✓ Branch 0 taken 424 times.
✗ Branch 1 not taken.
424 if (size)
983 424 *size = sizeof(*props);
984
985 424 props->vbv_delay = UINT64_MAX;
986
987 424 return props;
988 }
989
990 840 AVCPBProperties *ff_add_cpb_side_data(AVCodecContext *avctx)
991 {
992 AVPacketSideData *tmp;
993 AVCPBProperties *props;
994 size_t size;
995 int i;
996
997
2/2
✓ Branch 0 taken 441 times.
✓ Branch 1 taken 399 times.
840 for (i = 0; i < avctx->nb_coded_side_data; i++)
998
1/2
✓ Branch 0 taken 441 times.
✗ Branch 1 not taken.
441 if (avctx->coded_side_data[i].type == AV_PKT_DATA_CPB_PROPERTIES)
999 441 return (AVCPBProperties *)avctx->coded_side_data[i].data;
1000
1001 399 props = av_cpb_properties_alloc(&size);
1002
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 399 times.
399 if (!props)
1003 return NULL;
1004
1005 399 tmp = av_realloc_array(avctx->coded_side_data, avctx->nb_coded_side_data + 1, sizeof(*tmp));
1006
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 399 times.
399 if (!tmp) {
1007 av_freep(&props);
1008 return NULL;
1009 }
1010
1011 399 avctx->coded_side_data = tmp;
1012 399 avctx->nb_coded_side_data++;
1013
1014 399 avctx->coded_side_data[avctx->nb_coded_side_data - 1].type = AV_PKT_DATA_CPB_PROPERTIES;
1015 399 avctx->coded_side_data[avctx->nb_coded_side_data - 1].data = (uint8_t*)props;
1016 399 avctx->coded_side_data[avctx->nb_coded_side_data - 1].size = size;
1017
1018 399 return props;
1019 }
1020
1021 static unsigned bcd2uint(uint8_t bcd)
1022 {
1023 unsigned low = bcd & 0xf;
1024 unsigned high = bcd >> 4;
1025 if (low > 9 || high > 9)
1026 return 0;
1027 return low + 10*high;
1028 }
1029
1030 int ff_alloc_timecode_sei(const AVFrame *frame, AVRational rate, size_t prefix_len,
1031 void **data, size_t *sei_size)
1032 {
1033 AVFrameSideData *sd = NULL;
1034 uint8_t *sei_data;
1035 PutBitContext pb;
1036 uint32_t *tc;
1037 int m;
1038
1039 if (frame)
1040 sd = av_frame_get_side_data(frame, AV_FRAME_DATA_S12M_TIMECODE);
1041
1042 if (!sd) {
1043 *data = NULL;
1044 return 0;
1045 }
1046 tc = (uint32_t*)sd->data;
1047 m = tc[0] & 3;
1048
1049 *sei_size = sizeof(uint32_t) * 4;
1050 *data = av_mallocz(*sei_size + prefix_len);
1051 if (!*data)
1052 return AVERROR(ENOMEM);
1053 sei_data = (uint8_t*)*data + prefix_len;
1054
1055 init_put_bits(&pb, sei_data, *sei_size);
1056 put_bits(&pb, 2, m); // num_clock_ts
1057
1058 for (int j = 1; j <= m; j++) {
1059 uint32_t tcsmpte = tc[j];
1060 unsigned hh = bcd2uint(tcsmpte & 0x3f); // 6-bit hours
1061 unsigned mm = bcd2uint(tcsmpte>>8 & 0x7f); // 7-bit minutes
1062 unsigned ss = bcd2uint(tcsmpte>>16 & 0x7f); // 7-bit seconds
1063 unsigned ff = bcd2uint(tcsmpte>>24 & 0x3f); // 6-bit frames
1064 unsigned drop = tcsmpte & 1<<30 && !0; // 1-bit drop if not arbitrary bit
1065
1066 /* Calculate frame number of HEVC by SMPTE ST 12-1:2014 Sec 12.2 if rate > 30FPS */
1067 if (av_cmp_q(rate, (AVRational) {30, 1}) == 1) {
1068 unsigned pc;
1069 ff *= 2;
1070 if (av_cmp_q(rate, (AVRational) {50, 1}) == 0)
1071 pc = !!(tcsmpte & 1 << 7);
1072 else
1073 pc = !!(tcsmpte & 1 << 23);
1074 ff = (ff + pc) & 0x7f;
1075 }
1076
1077 put_bits(&pb, 1, 1); // clock_timestamp_flag
1078 put_bits(&pb, 1, 1); // units_field_based_flag
1079 put_bits(&pb, 5, 0); // counting_type
1080 put_bits(&pb, 1, 1); // full_timestamp_flag
1081 put_bits(&pb, 1, 0); // discontinuity_flag
1082 put_bits(&pb, 1, drop);
1083 put_bits(&pb, 9, ff);
1084 put_bits(&pb, 6, ss);
1085 put_bits(&pb, 6, mm);
1086 put_bits(&pb, 5, hh);
1087 put_bits(&pb, 5, 0);
1088 }
1089 flush_put_bits(&pb);
1090
1091 return 0;
1092 }
1093
1094 16049 int64_t ff_guess_coded_bitrate(AVCodecContext *avctx)
1095 {
1096 16049 AVRational framerate = avctx->framerate;
1097 16049 int bits_per_coded_sample = avctx->bits_per_coded_sample;
1098 int64_t bitrate;
1099
1100
3/4
✓ Branch 0 taken 16049 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 16040 times.
16049 if (!(framerate.num && framerate.den))
1101 9 framerate = av_inv_q(avctx->time_base);
1102
2/4
✓ Branch 0 taken 16049 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 16049 times.
16049 if (!(framerate.num && framerate.den))
1103 return 0;
1104
1105
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16049 times.
16049 if (!bits_per_coded_sample) {
1106 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
1107 bits_per_coded_sample = av_get_bits_per_pixel(desc);
1108 }
1109 16049 bitrate = (int64_t)bits_per_coded_sample * avctx->width * avctx->height *
1110 16049 framerate.num / framerate.den;
1111
1112 16049 return bitrate;
1113 }
1114
1115 2400 int ff_int_from_list_or_default(void *ctx, const char * val_name, int val,
1116 const int * array_valid_values, int default_value)
1117 {
1118 2400 int i = 0, ref_val;
1119
1120 while (1) {
1121 6400 ref_val = array_valid_values[i];
1122
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6400 times.
6400 if (ref_val == INT_MAX)
1123 break;
1124
2/2
✓ Branch 0 taken 2400 times.
✓ Branch 1 taken 4000 times.
6400 if (val == ref_val)
1125 2400 return val;
1126 4000 i++;
1127 }
1128 /* val is not a valid value */
1129 av_log(ctx, AV_LOG_DEBUG,
1130 "%s %d are not supported. Set to default value : %d\n", val_name, val, default_value);
1131 return default_value;
1132 }
1133