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); \ 73 const AVFrame *frame,
int *got_packet_ptr)
75 int n, sample_size, v, ret;
79 const int16_t *samples_int16_t;
81 const int64_t *samples_int64_t;
82 const uint16_t *samples_uint16_t;
83 const uint32_t *samples_uint32_t;
87 samples = (
const short *)frame->
data[0];
97 ENCODE(uint32_t, le32, samples, dst, n, 0, 0x80000000)
100 ENCODE(uint32_t, be32, samples, dst, n, 0, 0x80000000)
109 ENCODE(uint32_t, le24, samples, dst, n, 8, 0x800000)
112 ENCODE(uint32_t, be24, samples, dst, n, 8, 0x800000)
119 bytestream_put_be24(&dst, tmp);
124 ENCODE(uint16_t, le16, samples, dst, n, 0, 0x8000)
127 ENCODE(uint16_t, be16, samples, dst, n, 0, 0x8000)
130 srcu8 = frame->
data[0];
138 ENCODE(int64_t, le64, samples, dst, n, 0, 0)
145 ENCODE(int16_t, le16, samples, dst, n, 0, 0)
153 ENCODE(int64_t, be64, samples, dst, n, 0, 0)
160 ENCODE(int16_t, be16, samples, dst, n, 0, 0)
168 memcpy(dst, samples, n * sample_size);
169 dst += n * sample_size;
207 for (i = 0; i < 256; i++)
211 for (i = 0; i < 256; i++)
236 #define DECODE(size, endian, src, dst, n, shift, offset) \ 237 for (; n > 0; n--) { \ 238 uint ## size ## _t v = bytestream_get_ ## endian(&src); \ 239 AV_WN ## size ## A(dst, (v - offset) << shift); \ 244 #define DECODE_PLANAR(size, endian, src, dst, n, shift, offset) \ 247 n /= avctx->channels; \ 248 for (c = 0; c < avctx->channels; c++) { \ 249 samples = frame->extended_data[c]; \ 251 DECODE(size, endian, src, samples, n2, 0, 0) \ 255 #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]; \ 260 memcpy(samples, src, n * size / 8); \ 261 src += n * size / 8; \ 267 int *got_frame_ptr,
AVPacket *avpkt)
270 int buf_size = avpkt->
size;
273 int sample_size, c, n, ret, samples_per_block;
280 samples_per_block = 1;
283 samples_per_block = 2;
287 if (sample_size == 0) {
294 if (n && buf_size % n) {
299 buf_size -= buf_size % n;
302 n = buf_size / sample_size;
310 samples = frame->
data[0];
314 DECODE(32, le32, src, samples, n, 0, 0x80000000)
317 DECODE(32, be32, src, samples, n, 0, 0x80000000)
320 DECODE(32, le24, src, samples, n, 8, 0)
323 DECODE(32, be24, src, samples, n, 8, 0)
326 DECODE(32, le24, src, samples, n, 8, 0x800000)
329 DECODE(32, be24, src, samples, n, 8, 0x800000)
333 uint32_t v = bytestream_get_be24(&src);
353 DECODE(16, le16, src, samples, n, 0, 0x8000)
356 DECODE(16, be16, src, samples, n, 0, 0x8000)
360 *samples++ = *src++ + 128;
364 DECODE(64, le64, src, samples, n, 0, 0)
368 DECODE(32, le32, src, samples, n, 0, 0)
371 DECODE(16, le16, src, samples, n, 0, 0)
379 DECODE(64, be64, src, samples, n, 0, 0)
383 DECODE(32, be32, src, samples, n, 0, 0)
386 DECODE(16, be16, src, samples, n, 0, 0)
394 memcpy(samples, src, n * sample_size);
415 for (c = 0; c < avctx->
channels; c++) {
417 for (i = 0; i < n; i++) {
419 *dst_int32_t++ = (src[2] << 28) |
422 ((src[2] & 0x0F) << 8) |
425 *dst_int32_t++ = (src[4] << 24) |
427 ((src[2] & 0xF0) << 8) |
444 #define PCM_ENCODER_0(id_, sample_fmt_, name_, long_name_) 445 #define PCM_ENCODER_1(id_, sample_fmt_, name_, long_name_) \ 446 AVCodec ff_ ## name_ ## _encoder = { \ 448 .long_name = NULL_IF_CONFIG_SMALL(long_name_), \ 449 .type = AVMEDIA_TYPE_AUDIO, \ 450 .id = AV_CODEC_ID_ ## id_, \ 451 .init = pcm_encode_init, \ 452 .encode2 = pcm_encode_frame, \ 453 .capabilities = AV_CODEC_CAP_VARIABLE_FRAME_SIZE, \ 454 .sample_fmts = (const enum AVSampleFormat[]){ sample_fmt_, \ 455 AV_SAMPLE_FMT_NONE }, \ 458 #define PCM_ENCODER_2(cf, id, sample_fmt, name, long_name) \ 459 PCM_ENCODER_ ## cf(id, sample_fmt, name, long_name) 460 #define PCM_ENCODER_3(cf, id, sample_fmt, name, long_name) \ 461 PCM_ENCODER_2(cf, id, sample_fmt, name, long_name) 462 #define PCM_ENCODER(id, sample_fmt, name, long_name) \ 463 PCM_ENCODER_3(CONFIG_ ## id ## _ENCODER, id, sample_fmt, name, long_name) 465 #define PCM_DECODER_0(id, sample_fmt, name, long_name) 466 #define PCM_DECODER_1(id_, sample_fmt_, name_, long_name_) \ 467 AVCodec ff_ ## name_ ## _decoder = { \ 469 .long_name = NULL_IF_CONFIG_SMALL(long_name_), \ 470 .type = AVMEDIA_TYPE_AUDIO, \ 471 .id = AV_CODEC_ID_ ## id_, \ 472 .priv_data_size = sizeof(PCMDecode), \ 473 .init = pcm_decode_init, \ 474 .decode = pcm_decode_frame, \ 475 .capabilities = AV_CODEC_CAP_DR1, \ 476 .sample_fmts = (const enum AVSampleFormat[]){ sample_fmt_, \ 477 AV_SAMPLE_FMT_NONE }, \ 480 #define PCM_DECODER_2(cf, id, sample_fmt, name, long_name) \ 481 PCM_DECODER_ ## cf(id, sample_fmt, name, long_name) 482 #define PCM_DECODER_3(cf, id, sample_fmt, name, long_name) \ 483 PCM_DECODER_2(cf, id, sample_fmt, name, long_name) 484 #define PCM_DECODER(id, sample_fmt, name, long_name) \ 485 PCM_DECODER_3(CONFIG_ ## id ## _DECODER, id, sample_fmt, name, long_name) 487 #define PCM_CODEC(id, sample_fmt_, name, long_name_) \ 488 PCM_ENCODER(id, sample_fmt_, name, long_name_); \ 489 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)
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)
av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic ? ac->func_descr_generic :ac->func_descr)
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.
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).
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.
#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