+ if (video) {
+ video->unset_colour_conversion ();
+ }
+}
+
+void
+DCPContent::set_reference_video (bool r)
+{
+ ChangeSignaller<Content> cc (this, DCPContentProperty::REFERENCE_VIDEO);
+
+ {
+ boost::mutex::scoped_lock lm (_mutex);
+ _reference_video = r;
+ }
+}
+
+void
+DCPContent::set_reference_audio (bool r)
+{
+ ChangeSignaller<Content> cc (this, DCPContentProperty::REFERENCE_AUDIO);
+
+ {
+ boost::mutex::scoped_lock lm (_mutex);
+ _reference_audio = r;
+ }
+}
+
+void
+DCPContent::set_reference_text (TextType type, bool r)
+{
+ ChangeSignaller<Content> cc (this, DCPContentProperty::REFERENCE_TEXT);
+
+ {
+ boost::mutex::scoped_lock lm (_mutex);
+ _reference_text[type] = r;
+ }
+}
+
+list<DCPTimePeriod>
+DCPContent::reels (shared_ptr<const Film> film) const
+{
+ list<int64_t> reel_lengths = _reel_lengths;
+ if (reel_lengths.empty ()) {
+ /* Old metadata with no reel lengths; get them here instead */
+ try {
+ scoped_ptr<DCPExaminer> examiner (new DCPExaminer (shared_from_this()));
+ reel_lengths = examiner->reel_lengths ();
+ } catch (...) {
+ /* Could not examine the DCP; guess reels */
+ reel_lengths.push_back (length_after_trim(film).frames_round(film->video_frame_rate()));
+ }
+ }
+
+ list<DCPTimePeriod> p;
+
+ /* This content's frame rate must be the same as the output DCP rate, so we can
+ convert `directly' from ContentTime to DCPTime.
+ */
+
+ /* The starting point of this content on the timeline */
+ DCPTime pos = position() - DCPTime (trim_start().get());
+
+ BOOST_FOREACH (int64_t i, reel_lengths) {
+ /* This reel runs from `pos' to `to' */
+ DCPTime const to = pos + DCPTime::from_frames (i, film->video_frame_rate());
+ if (to > position()) {
+ p.push_back (DCPTimePeriod (max(position(), pos), min(end(film), to)));
+ if (to > end(film)) {
+ break;
+ }
+ }
+ pos = to;
+ }
+
+ return p;
+}
+
+list<DCPTime>
+DCPContent::reel_split_points (shared_ptr<const Film> film) const
+{
+ list<DCPTime> s;
+ BOOST_FOREACH (DCPTimePeriod i, reels(film)) {
+ s.push_back (i.from);
+ }
+ return s;
+}
+
+bool
+DCPContent::can_reference (shared_ptr<const Film> film, function<bool (shared_ptr<const Content>)> part, string overlapping, string& why_not) const
+{
+ /* We must be using the same standard as the film */
+ if (_standard) {
+ if (_standard.get() == dcp::INTEROP && !film->interop()) {
+ /// TRANSLATORS: this string will follow "Cannot reference this DCP: "
+ why_not = _("it is Interop and the film is set to SMPTE.");
+ return false;
+ } else if (_standard.get() == dcp::SMPTE && film->interop()) {
+ /// TRANSLATORS: this string will follow "Cannot reference this DCP: "
+ why_not = _("it is SMPTE and the film is set to Interop.");
+ return false;
+ }
+ }
+
+ /* And the same frame rate */
+ if (!video_frame_rate() || (lrint(video_frame_rate().get()) != film->video_frame_rate())) {
+ /// TRANSLATORS: this string will follow "Cannot reference this DCP: "
+ why_not = _("it has a different frame rate to the film.");
+ return false;
+ }
+
+ list<DCPTimePeriod> const fr = film->reels ();
+
+ list<DCPTimePeriod> reel_list;
+ try {
+ reel_list = reels (film);
+ } catch (dcp::DCPReadError &) {
+ /* We couldn't read the DCP; it's probably missing */
+ return false;
+ } catch (dcp::KDMDecryptionError &) {
+ /* We have an incorrect KDM */
+ return false;
+ }
+
+ /* fr must contain reels(). It can also contain other reels, but it must at
+ least contain reels().
+ */
+ BOOST_FOREACH (DCPTimePeriod i, reel_list) {
+ if (find (fr.begin(), fr.end(), i) == fr.end ()) {
+ /// TRANSLATORS: this string will follow "Cannot reference this DCP: "
+ why_not = _("its reel lengths differ from those in the film; set the reel mode to 'split by video content'.");
+ return false;
+ }
+ }
+
+ ContentList a = overlaps (film, film->content(), part, position(), end(film));
+ if (a.size() != 1 || a.front().get() != this) {
+ why_not = overlapping;
+ return false;
+ }
+
+ return true;
+}
+
+static
+bool check_video (shared_ptr<const Content> c)
+{
+ return static_cast<bool>(c->video);
+}
+
+bool
+DCPContent::can_reference_video (shared_ptr<const Film> film, string& why_not) const
+{
+ if (!video) {
+ why_not = _("There is no video in this DCP");
+ return false;
+ }
+
+ Resolution video_res = RESOLUTION_2K;
+ if (video->size().width > 2048 || video->size().height > 1080) {
+ video_res = RESOLUTION_4K;
+ }
+
+ if (film->resolution() != video_res) {
+ if (video_res == RESOLUTION_4K) {
+ /// TRANSLATORS: this string will follow "Cannot reference this DCP: "
+ why_not = _("it is 4K and the film is 2K.");
+ } else {
+ /// TRANSLATORS: this string will follow "Cannot reference this DCP: "
+ why_not = _("it is 2K and the film is 4K.");
+ }
+ return false;
+ } else if (film->frame_size() != video->size()) {
+ /// TRANSLATORS: this string will follow "Cannot reference this DCP: "
+ why_not = _("its video frame size differs from the film's.");
+ return false;
+ }
+
+ /// TRANSLATORS: this string will follow "Cannot reference this DCP: "
+ return can_reference (film, bind (&check_video, _1), _("it overlaps other video content; remove the other content."), why_not);
+}
+
+static
+bool check_audio (shared_ptr<const Content> c)
+{
+ return static_cast<bool>(c->audio);
+}
+
+bool
+DCPContent::can_reference_audio (shared_ptr<const Film> film, string& why_not) const
+{
+ shared_ptr<DCPDecoder> decoder;
+ try {
+ decoder.reset (new DCPDecoder (film, shared_from_this(), false));
+ } catch (dcp::DCPReadError &) {
+ /* We couldn't read the DCP, so it's probably missing */
+ return false;
+ } catch (DCPError &) {
+ /* We couldn't read the DCP, so it's probably missing */
+ return false;
+ } catch (dcp::KDMDecryptionError &) {
+ /* We have an incorrect KDM */
+ return false;
+ }
+
+ BOOST_FOREACH (shared_ptr<dcp::Reel> i, decoder->reels()) {
+ if (!i->main_sound()) {
+ /// TRANSLATORS: this string will follow "Cannot reference this DCP: "
+ why_not = _("it does not have sound in all its reels.");
+ return false;
+ }
+ }
+
+ /// TRANSLATORS: this string will follow "Cannot reference this DCP: "
+ return can_reference (film, bind (&check_audio, _1), _("it overlaps other audio content; remove the other content."), why_not);
+}
+
+static
+bool check_text (shared_ptr<const Content> c)
+{
+ return !c->text.empty();
+}
+
+bool
+DCPContent::can_reference_text (shared_ptr<const Film> film, TextType type, string& why_not) const
+{
+ shared_ptr<DCPDecoder> decoder;
+ try {
+ decoder.reset (new DCPDecoder (film, shared_from_this(), false));
+ } catch (dcp::DCPReadError &) {
+ /* We couldn't read the DCP, so it's probably missing */
+ return false;
+ } catch (dcp::KDMDecryptionError &) {
+ /* We have an incorrect KDM */
+ return false;
+ }
+
+ BOOST_FOREACH (shared_ptr<dcp::Reel> i, decoder->reels()) {
+ if (type == TEXT_OPEN_SUBTITLE && !i->main_subtitle()) {
+ /// TRANSLATORS: this string will follow "Cannot reference this DCP: "
+ why_not = _("it does not have open subtitles in all its reels.");
+ return false;
+ }
+ if (type == TEXT_CLOSED_CAPTION && i->closed_captions().empty()) {
+ /// TRANSLATORS: this string will follow "Cannot reference this DCP: "
+ why_not = _("it does not have closed captions in all its reels.");
+ return false;
+ }
+ }
+
+ /// TRANSLATORS: this string will follow "Cannot reference this DCP: "
+ return can_reference (film, bind (&check_text, _1), _("it overlaps other text content; remove the other content."), why_not);
+}
+
+void
+DCPContent::take_settings_from (shared_ptr<const Content> c)
+{
+ shared_ptr<const DCPContent> dc = dynamic_pointer_cast<const DCPContent> (c);
+ if (!dc) {
+ return;
+ }
+
+ _reference_video = dc->_reference_video;
+ _reference_audio = dc->_reference_audio;
+ for (int i = 0; i < TEXT_COUNT; ++i) {
+ _reference_text[i] = dc->_reference_text[i];
+ }
+}
+
+void
+DCPContent::set_cpl (string id)
+{
+ ChangeSignaller<Content> cc (this, DCPContentProperty::CPL);
+
+ {
+ boost::mutex::scoped_lock lm (_mutex);
+ _cpl = id;
+ }
+}
+
+bool
+DCPContent::kdm_timing_window_valid () const
+{
+ if (!_kdm) {
+ return true;
+ }
+
+ dcp::LocalTime now;
+ return _kdm->not_valid_before() < now && now < _kdm->not_valid_after();