X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=blobdiff_plain;f=src%2Fwx%2Ffilm_viewer.cc;h=178311ac9bb0f78859c71e9569c2e524831a5eb5;hp=5af2d7462b76dd7820c28a683bf3905d2b92f84d;hb=444e1d4e0062677220d32b78b97a4b730156b514;hpb=a8e31120a793f09ab56cc2847d76944ba698ba95 diff --git a/src/wx/film_viewer.cc b/src/wx/film_viewer.cc index 5af2d7462..178311ac9 100644 --- a/src/wx/film_viewer.cc +++ b/src/wx/film_viewer.cc @@ -28,6 +28,7 @@ #include "wx_util.h" #include "closed_captions_dialog.h" #include "gl_video_view.h" +#include "simple_video_view.h" #include "lib/film.h" #include "lib/ratio.h" #include "lib/util.h" @@ -78,13 +79,12 @@ rtaudio_callback (void* out, void *, unsigned int frames, double, RtAudioStreamS } FilmViewer::FilmViewer (wxWindow* p) - /* XXX: make this configurable */ - : _video_view (new GLVideoView(p)) - , _coalesce_player_changes (false) + : _coalesce_player_changes (false) , _audio (DCPOMATIC_RTAUDIO_API) , _audio_channels (0) , _audio_block_size (1024) , _playing (false) + , _suspended (0) , _latency_history_count (0) , _dropped (0) , _closed_captions_dialog (new ClosedCaptionsDialog(p, this)) @@ -92,15 +92,22 @@ 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) { - /* XXX: maybe this should be proxied through the VideoView */ - _video_view->get()->Bind (wxEVT_SIZE, boost::bind (&FilmViewer::video_view_sized, this)); - _timer.Bind (wxEVT_TIMER, boost::bind (&FilmViewer::timer, this)); + switch (Config::instance()->video_view_type()) { + case Config::VIDEO_VIEW_OPENGL: + _video_view = new GLVideoView (this, p); + break; + case Config::VIDEO_VIEW_SIMPLE: + _video_view = new SimpleVideoView (this, p); + break; + } + + _video_view->Sized.connect (boost::bind(&FilmViewer::video_view_sized, this)); set_film (shared_ptr ()); @@ -113,6 +120,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 (_video_view->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) { @@ -125,14 +160,13 @@ FilmViewer::set_film (shared_ptr film) _player_video.first.reset (); _player_video.second = DCPTime (); - _frame.reset (); + _video_view->set_image (shared_ptr()); _closed_captions_dialog->clear (); if (!_film) { _player.reset (); recreate_butler (); - _frame.reset (); - refresh_panel (); + refresh_view (); return; } @@ -166,191 +200,47 @@ 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); + _butler.reset( + new Butler( + _player, + Config::instance()->audio_mapping(_audio_channels), + _audio_channels, + bind(&PlayerVideo::force, _1, AV_PIX_FMT_RGB24), + false, + true + ) + ); - 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, 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 (); - } -} - -void -FilmViewer::refresh_panel () -{ - /* XXX */ - - /* - _state_timer.set ("refresh-panel"); - _panel->Refresh (); - _panel->Update (); - _state_timer.unset (); - */ + resume (); } void -FilmViewer::get () +FilmViewer::refresh_view () { - 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"); - - /* XXX: do we need to store _frame? */ - _frame = _player_video.first->image (bind(&PlayerVideo::force, _1, AV_PIX_FMT_RGB24), false, true); - _video_view->set_image (_frame); - - _state_timer.set ("ImageChanged"); - ImageChanged (_player_video.first); + _state_timer.set ("update-view"); + _video_view->update (); _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 -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) { _outline_content = o; - refresh_panel (); + refresh_view (); } void @@ -396,13 +286,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 () { @@ -423,7 +331,7 @@ FilmViewer::start () _playing = true; _dropped = 0; - timer (); + _video_view->start (); Started (position()); } @@ -506,7 +414,7 @@ FilmViewer::quick_refresh () return false; } - display_player_video (); + _video_view->display_player_video (); return true; } @@ -547,17 +455,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 @@ -565,11 +475,16 @@ FilmViewer::config_changed (Config::Property p) { #ifdef DCPOMATIC_VARIANT_SWAROOP if (p == Config::PLAYER_BACKGROUND_IMAGE) { - refresh_panel (); + refresh_view (); return; } #endif + if (p == Config::AUDIO_MAPPING) { + recreate_butler (); + return; + } + if (p != Config::SOUND && p != Config::SOUND_OUTPUT) { return; } @@ -698,7 +613,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 */