Move _state_timer into VideoView.
[dcpomatic.git] / src / wx / video_view.cc
index 22cad3979dbdc44cb18375f51e9487aa2a7ee09c..e6588865641670b388a2643c761d7d070547902a 100644 (file)
 #include "film_viewer.h"
 #include "lib/butler.h"
 
+VideoView::VideoView (FilmViewer* viewer)
+       : _viewer (viewer)
+#ifdef DCPOMATIC_VARIANT_SWAROOP
+       , _in_watermark (false)
+#endif
+       , _state_timer ("viewer")
+       , _video_frame_rate (0)
+       , _dropped (0)
+{
+
+}
+
 void
 VideoView::clear ()
 {
+       boost::mutex::scoped_lock lm (_mutex);
        _player_video.first.reset ();
        _player_video.second = dcpomatic::DCPTime ();
 }
@@ -36,9 +49,15 @@ VideoView::clear ()
 bool
 VideoView::get_next_frame (bool non_blocking)
 {
+       if (_length == dcpomatic::DCPTime()) {
+               return true;
+       }
+
        DCPOMATIC_ASSERT (_viewer->butler());
        _viewer->_gets++;
 
+       boost::mutex::scoped_lock lm (_mutex);
+
        do {
                Butler::Error e;
                _player_video = _viewer->butler()->get_video (!non_blocking, &e);
@@ -52,11 +71,35 @@ VideoView::get_next_frame (bool non_blocking)
                _player_video.first->eyes() != EYES_BOTH
                );
 
-       try {
-               _viewer->butler()->rethrow ();
-       } catch (DecodeError& e) {
-               error_dialog (get(), e.what());
+       return true;
+}
+
+dcpomatic::DCPTime
+VideoView::one_video_frame () const
+{
+       return dcpomatic::DCPTime::from_frames (1, video_frame_rate());
+}
+
+/** @return Time in ms until the next frame is due */
+int
+VideoView::time_until_next_frame () const
+{
+       if (length() == dcpomatic::DCPTime()) {
+               /* There's no content, so this doesn't matter */
+               return 0;
        }
 
-       return true;
+       dcpomatic::DCPTime const next = position() + one_video_frame();
+       dcpomatic::DCPTime const time = _viewer->audio_time().get_value_or(position());
+       if (next < time) {
+               return 0;
+       }
+       return (next.seconds() - time.seconds()) * 1000;
+}
+
+void
+VideoView::start ()
+{
+       boost::mutex::scoped_lock lm (_mutex);
+       _dropped = 0;
 }