28#include "config_components.h"
43#if !CONFIG_HARDCODED_TABLES
45#if CONFIG_PCM_ALAW_ENCODER
52#if CONFIG_PCM_MULAW_ENCODER
59#if CONFIG_PCM_VIDC_ENCODER
88#define ENCODE(type, endian, src, dst, n, shift, offset) \
89 samples_ ## type = (const type *) src; \
90 for (; n > 0; n--) { \
91 register type v = (*samples_ ## type++ >> shift) + offset; \
92 bytestream_put_ ## endian(&dst, v); \
95#define ENCODE_PLANAR(type, endian, dst, n, shift, offset) \
96 n /= avctx->ch_layout.nb_channels; \
97 for (c = 0; c < avctx->ch_layout.nb_channels; c++) { \
99 samples_ ## type = (const type *) frame->extended_data[c]; \
100 for (i = n; i > 0; i--) { \
101 register type v = (*samples_ ## type++ >> shift) + offset; \
102 bytestream_put_ ## endian(&dst, v); \
109 int n,
c, sample_size, ret;
110 const short *samples;
112 const uint8_t *samples_uint8_t;
113 const int16_t *samples_int16_t;
114 const int32_t *samples_int32_t;
115 const int64_t *samples_int64_t;
116 const uint16_t *samples_uint16_t;
117 const uint32_t *samples_uint32_t;
121 samples = (
const short *)
frame->data[0];
154 bytestream_put_be24(&
dst,
tmp);
165 ENCODE(uint8_t,
byte, samples,
dst, n, 0, -128)
215 memcpy(
dst, samples, n * sample_size);
225 const uint8_t *
src =
frame->extended_data[
c];
229#if CONFIG_PCM_ALAW_ENCODER
233 *
dst++ = linear_to_alaw[(v + 32768) >> 2];
237#if CONFIG_PCM_MULAW_ENCODER
241 *
dst++ = linear_to_ulaw[(v + 32768) >> 2];
245#if CONFIG_PCM_VIDC_ENCODER
249 *
dst++ = linear_to_vidc[(v + 32768) >> 2];
268 static const struct {
272 uint8_t bits_per_sample;
273 } codec_id_to_samplefmt[] = {
274 #define ENTRY(CODEC_ID, SAMPLE_FMT, BITS_PER_SAMPLE) \
275 { AV_CODEC_ID_PCM_ ## CODEC_ID, AV_SAMPLE_FMT_ ## SAMPLE_FMT, \
276 BITS_PER_SAMPLE / 8, BITS_PER_SAMPLE }
278 ENTRY(S16BE, S16, 16),
ENTRY(S16BE_PLANAR, S16P, 16),
279 ENTRY(S16LE, S16, 16),
ENTRY(S16LE_PLANAR, S16P, 16),
280 ENTRY(S24DAUD, S16, 24),
ENTRY(S24BE, S32, 24),
281 ENTRY(S24LE, S32, 24),
ENTRY(S24LE_PLANAR, S32P, 24),
283 ENTRY(S32LE_PLANAR, S32P, 32),
296 s->sample_size = codec_id_to_samplefmt[
i].sample_size;
297 avctx->
sample_fmt = codec_id_to_samplefmt[
i].sample_fmt;
321 s->base.sample_size = 4;
347 av_unreachable(
"pcm_lut_decode_init() only used with alaw, mulaw and vidc");
348#if CONFIG_PCM_ALAW_DECODER
350 for (
int i = 0;
i < 256;
i++)
351 s->table[
i] = alaw2linear(
i);
354#if CONFIG_PCM_MULAW_DECODER
356 for (
int i = 0;
i < 256;
i++)
357 s->table[
i] = ulaw2linear(
i);
360#if CONFIG_PCM_VIDC_DECODER
362 for (
int i = 0;
i < 256;
i++)
363 s->table[
i] = vidc2linear(
i);
369 s->base.sample_size = 1;
384#define DECODE(size, endian, src, dst, n, shift, offset) \
385 for (; n > 0; n--) { \
386 uint ## size ## _t v = bytestream_get_ ## endian(&src); \
387 AV_WN ## size ## A(dst, (uint ## size ## _t)(v - offset) << shift); \
391#define DECODE_PLANAR(size, endian, src, dst, n, shift, offset) \
393 for (c = 0; c < avctx->ch_layout.nb_channels; c++) { \
395 dst = frame->extended_data[c]; \
396 for (i = n; i > 0; i--) { \
397 uint ## size ## _t v = bytestream_get_ ## endian(&src); \
398 AV_WN ## size ## A(dst, (uint ## size ##_t)(v - offset) << shift); \
404 int *got_frame_ptr,
AVPacket *avpkt)
406 const uint8_t *
src = avpkt->
data;
407 int buf_size = avpkt->
size;
410 int sample_size =
s->sample_size;
411 int c, n, ret, samples_per_block;
415 samples_per_block = 1;
418 samples_per_block = 2;
433 if (n && buf_size % n) {
436 "Invalid PCM packet, data has size %d but at least a size of %d was expected\n",
440 buf_size -= buf_size % n;
443 n = buf_size / sample_size;
449 samples =
frame->data[0];
475 uint32_t v = bytestream_get_be24(&
src);
490 *samples++ = *
src++ + 128;
494 int sign = *
src >> 7;
495 int magn = *
src & 0x7f;
496 *samples++ = sign ? 128 - magn : 128 + magn;
504 samples =
frame->extended_data[
c];
505 for (
i = n;
i > 0;
i--)
506 *samples++ = *
src++ + 128;
558 memcpy(samples,
src, n * sample_size);
568 samples =
frame->extended_data[
c];
572#if CONFIG_PCM_ALAW_DECODER || CONFIG_PCM_MULAW_DECODER || \
573 CONFIG_PCM_VIDC_DECODER
578 int16_t *restrict samples_16 = (int16_t*)samples;
581 *samples_16++ = lut[*
src++];
591 for (
i = 0;
i < n;
i++) {
593 *dst_int32_t++ = ((uint32_t)
src[2]<<28) |
596 ((
src[2] & 0x0F) << 8) |
599 *dst_int32_t++ = ((uint32_t)
src[4]<<24) |
601 ((
src[2] & 0xF0) << 8) |
617 (
const float *)
frame->extended_data[0],
626#define PCM_ENCODER_0(id_, sample_fmt_, name_, long_name_)
627#define PCM_ENCODER_1(id_, sample_fmt_, name_, long_name_) \
628const FFCodec ff_ ## name_ ## _encoder = { \
630 CODEC_LONG_NAME(long_name_), \
631 .p.type = AVMEDIA_TYPE_AUDIO, \
633 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_VARIABLE_FRAME_SIZE | \
634 AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE, \
635 .init = pcm_encode_init, \
636 FF_CODEC_ENCODE_CB(pcm_encode_frame), \
637 CODEC_SAMPLEFMTS(sample_fmt_), \
640#define PCM_ENCODER_2(cf, id, sample_fmt, name, long_name) \
641 PCM_ENCODER_ ## cf(id, sample_fmt, name, long_name)
642#define PCM_ENCODER_3(cf, id, sample_fmt, name, long_name) \
643 PCM_ENCODER_2(cf, id, sample_fmt, name, long_name)
644#define PCM_ENCODER(id, sample_fmt, name, long_name) \
645 PCM_ENCODER_3(CONFIG_PCM_ ## id ## _ENCODER, AV_CODEC_ID_PCM_ ## id, \
646 AV_SAMPLE_FMT_ ## sample_fmt, pcm_ ## name, long_name)
648#define PCM_DECODER_0(id, sample_fmt, name, long_name, Context, init_func)
649#define PCM_DECODER_1(id_, sample_fmt, name_, long_name, Context, init_func)\
650const FFCodec ff_ ## name_ ## _decoder = { \
652 CODEC_LONG_NAME(long_name), \
653 .p.type = AVMEDIA_TYPE_AUDIO, \
655 .priv_data_size = sizeof(Context), \
657 FF_CODEC_DECODE_CB(pcm_decode_frame), \
658 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_PARAM_CHANGE, \
661#define PCM_DECODER_2(cf, id, sample_fmt, name, long_name, Context, init_func) \
662 PCM_DECODER_ ## cf(id, sample_fmt, name, long_name, Context, init_func)
663#define PCM_DECODER_3(cf, id, sample_fmt, name, long_name, Context, init_func) \
664 PCM_DECODER_2(cf, id, sample_fmt, name, long_name, Context, init_func)
665#define PCM_DEC_EXT(id, sample_fmt, name, long_name, Context, init_func) \
666 PCM_DECODER_3(CONFIG_PCM_ ## id ## _DECODER, AV_CODEC_ID_PCM_ ## id, \
667 AV_SAMPLE_FMT_ ## sample_fmt, pcm_ ## name, long_name, \
670#define PCM_DECODER(id, sample_fmt, name, long_name) \
671 PCM_DEC_EXT(id, sample_fmt, name, long_name, PCMDecode, pcm_decode_init)
673#define PCM_CODEC(id, sample_fmt_, name, long_name_) \
674 PCM_ENCODER(id, sample_fmt_, name, long_name_); \
675 PCM_DECODER(id, sample_fmt_, name, long_name_)
677#define PCM_CODEC_EXT(id, sample_fmt, name, long_name, DecContext, dec_init_func) \
678 PCM_DEC_EXT(id, sample_fmt, name, long_name, DecContext, dec_init_func); \
679 PCM_ENCODER(id, sample_fmt, name, long_name)
688PCM_CODEC (F32BE, FLT, f32be,
"PCM 32-bit floating point big-endian");
689PCM_CODEC (F32LE, FLT, f32le,
"PCM 32-bit floating point little-endian");
690PCM_CODEC (F64BE, DBL, f64be,
"PCM 64-bit floating point big-endian");
691PCM_CODEC (F64LE, DBL, f64le,
"PCM 64-bit floating point little-endian");
692PCM_DECODER (LXF, S32P,lxf,
"PCM signed 20-bit little-endian planar");
695PCM_CODEC (S8_PLANAR, U8P, s8_planar,
"PCM signed 8-bit planar");
696PCM_CODEC (S16BE, S16, s16be,
"PCM signed 16-bit big-endian");
697PCM_CODEC (S16BE_PLANAR, S16P,s16be_planar,
"PCM signed 16-bit big-endian planar");
698PCM_CODEC (S16LE, S16, s16le,
"PCM signed 16-bit little-endian");
699PCM_CODEC (S16LE_PLANAR, S16P,s16le_planar,
"PCM signed 16-bit little-endian planar");
700PCM_CODEC (S24BE, S32, s24be,
"PCM signed 24-bit big-endian");
701PCM_CODEC (S24DAUD, S16, s24daud,
"PCM D-Cinema audio signed 24-bit");
702PCM_CODEC (S24LE, S32, s24le,
"PCM signed 24-bit little-endian");
703PCM_CODEC (S24LE_PLANAR, S32P,s24le_planar,
"PCM signed 24-bit little-endian planar");
704PCM_CODEC (S32BE, S32, s32be,
"PCM signed 32-bit big-endian");
705PCM_CODEC (S32LE, S32, s32le,
"PCM signed 32-bit little-endian");
706PCM_CODEC (S32LE_PLANAR, S32P,s32le_planar,
"PCM signed 32-bit little-endian planar");
708PCM_CODEC (U16BE, S16, u16be,
"PCM unsigned 16-bit big-endian");
709PCM_CODEC (U16LE, S16, u16le,
"PCM unsigned 16-bit little-endian");
710PCM_CODEC (U24BE, S32, u24be,
"PCM unsigned 24-bit big-endian");
711PCM_CODEC (U24LE, S32, u24le,
"PCM unsigned 24-bit little-endian");
712PCM_CODEC (U32BE, S32, u32be,
"PCM unsigned 32-bit big-endian");
713PCM_CODEC (U32LE, S32, u32le,
"PCM unsigned 32-bit little-endian");
714PCM_CODEC (S64BE, S64, s64be,
"PCM signed 64-bit big-endian");
715PCM_CODEC (S64LE, S64, s64le,
"PCM signed 64-bit little-endian");
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
#define av_unreachable(msg)
Asserts that are used as compiler optimization hints depending upon ASSERT_LEVEL and NBDEBUG.
Libavcodec external API header.
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
static av_always_inline unsigned int bytestream_get_buffer(const uint8_t **b, uint8_t *dst, unsigned int size)
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
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL be64
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL le16
uint64_t_TMPL AV_WL64 unsigned int_TMPL le32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL le24
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
static const uint32_t S8[256]
#define i(width, name, range_min, range_max)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
AVCodecID
Identify the syntax and semantics of the bitstream.
@ AV_CODEC_ID_PCM_S16BE_PLANAR
@ AV_CODEC_ID_PCM_S32LE_PLANAR
@ AV_CODEC_ID_PCM_S24LE_PLANAR
@ AV_CODEC_ID_PCM_S24DAUD
@ AV_CODEC_ID_PCM_S16LE_PLANAR
@ AV_CODEC_ID_PCM_S8_PLANAR
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
@ AV_SAMPLE_FMT_S32
signed 32 bits
@ AV_SAMPLE_FMT_S16
signed 16 bits
#define ENTRY(CODEC_ID, SAMPLE_FMT, BITS_PER_SAMPLE)
av_unused static av_cold int pcm_scale_decode_init(AVCodecContext *avctx)
av_unused static av_cold int pcm_lut_decode_init(AVCodecContext *avctx)
av_unused static av_cold int pcm_encode_init(AVCodecContext *avctx)
#define PCM_DEC_EXT(id, sample_fmt, name, long_name, Context, init_func)
#define ENCODE_PLANAR(type, endian, dst, n, shift, offset)
av_unused static av_cold int pcm_decode_init(AVCodecContext *avctx)
#define DECODE(size, endian, src, dst, n, shift, offset)
Read PCM samples macro.
static av_unused int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
static int pcm_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
#define PCM_CODEC(id, sample_fmt_, name, long_name_)
#define ENCODE(type, endian, src, dst, n, shift, offset)
Write PCM samples macro.
#define PCM_CODEC_EXT(id, sample_fmt, name, long_name, DecContext, dec_init_func)
#define PCM_DECODER(id, sample_fmt, name, long_name)
#define DECODE_PLANAR(size, endian, src, dst, n, shift, offset)
Macro definitions for various function/variable attributes.
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
const uint8_t ff_reverse[256]
static int ff_thread_once(char *control, void(*routine)(void))
Memory handling functions.
#define FF_ARRAY_ELEMS(a)
int nb_channels
Number of channels in this layout.
main external API structure.
AVChannelLayout ch_layout
Audio channel layout.
enum AVSampleFormat sample_fmt
audio sample format
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
int64_t bit_rate
the average bitrate
const struct AVCodec * codec
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
int sample_rate
samples per second
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs.
void(* vector_fmul_scalar)(float *dst, const float *src, float mul, int len)
Multiply a vector of floats by a scalar float.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
void(* vector_fmul_scalar)(float *dst, const float *src, float mul, int len)