From: Carl Hetherington Date: Mon, 20 Aug 2018 22:01:14 +0000 (+0100) Subject: Make ContentChange into a generic ChangeSignaller and use it for Film X-Git-Tag: v2.13.44^0 X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=5dbd022f3abb0ebab57fb67073a07ed60df902a6 Make ContentChange into a generic ChangeSignaller and use it for Film changes, since we setup_pieces() in response to at least one of these and hence we must know before it happens so we can suspend the butler and player. --- diff --git a/src/lib/audio_content.cc b/src/lib/audio_content.cc index 703696a44..f3212ca7a 100644 --- a/src/lib/audio_content.cc +++ b/src/lib/audio_content.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2016 Carl Hetherington + Copyright (C) 2013-2018 Carl Hetherington This file is part of DCP-o-matic. @@ -146,7 +146,7 @@ AudioContent::technical_summary () const void AudioContent::set_mapping (AudioMapping mapping) { - ContentChange cc (_parent, AudioContentProperty::STREAMS); + ChangeSignaller cc (_parent, AudioContentProperty::STREAMS); int c = 0; BOOST_FOREACH (AudioStreamPtr i, streams ()) { @@ -341,7 +341,7 @@ AudioContent::add_properties (list& p) const void AudioContent::set_streams (vector streams) { - ContentChange cc (_parent, AudioContentProperty::STREAMS); + ChangeSignaller cc (_parent, AudioContentProperty::STREAMS); { boost::mutex::scoped_lock lm (_mutex); @@ -360,7 +360,7 @@ AudioContent::stream () const void AudioContent::add_stream (AudioStreamPtr stream) { - ContentChange cc (_parent, AudioContentProperty::STREAMS); + ChangeSignaller cc (_parent, AudioContentProperty::STREAMS); { boost::mutex::scoped_lock lm (_mutex); @@ -371,7 +371,7 @@ AudioContent::add_stream (AudioStreamPtr stream) void AudioContent::set_stream (AudioStreamPtr stream) { - ContentChange cc (_parent, AudioContentProperty::STREAMS); + ChangeSignaller cc (_parent, AudioContentProperty::STREAMS); { boost::mutex::scoped_lock lm (_mutex); diff --git a/src/lib/change_signaller.h b/src/lib/change_signaller.h new file mode 100644 index 000000000..ec1f14ea3 --- /dev/null +++ b/src/lib/change_signaller.h @@ -0,0 +1,58 @@ +/* + Copyright (C) 2018 Carl Hetherington + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see . + +*/ + +#ifndef DCPOMATIC_CHANGE_H +#define DCPOMATIC_CHANGE_H + +#include + +template +class ChangeSignaller : public boost::noncopyable +{ +public: + ChangeSignaller (T* t, int p) + : _thing (t) + , _property (p) + , _done (true) + { + _thing->signal_change (CHANGE_TYPE_PENDING, _property); + } + + ~ChangeSignaller () + { + if (_done) { + _thing->signal_change (CHANGE_TYPE_DONE, _property); + } else { + _thing->signal_change (CHANGE_TYPE_CANCELLED, _property); + } + } + + void abort () + { + _done = false; + } + +private: + T* _thing; + int _property; + bool _done; +}; + +#endif diff --git a/src/lib/content.cc b/src/lib/content.cc index ae0b08dcc..04bdc8126 100644 --- a/src/lib/content.cc +++ b/src/lib/content.cc @@ -23,6 +23,7 @@ */ #include "content.h" +#include "change_signaller.h" #include "util.h" #include "content_factory.h" #include "video_content.h" @@ -205,7 +206,7 @@ Content::set_position (DCPTime p) audio->modify_position (p); } - ContentChange cc (this, ContentProperty::POSITION); + ChangeSignaller cc (this, ContentProperty::POSITION); { boost::mutex::scoped_lock lm (_mutex); @@ -231,7 +232,7 @@ Content::set_trim_start (ContentTime t) audio->modify_trim_start (t); } - ContentChange cc (this, ContentProperty::TRIM_START); + ChangeSignaller cc (this, ContentProperty::TRIM_START); { boost::mutex::scoped_lock lm (_mutex); @@ -242,7 +243,7 @@ Content::set_trim_start (ContentTime t) void Content::set_trim_end (ContentTime t) { - ContentChange cc (this, ContentProperty::TRIM_END); + ChangeSignaller cc (this, ContentProperty::TRIM_END); { boost::mutex::scoped_lock lm (_mutex); @@ -310,7 +311,7 @@ Content::paths_valid () const void Content::set_path (boost::filesystem::path path) { - ContentChange cc (this, ContentProperty::PATH); + ChangeSignaller cc (this, ContentProperty::PATH); _paths.clear (); _paths.push_back (path); } @@ -318,7 +319,7 @@ Content::set_path (boost::filesystem::path path) void Content::set_paths (vector paths) { - ContentChange cc (this, ContentProperty::PATH); + ChangeSignaller cc (this, ContentProperty::PATH); _paths = paths; } @@ -369,7 +370,7 @@ Content::reel_split_points () const void Content::set_video_frame_rate (double r) { - ContentChange cc (this, ContentProperty::VIDEO_FRAME_RATE); + ChangeSignaller cc (this, ContentProperty::VIDEO_FRAME_RATE); { boost::mutex::scoped_lock lm (_mutex); @@ -385,7 +386,7 @@ Content::set_video_frame_rate (double r) void Content::unset_video_frame_rate () { - ContentChange cc (this, ContentProperty::VIDEO_FRAME_RATE); + ChangeSignaller cc (this, ContentProperty::VIDEO_FRAME_RATE); { boost::mutex::scoped_lock lm (_mutex); diff --git a/src/lib/content.h b/src/lib/content.h index e8710ccb7..d519dc52b 100644 --- a/src/lib/content.h +++ b/src/lib/content.h @@ -28,6 +28,7 @@ #include "types.h" #include "signaller.h" #include "dcpomatic_time.h" +#include "change_signaller.h" #include "user_property.h" #include #include @@ -207,7 +208,7 @@ private: friend struct best_dcp_frame_rate_test_single; friend struct best_dcp_frame_rate_test_double; friend struct audio_sampling_rate_test; - friend class ContentChange; + template friend class ChangeSignaller; void signal_change (ChangeType, int); diff --git a/src/lib/content_change.cc b/src/lib/content_change.cc deleted file mode 100644 index 6e390dc76..000000000 --- a/src/lib/content_change.cc +++ /dev/null @@ -1,46 +0,0 @@ -/* - Copyright (C) 2013-2018 Carl Hetherington - - This file is part of DCP-o-matic. - - DCP-o-matic is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - DCP-o-matic is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with DCP-o-matic. If not, see . - -*/ - -#include "content_change.h" -#include "content.h" - -ContentChange::ContentChange (Content* c, int p) - : _content (c) - , _property (p) - , _done (true) -{ - _content->signal_change (CHANGE_TYPE_PENDING, _property); -} - - -ContentChange::~ContentChange () -{ - if (_done) { - _content->signal_change (CHANGE_TYPE_DONE, _property); - } else { - _content->signal_change (CHANGE_TYPE_CANCELLED, _property); - } -} - -void -ContentChange::abort () -{ - _done = false; -} diff --git a/src/lib/content_change.h b/src/lib/content_change.h deleted file mode 100644 index 67012a7a5..000000000 --- a/src/lib/content_change.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - Copyright (C) 2013-2018 Carl Hetherington - - This file is part of DCP-o-matic. - - DCP-o-matic is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - DCP-o-matic is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with DCP-o-matic. If not, see . - -*/ - -class Content; - -class ContentChange -{ -public: - ContentChange (Content* c, int p); - ~ContentChange (); - - void abort (); - -private: - Content* _content; - int _property; - bool _done; -}; diff --git a/src/lib/content_part.h b/src/lib/content_part.h index 58833655f..eb96b1371 100644 --- a/src/lib/content_part.h +++ b/src/lib/content_part.h @@ -23,7 +23,7 @@ #define DCPOMATIC_CONTENT_PART_H #include "content.h" -#include "content_change.h" +#include "change_signaller.h" #include #include @@ -42,7 +42,7 @@ protected: void maybe_set (T& member, T new_value, int property) const { - ContentChange cc (_parent, property); + ChangeSignaller cc (_parent, property); { boost::mutex::scoped_lock lm (_mutex); if (member == new_value) { @@ -57,7 +57,7 @@ protected: void maybe_set (boost::optional& member, T new_value, int property) const { - ContentChange cc (_parent, property); + ChangeSignaller cc (_parent, property); { boost::mutex::scoped_lock lm (_mutex); if (member && member.get() == new_value) { diff --git a/src/lib/dcp_content.cc b/src/lib/dcp_content.cc index a527b1f80..0514ca6f7 100644 --- a/src/lib/dcp_content.cc +++ b/src/lib/dcp_content.cc @@ -159,11 +159,11 @@ DCPContent::examine (shared_ptr job) string const old_name = name (); int const old_texts = text.size (); - ContentChange cc_texts (this, DCPContentProperty::TEXTS); - ContentChange cc_assets (this, DCPContentProperty::NEEDS_ASSETS); - ContentChange cc_kdm (this, DCPContentProperty::NEEDS_KDM); - ContentChange cc_name (this, DCPContentProperty::NAME); - ContentChange cc_streams (this, AudioContentProperty::STREAMS); + ChangeSignaller cc_texts (this, DCPContentProperty::TEXTS); + ChangeSignaller cc_assets (this, DCPContentProperty::NEEDS_ASSETS); + ChangeSignaller cc_kdm (this, DCPContentProperty::NEEDS_KDM); + ChangeSignaller cc_name (this, DCPContentProperty::NAME); + ChangeSignaller cc_streams (this, AudioContentProperty::STREAMS); if (job) { job->set_progress_unknown (); @@ -182,7 +182,7 @@ DCPContent::examine (shared_ptr job) } if (examiner->has_audio()) { - ContentChange cc (this, AudioContentProperty::STREAMS); + ChangeSignaller cc (this, AudioContentProperty::STREAMS); { boost::mutex::scoped_lock lm (_mutex); audio.reset (new AudioContent (this)); @@ -401,7 +401,7 @@ DCPContent::set_default_colour_conversion () void DCPContent::set_reference_video (bool r) { - ContentChange cc (this, DCPContentProperty::REFERENCE_VIDEO); + ChangeSignaller cc (this, DCPContentProperty::REFERENCE_VIDEO); { boost::mutex::scoped_lock lm (_mutex); @@ -412,7 +412,7 @@ DCPContent::set_reference_video (bool r) void DCPContent::set_reference_audio (bool r) { - ContentChange cc (this, DCPContentProperty::REFERENCE_AUDIO); + ChangeSignaller cc (this, DCPContentProperty::REFERENCE_AUDIO); { boost::mutex::scoped_lock lm (_mutex); @@ -423,7 +423,7 @@ DCPContent::set_reference_audio (bool r) void DCPContent::set_reference_text (TextType type, bool r) { - ContentChange cc (this, DCPContentProperty::REFERENCE_TEXT); + ChangeSignaller cc (this, DCPContentProperty::REFERENCE_TEXT); { boost::mutex::scoped_lock lm (_mutex); @@ -649,7 +649,7 @@ DCPContent::take_settings_from (shared_ptr c) void DCPContent::set_cpl (string id) { - ContentChange cc (this, DCPContentProperty::CPL); + ChangeSignaller cc (this, DCPContentProperty::CPL); { boost::mutex::scoped_lock lm (_mutex); diff --git a/src/lib/ffmpeg_content.cc b/src/lib/ffmpeg_content.cc index 05b6ae8ea..961c0b0a3 100644 --- a/src/lib/ffmpeg_content.cc +++ b/src/lib/ffmpeg_content.cc @@ -251,8 +251,8 @@ FFmpegContent::as_xml (xmlpp::Node* node, bool with_paths) const void FFmpegContent::examine (shared_ptr job) { - ContentChange cc1 (this, FFmpegContentProperty::SUBTITLE_STREAMS); - ContentChange cc2 (this, FFmpegContentProperty::SUBTITLE_STREAM); + ChangeSignaller cc1 (this, FFmpegContentProperty::SUBTITLE_STREAMS); + ChangeSignaller cc2 (this, FFmpegContentProperty::SUBTITLE_STREAM); job->set_progress_unknown (); @@ -369,7 +369,7 @@ FFmpegContent::technical_summary () const void FFmpegContent::set_subtitle_stream (shared_ptr s) { - ContentChange cc (this, FFmpegContentProperty::SUBTITLE_STREAM); + ChangeSignaller cc (this, FFmpegContentProperty::SUBTITLE_STREAM); { boost::mutex::scoped_lock lm (_mutex); @@ -410,7 +410,7 @@ FFmpegContent::full_length () const void FFmpegContent::set_filters (vector const & filters) { - ContentChange cc (this, FFmpegContentProperty::FILTERS); + ChangeSignaller cc (this, FFmpegContentProperty::FILTERS); { boost::mutex::scoped_lock lm (_mutex); @@ -630,7 +630,7 @@ void FFmpegContent::signal_subtitle_stream_changed () { /* XXX: this is too late; really it should be before the change */ - ContentChange cc (this, FFmpegContentProperty::SUBTITLE_STREAM); + ChangeSignaller cc (this, FFmpegContentProperty::SUBTITLE_STREAM); } vector > diff --git a/src/lib/film.cc b/src/lib/film.cc index eaaa611af..8576c5a67 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -51,6 +51,7 @@ #include "dcp_content.h" #include "screen_kdm.h" #include "cinema.h" +#include "change_signaller.h" #include #include #include @@ -824,141 +825,142 @@ Film::set_directory (boost::filesystem::path d) void Film::set_name (string n) { + ChangeSignaller ch (this, NAME); _name = n; - signal_changed (NAME); } void Film::set_use_isdcf_name (bool u) { + ChangeSignaller ch (this, USE_ISDCF_NAME); _use_isdcf_name = u; - signal_changed (USE_ISDCF_NAME); } void Film::set_dcp_content_type (DCPContentType const * t) { + ChangeSignaller ch (this, DCP_CONTENT_TYPE); _dcp_content_type = t; - signal_changed (DCP_CONTENT_TYPE); } void Film::set_container (Ratio const * c) { + ChangeSignaller ch (this, CONTAINER); _container = c; - signal_changed (CONTAINER); } void Film::set_resolution (Resolution r) { + ChangeSignaller ch (this, RESOLUTION); _resolution = r; - signal_changed (RESOLUTION); } void Film::set_j2k_bandwidth (int b) { + ChangeSignaller ch (this, J2K_BANDWIDTH); _j2k_bandwidth = b; - signal_changed (J2K_BANDWIDTH); } void Film::set_isdcf_metadata (ISDCFMetadata m) { + ChangeSignaller ch (this, ISDCF_METADATA); _isdcf_metadata = m; - signal_changed (ISDCF_METADATA); } void Film::set_video_frame_rate (int f) { + ChangeSignaller ch (this, VIDEO_FRAME_RATE); _video_frame_rate = f; - signal_changed (VIDEO_FRAME_RATE); } void Film::set_audio_channels (int c) { + ChangeSignaller ch (this, AUDIO_CHANNELS); _audio_channels = c; - signal_changed (AUDIO_CHANNELS); } void Film::set_three_d (bool t) { + ChangeSignaller ch (this, THREE_D); _three_d = t; - signal_changed (THREE_D); if (_three_d && _isdcf_metadata.two_d_version_of_three_d) { + ChangeSignaller ch (this, ISDCF_METADATA); _isdcf_metadata.two_d_version_of_three_d = false; - signal_changed (ISDCF_METADATA); } } void Film::set_interop (bool i) { + ChangeSignaller ch (this, INTEROP); _interop = i; - signal_changed (INTEROP); } void Film::set_audio_processor (AudioProcessor const * processor) { + ChangeSignaller ch1 (this, AUDIO_PROCESSOR); + ChangeSignaller ch2 (this, AUDIO_CHANNELS); _audio_processor = processor; - signal_changed (AUDIO_PROCESSOR); - signal_changed (AUDIO_CHANNELS); } void Film::set_reel_type (ReelType t) { + ChangeSignaller ch (this, REEL_TYPE); _reel_type = t; - signal_changed (REEL_TYPE); } /** @param r Desired reel length in bytes */ void Film::set_reel_length (int64_t r) { + ChangeSignaller ch (this, REEL_LENGTH); _reel_length = r; - signal_changed (REEL_LENGTH); } void Film::set_upload_after_make_dcp (bool u) { + ChangeSignaller ch (this, UPLOAD_AFTER_MAKE_DCP); _upload_after_make_dcp = u; - signal_changed (UPLOAD_AFTER_MAKE_DCP); } void -Film::signal_changed (Property p) +Film::signal_change (ChangeType type, int p) { - _dirty = true; - - Change (CHANGE_TYPE_PENDING, p); - bool changed = false; + signal_change (type, static_cast(p)); +} - switch (p) { - case Film::CONTENT: - set_video_frame_rate (_playlist->best_video_frame_rate ()); - changed = true; - break; - case Film::VIDEO_FRAME_RATE: - case Film::SEQUENCE: - _playlist->maybe_sequence (); - changed = true; - break; - default: - break; - } +void +Film::signal_change (ChangeType type, Property p) +{ + if (type == CHANGE_TYPE_DONE) { + _dirty = true; + + switch (p) { + case Film::CONTENT: + set_video_frame_rate (_playlist->best_video_frame_rate ()); + break; + case Film::VIDEO_FRAME_RATE: + case Film::SEQUENCE: + _playlist->maybe_sequence (); + break; + default: + break; + } - if (changed) { - emit (boost::bind (boost::ref (Change), CHANGE_TYPE_DONE, p)); + emit (boost::bind (boost::ref (Change), type, p)); } else { - Change (CHANGE_TYPE_CANCELLED, p); + Change (type, p); } } @@ -1036,22 +1038,22 @@ Film::cpls () const void Film::set_signed (bool s) { + ChangeSignaller ch (this, SIGNED); _signed = s; - signal_changed (SIGNED); } void Film::set_encrypted (bool e) { + ChangeSignaller ch (this, ENCRYPTED); _encrypted = e; - signal_changed (ENCRYPTED); } void Film::set_key (dcp::Key key) { + ChangeSignaller ch (this, KEY); _key = key; - signal_changed (KEY); } ContentList @@ -1165,34 +1167,31 @@ Film::active_frame_rate_change (DCPTime t) const void Film::playlist_content_change (ChangeType type, weak_ptr c, int p, bool frequent) { - if (type != CHANGE_TYPE_DONE) { - return; - } - - _dirty = true; - if (p == ContentProperty::VIDEO_FRAME_RATE) { - set_video_frame_rate (_playlist->best_video_frame_rate ()); + signal_change (type, Film::CONTENT); } else if (p == AudioContentProperty::STREAMS) { - signal_changed (NAME); + signal_change (type, Film::NAME); } - emit (boost::bind (boost::ref (ContentChange), type, c, p, frequent)); + if (type == CHANGE_TYPE_DONE) { + emit (boost::bind (boost::ref (ContentChange), type, c, p, frequent)); + } else { + ContentChange (type, c, p, frequent); + } } void Film::playlist_change (ChangeType type) { - if (type == CHANGE_TYPE_DONE) { - signal_changed (CONTENT); - signal_changed (NAME); - } + signal_change (type, CONTENT); + signal_change (type, NAME); } void Film::playlist_order_changed () { - signal_changed (CONTENT_ORDER); + /* XXX: missing PENDING */ + signal_change (CHANGE_TYPE_DONE, CONTENT_ORDER); } int @@ -1214,9 +1213,9 @@ Film::set_sequence (bool s) return; } + ChangeSignaller cc (this, SEQUENCE); _sequence = s; _playlist->set_sequence (s); - signal_changed (SEQUENCE); } /** @return Size of the largest possible image in whatever resolution we are using */ diff --git a/src/lib/film.h b/src/lib/film.h index 649768c7a..26700323a 100644 --- a/src/lib/film.h +++ b/src/lib/film.h @@ -335,8 +335,10 @@ public: private: friend struct ::isdcf_name_test; + template friend class ChangeSignaller; - void signal_changed (Property); + void signal_change (ChangeType, Property); + void signal_change (ChangeType, int); std::string video_identifier () const; void playlist_change (ChangeType); void playlist_order_changed (); diff --git a/src/lib/text_content.cc b/src/lib/text_content.cc index 35dee525a..a077b2c46 100644 --- a/src/lib/text_content.cc +++ b/src/lib/text_content.cc @@ -427,7 +427,7 @@ void TextContent::font_changed () { /* XXX: too late */ - ContentChange cc (_parent, TextContentProperty::FONTS); + ChangeSignaller cc (_parent, TextContentProperty::FONTS); } void diff --git a/src/lib/video_content.cc b/src/lib/video_content.cc index 81f4138fb..8cb305463 100644 --- a/src/lib/video_content.cc +++ b/src/lib/video_content.cc @@ -234,9 +234,9 @@ VideoContent::take_from_examiner (shared_ptr d) optional const ar = d->sample_aspect_ratio (); bool const yuv = d->yuv (); - ContentChange cc1 (_parent, VideoContentProperty::SIZE); - ContentChange cc2 (_parent, VideoContentProperty::SCALE); - ContentChange cc3 (_parent, ContentProperty::LENGTH); + ChangeSignaller cc1 (_parent, VideoContentProperty::SIZE); + ChangeSignaller cc2 (_parent, VideoContentProperty::SCALE); + ChangeSignaller cc3 (_parent, ContentProperty::LENGTH); { boost::mutex::scoped_lock lm (_mutex); diff --git a/src/lib/wscript b/src/lib/wscript index 68e44ccd0..0cc3d7823 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -47,7 +47,6 @@ sources = """ colour_conversion.cc config.cc content.cc - content_change.cc content_factory.cc cross.cc curl_uploader.cc