+ _state_timer.unset ();
+}
+
+
+void
+SimpleVideoView::timer ()
+{
+ if (!_viewer->playing()) {
+ return;
+ }
+
+ display_next_frame (false);
+ auto const next = position() + _viewer->one_video_frame();
+
+ if (next >= length()) {
+ _viewer->finished ();
+ return;
+ }
+
+ LOG_DEBUG_VIDEO_VIEW("%1 -> %2; delay %3", next.seconds(), _viewer->time().seconds(), max((next.seconds() - _viewer->time().seconds()) * 1000, 1.0));
+ _timer.Start (max(1, time_until_next_frame().get_value_or(0)), wxTIMER_ONE_SHOT);
+
+ if (_viewer->butler()) {
+ try {
+ _viewer->butler()->rethrow();
+ } catch (dcp::FileError& e) {
+ error_dialog(_panel, _("Could not play content"), std_to_wx(e.what()));
+ }
+ }
+}
+
+
+void
+SimpleVideoView::start ()
+{
+ VideoView::start ();
+ timer ();
+}
+
+
+/** Try to get a frame from the butler and display it.
+ * @param non_blocking true to return false quickly if no video is available quickly (i.e. we are waiting for the butler).
+ * false to ask the butler to block until it has video (unless it is suspended).
+ * @return true on success, false if we did nothing because it would have taken too long.
+ */
+VideoView::NextFrameResult
+SimpleVideoView::display_next_frame (bool non_blocking)
+{
+ auto const r = get_next_frame (non_blocking);
+ if (r != SUCCESS) {
+ return r;
+ }
+
+ update ();
+
+ try {
+ _viewer->butler()->rethrow ();
+ } catch (DecodeError& e) {
+ error_dialog (get(), e.what());
+ }
+
+ return SUCCESS;
+}
+
+
+void
+SimpleVideoView::update ()
+{
+ if (!player_video().first) {
+ _image.reset ();
+ refresh_panel ();
+ return;
+ }
+
+ if (_viewer->playing() && (_viewer->time() - player_video().second) > one_video_frame()) {
+ /* Too late; just drop this frame before we try to get its image (which will be the time-consuming
+ part if this frame is J2K).
+ */
+ add_dropped ();
+ return;
+ }
+
+ /* In an ideal world, what we would do here is:
+ *
+ * 1. convert to XYZ exactly as we do in the DCP creation path.
+ * 2. convert back to RGB for the preview display, compensating
+ * for the monitor etc. etc.
+ *
+ * but this is inefficient if the source is RGB. Since we don't
+ * (currently) care too much about the precise accuracy of the preview's
+ * colour mapping (and we care more about its speed) we try to short-
+ * circuit this "ideal" situation in some cases.
+ *
+ * The content's specified colour conversion indicates the colourspace
+ * which the content is in (according to the user).
+ *
+ * PlayerVideo::image (bound to PlayerVideo::force) will take the source
+ * image and convert it (from whatever the user has said it is) to RGB.
+ */
+
+ _state_timer.set ("get image");
+
+ auto const pv = player_video();
+ _image = pv.first->image(boost::bind(&PlayerVideo::force, AV_PIX_FMT_RGB24), VideoRange::FULL, true);
+ if (pv.first->colour_conversion() && pv.first->colour_conversion()->about_equal(dcp::ColourConversion::rec2020_to_xyz(), 1e-6)) {
+ _image = Image::ensure_alignment(_rec2020_filter_graph.get(_image->size(), _image->pixel_format())->process(_image).front(), Image::Alignment::COMPACT);
+ }
+
+ _state_timer.set ("ImageChanged");
+ _viewer->image_changed (player_video().first);
+ _state_timer.unset ();
+
+ _inter_position = player_video().first->inter_position ();
+ _inter_size = player_video().first->inter_size ();
+
+ refresh_panel ();