+
+vector<boost::filesystem::path>
+DCPContent::directories () const
+{
+ return dcp::DCP::directories_from_files (paths());
+}
+
+void
+DCPContent::add_properties (shared_ptr<const Film> film, list<UserProperty>& p) const
+{
+ Content::add_properties (film, p);
+ if (video) {
+ video->add_properties (p);
+ }
+ if (audio) {
+ audio->add_properties (film, p);
+ }
+}
+
+void
+DCPContent::set_default_colour_conversion ()
+{
+ /* Default to no colour conversion for DCPs */
+ if (video) {
+ video->unset_colour_conversion ();
+ }
+}
+
+void
+DCPContent::set_reference_video (bool r)
+{
+ ContentChangeSignaller cc (this, DCPContentProperty::REFERENCE_VIDEO);
+
+ {
+ boost::mutex::scoped_lock lm (_mutex);
+ _reference_video = r;
+ }
+}
+
+void
+DCPContent::set_reference_audio (bool r)
+{
+ ContentChangeSignaller cc (this, DCPContentProperty::REFERENCE_AUDIO);
+
+ {
+ boost::mutex::scoped_lock lm (_mutex);
+ _reference_audio = r;
+ }
+}
+
+void
+DCPContent::set_reference_text (TextType type, bool r)
+{
+ ContentChangeSignaller cc (this, DCPContentProperty::REFERENCE_TEXT);
+
+ {
+ boost::mutex::scoped_lock lm (_mutex);
+ _reference_text[static_cast<int>(type)] = r;
+ }
+}
+
+list<DCPTimePeriod>
+DCPContent::reels (shared_ptr<const Film> film) const
+{
+ auto 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(), film->tolerant()));
+ 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 */
+ auto pos = position() - DCPTime (trim_start().get());
+
+ for (auto 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;
+ for (auto 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::Standard::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::Standard::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;
+ }
+
+ auto const fr = film->reels ();
+
+ list<DCPTimePeriod> reel_list;
+ try {
+ reel_list = reels (film);
+ } catch (dcp::ReadError &) {
+ /* 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().
+ */
+ for (auto 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;
+ }
+ }
+
+ auto 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) && c->video->use();
+}
+
+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;
+ }
+
+ if (film->resolution() != resolution()) {
+ if (resolution() == Resolution::FOUR_K) {
+ /// 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) && !c->audio->mapping().mapped_output_channels().empty();
+}
+
+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, film->tolerant(), shared_ptr<DCPDecoder>()));
+ } catch (dcp::ReadError &) {
+ /* 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;
+ }
+
+ for (auto 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, film->tolerant(), shared_ptr<DCPDecoder>()));
+ } catch (dcp::ReadError &) {
+ /* We couldn't read the DCP, so it's probably missing */
+ return false;
+ } catch (dcp::KDMDecryptionError &) {
+ /* We have an incorrect KDM */
+ return false;
+ }
+
+ for (auto i: decoder->reels()) {
+ if (type == TextType::OPEN_SUBTITLE) {
+ if (!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;
+ } else if (i->main_subtitle()->entry_point().get_value_or(0) != 0) {
+ /// TRANSLATORS: this string will follow "Cannot reference this DCP: "
+ why_not = _("one if its subtitle reels has a non-zero entry point so it must be re-written.");
+ return false;
+ }
+ }
+ if (type == TextType::CLOSED_CAPTION) {
+ if (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;
+ }
+ for (auto j: i->closed_captions()) {
+ if (j->entry_point().get_value_or(0) != 0) {
+ /// TRANSLATORS: this string will follow "Cannot reference this DCP: "
+ why_not = _("one if its closed caption has a non-zero entry point so it must be re-written.");
+ return false;
+ }
+ }
+ }
+ }
+
+ if (trim_start() != dcpomatic::ContentTime()) {
+ /// TRANSLATORS: this string will follow "Cannot reference this DCP: "
+ why_not = _("it has a start trim so its subtitles or closed captions must be re-written.");
+ 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)
+{
+ auto 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 < static_cast<int>(TextType::COUNT); ++i) {
+ _reference_text[i] = dc->_reference_text[i];
+ }
+}
+
+void
+DCPContent::set_cpl (string id)
+{
+ ContentChangeSignaller 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();
+}
+
+
+Resolution
+DCPContent::resolution () const
+{
+ if (video->size().width > 2048 || video->size().height > 1080) {
+ return Resolution::FOUR_K;
+ }
+
+ return Resolution::TWO_K;
+}
+