FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/utils.c
Date: 2022-07-04 19:11:22
Exec Total Coverage
Lines: 409 562 72.8%
Branches: 305 428 71.3%

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