FFmpeg
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"
29 #include "libavutil/attributes.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
46  case AV_CODEC_ID_PCM_ALAW: {
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
53  case AV_CODEC_ID_PCM_MULAW: {
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
60  case AV_CODEC_ID_PCM_VIDC: {
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;
164  case AV_CODEC_ID_PCM_S8:
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 */
214  case AV_CODEC_ID_PCM_U8:
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 
261 typedef 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 
308 typedef 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 
320  avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
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 
336 typedef struct PCMLUTDecode {
338  int16_t table[256];
339 } PCMLUTDecode;
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 
368  avctx->sample_fmt = AV_SAMPLE_FMT_S16;
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;
488  case AV_CODEC_ID_PCM_S8:
489  for (; n > 0; n--)
490  *samples++ = *src++ + 128;
491  break;
492  case AV_CODEC_ID_PCM_SGA:
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 */
557  case AV_CODEC_ID_PCM_U8:
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
576  case AV_CODEC_ID_PCM_VIDC: {
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
585  case AV_CODEC_ID_PCM_LXF:
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 ||
614  avctx->codec_id == AV_CODEC_ID_PCM_F24LE) {
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_) \
628 const 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)\
650 const 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
685 PCM_CODEC_EXT(ALAW, S16, alaw, "PCM A-law / G.711 A-law", PCMLUTDecode, pcm_lut_decode_init);
686 PCM_DEC_EXT (F16LE, FLT, f16le, "PCM 16.8 floating point little-endian", PCMScaleDecode, pcm_scale_decode_init);
687 PCM_DEC_EXT (F24LE, FLT, f24le, "PCM 24.0 floating point little-endian", PCMScaleDecode, pcm_scale_decode_init);
688 PCM_CODEC (F32BE, FLT, f32be, "PCM 32-bit floating point big-endian");
689 PCM_CODEC (F32LE, FLT, f32le, "PCM 32-bit floating point little-endian");
690 PCM_CODEC (F64BE, DBL, f64be, "PCM 64-bit floating point big-endian");
691 PCM_CODEC (F64LE, DBL, f64le, "PCM 64-bit floating point little-endian");
692 PCM_DECODER (LXF, S32P,lxf, "PCM signed 20-bit little-endian planar");
693 PCM_CODEC_EXT(MULAW, S16, mulaw, "PCM mu-law / G.711 mu-law", PCMLUTDecode, pcm_lut_decode_init);
694 PCM_CODEC (S8, U8, s8, "PCM signed 8-bit");
695 PCM_CODEC (S8_PLANAR, U8P, s8_planar, "PCM signed 8-bit planar");
696 PCM_CODEC (S16BE, S16, s16be, "PCM signed 16-bit big-endian");
697 PCM_CODEC (S16BE_PLANAR, S16P,s16be_planar, "PCM signed 16-bit big-endian planar");
698 PCM_CODEC (S16LE, S16, s16le, "PCM signed 16-bit little-endian");
699 PCM_CODEC (S16LE_PLANAR, S16P,s16le_planar, "PCM signed 16-bit little-endian planar");
700 PCM_CODEC (S24BE, S32, s24be, "PCM signed 24-bit big-endian");
701 PCM_CODEC (S24DAUD, S16, s24daud, "PCM D-Cinema audio signed 24-bit");
702 PCM_CODEC (S24LE, S32, s24le, "PCM signed 24-bit little-endian");
703 PCM_CODEC (S24LE_PLANAR, S32P,s24le_planar, "PCM signed 24-bit little-endian planar");
704 PCM_CODEC (S32BE, S32, s32be, "PCM signed 32-bit big-endian");
705 PCM_CODEC (S32LE, S32, s32le, "PCM signed 32-bit little-endian");
706 PCM_CODEC (S32LE_PLANAR, S32P,s32le_planar, "PCM signed 32-bit little-endian planar");
707 PCM_CODEC (U8, U8, u8, "PCM unsigned 8-bit");
708 PCM_CODEC (U16BE, S16, u16be, "PCM unsigned 16-bit big-endian");
709 PCM_CODEC (U16LE, S16, u16le, "PCM unsigned 16-bit little-endian");
710 PCM_CODEC (U24BE, S32, u24be, "PCM unsigned 24-bit big-endian");
711 PCM_CODEC (U24LE, S32, u24le, "PCM unsigned 24-bit little-endian");
712 PCM_CODEC (U32BE, S32, u32be, "PCM unsigned 32-bit big-endian");
713 PCM_CODEC (U32LE, S32, u32le, "PCM unsigned 32-bit little-endian");
714 PCM_CODEC (S64BE, S64, s64be, "PCM signed 64-bit big-endian");
715 PCM_CODEC (S64LE, S64, s64le, "PCM signed 64-bit little-endian");
716 PCM_CODEC_EXT(VIDC, S16, vidc, "PCM Archimedes VIDC", PCMLUTDecode, pcm_lut_decode_init);
717 PCM_DECODER (SGA, U8, sga, "PCM SGA");
AV_CODEC_ID_PCM_S16LE
@ AV_CODEC_ID_PCM_S16LE
Definition: codec_id.h:339
PCM_CODEC_EXT
#define PCM_CODEC_EXT(id, sample_fmt, name, long_name, DecContext, dec_init_func)
Definition: pcm.c:677
PCM_CODEC
#define PCM_CODEC(id, sample_fmt_, name, long_name_)
Definition: pcm.c:673
AV_CODEC_ID_PCM_F32BE
@ AV_CODEC_ID_PCM_F32BE
Definition: codec_id.h:359
le32
uint64_t_TMPL AV_WL64 unsigned int_TMPL le32
Definition: bytestream.h:92
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
ENCODE
#define ENCODE(type, endian, src, dst, n, shift, offset)
Write PCM samples macro.
Definition: pcm.c:88
pcm_tablegen.h
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:1040
U8
@ U8
Definition: sw_ops.c:39
thread.h
int64_t
long long int64_t
Definition: coverity.c:34
av_unused
#define av_unused
Definition: attributes.h:164
AV_CODEC_ID_PCM_S32LE_PLANAR
@ AV_CODEC_ID_PCM_S32LE_PLANAR
Definition: codec_id.h:368
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:459
pcm_scale_decode_init
av_unused static av_cold int pcm_scale_decode_init(AVCodecContext *avctx)
Definition: pcm.c:315
AVPacket::data
uint8_t * data
Definition: packet.h:595
AV_CODEC_ID_PCM_S16BE_PLANAR
@ AV_CODEC_ID_PCM_S16BE_PLANAR
Definition: codec_id.h:369
encode.h
ff_reverse
const uint8_t ff_reverse[256]
Definition: reverse.c:23
AV_SAMPLE_FMT_S32P
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
Definition: samplefmt.h:65
AV_CODEC_ID_PCM_U24LE
@ AV_CODEC_ID_PCM_U24LE
Definition: codec_id.h:353
AV_CODEC_ID_PCM_SGA
@ AV_CODEC_ID_PCM_SGA
Definition: codec_id.h:375
reverse.h
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:329
AV_CODEC_ID_PCM_S16LE_PLANAR
@ AV_CODEC_ID_PCM_S16LE_PLANAR
Definition: codec_id.h:357
AV_CODEC_ID_PCM_S64LE
@ AV_CODEC_ID_PCM_S64LE
Definition: codec_id.h:370
pcm_decode_init
av_unused static av_cold int pcm_decode_init(AVCodecContext *avctx)
Definition: pcm.c:265
AVCodecContext::codec
const struct AVCodec * codec
Definition: avcodec.h:452
AV_CODEC_ID_PCM_S16BE
@ AV_CODEC_ID_PCM_S16BE
Definition: codec_id.h:340
PCMScaleDecode::base
PCMDecode base
Definition: pcm.c:309
PCMScaleDecode::scale
float scale
Definition: pcm.c:312
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:1055
be24
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
le24
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL le24
Definition: bytestream.h:93
PCMLUTDecode
Definition: pcm.c:336
PCMScaleDecode::vector_fmul_scalar
void(* vector_fmul_scalar)(float *dst, const float *src, float mul, int len)
Definition: pcm.c:310
PCM_DECODER
#define PCM_DECODER(id, sample_fmt, name, long_name)
Definition: pcm.c:670
av_get_bits_per_sample
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
Definition: utils.c:549
AV_CODEC_ID_PCM_S8
@ AV_CODEC_ID_PCM_S8
Definition: codec_id.h:343
ff_thread_once
static int ff_thread_once(char *control, void(*routine)(void))
Definition: thread.h:205
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:119
s
#define s(width, name)
Definition: cbs_vp9.c:198
AV_CODEC_ID_PCM_LXF
@ AV_CODEC_ID_PCM_LXF
Definition: codec_id.h:364
AVCodecContext::bits_per_raw_sample
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:1571
AV_CODEC_ID_PCM_F24LE
@ AV_CODEC_ID_PCM_F24LE
Definition: codec_id.h:373
channels
channels
Definition: aptx.h:31
decode.h
AV_WN16A
#define AV_WN16A(p, v)
Definition: intreadwrite.h:530
AV_CODEC_ID_PCM_MULAW
@ AV_CODEC_ID_PCM_MULAW
Definition: codec_id.h:345
AV_CODEC_ID_PCM_U16BE
@ AV_CODEC_ID_PCM_U16BE
Definition: codec_id.h:342
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:410
tmp
static uint8_t tmp[40]
Definition: aes_ctr.c:52
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:453
if
if(ret)
Definition: filter_design.txt:179
pcm_encode_frame
static av_unused int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Definition: pcm.c:106
AV_CODEC_ID_PCM_ALAW
@ AV_CODEC_ID_PCM_ALAW
Definition: codec_id.h:346
AV_ONCE_INIT
#define AV_ONCE_INIT
Definition: thread.h:203
pcm_lut_decode_init
av_unused static av_cold int pcm_lut_decode_init(AVCodecContext *avctx)
Definition: pcm.c:341
AV_CODEC_ID_PCM_U24BE
@ AV_CODEC_ID_PCM_U24BE
Definition: codec_id.h:354
AVFloatDSPContext::vector_fmul_scalar
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
ENTRY
#define ENTRY(CODEC_ID, SAMPLE_FMT, BITS_PER_SAMPLE)
av_unreachable
#define av_unreachable(msg)
Asserts that are used as compiler optimization hints depending upon ASSERT_LEVEL and NBDEBUG.
Definition: avassert.h:116
AV_CODEC_ID_PCM_U32BE
@ AV_CODEC_ID_PCM_U32BE
Definition: codec_id.h:350
AVCodecContext::bit_rate
int64_t bit_rate
the average bitrate
Definition: avcodec.h:493
AV_CODEC_ID_PCM_S64BE
@ AV_CODEC_ID_PCM_S64BE
Definition: codec_id.h:371
be64
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
DECODE_PLANAR
#define DECODE_PLANAR(size, endian, src, dst, n, shift, offset)
Definition: pcm.c:391
pcm_decode_frame
static int pcm_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
Definition: pcm.c:403
be32
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
AVOnce
#define AVOnce
Definition: thread.h:202
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
AV_CODEC_ID_PCM_S24LE_PLANAR
@ AV_CODEC_ID_PCM_S24LE_PLANAR
Definition: codec_id.h:367
float_dsp.h
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:49
AV_CODEC_ID_PCM_VIDC
@ AV_CODEC_ID_PCM_VIDC
Definition: codec_id.h:374
AV_CODEC_ID_PCM_S24LE
@ AV_CODEC_ID_PCM_S24LE
Definition: codec_id.h:351
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1768
AVPacket::size
int size
Definition: packet.h:596
codec_internal.h
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:87
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:424
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1047
AVFloatDSPContext
Definition: float_dsp.h:24
DECODE
#define DECODE(size, endian, src, dst, n, shift, offset)
Read PCM samples macro.
Definition: pcm.c:384
PCMLUTDecode::table
int16_t table[256]
Definition: pcm.c:338
ENCODE_PLANAR
#define ENCODE_PLANAR(type, endian, dst, n, shift, offset)
Definition: pcm.c:95
attributes.h
AVCodec::id
enum AVCodecID id
Definition: codec.h:186
PCMLUTDecode::base
PCMDecode base
Definition: pcm.c:337
AVCodecContext::bits_per_coded_sample
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
Definition: avcodec.h:1564
bytestream_put_buffer
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
Definition: bytestream.h:372
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:58
AV_CODEC_ID_PCM_F64BE
@ AV_CODEC_ID_PCM_F64BE
Definition: codec_id.h:361
AV_CODEC_ID_PCM_S32BE
@ AV_CODEC_ID_PCM_S32BE
Definition: codec_id.h:348
AV_SAMPLE_FMT_S16
@ AV_SAMPLE_FMT_S16
signed 16 bits
Definition: samplefmt.h:58
le64
uint64_t_TMPL le64
Definition: bytestream.h:91
AV_CODEC_ID_PCM_F16LE
@ AV_CODEC_ID_PCM_F16LE
Definition: codec_id.h:372
len
int len
Definition: vorbis_enc_data.h:426
avcodec.h
bytestream_get_buffer
static av_always_inline unsigned int bytestream_get_buffer(const uint8_t **b, uint8_t *dst, unsigned int size)
Definition: bytestream.h:363
ret
ret
Definition: filter_design.txt:187
AVCodecContext::block_align
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
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:265
be16
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
PCMDecode
Definition: pcm.c:261
le16
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL le16
Definition: bytestream.h:94
PCM_DEC_EXT
#define PCM_DEC_EXT(id, sample_fmt, name, long_name, Context, init_func)
Definition: pcm.c:665
AVCodecContext
main external API structure.
Definition: avcodec.h:443
ff_get_encode_buffer
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
Definition: encode.c:105
AV_CODEC_ID_PCM_U32LE
@ AV_CODEC_ID_PCM_U32LE
Definition: codec_id.h:349
samples
Filter the word “frame” indicates either a video frame or a group of audio samples
Definition: filter_design.txt:8
AV_CODEC_ID_PCM_S32LE
@ AV_CODEC_ID_PCM_S32LE
Definition: codec_id.h:347
mem.h
AV_CODEC_ID_PCM_U8
@ AV_CODEC_ID_PCM_U8
Definition: codec_id.h:344
pcm_encode_init
av_unused static av_cold int pcm_encode_init(AVCodecContext *avctx)
Definition: pcm.c:41
AV_CODEC_ID_PCM_S24DAUD
@ AV_CODEC_ID_PCM_S24DAUD
Definition: codec_id.h:355
AV_CODEC_ID_PCM_F64LE
@ AV_CODEC_ID_PCM_F64LE
Definition: codec_id.h:362
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:470
AVPacket
This structure stores compressed data.
Definition: packet.h:572
avpriv_float_dsp_alloc
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
Definition: float_dsp.c:135
PCMScaleDecode
Definition: pcm.c:308
AV_CODEC_ID_PCM_S8_PLANAR
@ AV_CODEC_ID_PCM_S8_PLANAR
Definition: codec_id.h:366
int32_t
int32_t
Definition: audioconvert.c:56
bytestream.h
AV_CODEC_ID_PCM_U16LE
@ AV_CODEC_ID_PCM_U16LE
Definition: codec_id.h:341
S8
static const uint32_t S8[256]
Definition: cast5.c:328
AV_CODEC_ID_PCM_F32LE
@ AV_CODEC_ID_PCM_F32LE
Definition: codec_id.h:360
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
PCMDecode::sample_size
int sample_size
Definition: pcm.c:262
AV_SAMPLE_FMT_S32
@ AV_SAMPLE_FMT_S32
signed 32 bits
Definition: samplefmt.h:59
AV_CODEC_ID_PCM_S24BE
@ AV_CODEC_ID_PCM_S24BE
Definition: codec_id.h:352
AV_SAMPLE_FMT_FLT
@ AV_SAMPLE_FMT_FLT
float
Definition: samplefmt.h:60
src
#define src
Definition: vp8dsp.c:248