Remove some more unnecessary use of shared_ptr.
authorCarl Hetherington <cth@carlh.net>
Fri, 14 Oct 2022 22:28:32 +0000 (00:28 +0200)
committerCarl Hetherington <cth@carlh.net>
Sun, 16 Oct 2022 22:10:59 +0000 (00:10 +0200)
13 files changed:
src/lib/butler.cc
src/lib/butler.h
src/lib/dcp_encoder.cc
src/lib/encoder.cc
src/lib/encoder.h
src/lib/ffmpeg_encoder.cc
src/lib/subtitle_encoder.cc
src/wx/film_viewer.cc
src/wx/film_viewer.h
test/butler_test.cc
test/dcp_playback_test.cc
test/player_test.cc
test/threed_test.cc

index ce35b1f39aff61da043aa71e0a3d5fad0e963f11..b2fbc6c60b630be0c0478dace3b922c735517878 100644 (file)
@@ -62,7 +62,7 @@ using namespace boost::placeholders;
  */
 Butler::Butler (
        weak_ptr<const Film> film,
-       shared_ptr<Player> player,
+       Player& player,
        AudioMapping audio_mapping,
        int audio_channels,
        function<AVPixelFormat (AVPixelFormat)> pixel_format,
@@ -89,13 +89,13 @@ Butler::Butler (
        , _fast (fast)
        , _prepare_only_proxy (prepare_only_proxy)
 {
-       _player_video_connection = _player->Video.connect (bind (&Butler::video, this, _1, _2));
-       _player_audio_connection = _player->Audio.connect (bind (&Butler::audio, this, _1, _2, _3));
-       _player_text_connection = _player->Text.connect (bind (&Butler::text, this, _1, _2, _3, _4));
+       _player_video_connection = _player.Video.connect(bind(&Butler::video, this, _1, _2));
+       _player_audio_connection = _player.Audio.connect(bind(&Butler::audio, this, _1, _2, _3));
+       _player_text_connection = _player.Text.connect(bind(&Butler::text, this, _1, _2, _3, _4));
        /* The butler must hear about things first, otherwise it might not sort out suspensions in time for
           get_video() to be called in response to this signal.
        */
-       _player_change_connection = _player->Change.connect (bind (&Butler::player_change, this, _1, _2), boost::signals2::at_front);
+       _player_change_connection = _player.Change.connect(bind(&Butler::player_change, this, _1, _2), boost::signals2::at_front);
        _thread = boost::thread (bind(&Butler::thread, this));
 #ifdef DCPOMATIC_LINUX
        pthread_setname_np (_thread.native_handle(), "butler");
@@ -200,7 +200,7 @@ try
                /* Do any seek that has been requested */
                if (_pending_seek_position) {
                        _finished = false;
-                       _player->seek (*_pending_seek_position, _pending_seek_accurate);
+                       _player.seek(*_pending_seek_position, _pending_seek_accurate);
                        _pending_seek_position = optional<DCPTime> ();
                }
 
@@ -210,7 +210,7 @@ try
                */
                while (should_run() && !_pending_seek_position) {
                        lm.unlock ();
-                       bool const r = _player->pass ();
+                       bool const r = _player.pass();
                        lm.lock ();
                        if (r) {
                                _finished = true;
@@ -410,7 +410,7 @@ Butler::player_change (ChangeType type, int property)
                if (type == ChangeType::DONE) {
                        auto film = _film.lock();
                        if (film) {
-                               _video.reset_metadata (film, _player->video_container_size());
+                               _video.reset_metadata(film, _player.video_container_size());
                        }
                }
                return;
index bac94a74297e8f785ed38211d59683564aea8ae6..1dba6e129839ab1ff9920bd1ee61d3cac622d2c3 100644 (file)
@@ -50,7 +50,7 @@ public:
 
        Butler (
                std::weak_ptr<const Film> film,
-               std::shared_ptr<Player> player,
+               Player& player,
                AudioMapping map,
                int audio_channels,
                std::function<AVPixelFormat (AVPixelFormat)> pixel_format,
@@ -105,7 +105,7 @@ private:
        void seek_unlocked (dcpomatic::DCPTime position, bool accurate);
 
        std::weak_ptr<const Film> _film;
-       std::shared_ptr<Player> _player;
+       Player& _player;
        boost::thread _thread;
 
        VideoRingBuffers _video;
index 16a99e79e0ff28563c8d9546641b83ee10014d50..9a840c8ab916b6a594f4e6881f223ad20346f4f5 100644 (file)
@@ -68,10 +68,10 @@ DCPEncoder::DCPEncoder (shared_ptr<const Film> film, weak_ptr<Job> job)
        , _finishing (false)
        , _non_burnt_subtitles (false)
 {
-       _player_video_connection = _player->Video.connect (bind (&DCPEncoder::video, this, _1, _2));
-       _player_audio_connection = _player->Audio.connect (bind (&DCPEncoder::audio, this, _1, _2));
-       _player_text_connection = _player->Text.connect (bind (&DCPEncoder::text, this, _1, _2, _3, _4));
-       _player_atmos_connection = _player->Atmos.connect (bind (&DCPEncoder::atmos, this, _1, _2, _3));
+       _player_video_connection = _player.Video.connect(bind(&DCPEncoder::video, this, _1, _2));
+       _player_audio_connection = _player.Audio.connect(bind(&DCPEncoder::audio, this, _1, _2));
+       _player_text_connection = _player.Text.connect(bind(&DCPEncoder::text, this, _1, _2, _3, _4));
+       _player_atmos_connection = _player.Atmos.connect(bind(&DCPEncoder::atmos, this, _1, _2, _3));
 
        for (auto c: film->content ()) {
                for (auto i: c->text) {
@@ -104,10 +104,10 @@ DCPEncoder::go ()
        }
 
        if (_non_burnt_subtitles) {
-               _writer.write(_player->get_subtitle_fonts());
+               _writer.write(_player.get_subtitle_fonts());
        }
 
-       while (!_player->pass ()) {}
+       while (!_player.pass()) {}
 
        for (auto i: get_referenced_reel_assets(_film, _film->playlist())) {
                _writer.write(i);
index 1d688c31868d49450140e7381994f3431fe6bb5d..5268d8620f65377fef796df3613e834ab4e98deb 100644 (file)
@@ -41,7 +41,7 @@
 Encoder::Encoder (std::shared_ptr<const Film> film, std::weak_ptr<Job> job)
        : _film (film)
        , _job (job)
-       , _player (new Player(film, Image::Alignment::PADDED))
+       , _player(film, Image::Alignment::PADDED)
 {
 
 }
index 19c1120b360f789fd8af1ef76ccf85a97e494337..24217b1244179648e0e55cfa85298836734e711c 100644 (file)
@@ -23,6 +23,7 @@
 #define DCPOMATIC_ENCODER_H
 
 
+#include "player.h"
 #include "player_text.h"
 #include "types.h"
 #include <boost/signals2.hpp>
@@ -62,7 +63,7 @@ public:
 protected:
        std::shared_ptr<const Film> _film;
        std::weak_ptr<Job> _job;
-       std::shared_ptr<Player> _player;
+       Player _player;
 };
 
 
index 2fcad68fe3c6fa14494f120177b479fc76e36dac..001645af3c59e21ac7fdfaf89e55f205812a1763 100644 (file)
@@ -79,8 +79,8 @@ FFmpegEncoder::FFmpegEncoder (
                Butler::Audio::ENABLED
                )
 {
-       _player->set_always_burn_open_subtitles ();
-       _player->set_play_referenced ();
+       _player.set_always_burn_open_subtitles();
+       _player.set_play_referenced();
 }
 
 
index 2331eb52a8871241ba3ce58a87a3a99348a7aebf..51b9963bc02a168d1988120f586b93625faa0769 100644 (file)
@@ -56,10 +56,10 @@ SubtitleEncoder::SubtitleEncoder (shared_ptr<const Film> film, shared_ptr<Job> j
        , _reel_index (0)
        , _length (film->length())
 {
-       _player->set_play_referenced ();
-       _player->set_ignore_video ();
-       _player->set_ignore_audio ();
-       _player->Text.connect (boost::bind(&SubtitleEncoder::text, this, _1, _2, _3, _4));
+       _player.set_play_referenced();
+       _player.set_ignore_video();
+       _player.set_ignore_audio();
+       _player.Text.connect(boost::bind(&SubtitleEncoder::text, this, _1, _2, _3, _4));
 
        string const extension = film->interop() ? ".xml" : ".mxf";
 
@@ -99,7 +99,7 @@ SubtitleEncoder::go ()
 
        _reel_index = 0;
 
-       while (!_player->pass()) {}
+       while (!_player.pass()) {}
 
        int reel = 0;
        for (auto& i: _assets) {
@@ -119,7 +119,7 @@ SubtitleEncoder::go ()
                }
 
                if (!_film->interop() || _include_font) {
-                       for (auto j: _player->get_subtitle_fonts()) {
+                       for (auto j: _player.get_subtitle_fonts()) {
                                i.first->add_font(j->id(), j->data().get_value_or(_default_font));
                        }
                }
index c56e2f5d26f89a3478e3e2385ddd99ee5dd82dd2..c5fb502177af5c52b5cc3e1280464b711cf04748 100644 (file)
@@ -161,14 +161,14 @@ FilmViewer::set_film (shared_ptr<Film> film)
        _closed_captions_dialog->clear ();
 
        if (!_film) {
-               _player.reset ();
+               _player = boost::none;
                recreate_butler ();
                _video_view->update ();
                return;
        }
 
        try {
-               _player = make_shared<Player>(_film, _optimise_for_j2k ? Image::Alignment::COMPACT : Image::Alignment::PADDED);
+               _player.emplace(_film, _optimise_for_j2k ? Image::Alignment::COMPACT : Image::Alignment::PADDED);
                _player->set_fast ();
                if (_dcp_decode_reduction) {
                        _player->set_dcp_decode_reduction (_dcp_decode_reduction);
@@ -219,9 +219,11 @@ FilmViewer::recreate_butler ()
        auto const j2k_gl_optimised = false;
 #endif
 
+       DCPOMATIC_ASSERT(_player);
+
        _butler = std::make_shared<Butler>(
                _film,
-               _player,
+               *_player,
                Config::instance()->audio_mapping(_audio_channels),
                _audio_channels,
                boost::bind(&PlayerVideo::force, AV_PIX_FMT_RGB24),
@@ -517,6 +519,7 @@ FilmViewer::quick_refresh ()
 void
 FilmViewer::seek (shared_ptr<Content> content, ContentTime t, bool accurate)
 {
+       DCPOMATIC_ASSERT(_player);
        auto dt = _player->content_time_to_dcp (content, t);
        if (dt) {
                seek (*dt, accurate);
@@ -722,6 +725,7 @@ FilmViewer::dcp_decode_reduction () const
 optional<ContentTime>
 FilmViewer::position_in_content (shared_ptr<const Content> content) const
 {
+       DCPOMATIC_ASSERT(_player);
        return _player->dcp_to_content_time (content, position());
 }
 
index 1fa85a621c9fb85e30e8fa20fe71cf13a505d54d..062522ffd54bb2fa24d48b582212e57c8670b22d 100644 (file)
@@ -175,7 +175,7 @@ private:
        bool quick_refresh ();
 
        std::shared_ptr<Film> _film;
-       std::shared_ptr<Player> _player;
+       boost::optional<Player> _player;
 
        std::shared_ptr<VideoView> _video_view;
        bool _coalesce_player_changes = false;
index 1645d41003fe886a485506ab1a5a6a1d6bd1a989..97e4ccc0effbdec2718baa3fd399bc8303398940 100644 (file)
@@ -60,9 +60,11 @@ BOOST_AUTO_TEST_CASE (butler_test1)
                map.set (i, i, 1);
        }
 
+       Player player(film, Image::Alignment::COMPACT);
+
        Butler butler (
                film,
-               make_shared<Player>(film, Image::Alignment::COMPACT),
+               player,
                map,
                6,
                boost::bind(&PlayerVideo::force, AV_PIX_FMT_RGB24),
@@ -105,9 +107,11 @@ BOOST_AUTO_TEST_CASE (butler_test2)
                map.set (i, i, 1);
        }
 
+       Player player(film, Image::Alignment::COMPACT);
+
        Butler butler (
                film,
-               make_shared<Player>(film, Image::Alignment::COMPACT),
+               player,
                map,
                6,
                boost::bind(&PlayerVideo::force, AV_PIX_FMT_RGB24),
index 62c72cc84e85fd25e86ee605643e27fe4811a78c..a5b69e1819051da1ab404ff7bf3a1e61af737adf 100644 (file)
@@ -43,9 +43,11 @@ BOOST_AUTO_TEST_CASE (dcp_playback_test)
        film->examine_and_add_content (content);
        BOOST_REQUIRE (!wait_for_jobs());
 
+       Player player(film, Image::Alignment::PADDED);
+
        auto butler = std::make_shared<Butler>(
                film,
-               make_shared<Player>(film, Image::Alignment::PADDED),
+               player,
                AudioMapping(6, 6),
                6,
                boost::bind(&PlayerVideo::force, AV_PIX_FMT_RGB24),
index 19336ac4f4d27ad0483dbe19850d34cec923375b..6b29cbc309fda2adeaaff586a16320dd09d59123 100644 (file)
@@ -83,9 +83,9 @@ BOOST_AUTO_TEST_CASE (player_silence_padding_test)
 
        accumulated = std::make_shared<AudioBuffers>(film->audio_channels(), 0);
 
-       auto player = std::make_shared<Player>(film, Image::Alignment::COMPACT);
-       player->Audio.connect (bind (&accumulate, _1, _2));
-       while (!player->pass ()) {}
+       Player player(film, Image::Alignment::COMPACT);
+       player.Audio.connect(bind(&accumulate, _1, _2));
+       while (!player.pass()) {}
        BOOST_REQUIRE (accumulated->frames() >= 48000);
        BOOST_CHECK_EQUAL (accumulated->channels(), film->audio_channels ());
 
@@ -163,12 +163,12 @@ BOOST_AUTO_TEST_CASE (player_subframe_test)
        /* Length should be rounded up from B's length to the next video frame */
        BOOST_CHECK (film->length() == DCPTime::from_frames(3 * 24 + 1, 24));
 
-       auto player = std::make_shared<Player>(film, Image::Alignment::COMPACT);
-       player->setup_pieces ();
-       BOOST_REQUIRE_EQUAL (player->_black._periods.size(), 1U);
-       BOOST_CHECK (player->_black._periods.front() == DCPTimePeriod(DCPTime::from_frames(3 * 24, 24), DCPTime::from_frames(3 * 24 + 1, 24)));
-       BOOST_REQUIRE_EQUAL (player->_silent._periods.size(), 1U);
-       BOOST_CHECK (player->_silent._periods.front() == DCPTimePeriod(DCPTime(289920), DCPTime::from_frames(3 * 24 + 1, 24)));
+       Player player(film, Image::Alignment::COMPACT);
+       player.setup_pieces();
+       BOOST_REQUIRE_EQUAL(player._black._periods.size(), 1U);
+       BOOST_CHECK(player._black._periods.front() == DCPTimePeriod(DCPTime::from_frames(3 * 24, 24), DCPTime::from_frames(3 * 24 + 1, 24)));
+       BOOST_REQUIRE_EQUAL(player._silent._periods.size(), 1U);
+       BOOST_CHECK(player._silent._periods.front() == DCPTimePeriod(DCPTime(289920), DCPTime::from_frames(3 * 24 + 1, 24)));
 }
 
 
@@ -205,11 +205,11 @@ BOOST_AUTO_TEST_CASE (player_interleave_test)
        film->examine_and_add_content (s);
        BOOST_REQUIRE (!wait_for_jobs ());
 
-       auto player = std::make_shared<Player>(film, Image::Alignment::COMPACT);
-       player->Video.connect (bind (&video, _1, _2));
-       player->Audio.connect (bind (&audio, _1, _2));
+       Player player(film, Image::Alignment::COMPACT);
+       player.Video.connect(bind(&video, _1, _2));
+       player.Audio.connect(bind(&audio, _1, _2));
        video_frames = audio_frames = 0;
-       while (!player->pass ()) {
+       while (!player.pass()) {
                BOOST_CHECK (abs(video_frames - (audio_frames / 2000)) <= 8);
        }
 }
@@ -228,10 +228,10 @@ BOOST_AUTO_TEST_CASE (player_seek_test)
        BOOST_REQUIRE (!wait_for_jobs ());
        dcp->only_text()->set_use (true);
 
-       auto player = std::make_shared<Player>(film, Image::Alignment::COMPACT);
-       player->set_fast ();
-       player->set_always_burn_open_subtitles ();
-       player->set_play_referenced ();
+       Player player(film, Image::Alignment::COMPACT);
+       player.set_fast();
+       player.set_always_burn_open_subtitles();
+       player.set_play_referenced();
 
        auto butler = std::make_shared<Butler>(
                film, player, AudioMapping(), 2, bind(PlayerVideo::force, AV_PIX_FMT_RGB24), VideoRange::FULL, Image::Alignment::PADDED, true, false, Butler::Audio::DISABLED
@@ -261,10 +261,10 @@ BOOST_AUTO_TEST_CASE (player_seek_test2)
        BOOST_REQUIRE (!wait_for_jobs ());
        dcp->only_text()->set_use (true);
 
-       auto player = std::make_shared<Player>(film, Image::Alignment::COMPACT);
-       player->set_fast ();
-       player->set_always_burn_open_subtitles ();
-       player->set_play_referenced ();
+       Player player(film, Image::Alignment::COMPACT);
+       player.set_fast();
+       player.set_always_burn_open_subtitles();
+       player.set_play_referenced();
 
        auto butler = std::make_shared<Butler>
                (film, player, AudioMapping(), 2, bind(PlayerVideo::force, AV_PIX_FMT_RGB24), VideoRange::FULL, Image::Alignment::PADDED, true, false, Butler::Audio::DISABLED
@@ -336,13 +336,13 @@ BOOST_AUTO_TEST_CASE (player_ignore_video_and_audio_test)
        text->only_text()->set_type (TextType::CLOSED_CAPTION);
        text->only_text()->set_use (true);
 
-       auto player = std::make_shared<Player>(film, Image::Alignment::COMPACT);
-       player->set_ignore_video ();
-       player->set_ignore_audio ();
+       Player player(film, Image::Alignment::COMPACT);
+       player.set_ignore_video();
+       player.set_ignore_audio();
 
        list<Sub> out;
-       player->Text.connect (bind (&store, &out, _1, _2, _3, _4));
-       while (!player->pass ()) {}
+       player.Text.connect(bind (&store, &out, _1, _2, _3, _4));
+       while (!player.pass()) {}
 
        BOOST_CHECK_EQUAL (out.size(), 6U);
 }
@@ -356,8 +356,8 @@ BOOST_AUTO_TEST_CASE (player_trim_crash)
        film->examine_and_add_content (boon);
        BOOST_REQUIRE (!wait_for_jobs());
 
-       auto player = std::make_shared<Player>(film, Image::Alignment::COMPACT);
-       player->set_fast ();
+       Player player(film, Image::Alignment::COMPACT);
+       player.set_fast();
        auto butler = std::make_shared<Butler>(
                film, player, AudioMapping(), 6, bind(&PlayerVideo::force, AV_PIX_FMT_RGB24), VideoRange::FULL, Image::Alignment::COMPACT, true, false, Butler::Audio::ENABLED
                );
@@ -489,7 +489,7 @@ BOOST_AUTO_TEST_CASE (encrypted_dcp_with_no_kdm_gives_no_butler_error)
        auto content2 = std::make_shared<DCPContent>(film->dir(film->dcp_name()));
        auto film2 = new_test_film2 ("encrypted_dcp_with_no_kdm_gives_no_butler_error2", { content2 });
 
-       auto player = std::make_shared<Player>(film2, Image::Alignment::COMPACT);
+       Player player(film, Image::Alignment::COMPACT);
        Butler butler(film2, player, AudioMapping(), 2, bind(PlayerVideo::force, AV_PIX_FMT_RGB24), VideoRange::FULL, Image::Alignment::PADDED, true, false, Butler::Audio::ENABLED);
 
        float buffer[2000 * 6];
@@ -527,14 +527,14 @@ BOOST_AUTO_TEST_CASE (interleaved_subtitle_are_emitted_correctly)
        subs1->set_position(film, DCPTime());
        subs2->set_position(film, DCPTime());
 
-       auto player = std::make_shared<Player>(film, Image::Alignment::COMPACT);
+       Player player(film, Image::Alignment::COMPACT);
        dcp::Time last;
-       player->Text.connect([&last](PlayerText text, TextType, optional<DCPTextTrack>, dcpomatic::DCPTimePeriod) {
+       player.Text.connect([&last](PlayerText text, TextType, optional<DCPTextTrack>, dcpomatic::DCPTimePeriod) {
                for (auto sub: text.string) {
                        BOOST_CHECK(sub.in() >= last);
                        last = sub.in();
                }
        });
-       while (!player->pass()) {}
+       while (!player.pass()) {}
 }
 
index e322dbda520a62076b9e9fcefce8ed100eb565a2..ce8b67ed649e89bb82cea062bd23f47ddafee60e 100644 (file)
@@ -270,7 +270,7 @@ BOOST_AUTO_TEST_CASE (threed_test_butler_overfill)
        film->examine_and_add_content(B);
        BOOST_REQUIRE (!wait_for_jobs());
 
-       auto player = std::make_shared<Player>(film, Image::Alignment::COMPACT);
+       Player player(film, Image::Alignment::COMPACT);
        int const audio_channels = 2;
        auto butler = std::make_shared<Butler>(
                film, player, AudioMapping(), audio_channels, boost::bind(PlayerVideo::force, AV_PIX_FMT_RGB24), VideoRange::FULL, Image::Alignment::PADDED, true, false, Butler::Audio::ENABLED