From: Carl Hetherington Date: Sat, 23 Nov 2019 09:42:16 +0000 (+0100) Subject: Don't busy-wait when there's nothing to play. X-Git-Tag: v2.15.40^2~6 X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=89e92b3e7effafd2ca3aa1e9300777f2d2fb6183 Don't busy-wait when there's nothing to play. --- diff --git a/src/wx/gl_video_view.cc b/src/wx/gl_video_view.cc index ddae9bb3c..a461939a7 100644 --- a/src/wx/gl_video_view.cc +++ b/src/wx/gl_video_view.cc @@ -334,13 +334,17 @@ try } draw (inter_position, inter_size); - while (time_until_next_frame() < 5) { + while (true) { + optional n = time_until_next_frame(); + if (!n || *n > 5) { + break; + } get_next_frame (true); add_dropped (); } boost::this_thread::interruption_point (); - dcpomatic_sleep_milliseconds (time_until_next_frame()); + dcpomatic_sleep_milliseconds (time_until_next_frame().get_value_or(0)); } /* XXX: leaks _context, but that seems preferable to deleting it here diff --git a/src/wx/simple_video_view.cc b/src/wx/simple_video_view.cc index 6eabbc0b0..e349b865c 100644 --- a/src/wx/simple_video_view.cc +++ b/src/wx/simple_video_view.cc @@ -159,7 +159,7 @@ SimpleVideoView::timer () } LOG_DEBUG_PLAYER("%1 -> %2; delay %3", next.seconds(), _viewer->time().seconds(), max((next.seconds() - _viewer->time().seconds()) * 1000, 1.0)); - _timer.Start (time_until_next_frame(), wxTIMER_ONE_SHOT); + _timer.Start (time_until_next_frame().get_value_or(0), wxTIMER_ONE_SHOT); if (_viewer->butler()) { _viewer->butler()->rethrow (); diff --git a/src/wx/video_view.cc b/src/wx/video_view.cc index 7f93f765e..4edc2cd23 100644 --- a/src/wx/video_view.cc +++ b/src/wx/video_view.cc @@ -22,8 +22,10 @@ #include "wx_util.h" #include "film_viewer.h" #include "lib/butler.h" +#include using boost::shared_ptr; +using boost::optional; VideoView::VideoView (FilmViewer* viewer) : _viewer (viewer) @@ -89,13 +91,13 @@ 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 +/** @return Time in ms until the next frame is due, or empty if nothing is due */ +optional VideoView::time_until_next_frame () const { if (length() == dcpomatic::DCPTime()) { /* There's no content, so this doesn't matter */ - return 0; + return optional(); } dcpomatic::DCPTime const next = position() + one_video_frame(); diff --git a/src/wx/video_view.h b/src/wx/video_view.h index ad492bd43..f9e067043 100644 --- a/src/wx/video_view.h +++ b/src/wx/video_view.h @@ -107,7 +107,7 @@ public: protected: bool get_next_frame (bool non_blocking); - int time_until_next_frame () const; + boost::optional time_until_next_frame () const; dcpomatic::DCPTime one_video_frame () const; int video_frame_rate () const {