From 7d8d78c183656191ff44c9464e06b843bfadc54d Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sat, 15 Oct 2022 00:28:32 +0200 Subject: [PATCH] Remove some more unnecessary use of shared_ptr. --- src/lib/butler.cc | 16 +++++----- src/lib/butler.h | 4 +-- src/lib/dcp_encoder.cc | 12 +++---- src/lib/encoder.cc | 2 +- src/lib/encoder.h | 3 +- src/lib/ffmpeg_encoder.cc | 4 +-- src/lib/subtitle_encoder.cc | 12 +++---- src/wx/film_viewer.cc | 10 ++++-- src/wx/film_viewer.h | 2 +- test/butler_test.cc | 8 +++-- test/dcp_playback_test.cc | 4 ++- test/player_test.cc | 64 ++++++++++++++++++------------------- test/threed_test.cc | 2 +- 13 files changed, 77 insertions(+), 66 deletions(-) diff --git a/src/lib/butler.cc b/src/lib/butler.cc index ce35b1f39..b2fbc6c60 100644 --- a/src/lib/butler.cc +++ b/src/lib/butler.cc @@ -62,7 +62,7 @@ using namespace boost::placeholders; */ Butler::Butler ( weak_ptr film, - shared_ptr player, + Player& player, AudioMapping audio_mapping, int audio_channels, function 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 (); } @@ -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; diff --git a/src/lib/butler.h b/src/lib/butler.h index bac94a742..1dba6e129 100644 --- a/src/lib/butler.h +++ b/src/lib/butler.h @@ -50,7 +50,7 @@ public: Butler ( std::weak_ptr film, - std::shared_ptr player, + Player& player, AudioMapping map, int audio_channels, std::function pixel_format, @@ -105,7 +105,7 @@ private: void seek_unlocked (dcpomatic::DCPTime position, bool accurate); std::weak_ptr _film; - std::shared_ptr _player; + Player& _player; boost::thread _thread; VideoRingBuffers _video; diff --git a/src/lib/dcp_encoder.cc b/src/lib/dcp_encoder.cc index 16a99e79e..9a840c8ab 100644 --- a/src/lib/dcp_encoder.cc +++ b/src/lib/dcp_encoder.cc @@ -68,10 +68,10 @@ DCPEncoder::DCPEncoder (shared_ptr film, weak_ptr 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); diff --git a/src/lib/encoder.cc b/src/lib/encoder.cc index 1d688c318..5268d8620 100644 --- a/src/lib/encoder.cc +++ b/src/lib/encoder.cc @@ -41,7 +41,7 @@ Encoder::Encoder (std::shared_ptr film, std::weak_ptr job) : _film (film) , _job (job) - , _player (new Player(film, Image::Alignment::PADDED)) + , _player(film, Image::Alignment::PADDED) { } diff --git a/src/lib/encoder.h b/src/lib/encoder.h index 19c1120b3..24217b124 100644 --- a/src/lib/encoder.h +++ b/src/lib/encoder.h @@ -23,6 +23,7 @@ #define DCPOMATIC_ENCODER_H +#include "player.h" #include "player_text.h" #include "types.h" #include @@ -62,7 +63,7 @@ public: protected: std::shared_ptr _film; std::weak_ptr _job; - std::shared_ptr _player; + Player _player; }; diff --git a/src/lib/ffmpeg_encoder.cc b/src/lib/ffmpeg_encoder.cc index 2fcad68fe..001645af3 100644 --- a/src/lib/ffmpeg_encoder.cc +++ b/src/lib/ffmpeg_encoder.cc @@ -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(); } diff --git a/src/lib/subtitle_encoder.cc b/src/lib/subtitle_encoder.cc index 2331eb52a..51b9963bc 100644 --- a/src/lib/subtitle_encoder.cc +++ b/src/lib/subtitle_encoder.cc @@ -56,10 +56,10 @@ SubtitleEncoder::SubtitleEncoder (shared_ptr film, shared_ptr 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)); } } diff --git a/src/wx/film_viewer.cc b/src/wx/film_viewer.cc index c56e2f5d2..c5fb50217 100644 --- a/src/wx/film_viewer.cc +++ b/src/wx/film_viewer.cc @@ -161,14 +161,14 @@ FilmViewer::set_film (shared_ptr film) _closed_captions_dialog->clear (); if (!_film) { - _player.reset (); + _player = boost::none; recreate_butler (); _video_view->update (); return; } try { - _player = make_shared(_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( _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, 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 FilmViewer::position_in_content (shared_ptr content) const { + DCPOMATIC_ASSERT(_player); return _player->dcp_to_content_time (content, position()); } diff --git a/src/wx/film_viewer.h b/src/wx/film_viewer.h index 1fa85a621..062522ffd 100644 --- a/src/wx/film_viewer.h +++ b/src/wx/film_viewer.h @@ -175,7 +175,7 @@ private: bool quick_refresh (); std::shared_ptr _film; - std::shared_ptr _player; + boost::optional _player; std::shared_ptr _video_view; bool _coalesce_player_changes = false; diff --git a/test/butler_test.cc b/test/butler_test.cc index 1645d4100..97e4ccc0e 100644 --- a/test/butler_test.cc +++ b/test/butler_test.cc @@ -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(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(film, Image::Alignment::COMPACT), + player, map, 6, boost::bind(&PlayerVideo::force, AV_PIX_FMT_RGB24), diff --git a/test/dcp_playback_test.cc b/test/dcp_playback_test.cc index 62c72cc84..a5b69e181 100644 --- a/test/dcp_playback_test.cc +++ b/test/dcp_playback_test.cc @@ -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( film, - make_shared(film, Image::Alignment::PADDED), + player, AudioMapping(6, 6), 6, boost::bind(&PlayerVideo::force, AV_PIX_FMT_RGB24), diff --git a/test/player_test.cc b/test/player_test.cc index 19336ac4f..6b29cbc30 100644 --- a/test/player_test.cc +++ b/test/player_test.cc @@ -83,9 +83,9 @@ BOOST_AUTO_TEST_CASE (player_silence_padding_test) accumulated = std::make_shared(film->audio_channels(), 0); - auto player = std::make_shared(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(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(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(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( 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(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 (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(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 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(film, Image::Alignment::COMPACT); - player->set_fast (); + Player player(film, Image::Alignment::COMPACT); + player.set_fast(); auto butler = std::make_shared( 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(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(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(film, Image::Alignment::COMPACT); + Player player(film, Image::Alignment::COMPACT); dcp::Time last; - player->Text.connect([&last](PlayerText text, TextType, optional, dcpomatic::DCPTimePeriod) { + player.Text.connect([&last](PlayerText text, TextType, optional, dcpomatic::DCPTimePeriod) { for (auto sub: text.string) { BOOST_CHECK(sub.in() >= last); last = sub.in(); } }); - while (!player->pass()) {} + while (!player.pass()) {} } diff --git a/test/threed_test.cc b/test/threed_test.cc index e322dbda5..ce8b67ed6 100644 --- a/test/threed_test.cc +++ b/test/threed_test.cc @@ -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(film, Image::Alignment::COMPACT); + Player player(film, Image::Alignment::COMPACT); int const audio_channels = 2; auto butler = std::make_shared( film, player, AudioMapping(), audio_channels, boost::bind(PlayerVideo::force, AV_PIX_FMT_RGB24), VideoRange::FULL, Image::Alignment::PADDED, true, false, Butler::Audio::ENABLED -- 2.30.2