Try to clean up resampler output correctly.
authorCarl Hetherington <cth@carlh.net>
Wed, 24 Jul 2013 14:53:54 +0000 (15:53 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 24 Jul 2013 14:53:54 +0000 (15:53 +0100)
src/lib/player.cc
src/lib/player.h
src/lib/resampler.cc

index f90cf32f5c3f228a35726017837de3c08a40492e..37f172f1da72ea922f7a69dc018e9151bbdd3dc1 100644 (file)
@@ -191,6 +191,18 @@ Player::pass ()
                        cout << "Pass " << *earliest << "\n";
 #endif                 
                        earliest->decoder->pass ();
+                       
+                       if (earliest->decoder->done()) {
+                               shared_ptr<AudioContent> ac = dynamic_pointer_cast<AudioContent> (earliest->content);
+                               assert (ac);
+                               shared_ptr<Resampler> re = resampler (ac, false);
+                               if (re) {
+                                       shared_ptr<const AudioBuffers> b = re->flush ();
+                                       if (b->frames ()) {
+                                               process_audio (earliest, b, ac->audio_length ());
+                                       }
+                               }
+                       }
                }
                break;
        }
@@ -267,7 +279,7 @@ Player::process_audio (weak_ptr<Piece> weak_piece, shared_ptr<const AudioBuffers
 
        /* Resample */
        if (content->content_audio_frame_rate() != content->output_audio_frame_rate()) {
-               shared_ptr<Resampler> r = resampler (content);
+               shared_ptr<Resampler> r = resampler (content, true);
                audio = r->run (audio);
        }
 
@@ -501,12 +513,16 @@ Player::set_video_container_size (libdcp::Size s)
 }
 
 shared_ptr<Resampler>
-Player::resampler (shared_ptr<AudioContent> c)
+Player::resampler (shared_ptr<AudioContent> c, bool create)
 {
        map<shared_ptr<AudioContent>, shared_ptr<Resampler> >::iterator i = _resamplers.find (c);
        if (i != _resamplers.end ()) {
                return i->second;
        }
+
+       if (!create) {
+               return shared_ptr<Resampler> ();
+       }
        
        shared_ptr<Resampler> r (new Resampler (c->content_audio_frame_rate(), c->output_audio_frame_rate(), c->audio_channels()));
        _resamplers[c] = r;
index 8b28f010de67facb93f108c0eaaa5015f3c4e2e8..baaa8579166a0837be3e8f3a4783b662941f8b43 100644 (file)
@@ -90,7 +90,7 @@ private:
        void flush ();
        void emit_black ();
        void emit_silence (OutputAudioFrame);
-       boost::shared_ptr<Resampler> resampler (boost::shared_ptr<AudioContent>);
+       boost::shared_ptr<Resampler> resampler (boost::shared_ptr<AudioContent>, bool);
        void film_changed (Film::Property);
        void update_subtitle ();
 
index 565fb69c29b127240b956b64e75f744bce5df8e9..2a4320bd8523efb6124a58b9f072d16f6827ece8 100644 (file)
@@ -42,6 +42,8 @@ Resampler::Resampler (int in, int out, int channels)
           input and output layouts are the same.
        */
 
+       cout << "resamp for " << _channels << " " << _in_rate << " " << _out_rate << "\n";
+
        _swr_context = swr_alloc_set_opts (
                0,
                av_get_default_channel_layout (_channels),
@@ -80,7 +82,6 @@ Resampler::run (shared_ptr<const AudioBuffers> in)
        return resampled;
 }      
 
-/* XXX: no-one calls this */
 shared_ptr<const AudioBuffers>
 Resampler::flush ()
 {