Flush decoded_audio buffer on seek.
authorCarl Hetherington <cth@carlh.net>
Fri, 11 Apr 2014 09:21:02 +0000 (10:21 +0100)
committerCarl Hetherington <cth@carlh.net>
Fri, 11 Apr 2014 09:21:02 +0000 (10:21 +0100)
src/lib/audio_decoder.cc
src/lib/audio_decoder.h

index 6486d176a77d876c61a43ca33c9ef3f91aaa5052..17a534aa477489289308a8ff6e31706229ad2ca3 100644 (file)
@@ -37,11 +37,18 @@ using boost::shared_ptr;
 
 AudioDecoder::AudioDecoder (shared_ptr<const AudioContent> content)
        : _audio_content (content)
-       , _decoded_audio (shared_ptr<AudioBuffers> (new AudioBuffers (content->audio_channels(), 0)), 0)
 {
        if (content->output_audio_frame_rate() != content->content_audio_frame_rate() && content->audio_channels ()) {
                _resampler.reset (new Resampler (content->content_audio_frame_rate(), content->output_audio_frame_rate(), content->audio_channels ()));
        }
+
+       reset_decoded_audio ();
+}
+
+void
+AudioDecoder::reset_decoded_audio ()
+{
+       _decoded_audio = ContentAudio (shared_ptr<AudioBuffers> (new AudioBuffers (_audio_content->audio_channels(), 0)), 0);
 }
 
 shared_ptr<ContentAudio>
@@ -106,7 +113,7 @@ AudioDecoder::audio (shared_ptr<const AudioBuffers> data, ContentTime time)
                _audio_position = time.frames (_audio_content->output_audio_frame_rate ());
        }
 
-       assert (_audio_position >= (_decoded_audio.frame + _decoded_audio.audio->frames()));
+       assert (_audio_position.get() >= (_decoded_audio.frame + _decoded_audio.audio->frames()));
 
        /* Resize _decoded_audio to fit the new data */
        int const new_size = _audio_position.get() + data->frames() - _decoded_audio.frame;
@@ -139,4 +146,5 @@ void
 AudioDecoder::seek (ContentTime, bool)
 {
        _audio_position.reset ();
+       reset_decoded_audio ();
 }
index c83c356b7488c157dc85a6cd589dc7f256d029d5..0b0d306f647469fd4d09654338e5fd932cdd8c3e 100644 (file)
@@ -57,6 +57,7 @@ protected:
        void seek (ContentTime time, bool accurate);
        void audio (boost::shared_ptr<const AudioBuffers>, ContentTime);
        void flush ();
+       void reset_decoded_audio ();
 
        boost::shared_ptr<const AudioContent> _audio_content;
        boost::shared_ptr<Resampler> _resampler;