Tidy up calls to handle both video types.
authorCarl Hetherington <cth@carlh.net>
Sun, 6 Nov 2022 20:51:12 +0000 (21:51 +0100)
committerCarl Hetherington <cth@carlh.net>
Thu, 22 Dec 2022 23:12:00 +0000 (00:12 +0100)
src/lib/butler.cc
src/lib/player.cc
src/lib/video_type.cc
src/lib/video_type.h
src/wx/film_viewer.cc

index 5b6139a81fbbb86bbdb168a84028d1eda5f1ba11..0063fa36ff5eaf3781f0f4c1eadb62fe177c8dd2 100644 (file)
@@ -136,7 +136,7 @@ Butler::~Butler ()
 bool
 Butler::should_run () const
 {
-       auto check_video_much_too_big = [this](VideoType type) {
+       for (auto type: _video.indices()) {
                if (_video[type].size() >= MAXIMUM_VIDEO_READAHEAD * 10) {
                        /* This is way too big */
                        auto pos = _audio.peek();
@@ -150,9 +150,6 @@ Butler::should_run () const
                }
        };
 
-       check_video_much_too_big(VideoType::MAIN);
-       check_video_much_too_big(VideoType::SIGN_LANGUAGE);
-
        if (_audio.size() >= MAXIMUM_AUDIO_READAHEAD * 10) {
                /* This is way too big */
                auto pos = _audio.peek();
@@ -165,15 +162,12 @@ Butler::should_run () const
                }
        }
 
-       auto check_video_too_big = [this](VideoType type) {
-               if (_video[type].size() >= MAXIMUM_VIDEO_READAHEAD * 2) {
-                       LOG_WARNING ("Butler video buffers reached %1 frames (audio is %2)", _video[type].size(), _audio.size());
+       for (auto& video: _video) {
+               if (video.size() >= MAXIMUM_VIDEO_READAHEAD * 2) {
+                       LOG_WARNING ("Butler video buffers reached %1 frames (audio is %2)", video.size(), _audio.size());
                }
        };
 
-       check_video_too_big(VideoType::MAIN);
-       check_video_too_big(VideoType::SIGN_LANGUAGE);
-
        if (_audio.size() >= MAXIMUM_AUDIO_READAHEAD * 2) {
                LOG_WARNING ("Butler audio buffers reached %1 frames (main video is %2)", _audio.size(), _video[VideoType::MAIN].size());
        }
@@ -325,8 +319,9 @@ Butler::seek_unlocked (DCPTime position, bool accurate)
        _pending_seek_position = position;
        _pending_seek_accurate = accurate;
 
-       _video[VideoType::MAIN].clear();
-       _video[VideoType::SIGN_LANGUAGE].clear();
+       for (auto& video: _video) {
+               video.clear();
+       }
        _audio.clear ();
        _closed_caption.clear ();
 
@@ -426,8 +421,9 @@ Butler::player_change (ChangeType type, int property)
                if (type == ChangeType::DONE) {
                        auto film = _film.lock();
                        if (film) {
-                               _video[VideoType::MAIN].reset_metadata(film, _player.video_container_size(VideoType::MAIN));
-                               _video[VideoType::SIGN_LANGUAGE].reset_metadata(film, _player.video_container_size(VideoType::SIGN_LANGUAGE));
+                               for (auto type: _video.indices()) {
+                                       _video[type].reset_metadata(film, _player.video_container_size(type));
+                               }
                        }
                }
                return;
index a55b4153cf9d9c587e68f4882ce497bad2b08226..1bfa79385e6cf5024a8bac44a71c3747e5bc937e 100644 (file)
@@ -155,8 +155,9 @@ void
 Player::construct ()
 {
        connect();
-       set_video_container_size(VideoType::MAIN, full_size(VideoType::MAIN));
-       set_video_container_size(VideoType::SIGN_LANGUAGE, full_size(VideoType::SIGN_LANGUAGE));
+       for (auto type: video_types()) {
+               set_video_container_size(type, full_size(type));
+       }
 
        _black_image[VideoType::SIGN_LANGUAGE] = make_shared<Image>(AV_PIX_FMT_RGB24, dcp::Size(SIGN_LANGUAGE_WIDTH, SIGN_LANGUAGE_HEIGHT), Image::Alignment::PADDED);
 
@@ -418,7 +419,9 @@ Player::setup_pieces ()
        }
        _silent = Empty(film, playlist(), bind(&have_audio, _1), _playback_length);
 
-       _next_video_time[VideoType::MAIN] = _next_video_time[VideoType::SIGN_LANGUAGE] = boost::none;
+       for (auto& next: _next_video_time) {
+               next = boost::none;
+       }
        _next_audio_time = boost::none;
 }
 
@@ -713,8 +716,9 @@ Player::pass ()
 
        if (_playback_length.load() == DCPTime() || !film) {
                /* Special; just give one black frame */
-               use_video(black_player_video_frame(VideoType::MAIN, Eyes::BOTH), DCPTime(), one_video_frame());
-               use_video(black_player_video_frame(VideoType::SIGN_LANGUAGE, Eyes::BOTH), DCPTime(), one_video_frame());
+               for (auto type: video_types()) {
+                       use_video(black_player_video_frame(type, Eyes::BOTH), DCPTime(), one_video_frame());
+               }
                return true;
        }
 
@@ -758,16 +762,13 @@ Player::pass ()
                which = CONTENT;
        }
 
-       auto check_black = [this, &earliest_time, &which, &black_type](VideoType type) {
+       for (auto type: _black.indices()) {
                if (!_black[type].done() && !_ignore_video && (!earliest_time || _black[type].position() < *earliest_time)) {
                        earliest_time = _black[type].position();
                        which = BLACK;
                        black_type = type;
                }
-       };
-
-       check_black(VideoType::MAIN);
-       check_black(VideoType::SIGN_LANGUAGE);
+       }
 
        if (!_silent.done() && !_ignore_audio && (!earliest_time || _silent.position() < *earliest_time)) {
                earliest_time = _silent.position ();
@@ -1395,20 +1396,29 @@ Player::seek (DCPTime time, bool accurate)
                }
        }
 
