FFmpeg  3.4.9
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 "libavutil/attributes.h"
28 #include "libavutil/float_dsp.h"
29 #include "avcodec.h"
30 #include "bytestream.h"
31 #include "internal.h"
32 #include "mathops.h"
33 #include "pcm_tablegen.h"
34 
36 {
37  avctx->frame_size = 0;
38  switch (avctx->codec->id) {
41  break;
44  break;
45  default:
46  break;
47  }
48 
50  avctx->block_align = avctx->channels * avctx->bits_per_coded_sample / 8;
51  avctx->bit_rate = avctx->block_align * 8LL * avctx->sample_rate;
52 
53  return 0;
54 }
55 
56 /**
57  * Write PCM samples macro
58  * @param type Datatype of native machine format
59  * @param endian bytestream_put_xxx() suffix
60  * @param src Source pointer (variable name)
61  * @param dst Destination pointer (variable name)
62  * @param n Total number of samples (variable name)
63  * @param shift Bitshift (bits)
64  * @param offset Sample value offset
65  */
66 #define ENCODE(type, endian, src, dst, n, shift, offset) \
67  samples_ ## type = (const type *) src; \
68  for (; n > 0; n--) { \
69  register type v = (*samples_ ## type++ >> shift) + offset; \
70  bytestream_put_ ## endian(&dst, v); \
71  }
72 
73 #define ENCODE_PLANAR(type, endian, dst, n, shift, offset) \
74  n /= avctx->channels; \
75  for (c = 0; c < avctx->channels; c++) { \
76  int i; \
77  samples_ ## type = (const type *) frame->extended_data[c]; \
78  for (i = n; i > 0; i--) { \
79  register type v = (*samples_ ## type++ >> shift) + offset; \
80  bytestream_put_ ## endian(&dst, v); \
81  } \
82  }
83 
84 static int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
85  const AVFrame *frame, int *got_packet_ptr)
86 {
87  int n, c, sample_size, v, ret;
88  const short *samples;
89  unsigned char *dst;
90  const uint8_t *samples_uint8_t;
91  const int16_t *samples_int16_t;
92  const int32_t *samples_int32_t;
93  const int64_t *samples_int64_t;
94  const uint16_t *samples_uint16_t;
95  const uint32_t *samples_uint32_t;
96 
97  sample_size = av_get_bits_per_sample(avctx->codec->id) / 8;
98  n = frame->nb_samples * avctx->channels;
99  samples = (const short *)frame->data[0];
100 
101  if ((ret = ff_alloc_packet2(avctx, avpkt, n * sample_size, n * sample_size)) < 0)
102  return ret;
103  dst = avpkt->data;
104 
105  switch (avctx->codec->id) {
107  ENCODE(uint32_t, le32, samples, dst, n, 0, 0x80000000)
108  break;
110  ENCODE(uint32_t, be32, samples, dst, n, 0, 0x80000000)
111  break;
113  ENCODE(int32_t, le24, samples, dst, n, 8, 0)
114  break;
116  ENCODE_PLANAR(int32_t, le24, dst, n, 8, 0)
117  break;
119  ENCODE(int32_t, be24, samples, dst, n, 8, 0)
120  break;
122  ENCODE(uint32_t, le24, samples, dst, n, 8, 0x800000)
123  break;
125  ENCODE(uint32_t, be24, samples, dst, n, 8, 0x800000)
126  break;
128  for (; n > 0; n--) {
129  uint32_t tmp = ff_reverse[(*samples >> 8) & 0xff] +
130  (ff_reverse[*samples & 0xff] << 8);
131  tmp <<= 4; // sync flags would go here
132  bytestream_put_be24(&dst, tmp);
133  samples++;
134  }
135  break;
137  ENCODE(uint16_t, le16, samples, dst, n, 0, 0x8000)
138  break;
140  ENCODE(uint16_t, be16, samples, dst, n, 0, 0x8000)
141  break;
142  case AV_CODEC_ID_PCM_S8:
143  ENCODE(uint8_t, byte, samples, dst, n, 0, -128)
144  break;
146  ENCODE_PLANAR(uint8_t, byte, dst, n, 0, -128)
147  break;
148 #if HAVE_BIGENDIAN
151  ENCODE(int64_t, le64, samples, dst, n, 0, 0)
152  break;
155  ENCODE(int32_t, le32, samples, dst, n, 0, 0)
156  break;
158  ENCODE_PLANAR(int32_t, le32, dst, n, 0, 0)
159  break;
161  ENCODE(int16_t, le16, samples, dst, n, 0, 0)
162  break;
164  ENCODE_PLANAR(int16_t, le16, dst, n, 0, 0)
165  break;
171 #else
174  ENCODE(int64_t, be64, samples, dst, n, 0, 0)
175  break;
178  ENCODE(int32_t, be32, samples, dst, n, 0, 0)
179  break;
181  ENCODE(int16_t, be16, samples, dst, n, 0, 0)
182  break;
184  ENCODE_PLANAR(int16_t, be16, dst, n, 0, 0)
185  break;
191 #endif /* HAVE_BIGENDIAN */
192  case AV_CODEC_ID_PCM_U8:
193  memcpy(dst, samples, n * sample_size);
194  break;
195 #if HAVE_BIGENDIAN
197 #else
200 #endif /* HAVE_BIGENDIAN */
201  n /= avctx->channels;
202  for (c = 0; c < avctx->channels; c++) {
203  const uint8_t *src = frame->extended_data[c];
204  bytestream_put_buffer(&dst, src, n * sample_size);
205  }
206  break;
208  for (; n > 0; n--) {
209  v = *samples++;
210  *dst++ = linear_to_alaw[(v + 32768) >> 2];
211  }
212  break;
214  for (; n > 0; n--) {
215  v = *samples++;
216  *dst++ = linear_to_ulaw[(v + 32768) >> 2];
217  }
218  break;
219  default:
220  return -1;
221  }
222 
223  *got_packet_ptr = 1;
224  return 0;
225 }
226 
227 typedef struct PCMDecode {
228  short table[256];
230  float scale;
231 } PCMDecode;
232 
234 {
235  PCMDecode *s = avctx->priv_data;
236  int i;
237 
238  if (avctx->channels <= 0) {
239  av_log(avctx, AV_LOG_ERROR, "PCM channels out of bounds\n");
240  return AVERROR(EINVAL);
241  }
242 
243  switch (avctx->codec_id) {
245  for (i = 0; i < 256; i++)
246  s->table[i] = alaw2linear(i);
247  break;
249  for (i = 0; i < 256; i++)
250  s->table[i] = ulaw2linear(i);
251  break;
254  if (avctx->bits_per_coded_sample < 1 || avctx->bits_per_coded_sample > 24)
255  return AVERROR_INVALIDDATA;
256 
257  s->scale = 1. / (1 << (avctx->bits_per_coded_sample - 1));
259  if (!s->fdsp)
260  return AVERROR(ENOMEM);
261  break;
262  default:
263  break;
264  }
265 
266  avctx->sample_fmt = avctx->codec->sample_fmts[0];
267 
268  if (avctx->sample_fmt == AV_SAMPLE_FMT_S32)
270 
271  return 0;
272 }
273 
275 {
276  PCMDecode *s = avctx->priv_data;
277 
278  av_freep(&s->fdsp);
279 
280  return 0;
281 }
282 
283 /**
284  * Read PCM samples macro
285  * @param size Data size of native machine format
286  * @param endian bytestream_get_xxx() endian suffix
287  * @param src Source pointer (variable name)
288  * @param dst Destination pointer (variable name)
289  * @param n Total number of samples (variable name)
290  * @param shift Bitshift (bits)
291  * @param offset Sample value offset
292  */
293 #define DECODE(size, endian, src, dst, n, shift, offset) \
294  for (; n > 0; n--) { \
295  uint ## size ## _t v = bytestream_get_ ## endian(&src); \
296  AV_WN ## size ## A(dst, (uint ## size ## _t)(v - offset) << shift); \
297  dst += size / 8; \
298  }
299 
300 #define DECODE_PLANAR(size, endian, src, dst, n, shift, offset) \
301  n /= avctx->channels; \
302  for (c = 0; c < avctx->channels; c++) { \
303  int i; \
304  dst = frame->extended_data[c]; \
305  for (i = n; i > 0; i--) { \
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 
312 static int pcm_decode_frame(AVCodecContext *avctx, void *data,
313  int *got_frame_ptr, AVPacket *avpkt)
314 {
315  const uint8_t *src = avpkt->data;
316  int buf_size = avpkt->size;
317  PCMDecode *s = avctx->priv_data;
318  AVFrame *frame = data;
319  int sample_size, c, n, ret, samples_per_block;
320  uint8_t *samples;
321  int32_t *dst_int32_t;
322 
323  sample_size = av_get_bits_per_sample(avctx->codec_id) / 8;
324 
325  /* av_get_bits_per_sample returns 0 for AV_CODEC_ID_PCM_DVD */
326  samples_per_block = 1;
327  if (avctx->codec_id == AV_CODEC_ID_PCM_LXF) {
328  /* we process 40-bit blocks per channel for LXF */
329  samples_per_block = 2;
330  sample_size = 5;
331  }
332 
333  if (sample_size == 0) {
334  av_log(avctx, AV_LOG_ERROR, "Invalid sample_size\n");
335  return AVERROR(EINVAL);
336  }
337 
338  if (avctx->channels == 0) {
339  av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
340  return AVERROR(EINVAL);
341  }
342 
343  if (avctx->codec_id != avctx->codec->id) {
344  av_log(avctx, AV_LOG_ERROR, "codec ids mismatch\n");
345  return AVERROR(EINVAL);
346  }
347 
348  n = avctx->channels * sample_size;
349 
350  if (n && buf_size % n) {
351  if (buf_size < n) {
352  av_log(avctx, AV_LOG_ERROR,
353  "Invalid PCM packet, data has size %d but at least a size of %d was expected\n",
354  buf_size, n);
355  return AVERROR_INVALIDDATA;
356  } else
357  buf_size -= buf_size % n;
358  }
359 
360  n = buf_size / sample_size;
361 
362  /* get output buffer */
363  frame->nb_samples = n * samples_per_block / avctx->channels;
364  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
365  return ret;
366  samples = frame->data[0];
367 
368  switch (avctx->codec_id) {
370  DECODE(32, le32, src, samples, n, 0, 0x80000000)
371  break;
373  DECODE(32, be32, src, samples, n, 0, 0x80000000)
374  break;
376  DECODE(32, le24, src, samples, n, 8, 0)
377  break;
379  DECODE_PLANAR(32, le24, src, samples, n, 8, 0);
380  break;
382  DECODE(32, be24, src, samples, n, 8, 0)
383  break;
385  DECODE(32, le24, src, samples, n, 8, 0x800000)
386  break;
388  DECODE(32, be24, src, samples, n, 8, 0x800000)
389  break;
391  for (; n > 0; n--) {
392  uint32_t v = bytestream_get_be24(&src);
393  v >>= 4; // sync flags are here
394  AV_WN16A(samples, ff_reverse[(v >> 8) & 0xff] +
395  (ff_reverse[v & 0xff] << 8));
396  samples += 2;
397  }
398  break;
400  DECODE(16, le16, src, samples, n, 0, 0x8000)
401  break;
403  DECODE(16, be16, src, samples, n, 0, 0x8000)
404  break;
405  case AV_CODEC_ID_PCM_S8:
406  for (; n > 0; n--)
407  *samples++ = *src++ + 128;
408  break;
410  n /= avctx->channels;
411  for (c = 0; c < avctx->channels; c++) {
412  int i;
413  samples = frame->extended_data[c];
414  for (i = n; i > 0; i--)
415  *samples++ = *src++ + 128;
416  }
417  break;
418 #if HAVE_BIGENDIAN
421  DECODE(64, le64, src, samples, n, 0, 0)
422  break;
427  DECODE(32, le32, src, samples, n, 0, 0)
428  break;
430  DECODE_PLANAR(32, le32, src, samples, n, 0, 0);
431  break;
433  DECODE(16, le16, src, samples, n, 0, 0)
434  break;
436  DECODE_PLANAR(16, le16, src, samples, n, 0, 0);
437  break;
443 #else
446  DECODE(64, be64, src, samples, n, 0, 0)
447  break;
450  DECODE(32, be32, src, samples, n, 0, 0)
451  break;
453  DECODE(16, be16, src, samples, n, 0, 0)
454  break;
456  DECODE_PLANAR(16, be16, src, samples, n, 0, 0);
457  break;
465 #endif /* HAVE_BIGENDIAN */
466  case AV_CODEC_ID_PCM_U8:
467  memcpy(samples, src, n * sample_size);
468  break;
469 #if HAVE_BIGENDIAN
471 #else
474 #endif /* HAVE_BIGENDIAN */
475  n /= avctx->channels;
476  for (c = 0; c < avctx->channels; c++) {
477  samples = frame->extended_data[c];
478  bytestream_get_buffer(&src, samples, n * sample_size);
479  }
480  break;
482  for (; n > 0; n--) {
483  int v = *src++;
484  if (v < 128)
485  v = 128 - v;
486  *samples++ = v;
487  }
488  break;
491  for (; n > 0; n--) {
492  AV_WN16A(samples, s->table[*src++]);
493  samples += 2;
494  }
495  break;
496  case AV_CODEC_ID_PCM_LXF:
497  {
498  int i;
499  n /= avctx->channels;
500  for (c = 0; c < avctx->channels; c++) {
501  dst_int32_t = (int32_t *)frame->extended_data[c];
502  for (i = 0; i < n; i++) {
503  // extract low 20 bits and expand to 32 bits
504  *dst_int32_t++ = ((uint32_t)src[2]<<28) |
505  (src[1] << 20) |
506  (src[0] << 12) |
507  ((src[2] & 0x0F) << 8) |
508  src[1];
509  // extract high 20 bits and expand to 32 bits
510  *dst_int32_t++ = ((uint32_t)src[4]<<24) |
511  (src[3] << 16) |
512  ((src[2] & 0xF0) << 8) |
513  (src[4] << 4) |
514  (src[3] >> 4);
515  src += 5;
516  }
517  }
518  break;
519  }
520  default:
521  return -1;
522  }
523 
524  if (avctx->codec_id == AV_CODEC_ID_PCM_F16LE ||
525  avctx->codec_id == AV_CODEC_ID_PCM_F24LE) {
526  s->fdsp->vector_fmul_scalar((float *)frame->extended_data[0],
527  (const float *)frame->extended_data[0],
528  s->scale, FFALIGN(frame->nb_samples * avctx->channels, 4));
529  emms_c();
530  }
531 
532  *got_frame_ptr = 1;
533 
534  return buf_size;
535 }
536 
537 #define PCM_ENCODER_0(id_, sample_fmt_, name_, long_name_)
538 #define PCM_ENCODER_1(id_, sample_fmt_, name_, long_name_) \
539 AVCodec ff_ ## name_ ## _encoder = { \
540  .name = #name_, \
541  .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
542  .type = AVMEDIA_TYPE_AUDIO, \
543  .id = AV_CODEC_ID_ ## id_, \
544  .init = pcm_encode_init, \
545  .encode2 = pcm_encode_frame, \
546  .capabilities = AV_CODEC_CAP_VARIABLE_FRAME_SIZE, \
547  .sample_fmts = (const enum AVSampleFormat[]){ sample_fmt_, \
548  AV_SAMPLE_FMT_NONE }, \
549 }
550 
551 #define PCM_ENCODER_2(cf, id, sample_fmt, name, long_name) \
552  PCM_ENCODER_ ## cf(id, sample_fmt, name, long_name)
553 #define PCM_ENCODER_3(cf, id, sample_fmt, name, long_name) \
554  PCM_ENCODER_2(cf, id, sample_fmt, name, long_name)
555 #define PCM_ENCODER(id, sample_fmt, name, long_name) \
556  PCM_ENCODER_3(CONFIG_ ## id ## _ENCODER, id, sample_fmt, name, long_name)
557 
558 #define PCM_DECODER_0(id, sample_fmt, name, long_name)
559 #define PCM_DECODER_1(id_, sample_fmt_, name_, long_name_) \
560 AVCodec ff_ ## name_ ## _decoder = { \
561  .name = #name_, \
562  .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
563  .type = AVMEDIA_TYPE_AUDIO, \
564  .id = AV_CODEC_ID_ ## id_, \
565  .priv_data_size = sizeof(PCMDecode), \
566  .init = pcm_decode_init, \
567  .close = pcm_decode_close, \
568  .decode = pcm_decode_frame, \
569  .capabilities = AV_CODEC_CAP_DR1, \
570  .sample_fmts = (const enum AVSampleFormat[]){ sample_fmt_, \
571  AV_SAMPLE_FMT_NONE }, \
572 }
573 
574 #define PCM_DECODER_2(cf, id, sample_fmt, name, long_name) \
575  PCM_DECODER_ ## cf(id, sample_fmt, name, long_name)
576 #define PCM_DECODER_3(cf, id, sample_fmt, name, long_name) \
577  PCM_DECODER_2(cf, id, sample_fmt, name, long_name)
578 #define PCM_DECODER(id, sample_fmt, name, long_name) \
579  PCM_DECODER_3(CONFIG_ ## id ## _DECODER, id, sample_fmt, name, long_name)
580 
581 #define PCM_CODEC(id, sample_fmt_, name, long_name_) \
582  PCM_ENCODER(id, sample_fmt_, name, long_name_); \
583  PCM_DECODER(id, sample_fmt_, name, long_name_)
584 
585 /* Note: Do not forget to add new entries to the Makefile as well. */
586 PCM_CODEC (PCM_ALAW, AV_SAMPLE_FMT_S16, pcm_alaw, "PCM A-law / G.711 A-law");
587 PCM_DECODER(PCM_F16LE, AV_SAMPLE_FMT_FLT, pcm_f16le, "PCM 16.8 floating point little-endian");
588 PCM_DECODER(PCM_F24LE, AV_SAMPLE_FMT_FLT, pcm_f24le, "PCM 24.0 floating point little-endian");
589 PCM_CODEC (PCM_F32BE, AV_SAMPLE_FMT_FLT, pcm_f32be, "PCM 32-bit floating point big-endian");
590 PCM_CODEC (PCM_F32LE, AV_SAMPLE_FMT_FLT, pcm_f32le, "PCM 32-bit floating point little-endian");
591 PCM_CODEC (PCM_F64BE, AV_SAMPLE_FMT_DBL, pcm_f64be, "PCM 64-bit floating point big-endian");
592 PCM_CODEC (PCM_F64LE, AV_SAMPLE_FMT_DBL, pcm_f64le, "PCM 64-bit floating point little-endian");
593 PCM_DECODER(PCM_LXF, AV_SAMPLE_FMT_S32P,pcm_lxf, "PCM signed 20-bit little-endian planar");
594 PCM_CODEC (PCM_MULAW, AV_SAMPLE_FMT_S16, pcm_mulaw, "PCM mu-law / G.711 mu-law");
595 PCM_CODEC (PCM_S8, AV_SAMPLE_FMT_U8, pcm_s8, "PCM signed 8-bit");
596 PCM_CODEC (PCM_S8_PLANAR, AV_SAMPLE_FMT_U8P, pcm_s8_planar, "PCM signed 8-bit planar");
597 PCM_CODEC (PCM_S16BE, AV_SAMPLE_FMT_S16, pcm_s16be, "PCM signed 16-bit big-endian");
598 PCM_CODEC (PCM_S16BE_PLANAR, AV_SAMPLE_FMT_S16P,pcm_s16be_planar, "PCM signed 16-bit big-endian planar");
599 PCM_CODEC (PCM_S16LE, AV_SAMPLE_FMT_S16, pcm_s16le, "PCM signed 16-bit little-endian");
600 PCM_CODEC (PCM_S16LE_PLANAR, AV_SAMPLE_FMT_S16P,pcm_s16le_planar, "PCM signed 16-bit little-endian planar");
601 PCM_CODEC (PCM_S24BE, AV_SAMPLE_FMT_S32, pcm_s24be, "PCM signed 24-bit big-endian");
602 PCM_CODEC (PCM_S24DAUD, AV_SAMPLE_FMT_S16, pcm_s24daud, "PCM D-Cinema audio signed 24-bit");
603 PCM_CODEC (PCM_S24LE, AV_SAMPLE_FMT_S32, pcm_s24le, "PCM signed 24-bit little-endian");
604 PCM_CODEC (PCM_S24LE_PLANAR, AV_SAMPLE_FMT_S32P,pcm_s24le_planar, "PCM signed 24-bit little-endian planar");
605 PCM_CODEC (PCM_S32BE, AV_SAMPLE_FMT_S32, pcm_s32be, "PCM signed 32-bit big-endian");
606 PCM_CODEC (PCM_S32LE, AV_SAMPLE_FMT_S32, pcm_s32le, "PCM signed 32-bit little-endian");
607 PCM_CODEC (PCM_S32LE_PLANAR, AV_SAMPLE_FMT_S32P,pcm_s32le_planar, "PCM signed 32-bit little-endian planar");
608 PCM_CODEC (PCM_U8, AV_SAMPLE_FMT_U8, pcm_u8, "PCM unsigned 8-bit");
609 PCM_CODEC (PCM_U16BE, AV_SAMPLE_FMT_S16, pcm_u16be, "PCM unsigned 16-bit big-endian");
610 PCM_CODEC (PCM_U16LE, AV_SAMPLE_FMT_S16, pcm_u16le, "PCM unsigned 16-bit little-endian");
611 PCM_CODEC (PCM_U24BE, AV_SAMPLE_FMT_S32, pcm_u24be, "PCM unsigned 24-bit big-endian");
612 PCM_CODEC (PCM_U24LE, AV_SAMPLE_FMT_S32, pcm_u24le, "PCM unsigned 24-bit little-endian");
613 PCM_CODEC (PCM_U32BE, AV_SAMPLE_FMT_S32, pcm_u32be, "PCM unsigned 32-bit big-endian");
614 PCM_CODEC (PCM_U32LE, AV_SAMPLE_FMT_S32, pcm_u32le, "PCM unsigned 32-bit little-endian");
615 PCM_DECODER(PCM_ZORK, AV_SAMPLE_FMT_U8, pcm_zork, "PCM Zork");
616 PCM_CODEC (PCM_S64BE, AV_SAMPLE_FMT_S64, pcm_s64be, "PCM signed 64-bit big-endian");
617 PCM_CODEC (PCM_S64LE, AV_SAMPLE_FMT_S64, pcm_s64le, "PCM signed 64-bit little-endian");
const struct AVCodec * codec
Definition: avcodec.h:1770
const char * s
Definition: avisynth_c.h:768
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
This structure describes decoded (raw) audio or video data.
Definition: frame.h:201
static void pcm_alaw_tableinit(void)
Definition: pcm_tablegen.h:105
int64_t bit_rate
the average bitrate
Definition: avcodec.h:1826
static void pcm_ulaw_tableinit(void)
Definition: pcm_tablegen.h:110
const uint8_t ff_reverse[256]
Definition: reverse.c:23
#define DECODE_PLANAR(size, endian, src, dst, n, shift, offset)
Definition: pcm.c:300
static av_cold int ulaw2linear(unsigned char u_val)
Definition: pcm_tablegen.h:55
static int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Definition: pcm.c:84
int size
Definition: avcodec.h:1680
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:3164
#define src
Definition: vp8dsp.c:254
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
Definition: avcodec.h:2560
Macro definitions for various function/variable attributes.
Definition: pcm.c:227
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:32
short table[256]
Definition: pcm.c:228
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:2531
uint8_t
#define av_cold
Definition: attributes.h:82
AV_SAMPLE_FMT_U8
#define emms_c()
Definition: internal.h:54
static AVFrame * frame
const char data[16]
Definition: mxf.c:90
static av_cold int pcm_decode_close(AVCodecContext *avctx)
Definition: pcm.c:274
uint8_t * data
Definition: avcodec.h:1679
static uint8_t linear_to_ulaw[16384]
Definition: pcm_tablegen.h:79
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
Definition: avcodec.h:3157
signed 32 bits
Definition: samplefmt.h:62
#define FFALIGN(x, a)
Definition: macros.h:48
#define av_log(a,...)
static int pcm_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Definition: pcm.c:312
enum AVCodecID id
Definition: avcodec.h:3753
#define PCM_CODEC(id, sample_fmt_, name, long_name_)
Definition: pcm.c:581
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
Definition: utils.c:1709
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
Definition: float_dsp.c:127
#define AVERROR(e)
Definition: error.h:43
#define DECODE(size, endian, src, dst, n, shift, offset)
Read PCM samples macro.
Definition: pcm.c:293
#define ENCODE_PLANAR(type, endian, dst, n, shift, offset)
Definition: pcm.c:73
#define ENCODE(type, endian, src, dst, n, shift, offset)
Write PCM samples macro.
Definition: pcm.c:66
static av_cold int pcm_encode_init(AVCodecContext *avctx)
Definition: pcm.c:35
static av_cold int alaw2linear(unsigned char a_val)
Definition: pcm_tablegen.h:40
signed 32 bits, planar
Definition: samplefmt.h:68
signed 64 bits
Definition: samplefmt.h:71
int32_t
float scale
Definition: pcm.c:230
int n
Definition: avisynth_c.h:684
unsigned 8 bits, planar
Definition: samplefmt.h:66
#define AV_WN16A(p, v)
Definition: intreadwrite.h:539
static av_always_inline unsigned int bytestream_get_buffer(const uint8_t **b, uint8_t *dst, unsigned int size)
Definition: bytestream.h:359
if(ret< 0)
Definition: vf_mcdeint.c:279
int frame_size
Number of samples per channel in an audio frame.
Definition: avcodec.h:2543
Libavcodec external API header.
enum AVCodecID codec_id
Definition: avcodec.h:1778
int sample_rate
samples per second
Definition: avcodec.h:2523
main external API structure.
Definition: avcodec.h:1761
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1669
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
static av_cold int pcm_decode_init(AVCodecContext *avctx)
Definition: pcm.c:233
#define PCM_DECODER(id, sample_fmt, name, long_name)
Definition: pcm.c:578
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:215
common internal api header.
signed 16 bits
Definition: samplefmt.h:61
static double c[64]
static uint8_t linear_to_alaw[16384]
Definition: pcm_tablegen.h:78
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
Definition: bytestream.h:368
void * priv_data
Definition: avcodec.h:1803
int channels
number of audio channels
Definition: avcodec.h:2524
#define av_freep(p)
signed 16 bits, planar
Definition: samplefmt.h:67
AVFloatDSPContext * fdsp
Definition: pcm.c:229
enum AVSampleFormat * sample_fmts
array of supported sample formats, or NULL if unknown, array is terminated by -1
Definition: avcodec.h:3762
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:248
This structure stores compressed data.
Definition: avcodec.h:1656
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:267
for(j=16;j >0;--j)
static uint8_t tmp[11]
Definition: aes_ctr.c:26