summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2019-11-23 10:42:16 +0100
committerCarl Hetherington <cth@carlh.net>2020-01-08 21:56:47 +0100
commit89e92b3e7effafd2ca3aa1e9300777f2d2fb6183 (patch)
treebb542303b25fd0a09be1df91319beb67e1609759 /src
parentac69a0eb81e23a341545e05fa12a0e26070cb222 (diff)
Don't busy-wait when there's nothing to play.
Diffstat (limited to 'src')
-rw-r--r--src/wx/gl_video_view.cc8
-rw-r--r--src/wx/simple_video_view.cc2
-rw-r--r--src/wx/video_view.cc8
-rw-r--r--src/wx/video_view.h2
4 files changed, 13 insertions, 7 deletions
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<int> 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 <boost/optional.hpp>
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<int>
VideoView::time_until_next_frame () const
{
if (length() == dcpomatic::DCPTime()) {
/* There's no content, so this doesn't matter */
- return 0;
+ return optional<int>();
}
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<int> time_until_next_frame () const;
dcpomatic::DCPTime one_video_frame () const;
int video_frame_rate () const {