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); \
82 #define ENCODE_PLANAR(type, endian, dst, n, shift, offset) \
83 n /= avctx->channels; \
84 for (c = 0; c < avctx->channels; c++) { \
86 samples_ ## type = (const type *) frame->extended_data[c]; \
87 for (i = n; i > 0; i--) { \
88 register type v = (*samples_ ## type++ >> shift) + offset; \
89 bytestream_put_ ## endian(&dst, v); \
96 int n,
c, sample_size,
v,
ret;
100 const int16_t *samples_int16_t;
101 const int32_t *samples_int32_t;
102 const int64_t *samples_int64_t;
103 const uint16_t *samples_uint16_t;
104 const uint32_t *samples_uint32_t;
108 samples = (
const short *)frame->
data[0];
116 ENCODE(uint32_t,
le32, samples, dst, n, 0, 0x80000000)
119 ENCODE(uint32_t,
be32, samples, dst, n, 0, 0x80000000)
131 ENCODE(uint32_t,
le24, samples, dst, n, 8, 0x800000)
134 ENCODE(uint32_t,
be24, samples, dst, n, 8, 0x800000)
138 uint32_t tmp =
ff_reverse[(*samples >> 8) & 0xff] +
141 bytestream_put_be24(&dst, tmp);
146 ENCODE(uint16_t,
le16, samples, dst, n, 0, 0x8000)
149 ENCODE(uint16_t,
be16, samples, dst, n, 0, 0x8000)
198 memcpy(dst, samples, n * sample_size);
207 for (c = 0; c < avctx->
channels; c++) {
248 for (i = 0; i < 256; i++)
252 for (i = 0; i < 256; i++)
277 #define DECODE(size, endian, src, dst, n, shift, offset) \
278 for (; n > 0; n--) { \
279 uint ## size ## _t v = bytestream_get_ ## endian(&src); \
280 AV_WN ## size ## A(dst, (v - offset) << shift); \
284 #define DECODE_PLANAR(size, endian, src, dst, n, shift, offset) \
285 n /= avctx->channels; \
286 for (c = 0; c < avctx->channels; c++) { \
288 dst = frame->extended_data[c]; \
289 for (i = n; i > 0; i--) { \
290 uint ## size ## _t v = bytestream_get_ ## endian(&src); \
291 AV_WN ## size ## A(dst, (v - offset) << shift); \
297 int *got_frame_ptr,
AVPacket *avpkt)
300 int buf_size = avpkt->
size;
303 int sample_size,
c,
n,
ret, samples_per_block;
310 samples_per_block = 1;
315 "PCM DVD unsupported sample depth %i\n",
320 samples_per_block = 2;
324 samples_per_block = 2;
328 if (sample_size == 0) {
345 if (n && buf_size % n) {
348 "Invalid PCM packet, data has size %d but at least a size of %d was expected\n",
352 buf_size -= buf_size %
n;
355 n = buf_size / sample_size;
361 samples = frame->
data[0];
365 DECODE(32,
le32, src, samples, n, 0, 0x80000000)
368 DECODE(32,
be32, src, samples, n, 0, 0x80000000)
380 DECODE(32,
le24, src, samples, n, 8, 0x800000)
383 DECODE(32,
be24, src, samples, n, 8, 0x800000)
387 uint32_t
v = bytestream_get_be24(&src);
402 *samples++ = *src++ + 128;
406 for (c = 0; c < avctx->
channels; c++) {
409 for (i = n; i > 0; i--)
410 *samples++ = *src++ + 128;
454 memcpy(samples, src, n * sample_size);
463 for (c = 0; c < avctx->
channels; c++) {
494 *dst_int32_t++ = (bytestream_get_be16(&src) << 16) + ((*src8 & 0xf0) << 8);
495 *dst_int32_t++ = (bytestream_get_be16(&src) << 16) + ((*src8++ & 0x0f) << 12);
505 *dst_int32_t++ = (bytestream_get_be16(&src) << 16) + ((*src8++) << 8);
506 *dst_int32_t++ = (bytestream_get_be16(&src) << 16) + ((*src8++) << 8);
518 for (c = 0; c < avctx->
channels; c++) {
520 for (i = 0; i <
n; i++) {
522 *dst_int32_t++ = (src[2] << 28) |
525 ((src[2] & 0x0F) << 8) |
528 *dst_int32_t++ = (src[4] << 24) |
530 ((src[2] & 0xF0) << 8) |
547 #define PCM_ENCODER_0(id_, sample_fmt_, name_, long_name_)
548 #define PCM_ENCODER_1(id_, sample_fmt_, name_, long_name_) \
549 AVCodec ff_ ## name_ ## _encoder = { \
551 .type = AVMEDIA_TYPE_AUDIO, \
552 .id = AV_CODEC_ID_ ## id_, \
553 .init = pcm_encode_init, \
554 .encode2 = pcm_encode_frame, \
555 .close = pcm_encode_close, \
556 .capabilities = CODEC_CAP_VARIABLE_FRAME_SIZE, \
557 .sample_fmts = (const enum AVSampleFormat[]){ sample_fmt_, \
558 AV_SAMPLE_FMT_NONE }, \
559 .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
562 #define PCM_ENCODER_2(cf, id, sample_fmt, name, long_name) \
563 PCM_ENCODER_ ## cf(id, sample_fmt, name, long_name)
564 #define PCM_ENCODER_3(cf, id, sample_fmt, name, long_name) \
565 PCM_ENCODER_2(cf, id, sample_fmt, name, long_name)
566 #define PCM_ENCODER(id, sample_fmt, name, long_name) \
567 PCM_ENCODER_3(CONFIG_ ## id ## _ENCODER, id, sample_fmt, name, long_name)
569 #define PCM_DECODER_0(id, sample_fmt, name, long_name)
570 #define PCM_DECODER_1(id_, sample_fmt_, name_, long_name_) \
571 AVCodec ff_ ## name_ ## _decoder = { \
573 .type = AVMEDIA_TYPE_AUDIO, \
574 .id = AV_CODEC_ID_ ## id_, \
575 .priv_data_size = sizeof(PCMDecode), \
576 .init = pcm_decode_init, \
577 .decode = pcm_decode_frame, \
578 .capabilities = CODEC_CAP_DR1, \
579 .sample_fmts = (const enum AVSampleFormat[]){ sample_fmt_, \
580 AV_SAMPLE_FMT_NONE }, \
581 .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
584 #define PCM_DECODER_2(cf, id, sample_fmt, name, long_name) \
585 PCM_DECODER_ ## cf(id, sample_fmt, name, long_name)
586 #define PCM_DECODER_3(cf, id, sample_fmt, name, long_name) \
587 PCM_DECODER_2(cf, id, sample_fmt, name, long_name)
588 #define PCM_DECODER(id, sample_fmt, name, long_name) \
589 PCM_DECODER_3(CONFIG_ ## id ## _DECODER, id, sample_fmt, name, long_name)
591 #define PCM_CODEC(id, sample_fmt_, name, long_name_) \
592 PCM_ENCODER(id, sample_fmt_, name, long_name_); \
593 PCM_DECODER(id, sample_fmt_, name, long_name_)