summaryrefslogtreecommitdiff
path: root/libavcodec/pcm.c
diff options
context:
space:
mode:
authorLars Täuber <lars.taeuber@gmx.net>2008-05-17 11:42:03 +0000
committerDiego Biurrun <diego@biurrun.de>2008-05-17 11:42:03 +0000
commit1472b7dd2824513894f779125c298f0ad991ad04 (patch)
tree62fd52458f237a41fbc52bcca47bbee6b33642e8 /libavcodec/pcm.c
parent8f89843475110309d57077ed1d4aa405a623be1c (diff)
LPCM 24 bits support, patch by Lars Täuber, lars.taeuber gmx net
Originally committed as revision 13187 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/pcm.c')
-rw-r--r--libavcodec/pcm.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/libavcodec/pcm.c b/libavcodec/pcm.c
index 2c8281128d..065f27a1ba 100644
--- a/libavcodec/pcm.c
+++ b/libavcodec/pcm.c
@@ -383,16 +383,22 @@ static int pcm_decode_frame(AVCodecContext *avctx,
samples = data;
src = buf;
- n= av_get_bits_per_sample(avctx->codec_id)/8;
- if(n && buf_size % n){
- av_log(avctx, AV_LOG_ERROR, "invalid PCM packet\n");
- return -1;
- }
if(avctx->channels <= 0 || avctx->channels > MAX_CHANNELS){
av_log(avctx, AV_LOG_ERROR, "PCM channels out of bounds\n");
return -1;
}
+ n = avctx->channels * av_get_bits_per_sample(avctx->codec_id)/8;
+ /* av_get_bits_per_sample returns 0 for CODEC_ID_PCM_DVD */
+ if (CODEC_ID_PCM_DVD == avctx->codec_id)
+ /* 2 samples are interleaved per block in PCM_DVD */
+ n = 2 * avctx->channels * avctx->bits_per_sample/8;
+
+ if(n && buf_size % n){
+ av_log(avctx, AV_LOG_ERROR, "invalid PCM packet\n");
+ return -1;
+ }
+
buf_size= FFMIN(buf_size, *data_size/2);
*data_size=0;
@@ -492,6 +498,20 @@ static int pcm_decode_frame(AVCodecContext *avctx,
*samples++ = s->table[*src++];
}
break;
+ case CODEC_ID_PCM_DVD:
+ if(avctx->bits_per_sample != 20 && avctx->bits_per_sample != 24) {
+ av_log(avctx, AV_LOG_ERROR, "PCM DVD unsupported sample depth\n");
+ return -1;
+ } else {
+ int jump = avctx->channels * (avctx->bits_per_sample-16) / 4;
+ n = buf_size / (avctx->channels * 2 * avctx->bits_per_sample / 8);
+ while (n--) {
+ for (c=0; c < 2*avctx->channels; c++)
+ *samples++ = bytestream_get_be16(&src);
+ src += jump;
+ }
+ }
+ break;
default:
return -1;
}
@@ -537,6 +557,7 @@ AVCodec name ## _decoder = { \
PCM_ENCODER(id,name,long_name_) PCM_DECODER(id,name,long_name_)
PCM_CODEC (CODEC_ID_PCM_ALAW, pcm_alaw, "A-law PCM");
+PCM_CODEC (CODEC_ID_PCM_DVD, pcm_dvd, "signed 16|20|24-bit big-endian PCM");
PCM_CODEC (CODEC_ID_PCM_MULAW, pcm_mulaw, "mu-law PCM");
PCM_CODEC (CODEC_ID_PCM_S8, pcm_s8, "signed 8-bit PCM");
PCM_CODEC (CODEC_ID_PCM_S16BE, pcm_s16be, "signed 16-bit big-endian PCM");