Set up seek position correctly when a seek skips over a reel in
[dcpomatic.git] / src / lib / audio_ring_buffers.cc
index 81072474ed7203ebea62dbadf20b4cc39b866664..42115efa3e786835cfb7e62b20e31b80d8095f1f 100644 (file)
@@ -22,6 +22,7 @@
 #include "dcpomatic_assert.h"
 #include "exceptions.h"
 #include <boost/foreach.hpp>
+#include <iostream>
 
 using std::min;
 using std::cout;
@@ -34,7 +35,7 @@ AudioRingBuffers::AudioRingBuffers ()
 }
 
 void
-AudioRingBuffers::put (shared_ptr<const AudioBuffers> data, DCPTime time)
+AudioRingBuffers::put (shared_ptr<const AudioBuffers> data)
 {
        boost::mutex::scoped_lock lm (_mutex);
 
@@ -43,10 +44,10 @@ AudioRingBuffers::put (shared_ptr<const AudioBuffers> data, DCPTime time)
        }
 
        _buffers.push_back (data);
-       _latest = time;
 }
 
-void
+/** @return true if there was an underrun, otherwise false */
+bool
 AudioRingBuffers::get (float* out, int channels, int frames)
 {
        boost::mutex::scoped_lock lm (_mutex);
@@ -59,12 +60,14 @@ AudioRingBuffers::get (float* out, int channels, int frames)
                                }
                        }
                        cout << "audio underrun; missing " << frames << "!\n";
-                       return;
+                       return true;
                }
 
-               int const to_do = min (frames, _buffers.front()->frames() - _used_in_head);
-               float** p = _buffers.front()->data();
-               int const c = min (_buffers.front()->channels(), channels);
+               shared_ptr<const AudioBuffers> front = _buffers.front ();
+
+               int const to_do = min (frames, front->frames() - _used_in_head);
+               float** p = front->data();
+               int const c = min (front->channels(), channels);
                for (int i = 0; i < to_do; ++i) {
                        for (int j = 0; j < c; ++j) {
                                *out++ = p[j][i + _used_in_head];
@@ -76,11 +79,13 @@ AudioRingBuffers::get (float* out, int channels, int frames)
                _used_in_head += to_do;
                frames -= to_do;
 
-               if (_used_in_head == _buffers.front()->frames()) {
+               if (_used_in_head == front->frames()) {
                        _buffers.pop_front ();
                        _used_in_head = 0;
                }
        }
+
+       return false;
 }
 
 void
@@ -89,11 +94,10 @@ AudioRingBuffers::clear ()
        boost::mutex::scoped_lock lm (_mutex);
        _buffers.clear ();
        _used_in_head = 0;
-       _latest = DCPTime ();
 }
 
 Frame
-AudioRingBuffers::size ()
+AudioRingBuffers::size () const
 {
        boost::mutex::scoped_lock lm (_mutex);
        Frame s = 0;