+       for (auto& next: _next_video_time) {
+               if (accurate) {
+                       next = time;
+               } else {
+                       next = boost::none;
+               }
+       }
+
+       for (auto& black: _black) {
+               black.set_position(time);
+       }
+
        if (accurate) {
-               _next_video_time[VideoType::MAIN] = _next_video_time[VideoType::SIGN_LANGUAGE] = time;
                _next_audio_time = time;
        } else {
-               _next_video_time[VideoType::MAIN] = _next_video_time[VideoType::SIGN_LANGUAGE] = boost::none;
                _next_audio_time = boost::none;
        }
 
-       _black[VideoType::MAIN].set_position(time);
-       _black[VideoType::SIGN_LANGUAGE].set_position(time);
        _silent.set_position (time);
 
-       _last_video[VideoType::MAIN][Eyes::LEFT] = _last_video[VideoType::MAIN][Eyes::RIGHT] = _last_video[VideoType::MAIN][Eyes::BOTH] = {};
-       _last_video[VideoType::SIGN_LANGUAGE][Eyes::LEFT] = _last_video[VideoType::SIGN_LANGUAGE][Eyes::RIGHT] = _last_video[VideoType::SIGN_LANGUAGE][Eyes::BOTH] = {};
+       for (auto& last: _last_video) {
+               last[Eyes::LEFT] = last[Eyes::RIGHT] = last[Eyes::BOTH] = {};
+       }
 
        for (auto& state: _stream_states) {
                state.second.last_push_end = boost::none;
index 64cac7e2e2be7880b775cca806657f1485b63257..d94e2f43dbe9123082846ca45503b17ba824b1cb 100644 (file)
@@ -25,6 +25,7 @@
 
 
 using std::string;
+using std::vector;
 
 
 string
@@ -53,3 +54,10 @@ string_to_video_type(string type)
        DCPOMATIC_ASSERT(false);
 }
 
+
+vector<VideoType>
+video_types()
+{
+       return { VideoType::MAIN, VideoType::SIGN_LANGUAGE };
+}
+
index ca192857845cca647ee99a9ac77a18fa2d484c88..c137dc53ff8e8e1f72ad40955c5d92ac9becbfb5 100644 (file)
@@ -24,6 +24,7 @@
 
 
 #include <string>
+#include <vector>
 
 
 enum class VideoType
@@ -38,4 +39,7 @@ VideoType string_to_video_type(std::string type);
 std::string video_type_to_string(VideoType type);
 
 
+std::vector<VideoType> video_types();
+
+
 #endif
