Commit 287ba997 authored by Peter Ross's avatar Peter Ross

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
parent 4af92de6
......@@ -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);
......
......@@ -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
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment