FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/pcm.c
Date: 2021-09-24 20:55:06
Exec Total Coverage
Lines: 203 271 74.9%
Branches: 148 187 79.1%

Line Branch Exec Source
1 /*
2 * PCM codecs
3 * Copyright (c) 2001 Fabrice Bellard
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * PCM codecs
25 */
26
27 #include "config.h"
28 #include "libavutil/attributes.h"
29 #include "libavutil/float_dsp.h"
30 #include "libavutil/thread.h"
31 #include "avcodec.h"
32 #include "bytestream.h"
33 #include "encode.h"
34 #include "internal.h"
35 #include "mathops.h"
36 #include "pcm_tablegen.h"
37
38 1028 static av_cold int pcm_encode_init(AVCodecContext *avctx)
39 {
40 1028 avctx->frame_size = 0;
41 #if !CONFIG_HARDCODED_TABLES
42
3/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1020 times.
1028 switch (avctx->codec->id) {
43 #define INIT_ONCE(id, name) \
44 case AV_CODEC_ID_PCM_ ## id: \
45 if (CONFIG_PCM_ ## id ## _ENCODER) { \
46 static AVOnce init_static_once = AV_ONCE_INIT; \
47 ff_thread_once(&init_static_once, pcm_ ## name ## _tableinit); \
48 } \
49 break
50 6 INIT_ONCE(ALAW, alaw);
51 2 INIT_ONCE(MULAW, ulaw);
52 INIT_ONCE(VIDC, vidc);
53 1020 default:
54 1020 break;
55 }
56 #endif
57
58 1028 avctx->bits_per_coded_sample = av_get_bits_per_sample(avctx->codec->id);
59 1028 avctx->block_align = avctx->channels * avctx->bits_per_coded_sample / 8;
60 1028 avctx->bit_rate = avctx->block_align * 8LL * avctx->sample_rate;
61
62 1028 return 0;
63 }
64
65 /**
66 * Write PCM samples macro
67 * @param type Datatype of native machine format
68 * @param endian bytestream_put_xxx() suffix
69 * @param src Source pointer (variable name)
70 * @param dst Destination pointer (variable name)
71 * @param n Total number of samples (variable name)
72 * @param shift Bitshift (bits)
73 * @param offset Sample value offset
74 */
75 #define ENCODE(type, endian, src, dst, n, shift, offset) \
76 samples_ ## type = (const type *) src; \
77 for (; n > 0; n--) { \
78 register type v = (*samples_ ## type++ >> shift) + offset; \
79 bytestream_put_ ## endian(&dst, v); \
80 }
81
82 #define ENCODE_PLANAR(type, endian, dst, n, shift, offset) \
83 n /= avctx->channels; \
84 for (c = 0; c < avctx->channels; c++) { \
85 int i; \
86 samples_ ## type = (const type *) frame->extended_data[c]; \
87 for (i = n; i > 0; i--) { \
88 register type v = (*samples_ ## type++ >> shift) + offset; \
89 bytestream_put_ ## endian(&dst, v); \
90 } \
91 }
92
93 238758 static int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
94 const AVFrame *frame, int *got_packet_ptr)
95 {
96 int n, c, sample_size, v, ret;
97 const short *samples;
98 unsigned char *dst;
99 const uint8_t *samples_uint8_t;
100 const int16_t *samples_int16_t;
101 const int32_t *samples_int32_t;
102 const int64_t *samples_int64_t;
103 const uint16_t *samples_uint16_t;
104 const uint32_t *samples_uint32_t;
105
106 238758 sample_size = av_get_bits_per_sample(avctx->codec->id) / 8;
107 238758 n = frame->nb_samples * avctx->channels;
108 238758 samples = (const short *)frame->data[0];
109
110
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 238758 times.
238758 if ((ret = ff_get_encode_buffer(avctx, avpkt, n * sample_size, 0)) < 0)
111 return ret;
112 238758 dst = avpkt->data;
113
114
20/22
✓ Branch 0 taken 259 times.
✓ Branch 1 taken 259 times.
✓ Branch 2 taken 5847 times.
✓ Branch 3 taken 259 times.
✓ Branch 4 taken 259 times.
✓ Branch 5 taken 259 times.
✓ Branch 6 taken 259 times.
✓ Branch 7 taken 20 times.
✓ Branch 8 taken 259 times.
✓ Branch 9 taken 259 times.
✓ Branch 10 taken 366 times.
✓ Branch 11 taken 259 times.
✓ Branch 12 taken 259 times.
✓ Branch 13 taken 562 times.
✓ Branch 14 taken 397 times.
✓ Branch 15 taken 303 times.
✓ Branch 16 taken 227373 times.
✓ Branch 17 taken 518 times.
✓ Branch 18 taken 479 times.
✓ Branch 19 taken 303 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
238758 switch (avctx->codec->id) {
115 259 case AV_CODEC_ID_PCM_U32LE:
116
2/2
✓ Branch 1 taken 529200 times.
✓ Branch 2 taken 259 times.
529459 ENCODE(uint32_t, le32, samples, dst, n, 0, 0x80000000)
117 259 break;
118 259 case AV_CODEC_ID_PCM_U32BE:
119
2/2
✓ Branch 1 taken 529200 times.
✓ Branch 2 taken 259 times.
529459 ENCODE(uint32_t, be32, samples, dst, n, 0, 0x80000000)
120 259 break;
121 5847 case AV_CODEC_ID_PCM_S24LE:
122
2/2
✓ Branch 1 taken 39348586 times.
✓ Branch 2 taken 5847 times.
39354433 ENCODE(int32_t, le24, samples, dst, n, 8, 0)
123 5847 break;
124 259 case AV_CODEC_ID_PCM_S24LE_PLANAR:
125
4/4
✓ Branch 1 taken 529200 times.
✓ Branch 2 taken 518 times.
✓ Branch 3 taken 518 times.
✓ Branch 4 taken 259 times.
529977 ENCODE_PLANAR(int32_t, le24, dst, n, 8, 0)
126 259 break;
127 259 case AV_CODEC_ID_PCM_S24BE:
128
2/2
✓ Branch 1 taken 529200 times.
✓ Branch 2 taken 259 times.
529459 ENCODE(int32_t, be24, samples, dst, n, 8, 0)
129 259 break;
130 259 case AV_CODEC_ID_PCM_U24LE:
131
2/2
✓ Branch 1 taken 529200 times.
✓ Branch 2 taken 259 times.
529459 ENCODE(uint32_t, le24, samples, dst, n, 8, 0x800000)
132 259 break;
133 259 case AV_CODEC_ID_PCM_U24BE:
134
2/2
✓ Branch 1 taken 529200 times.
✓ Branch 2 taken 259 times.
529459 ENCODE(uint32_t, be24, samples, dst, n, 8, 0x800000)
135 259 break;
136 20 case AV_CODEC_ID_PCM_S24DAUD:
137
2/2
✓ Branch 0 taken 40920 times.
✓ Branch 1 taken 20 times.
40940 for (; n > 0; n--) {
138 40920 uint32_t tmp = ff_reverse[(*samples >> 8) & 0xff] +
139 40920 (ff_reverse[*samples & 0xff] << 8);
140 40920 tmp <<= 4; // sync flags would go here
141 40920 bytestream_put_be24(&dst, tmp);
142 40920 samples++;
143 }
144 20 break;
145 259 case AV_CODEC_ID_PCM_U16LE:
146
2/2
✓ Branch 1 taken 529200 times.
✓ Branch 2 taken 259 times.
529459 ENCODE(uint16_t, le16, samples, dst, n, 0, 0x8000)
147 259 break;
148 259 case AV_CODEC_ID_PCM_U16BE:
149
2/2
✓ Branch 1 taken 529200 times.
✓ Branch 2 taken 259 times.
529459 ENCODE(uint16_t, be16, samples, dst, n, 0, 0x8000)
150 259 break;
151 366 case AV_CODEC_ID_PCM_S8:
152
2/2
✓ Branch 1 taken 7726268 times.
✓ Branch 2 taken 366 times.
7726634 ENCODE(uint8_t, byte, samples, dst, n, 0, -128)
153 366 break;
154 259 case AV_CODEC_ID_PCM_S8_PLANAR:
155
4/4
✓ Branch 1 taken 529200 times.
✓ Branch 2 taken 518 times.
✓ Branch 3 taken 518 times.
✓ Branch 4 taken 259 times.
529977 ENCODE_PLANAR(uint8_t, byte, dst, n, 0, -128)
156 259 break;
157 #if HAVE_BIGENDIAN
158 case AV_CODEC_ID_PCM_S64LE:
159 case AV_CODEC_ID_PCM_F64LE:
160 ENCODE(int64_t, le64, samples, dst, n, 0, 0)
161 break;
162 case AV_CODEC_ID_PCM_S32LE:
163 case AV_CODEC_ID_PCM_F32LE:
164 ENCODE(int32_t, le32, samples, dst, n, 0, 0)
165 break;
166 case AV_CODEC_ID_PCM_S32LE_PLANAR:
167 ENCODE_PLANAR(int32_t, le32, dst, n, 0, 0)
168 break;
169 case AV_CODEC_ID_PCM_S16LE:
170 ENCODE(int16_t, le16, samples, dst, n, 0, 0)
171 break;
172 case AV_CODEC_ID_PCM_S16LE_PLANAR:
173 ENCODE_PLANAR(int16_t, le16, dst, n, 0, 0)
174 break;
175 case AV_CODEC_ID_PCM_F64BE:
176 case AV_CODEC_ID_PCM_F32BE:
177 case AV_CODEC_ID_PCM_S64BE:
178 case AV_CODEC_ID_PCM_S32BE:
179 case AV_CODEC_ID_PCM_S16BE:
180 #else
181 259 case AV_CODEC_ID_PCM_S64BE:
182 case AV_CODEC_ID_PCM_F64BE:
183
2/2
✓ Branch 1 taken 529200 times.
✓ Branch 2 taken 259 times.
529459 ENCODE(int64_t, be64, samples, dst, n, 0, 0)
184 259 break;
185 562 case AV_CODEC_ID_PCM_F32BE:
186 case AV_CODEC_ID_PCM_S32BE:
187
2/2
✓ Branch 1 taken 1159776 times.
✓ Branch 2 taken 562 times.
1160338 ENCODE(int32_t, be32, samples, dst, n, 0, 0)
188 562 break;
189 397 case AV_CODEC_ID_PCM_S16BE:
190
2/2
✓ Branch 1 taken 673696 times.
✓ Branch 2 taken 397 times.
674093 ENCODE(int16_t, be16, samples, dst, n, 0, 0)
191 397 break;
192 303 case AV_CODEC_ID_PCM_S16BE_PLANAR:
193
4/4
✓ Branch 1 taken 617400 times.
✓ Branch 2 taken 606 times.
✓ Branch 3 taken 606 times.
✓ Branch 4 taken 303 times.
618309 ENCODE_PLANAR(int16_t, be16, dst, n, 0, 0)
194 303 break;
195 227373 case AV_CODEC_ID_PCM_F64LE:
196 case AV_CODEC_ID_PCM_F32LE:
197 case AV_CODEC_ID_PCM_S64LE:
198 case AV_CODEC_ID_PCM_S32LE:
199 case AV_CODEC_ID_PCM_S16LE:
200 #endif /* HAVE_BIGENDIAN */
201 case AV_CODEC_ID_PCM_U8:
202 227373 memcpy(dst, samples, n * sample_size);
203 227373 break;
204 #if HAVE_BIGENDIAN
205 case AV_CODEC_ID_PCM_S16BE_PLANAR:
206 #else
207 518 case AV_CODEC_ID_PCM_S16LE_PLANAR:
208 case AV_CODEC_ID_PCM_S32LE_PLANAR:
209 #endif /* HAVE_BIGENDIAN */
210 518 n /= avctx->channels;
211
2/2
✓ Branch 0 taken 1036 times.
✓ Branch 1 taken 518 times.
1554 for (c = 0; c < avctx->channels; c++) {
212 1036 const uint8_t *src = frame->extended_data[c];
213 1036 bytestream_put_buffer(&dst, src, n * sample_size);
214 }
215 518 break;
216 479 case AV_CODEC_ID_PCM_ALAW:
217
2/2
✓ Branch 0 taken 749700 times.
✓ Branch 1 taken 479 times.
750179 for (; n > 0; n--) {
218 749700 v = *samples++;
219 749700 *dst++ = linear_to_alaw[(v + 32768) >> 2];
220 }
221 479 break;
222 303 case AV_CODEC_ID_PCM_MULAW:
223
2/2
✓ Branch 0 taken 573300 times.
✓ Branch 1 taken 303 times.
573603 for (; n > 0; n--) {
224 573300 v = *samples++;
225 573300 *dst++ = linear_to_ulaw[(v + 32768) >> 2];
226 }
227 303 break;
228 case AV_CODEC_ID_PCM_VIDC:
229 for (; n > 0; n--) {
230 v = *samples++;
231 *dst++ = linear_to_vidc[(v + 32768) >> 2];
232 }
233 break;
234 default:
235 return -1;
236 }
237
238 238758 *got_packet_ptr = 1;
239 238758 return 0;
240 }
241
242 typedef struct PCMDecode {
243 short table[256];
244 void (*vector_fmul_scalar)(float *dst, const float *src, float mul,
245 int len);
246 float scale;
247 } PCMDecode;
248
249 1487 static av_cold int pcm_decode_init(AVCodecContext *avctx)
250 {
251 1487 PCMDecode *s = avctx->priv_data;
252 AVFloatDSPContext *fdsp;
253 int i;
254
255
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1487 times.
1487 if (avctx->channels <= 0) {
256 av_log(avctx, AV_LOG_ERROR, "PCM channels out of bounds\n");
257 return AVERROR(EINVAL);
258 }
259
260
3/5
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1449 times.
1487 switch (avctx->codec_id) {
261 24 case AV_CODEC_ID_PCM_ALAW:
262
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 24 times.
6168 for (i = 0; i < 256; i++)
263 6144 s->table[i] = alaw2linear(i);
264 24 break;
265 14 case AV_CODEC_ID_PCM_MULAW:
266
2/2
✓ Branch 0 taken 3584 times.
✓ Branch 1 taken 14 times.
3598 for (i = 0; i < 256; i++)
267 3584 s->table[i] = ulaw2linear(i);
268 14 break;
269 case AV_CODEC_ID_PCM_VIDC:
270 for (i = 0; i < 256; i++)
271 s->table[i] = vidc2linear(i);
272 break;
273 case AV_CODEC_ID_PCM_F16LE:
274 case AV_CODEC_ID_PCM_F24LE:
275 if (avctx->bits_per_coded_sample < 1 || avctx->bits_per_coded_sample > 24)
276 return AVERROR_INVALIDDATA;
277
278 s->scale = 1. / (1 << (avctx->bits_per_coded_sample - 1));
279 fdsp = avpriv_float_dsp_alloc(0);
280 if (!fdsp)
281 return AVERROR(ENOMEM);
282 s->vector_fmul_scalar = fdsp->vector_fmul_scalar;
283 av_free(fdsp);
284 break;
285 1449 default:
286 1449 break;
287 }
288
289 1487 avctx->sample_fmt = avctx->codec->sample_fmts[0];
290
291
2/2
✓ Branch 0 taken 59 times.
✓ Branch 1 taken 1428 times.
1487 if (avctx->sample_fmt == AV_SAMPLE_FMT_S32)
292 59 avctx->bits_per_raw_sample = av_get_bits_per_sample(avctx->codec_id);
293
294 1487 return 0;
295 }
296
297 /**
298 * Read PCM samples macro
299 * @param size Data size of native machine format
300 * @param endian bytestream_get_xxx() endian suffix
301 * @param src Source pointer (variable name)
302 * @param dst Destination pointer (variable name)
303 * @param n Total number of samples (variable name)
304 * @param shift Bitshift (bits)
305 * @param offset Sample value offset
306 */
307 #define DECODE(size, endian, src, dst, n, shift, offset) \
308 for (; n > 0; n--) { \
309 uint ## size ## _t v = bytestream_get_ ## endian(&src); \
310 AV_WN ## size ## A(dst, (uint ## size ## _t)(v - offset) << shift); \
311 dst += size / 8; \
312 }
313
314 #define DECODE_PLANAR(size, endian, src, dst, n, shift, offset) \
315 n /= avctx->channels; \
316 for (c = 0; c < avctx->channels; c++) { \
317 int i; \
318 dst = frame->extended_data[c]; \
319 for (i = n; i > 0; i--) { \
320 uint ## size ## _t v = bytestream_get_ ## endian(&src); \
321 AV_WN ## size ## A(dst, (uint ## size ##_t)(v - offset) << shift); \
322 dst += size / 8; \
323 } \
324 }
325
326 77476 static int pcm_decode_frame(AVCodecContext *avctx, void *data,
327 int *got_frame_ptr, AVPacket *avpkt)
328 {
329 77476 const uint8_t *src = avpkt->data;
330 77476 int buf_size = avpkt->size;
331 77476 PCMDecode *s = avctx->priv_data;
332 77476 AVFrame *frame = data;
333 int sample_size, c, n, ret, samples_per_block;
334 uint8_t *samples;
335 int32_t *dst_int32_t;
336
337 77476 sample_size = av_get_bits_per_sample(avctx->codec_id) / 8;
338
339 /* av_get_bits_per_sample returns 0 for AV_CODEC_ID_PCM_DVD */
340 77476 samples_per_block = 1;
341
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 77476 times.
77476 if (avctx->codec_id == AV_CODEC_ID_PCM_LXF) {
342 /* we process 40-bit blocks per channel for LXF */
343 samples_per_block = 2;
344 sample_size = 5;
345 }
346
347
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 77476 times.
77476 if (sample_size == 0) {
348 av_log(avctx, AV_LOG_ERROR, "Invalid sample_size\n");
349 return AVERROR(EINVAL);
350 }
351
352
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 77476 times.
77476 if (avctx->channels == 0) {
353 av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
354 return AVERROR(EINVAL);
355 }
356
357
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 77476 times.
77476 if (avctx->codec_id != avctx->codec->id) {
358 av_log(avctx, AV_LOG_ERROR, "codec ids mismatch\n");
359 return AVERROR(EINVAL);
360 }
361
362 77476 n = avctx->channels * sample_size;
363
364
2/4
✓ Branch 0 taken 77476 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 77476 times.
77476 if (n && buf_size % n) {
365 if (buf_size < n) {
366 av_log(avctx, AV_LOG_ERROR,
367 "Invalid PCM packet, data has size %d but at least a size of %d was expected\n",
368 buf_size, n);
369 return AVERROR_INVALIDDATA;
370 } else
371 buf_size -= buf_size % n;
372 }
373
374 77476 n = buf_size / sample_size;
375
376 /* get output buffer */
377 77476 frame->nb_samples = n * samples_per_block / avctx->channels;
378
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 77476 times.
77476 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
379 return ret;
380 77476 samples = frame->data[0];
381
382
19/22
✓ Branch 0 taken 259 times.
✓ Branch 1 taken 259 times.
✓ Branch 2 taken 14479 times.
✓ Branch 3 taken 259 times.
✓ Branch 4 taken 259 times.
✓ Branch 5 taken 259 times.
✓ Branch 6 taken 259 times.
✓ Branch 7 taken 20 times.
✓ Branch 8 taken 259 times.
✓ Branch 9 taken 259 times.
✓ Branch 10 taken 259 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 259 times.
✓ Branch 13 taken 259 times.
✓ Branch 14 taken 518 times.
✓ Branch 15 taken 1028 times.
✓ Branch 16 taken 303 times.
✓ Branch 17 taken 54771 times.
✓ Branch 18 taken 660 times.
✓ Branch 19 taken 2848 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
77476 switch (avctx->codec_id) {
383 259 case AV_CODEC_ID_PCM_U32LE:
384
2/2
✓ Branch 1 taken 529200 times.
✓ Branch 2 taken 259 times.
529459 DECODE(32, le32, src, samples, n, 0, 0x80000000)
385 259 break;
386 259 case AV_CODEC_ID_PCM_U32BE:
387
2/2
✓ Branch 1 taken 529200 times.
✓ Branch 2 taken 259 times.
529459 DECODE(32, be32, src, samples, n, 0, 0x80000000)
388 259 break;
389 14479 case AV_CODEC_ID_PCM_S24LE:
390
2/2
✓ Branch 1 taken 19744724 times.
✓ Branch 2 taken 14479 times.
19759203 DECODE(32, le24, src, samples, n, 8, 0)
391 14479 break;
392 259 case AV_CODEC_ID_PCM_S24LE_PLANAR:
393
4/4
✓ Branch 1 taken 529200 times.
✓ Branch 2 taken 518 times.
✓ Branch 3 taken 518 times.
✓ Branch 4 taken 259 times.
529977 DECODE_PLANAR(32, le24, src, samples, n, 8, 0);
394 259 break;
395 259 case AV_CODEC_ID_PCM_S24BE:
396
2/2
✓ Branch 1 taken 529200 times.
✓ Branch 2 taken 259 times.
529459 DECODE(32, be24, src, samples, n, 8, 0)
397 259 break;
398 259 case AV_CODEC_ID_PCM_U24LE:
399
2/2
✓ Branch 1 taken 529200 times.
✓ Branch 2 taken 259 times.
529459 DECODE(32, le24, src, samples, n, 8, 0x800000)
400 259 break;
401 259 case AV_CODEC_ID_PCM_U24BE:
402
2/2
✓ Branch 1 taken 529200 times.
✓ Branch 2 taken 259 times.
529459 DECODE(32, be24, src, samples, n, 8, 0x800000)
403 259 break;
404 20 case AV_CODEC_ID_PCM_S24DAUD:
405
2/2
✓ Branch 0 taken 40920 times.
✓ Branch 1 taken 20 times.
40940 for (; n > 0; n--) {
406 40920 uint32_t v = bytestream_get_be24(&src);
407 40920 v >>= 4; // sync flags are here
408 40920 AV_WN16A(samples, ff_reverse[(v >> 8) & 0xff] +
409 (ff_reverse[v & 0xff] << 8));
410 40920 samples += 2;
411 }
412 20 break;
413 259 case AV_CODEC_ID_PCM_U16LE:
414
2/2
✓ Branch 1 taken 529200 times.
✓ Branch 2 taken 259 times.
529459 DECODE(16, le16, src, samples, n, 0, 0x8000)
415 259 break;
416 259 case AV_CODEC_ID_PCM_U16BE:
417
2/2
✓ Branch 1 taken 529200 times.
✓ Branch 2 taken 259 times.
529459 DECODE(16, be16, src, samples, n, 0, 0x8000)
418 259 break;
419 259 case AV_CODEC_ID_PCM_S8:
420
2/2
✓ Branch 0 taken 529200 times.
✓ Branch 1 taken 259 times.
529459 for (; n > 0; n--)
421 529200 *samples++ = *src++ + 128;
422 259 break;
423 case AV_CODEC_ID_PCM_SGA:
424 for (; n > 0; n--) {
425 int sign = *src >> 7;
426 int magn = *src & 0x7f;
427 *samples++ = sign ? 128 - magn : 128 + magn;
428 src++;
429 }
430 break;
431 259 case AV_CODEC_ID_PCM_S8_PLANAR:
432 259 n /= avctx->channels;
433
2/2
✓ Branch 0 taken 518 times.
✓ Branch 1 taken 259 times.
777 for (c = 0; c < avctx->channels; c++) {
434 int i;
435 518 samples = frame->extended_data[c];
436
2/2
✓ Branch 0 taken 529200 times.
✓ Branch 1 taken 518 times.
529718 for (i = n; i > 0; i--)
437 529200 *samples++ = *src++ + 128;
438 }
439 259 break;
440 #if HAVE_BIGENDIAN
441 case AV_CODEC_ID_PCM_S64LE:
442 case AV_CODEC_ID_PCM_F64LE:
443 DECODE(64, le64, src, samples, n, 0, 0)
444 break;
445 case AV_CODEC_ID_PCM_S32LE:
446 case AV_CODEC_ID_PCM_F32LE:
447 case AV_CODEC_ID_PCM_F24LE:
448 case AV_CODEC_ID_PCM_F16LE:
449 DECODE(32, le32, src, samples, n, 0, 0)
450 break;
451 case AV_CODEC_ID_PCM_S32LE_PLANAR:
452 DECODE_PLANAR(32, le32, src, samples, n, 0, 0);
453 break;
454 case AV_CODEC_ID_PCM_S16LE:
455 DECODE(16, le16, src, samples, n, 0, 0)
456 break;
457 case AV_CODEC_ID_PCM_S16LE_PLANAR:
458 DECODE_PLANAR(16, le16, src, samples, n, 0, 0);
459 break;
460 case AV_CODEC_ID_PCM_F64BE:
461 case AV_CODEC_ID_PCM_F32BE:
462 case AV_CODEC_ID_PCM_S64BE:
463 case AV_CODEC_ID_PCM_S32BE:
464 case AV_CODEC_ID_PCM_S16BE:
465 #else
466 259 case AV_CODEC_ID_PCM_S64BE:
467 case AV_CODEC_ID_PCM_F64BE:
468
2/2
✓ Branch 1 taken 529200 times.
✓ Branch 2 taken 259 times.
529459 DECODE(64, be64, src, samples, n, 0, 0)
469 259 break;
470 518 case AV_CODEC_ID_PCM_F32BE:
471 case AV_CODEC_ID_PCM_S32BE:
472
2/2
✓ Branch 1 taken 1058400 times.
✓ Branch 2 taken 518 times.
1058918 DECODE(32, be32, src, samples, n, 0, 0)
473 518 break;
474 1028 case AV_CODEC_ID_PCM_S16BE:
475
2/2
✓ Branch 1 taken 1887814 times.
✓ Branch 2 taken 1028 times.
1888842 DECODE(16, be16, src, samples, n, 0, 0)
476 1028 break;
477 303 case AV_CODEC_ID_PCM_S16BE_PLANAR:
478
4/4
✓ Branch 1 taken 617400 times.
✓ Branch 2 taken 606 times.
✓ Branch 3 taken 606 times.
✓ Branch 4 taken 303 times.
618309 DECODE_PLANAR(16, be16, src, samples, n, 0, 0);
479 303 break;
480 54771 case AV_CODEC_ID_PCM_F64LE:
481 case AV_CODEC_ID_PCM_F32LE:
482 case AV_CODEC_ID_PCM_F24LE:
483 case AV_CODEC_ID_PCM_F16LE:
484 case AV_CODEC_ID_PCM_S64LE:
485 case AV_CODEC_ID_PCM_S32LE:
486 case AV_CODEC_ID_PCM_S16LE:
487 #endif /* HAVE_BIGENDIAN */
488 case AV_CODEC_ID_PCM_U8:
489 54771 memcpy(samples, src, n * sample_size);
490 54771 break;
491 #if HAVE_BIGENDIAN
492 case AV_CODEC_ID_PCM_S16BE_PLANAR:
493 #else
494 660 case AV_CODEC_ID_PCM_S16LE_PLANAR:
495 case AV_CODEC_ID_PCM_S32LE_PLANAR:
496 #endif /* HAVE_BIGENDIAN */
497 660 n /= avctx->channels;
498
2/2
✓ Branch 0 taken 1320 times.
✓ Branch 1 taken 660 times.
1980 for (c = 0; c < avctx->channels; c++) {
499 1320 samples = frame->extended_data[c];
500 1320 bytestream_get_buffer(&src, samples, n * sample_size);
501 }
502 660 break;
503 2848 case AV_CODEC_ID_PCM_ALAW:
504 case AV_CODEC_ID_PCM_MULAW:
505 case AV_CODEC_ID_PCM_VIDC:
506
2/2
✓ Branch 0 taken 4969188 times.
✓ Branch 1 taken 2848 times.
4972036 for (; n > 0; n--) {
507 4969188 AV_WN16A(samples, s->table[*src++]);
508 4969188 samples += 2;
509 }
510 2848 break;
511 case AV_CODEC_ID_PCM_LXF:
512 {
513 int i;
514 n /= avctx->channels;
515 for (c = 0; c < avctx->channels; c++) {
516 dst_int32_t = (int32_t *)frame->extended_data[c];
517 for (i = 0; i < n; i++) {
518 // extract low 20 bits and expand to 32 bits
519 *dst_int32_t++ = ((uint32_t)src[2]<<28) |
520 (src[1] << 20) |
521 (src[0] << 12) |
522 ((src[2] & 0x0F) << 8) |
523 src[1];
524 // extract high 20 bits and expand to 32 bits
525 *dst_int32_t++ = ((uint32_t)src[4]<<24) |
526 (src[3] << 16) |
527 ((src[2] & 0xF0) << 8) |
528 (src[4] << 4) |
529 (src[3] >> 4);
530 src += 5;
531 }
532 }
533 break;
534 }
535 default:
536 return -1;
537 }
538
539
1/2
✓ Branch 0 taken 77476 times.
✗ Branch 1 not taken.
77476 if (avctx->codec_id == AV_CODEC_ID_PCM_F16LE ||
540
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 77476 times.
77476 avctx->codec_id == AV_CODEC_ID_PCM_F24LE) {
541 s->vector_fmul_scalar((float *)frame->extended_data[0],
542 (const float *)frame->extended_data[0],
543 s->scale, FFALIGN(frame->nb_samples * avctx->channels, 4));
544 emms_c();
545 }
546
547 77476 *got_frame_ptr = 1;
548
549 77476 return buf_size;
550 }
551
552 #define PCM_ENCODER_0(id_, sample_fmt_, name_, long_name_)
553 #define PCM_ENCODER_1(id_, sample_fmt_, name_, long_name_) \
554 const AVCodec ff_ ## name_ ## _encoder = { \
555 .name = #name_, \
556 .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
557 .type = AVMEDIA_TYPE_AUDIO, \
558 .id = AV_CODEC_ID_ ## id_, \
559 .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_VARIABLE_FRAME_SIZE, \
560 .init = pcm_encode_init, \
561 .encode2 = pcm_encode_frame, \
562 .sample_fmts = (const enum AVSampleFormat[]){ sample_fmt_, \
563 AV_SAMPLE_FMT_NONE }, \
564 .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, \
565 }
566
567 #define PCM_ENCODER_2(cf, id, sample_fmt, name, long_name) \
568 PCM_ENCODER_ ## cf(id, sample_fmt, name, long_name)
569 #define PCM_ENCODER_3(cf, id, sample_fmt, name, long_name) \
570 PCM_ENCODER_2(cf, id, sample_fmt, name, long_name)
571 #define PCM_ENCODER(id, sample_fmt, name, long_name) \
572 PCM_ENCODER_3(CONFIG_ ## id ## _ENCODER, id, sample_fmt, name, long_name)
573
574 #define PCM_DECODER_0(id, sample_fmt, name, long_name)
575 #define PCM_DECODER_1(id_, sample_fmt_, name_, long_name_) \
576 const AVCodec ff_ ## name_ ## _decoder = { \
577 .name = #name_, \
578 .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
579 .type = AVMEDIA_TYPE_AUDIO, \
580 .id = AV_CODEC_ID_ ## id_, \
581 .priv_data_size = sizeof(PCMDecode), \
582 .init = pcm_decode_init, \
583 .decode = pcm_decode_frame, \
584 .capabilities = AV_CODEC_CAP_DR1, \
585 .sample_fmts = (const enum AVSampleFormat[]){ sample_fmt_, \
586 AV_SAMPLE_FMT_NONE }, \
587 .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, \
588 }
589
590 #define PCM_DECODER_2(cf, id, sample_fmt, name, long_name) \
591 PCM_DECODER_ ## cf(id, sample_fmt, name, long_name)
592 #define PCM_DECODER_3(cf, id, sample_fmt, name, long_name) \
593 PCM_DECODER_2(cf, id, sample_fmt, name, long_name)
594 #define PCM_DECODER(id, sample_fmt, name, long_name) \
595 PCM_DECODER_3(CONFIG_ ## id ## _DECODER, id, sample_fmt, name, long_name)
596
597 #define PCM_CODEC(id, sample_fmt_, name, long_name_) \
598 PCM_ENCODER(id, sample_fmt_, name, long_name_); \
599 PCM_DECODER(id, sample_fmt_, name, long_name_)
600
601 /* Note: Do not forget to add new entries to the Makefile as well. */
602 PCM_CODEC (PCM_ALAW, AV_SAMPLE_FMT_S16, pcm_alaw, "PCM A-law / G.711 A-law");
603 PCM_DECODER(PCM_F16LE, AV_SAMPLE_FMT_FLT, pcm_f16le, "PCM 16.8 floating point little-endian");
604 PCM_DECODER(PCM_F24LE, AV_SAMPLE_FMT_FLT, pcm_f24le, "PCM 24.0 floating point little-endian");
605 PCM_CODEC (PCM_F32BE, AV_SAMPLE_FMT_FLT, pcm_f32be, "PCM 32-bit floating point big-endian");
606 PCM_CODEC (PCM_F32LE, AV_SAMPLE_FMT_FLT, pcm_f32le, "PCM 32-bit floating point little-endian");
607 PCM_CODEC (PCM_F64BE, AV_SAMPLE_FMT_DBL, pcm_f64be, "PCM 64-bit floating point big-endian");
608 PCM_CODEC (PCM_F64LE, AV_SAMPLE_FMT_DBL, pcm_f64le, "PCM 64-bit floating point little-endian");
609 PCM_DECODER(PCM_LXF, AV_SAMPLE_FMT_S32P,pcm_lxf, "PCM signed 20-bit little-endian planar");
610 PCM_CODEC (PCM_MULAW, AV_SAMPLE_FMT_S16, pcm_mulaw, "PCM mu-law / G.711 mu-law");
611 PCM_CODEC (PCM_S8, AV_SAMPLE_FMT_U8, pcm_s8, "PCM signed 8-bit");
612 PCM_CODEC (PCM_S8_PLANAR, AV_SAMPLE_FMT_U8P, pcm_s8_planar, "PCM signed 8-bit planar");
613 PCM_CODEC (PCM_S16BE, AV_SAMPLE_FMT_S16, pcm_s16be, "PCM signed 16-bit big-endian");
614 PCM_CODEC (PCM_S16BE_PLANAR, AV_SAMPLE_FMT_S16P,pcm_s16be_planar, "PCM signed 16-bit big-endian planar");
615 PCM_CODEC (PCM_S16LE, AV_SAMPLE_FMT_S16, pcm_s16le, "PCM signed 16-bit little-endian");
616 PCM_CODEC (PCM_S16LE_PLANAR, AV_SAMPLE_FMT_S16P,pcm_s16le_planar, "PCM signed 16-bit little-endian planar");
617 PCM_CODEC (PCM_S24BE, AV_SAMPLE_FMT_S32, pcm_s24be, "PCM signed 24-bit big-endian");
618 PCM_CODEC (PCM_S24DAUD, AV_SAMPLE_FMT_S16, pcm_s24daud, "PCM D-Cinema audio signed 24-bit");
619 PCM_CODEC (PCM_S24LE, AV_SAMPLE_FMT_S32, pcm_s24le, "PCM signed 24-bit little-endian");
620 PCM_CODEC (PCM_S24LE_PLANAR, AV_SAMPLE_FMT_S32P,pcm_s24le_planar, "PCM signed 24-bit little-endian planar");
621 PCM_CODEC (PCM_S32BE, AV_SAMPLE_FMT_S32, pcm_s32be, "PCM signed 32-bit big-endian");
622 PCM_CODEC (PCM_S32LE, AV_SAMPLE_FMT_S32, pcm_s32le, "PCM signed 32-bit little-endian");
623 PCM_CODEC (PCM_S32LE_PLANAR, AV_SAMPLE_FMT_S32P,pcm_s32le_planar, "PCM signed 32-bit little-endian planar");
624 PCM_CODEC (PCM_U8, AV_SAMPLE_FMT_U8, pcm_u8, "PCM unsigned 8-bit");
625 PCM_CODEC (PCM_U16BE, AV_SAMPLE_FMT_S16, pcm_u16be, "PCM unsigned 16-bit big-endian");
626 PCM_CODEC (PCM_U16LE, AV_SAMPLE_FMT_S16, pcm_u16le, "PCM unsigned 16-bit little-endian");
627 PCM_CODEC (PCM_U24BE, AV_SAMPLE_FMT_S32, pcm_u24be, "PCM unsigned 24-bit big-endian");
628 PCM_CODEC (PCM_U24LE, AV_SAMPLE_FMT_S32, pcm_u24le, "PCM unsigned 24-bit little-endian");
629 PCM_CODEC (PCM_U32BE, AV_SAMPLE_FMT_S32, pcm_u32be, "PCM unsigned 32-bit big-endian");
630 PCM_CODEC (PCM_U32LE, AV_SAMPLE_FMT_S32, pcm_u32le, "PCM unsigned 32-bit little-endian");
631 PCM_CODEC (PCM_S64BE, AV_SAMPLE_FMT_S64, pcm_s64be, "PCM signed 64-bit big-endian");
632 PCM_CODEC (PCM_S64LE, AV_SAMPLE_FMT_S64, pcm_s64le, "PCM signed 64-bit little-endian");
633 PCM_CODEC (PCM_VIDC, AV_SAMPLE_FMT_S16, pcm_vidc, "PCM Archimedes VIDC");
634 PCM_DECODER(PCM_SGA, AV_SAMPLE_FMT_U8, pcm_sga, "PCM SGA");
635