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