Rename TYPE_DEBUG_PLAYER to TYPE_DEBUG_VIDEO_VIEW.
[dcpomatic.git] / src / lib / audio_ring_buffers.cc
index f51ff8a38860e03b7d3e867b9fea9e861d46ead4..cd7f4f597fbfaf8f35ebcd5e998f3e20edccb72d 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2016-2018 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2016-2019 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
@@ -31,6 +31,7 @@ using std::pair;
 using std::list;
 using boost::shared_ptr;
 using boost::optional;
+using namespace dcpomatic;
 
 AudioRingBuffers::AudioRingBuffers ()
        : _used_in_head (0)
@@ -38,14 +39,19 @@ AudioRingBuffers::AudioRingBuffers ()
 
 }
 
+/** @param frame_rate Frame rate in use; this is only used to check timing consistency of the incoming data */
 void
-AudioRingBuffers::put (shared_ptr<const AudioBuffers> data, DCPTime time)
+AudioRingBuffers::put (shared_ptr<const AudioBuffers> data, DCPTime time, int frame_rate)
 {
        boost::mutex::scoped_lock lm (_mutex);
 
        if (!_buffers.empty()) {
                DCPOMATIC_ASSERT (_buffers.front().first->channels() == data->channels());
-               DCPOMATIC_ASSERT ((_buffers.back().second + DCPTime::from_frames(_buffers.back().first->frames(), 48000)) == time);
+               DCPTime const end = (_buffers.back().second + DCPTime::from_frames(_buffers.back().first->frames(), frame_rate));
+               if (labs(end.get() - time.get()) > 1) {
+                       cout << "bad put " << to_string(_buffers.back().second) << " " << _buffers.back().first->frames() << " " << to_string(time) << "\n";
+               }
+               DCPOMATIC_ASSERT (labs(end.get() - time.get()) < 2);
        }
 
        _buffers.push_back(make_pair(data, time));
@@ -98,6 +104,16 @@ AudioRingBuffers::get (float* out, int channels, int frames)
        return time;
 }
 
+optional<DCPTime>
+AudioRingBuffers::peek () const
+{
+       boost::mutex::scoped_lock lm (_mutex);
+       if (_buffers.empty()) {
+               return optional<DCPTime>();
+       }
+       return _buffers.front().second;
+}
+
 void
 AudioRingBuffers::clear ()
 {