From 287ba997b5a4df061a0f6efb1cc7e2ae67831f7e Mon Sep 17 00:00:00 2001 From: Peter Ross Date: Thu, 4 Sep 2008 10:18:04 +0000 Subject: [PATCH] Remove further 1sample=2byte assumptions within FFmpeg to allow F32LE/F64BE/F64LE audio to be encoded properly. Originally committed as revision 15192 to svn://svn.ffmpeg.org/ffmpeg/trunk --- ffmpeg.c | 49 +++++++++++------------------------ tests/ffmpeg.regression.ref | 24 ++++++++--------- tests/rotozoom.regression.ref | 24 ++++++++--------- 3 files changed, 39 insertions(+), 58 deletions(-) diff --git a/ffmpeg.c b/ffmpeg.c index 91dca40cf4..76d157f1a3 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -524,6 +524,8 @@ static void do_audio_out(AVFormatContext *s, int size_out, frame_bytes, ret; AVCodecContext *enc= ost->st->codec; AVCodecContext *dec= ist->st->codec; + int osize= av_get_bits_per_sample_format(enc->sample_fmt)/8; + int isize= av_get_bits_per_sample_format(dec->sample_fmt)/8; /* SC: dynamic allocation of buffers */ if (!audio_buf) @@ -622,8 +624,8 @@ static void do_audio_out(AVFormatContext *s, buftmp = audio_buf; size_out = audio_resample(ost->resample, (short *)buftmp, (short *)buf, - size / (ist->st->codec->channels * 2)); - size_out = size_out * enc->channels * 2; + size / (ist->st->codec->channels * isize)); + size_out = size_out * enc->channels * osize; } else { buftmp = buf; size_out = size; @@ -632,17 +634,15 @@ static void do_audio_out(AVFormatContext *s, if (dec->sample_fmt!=enc->sample_fmt) { const void *ibuf[6]= {buftmp}; void *obuf[6]= {audio_out2}; - int istride[6]= {av_get_bits_per_sample_format(dec->sample_fmt)/8}; - int ostride[6]= {av_get_bits_per_sample_format(enc->sample_fmt)/8}; + int istride[6]= {isize}; + int ostride[6]= {osize}; int len= size_out/istride[0]; if (av_audio_convert(ost->reformat_ctx, obuf, ostride, ibuf, istride, len)<0) { printf("av_audio_convert() failed\n"); return; } buftmp = audio_out2; - /* FIXME: existing code assume that size_out equals framesize*channels*2 - remove this legacy cruft */ - size_out = len*2; + size_out = len*osize; } /* now encode as many frames as possible */ @@ -654,7 +654,7 @@ static void do_audio_out(AVFormatContext *s, } av_fifo_generic_write(&ost->fifo, buftmp, size_out, NULL); - frame_bytes = enc->frame_size * 2 * enc->channels; + frame_bytes = enc->frame_size * osize * enc->channels; while (av_fifo_size(&ost->fifo) >= frame_bytes) { AVPacket pkt; @@ -679,36 +679,17 @@ static void do_audio_out(AVFormatContext *s, } } else { AVPacket pkt; + int coded_bps = av_get_bits_per_sample(enc->codec->id)/8; av_init_packet(&pkt); - ost->sync_opts += size_out / (2 * enc->channels); + ost->sync_opts += size_out / (osize * enc->channels); /* output a pcm frame */ - /* XXX: change encoding codec API to avoid this ? */ - switch(enc->codec->id) { - case CODEC_ID_PCM_S32LE: - case CODEC_ID_PCM_S32BE: - case CODEC_ID_PCM_U32LE: - case CODEC_ID_PCM_U32BE: - case CODEC_ID_PCM_F32BE: - size_out = size_out << 1; - break; - case CODEC_ID_PCM_S24LE: - case CODEC_ID_PCM_S24BE: - case CODEC_ID_PCM_U24LE: - case CODEC_ID_PCM_U24BE: - case CODEC_ID_PCM_S24DAUD: - size_out = size_out / 2 * 3; - break; - case CODEC_ID_PCM_S16LE: - case CODEC_ID_PCM_S16BE: - case CODEC_ID_PCM_U16LE: - case CODEC_ID_PCM_U16BE: - break; - default: - size_out = size_out >> 1; - break; - } + /* determine the size of the coded buffer */ + size_out /= osize; + if (coded_bps) + size_out *= coded_bps; + //FIXME pass ost->sync_opts as AVFrame.pts in avcodec_encode_audio() ret = avcodec_encode_audio(enc, audio_out, size_out, (short *)buftmp); diff --git a/tests/ffmpeg.regression.ref b/tests/ffmpeg.regression.ref index f96e68d046..643bb98bfe 100644 --- a/tests/ffmpeg.regression.ref +++ b/tests/ffmpeg.regression.ref @@ -265,18 +265,18 @@ stddev: 0.00 PSNR:999.99 bytes: 1058444/ 1058444 2116824 ./tests/data/a-pcm_f32be.au 95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.vsynth.out.wav stddev: 0.00 PSNR:999.99 bytes: 1058444/ 1058444 -2e38d92746dc232b6d9947271c1d6b18 *./tests/data/a-pcm_f32le.wav -529256 ./tests/data/a-pcm_f32le.wav -d50de60eddcebf645fb73c3468ce3dc5 *./tests/data/pcm.vsynth.out.wav -stddev:10682.28 PSNR: 15.75 bytes: 264644/ 1058444 -7e537c073be3660dc389ea94b55682a6 *./tests/data/a-pcm_f64be.au -529224 ./tests/data/a-pcm_f64be.au -060e8edf8a21807a87e54edba4a9bfe8 *./tests/data/pcm.vsynth.out.wav -stddev:10705.84 PSNR: 15.73 bytes: 132344/ 1058444 -6e2bbd21c2d4ba083e8de45017161141 *./tests/data/a-pcm_f64le.wav -529256 ./tests/data/a-pcm_f64le.wav -060e8edf8a21807a87e54edba4a9bfe8 *./tests/data/pcm.vsynth.out.wav -stddev:10705.84 PSNR: 15.73 bytes: 132344/ 1058444 +4104d0804a80fb8d02952ca5103b1012 *./tests/data/a-pcm_f32le.wav +2116856 ./tests/data/a-pcm_f32le.wav +95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.vsynth.out.wav +stddev: 0.00 PSNR:999.99 bytes: 1058444/ 1058444 +8112296b1ed94f72f20d04b1a54850a7 *./tests/data/a-pcm_f64be.au +4233624 ./tests/data/a-pcm_f64be.au +95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.vsynth.out.wav +stddev: 0.00 PSNR:999.99 bytes: 1058444/ 1058444 +26598accec99bdbaf76d575045aca7a9 *./tests/data/a-pcm_f64le.wav +4233656 ./tests/data/a-pcm_f64le.wav +95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.vsynth.out.wav +stddev: 0.00 PSNR:999.99 bytes: 1058444/ 1058444 8c74234928ed425b1171211a89f67ead *./tests/data/a-pcm_zork.wav 529256 ./tests/data/a-pcm_zork.wav 864c8c866ac25642c29a13b122c70709 *./tests/data/pcm.vsynth.out.wav diff --git a/tests/rotozoom.regression.ref b/tests/rotozoom.regression.ref index c5c89634ca..1a71f4cd76 100644 --- a/tests/rotozoom.regression.ref +++ b/tests/rotozoom.regression.ref @@ -265,18 +265,18 @@ stddev: 0.00 PSNR:999.99 bytes: 1058444/ 1058444 2116824 ./tests/data/a-pcm_f32be.au 95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.rotozoom.out.wav stddev: 0.00 PSNR:999.99 bytes: 1058444/ 1058444 -2e38d92746dc232b6d9947271c1d6b18 *./tests/data/a-pcm_f32le.wav -529256 ./tests/data/a-pcm_f32le.wav -d50de60eddcebf645fb73c3468ce3dc5 *./tests/data/pcm.rotozoom.out.wav -stddev:10682.28 PSNR: 15.75 bytes: 264644/ 1058444 -7e537c073be3660dc389ea94b55682a6 *./tests/data/a-pcm_f64be.au -529224 ./tests/data/a-pcm_f64be.au -060e8edf8a21807a87e54edba4a9bfe8 *./tests/data/pcm.rotozoom.out.wav -stddev:10705.84 PSNR: 15.73 bytes: 132344/ 1058444 -6e2bbd21c2d4ba083e8de45017161141 *./tests/data/a-pcm_f64le.wav -529256 ./tests/data/a-pcm_f64le.wav -060e8edf8a21807a87e54edba4a9bfe8 *./tests/data/pcm.rotozoom.out.wav -stddev:10705.84 PSNR: 15.73 bytes: 132344/ 1058444 +4104d0804a80fb8d02952ca5103b1012 *./tests/data/a-pcm_f32le.wav +2116856 ./tests/data/a-pcm_f32le.wav +95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.rotozoom.out.wav +stddev: 0.00 PSNR:999.99 bytes: 1058444/ 1058444 +8112296b1ed94f72f20d04b1a54850a7 *./tests/data/a-pcm_f64be.au +4233624 ./tests/data/a-pcm_f64be.au +95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.rotozoom.out.wav +stddev: 0.00 PSNR:999.99 bytes: 1058444/ 1058444 +26598accec99bdbaf76d575045aca7a9 *./tests/data/a-pcm_f64le.wav +4233656 ./tests/data/a-pcm_f64le.wav +95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.rotozoom.out.wav +stddev: 0.00 PSNR:999.99 bytes: 1058444/ 1058444 8c74234928ed425b1171211a89f67ead *./tests/data/a-pcm_zork.wav 529256 ./tests/data/a-pcm_zork.wav 864c8c866ac25642c29a13b122c70709 *./tests/data/pcm.rotozoom.out.wav