Go to the documentation of this file.
28 #include "config_components.h"
43 #if !CONFIG_HARDCODED_TABLES
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); \
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); \
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++) { \
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); \
98 int n,
c, sample_size, v,
ret;
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;
143 bytestream_put_be24(&dst,
tmp);
204 memcpy(dst,
samples, n * sample_size);
259 for (
i = 0;
i < 256;
i++)
263 for (
i = 0;
i < 256;
i++)
267 for (
i = 0;
i < 256;
i++)
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); \
311 #define DECODE_PLANAR(size, endian, src, dst, n, shift, offset) \
313 for (c = 0; c < avctx->ch_layout.nb_channels; c++) { \
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); \
324 int *got_frame_ptr,
AVPacket *avpkt)
326 const uint8_t *
src = avpkt->
data;
327 int buf_size = avpkt->
size;
330 int sample_size,
c, n,
ret, samples_per_block;
337 samples_per_block = 1;
340 samples_per_block = 2;
344 if (sample_size == 0) {
361 if (n && buf_size % n) {
364 "Invalid PCM packet, data has size %d but at least a size of %d was expected\n",
368 buf_size -= buf_size % n;
371 n = buf_size / sample_size;
403 uint32_t v = bytestream_get_be24(&
src);
422 int sign = *
src >> 7;
423 int magn = *
src & 0x7f;
424 *
samples++ = sign ? 128 - magn : 128 + magn;
433 for (
i = n;
i > 0;
i--)
516 *dst_int32_t++ = ((uint32_t)
src[2]<<28) |
519 ((
src[2] & 0x0F) << 8) |
522 *dst_int32_t++ = ((uint32_t)
src[4]<<24) |
524 ((
src[2] & 0xF0) << 8) |
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 = { \
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 }, \
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)
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 = { \
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 }, \
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)
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_)
int frame_size
Number of samples per channel in an audio frame.
#define PCM_CODEC(id, sample_fmt_, name, long_name_)
static uint8_t linear_to_alaw[16384]
uint64_t_TMPL AV_WL64 unsigned int_TMPL le32
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
#define ENCODE(type, endian, src, dst, n, shift, offset)
Write PCM samples macro.
int sample_rate
samples per second
static av_cold int vidc2linear(unsigned char u_val)
@ AV_CODEC_ID_PCM_S32LE_PLANAR
This structure describes decoded (raw) audio or video data.
@ AV_CODEC_ID_PCM_S16BE_PLANAR
const uint8_t ff_reverse[256]
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
int nb_channels
Number of channels in this layout.
@ AV_CODEC_ID_PCM_S16LE_PLANAR
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
const struct AVCodec * codec
AVChannelLayout ch_layout
Audio channel layout.
enum AVSampleFormat * sample_fmts
array of supported sample formats, or NULL if unknown, array is terminated by -1
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
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL le24
#define PCM_DECODER(id, sample_fmt, name, long_name)
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static uint8_t linear_to_ulaw[16384]
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
void(* vector_fmul_scalar)(float *dst, const float *src, float mul, int len)
Multiply a vector of floats by a scalar float.
int64_t bit_rate
the average bitrate
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL be64
#define DECODE_PLANAR(size, endian, src, dst, n, shift, offset)
void(* vector_fmul_scalar)(float *dst, const float *src, float mul, int len)
static int pcm_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
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 av_cold int pcm_decode_init(AVCodecContext *avctx)
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
@ AV_CODEC_ID_PCM_S24LE_PLANAR
static int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
@ AV_SAMPLE_FMT_U8P
unsigned 8 bits, planar
static av_cold int alaw2linear(unsigned char a_val)
enum AVSampleFormat sample_fmt
audio sample format
#define DECODE(size, endian, src, dst, n, shift, offset)
Read PCM samples macro.
#define ENCODE_PLANAR(type, endian, dst, n, shift, offset)
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
int nb_samples
number of audio samples (per channel) described by this frame
#define i(width, name, range_min, range_max)
@ AV_SAMPLE_FMT_U8
unsigned 8 bits
uint8_t ** extended_data
pointers to the data planes/channels.
@ AV_SAMPLE_FMT_S16
signed 16 bits
static av_always_inline unsigned int bytestream_get_buffer(const uint8_t **b, uint8_t *dst, unsigned int size)
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs.
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
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL le16
static uint8_t linear_to_vidc[16384]
main external API structure.
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
#define INIT_ONCE(id, name)
Filter the word “frame” indicates either a video frame or a group of audio samples
@ AV_CODEC_ID_PCM_S24DAUD
static av_cold int pcm_encode_init(AVCodecContext *avctx)
This structure stores compressed data.
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
@ AV_CODEC_ID_PCM_S8_PLANAR
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
@ AV_SAMPLE_FMT_DBL
double
@ AV_SAMPLE_FMT_S32
signed 32 bits
static av_cold int ulaw2linear(unsigned char u_val)
@ AV_SAMPLE_FMT_S64
signed 64 bits