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)
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)
192 memcpy(dst, samples, n * sample_size);
201 for (c = 0; c < avctx->
channels; c++) {
242 for (i = 0; i < 256; i++)
246 for (i = 0; i < 256; i++)
271 #define DECODE(size, endian, src, dst, n, shift, offset) \
272 for (; n > 0; n--) { \
273 uint ## size ## _t v = bytestream_get_ ## endian(&src); \
274 AV_WN ## size ## A(dst, (v - offset) << shift); \
278 #define DECODE_PLANAR(size, endian, src, dst, n, shift, offset) \
279 n /= avctx->channels; \
280 for (c = 0; c < avctx->channels; c++) { \
282 dst = frame->extended_data[c]; \
283 for (i = n; i > 0; i--) { \
284 uint ## size ## _t v = bytestream_get_ ## endian(&src); \
285 AV_WN ## size ## A(dst, (v - offset) << shift); \
291 int *got_frame_ptr,
AVPacket *avpkt)
294 int buf_size = avpkt->
size;
297 int sample_size,
c,
n, ret, samples_per_block;
304 samples_per_block = 1;
307 samples_per_block = 2;
311 if (sample_size == 0) {
328 if (n && buf_size % n) {
331 "Invalid PCM packet, data has size %d but at least a size of %d was expected\n",
335 buf_size -= buf_size %
n;
338 n = buf_size / sample_size;
344 samples = frame->
data[0];
348 DECODE(32,
le32, src, samples, n, 0, 0x80000000)
351 DECODE(32,
be32, src, samples, n, 0, 0x80000000)
363 DECODE(32,
le24, src, samples, n, 8, 0x800000)
366 DECODE(32,
be24, src, samples, n, 8, 0x800000)
370 uint32_t v = bytestream_get_be24(&src);
385 *samples++ = *src++ + 128;
389 for (c = 0; c < avctx->
channels; c++) {
392 for (i = n; i > 0; i--)
393 *samples++ = *src++ + 128;
441 memcpy(samples, src, n * sample_size);
450 for (c = 0; c < avctx->
channels; c++) {
474 for (c = 0; c < avctx->
channels; c++) {
476 for (i = 0; i <
n; i++) {
478 *dst_int32_t++ = (src[2] << 28) |
481 ((src[2] & 0x0F) << 8) |
484 *dst_int32_t++ = (src[4] << 24) |
486 ((src[2] & 0xF0) << 8) |
503 #define PCM_ENCODER_0(id_, sample_fmt_, name_, long_name_)
504 #define PCM_ENCODER_1(id_, sample_fmt_, name_, long_name_) \
505 AVCodec ff_ ## name_ ## _encoder = { \
507 .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
508 .type = AVMEDIA_TYPE_AUDIO, \
509 .id = AV_CODEC_ID_ ## id_, \
510 .init = pcm_encode_init, \
511 .encode2 = pcm_encode_frame, \
512 .capabilities = AV_CODEC_CAP_VARIABLE_FRAME_SIZE, \
513 .sample_fmts = (const enum AVSampleFormat[]){ sample_fmt_, \
514 AV_SAMPLE_FMT_NONE }, \
517 #define PCM_ENCODER_2(cf, id, sample_fmt, name, long_name) \
518 PCM_ENCODER_ ## cf(id, sample_fmt, name, long_name)
519 #define PCM_ENCODER_3(cf, id, sample_fmt, name, long_name) \
520 PCM_ENCODER_2(cf, id, sample_fmt, name, long_name)
521 #define PCM_ENCODER(id, sample_fmt, name, long_name) \
522 PCM_ENCODER_3(CONFIG_ ## id ## _ENCODER, id, sample_fmt, name, long_name)
524 #define PCM_DECODER_0(id, sample_fmt, name, long_name)
525 #define PCM_DECODER_1(id_, sample_fmt_, name_, long_name_) \
526 AVCodec ff_ ## name_ ## _decoder = { \
528 .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
529 .type = AVMEDIA_TYPE_AUDIO, \
530 .id = AV_CODEC_ID_ ## id_, \
531 .priv_data_size = sizeof(PCMDecode), \
532 .init = pcm_decode_init, \
533 .decode = pcm_decode_frame, \
534 .capabilities = AV_CODEC_CAP_DR1, \
535 .sample_fmts = (const enum AVSampleFormat[]){ sample_fmt_, \
536 AV_SAMPLE_FMT_NONE }, \
539 #define PCM_DECODER_2(cf, id, sample_fmt, name, long_name) \
540 PCM_DECODER_ ## cf(id, sample_fmt, name, long_name)
541 #define PCM_DECODER_3(cf, id, sample_fmt, name, long_name) \
542 PCM_DECODER_2(cf, id, sample_fmt, name, long_name)
543 #define PCM_DECODER(id, sample_fmt, name, long_name) \
544 PCM_DECODER_3(CONFIG_ ## id ## _DECODER, id, sample_fmt, name, long_name)
546 #define PCM_CODEC(id, sample_fmt_, name, long_name_) \
547 PCM_ENCODER(id, sample_fmt_, name, long_name_); \
548 PCM_DECODER(id, sample_fmt_, name, long_name_)
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)
int64_t bit_rate
the average bitrate
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
const uint8_t ff_reverse[256]
#define ENCODE_PLANAR(type, endian, dst, n, shift, offset)
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)
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.
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 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)
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
#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
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