Merge remote-tracking branch 'origin/master' into 2.0
[dcpomatic.git] / src / lib / audio_decoder.cc
index e4c82f64c1a7c05d33b7f02fbf043ef5aa93b80a..f3251f306bf47284a71bc1d53917631e917c827b 100644 (file)
@@ -17,6 +17,7 @@
 
 */
 
+#include <iostream>
 #include "audio_decoder.h"
 #include "audio_buffers.h"
 #include "audio_processor.h"
@@ -25,7 +26,6 @@
 
 #include "i18n.h"
 
-using std::stringstream;
 using std::list;
 using std::pair;
 using std::cout;
@@ -80,10 +80,10 @@ AudioDecoder::get_audio (AudioFrame frame, AudioFrame length, bool accurate)
         */
        if (accurate) {
                /* Keep stuffing data into _decoded_audio until we have enough data, or the subclass does not want to give us any more */
-               while (!pass() && (_decoded_audio.frame > frame || (_decoded_audio.frame + _decoded_audio.audio->frames()) < end)) {}
+               while ((_decoded_audio.frame > frame || (_decoded_audio.frame + _decoded_audio.audio->frames()) < end) && !pass ()) {}
                decoded_offset = frame - _decoded_audio.frame;
        } else {
-               while (!pass() && _decoded_audio.audio->frames() < length) {}
+               while (_decoded_audio.audio->frames() < length && !pass ()) {}
                /* Use decoded_offset of 0, as we don't really care what frames we return */
        }
 
@@ -174,6 +174,13 @@ AudioDecoder::audio (shared_ptr<const AudioBuffers> data, ContentTime time)
 void
 AudioDecoder::add (shared_ptr<const AudioBuffers> data)
 {
+       if (!_audio_position) {
+               /* This should only happen when there is a seek followed by a flush, but
+                  we need to cope with it.
+               */
+               return;
+       }
+       
        /* Resize _decoded_audio to fit the new data */
        int new_size = 0;
        if (_decoded_audio.audio->frames() == 0) {