index 50a7390939e89511e7c8eb2688a4bb976260a6dd..e871489169ed39939ffe47bd796419466c1bc3dd 100644 (file)
@@ -106,8 +106,9 @@ FilmViewer::FilmViewer (wxWindow* p)
        _video_view = std::make_shared<SimpleVideoView>(this, p);
 #endif
 
-       _video_view[VideoType::MAIN]->Sized.connect(boost::bind(&FilmViewer::video_view_sized, this, VideoType::MAIN));
-       _video_view[VideoType::SIGN_LANGUAGE]->Sized.connect(boost::bind(&FilmViewer::video_view_sized, this, VideoType::SIGN_LANGUAGE));
+       for (auto type: _video_view.indices()) {
+               _video_view[type]->Sized.connect(boost::bind(&FilmViewer::video_view_sized, this, type));
+       }
        _video_view[VideoType::MAIN]->TooManyDropped.connect(boost::bind(boost::ref(TooManyDropped)));
 
        set_film (shared_ptr<Film>());
@@ -162,8 +163,9 @@ FilmViewer::set_film (shared_ptr<Film> film)
 
        _film = film;
 
-       _video_view[VideoType::MAIN]->clear();
-       _video_view[VideoType::SIGN_LANGUAGE]->clear();
+       for (auto& view: _video_view) {
+               view->clear();
+       }
        _closed_captions_dialog->clear ();
 
        destroy_butler();
@@ -171,8 +173,9 @@ FilmViewer::set_film (shared_ptr<Film> film)
        if (!_film) {
                _player = boost::none;
                resume();
-               _video_view[VideoType::MAIN]->update();
-               _video_view[VideoType::SIGN_LANGUAGE]->update();
+               for (auto& view: _video_view) {
+                       view->update();
+               }
                return;
        }
 
@@ -380,8 +383,9 @@ FilmViewer::resume ()
        --_suspended;
        if (_playing && !_suspended) {
                start_audio_stream_if_open ();
-               _video_view[VideoType::MAIN]->start();
-               _video_view[VideoType::SIGN_LANGUAGE]->start();
+               for (auto& view: _video_view) {
+                       view->start();
+               }
        }
 }
 
@@ -417,8 +421,9 @@ FilmViewer::start ()
         * happens we want it to come after the Started signal, so do that first.
         */
        Started ();
-       _video_view[VideoType::MAIN]->start();
-       _video_view[VideoType::SIGN_LANGUAGE]->start();
+       for (auto& view: _video_view) {
+               view->start();
+       }
 }
 
 
@@ -435,12 +440,15 @@ FilmViewer::stop ()
        }
 
        _playing = false;
-       _video_view[VideoType::MAIN]->stop();
-       _video_view[VideoType::SIGN_LANGUAGE]->stop();
+       for (auto& view: _video_view) {
+               view->stop();
+       }
+
        Stopped ();
 
-       _video_view[VideoType::MAIN]->rethrow();
-       _video_view[VideoType::SIGN_LANGUAGE]->rethrow();
+       for (auto& view: _video_view) {
+               view->rethrow();
+       }
        return true;
 }
 
@@ -508,8 +516,9 @@ FilmViewer::film_change (ChangeType type, Film::Property p)
        if (p == Film::Property::AUDIO_CHANNELS) {
                destroy_and_maybe_create_butler();
        } else if (p == Film::Property::VIDEO_FRAME_RATE) {
-               _video_view[VideoType::MAIN]->set_video_frame_rate(_film->video_frame_rate());
-               _video_view[VideoType::SIGN_LANGUAGE]->set_video_frame_rate(_film->video_frame_rate());
+               for (auto& view: _video_view) {
+                       view->set_video_frame_rate(_film->video_frame_rate());
+               }
        } else if (p == Film::Property::THREE_D) {
                _video_view[VideoType::MAIN]->set_three_d(_film->three_d());
        } else if (p == Film::Property::CONTENT) {
@@ -521,8 +530,9 @@ FilmViewer::film_change (ChangeType type, Film::Property p)
 void
 FilmViewer::film_length_change ()
 {
-       _video_view[VideoType::MAIN]->set_length(_film->length());
-       _video_view[VideoType::SIGN_LANGUAGE]->set_length(_film->length());
+       for (auto& view: _video_view) {
+               view->set_length(_film->length());
+       }
 }