From 1a43dcc9b0d4c40cb8a19f2ff475c67ace4ef6a2 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 26 Oct 2022 19:41:12 +0200 Subject: [PATCH] Allow move construction of Player. --- src/lib/player.cc | 92 ++++++++++++++++++++++++++++++++++++++++++++--- src/lib/player.h | 16 +++++---- 2 files changed, 98 insertions(+), 10 deletions(-) diff --git a/src/lib/player.cc b/src/lib/player.cc index e9ca38c81..29237d93e 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -140,18 +140,102 @@ Player::construct () auto film = _film.lock(); DCPOMATIC_ASSERT(film); + connect(); + set_video_container_size(film->frame_size()); + + film_change (ChangeType::DONE, Film::Property::AUDIO_PROCESSOR); + + setup_pieces (); + seek (DCPTime (), true); +} + + +void +Player::connect() +{ + auto film = _film.lock(); + DCPOMATIC_ASSERT(film); + _film_changed_connection = film->Change.connect(bind(&Player::film_change, this, _1, _2)); /* The butler must hear about this first, so since we are proxying this through to the butler we must be first. */ _playlist_change_connection = playlist()->Change.connect (bind (&Player::playlist_change, this, _1), boost::signals2::at_front); _playlist_content_change_connection = playlist()->ContentChange.connect (bind(&Player::playlist_content_change, this, _1, _3, _4)); - set_video_container_size(film->frame_size()); +} - film_change (ChangeType::DONE, Film::Property::AUDIO_PROCESSOR); - setup_pieces (); - seek (DCPTime (), true); +Player::Player(Player&& other) + : _film(other._film) + , _playlist(std::move(other._playlist)) + , _suspended(other._suspended.load()) + , _pieces(std::move(other._pieces)) + , _video_container_size(other._video_container_size.load()) + , _black_image(std::move(other._black_image)) + , _ignore_video(other._ignore_video.load()) + , _ignore_audio(other._ignore_audio.load()) + , _ignore_text(other._ignore_text.load()) + , _always_burn_open_subtitles(other._always_burn_open_subtitles.load()) + , _fast(other._fast.load()) + , _tolerant(other._tolerant) + , _play_referenced(other._play_referenced.load()) + , _next_video_time(other._next_video_time) + , _next_audio_time(other._next_audio_time) + , _dcp_decode_reduction(other._dcp_decode_reduction.load()) + , _last_video(std::move(other._last_video)) + , _audio_merger(std::move(other._audio_merger)) + , _shuffler(std::move(other._shuffler)) + , _delay(std::move(other._delay)) + , _stream_states(std::move(other._stream_states)) + , _black(std::move(other._black)) + , _silent(std::move(other._silent)) + , _active_texts(std::move(other._active_texts)) + , _audio_processor(std::move(other._audio_processor)) + , _playback_length(other._playback_length.load()) + , _subtitle_alignment(other._subtitle_alignment) +{ + connect(); +} + + +Player& +Player::operator=(Player&& other) +{ + if (this == &other) { + return *this; + } + + _film = std::move(other._film); + _playlist = std::move(other._playlist); + _suspended = other._suspended.load(); + _pieces = std::move(other._pieces); + _video_container_size = other._video_container_size.load(); + _black_image = std::move(other._black_image); + _ignore_video = other._ignore_video.load(); + _ignore_audio = other._ignore_audio.load(); + _ignore_text = other._ignore_text.load(); + _always_burn_open_subtitles = other._always_burn_open_subtitles.load(); + _fast = other._fast.load(); + _tolerant = other._tolerant; + _play_referenced = other._play_referenced.load(); + _next_video_time = other._next_video_time; + _next_audio_time = other._next_audio_time; + _dcp_decode_reduction = other._dcp_decode_reduction.load(); + _last_video = std::move(other._last_video); + _audio_merger = std::move(other._audio_merger); + _shuffler = std::move(other._shuffler); + _delay = std::move(other._delay); + _stream_states = std::move(other._stream_states); + _black = std::move(other._black); + _silent = std::move(other._silent); + _active_texts = std::move(other._active_texts); + _audio_processor = std::move(other._audio_processor); + _playback_length = other._playback_length.load(); + _subtitle_alignment = other._subtitle_alignment; + + connect(); + + return *this; } diff --git a/src/lib/player.h b/src/lib/player.h index 6e83da103..894f74bfc 100644 --- a/src/lib/player.h +++ b/src/lib/player.h @@ -80,8 +80,11 @@ public: Player (std::shared_ptr, Image::Alignment subtitle_alignment); Player (std::shared_ptr, std::shared_ptr playlist); - Player (Player const& Player) = delete; - Player& operator= (Player const& Player) = delete; + Player (Player const&) = delete; + Player& operator= (Player const&) = delete; + + Player(Player&& other); + Player& operator=(Player&& other); bool pass (); void seek (dcpomatic::DCPTime time, bool accurate); @@ -137,6 +140,7 @@ private: friend struct overlap_video_test1; void construct (); + void connect(); void setup_pieces (); void film_change (ChangeType, Film::Property); void playlist_change (ChangeType); @@ -173,9 +177,9 @@ private: */ mutable boost::mutex _mutex; - std::weak_ptr const _film; + std::weak_ptr _film; /** Playlist, or 0 if we are using the one from the _film */ - std::shared_ptr const _playlist; + std::shared_ptr _playlist; /** > 0 if we are suspended (i.e. pass() and seek() do nothing) */ boost::atomic _suspended; @@ -198,7 +202,7 @@ private: /** true if we should try to be fast rather than high quality */ boost::atomic _fast; /** true if we should keep going in the face of `survivable' errors */ - bool const _tolerant; + bool _tolerant; /** true if we should `play' (i.e output) referenced DCP data (e.g. for preview) */ boost::atomic _play_referenced; @@ -242,7 +246,7 @@ private: boost::atomic _playback_length; /** Alignment for subtitle images that we create */ - Image::Alignment const _subtitle_alignment = Image::Alignment::PADDED; + Image::Alignment _subtitle_alignment = Image::Alignment::PADDED; boost::signals2::scoped_connection _film_changed_connection; boost::signals2::scoped_connection _playlist_change_connection; -- 2.30.2