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