Browse code

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

Peter Ross authored on 2008/09/04 19:18:04
Showing 3 changed files
... ...
@@ -524,6 +524,8 @@ static void do_audio_out(AVFormatContext *s,
524 524
     int size_out, frame_bytes, ret;
525 525
     AVCodecContext *enc= ost->st->codec;
526 526
     AVCodecContext *dec= ist->st->codec;
527
+    int osize= av_get_bits_per_sample_format(enc->sample_fmt)/8;
528
+    int isize= av_get_bits_per_sample_format(dec->sample_fmt)/8;
527 529
 
528 530
     /* SC: dynamic allocation of buffers */
529 531
     if (!audio_buf)
... ...
@@ -622,8 +624,8 @@ static void do_audio_out(AVFormatContext *s,
622 622
         buftmp = audio_buf;
623 623
         size_out = audio_resample(ost->resample,
624 624
                                   (short *)buftmp, (short *)buf,
625
-                                  size / (ist->st->codec->channels * 2));
626
-        size_out = size_out * enc->channels * 2;
625
+                                  size / (ist->st->codec->channels * isize));
626
+        size_out = size_out * enc->channels * osize;
627 627
     } else {
628 628
         buftmp = buf;
629 629
         size_out = size;
... ...
@@ -632,17 +634,15 @@ static void do_audio_out(AVFormatContext *s,
632 632
     if (dec->sample_fmt!=enc->sample_fmt) {
633 633
         const void *ibuf[6]= {buftmp};
634 634
         void *obuf[6]= {audio_out2};
635
-        int istride[6]= {av_get_bits_per_sample_format(dec->sample_fmt)/8};
636
-        int ostride[6]= {av_get_bits_per_sample_format(enc->sample_fmt)/8};
635
+        int istride[6]= {isize};
636
+        int ostride[6]= {osize};
637 637
         int len= size_out/istride[0];
638 638
         if (av_audio_convert(ost->reformat_ctx, obuf, ostride, ibuf, istride, len)<0) {
639 639
             printf("av_audio_convert() failed\n");
640 640
             return;
641 641
         }
642 642
         buftmp = audio_out2;
643
-        /* FIXME: existing code assume that size_out equals framesize*channels*2
644
-                  remove this legacy cruft */
645
-        size_out = len*2;
643
+        size_out = len*osize;
646 644
     }
647 645
 
648 646
     /* now encode as many frames as possible */
... ...
@@ -654,7 +654,7 @@ static void do_audio_out(AVFormatContext *s,
654 654
         }
655 655
         av_fifo_generic_write(&ost->fifo, buftmp, size_out, NULL);
656 656
 
657
-        frame_bytes = enc->frame_size * 2 * enc->channels;
657
+        frame_bytes = enc->frame_size * osize * enc->channels;
658 658
 
659 659
         while (av_fifo_size(&ost->fifo) >= frame_bytes) {
660 660
             AVPacket pkt;
... ...
@@ -679,36 +679,17 @@ static void do_audio_out(AVFormatContext *s,
679 679
         }
680 680
     } else {
681 681
         AVPacket pkt;
682
+        int coded_bps = av_get_bits_per_sample(enc->codec->id)/8;
682 683
         av_init_packet(&pkt);
683 684
 
684
-        ost->sync_opts += size_out / (2 * enc->channels);
685
+        ost->sync_opts += size_out / (osize * enc->channels);
685 686
 
686 687
         /* output a pcm frame */
687
-        /* XXX: change encoding codec API to avoid this ? */
688
-        switch(enc->codec->id) {
689
-        case CODEC_ID_PCM_S32LE:
690
-        case CODEC_ID_PCM_S32BE:
691
-        case CODEC_ID_PCM_U32LE:
692
-        case CODEC_ID_PCM_U32BE:
693
-        case CODEC_ID_PCM_F32BE:
694
-            size_out = size_out << 1;
695
-            break;
696
-        case CODEC_ID_PCM_S24LE:
697
-        case CODEC_ID_PCM_S24BE:
698
-        case CODEC_ID_PCM_U24LE:
699
-        case CODEC_ID_PCM_U24BE:
700
-        case CODEC_ID_PCM_S24DAUD:
701
-            size_out = size_out / 2 * 3;
702
-            break;
703
-        case CODEC_ID_PCM_S16LE:
704
-        case CODEC_ID_PCM_S16BE:
705
-        case CODEC_ID_PCM_U16LE:
706
-        case CODEC_ID_PCM_U16BE:
707
-            break;
708
-        default:
709
-            size_out = size_out >> 1;
710
-            break;
711
-        }
688
+        /* determine the size of the coded buffer */
689
+        size_out /= osize;
690
+        if (coded_bps)
691
+            size_out *= coded_bps;
692
+
712 693
         //FIXME pass ost->sync_opts as AVFrame.pts in avcodec_encode_audio()
713 694
         ret = avcodec_encode_audio(enc, audio_out, size_out,
714 695
                                    (short *)buftmp);
... ...
@@ -265,18 +265,18 @@ stddev:    0.00 PSNR:999.99 bytes:  1058444/  1058444
265 265
 2116824 ./tests/data/a-pcm_f32be.au
266 266
 95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.vsynth.out.wav
267 267
 stddev:    0.00 PSNR:999.99 bytes:  1058444/  1058444
268
-2e38d92746dc232b6d9947271c1d6b18 *./tests/data/a-pcm_f32le.wav
269
-529256 ./tests/data/a-pcm_f32le.wav
270
-d50de60eddcebf645fb73c3468ce3dc5 *./tests/data/pcm.vsynth.out.wav
271
-stddev:10682.28 PSNR: 15.75 bytes:   264644/  1058444
272
-7e537c073be3660dc389ea94b55682a6 *./tests/data/a-pcm_f64be.au
273
-529224 ./tests/data/a-pcm_f64be.au
274
-060e8edf8a21807a87e54edba4a9bfe8 *./tests/data/pcm.vsynth.out.wav
275
-stddev:10705.84 PSNR: 15.73 bytes:   132344/  1058444
276
-6e2bbd21c2d4ba083e8de45017161141 *./tests/data/a-pcm_f64le.wav
277
-529256 ./tests/data/a-pcm_f64le.wav
278
-060e8edf8a21807a87e54edba4a9bfe8 *./tests/data/pcm.vsynth.out.wav
279
-stddev:10705.84 PSNR: 15.73 bytes:   132344/  1058444
268
+4104d0804a80fb8d02952ca5103b1012 *./tests/data/a-pcm_f32le.wav
269
+2116856 ./tests/data/a-pcm_f32le.wav
270
+95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.vsynth.out.wav
271
+stddev:    0.00 PSNR:999.99 bytes:  1058444/  1058444
272
+8112296b1ed94f72f20d04b1a54850a7 *./tests/data/a-pcm_f64be.au
273
+4233624 ./tests/data/a-pcm_f64be.au
274
+95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.vsynth.out.wav
275
+stddev:    0.00 PSNR:999.99 bytes:  1058444/  1058444
276
+26598accec99bdbaf76d575045aca7a9 *./tests/data/a-pcm_f64le.wav
277
+4233656 ./tests/data/a-pcm_f64le.wav
278
+95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.vsynth.out.wav
279
+stddev:    0.00 PSNR:999.99 bytes:  1058444/  1058444
280 280
 8c74234928ed425b1171211a89f67ead *./tests/data/a-pcm_zork.wav
281 281
 529256 ./tests/data/a-pcm_zork.wav
282 282
 864c8c866ac25642c29a13b122c70709 *./tests/data/pcm.vsynth.out.wav
... ...
@@ -265,18 +265,18 @@ stddev:    0.00 PSNR:999.99 bytes:  1058444/  1058444
265 265
 2116824 ./tests/data/a-pcm_f32be.au
266 266
 95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.rotozoom.out.wav
267 267
 stddev:    0.00 PSNR:999.99 bytes:  1058444/  1058444
268
-2e38d92746dc232b6d9947271c1d6b18 *./tests/data/a-pcm_f32le.wav
269
-529256 ./tests/data/a-pcm_f32le.wav
270
-d50de60eddcebf645fb73c3468ce3dc5 *./tests/data/pcm.rotozoom.out.wav
271
-stddev:10682.28 PSNR: 15.75 bytes:   264644/  1058444
272
-7e537c073be3660dc389ea94b55682a6 *./tests/data/a-pcm_f64be.au
273
-529224 ./tests/data/a-pcm_f64be.au
274
-060e8edf8a21807a87e54edba4a9bfe8 *./tests/data/pcm.rotozoom.out.wav
275
-stddev:10705.84 PSNR: 15.73 bytes:   132344/  1058444
276
-6e2bbd21c2d4ba083e8de45017161141 *./tests/data/a-pcm_f64le.wav
277
-529256 ./tests/data/a-pcm_f64le.wav
278
-060e8edf8a21807a87e54edba4a9bfe8 *./tests/data/pcm.rotozoom.out.wav
279
-stddev:10705.84 PSNR: 15.73 bytes:   132344/  1058444
268
+4104d0804a80fb8d02952ca5103b1012 *./tests/data/a-pcm_f32le.wav
269
+2116856 ./tests/data/a-pcm_f32le.wav
270
+95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.rotozoom.out.wav
271
+stddev:    0.00 PSNR:999.99 bytes:  1058444/  1058444
272
+8112296b1ed94f72f20d04b1a54850a7 *./tests/data/a-pcm_f64be.au
273
+4233624 ./tests/data/a-pcm_f64be.au
274
+95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.rotozoom.out.wav
275
+stddev:    0.00 PSNR:999.99 bytes:  1058444/  1058444
276
+26598accec99bdbaf76d575045aca7a9 *./tests/data/a-pcm_f64le.wav
277
+4233656 ./tests/data/a-pcm_f64le.wav
278
+95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.rotozoom.out.wav
279
+stddev:    0.00 PSNR:999.99 bytes:  1058444/  1058444
280 280
 8c74234928ed425b1171211a89f67ead *./tests/data/a-pcm_zork.wav
281 281
 529256 ./tests/data/a-pcm_zork.wav
282 282
 864c8c866ac25642c29a13b122c70709 *./tests/data/pcm.rotozoom.out.wav