X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fwx%2Ffilm_viewer.cc;h=509cc9426dd279ed14e960f6b12a8a4f5f2263dc;hb=e0b2ef3dbac6fc4900cad6fea4395c212578602b;hp=cb12a78e2fc797266b973e7d8b65ea2788dc8cd6;hpb=e153d7f5dc128d97160e41bdda3c4e4a05c7140b;p=dcpomatic.git diff --git a/src/wx/film_viewer.cc b/src/wx/film_viewer.cc index cb12a78e2..509cc9426 100644 --- a/src/wx/film_viewer.cc +++ b/src/wx/film_viewer.cc @@ -84,6 +84,7 @@ FilmViewer::FilmViewer (wxWindow* p) , _audio_channels (0) , _audio_block_size (1024) , _playing (false) + , _suspended (0) , _latency_history_count (0) , _dropped (0) , _closed_captions_dialog (new ClosedCaptionsDialog(p, this)) @@ -91,15 +92,15 @@ FilmViewer::FilmViewer (wxWindow* p) , _eyes (EYES_LEFT) , _pad_black (false) #ifdef DCPOMATIC_VARIANT_SWAROOP - , _in_watermark (false) , _background_image (false) #endif , _state_timer ("viewer") , _gets (0) + , _idle_get (false) { switch (Config::instance()->video_view_type()) { case Config::VIDEO_VIEW_OPENGL: - _video_view = new GLVideoView (p); + _video_view = new GLVideoView (this, p); break; case Config::VIDEO_VIEW_SIMPLE: _video_view = new SimpleVideoView (this, p); @@ -120,6 +121,34 @@ FilmViewer::~FilmViewer () stop (); } +/** Ask for ::get() to be called next time we are idle */ +void +FilmViewer::request_idle_get () +{ + if (_idle_get) { + return; + } + + _idle_get = true; + DCPOMATIC_ASSERT (signal_manager); + signal_manager->when_idle (boost::bind(&FilmViewer::idle_handler, this)); +} + +void +FilmViewer::idle_handler () +{ + if (!_idle_get) { + return; + } + + if (get(true)) { + _idle_get = false; + } else { + /* get() could not complete quickly so we'll try again later */ + signal_manager->when_idle (boost::bind(&FilmViewer::idle_handler, this)); + } +} + void FilmViewer::set_film (shared_ptr film) { @@ -172,44 +201,32 @@ FilmViewer::set_film (shared_ptr film) void FilmViewer::recreate_butler () { - bool const was_running = stop (); + suspend (); _butler.reset (); if (!_film) { + resume (); return; } - AudioMapping map = AudioMapping (_film->audio_channels(), _audio_channels); - - if (_audio_channels != 2 || _film->audio_channels() < 3) { - for (int i = 0; i < min (_film->audio_channels(), _audio_channels); ++i) { - map.set (i, i, 1); - } - } else { - /* Special case: stereo output, at least 3 channel input. - Map so that Lt = L(-3dB) + Ls(-3dB) + C(-6dB) + Lfe(-10dB) - Rt = R(-3dB) + Rs(-3dB) + C(-6dB) + Lfe(-10dB) - */ - map.set (dcp::LEFT, 0, 1 / sqrt(2)); // L -> Lt - map.set (dcp::RIGHT, 1, 1 / sqrt(2)); // R -> Rt - map.set (dcp::CENTRE, 0, 1 / 2.0); // C -> Lt - map.set (dcp::CENTRE, 1, 1 / 2.0); // C -> Rt - map.set (dcp::LFE, 0, 1 / sqrt(10)); // Lfe -> Lt - map.set (dcp::LFE, 1, 1 / sqrt(10)); // Lfe -> Rt - map.set (dcp::LS, 0, 1 / sqrt(2)); // Ls -> Lt - map.set (dcp::RS, 1, 1 / sqrt(2)); // Rs -> Rt - } + _butler.reset( + new Butler( + _player, + Config::instance()->audio_mapping(_audio_channels), + _audio_channels, + bind(&PlayerVideo::force, _1, AV_PIX_FMT_RGB24), + false, + true + ) + ); - _butler.reset (new Butler(_player, map, _audio_channels, bind(&PlayerVideo::force, _1, AV_PIX_FMT_RGB24), false, true)); if (!Config::instance()->sound() && !_audio.isStreamOpen()) { _butler->disable_audio (); } _closed_captions_dialog->set_film_and_butler (_film, _butler); - if (was_running) { - start (); - } + resume (); } void @@ -220,18 +237,29 @@ FilmViewer::refresh_view () _state_timer.unset (); } -void -FilmViewer::get () +/** Try to get a frame from the butler and display it. + * @param lazy 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. + */ +bool +FilmViewer::get (bool lazy) { DCPOMATIC_ASSERT (_butler); ++_gets; do { Butler::Error e; - _player_video = _butler->get_video (&e); + _player_video = _butler->get_video (!lazy, &e); if (!_player_video.first && e == Butler::AGAIN) { - signal_manager->when_idle (boost::bind(&FilmViewer::get, this)); - return; + if (lazy) { + /* No video available; return saying we failed */ + return false; + } else { + /* Player was suspended; come back later */ + signal_manager->when_idle (boost::bind(&FilmViewer::get, this, false)); + return false; + } } } while ( _player_video.first && @@ -240,9 +268,16 @@ FilmViewer::get () _player_video.first->eyes() != EYES_BOTH ); - _butler->rethrow (); + try { + _butler->rethrow (); + } catch (DecodeError& e) { + error_dialog (_video_view->get(), e.what()); + } display_player_video (); + PositionChanged (); + + return true; } void @@ -254,7 +289,7 @@ FilmViewer::display_player_video () return; } - if (_playing && (time() - _player_video.second) > one_video_frame()) { + if (_playing && !_suspended && (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). */ @@ -303,12 +338,11 @@ FilmViewer::display_player_video () void FilmViewer::timer () { - if (!_film || !_playing) { + if (!_film || !_playing || _suspended) { return; } - get (); - PositionChanged (); + get (false); DCPTime const next = _video_position + one_video_frame(); if (next >= _film->length()) { @@ -325,28 +359,6 @@ FilmViewer::timer () } } -bool -#ifdef DCPOMATIC_VARIANT_SWAROOP -XXX -FilmViewer::maybe_draw_background_image (wxPaintDC& dc) -{ - optional 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::set_outline_content (bool o) { @@ -397,13 +409,31 @@ FilmViewer::calculate_sizes () _out_size.width = max (64, _out_size.width); _out_size.height = max (64, _out_size.height); - /* Make OpenGL happy; XXX: only do this in GLVideoView? Is the round-to-4 constraint a thing? */ - _out_size.width &= ~3; - _out_size.height &= ~3; - _player->set_video_container_size (_out_size); } +void +FilmViewer::suspend () +{ + ++_suspended; + if (_audio.isStreamRunning()) { + _audio.abortStream(); + } +} + +void +FilmViewer::resume () +{ + --_suspended; + if (_playing && !_suspended) { + if (_audio.isStreamOpen()) { + _audio.setStreamTime (_video_position.seconds()); + _audio.startStream (); + } + timer (); + } +} + void FilmViewer::start () { @@ -548,17 +578,19 @@ FilmViewer::seek (DCPTime t, bool accurate) t = _film->length (); } - bool const was_running = stop (); + suspend (); _closed_captions_dialog->clear (); _butler->seek (t, accurate); - get (); - if (was_running) { - start (); + if (!_playing) { + request_idle_get (); + } else { + /* Make sure we get a frame so that _video_position is set up before we resume */ + while (!get(true)) {} } - PositionChanged (); + resume (); } void @@ -571,6 +603,11 @@ FilmViewer::config_changed (Config::Property p) } #endif + if (p == Config::AUDIO_MAPPING) { + recreate_butler (); + return; + } + if (p != Config::SOUND && p != Config::SOUND_OUTPUT) { return; } @@ -699,7 +736,7 @@ FilmViewer::dcp_decode_reduction () const DCPTime FilmViewer::one_video_frame () const { - return DCPTime::from_frames (1, _film->video_frame_rate()); + return DCPTime::from_frames (1, _film ? _film->video_frame_rate() : 24); } /** Open a dialog box showing our film's closed captions */