40 #if !CONFIG_HARDCODED_TABLES
42 #define INIT_ONCE(id, name) \
43 case AV_CODEC_ID_PCM_ ## id: \
44 if (CONFIG_PCM_ ## id ## _ENCODER) { \
45 static AVOnce init_static_once = AV_ONCE_INIT; \
46 ff_thread_once(&init_static_once, pcm_ ## name ## _tableinit); \
74 #define ENCODE(type, endian, src, dst, n, shift, offset) \
75 samples_ ## type = (const type *) src; \
76 for (; n > 0; n--) { \
77 register type v = (*samples_ ## type++ >> shift) + offset; \
78 bytestream_put_ ## endian(&dst, v); \
81 #define ENCODE_PLANAR(type, endian, dst, n, shift, offset) \
82 n /= avctx->channels; \
83 for (c = 0; c < avctx->channels; c++) { \
85 samples_ ## type = (const type *) frame->extended_data[c]; \
86 for (i = n; i > 0; i--) { \
87 register type v = (*samples_ ## type++ >> shift) + offset; \
88 bytestream_put_ ## endian(&dst, v); \
95 int n,
c, sample_size, v, ret;
99 const int16_t *samples_int16_t;
100 const int32_t *samples_int32_t;
101 const int64_t *samples_int64_t;
102 const uint16_t *samples_uint16_t;
103 const uint32_t *samples_uint32_t;
115 ENCODE(uint32_t, le32, samples, dst, n, 0, 0x80000000)
118 ENCODE(uint32_t, be32, samples, dst, n, 0, 0x80000000)
130 ENCODE(uint32_t, le24, samples, dst, n, 8, 0x800000)
133 ENCODE(uint32_t, be24, samples, dst, n, 8, 0x800000)
140 bytestream_put_be24(&dst,
tmp);
145 ENCODE(uint16_t, le16, samples, dst, n, 0, 0x8000)
148 ENCODE(uint16_t, be16, samples, dst, n, 0, 0x8000)
159 ENCODE(int64_t, le64, samples, dst, n, 0, 0)
169 ENCODE(int16_t, le16, samples, dst, n, 0, 0)
182 ENCODE(int64_t, be64, samples, dst, n, 0, 0)
189 ENCODE(int16_t, be16, samples, dst, n, 0, 0)
201 memcpy(dst, samples, n * sample_size);
261 for (
i = 0;
i < 256;
i++)
265 for (
i = 0;
i < 256;
i++)
269 for (
i = 0;
i < 256;
i++)
306 #define DECODE(size, endian, src, dst, n, shift, offset) \
307 for (; n > 0; n--) { \
308 uint ## size ## _t v = bytestream_get_ ## endian(&src); \
309 AV_WN ## size ## A(dst, (uint ## size ## _t)(v - offset) << shift); \
313 #define DECODE_PLANAR(size, endian, src, dst, n, shift, offset) \
314 n /= avctx->channels; \
315 for (c = 0; c < avctx->channels; c++) { \
317 dst = frame->extended_data[c]; \
318 for (i = n; i > 0; i--) { \
319 uint ## size ## _t v = bytestream_get_ ## endian(&src); \
320 AV_WN ## size ## A(dst, (uint ## size ##_t)(v - offset) << shift); \
326 int *got_frame_ptr,
AVPacket *avpkt)
329 int buf_size = avpkt->
size;
332 int sample_size,
c, n, ret, samples_per_block;
339 samples_per_block = 1;
342 samples_per_block = 2;
346 if (sample_size == 0) {
363 if (n && buf_size % n) {
366 "Invalid PCM packet, data has size %d but at least a size of %d was expected\n",
370 buf_size -= buf_size % n;
373 n = buf_size / sample_size;
383 DECODE(32, le32,
src, samples, n, 0, 0x80000000)
386 DECODE(32, be32,
src, samples, n, 0, 0x80000000)
398 DECODE(32, le24,
src, samples, n, 8, 0x800000)
401 DECODE(32, be24,
src, samples, n, 8, 0x800000)
405 uint32_t v = bytestream_get_be24(&
src);
413 DECODE(16, le16,
src, samples, n, 0, 0x8000)
416 DECODE(16, be16,
src, samples, n, 0, 0x8000)
420 *samples++ = *
src++ + 128;
424 int sign = *
src >> 7;
425 int magn = *
src & 0x7f;
426 *samples++ = sign ? 128 - magn : 128 + magn;
435 for (
i = n;
i > 0;
i--)
436 *samples++ = *
src++ + 128;
488 memcpy(samples,
src, n * sample_size);
518 *dst_int32_t++ = ((uint32_t)
src[2]<<28) |
521 ((
src[2] & 0x0F) << 8) |
524 *dst_int32_t++ = ((uint32_t)
src[4]<<24) |
526 ((
src[2] & 0xF0) << 8) |
551 #define PCM_ENCODER_0(id_, sample_fmt_, name_, long_name_)
552 #define PCM_ENCODER_1(id_, sample_fmt_, name_, long_name_) \
553 AVCodec ff_ ## name_ ## _encoder = { \
555 .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
556 .type = AVMEDIA_TYPE_AUDIO, \
557 .id = AV_CODEC_ID_ ## id_, \
558 .init = pcm_encode_init, \
559 .encode2 = pcm_encode_frame, \
560 .capabilities = AV_CODEC_CAP_VARIABLE_FRAME_SIZE, \
561 .sample_fmts = (const enum AVSampleFormat[]){ sample_fmt_, \
562 AV_SAMPLE_FMT_NONE }, \
563 .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, \
566 #define PCM_ENCODER_2(cf, id, sample_fmt, name, long_name) \
567 PCM_ENCODER_ ## cf(id, sample_fmt, name, long_name)
568 #define PCM_ENCODER_3(cf, id, sample_fmt, name, long_name) \
569 PCM_ENCODER_2(cf, id, sample_fmt, name, long_name)
570 #define PCM_ENCODER(id, sample_fmt, name, long_name) \
571 PCM_ENCODER_3(CONFIG_ ## id ## _ENCODER, id, sample_fmt, name, long_name)
573 #define PCM_DECODER_0(id, sample_fmt, name, long_name)
574 #define PCM_DECODER_1(id_, sample_fmt_, name_, long_name_) \
575 AVCodec ff_ ## name_ ## _decoder = { \
577 .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
578 .type = AVMEDIA_TYPE_AUDIO, \
579 .id = AV_CODEC_ID_ ## id_, \
580 .priv_data_size = sizeof(PCMDecode), \
581 .init = pcm_decode_init, \
582 .decode = pcm_decode_frame, \
583 .capabilities = AV_CODEC_CAP_DR1, \
584 .sample_fmts = (const enum AVSampleFormat[]){ sample_fmt_, \
585 AV_SAMPLE_FMT_NONE }, \
586 .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, \
589 #define PCM_DECODER_2(cf, id, sample_fmt, name, long_name) \
590 PCM_DECODER_ ## cf(id, sample_fmt, name, long_name)
591 #define PCM_DECODER_3(cf, id, sample_fmt, name, long_name) \
592 PCM_DECODER_2(cf, id, sample_fmt, name, long_name)
593 #define PCM_DECODER(id, sample_fmt, name, long_name) \
594 PCM_DECODER_3(CONFIG_ ## id ## _DECODER, id, sample_fmt, name, long_name)
596 #define PCM_CODEC(id, sample_fmt_, name, long_name_) \
597 PCM_ENCODER(id, sample_fmt_, name, long_name_); \
598 PCM_DECODER(id, sample_fmt_, name, long_name_)
Macro definitions for various function/variable attributes.
Libavcodec external API header.
static av_always_inline unsigned int bytestream_get_buffer(const uint8_t **b, uint8_t *dst, unsigned int size)
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static float mul(float src0, float src1)
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
@ 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
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
@ AV_SAMPLE_FMT_S64
signed 64 bits
@ AV_SAMPLE_FMT_U8P
unsigned 8 bits, planar
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
@ AV_SAMPLE_FMT_S32
signed 32 bits
@ AV_SAMPLE_FMT_DBL
double
@ AV_SAMPLE_FMT_S16
signed 16 bits
#define INIT_ONCE(id, name)
static int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
#define ENCODE_PLANAR(type, endian, dst, n, shift, offset)
#define DECODE(size, endian, src, dst, n, shift, offset)
Read PCM samples macro.
static av_cold int pcm_encode_init(AVCodecContext *avctx)
static av_cold int pcm_decode_init(AVCodecContext *avctx)
static int pcm_decode_frame(AVCodecContext *avctx, void *data, 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_DECODER(id, sample_fmt, name, long_name)
#define DECODE_PLANAR(size, endian, src, dst, n, shift, offset)
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
common internal API header
const uint8_t ff_reverse[256]
static av_cold int ulaw2linear(unsigned char u_val)
static av_cold int alaw2linear(unsigned char a_val)
static av_cold int vidc2linear(unsigned char u_val)
static uint8_t linear_to_alaw[16384]
static uint8_t linear_to_ulaw[16384]
static uint8_t linear_to_vidc[16384]
typedef void(RENAME(mix_any_func_type))
main external API structure.
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 channels
number of audio channels
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs.
int frame_size
Number of samples per channel in an audio frame.
enum AVSampleFormat * sample_fmts
array of supported sample formats, or NULL if unknown, array is terminated by -1
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.
int nb_samples
number of audio samples (per channel) described by this frame
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
uint8_t ** extended_data
pointers to the data planes/channels.
This structure stores compressed data.
void(* vector_fmul_scalar)(float *dst, const float *src, float mul, int len)