75 #define ENCODE(type, endian, src, dst, n, shift, offset) \
76 samples_ ## type = (const type *) src; \
77 for (; n > 0; n--) { \
78 register type v = (*samples_ ## type++ >> shift) + offset; \
79 bytestream_put_ ## endian(&dst, v); \
83 const AVFrame *frame,
int *got_packet_ptr)
85 int n, sample_size, v, ret;
89 const int16_t *samples_int16_t;
91 const int64_t *samples_int64_t;
92 const uint16_t *samples_uint16_t;
93 const uint32_t *samples_uint32_t;
97 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)
119 ENCODE(uint32_t, le24, samples, dst, n, 8, 0x800000)
122 ENCODE(uint32_t, be24, samples, dst, n, 8, 0x800000)
126 uint32_t tmp =
ff_reverse[(*samples >> 8) & 0xff] +
129 bytestream_put_be24(&dst, tmp);
134 ENCODE(uint16_t, le16, samples, dst, n, 0, 0x8000)
137 ENCODE(uint16_t, be16, samples, dst, n, 0, 0x8000)
140 srcu8 = frame->
data[0];
148 ENCODE(int64_t, le64, samples, dst, n, 0, 0)
155 ENCODE(int16_t, le16, samples, dst, n, 0, 0)
163 ENCODE(int64_t, be64, samples, dst, n, 0, 0)
170 ENCODE(int16_t, be16, samples, dst, n, 0, 0)
178 memcpy(dst, samples, n * sample_size);
179 dst += n * sample_size;
218 for (i = 0; i < 256; i++)
222 for (i = 0; i < 256; i++)
250 #define DECODE(size, endian, src, dst, n, shift, offset) \
251 for (; n > 0; n--) { \
252 uint ## size ## _t v = bytestream_get_ ## endian(&src); \
253 AV_WN ## size ## A(dst, (v - offset) << shift); \
258 int *got_frame_ptr,
AVPacket *avpkt)
261 int buf_size = avpkt->
size;
263 int sample_size, c, n, ret, samples_per_block;
270 samples_per_block = 1;
278 samples_per_block = 2;
282 samples_per_block = 2;
286 if (sample_size == 0) {
293 if (n && buf_size % n) {
298 buf_size -= buf_size % n;
301 n = buf_size / sample_size;
313 DECODE(32, le32, src, samples, n, 0, 0x80000000)
316 DECODE(32, be32, src, samples, n, 0, 0x80000000)
319 DECODE(32, le24, src, samples, n, 8, 0)
322 DECODE(32, be24, src, samples, n, 8, 0)
325 DECODE(32, le24, src, samples, n, 8, 0x800000)
328 DECODE(32, be24, src, samples, n, 8, 0x800000)
332 uint32_t v = bytestream_get_be24(&src);
343 for (c = 0; c < avctx->
channels; c++) {
347 DECODE(16, le16, src, samples, n2, 0, 0)
349 memcpy(samples, src, n * 2);
356 DECODE(16, le16, src, samples, n, 0, 0x8000)
359 DECODE(16, be16, src, samples, n, 0, 0x8000)
363 *samples++ = *src++ + 128;
367 DECODE(64, le64, src, samples, n, 0, 0)
371 DECODE(32, le32, src, samples, n, 0, 0)
374 DECODE(16, le16, src, samples, n, 0, 0)
382 DECODE(64, be64, src, samples, n, 0, 0)
386 DECODE(32, be32, src, samples, n, 0, 0)
389 DECODE(16, be16, src, samples, n, 0, 0)
397 memcpy(samples, src, n * sample_size);
425 *dst_int32_t++ = (bytestream_get_be16(&src) << 16) + ((*src8 & 0xf0) << 8);
426 *dst_int32_t++ = (bytestream_get_be16(&src) << 16) + ((*src8++ & 0x0f) << 12);
436 *dst_int32_t++ = (bytestream_get_be16(&src) << 16) + ((*src8++) << 8);
437 *dst_int32_t++ = (bytestream_get_be16(&src) << 16) + ((*src8++) << 8);
449 for (c = 0; c < avctx->
channels; c++) {
451 for (i = 0; i < n; i++) {
453 *dst_int32_t++ = (src[2] << 28) |
456 ((src[2] & 0x0F) << 8) |
459 *dst_int32_t++ = (src[4] << 24) |
461 ((src[2] & 0xF0) << 8) |
479 #define PCM_ENCODER_0(id_, sample_fmt_, name_, long_name_)
480 #define PCM_ENCODER_1(id_, sample_fmt_, name_, long_name_) \
481 AVCodec ff_ ## name_ ## _encoder = { \
483 .type = AVMEDIA_TYPE_AUDIO, \
484 .id = AV_CODEC_ID_ ## id_, \
485 .init = pcm_encode_init, \
486 .encode2 = pcm_encode_frame, \
487 .close = pcm_encode_close, \
488 .capabilities = CODEC_CAP_VARIABLE_FRAME_SIZE, \
489 .sample_fmts = (const enum AVSampleFormat[]){ sample_fmt_, \
490 AV_SAMPLE_FMT_NONE }, \
491 .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
494 #define PCM_ENCODER_2(cf, id, sample_fmt, name, long_name) \
495 PCM_ENCODER_ ## cf(id, sample_fmt, name, long_name)
496 #define PCM_ENCODER_3(cf, id, sample_fmt, name, long_name) \
497 PCM_ENCODER_2(cf, id, sample_fmt, name, long_name)
498 #define PCM_ENCODER(id, sample_fmt, name, long_name) \
499 PCM_ENCODER_3(CONFIG_ ## id ## _ENCODER, id, sample_fmt, name, long_name)
501 #define PCM_DECODER_0(id, sample_fmt, name, long_name)
502 #define PCM_DECODER_1(id_, sample_fmt_, name_, long_name_) \
503 AVCodec ff_ ## name_ ## _decoder = { \
505 .type = AVMEDIA_TYPE_AUDIO, \
506 .id = AV_CODEC_ID_ ## id_, \
507 .priv_data_size = sizeof(PCMDecode), \
508 .init = pcm_decode_init, \
509 .decode = pcm_decode_frame, \
510 .capabilities = CODEC_CAP_DR1, \
511 .sample_fmts = (const enum AVSampleFormat[]){ sample_fmt_, \
512 AV_SAMPLE_FMT_NONE }, \
513 .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
516 #define PCM_DECODER_2(cf, id, sample_fmt, name, long_name) \
517 PCM_DECODER_ ## cf(id, sample_fmt, name, long_name)
518 #define PCM_DECODER_3(cf, id, sample_fmt, name, long_name) \
519 PCM_DECODER_2(cf, id, sample_fmt, name, long_name)
520 #define PCM_DECODER(id, sample_fmt, name, long_name) \
521 PCM_DECODER_3(CONFIG_ ## id ## _DECODER, id, sample_fmt, name, long_name)
523 #define PCM_CODEC(id, sample_fmt_, name, long_name_) \
524 PCM_ENCODER(id, sample_fmt_, name, long_name_); \
525 PCM_DECODER(id, sample_fmt_, name, long_name_)
const struct AVCodec * codec
This structure describes decoded (raw) audio or video data.
static void pcm_alaw_tableinit(void)
AVFrame * coded_frame
the picture in the bitstream
static void pcm_ulaw_tableinit(void)
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.
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
enum AVSampleFormat sample_fmt
audio sample format
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_)
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
#define DECODE(size, endian, src, dst, n, shift, offset)
Read PCM samples macro.
void av_log(void *avcl, int level, const char *fmt,...)
static av_cold int pcm_encode_close(AVCodecContext *avctx)
AVFrame * avcodec_alloc_frame(void)
Allocate an AVFrame and set its fields to default values.
#define ENCODE(type, endian, src, dst, n, shift, offset)
Write PCM samples macro.
static av_cold int pcm_encode_init(AVCodecContext *avctx)
int bit_rate
the average bitrate
static av_cold int alaw2linear(unsigned char a_val)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame)
Get a buffer for a frame.
int ff_alloc_packet(AVPacket *avpkt, int size)
Check AVPacket size and/or allocate data.
int frame_size
Number of samples per channel in an audio frame.
struct PCMDecode PCMDecode
int sample_rate
samples per second
main external API structure.
void avcodec_get_frame_defaults(AVFrame *frame)
Set the fields of the given AVFrame to default values.
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]
int channels
number of audio channels
const uint8_t ff_reverse[256]
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
if(!(ptr_align%ac->ptr_align)&&samples_align >=aligned_len)