Merge remote-tracking branch 'origin/master' into 2.0
[dcpomatic.git] / src / lib / audio_decoder.cc
index f425cf2808cfbf70d53f3ff2bf097a24ab0ba035..f3251f306bf47284a71bc1d53917631e917c827b 100644 (file)
@@ -17,6 +17,7 @@
 
 */
 
+#include <iostream>
 #include "audio_decoder.h"
 #include "audio_buffers.h"
 #include "audio_processor.h"
@@ -79,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 */
        }
 
@@ -173,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) {