33 #define MAX_CHANNELS 64
74 #define ENCODE(type, endian, src, dst, n, shift, offset) \
75 samples_##type = (const type*) src; \
77 register type v = (*samples_##type++ >> shift) + offset; \
78 bytestream_put_##endian(&dst, v); \
82 const AVFrame *frame,
int *got_packet_ptr)
84 int n, sample_size,
v, ret;
88 const int16_t *samples_int16_t;
89 const int32_t *samples_int32_t;
90 const int64_t *samples_int64_t;
91 const uint16_t *samples_uint16_t;
92 const uint32_t *samples_uint32_t;
96 samples = (
const short *)frame->
data[0];
106 ENCODE(uint32_t, le32, samples, dst, n, 0, 0x80000000)
109 ENCODE(uint32_t, be32, samples, dst, n, 0, 0x80000000)
112 ENCODE(int32_t, le24, samples, dst, n, 8, 0)
115 ENCODE(int32_t, be24, samples, dst, n, 8, 0)
118 ENCODE(uint32_t, le24, samples, dst, n, 8, 0x800000)
121 ENCODE(uint32_t, be24, samples, dst, n, 8, 0x800000)
125 uint32_t tmp =
av_reverse[(*samples >> 8) & 0xff] +
128 bytestream_put_be24(&dst, tmp);
133 ENCODE(uint16_t, le16, samples, dst, n, 0, 0x8000)
136 ENCODE(uint16_t, be16, samples, dst, n, 0, 0x8000)
139 srcu8 = frame->
data[0];
147 ENCODE(int64_t, le64, samples, dst, n, 0, 0)
151 ENCODE(int32_t, le32, samples, dst, n, 0, 0)
154 ENCODE(int16_t, le16, samples, dst, n, 0, 0)
162 ENCODE(int64_t, be64, samples, dst, n, 0, 0)
166 ENCODE(int32_t, be32, samples, dst, n, 0, 0)
169 ENCODE(int16_t, be16, samples, dst, n, 0, 0)
177 memcpy(dst, samples, n*sample_size);
178 dst += n*sample_size;
250 #define DECODE(size, endian, src, dst, n, shift, offset) \
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)
260 const uint8_t *src = avpkt->
data;
261 int buf_size = avpkt->
size;
263 int sample_size, c, n, ret, samples_per_block;
265 int32_t *dst_int32_t;
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);
344 src2[c] = &src[c*n*2];
347 AV_WN16A(samples, bytestream_get_le16(&src2[c]));
353 DECODE(16, le16, src, samples, n, 0, 0x8000)
356 DECODE(16, be16, src, samples, n, 0, 0x8000)
360 *samples++ = *src++ + 128;
365 DECODE(64, le64, src, samples, n, 0, 0)
369 DECODE(32, le32, src, samples, n, 0, 0)
372 DECODE(16, le16, src, samples, n, 0, 0)
380 DECODE(64, be64, src, samples, n, 0, 0)
384 DECODE(32, be32, src, samples, n, 0, 0)
387 DECODE(16, be16, src, samples, n, 0, 0)
395 memcpy(samples, src, n*sample_size);
415 dst_int32_t = (int32_t *)s->
frame.
data[0];
423 *dst_int32_t++ = (bytestream_get_be16(&src) << 16) + ((*src8 &0xf0) << 8);
424 *dst_int32_t++ = (bytestream_get_be16(&src) << 16) + ((*src8++ &0x0f) << 12);
434 *dst_int32_t++ = (bytestream_get_be16(&src) << 16) + ((*src8++) << 8);
435 *dst_int32_t++ = (bytestream_get_be16(&src) << 16) + ((*src8++) << 8);
447 dst_int32_t = (int32_t *)s->
frame.
data[0];
450 for (i = 0; i < n; i++) {
451 for (c = 0, src8 = src + i*5; c < avctx->
channels; c++, src8 += n*5) {
453 *dst_int32_t++ = (src8[2] << 28) | (src8[1] << 20) | (src8[0] << 12) |
454 ((src8[2] & 0xF) << 8) | src8[1];
457 for (c = 0, src8 = src + i*5; c < avctx->
channels; c++, src8 += n*5) {
459 *dst_int32_t++ = (src8[4] << 24) | (src8[3] << 16) |
460 ((src8[2] & 0xF0) << 8) | (src8[4] << 4) | (src8[3] >> 4);
476 #define PCM_ENCODER(id_,sample_fmt_,name_,long_name_) \
477 AVCodec ff_ ## name_ ## _encoder = { \
479 .type = AVMEDIA_TYPE_AUDIO, \
481 .init = pcm_encode_init, \
482 .encode2 = pcm_encode_frame, \
483 .close = pcm_encode_close, \
484 .capabilities = CODEC_CAP_VARIABLE_FRAME_SIZE, \
485 .sample_fmts = (const enum AVSampleFormat[]){sample_fmt_,AV_SAMPLE_FMT_NONE}, \
486 .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
489 #define PCM_ENCODER(id,sample_fmt_,name,long_name_)
493 #define PCM_DECODER(id_,sample_fmt_,name_,long_name_) \
494 AVCodec ff_ ## name_ ## _decoder = { \
496 .type = AVMEDIA_TYPE_AUDIO, \
498 .priv_data_size = sizeof(PCMDecode), \
499 .init = pcm_decode_init, \
500 .decode = pcm_decode_frame, \
501 .capabilities = CODEC_CAP_DR1, \
502 .sample_fmts = (const enum AVSampleFormat[]){sample_fmt_,AV_SAMPLE_FMT_NONE}, \
503 .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
506 #define PCM_DECODER(id,sample_fmt_,name,long_name_)
509 #define PCM_CODEC(id, sample_fmt_, name, long_name_) \
510 PCM_ENCODER(id,sample_fmt_,name,long_name_); PCM_DECODER(id,sample_fmt_,name,long_name_)
const uint8_t av_reverse[256]
#define PCM_DECODER(id, sample_fmt_, name, long_name_)
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...
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).
int av_get_bits_per_sample(enum CodecID codec_id)
Return codec bits per sample.
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 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)
static av_cold int alaw2linear(unsigned char a_val)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame)
int ff_alloc_packet(AVPacket *avpkt, int size)
Check AVPacket size and/or allocate data.
int frame_size
Samples per packet, initialized when calling 'init'.
struct PCMDecode PCMDecode
main external API structure.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static av_cold int pcm_decode_init(AVCodecContext *avctx)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
common internal api header.
common internal and external API header
static uint8_t linear_to_alaw[16384]
int channels
number of audio channels
int key_frame
1 -> keyframe, 0-> not
void avcodec_get_frame_defaults(AVFrame *pic)
Set the fields of the given AVFrame to default values.
enum AVSampleFormat * sample_fmts
array of supported sample formats, or NULL if unknown, array is terminated by -1
int nb_samples
number of audio samples (per channel) described by this frame