- if (was_running) {
- start ();
- }
-}
-
-void
-FilmViewer::refresh_panel ()
-{
- _state_timer.set ("refresh-panel");
- _panel->Refresh ();
- _panel->Update ();
- _state_timer.unset ();
-}
-
-void
-FilmViewer::get ()
-{
- DCPOMATIC_ASSERT (_butler);
- ++_gets;
-
- do {
- Butler::Error e;
- _player_video = _butler->get_video (&e);
- if (!_player_video.first && e == Butler::AGAIN) {
- signal_manager->when_idle (boost::bind(&FilmViewer::get, this));
- return;
- }
- } while (
- _player_video.first &&
- _film->three_d() &&
- _eyes != _player_video.first->eyes() &&
- _player_video.first->eyes() != EYES_BOTH
- );
-
- _butler->rethrow ();
-
- display_player_video ();
-}
-
-void
-FilmViewer::display_player_video ()
-{
- if (!_player_video.first) {
- _frame.reset ();
- refresh_panel ();
- return;
- }
-
- if (_playing && (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).
- */
- _video_position = _player_video.second;
- ++_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");
- _frame = _player_video.first->image (bind(&PlayerVideo::force, _1, AV_PIX_FMT_RGB24), false, true);
-
- _state_timer.set ("ImageChanged");
- ImageChanged (_player_video.first);
- _state_timer.unset ();
-
- _video_position = _player_video.second;
- _inter_position = _player_video.first->inter_position ();
- _inter_size = _player_video.first->inter_size ();
-
- refresh_panel ();
-
- _closed_captions_dialog->update (time());
-}
-
-void
-FilmViewer::timer ()
-{
- if (!_film || !_playing) {
- return;
- }
-
- get ();
- PositionChanged ();
- DCPTime const next = _video_position + one_video_frame();
-
- if (next >= _film->length()) {
- stop ();
- Finished ();
- return;
- }
-
- LOG_DEBUG_PLAYER("%1 -> %2; delay %3", next.seconds(), time().seconds(), max((next.seconds() - time().seconds()) * 1000, 1.0));
- _timer.Start (max ((next.seconds() - time().seconds()) * 1000, 1.0), wxTIMER_ONE_SHOT);
-
- if (_butler) {
- _butler->rethrow ();
- }
-}
-
-bool
-#ifdef DCPOMATIC_VARIANT_SWAROOP
-FilmViewer::maybe_draw_background_image (wxPaintDC& dc)
-{
- optional<boost::filesystem::path> bg = Config::instance()->player_background_image();
- if (bg) {
- wxImage image (std_to_wx(bg->string()));
- wxBitmap bitmap (image);
- dc.DrawBitmap (bitmap, max(0, (_panel_size.width - image.GetSize().GetWidth()) / 2), max(0, (_panel_size.height - image.GetSize().GetHeight()) / 2));
- return true;
- }
-
- return false;
-}
-#else
-FilmViewer::maybe_draw_background_image (wxPaintDC &)
-{
- return false;
-}
-#endif
-
-void
-FilmViewer::paint_panel ()
-{
- _state_timer.set ("paint-panel");
-
- wxPaintDC dc (_panel);
-
-#ifdef DCPOMATIC_VARIANT_SWAROOP
- if (_background_image) {
- dc.Clear ();
- maybe_draw_background_image (dc);
- _state_timer.unset ();
- return;
- }
-#endif
-
- if (!_out_size.width || !_out_size.height || !_film || !_frame || _out_size != _frame->size()) {
- dc.Clear ();
- } else {
-
- wxImage frame (_out_size.width, _out_size.height, _frame->data()[0], true);
- wxBitmap frame_bitmap (frame);
- dc.DrawBitmap (frame_bitmap, 0, max(0, (_panel_size.height - _out_size.height) / 2));
-
-#ifdef DCPOMATIC_VARIANT_SWAROOP
- DCPTime const period = DCPTime::from_seconds(Config::instance()->player_watermark_period() * 60);
- int64_t n = _video_position.get() / period.get();
- DCPTime from(n * period.get());
- DCPTime to = from + DCPTime::from_seconds(Config::instance()->player_watermark_duration() / 1000.0);
- if (from <= _video_position && _video_position <= to) {
- if (!_in_watermark) {
- _in_watermark = true;
- _watermark_x = rand() % _panel_size.width;
- _watermark_y = rand() % _panel_size.height;
- }
- dc.SetTextForeground(*wxWHITE);
- string wm = Config::instance()->player_watermark_theatre();
- boost::posix_time::ptime t = boost::posix_time::second_clock::local_time();
- wm += "\n" + boost::posix_time::to_iso_extended_string(t);
- dc.DrawText(std_to_wx(wm), _watermark_x, _watermark_y);
- } else {
- _in_watermark = false;
- }
-#endif
- }
-
- if (_out_size.width < _panel_size.width) {
- /* XXX: these colours are right for GNOME; may need adjusting for other OS */
- wxPen p (_pad_black ? wxColour(0, 0, 0) : wxColour(240, 240, 240));
- wxBrush b (_pad_black ? wxColour(0, 0, 0) : wxColour(240, 240, 240));
- dc.SetPen (p);
- dc.SetBrush (b);
- dc.DrawRectangle (_out_size.width, 0, _panel_size.width - _out_size.width, _panel_size.height);
- }
-
- if (_out_size.height < _panel_size.height) {
- wxPen p (_pad_black ? wxColour(0, 0, 0) : wxColour(240, 240, 240));
- wxBrush b (_pad_black ? wxColour(0, 0, 0) : wxColour(240, 240, 240));
- dc.SetPen (p);
- dc.SetBrush (b);
- int const gap = (_panel_size.height - _out_size.height) / 2;
- dc.DrawRectangle (0, 0, _panel_size.width, gap);
- dc.DrawRectangle (0, gap + _out_size.height + 1, _panel_size.width, gap + 1);
- }
-
- if (_outline_content) {
- wxPen p (wxColour (255, 0, 0), 2);
- dc.SetPen (p);
- dc.SetBrush (*wxTRANSPARENT_BRUSH);
- dc.DrawRectangle (_inter_position.x, _inter_position.y + (_panel_size.height - _out_size.height) / 2, _inter_size.width, _inter_size.height);
- }
-
- _state_timer.unset ();