X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fwx%2Ffilm_viewer.cc;h=893e1bf0fe4569dec8ede2d80bf75acc213b7beb;hb=30c9ecad729397574754163d13253c54a2285a6a;hp=7004ff517393900d737905aa40e915fbf46e7427;hpb=ec1df37a1940063dc0dbc45ad2dab638bdc92c0d;p=dcpomatic.git diff --git a/src/wx/film_viewer.cc b/src/wx/film_viewer.cc index 7004ff517..893e1bf0f 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,11 +92,11 @@ 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: @@ -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,10 +201,11 @@ FilmViewer::set_film (shared_ptr film) void FilmViewer::recreate_butler () { - bool const was_running = stop (); + suspend (); _butler.reset (); if (!_film) { + resume (); return; } @@ -190,14 +220,26 @@ FilmViewer::recreate_butler () 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 + if (_film->audio_channels() > 0) { + map.set (dcp::LEFT, 0, 1 / sqrt(2)); // L -> Lt + } + if (_film->audio_channels() > 1) { + map.set (dcp::RIGHT, 1, 1 / sqrt(2)); // R -> Rt + } + if (_film->audio_channels() > 2) { + map.set (dcp::CENTRE, 0, 1 / 2.0); // C -> Lt + map.set (dcp::CENTRE, 1, 1 / 2.0); // C -> Rt + } + if (_film->audio_channels() > 3) { + map.set (dcp::LFE, 0, 1 / sqrt(10)); // Lfe -> Lt + map.set (dcp::LFE, 1, 1 / sqrt(10)); // Lfe -> Rt + } + if (_film->audio_channels() > 4) { + map.set (dcp::LS, 0, 1 / sqrt(2)); // Ls -> Lt + } + if (_film->audio_channels() > 5) { + map.set (dcp::RS, 1, 1 / sqrt(2)); // Rs -> Rt + } } _butler.reset (new Butler(_player, map, _audio_channels, bind(&PlayerVideo::force, _1, AV_PIX_FMT_RGB24), false, true)); @@ -207,9 +249,7 @@ FilmViewer::recreate_butler () _closed_captions_dialog->set_film_and_butler (_film, _butler); - if (was_running) { - start (); - } + resume (); } void @@ -220,18 +260,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 +291,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 +312,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 +361,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 +382,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 +432,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 +601,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 @@ -699,7 +754,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 */