FFmpeg
Loading...
Searching...
No Matches
pcm.c
Go to the documentation of this file.
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 "config_components.h"
30#include "libavutil/float_dsp.h"
31#include "libavutil/mem.h"
32#include "libavutil/reverse.h"
33#include "libavutil/thread.h"
34#include "avcodec.h"
35#include "bytestream.h"
36#include "codec_internal.h"
37#include "decode.h"
38#include "encode.h"
39#include "pcm_tablegen.h"
40
42{
43#if !CONFIG_HARDCODED_TABLES
44 switch (avctx->codec->id) {
45#if CONFIG_PCM_ALAW_ENCODER
47 static AVOnce once_alaw = AV_ONCE_INIT;
48 ff_thread_once(&once_alaw, pcm_alaw_tableinit);
49 break;
50 }
51#endif
52#if CONFIG_PCM_MULAW_ENCODER
54 static AVOnce once_mulaw = AV_ONCE_INIT;
55 ff_thread_once(&once_mulaw, pcm_ulaw_tableinit);
56 break;
57 }
58#endif
59#if CONFIG_PCM_VIDC_ENCODER
61 static AVOnce once_vidc = AV_ONCE_INIT;
62 ff_thread_once(&once_vidc, pcm_vidc_tableinit);
63 break;
64 }
65#endif
66 default:
67 break;
68 }
69#endif
70
72 avctx->block_align = avctx->ch_layout.nb_channels * avctx->bits_per_coded_sample / 8;
73 avctx->bit_rate = avctx->block_align * 8LL * avctx->sample_rate;
74
75 return 0;
76}
77
78/**
79 * Write PCM samples macro
80 * @param type Datatype of native machine format
81 * @param endian bytestream_put_xxx() suffix
82 * @param src Source pointer (variable name)
83 * @param dst Destination pointer (variable name)
84 * @param n Total number of samples (variable name)
85 * @param shift Bitshift (bits)
86 * @param offset Sample value offset
87 */
88#define ENCODE(type, endian, src, dst, n, shift, offset) \
89 samples_ ## type = (const type *) src; \
90 for (; n > 0; n--) { \
91 register type v = (*samples_ ## type++ >> shift) + offset; \
92 bytestream_put_ ## endian(&dst, v); \
93 }
94
95#define ENCODE_PLANAR(type, endian, dst, n, shift, offset) \
96 n /= avctx->ch_layout.nb_channels; \
97 for (c = 0; c < avctx->ch_layout.nb_channels; c++) { \
98 int i; \
99 samples_ ## type = (const type *) frame->extended_data[c]; \
100 for (i = n; i > 0; i--) { \
101 register type v = (*samples_ ## type++ >> shift) + offset; \
102 bytestream_put_ ## endian(&dst, v); \
103 } \
104 }
105
107 const AVFrame *frame, int *got_packet_ptr)
108{
109 int n, c, sample_size, ret;
110 const short *samples;
111 unsigned char *dst;
112 const uint8_t *samples_uint8_t;
113 const int16_t *samples_int16_t;
114 const int32_t *samples_int32_t;
115 const int64_t *samples_int64_t;
116 const uint16_t *samples_uint16_t;
117 const uint32_t *samples_uint32_t;
118
119 sample_size = av_get_bits_per_sample(avctx->codec->id) / 8;
120 n = frame->nb_samples * avctx->ch_layout.nb_channels;
121 samples = (const short *)frame->data[0];
122
123 if ((ret = ff_get_encode_buffer(avctx, avpkt, n * sample_size, 0)) < 0)
124 return ret;
125 dst = avpkt->data;
126
127 switch (avctx->codec->id) {
129 ENCODE(uint32_t, le32, samples, dst, n, 0, 0x80000000)
130 break;
132 ENCODE(uint32_t, be32, samples, dst, n, 0, 0x80000000)
133 break;
135 ENCODE(int32_t, le24, samples, dst, n, 8, 0)
136 break;
138 ENCODE_PLANAR(int32_t, le24, dst, n, 8, 0)
139 break;
141 ENCODE(int32_t, be24, samples, dst, n, 8, 0)
142 break;
144 ENCODE(uint32_t, le24, samples, dst, n, 8, 0x800000)
145 break;
147 ENCODE(uint32_t, be24, samples, dst, n, 8, 0x800000)
148 break;
150 for (; n > 0; n--) {
151 uint32_t tmp = ff_reverse[(*samples >> 8) & 0xff] +
152 (ff_reverse[*samples & 0xff] << 8);
153 tmp <<= 4; // sync flags would go here
154 bytestream_put_be24(&dst, tmp);
155 samples++;
156 }
157 break;
159 ENCODE(uint16_t, le16, samples, dst, n, 0, 0x8000)
160 break;
162 ENCODE(uint16_t, be16, samples, dst, n, 0, 0x8000)
163 break;
165 ENCODE(uint8_t, byte, samples, dst, n, 0, -128)
166 break;
168 ENCODE_PLANAR(uint8_t, byte, dst, n, 0, -128)
169 break;
170#if HAVE_BIGENDIAN
173 ENCODE(int64_t, le64, samples, dst, n, 0, 0)
174 break;
177 ENCODE(int32_t, le32, samples, dst, n, 0, 0)
178 break;
180 ENCODE_PLANAR(int32_t, le32, dst, n, 0, 0)
181 break;
183 ENCODE(int16_t, le16, samples, dst, n, 0, 0)
184 break;
186 ENCODE_PLANAR(int16_t, le16, dst, n, 0, 0)
187 break;
193#else
196 ENCODE(int64_t, be64, samples, dst, n, 0, 0)
197 break;
200 ENCODE(int32_t, be32, samples, dst, n, 0, 0)
201 break;
203 ENCODE(int16_t, be16, samples, dst, n, 0, 0)
204 break;
206 ENCODE_PLANAR(int16_t, be16, dst, n, 0, 0)
207 break;
213#endif /* HAVE_BIGENDIAN */
215 memcpy(dst, samples, n * sample_size);
216 break;
217#if HAVE_BIGENDIAN
219#else
222#endif /* HAVE_BIGENDIAN */
223 n /= avctx->ch_layout.nb_channels;
224 for (c = 0; c < avctx->ch_layout.nb_channels; c++) {
225 const uint8_t *src = frame->extended_data[c];
226 bytestream_put_buffer(&dst, src, n * sample_size);
227 }
228 break;
229#if CONFIG_PCM_ALAW_ENCODER
231 for (; n > 0; n--) {
232 int v = *samples++;
233 *dst++ = linear_to_alaw[(v + 32768) >> 2];
234 }
235 break;
236#endif
237#if CONFIG_PCM_MULAW_ENCODER
239 for (; n > 0; n--) {
240 int v = *samples++;
241 *dst++ = linear_to_ulaw[(v + 32768) >> 2];
242 }
243 break;
244#endif
245#if CONFIG_PCM_VIDC_ENCODER
247 for (; n > 0; n--) {
248 int v = *samples++;
249 *dst++ = linear_to_vidc[(v + 32768) >> 2];
250 }
251 break;
252#endif
253 default:
254 return -1;
255 }
256
257 *got_packet_ptr = 1;
258 return 0;
259}
260
261typedef struct PCMDecode {
263} PCMDecode;
264
266{
267 PCMDecode *s = avctx->priv_data;
268 static const struct {
269 enum AVCodecID codec_id;
270 int8_t sample_fmt;
271 uint8_t sample_size;
272 uint8_t bits_per_sample;
273 } codec_id_to_samplefmt[] = {
274 #define ENTRY(CODEC_ID, SAMPLE_FMT, BITS_PER_SAMPLE) \
275 { AV_CODEC_ID_PCM_ ## CODEC_ID, AV_SAMPLE_FMT_ ## SAMPLE_FMT, \
276 BITS_PER_SAMPLE / 8, BITS_PER_SAMPLE }
277 ENTRY(S8, U8, 8), ENTRY(S8_PLANAR, U8P, 8),
278 ENTRY(S16BE, S16, 16), ENTRY(S16BE_PLANAR, S16P, 16),
279 ENTRY(S16LE, S16, 16), ENTRY(S16LE_PLANAR, S16P, 16),
280 ENTRY(S24DAUD, S16, 24), ENTRY(S24BE, S32, 24),
281 ENTRY(S24LE, S32, 24), ENTRY(S24LE_PLANAR, S32P, 24),
282 ENTRY(S32BE, S32, 32), ENTRY(S32LE, S32, 32),
283 ENTRY(S32LE_PLANAR, S32P, 32),
284 ENTRY(S64BE, S64, 64), ENTRY(S64LE, S64, 64),
285 ENTRY(SGA, U8, 8), ENTRY(U8, U8, 8),
286 ENTRY(U16BE, S16, 16), ENTRY(U16LE, S16, 16),
287 ENTRY(U24BE, S32, 24), ENTRY(U24LE, S32, 24),
288 ENTRY(U32BE, S32, 32), ENTRY(U32LE, S32, 32),
289 ENTRY(F32BE, FLT, 32), ENTRY(F32LE, FLT, 32),
290 ENTRY(F64BE, DBL, 64), ENTRY(F64LE, DBL, 64),
291 { .codec_id = AV_CODEC_ID_PCM_LXF, .sample_fmt = AV_SAMPLE_FMT_S32P, .sample_size = 5 },
292 };
293
294 for (unsigned i = 0; i < FF_ARRAY_ELEMS(codec_id_to_samplefmt); ++i) {
295 if (codec_id_to_samplefmt[i].codec_id == avctx->codec_id) {
296 s->sample_size = codec_id_to_samplefmt[i].sample_size;
297 avctx->sample_fmt = codec_id_to_samplefmt[i].sample_fmt;
298 if (avctx->sample_fmt == AV_SAMPLE_FMT_S32)
299 avctx->bits_per_raw_sample = codec_id_to_samplefmt[i].bits_per_sample;
300 break;
301 }
302 av_assert1(i + 1 < FF_ARRAY_ELEMS(codec_id_to_samplefmt));
303 }
304
305 return 0;
306}
307
308typedef struct PCMScaleDecode {
310 void (*vector_fmul_scalar)(float *dst, const float *src, float mul,
311 int len);
312 float scale;
314
316{
317 PCMScaleDecode *s = avctx->priv_data;
318 AVFloatDSPContext *fdsp;
319
321 s->base.sample_size = 4;
322
323 if (avctx->bits_per_coded_sample < 1 || avctx->bits_per_coded_sample > 24)
324 return AVERROR_INVALIDDATA;
325
326 s->scale = 1. / (1 << (avctx->bits_per_coded_sample - 1));
327 fdsp = avpriv_float_dsp_alloc(0);
328 if (!fdsp)
329 return AVERROR(ENOMEM);
330 s->vector_fmul_scalar = fdsp->vector_fmul_scalar;
331 av_free(fdsp);
332
333 return 0;
334}
335
336typedef struct PCMLUTDecode {
338 int16_t table[256];
340
342{
343 PCMLUTDecode *s = avctx->priv_data;
344
345 switch (avctx->codec_id) {
346 default:
347 av_unreachable("pcm_lut_decode_init() only used with alaw, mulaw and vidc");
348#if CONFIG_PCM_ALAW_DECODER
350 for (int i = 0; i < 256; i++)
351 s->table[i] = alaw2linear(i);
352 break;
353#endif
354#if CONFIG_PCM_MULAW_DECODER
356 for (int i = 0; i < 256; i++)
357 s->table[i] = ulaw2linear(i);
358 break;
359#endif
360#if CONFIG_PCM_VIDC_DECODER
362 for (int i = 0; i < 256; i++)
363 s->table[i] = vidc2linear(i);
364 break;
365#endif
366 }
367
369 s->base.sample_size = 1;
370
371 return 0;
372}
373
374/**
375 * Read PCM samples macro
376 * @param size Data size of native machine format
377 * @param endian bytestream_get_xxx() endian suffix
378 * @param src Source pointer (variable name)
379 * @param dst Destination pointer (variable name)
380 * @param n Total number of samples (variable name)
381 * @param shift Bitshift (bits)
382 * @param offset Sample value offset
383 */
384#define DECODE(size, endian, src, dst, n, shift, offset) \
385 for (; n > 0; n--) { \
386 uint ## size ## _t v = bytestream_get_ ## endian(&src); \
387 AV_WN ## size ## A(dst, (uint ## size ## _t)(v - offset) << shift); \
388 dst += size / 8; \
389 }
390
391#define DECODE_PLANAR(size, endian, src, dst, n, shift, offset) \
392 n /= channels; \
393 for (c = 0; c < avctx->ch_layout.nb_channels; c++) { \
394 int i; \
395 dst = frame->extended_data[c]; \
396 for (i = n; i > 0; i--) { \
397 uint ## size ## _t v = bytestream_get_ ## endian(&src); \
398 AV_WN ## size ## A(dst, (uint ## size ##_t)(v - offset) << shift); \
399 dst += size / 8; \
400 } \
401 }
402
404 int *got_frame_ptr, AVPacket *avpkt)
405{
406 const uint8_t *src = avpkt->data;
407 int buf_size = avpkt->size;
408 PCMDecode *s = avctx->priv_data;
409 int channels = avctx->ch_layout.nb_channels;
410 int sample_size = s->sample_size;
411 int c, n, ret, samples_per_block;
412 uint8_t *samples;
413 int32_t *dst_int32_t;
414
415 samples_per_block = 1;
416 if (avctx->codec_id == AV_CODEC_ID_PCM_LXF) {
417 /* we process 40-bit blocks per channel for LXF */
418 samples_per_block = 2;
419 }
420
421 if (channels == 0) {
422 av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
423 return AVERROR(EINVAL);
424 }
425
426 if (avctx->codec_id != avctx->codec->id) {
427 av_log(avctx, AV_LOG_ERROR, "codec ids mismatch\n");
428 return AVERROR(EINVAL);
429 }
430
431 n = channels * sample_size;
432
433 if (n && buf_size % n) {
434 if (buf_size < n) {
435 av_log(avctx, AV_LOG_ERROR,
436 "Invalid PCM packet, data has size %d but at least a size of %d was expected\n",
437 buf_size, n);
438 return AVERROR_INVALIDDATA;
439 } else
440 buf_size -= buf_size % n;
441 }
442
443 n = buf_size / sample_size;
444
445 /* get output buffer */
446 frame->nb_samples = n * samples_per_block / channels;
447 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
448 return ret;
449 samples = frame->data[0];
450
451 switch (avctx->codec_id) {
453 DECODE(32, le32, src, samples, n, 0, 0x80000000)
454 break;
456 DECODE(32, be32, src, samples, n, 0, 0x80000000)
457 break;
459 DECODE(32, le24, src, samples, n, 8, 0)
460 break;
462 DECODE_PLANAR(32, le24, src, samples, n, 8, 0);
463 break;
465 DECODE(32, be24, src, samples, n, 8, 0)
466 break;
468 DECODE(32, le24, src, samples, n, 8, 0x800000)
469 break;
471 DECODE(32, be24, src, samples, n, 8, 0x800000)
472 break;
474 for (; n > 0; n--) {
475 uint32_t v = bytestream_get_be24(&src);
476 v >>= 4; // sync flags are here
477 AV_WN16A(samples, ff_reverse[(v >> 8) & 0xff] +
478 (ff_reverse[v & 0xff] << 8));
479 samples += 2;
480 }
481 break;
483 DECODE(16, le16, src, samples, n, 0, 0x8000)
484 break;
486 DECODE(16, be16, src, samples, n, 0, 0x8000)
487 break;
489 for (; n > 0; n--)
490 *samples++ = *src++ + 128;
491 break;
493 for (; n > 0; n--) {
494 int sign = *src >> 7;
495 int magn = *src & 0x7f;
496 *samples++ = sign ? 128 - magn : 128 + magn;
497 src++;
498 }
499 break;
501 n /= avctx->ch_layout.nb_channels;
502 for (c = 0; c < avctx->ch_layout.nb_channels; c++) {
503 int i;
504 samples = frame->extended_data[c];
505 for (i = n; i > 0; i--)
506 *samples++ = *src++ + 128;
507 }
508 break;
509#if HAVE_BIGENDIAN
512 DECODE(64, le64, src, samples, n, 0, 0)
513 break;
518 DECODE(32, le32, src, samples, n, 0, 0)
519 break;
521 DECODE_PLANAR(32, le32, src, samples, n, 0, 0);
522 break;
524 DECODE(16, le16, src, samples, n, 0, 0)
525 break;
527 DECODE_PLANAR(16, le16, src, samples, n, 0, 0);
528 break;
534#else
537 DECODE(64, be64, src, samples, n, 0, 0)
538 break;
541 DECODE(32, be32, src, samples, n, 0, 0)
542 break;
544 DECODE(16, be16, src, samples, n, 0, 0)
545 break;
547 DECODE_PLANAR(16, be16, src, samples, n, 0, 0);
548 break;
556#endif /* HAVE_BIGENDIAN */
558 memcpy(samples, src, n * sample_size);
559 break;
560#if HAVE_BIGENDIAN
562#else
565#endif /* HAVE_BIGENDIAN */
566 n /= avctx->ch_layout.nb_channels;
567 for (c = 0; c < avctx->ch_layout.nb_channels; c++) {
568 samples = frame->extended_data[c];
569 bytestream_get_buffer(&src, samples, n * sample_size);
570 }
571 break;
572#if CONFIG_PCM_ALAW_DECODER || CONFIG_PCM_MULAW_DECODER || \
573 CONFIG_PCM_VIDC_DECODER
577 const int16_t *const lut = ((PCMLUTDecode*)avctx->priv_data)->table;
578 int16_t *restrict samples_16 = (int16_t*)samples;
579
580 for (; n > 0; n--)
581 *samples_16++ = lut[*src++];
582 break;
583 }
584#endif
586 {
587 int i;
588 n /= channels;
589 for (c = 0; c < channels; c++) {
590 dst_int32_t = (int32_t *)frame->extended_data[c];
591 for (i = 0; i < n; i++) {
592 // extract low 20 bits and expand to 32 bits
593 *dst_int32_t++ = ((uint32_t)src[2]<<28) |
594 (src[1] << 20) |
595 (src[0] << 12) |
596 ((src[2] & 0x0F) << 8) |
597 src[1];
598 // extract high 20 bits and expand to 32 bits
599 *dst_int32_t++ = ((uint32_t)src[4]<<24) |
600 (src[3] << 16) |
601 ((src[2] & 0xF0) << 8) |
602 (src[4] << 4) |
603 (src[3] >> 4);
604 src += 5;
605 }
606 }
607 break;
608 }
609 default:
610 return -1;
611 }
612
613 if (avctx->codec_id == AV_CODEC_ID_PCM_F16LE ||
615 PCMScaleDecode *s2 = avctx->priv_data;
616 s2->vector_fmul_scalar((float *)frame->extended_data[0],
617 (const float *)frame->extended_data[0],
618 s2->scale, FFALIGN(frame->nb_samples * avctx->ch_layout.nb_channels, 4));
619 }
620
621 *got_frame_ptr = 1;
622
623 return buf_size;
624}
625
626#define PCM_ENCODER_0(id_, sample_fmt_, name_, long_name_)
627#define PCM_ENCODER_1(id_, sample_fmt_, name_, long_name_) \
628const FFCodec ff_ ## name_ ## _encoder = { \
629 .p.name = #name_, \
630 CODEC_LONG_NAME(long_name_), \
631 .p.type = AVMEDIA_TYPE_AUDIO, \
632 .p.id = id_, \
633 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_VARIABLE_FRAME_SIZE | \
634 AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE, \
635 .init = pcm_encode_init, \
636 FF_CODEC_ENCODE_CB(pcm_encode_frame), \
637 CODEC_SAMPLEFMTS(sample_fmt_), \
638}
639
640#define PCM_ENCODER_2(cf, id, sample_fmt, name, long_name) \
641 PCM_ENCODER_ ## cf(id, sample_fmt, name, long_name)
642#define PCM_ENCODER_3(cf, id, sample_fmt, name, long_name) \
643 PCM_ENCODER_2(cf, id, sample_fmt, name, long_name)
644#define PCM_ENCODER(id, sample_fmt, name, long_name) \
645 PCM_ENCODER_3(CONFIG_PCM_ ## id ## _ENCODER, AV_CODEC_ID_PCM_ ## id, \
646 AV_SAMPLE_FMT_ ## sample_fmt, pcm_ ## name, long_name)
647
648#define PCM_DECODER_0(id, sample_fmt, name, long_name, Context, init_func)
649#define PCM_DECODER_1(id_, sample_fmt, name_, long_name, Context, init_func)\
650const FFCodec ff_ ## name_ ## _decoder = { \
651 .p.name = #name_, \
652 CODEC_LONG_NAME(long_name), \
653 .p.type = AVMEDIA_TYPE_AUDIO, \
654 .p.id = id_, \
655 .priv_data_size = sizeof(Context), \
656 .init = init_func, \
657 FF_CODEC_DECODE_CB(pcm_decode_frame), \
658 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_PARAM_CHANGE, \
659}
660
661#define PCM_DECODER_2(cf, id, sample_fmt, name, long_name, Context, init_func) \
662 PCM_DECODER_ ## cf(id, sample_fmt, name, long_name, Context, init_func)
663#define PCM_DECODER_3(cf, id, sample_fmt, name, long_name, Context, init_func) \
664 PCM_DECODER_2(cf, id, sample_fmt, name, long_name, Context, init_func)
665#define PCM_DEC_EXT(id, sample_fmt, name, long_name, Context, init_func) \
666 PCM_DECODER_3(CONFIG_PCM_ ## id ## _DECODER, AV_CODEC_ID_PCM_ ## id, \
667 AV_SAMPLE_FMT_ ## sample_fmt, pcm_ ## name, long_name, \
668 Context, init_func)
669
670#define PCM_DECODER(id, sample_fmt, name, long_name) \
671 PCM_DEC_EXT(id, sample_fmt, name, long_name, PCMDecode, pcm_decode_init)
672
673#define PCM_CODEC(id, sample_fmt_, name, long_name_) \
674 PCM_ENCODER(id, sample_fmt_, name, long_name_); \
675 PCM_DECODER(id, sample_fmt_, name, long_name_)
676
677#define PCM_CODEC_EXT(id, sample_fmt, name, long_name, DecContext, dec_init_func) \
678 PCM_DEC_EXT(id, sample_fmt, name, long_name, DecContext, dec_init_func); \
679 PCM_ENCODER(id, sample_fmt, name, long_name)
680
681/* Note: Do not forget to add new entries to the Makefile and
682 * to the table in pcm_decode_init() as well. */
683// AV_CODEC_ID_* pcm_* name
684// AV_SAMPLE_FMT_* long name DecodeContext decode init func
685PCM_CODEC_EXT(ALAW, S16, alaw, "PCM A-law / G.711 A-law", PCMLUTDecode, pcm_lut_decode_init);
686PCM_DEC_EXT (F16LE, FLT, f16le, "PCM 16.8 floating point little-endian", PCMScaleDecode, pcm_scale_decode_init);
687PCM_DEC_EXT (F24LE, FLT, f24le, "PCM 24.0 floating point little-endian", PCMScaleDecode, pcm_scale_decode_init);
688PCM_CODEC (F32BE, FLT, f32be, "PCM 32-bit floating point big-endian");
689PCM_CODEC (F32LE, FLT, f32le, "PCM 32-bit floating point little-endian");
690PCM_CODEC (F64BE, DBL, f64be, "PCM 64-bit floating point big-endian");
691PCM_CODEC (F64LE, DBL, f64le, "PCM 64-bit floating point little-endian");
692PCM_DECODER (LXF, S32P,lxf, "PCM signed 20-bit little-endian planar");
693PCM_CODEC_EXT(MULAW, S16, mulaw, "PCM mu-law / G.711 mu-law", PCMLUTDecode, pcm_lut_decode_init);
694PCM_CODEC (S8, U8, s8, "PCM signed 8-bit");
695PCM_CODEC (S8_PLANAR, U8P, s8_planar, "PCM signed 8-bit planar");
696PCM_CODEC (S16BE, S16, s16be, "PCM signed 16-bit big-endian");
697PCM_CODEC (S16BE_PLANAR, S16P,s16be_planar, "PCM signed 16-bit big-endian planar");
698PCM_CODEC (S16LE, S16, s16le, "PCM signed 16-bit little-endian");
699PCM_CODEC (S16LE_PLANAR, S16P,s16le_planar, "PCM signed 16-bit little-endian planar");
700PCM_CODEC (S24BE, S32, s24be, "PCM signed 24-bit big-endian");
701PCM_CODEC (S24DAUD, S16, s24daud, "PCM D-Cinema audio signed 24-bit");
702PCM_CODEC (S24LE, S32, s24le, "PCM signed 24-bit little-endian");
703PCM_CODEC (S24LE_PLANAR, S32P,s24le_planar, "PCM signed 24-bit little-endian planar");
704PCM_CODEC (S32BE, S32, s32be, "PCM signed 32-bit big-endian");
705PCM_CODEC (S32LE, S32, s32le, "PCM signed 32-bit little-endian");
706PCM_CODEC (S32LE_PLANAR, S32P,s32le_planar, "PCM signed 32-bit little-endian planar");
707PCM_CODEC (U8, U8, u8, "PCM unsigned 8-bit");
708PCM_CODEC (U16BE, S16, u16be, "PCM unsigned 16-bit big-endian");
709PCM_CODEC (U16LE, S16, u16le, "PCM unsigned 16-bit little-endian");
710PCM_CODEC (U24BE, S32, u24be, "PCM unsigned 24-bit big-endian");
711PCM_CODEC (U24LE, S32, u24le, "PCM unsigned 24-bit little-endian");
712PCM_CODEC (U32BE, S32, u32be, "PCM unsigned 32-bit big-endian");
713PCM_CODEC (U32LE, S32, u32le, "PCM unsigned 32-bit little-endian");
714PCM_CODEC (S64BE, S64, s64be, "PCM signed 64-bit big-endian");
715PCM_CODEC (S64LE, S64, s64le, "PCM signed 64-bit little-endian");
716PCM_CODEC_EXT(VIDC, S16, vidc, "PCM Archimedes VIDC", PCMLUTDecode, pcm_lut_decode_init);
717PCM_DECODER (SGA, U8, sga, "PCM SGA");
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
channels
Definition aptx.h:31
int32_t
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition avassert.h:58
#define av_unreachable(msg)
Asserts that are used as compiler optimization hints depending upon ASSERT_LEVEL and NBDEBUG.
Definition avassert.h:109
Libavcodec external API header.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL be16
Definition bytestream.h:98
static av_always_inline unsigned int bytestream_get_buffer(const uint8_t **b, uint8_t *dst, unsigned int size)
Definition bytestream.h:363
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL be24
Definition bytestream.h:97
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
Definition bytestream.h:372
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL be64
Definition bytestream.h:95
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL le16
Definition bytestream.h:94
uint64_t_TMPL AV_WL64 unsigned int_TMPL le32
Definition bytestream.h:92
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL le24
Definition bytestream.h:93
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL be32
Definition bytestream.h:96
uint64_t_TMPL le64
Definition bytestream.h:91
static const uint32_t S8[256]
Definition cast5.c:328
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
long long int64_t
Definition coverity.c:34
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition decode.c:1777
static AVFrame * frame
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
Definition encode.c:106
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
Definition utils.c:556
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition codec_id.h:47
@ AV_CODEC_ID_PCM_F24LE
Definition codec_id.h:364
@ AV_CODEC_ID_PCM_F32LE
Definition codec_id.h:351
@ AV_CODEC_ID_PCM_S24BE
Definition codec_id.h:343
@ AV_CODEC_ID_PCM_S64BE
Definition codec_id.h:362
@ AV_CODEC_ID_PCM_S16BE_PLANAR
Definition codec_id.h:360
@ AV_CODEC_ID_PCM_U8
Definition codec_id.h:335
@ AV_CODEC_ID_PCM_S16LE
Definition codec_id.h:330
@ AV_CODEC_ID_PCM_S32LE_PLANAR
Definition codec_id.h:359
@ AV_CODEC_ID_PCM_F16LE
Definition codec_id.h:363
@ AV_CODEC_ID_PCM_F32BE
Definition codec_id.h:350
@ AV_CODEC_ID_PCM_S24LE_PLANAR
Definition codec_id.h:358
@ AV_CODEC_ID_PCM_S16BE
Definition codec_id.h:331
@ AV_CODEC_ID_PCM_S24LE
Definition codec_id.h:342
@ AV_CODEC_ID_PCM_U24BE
Definition codec_id.h:345
@ AV_CODEC_ID_PCM_S24DAUD
Definition codec_id.h:346
@ AV_CODEC_ID_PCM_S32LE
Definition codec_id.h:338
@ AV_CODEC_ID_PCM_S8
Definition codec_id.h:334
@ AV_CODEC_ID_PCM_U32LE
Definition codec_id.h:340
@ AV_CODEC_ID_PCM_VIDC
Definition codec_id.h:365
@ AV_CODEC_ID_PCM_ALAW
Definition codec_id.h:337
@ AV_CODEC_ID_PCM_F64LE
Definition codec_id.h:353
@ AV_CODEC_ID_PCM_U16BE
Definition codec_id.h:333
@ AV_CODEC_ID_PCM_LXF
Definition codec_id.h:355
@ AV_CODEC_ID_PCM_SGA
Definition codec_id.h:366
@ AV_CODEC_ID_PCM_S64LE
Definition codec_id.h:361
@ AV_CODEC_ID_PCM_F64BE
Definition codec_id.h:352
@ AV_CODEC_ID_PCM_S32BE
Definition codec_id.h:339
@ AV_CODEC_ID_PCM_S16LE_PLANAR
Definition codec_id.h:348
@ AV_CODEC_ID_PCM_U24LE
Definition codec_id.h:344
@ AV_CODEC_ID_PCM_U16LE
Definition codec_id.h:332
@ AV_CODEC_ID_PCM_S8_PLANAR
Definition codec_id.h:357
@ AV_CODEC_ID_PCM_U32BE
Definition codec_id.h:341
@ AV_CODEC_ID_PCM_MULAW
Definition codec_id.h:336
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
@ AV_SAMPLE_FMT_FLT
float
Definition samplefmt.h:60
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
Definition samplefmt.h:65
@ AV_SAMPLE_FMT_S32
signed 32 bits
Definition samplefmt.h:59
@ AV_SAMPLE_FMT_S16
signed 16 bits
Definition samplefmt.h:58
#define AV_WN16A(p, v)
#define ENTRY(CODEC_ID, SAMPLE_FMT, BITS_PER_SAMPLE)
av_unused static av_cold int pcm_scale_decode_init(AVCodecContext *avctx)
Definition pcm.c:315
av_unused static av_cold int pcm_lut_decode_init(AVCodecContext *avctx)
Definition pcm.c:341
av_unused static av_cold int pcm_encode_init(AVCodecContext *avctx)
Definition pcm.c:41
#define PCM_DEC_EXT(id, sample_fmt, name, long_name, Context, init_func)
Definition pcm.c:665
#define ENCODE_PLANAR(type, endian, dst, n, shift, offset)
Definition pcm.c:95
av_unused static av_cold int pcm_decode_init(AVCodecContext *avctx)
Definition pcm.c:265
#define DECODE(size, endian, src, dst, n, shift, offset)
Read PCM samples macro.
Definition pcm.c:384
static av_unused int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Definition pcm.c:106
static int pcm_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
Definition pcm.c:403
#define PCM_CODEC(id, sample_fmt_, name, long_name_)
Definition pcm.c:673
#define ENCODE(type, endian, src, dst, n, shift, offset)
Write PCM samples macro.
Definition pcm.c:88
#define PCM_CODEC_EXT(id, sample_fmt, name, long_name, DecContext, dec_init_func)
Definition pcm.c:677
#define PCM_DECODER(id, sample_fmt, name, long_name)
Definition pcm.c:670
#define DECODE_PLANAR(size, endian, src, dst, n, shift, offset)
Definition pcm.c:391
Macro definitions for various function/variable attributes.
#define av_unused
Definition attributes.h:164
#define av_cold
Definition attributes.h:117
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
Definition float_dsp.c:135
const uint8_t ff_reverse[256]
Definition reverse.c:23
#define AVOnce
Definition thread.h:202
static int ff_thread_once(char *control, void(*routine)(void))
Definition thread.h:205
#define AV_ONCE_INIT
Definition thread.h:203
#define FFALIGN(x, a)
Definition macros.h:78
Memory handling functions.
#define FF_ARRAY_ELEMS(a)
int nb_channels
Number of channels in this layout.
main external API structure.
Definition avcodec.h:443
AVChannelLayout ch_layout
Audio channel layout.
Definition avcodec.h:1055
enum AVSampleFormat sample_fmt
audio sample format
Definition avcodec.h:1047
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
Definition avcodec.h:1564
int64_t bit_rate
the average bitrate
Definition avcodec.h:493
const struct AVCodec * codec
Definition avcodec.h:452
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition avcodec.h:1571
int sample_rate
samples per second
Definition avcodec.h:1040
enum AVCodecID codec_id
Definition avcodec.h:453
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs.
Definition avcodec.h:1075
void * priv_data
Definition avcodec.h:470
enum AVCodecID id
Definition codec.h:189
void(* vector_fmul_scalar)(float *dst, const float *src, float mul, int len)
Multiply a vector of floats by a scalar float.
Definition float_dsp.h:85
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
This structure stores compressed data.
Definition packet.h:580
int size
Definition packet.h:604
uint8_t * data
Definition packet.h:603
int sample_size
Definition pcm.c:262
int16_t table[256]
Definition pcm.c:338
PCMDecode base
Definition pcm.c:337
void(* vector_fmul_scalar)(float *dst, const float *src, float mul, int len)
Definition pcm.c:310
float scale
Definition pcm.c:312
PCMDecode base
Definition pcm.c:309
#define av_free(p)
#define av_log(a,...)
static uint8_t tmp[40]
Definition aes_ctr.c:52
#define src
Definition vp8dsp.c:248
enum AVCodecID codec_id
int len
static double c[64]