65 #define ENCODE(type, endian, src, dst, n, shift, offset) \
66 samples_ ## type = (const type *) src; \
67 for (; n > 0; n--) { \
68 register type v = (*samples_ ## type++ >> shift) + offset; \
69 bytestream_put_ ## endian(&dst, v); \
72 #define ENCODE_PLANAR(type, endian, dst, n, shift, offset) \
73 n /= avctx->channels; \
74 for (c = 0; c < avctx->channels; c++) { \
76 samples_ ## type = (const type *) frame->extended_data[c]; \
77 for (i = n; i > 0; i--) { \
78 register type v = (*samples_ ## type++ >> shift) + offset; \
79 bytestream_put_ ## endian(&dst, v); \
86 int n,
c, sample_size,
v,
ret;
90 const int16_t *samples_int16_t;
92 const int64_t *samples_int64_t;
93 const uint16_t *samples_uint16_t;
94 const uint32_t *samples_uint32_t;
98 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)
121 ENCODE(uint32_t,
le24, samples, dst, n, 8, 0x800000)
124 ENCODE(uint32_t,
be24, samples, dst, n, 8, 0x800000)
128 uint32_t tmp =
ff_reverse[(*samples >> 8) & 0xff] +
131 bytestream_put_be24(&dst, tmp);
136 ENCODE(uint16_t,
le16, samples, dst, n, 0, 0x8000)
139 ENCODE(uint16_t,
be16, samples, dst, n, 0, 0x8000)
188 memcpy(dst, samples, n * sample_size);
197 for (c = 0; c < avctx->
channels; c++) {
238 for (i = 0; i < 256; i++)
242 for (i = 0; i < 256; i++)
267 #define DECODE(size, endian, src, dst, n, shift, offset) \
268 for (; n > 0; n--) { \
269 uint ## size ## _t v = bytestream_get_ ## endian(&src); \
270 AV_WN ## size ## A(dst, (v - offset) << shift); \
274 #define DECODE_PLANAR(size, endian, src, dst, n, shift, offset) \
275 n /= avctx->channels; \
276 for (c = 0; c < avctx->channels; c++) { \
278 dst = frame->extended_data[c]; \
279 for (i = n; i > 0; i--) { \
280 uint ## size ## _t v = bytestream_get_ ## endian(&src); \
281 AV_WN ## size ## A(dst, (v - offset) << shift); \
287 int *got_frame_ptr,
AVPacket *avpkt)
290 int buf_size = avpkt->
size;
293 int sample_size,
c,
n,
ret, samples_per_block;
300 samples_per_block = 1;
303 samples_per_block = 2;
307 if (sample_size == 0) {
324 if (n && buf_size % n) {
327 "Invalid PCM packet, data has size %d but at least a size of %d was expected\n",
331 buf_size -= buf_size %
n;
334 n = buf_size / sample_size;
340 samples = frame->
data[0];
344 DECODE(32,
le32, src, samples, n, 0, 0x80000000)
347 DECODE(32,
be32, src, samples, n, 0, 0x80000000)
359 DECODE(32,
le24, src, samples, n, 8, 0x800000)
362 DECODE(32,
be24, src, samples, n, 8, 0x800000)
366 uint32_t
v = bytestream_get_be24(&src);
381 *samples++ = *src++ + 128;
385 for (c = 0; c < avctx->
channels; c++) {
388 for (i = n; i > 0; i--)
389 *samples++ = *src++ + 128;
433 memcpy(samples, src, n * sample_size);
442 for (c = 0; c < avctx->
channels; c++) {
466 for (c = 0; c < avctx->
channels; c++) {
468 for (i = 0; i <
n; i++) {
470 *dst_int32_t++ = (src[2] << 28) |
473 ((src[2] & 0x0F) << 8) |
476 *dst_int32_t++ = (src[4] << 24) |
478 ((src[2] & 0xF0) << 8) |
495 #define PCM_ENCODER_0(id_, sample_fmt_, name_, long_name_)
496 #define PCM_ENCODER_1(id_, sample_fmt_, name_, long_name_) \
497 AVCodec ff_ ## name_ ## _encoder = { \
499 .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
500 .type = AVMEDIA_TYPE_AUDIO, \
501 .id = AV_CODEC_ID_ ## id_, \
502 .init = pcm_encode_init, \
503 .encode2 = pcm_encode_frame, \
504 .capabilities = CODEC_CAP_VARIABLE_FRAME_SIZE, \
505 .sample_fmts = (const enum AVSampleFormat[]){ sample_fmt_, \
506 AV_SAMPLE_FMT_NONE }, \
509 #define PCM_ENCODER_2(cf, id, sample_fmt, name, long_name) \
510 PCM_ENCODER_ ## cf(id, sample_fmt, name, long_name)
511 #define PCM_ENCODER_3(cf, id, sample_fmt, name, long_name) \
512 PCM_ENCODER_2(cf, id, sample_fmt, name, long_name)
513 #define PCM_ENCODER(id, sample_fmt, name, long_name) \
514 PCM_ENCODER_3(CONFIG_ ## id ## _ENCODER, id, sample_fmt, name, long_name)
516 #define PCM_DECODER_0(id, sample_fmt, name, long_name)
517 #define PCM_DECODER_1(id_, sample_fmt_, name_, long_name_) \
518 AVCodec ff_ ## name_ ## _decoder = { \
520 .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
521 .type = AVMEDIA_TYPE_AUDIO, \
522 .id = AV_CODEC_ID_ ## id_, \
523 .priv_data_size = sizeof(PCMDecode), \
524 .init = pcm_decode_init, \
525 .decode = pcm_decode_frame, \
526 .capabilities = CODEC_CAP_DR1, \
527 .sample_fmts = (const enum AVSampleFormat[]){ sample_fmt_, \
528 AV_SAMPLE_FMT_NONE }, \
531 #define PCM_DECODER_2(cf, id, sample_fmt, name, long_name) \
532 PCM_DECODER_ ## cf(id, sample_fmt, name, long_name)
533 #define PCM_DECODER_3(cf, id, sample_fmt, name, long_name) \
534 PCM_DECODER_2(cf, id, sample_fmt, name, long_name)
535 #define PCM_DECODER(id, sample_fmt, name, long_name) \
536 PCM_DECODER_3(CONFIG_ ## id ## _DECODER, id, sample_fmt, name, long_name)
538 #define PCM_CODEC(id, sample_fmt_, name, long_name_) \
539 PCM_ENCODER(id, sample_fmt_, name, long_name_); \
540 PCM_DECODER(id, sample_fmt_, name, long_name_)
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and/or allocate data.
const struct AVCodec * codec
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
static void pcm_alaw_tableinit(void)
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.
uint64_t_TMPL AV_WL64 unsigned int_TMPL le32
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).
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL be24
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.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL be64
#define ENCODE_PLANAR(type, endian, dst, n, shift, offset)
Libavcodec external API header.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL be16
#define ENCODE(type, endian, src, dst, n, shift, offset)
Write PCM samples macro.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL le24
static av_cold int pcm_encode_init(AVCodecContext *avctx)
int bit_rate
the average bitrate
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.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_WB16 unsigned int_TMPL byte
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.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL be32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL le16
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
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