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;
217 for (i = 0; i < 256; i++)
221 for (i = 0; i < 256; i++)
246 #define DECODE(size, endian, src, dst, n, shift, offset) \
247 for (; n > 0; n--) { \
248 uint ## size ## _t v = bytestream_get_ ## endian(&src); \
249 AV_WN ## size ## A(dst, (v - offset) << shift); \
254 #define DECODE_PLANAR(size, endian, src, dst, n, shift, offset) \
257 n /= avctx->channels; \
258 for (c = 0; c < avctx->channels; c++) { \
259 samples = frame->extended_data[c]; \
261 DECODE(size, endian, src, samples, n2, 0, 0) \
265 #define DECODE_PLANAR(size, endian, src, dst, n, shift, offset) \
267 n /= avctx->channels; \
268 for (c = 0; c < avctx->channels; c++) { \
269 samples = frame->extended_data[c]; \
270 memcpy(samples, src, n * size / 8); \
271 src += n * size / 8; \
277 int *got_frame_ptr,
AVPacket *avpkt)
280 int buf_size = avpkt->
size;
283 int sample_size, c, n, ret, samples_per_block;
290 samples_per_block = 1;
293 samples_per_block = 2;
297 if (sample_size == 0) {
304 if (n && buf_size % n) {
309 buf_size -= buf_size % n;
312 n = buf_size / sample_size;
320 samples = frame->
data[0];
324 DECODE(32, le32, src, samples, n, 0, 0x80000000)
327 DECODE(32, be32, src, samples, n, 0, 0x80000000)
330 DECODE(32, le24, src, samples, n, 8, 0)
333 DECODE(32, be24, src, samples, n, 8, 0)
336 DECODE(32, le24, src, samples, n, 8, 0x800000)
339 DECODE(32, be24, src, samples, n, 8, 0x800000)
343 uint32_t v = bytestream_get_be24(&src);
360 DECODE(16, le16, src, samples, n, 0, 0x8000)
363 DECODE(16, be16, src, samples, n, 0, 0x8000)
367 *samples++ = *src++ + 128;
371 DECODE(64, le64, src, samples, n, 0, 0)
375 DECODE(32, le32, src, samples, n, 0, 0)
378 DECODE(16, le16, src, samples, n, 0, 0)
386 DECODE(64, be64, src, samples, n, 0, 0)
390 DECODE(32, be32, src, samples, n, 0, 0)
393 DECODE(16, be16, src, samples, n, 0, 0)
401 memcpy(samples, src, n * sample_size);
422 for (c = 0; c < avctx->
channels; c++) {
424 for (i = 0; i < n; i++) {
426 *dst_int32_t++ = (src[2] << 28) |
429 ((src[2] & 0x0F) << 8) |
432 *dst_int32_t++ = (src[4] << 24) |
434 ((src[2] & 0xF0) << 8) |
451 #define PCM_ENCODER_0(id_, sample_fmt_, name_, long_name_)
452 #define PCM_ENCODER_1(id_, sample_fmt_, name_, long_name_) \
453 AVCodec ff_ ## name_ ## _encoder = { \
455 .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
456 .type = AVMEDIA_TYPE_AUDIO, \
457 .id = AV_CODEC_ID_ ## id_, \
458 .init = pcm_encode_init, \
459 .encode2 = pcm_encode_frame, \
460 .close = pcm_encode_close, \
461 .capabilities = CODEC_CAP_VARIABLE_FRAME_SIZE, \
462 .sample_fmts = (const enum AVSampleFormat[]){ sample_fmt_, \
463 AV_SAMPLE_FMT_NONE }, \
466 #define PCM_ENCODER_2(cf, id, sample_fmt, name, long_name) \
467 PCM_ENCODER_ ## cf(id, sample_fmt, name, long_name)
468 #define PCM_ENCODER_3(cf, id, sample_fmt, name, long_name) \
469 PCM_ENCODER_2(cf, id, sample_fmt, name, long_name)
470 #define PCM_ENCODER(id, sample_fmt, name, long_name) \
471 PCM_ENCODER_3(CONFIG_ ## id ## _ENCODER, id, sample_fmt, name, long_name)
473 #define PCM_DECODER_0(id, sample_fmt, name, long_name)
474 #define PCM_DECODER_1(id_, sample_fmt_, name_, long_name_) \
475 AVCodec ff_ ## name_ ## _decoder = { \
477 .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
478 .type = AVMEDIA_TYPE_AUDIO, \
479 .id = AV_CODEC_ID_ ## id_, \
480 .priv_data_size = sizeof(PCMDecode), \
481 .init = pcm_decode_init, \
482 .decode = pcm_decode_frame, \
483 .capabilities = CODEC_CAP_DR1, \
484 .sample_fmts = (const enum AVSampleFormat[]){ sample_fmt_, \
485 AV_SAMPLE_FMT_NONE }, \
488 #define PCM_DECODER_2(cf, id, sample_fmt, name, long_name) \
489 PCM_DECODER_ ## cf(id, sample_fmt, name, long_name)
490 #define PCM_DECODER_3(cf, id, sample_fmt, name, long_name) \
491 PCM_DECODER_2(cf, id, sample_fmt, name, long_name)
492 #define PCM_DECODER(id, sample_fmt, name, long_name) \
493 PCM_DECODER_3(CONFIG_ ## id ## _DECODER, id, sample_fmt, name, long_name)
495 #define PCM_CODEC(id, sample_fmt_, name, long_name_) \
496 PCM_ENCODER(id, sample_fmt_, name, long_name_); \
497 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)
#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.
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
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
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.
#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)
#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_alloc_packet(AVPacket *avpkt, int size)
Check AVPacket size and/or allocate data.
if(ac->has_optimized_func)
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.
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