FFmpeg  4.4.6
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 "libavutil/attributes.h"
29 #include "libavutil/float_dsp.h"
30 #include "libavutil/thread.h"
31 #include "avcodec.h"
32 #include "bytestream.h"
33 #include "internal.h"
34 #include "mathops.h"
35 #include "pcm_tablegen.h"
36 
38 {
39  avctx->frame_size = 0;
40 #if !CONFIG_HARDCODED_TABLES
41  switch (avctx->codec->id) {
42 #define INIT_ONCE(id, name) \
43  case AV_CODEC_ID_PCM_ ## id: \
44  if (CONFIG_PCM_ ## id ## _ENCODER) { \
45  static AVOnce init_static_once = AV_ONCE_INIT; \
46  ff_thread_once(&init_static_once, pcm_ ## name ## _tableinit); \
47  } \
48  break
49  INIT_ONCE(ALAW, alaw);
50  INIT_ONCE(MULAW, ulaw);
51  INIT_ONCE(VIDC, vidc);
52  default:
53  break;
54  }
55 #endif
56 
58  avctx->block_align = avctx->channels * avctx->bits_per_coded_sample / 8;
59  avctx->bit_rate = avctx->block_align * 8LL * avctx->sample_rate;
60 
61  return 0;
62 }
63 
64 /**
65  * Write PCM samples macro
66  * @param type Datatype of native machine format
67  * @param endian bytestream_put_xxx() suffix
68  * @param src Source pointer (variable name)
69  * @param dst Destination pointer (variable name)
70  * @param n Total number of samples (variable name)
71  * @param shift Bitshift (bits)
72  * @param offset Sample value offset
73  */
74 #define ENCODE(type, endian, src, dst, n, shift, offset) \
75  samples_ ## type = (const type *) src; \
76  for (; n > 0; n--) { \
77  register type v = (*samples_ ## type++ >> shift) + offset; \
78  bytestream_put_ ## endian(&dst, v); \
79  }
80 
81 #define ENCODE_PLANAR(type, endian, dst, n, shift, offset) \
82  n /= avctx->channels; \
83  for (c = 0; c < avctx->channels; c++) { \
84  int i; \
85  samples_ ## type = (const type *) frame->extended_data[c]; \
86  for (i = n; i > 0; i--) { \
87  register type v = (*samples_ ## type++ >> shift) + offset; \
88  bytestream_put_ ## endian(&dst, v); \
89  } \
90  }
91 
92 static int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
93  const AVFrame *frame, int *got_packet_ptr)
94 {
95  int n, c, sample_size, v, ret;
96  const short *samples;
97  unsigned char *dst;
98  const uint8_t *samples_uint8_t;
99  const int16_t *samples_int16_t;
100  const int32_t *samples_int32_t;
101  const int64_t *samples_int64_t;
102  const uint16_t *samples_uint16_t;
103  const uint32_t *samples_uint32_t;
104 
105  sample_size = av_get_bits_per_sample(avctx->codec->id) / 8;
106  n = frame->nb_samples * avctx->channels;
107  samples = (const short *)frame->data[0];
108 
109  if ((ret = ff_alloc_packet2(avctx, avpkt, n * sample_size, n * sample_size)) < 0)
110  return ret;
111  dst = avpkt->data;
112 
113  switch (avctx->codec->id) {
115  ENCODE(uint32_t, le32, samples, dst, n, 0, 0x80000000)
116  break;
118  ENCODE(uint32_t, be32, samples, dst, n, 0, 0x80000000)
119  break;
121  ENCODE(int32_t, le24, samples, dst, n, 8, 0)
122  break;
124  ENCODE_PLANAR(int32_t, le24, dst, n, 8, 0)
125  break;
127  ENCODE(int32_t, be24, samples, dst, n, 8, 0)
128  break;
130  ENCODE(uint32_t, le24, samples, dst, n, 8, 0x800000)
131  break;
133  ENCODE(uint32_t, be24, samples, dst, n, 8, 0x800000)
134  break;
136  for (; n > 0; n--) {
137  uint32_t tmp = ff_reverse[(*samples >> 8) & 0xff] +
138  (ff_reverse[*samples & 0xff] << 8);
139  tmp <<= 4; // sync flags would go here
140  bytestream_put_be24(&dst, tmp);
141  samples++;
142  }
143  break;
145  ENCODE(uint16_t, le16, samples, dst, n, 0, 0x8000)
146  break;
148  ENCODE(uint16_t, be16, samples, dst, n, 0, 0x8000)
149  break;
150  case AV_CODEC_ID_PCM_S8:
151  ENCODE(uint8_t, byte, samples, dst, n, 0, -128)
152  break;
154  ENCODE_PLANAR(uint8_t, byte, dst, n, 0, -128)
155  break;
156 #if HAVE_BIGENDIAN
159  ENCODE(int64_t, le64, samples, dst, n, 0, 0)
160  break;
163  ENCODE(int32_t, le32, samples, dst, n, 0, 0)
164  break;
166  ENCODE_PLANAR(int32_t, le32, dst, n, 0, 0)
167  break;
169  ENCODE(int16_t, le16, samples, dst, n, 0, 0)
170  break;
172  ENCODE_PLANAR(int16_t, le16, dst, n, 0, 0)
173  break;
179 #else
182  ENCODE(int64_t, be64, samples, dst, n, 0, 0)
183  break;
186  ENCODE(int32_t, be32, samples, dst, n, 0, 0)
187  break;
189  ENCODE(int16_t, be16, samples, dst, n, 0, 0)
190  break;
192  ENCODE_PLANAR(int16_t, be16, dst, n, 0, 0)
193  break;
199 #endif /* HAVE_BIGENDIAN */
200  case AV_CODEC_ID_PCM_U8:
201  memcpy(dst, samples, n * sample_size);
202  break;
203 #if HAVE_BIGENDIAN
205 #else
208 #endif /* HAVE_BIGENDIAN */
209  n /= avctx->channels;
210  for (c = 0; c < avctx->channels; c++) {
211  const uint8_t *src = frame->extended_data[c];
212  bytestream_put_buffer(&dst, src, n * sample_size);
213  }
214  break;
216  for (; n > 0; n--) {
217  v = *samples++;
218  *dst++ = linear_to_alaw[(v + 32768) >> 2];
219  }
220  break;
222  for (; n > 0; n--) {
223  v = *samples++;
224  *dst++ = linear_to_ulaw[(v + 32768) >> 2];
225  }
226  break;
228  for (; n > 0; n--) {
229  v = *samples++;
230  *dst++ = linear_to_vidc[(v + 32768) >> 2];
231  }
232  break;
233  default:
234  return -1;
235  }
236 
237  *got_packet_ptr = 1;
238  return 0;
239 }
240 
241 typedef struct PCMDecode {
242  short table[256];
243  void (*vector_fmul_scalar)(float *dst, const float *src, float mul,
244  int len);
245  float scale;
246 } PCMDecode;
247 
249 {
250  PCMDecode *s = avctx->priv_data;
251  AVFloatDSPContext *fdsp;
252  int i;
253 
254  if (avctx->channels <= 0) {
255  av_log(avctx, AV_LOG_ERROR, "PCM channels out of bounds\n");
256  return AVERROR(EINVAL);
257  }
258 
259  switch (avctx->codec_id) {
261  for (i = 0; i < 256; i++)
262  s->table[i] = alaw2linear(i);
263  break;
265  for (i = 0; i < 256; i++)
266  s->table[i] = ulaw2linear(i);
267  break;
269  for (i = 0; i < 256; i++)
270  s->table[i] = vidc2linear(i);
271  break;
274  if (avctx->bits_per_coded_sample < 1 || avctx->bits_per_coded_sample > 24)
275  return AVERROR_INVALIDDATA;
276 
277  s->scale = 1. / (1 << (avctx->bits_per_coded_sample - 1));
278  fdsp = avpriv_float_dsp_alloc(0);
279  if (!fdsp)
280  return AVERROR(ENOMEM);
281  s->vector_fmul_scalar = fdsp->vector_fmul_scalar;
282  av_free(fdsp);
283  break;
284  default:
285  break;
286  }
287 
288  avctx->sample_fmt = avctx->codec->sample_fmts[0];
289 
290  if (avctx->sample_fmt == AV_SAMPLE_FMT_S32)
292 
293  return 0;
294 }
295 
296 /**
297  * Read PCM samples macro
298  * @param size Data size of native machine format
299  * @param endian bytestream_get_xxx() endian suffix
300  * @param src Source pointer (variable name)
301  * @param dst Destination pointer (variable name)
302  * @param n Total number of samples (variable name)
303  * @param shift Bitshift (bits)
304  * @param offset Sample value offset
305  */
306 #define DECODE(size, endian, src, dst, n, shift, offset) \
307  for (; n > 0; n--) { \
308  uint ## size ## _t v = bytestream_get_ ## endian(&src); \
309  AV_WN ## size ## A(dst, (uint ## size ## _t)(v - offset) << shift); \
310  dst += size / 8; \
311  }
312 
313 #define DECODE_PLANAR(size, endian, src, dst, n, shift, offset) \
314  n /= avctx->channels; \
315  for (c = 0; c < avctx->channels; c++) { \
316  int i; \
317  dst = frame->extended_data[c]; \
318  for (i = n; i > 0; i--) { \
319  uint ## size ## _t v = bytestream_get_ ## endian(&src); \
320  AV_WN ## size ## A(dst, (uint ## size ##_t)(v - offset) << shift); \
321  dst += size / 8; \
322  } \
323  }
324 
325 static int pcm_decode_frame(AVCodecContext *avctx, void *data,
326  int *got_frame_ptr, AVPacket *avpkt)
327 {
328  const uint8_t *src = avpkt->data;
329  int buf_size = avpkt->size;
330  PCMDecode *s = avctx->priv_data;
331  AVFrame *frame = data;
332  int sample_size, c, n, ret, samples_per_block;
333  uint8_t *samples;
334  int32_t *dst_int32_t;
335 
336  sample_size = av_get_bits_per_sample(avctx->codec_id) / 8;
337 
338  /* av_get_bits_per_sample returns 0 for AV_CODEC_ID_PCM_DVD */
339  samples_per_block = 1;
340  if (avctx->codec_id == AV_CODEC_ID_PCM_LXF) {
341  /* we process 40-bit blocks per channel for LXF */
342  samples_per_block = 2;
343  sample_size = 5;
344  }
345 
346  if (sample_size == 0) {
347  av_log(avctx, AV_LOG_ERROR, "Invalid sample_size\n");
348  return AVERROR(EINVAL);
349  }
350 
351  if (avctx->channels == 0) {
352  av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
353  return AVERROR(EINVAL);
354  }
355 
356  if (avctx->codec_id != avctx->codec->id) {
357  av_log(avctx, AV_LOG_ERROR, "codec ids mismatch\n");
358  return AVERROR(EINVAL);
359  }
360 
361  n = avctx->channels * sample_size;
362 
363  if (n && buf_size % n) {
364  if (buf_size < n) {
365  av_log(avctx, AV_LOG_ERROR,
366  "Invalid PCM packet, data has size %d but at least a size of %d was expected\n",
367  buf_size, n);
368  return AVERROR_INVALIDDATA;
369  } else
370  buf_size -= buf_size % n;
371  }
372 
373  n = buf_size / sample_size;
374 
375  /* get output buffer */
376  frame->nb_samples = n * samples_per_block / avctx->channels;
377  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
378  return ret;
379  samples = frame->data[0];
380 
381  switch (avctx->codec_id) {
383  DECODE(32, le32, src, samples, n, 0, 0x80000000)
384  break;
386  DECODE(32, be32, src, samples, n, 0, 0x80000000)
387  break;
389  DECODE(32, le24, src, samples, n, 8, 0)
390  break;
392  DECODE_PLANAR(32, le24, src, samples, n, 8, 0);
393  break;
395  DECODE(32, be24, src, samples, n, 8, 0)
396  break;
398  DECODE(32, le24, src, samples, n, 8, 0x800000)
399  break;
401  DECODE(32, be24, src, samples, n, 8, 0x800000)
402  break;
404  for (; n > 0; n--) {
405  uint32_t v = bytestream_get_be24(&src);
406  v >>= 4; // sync flags are here
407  AV_WN16A(samples, ff_reverse[(v >> 8) & 0xff] +
408  (ff_reverse[v & 0xff] << 8));
409  samples += 2;
410  }
411  break;
413  DECODE(16, le16, src, samples, n, 0, 0x8000)
414  break;
416  DECODE(16, be16, src, samples, n, 0, 0x8000)
417  break;
418  case AV_CODEC_ID_PCM_S8:
419  for (; n > 0; n--)
420  *samples++ = *src++ + 128;
421  break;
422  case AV_CODEC_ID_PCM_SGA:
423  for (; n > 0; n--) {
424  int sign = *src >> 7;
425  int magn = *src & 0x7f;
426  *samples++ = sign ? 128 - magn : 128 + magn;
427  src++;
428  }
429  break;
431  n /= avctx->channels;
432  for (c = 0; c < avctx->channels; c++) {
433  int i;
434  samples = frame->extended_data[c];
435  for (i = n; i > 0; i--)
436  *samples++ = *src++ + 128;
437  }
438  break;
439 #if HAVE_BIGENDIAN
442  DECODE(64, le64, src, samples, n, 0, 0)
443  break;
448  DECODE(32, le32, src, samples, n, 0, 0)
449  break;
451  DECODE_PLANAR(32, le32, src, samples, n, 0, 0);
452  break;
454  DECODE(16, le16, src, samples, n, 0, 0)
455  break;
457  DECODE_PLANAR(16, le16, src, samples, n, 0, 0);
458  break;
464 #else
467  DECODE(64, be64, src, samples, n, 0, 0)
468  break;
471  DECODE(32, be32, src, samples, n, 0, 0)
472  break;
474  DECODE(16, be16, src, samples, n, 0, 0)
475  break;
477  DECODE_PLANAR(16, be16, src, samples, n, 0, 0);
478  break;
486 #endif /* HAVE_BIGENDIAN */
487  case AV_CODEC_ID_PCM_U8:
488  memcpy(samples, src, n * sample_size);
489  break;
490 #if HAVE_BIGENDIAN
492 #else
495 #endif /* HAVE_BIGENDIAN */
496  n /= avctx->channels;
497  for (c = 0; c < avctx->channels; c++) {
498  samples = frame->extended_data[c];
499  bytestream_get_buffer(&src, samples, n * sample_size);
500  }
501  break;
505  for (; n > 0; n--) {
506  AV_WN16A(samples, s->table[*src++]);
507  samples += 2;
508  }
509  break;
510  case AV_CODEC_ID_PCM_LXF:
511  {
512  int i;
513  n /= avctx->channels;
514  for (c = 0; c < avctx->channels; c++) {
515  dst_int32_t = (int32_t *)frame->extended_data[c];
516  for (i = 0; i < n; i++) {
517  // extract low 20 bits and expand to 32 bits
518  *dst_int32_t++ = ((uint32_t)src[2]<<28) |
519  (src[1] << 20) |
520  (src[0] << 12) |
521  ((src[2] & 0x0F) << 8) |
522  src[1];
523  // extract high 20 bits and expand to 32 bits
524  *dst_int32_t++ = ((uint32_t)src[4]<<24) |
525  (src[3] << 16) |
526  ((src[2] & 0xF0) << 8) |
527  (src[4] << 4) |
528  (src[3] >> 4);
529  src += 5;
530  }
531  }
532  break;
533  }
534  default:
535  return -1;
536  }
537 
538  if (avctx->codec_id == AV_CODEC_ID_PCM_F16LE ||
539  avctx->codec_id == AV_CODEC_ID_PCM_F24LE) {
540  s->vector_fmul_scalar((float *)frame->extended_data[0],
541  (const float *)frame->extended_data[0],
542  s->scale, FFALIGN(frame->nb_samples * avctx->channels, 4));
543  emms_c();
544  }
545 
546  *got_frame_ptr = 1;
547 
548  return buf_size;
549 }
550 
551 #define PCM_ENCODER_0(id_, sample_fmt_, name_, long_name_)
552 #define PCM_ENCODER_1(id_, sample_fmt_, name_, long_name_) \
553 AVCodec ff_ ## name_ ## _encoder = { \
554  .name = #name_, \
555  .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
556  .type = AVMEDIA_TYPE_AUDIO, \
557  .id = AV_CODEC_ID_ ## id_, \
558  .init = pcm_encode_init, \
559  .encode2 = pcm_encode_frame, \
560  .capabilities = AV_CODEC_CAP_VARIABLE_FRAME_SIZE, \
561  .sample_fmts = (const enum AVSampleFormat[]){ sample_fmt_, \
562  AV_SAMPLE_FMT_NONE }, \
563  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, \
564 }
565 
566 #define PCM_ENCODER_2(cf, id, sample_fmt, name, long_name) \
567  PCM_ENCODER_ ## cf(id, sample_fmt, name, long_name)
568 #define PCM_ENCODER_3(cf, id, sample_fmt, name, long_name) \
569  PCM_ENCODER_2(cf, id, sample_fmt, name, long_name)
570 #define PCM_ENCODER(id, sample_fmt, name, long_name) \
571  PCM_ENCODER_3(CONFIG_ ## id ## _ENCODER, id, sample_fmt, name, long_name)
572 
573 #define PCM_DECODER_0(id, sample_fmt, name, long_name)
574 #define PCM_DECODER_1(id_, sample_fmt_, name_, long_name_) \
575 AVCodec ff_ ## name_ ## _decoder = { \
576  .name = #name_, \
577  .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
578  .type = AVMEDIA_TYPE_AUDIO, \
579  .id = AV_CODEC_ID_ ## id_, \
580  .priv_data_size = sizeof(PCMDecode), \
581  .init = pcm_decode_init, \
582  .decode = pcm_decode_frame, \
583  .capabilities = AV_CODEC_CAP_DR1, \
584  .sample_fmts = (const enum AVSampleFormat[]){ sample_fmt_, \
585  AV_SAMPLE_FMT_NONE }, \
586  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, \
587 }
588 
589 #define PCM_DECODER_2(cf, id, sample_fmt, name, long_name) \
590  PCM_DECODER_ ## cf(id, sample_fmt, name, long_name)
591 #define PCM_DECODER_3(cf, id, sample_fmt, name, long_name) \
592  PCM_DECODER_2(cf, id, sample_fmt, name, long_name)
593 #define PCM_DECODER(id, sample_fmt, name, long_name) \
594  PCM_DECODER_3(CONFIG_ ## id ## _DECODER, id, sample_fmt, name, long_name)
595 
596 #define PCM_CODEC(id, sample_fmt_, name, long_name_) \
597  PCM_ENCODER(id, sample_fmt_, name, long_name_); \
598  PCM_DECODER(id, sample_fmt_, name, long_name_)
599 
600 /* Note: Do not forget to add new entries to the Makefile as well. */
601 PCM_CODEC (PCM_ALAW, AV_SAMPLE_FMT_S16, pcm_alaw, "PCM A-law / G.711 A-law");
602 PCM_DECODER(PCM_F16LE, AV_SAMPLE_FMT_FLT, pcm_f16le, "PCM 16.8 floating point little-endian");
603 PCM_DECODER(PCM_F24LE, AV_SAMPLE_FMT_FLT, pcm_f24le, "PCM 24.0 floating point little-endian");
604 PCM_CODEC (PCM_F32BE, AV_SAMPLE_FMT_FLT, pcm_f32be, "PCM 32-bit floating point big-endian");
605 PCM_CODEC (PCM_F32LE, AV_SAMPLE_FMT_FLT, pcm_f32le, "PCM 32-bit floating point little-endian");
606 PCM_CODEC (PCM_F64BE, AV_SAMPLE_FMT_DBL, pcm_f64be, "PCM 64-bit floating point big-endian");
607 PCM_CODEC (PCM_F64LE, AV_SAMPLE_FMT_DBL, pcm_f64le, "PCM 64-bit floating point little-endian");
608 PCM_DECODER(PCM_LXF, AV_SAMPLE_FMT_S32P,pcm_lxf, "PCM signed 20-bit little-endian planar");
609 PCM_CODEC (PCM_MULAW, AV_SAMPLE_FMT_S16, pcm_mulaw, "PCM mu-law / G.711 mu-law");
610 PCM_CODEC (PCM_S8, AV_SAMPLE_FMT_U8, pcm_s8, "PCM signed 8-bit");
611 PCM_CODEC (PCM_S8_PLANAR, AV_SAMPLE_FMT_U8P, pcm_s8_planar, "PCM signed 8-bit planar");
612 PCM_CODEC (PCM_S16BE, AV_SAMPLE_FMT_S16, pcm_s16be, "PCM signed 16-bit big-endian");
613 PCM_CODEC (PCM_S16BE_PLANAR, AV_SAMPLE_FMT_S16P,pcm_s16be_planar, "PCM signed 16-bit big-endian planar");
614 PCM_CODEC (PCM_S16LE, AV_SAMPLE_FMT_S16, pcm_s16le, "PCM signed 16-bit little-endian");
615 PCM_CODEC (PCM_S16LE_PLANAR, AV_SAMPLE_FMT_S16P,pcm_s16le_planar, "PCM signed 16-bit little-endian planar");
616 PCM_CODEC (PCM_S24BE, AV_SAMPLE_FMT_S32, pcm_s24be, "PCM signed 24-bit big-endian");
617 PCM_CODEC (PCM_S24DAUD, AV_SAMPLE_FMT_S16, pcm_s24daud, "PCM D-Cinema audio signed 24-bit");
618 PCM_CODEC (PCM_S24LE, AV_SAMPLE_FMT_S32, pcm_s24le, "PCM signed 24-bit little-endian");
619 PCM_CODEC (PCM_S24LE_PLANAR, AV_SAMPLE_FMT_S32P,pcm_s24le_planar, "PCM signed 24-bit little-endian planar");
620 PCM_CODEC (PCM_S32BE, AV_SAMPLE_FMT_S32, pcm_s32be, "PCM signed 32-bit big-endian");
621 PCM_CODEC (PCM_S32LE, AV_SAMPLE_FMT_S32, pcm_s32le, "PCM signed 32-bit little-endian");
622 PCM_CODEC (PCM_S32LE_PLANAR, AV_SAMPLE_FMT_S32P,pcm_s32le_planar, "PCM signed 32-bit little-endian planar");
623 PCM_CODEC (PCM_U8, AV_SAMPLE_FMT_U8, pcm_u8, "PCM unsigned 8-bit");
624 PCM_CODEC (PCM_U16BE, AV_SAMPLE_FMT_S16, pcm_u16be, "PCM unsigned 16-bit big-endian");
625 PCM_CODEC (PCM_U16LE, AV_SAMPLE_FMT_S16, pcm_u16le, "PCM unsigned 16-bit little-endian");
626 PCM_CODEC (PCM_U24BE, AV_SAMPLE_FMT_S32, pcm_u24be, "PCM unsigned 24-bit big-endian");
627 PCM_CODEC (PCM_U24LE, AV_SAMPLE_FMT_S32, pcm_u24le, "PCM unsigned 24-bit little-endian");
628 PCM_CODEC (PCM_U32BE, AV_SAMPLE_FMT_S32, pcm_u32be, "PCM unsigned 32-bit big-endian");
629 PCM_CODEC (PCM_U32LE, AV_SAMPLE_FMT_S32, pcm_u32le, "PCM unsigned 32-bit little-endian");
630 PCM_CODEC (PCM_S64BE, AV_SAMPLE_FMT_S64, pcm_s64be, "PCM signed 64-bit big-endian");
631 PCM_CODEC (PCM_S64LE, AV_SAMPLE_FMT_S64, pcm_s64le, "PCM signed 64-bit little-endian");
632 PCM_CODEC (PCM_VIDC, AV_SAMPLE_FMT_S16, pcm_vidc, "PCM Archimedes VIDC");
633 PCM_DECODER(PCM_SGA, AV_SAMPLE_FMT_U8, pcm_sga, "PCM SGA");
Macro definitions for various function/variable attributes.
#define av_cold
Definition: attributes.h:88
AV_SAMPLE_FMT_U8
uint8_t
int32_t
Libavcodec external API header.
static av_always_inline unsigned int bytestream_get_buffer(const uint8_t **b, uint8_t *dst, unsigned int size)
Definition: bytestream.h:363
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
Definition: bytestream.h:372
#define s(width, name)
Definition: cbs_vp9.c:257
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:1900
static AVFrame * frame
static float mul(float src0, float src1)
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
Definition: encode.c:33
@ AV_CODEC_ID_PCM_F24LE
Definition: codec_id.h:348
@ AV_CODEC_ID_PCM_F32LE
Definition: codec_id.h:334
@ AV_CODEC_ID_PCM_S24BE
Definition: codec_id.h:326
@ AV_CODEC_ID_PCM_S64BE
Definition: codec_id.h:346
@ AV_CODEC_ID_PCM_S16BE_PLANAR
Definition: codec_id.h:343
@ AV_CODEC_ID_PCM_U8
Definition: codec_id.h:318
@ AV_CODEC_ID_PCM_S16LE
Definition: codec_id.h:313
@ AV_CODEC_ID_PCM_S32LE_PLANAR
Definition: codec_id.h:342
@ AV_CODEC_ID_PCM_F16LE
Definition: codec_id.h:347
@ AV_CODEC_ID_PCM_F32BE
Definition: codec_id.h:333
@ AV_CODEC_ID_PCM_S24LE_PLANAR
Definition: codec_id.h:341
@ AV_CODEC_ID_PCM_S16BE
Definition: codec_id.h:314
@ AV_CODEC_ID_PCM_S24LE
Definition: codec_id.h:325
@ AV_CODEC_ID_PCM_U24BE
Definition: codec_id.h:328
@ AV_CODEC_ID_PCM_S24DAUD
Definition: codec_id.h:329
@ AV_CODEC_ID_PCM_S32LE
Definition: codec_id.h:321
@ AV_CODEC_ID_PCM_S8
Definition: codec_id.h:317
@ AV_CODEC_ID_PCM_U32LE
Definition: codec_id.h:323
@ AV_CODEC_ID_PCM_VIDC
Definition: codec_id.h:349
@ AV_CODEC_ID_PCM_ALAW
Definition: codec_id.h:320
@ AV_CODEC_ID_PCM_F64LE
Definition: codec_id.h:336
@ AV_CODEC_ID_PCM_U16BE
Definition: codec_id.h:316
@ AV_CODEC_ID_PCM_LXF
Definition: codec_id.h:338
@ AV_CODEC_ID_PCM_SGA
Definition: codec_id.h:350
@ AV_CODEC_ID_PCM_S64LE
Definition: codec_id.h:345
@ AV_CODEC_ID_PCM_F64BE
Definition: codec_id.h:335
@ AV_CODEC_ID_PCM_S32BE
Definition: codec_id.h:322
@ AV_CODEC_ID_PCM_S16LE_PLANAR
Definition: codec_id.h:331
@ AV_CODEC_ID_PCM_U24LE
Definition: codec_id.h:327
@ AV_CODEC_ID_PCM_U16LE
Definition: codec_id.h:315
@ AV_CODEC_ID_PCM_S8_PLANAR
Definition: codec_id.h:340
@ AV_CODEC_ID_PCM_U32BE
Definition: codec_id.h:324
@ AV_CODEC_ID_PCM_MULAW
Definition: codec_id.h:319
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
Definition: utils.c:639
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
#define AVERROR(e)
Definition: error.h:43
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
Definition: samplefmt.h:67
@ AV_SAMPLE_FMT_FLT
float
Definition: samplefmt.h:63
@ AV_SAMPLE_FMT_S64
signed 64 bits
Definition: samplefmt.h:71
@ AV_SAMPLE_FMT_U8P
unsigned 8 bits, planar
Definition: samplefmt.h:66
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
Definition: samplefmt.h:68
@ AV_SAMPLE_FMT_S32
signed 32 bits
Definition: samplefmt.h:62
@ AV_SAMPLE_FMT_DBL
double
Definition: samplefmt.h:64
@ AV_SAMPLE_FMT_S16
signed 16 bits
Definition: samplefmt.h:61
for(j=16;j >0;--j)
int i
Definition: input.c:407
#define AV_WN16A(p, v)
Definition: intreadwrite.h:534
#define INIT_ONCE(id, name)
static int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Definition: pcm.c:92
#define ENCODE_PLANAR(type, endian, dst, n, shift, offset)
Definition: pcm.c:81
#define DECODE(size, endian, src, dst, n, shift, offset)
Read PCM samples macro.
Definition: pcm.c:306
static av_cold int pcm_encode_init(AVCodecContext *avctx)
Definition: pcm.c:37
static av_cold int pcm_decode_init(AVCodecContext *avctx)
Definition: pcm.c:248
static int pcm_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Definition: pcm.c:325
#define PCM_CODEC(id, sample_fmt_, name, long_name_)
Definition: pcm.c:596
#define ENCODE(type, endian, src, dst, n, shift, offset)
Write PCM samples macro.
Definition: pcm.c:74
#define PCM_DECODER(id, sample_fmt, name, long_name)
Definition: pcm.c:593
#define DECODE_PLANAR(size, endian, src, dst, n, shift, offset)
Definition: pcm.c:313
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
Definition: float_dsp.c:135
common internal API header
#define emms_c()
Definition: internal.h:54
const uint8_t ff_reverse[256]
Definition: reverse.c:23
#define FFALIGN(x, a)
Definition: macros.h:48
const char data[16]
Definition: mxf.c:142
static av_cold int ulaw2linear(unsigned char u_val)
Definition: pcm_tablegen.h:61
static av_cold int alaw2linear(unsigned char a_val)
Definition: pcm_tablegen.h:46
static av_cold int vidc2linear(unsigned char u_val)
Definition: pcm_tablegen.h:78
static uint8_t linear_to_alaw[16384]
Definition: pcm_tablegen.h:99
static uint8_t linear_to_ulaw[16384]
Definition: pcm_tablegen.h:100
static uint8_t linear_to_vidc[16384]
Definition: pcm_tablegen.h:101
typedef void(RENAME(mix_any_func_type))
main external API structure.
Definition: avcodec.h:536
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1204
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
Definition: avcodec.h:1744
int64_t bit_rate
the average bitrate
Definition: avcodec.h:586
const struct AVCodec * codec
Definition: avcodec.h:545
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:1751
int sample_rate
samples per second
Definition: avcodec.h:1196
int channels
number of audio channels
Definition: avcodec.h:1197
enum AVCodecID codec_id
Definition: avcodec.h:546
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs.
Definition: avcodec.h:1233
int frame_size
Number of samples per channel in an audio frame.
Definition: avcodec.h:1216
void * priv_data
Definition: avcodec.h:563
enum AVCodecID id
Definition: codec.h:211
enum AVSampleFormat * sample_fmts
array of supported sample formats, or NULL if unknown, array is terminated by -1
Definition: codec.h:220
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:318
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:384
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:332
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:365
This structure stores compressed data.
Definition: packet.h:346
int size
Definition: packet.h:370
uint8_t * data
Definition: packet.h:369
Definition: pcm.c:241
short table[256]
Definition: pcm.c:242
float scale
Definition: pcm.c:245
void(* vector_fmul_scalar)(float *dst, const float *src, float mul, int len)
Definition: pcm.c:243
#define av_free(p)
#define av_log(a,...)
static uint8_t tmp[11]
Definition: aes_ctr.c:27
#define src
Definition: vp8dsp.c:255
if(ret< 0)
Definition: vf_mcdeint.c:282
int len
static double c[64]