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) \
268 n /= avctx->channels; \
269 for (c = 0; c < avctx->channels; c++) { \
270 samples = frame->extended_data[c]; \
271 memcpy(samples, src, n * size / 8); \
272 src += n * size / 8; \
278 int *got_frame_ptr,
AVPacket *avpkt)
281 int buf_size = avpkt->
size;
284 int sample_size, c, n, ret, samples_per_block;
291 samples_per_block = 1;
294 samples_per_block = 2;
298 if (sample_size == 0) {
305 if (n && buf_size % n) {
310 buf_size -= buf_size % n;
313 n = buf_size / sample_size;
321 samples = frame->
data[0];
325 DECODE(32, le32, src, samples, n, 0, 0x80000000)
328 DECODE(32, be32, src, samples, n, 0, 0x80000000)
331 DECODE(32, le24, src, samples, n, 8, 0)
334 DECODE(32, be24, src, samples, n, 8, 0)
337 DECODE(32, le24, src, samples, n, 8, 0x800000)
340 DECODE(32, be24, src, samples, n, 8, 0x800000)
344 uint32_t v = bytestream_get_be24(&src);
361 DECODE(16, le16, src, samples, n, 0, 0x8000)
364 DECODE(16, be16, src, samples, n, 0, 0x8000)
368 *samples++ = *src++ + 128;
372 DECODE(64, le64, src, samples, n, 0, 0)
376 DECODE(32, le32, src, samples, n, 0, 0)
379 DECODE(16, le16, src, samples, n, 0, 0)
387 DECODE(64, be64, src, samples, n, 0, 0)
391 DECODE(32, be32, src, samples, n, 0, 0)
394 DECODE(16, be16, src, samples, n, 0, 0)
402 memcpy(samples, src, n * sample_size);
423 for (c = 0; c < avctx->
channels; c++) {
425 for (i = 0; i < n; i++) {
427 *dst_int32_t++ = (src[2] << 28) |
430 ((src[2] & 0x0F) << 8) |
433 *dst_int32_t++ = (src[4] << 24) |
435 ((src[2] & 0xF0) << 8) |
452 #define PCM_ENCODER_0(id_, sample_fmt_, name_, long_name_)
453 #define PCM_ENCODER_1(id_, sample_fmt_, name_, long_name_) \
454 AVCodec ff_ ## name_ ## _encoder = { \
456 .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
457 .type = AVMEDIA_TYPE_AUDIO, \
458 .id = AV_CODEC_ID_ ## id_, \
459 .init = pcm_encode_init, \
460 .encode2 = pcm_encode_frame, \
461 .close = pcm_encode_close, \
462 .capabilities = CODEC_CAP_VARIABLE_FRAME_SIZE, \
463 .sample_fmts = (const enum AVSampleFormat[]){ sample_fmt_, \
464 AV_SAMPLE_FMT_NONE }, \
467 #define PCM_ENCODER_2(cf, id, sample_fmt, name, long_name) \
468 PCM_ENCODER_ ## cf(id, sample_fmt, name, long_name)
469 #define PCM_ENCODER_3(cf, id, sample_fmt, name, long_name) \
470 PCM_ENCODER_2(cf, id, sample_fmt, name, long_name)
471 #define PCM_ENCODER(id, sample_fmt, name, long_name) \
472 PCM_ENCODER_3(CONFIG_ ## id ## _ENCODER, id, sample_fmt, name, long_name)
474 #define PCM_DECODER_0(id, sample_fmt, name, long_name)
475 #define PCM_DECODER_1(id_, sample_fmt_, name_, long_name_) \
476 AVCodec ff_ ## name_ ## _decoder = { \
478 .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
479 .type = AVMEDIA_TYPE_AUDIO, \
480 .id = AV_CODEC_ID_ ## id_, \
481 .priv_data_size = sizeof(PCMDecode), \
482 .init = pcm_decode_init, \
483 .decode = pcm_decode_frame, \
484 .capabilities = CODEC_CAP_DR1, \
485 .sample_fmts = (const enum AVSampleFormat[]){ sample_fmt_, \
486 AV_SAMPLE_FMT_NONE }, \
489 #define PCM_DECODER_2(cf, id, sample_fmt, name, long_name) \
490 PCM_DECODER_ ## cf(id, sample_fmt, name, long_name)
491 #define PCM_DECODER_3(cf, id, sample_fmt, name, long_name) \
492 PCM_DECODER_2(cf, id, sample_fmt, name, long_name)
493 #define PCM_DECODER(id, sample_fmt, name, long_name) \
494 PCM_DECODER_3(CONFIG_ ## id ## _DECODER, id, sample_fmt, name, long_name)
496 #define PCM_CODEC(id, sample_fmt_, name, long_name_) \
497 PCM_ENCODER(id, sample_fmt_, name, long_name_); \
498 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