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); \ 73 #define ENCODE_PLANAR(type, endian, dst, n, shift, offset) \ 74 n /= avctx->channels; \ 75 for (c = 0; c < avctx->channels; c++) { \ 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); \ 87 int n,
c, sample_size, v, ret;
91 const int16_t *samples_int16_t;
93 const int64_t *samples_int64_t;
94 const uint16_t *samples_uint16_t;
95 const uint32_t *samples_uint32_t;
99 samples = (
const short *)frame->
data[0];
107 ENCODE(uint32_t, le32, samples, dst, n, 0, 0x80000000)
110 ENCODE(uint32_t, be32, samples, dst, n, 0, 0x80000000)
122 ENCODE(uint32_t, le24, samples, dst, n, 8, 0x800000)
125 ENCODE(uint32_t, be24, samples, dst, n, 8, 0x800000)
132 bytestream_put_be24(&dst, tmp);
137 ENCODE(uint16_t, le16, samples, dst, n, 0, 0x8000)
140 ENCODE(uint16_t, be16, samples, dst, n, 0, 0x8000)
151 ENCODE(int64_t, le64, samples, dst, n, 0, 0)
161 ENCODE(int16_t, le16, samples, dst, n, 0, 0)
174 ENCODE(int64_t, be64, samples, dst, n, 0, 0)
181 ENCODE(int16_t, be16, samples, dst, n, 0, 0)
193 memcpy(dst, samples, n * sample_size);
202 for (c = 0; c < avctx->
channels; c++) {
245 for (i = 0; i < 256; i++)
249 for (i = 0; i < 256; i++)
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); \ 300 #define DECODE_PLANAR(size, endian, src, dst, n, shift, offset) \ 301 n /= avctx->channels; \ 302 for (c = 0; c < avctx->channels; c++) { \ 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); \ 313 int *got_frame_ptr,
AVPacket *avpkt)
316 int buf_size = avpkt->
size;
319 int sample_size,
c,
n, ret, samples_per_block;
326 samples_per_block = 1;
329 samples_per_block = 2;
333 if (sample_size == 0) {
350 if (n && buf_size % n) {
353 "Invalid PCM packet, data has size %d but at least a size of %d was expected\n",
357 buf_size -= buf_size %
n;
360 n = buf_size / sample_size;
366 samples = frame->
data[0];
370 DECODE(32, le32, src, samples, n, 0, 0x80000000)
373 DECODE(32, be32, src, samples, n, 0, 0x80000000)
376 DECODE(32, le24, src, samples, n, 8, 0)
382 DECODE(32, be24, src, samples, n, 8, 0)
385 DECODE(32, le24, src, samples, n, 8, 0x800000)
388 DECODE(32, be24, src, samples, n, 8, 0x800000)
392 uint32_t v = bytestream_get_be24(&src);
400 DECODE(16, le16, src, samples, n, 0, 0x8000)
403 DECODE(16, be16, src, samples, n, 0, 0x8000)
407 *samples++ = *src++ + 128;
411 for (c = 0; c < avctx->
channels; c++) {
414 for (i = n; i > 0; i--)
415 *samples++ = *src++ + 128;
421 DECODE(64, le64, src, samples, n, 0, 0)
427 DECODE(32, le32, src, samples, n, 0, 0)
433 DECODE(16, le16, src, samples, n, 0, 0)
446 DECODE(64, be64, src, samples, n, 0, 0)
450 DECODE(32, be32, src, samples, n, 0, 0)
453 DECODE(16, be16, src, samples, n, 0, 0)
467 memcpy(samples, src, n * sample_size);
476 for (c = 0; c < avctx->
channels; c++) {
500 for (c = 0; c < avctx->
channels; c++) {
502 for (i = 0; i <
n; i++) {
504 *dst_int32_t++ = ((uint32_t)src[2]<<28) |
507 ((src[2] & 0x0F) << 8) |
510 *dst_int32_t++ = ((uint32_t)src[4]<<24) |
512 ((src[2] & 0xF0) << 8) |
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 = { \ 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 }, \ 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) 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 = { \ 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 }, \ 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) 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_)
const struct AVCodec * codec
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
static void pcm_alaw_tableinit(void)
int64_t bit_rate
the average bitrate
static void pcm_ulaw_tableinit(void)
const uint8_t ff_reverse[256]
#define DECODE_PLANAR(size, endian, src, dst, n, shift, offset)
static av_cold int ulaw2linear(unsigned char u_val)
static int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
Macro definitions for various function/variable attributes.
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
enum AVSampleFormat sample_fmt
audio sample format
static av_cold int pcm_decode_close(AVCodecContext *avctx)
static uint8_t linear_to_ulaw[16384]
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
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 AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
#define DECODE(size, endian, src, dst, n, shift, offset)
Read PCM samples macro.
#define ENCODE_PLANAR(type, endian, dst, n, shift, offset)
#define ENCODE(type, endian, src, dst, n, shift, offset)
Write PCM samples macro.
static av_cold int pcm_encode_init(AVCodecContext *avctx)
static av_cold int alaw2linear(unsigned char a_val)
static av_always_inline unsigned int bytestream_get_buffer(const uint8_t **b, uint8_t *dst, unsigned int size)
int frame_size
Number of samples per channel in an audio frame.
Libavcodec external API header.
int sample_rate
samples per second
main external API structure.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
void(* vector_fmul_scalar)(float *dst, const float *src, float mul, int len)
Multiply a vector of floats by a scalar float.
static av_cold int pcm_decode_init(AVCodecContext *avctx)
#define PCM_DECODER(id, sample_fmt, name, long_name)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
common internal api header.
static uint8_t linear_to_alaw[16384]
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
int channels
number of audio channels
enum AVSampleFormat * sample_fmts
array of supported sample formats, or NULL if unknown, array is terminated by -1
uint8_t ** extended_data
pointers to the data planes/channels.
This structure stores compressed data.
int nb_samples
number of audio samples (per channel) described by this frame