Use an enum instead of a bool to specify blocking/non-blocking.
authorCarl Hetherington <cth@carlh.net>
Fri, 15 Oct 2021 20:26:47 +0000 (22:26 +0200)
committerCarl Hetherington <cth@carlh.net>
Fri, 15 Oct 2021 20:42:48 +0000 (22:42 +0200)
src/lib/butler.cc
src/lib/butler.h
src/lib/ffmpeg_encoder.cc
src/wx/video_view.cc
test/butler_test.cc
test/dcp_playback_test.cc
test/player_test.cc

index 6f7349b5f07bd2b7511f8eaf0aecda9e21a40e28..f19e1e0808b13ca92ca3e712b34d15dcea212502 100644 (file)
@@ -238,12 +238,12 @@ try
 }
 
 
-/** @param blocking true if we should block until video is available.  If blocking is false
+/** @param behaviour BLOCKING if we should block until video is available.  If behaviour is NON_BLOCKING
  *  and no video is immediately available the method will return a 0 PlayerVideo and the error AGAIN.
  *  @param e if non-0 this is filled with an error code (if an error occurs) or is untouched if no error occurs.
  */
 pair<shared_ptr<PlayerVideo>, DCPTime>
-Butler::get_video (bool blocking, Error* e)
+Butler::get_video (Behaviour behaviour, Error* e)
 {
        boost::mutex::scoped_lock lm (_mutex);
 
@@ -260,7 +260,7 @@ Butler::get_video (bool blocking, Error* e)
                }
        };
 
-       if (_video.empty() && (_finished || _died || (_suspended && !blocking))) {
+       if (_video.empty() && (_finished || _died || (_suspended && behaviour == Behaviour::NON_BLOCKING))) {
                setup_error (e, Error::Code::AGAIN);
                return make_pair(shared_ptr<PlayerVideo>(), DCPTime());
        }
index 498af8d86af821f9bd3c52db0d0d936b8171e40a..529b7383d0b30a9fb84cef51302a26f6ac60cbca 100644 (file)
@@ -72,7 +72,12 @@ public:
                std::string summary () const;
        };
 
-       std::pair<std::shared_ptr<PlayerVideo>, dcpomatic::DCPTime> get_video (bool blocking, Error* e = 0);
+       enum class Behaviour {
+               BLOCKING,
+               NON_BLOCKING
+       };
+
+       std::pair<std::shared_ptr<PlayerVideo>, dcpomatic::DCPTime> get_video (Behaviour behaviour, Error* e = nullptr);
        boost::optional<dcpomatic::DCPTime> get_audio (float* out, Frame frames);
        boost::optional<TextRingBuffers::Data> get_closed_caption ();
 
index f8309048ccce740906ce4f7f13eb240838843ef5..d29e191edf018fc508ade75a55140765f2f46957 100644 (file)
@@ -176,7 +176,7 @@ FFmpegEncoder::go ()
 
                for (int j = 0; j < gets_per_frame; ++j) {
                        Butler::Error e;
-                       auto v = _butler->get_video (true, &e);
+                       auto v = _butler->get_video (Butler::Behaviour::BLOCKING, &e);
                        _butler->rethrow ();
                        if (v.first) {
                                auto fe = encoder->get (v.first->eyes());
index 331095253127896dd0f824c9bef6c0d5a9d01997..1c645f11f688bd6adab4924c07ad9b0fcd25811c 100644 (file)
@@ -75,7 +75,7 @@ VideoView::get_next_frame (bool non_blocking)
 
        do {
                Butler::Error e;
-               auto pv = butler->get_video (!non_blocking, &e);
+               auto pv = butler->get_video (non_blocking ? Butler::Behaviour::NON_BLOCKING : Butler::Behaviour::BLOCKING, &e);
                if (e.code == Butler::Error::Code::DIED) {
                        LOG_ERROR ("Butler died with %1", e.summary());
                }
index 787d1c3248a695e9f8ad114124280b72cd7aaa0f..e577793342e30c9835871cc5eb5dc78f1d062273 100644 (file)
@@ -61,9 +61,9 @@ BOOST_AUTO_TEST_CASE (butler_test1)
 
        Butler butler (film, make_shared<Player>(film, Image::Alignment::COMPACT), map, 6, bind(&PlayerVideo::force, _1, AV_PIX_FMT_RGB24), VideoRange::FULL, Image::Alignment::COMPACT, false, false);
 
-       BOOST_CHECK (butler.get_video(true, 0).second == DCPTime());
-       BOOST_CHECK (butler.get_video(true, 0).second == DCPTime::from_frames(1, 24));
-       BOOST_CHECK (butler.get_video(true, 0).second == DCPTime::from_frames(2, 24));
+       BOOST_CHECK (butler.get_video(Butler::Behaviour::BLOCKING, 0).second == DCPTime());
+       BOOST_CHECK (butler.get_video(Butler::Behaviour::BLOCKING, 0).second == DCPTime::from_frames(1, 24));
+       BOOST_CHECK (butler.get_video(Butler::Behaviour::BLOCKING, 0).second == DCPTime::from_frames(2, 24));
        /* XXX: check the frame contents */
 
        float buffer[256 * 6];
index a393ce979a066e1deb1ee39918000710da22d2e7..892825753378bb852ab6ed154b74482a81d094d8 100644 (file)
@@ -57,7 +57,7 @@ BOOST_AUTO_TEST_CASE (dcp_playback_test)
 
        std::vector<float> audio_buffer(2000 * 6);
        while (true) {
-               auto p = butler->get_video (true, 0);
+               auto p = butler->get_video (Butler::Behaviour::BLOCKING, 0);
                if (!p.first) {
                        break;
                }
index 5ed77219380f21cf5e692e153f6b0898f2accac8..cafb14586a1e56421449c7e97b5b0c3366c4a5fc 100644 (file)
@@ -239,7 +239,7 @@ BOOST_AUTO_TEST_CASE (player_seek_test)
        for (int i = 0; i < 10; ++i) {
                auto t = DCPTime::from_frames (i, 24);
                butler->seek (t, true);
-               auto video = butler->get_video(true, 0);
+               auto video = butler->get_video(Butler::Behaviour::BLOCKING, 0);
                BOOST_CHECK_EQUAL(video.second.get(), t.get());
                write_image(video.first->image(bind(PlayerVideo::force, _1, AV_PIX_FMT_RGB24), VideoRange::FULL, true), String::compose("build/test/player_seek_test_%1.png", i));
                /* This 14.08 is empirically chosen (hopefully) to accept changes in rendering between the reference and a test machine
@@ -273,7 +273,7 @@ BOOST_AUTO_TEST_CASE (player_seek_test2)
        for (int i = 0; i < 10; ++i) {
                auto t = DCPTime::from_seconds(5) + DCPTime::from_frames (i, 24);
                butler->seek (t, true);
-               auto video = butler->get_video(true, 0);
+               auto video = butler->get_video(Butler::Behaviour::BLOCKING, 0);
                BOOST_CHECK_EQUAL(video.second.get(), t.get());
                write_image(
                        video.first->image(bind(PlayerVideo::force, _1, AV_PIX_FMT_RGB24), VideoRange::FULL, true), String::compose("build/test/player_seek_test2_%1.png", i)