+ return !needs_kdm() && !needs_assets();
+}
+
+bool
+DCPContent::needs_kdm () const
+{
+ boost::mutex::scoped_lock lm (_mutex);
+ return _encrypted && !_kdm_valid;
+}
+
+bool
+DCPContent::needs_assets () const
+{
+ boost::mutex::scoped_lock lm (_mutex);
+ return _needs_assets;
+}
+
+vector<boost::filesystem::path>
+DCPContent::directories () const
+{
+ return dcp::DCP::directories_from_files (paths());
+}
+
+void
+DCPContent::add_properties (list<UserProperty>& p) const
+{
+ Content::add_properties (p);
+ if (video) {
+ video->add_properties (p);
+ }
+ if (audio) {
+ audio->add_properties (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)
+{
+ {
+ boost::mutex::scoped_lock lm (_mutex);
+ _reference_video = r;
+ }
+
+ signal_changed (DCPContentProperty::REFERENCE_VIDEO);
+}
+
+void
+DCPContent::set_reference_audio (bool r)
+{
+ {
+ boost::mutex::scoped_lock lm (_mutex);
+ _reference_audio = r;
+ }
+
+ signal_changed (DCPContentProperty::REFERENCE_AUDIO);
+}
+
+void
+DCPContent::set_reference_caption (CaptionType type, bool r)
+{
+ {
+ boost::mutex::scoped_lock lm (_mutex);
+ _reference_caption[type] = r;
+ }
+
+ signal_changed (DCPContentProperty::REFERENCE_CAPTION);
+}
+
+list<DCPTimePeriod>
+DCPContent::reels () 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().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(), to)));
+ if (to > end()) {
+ break;
+ }
+ }
+ pos = to;
+ }
+
+ return p;
+}
+
+list<DCPTime>
+DCPContent::reel_split_points () const
+{
+ list<DCPTime> s;
+ BOOST_FOREACH (DCPTimePeriod i, reels()) {
+ s.push_back (i.from);
+ }
+ return s;
+}
+
+bool
+DCPContent::can_reference (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 ();
+ } 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()->content(), part, position(), end());
+ 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 (string& why_not) const
+{
+ if (!video) {
+ why_not = _("There is no video in this DCP");
+ return false;
+ }
+
+ 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 (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 (string& why_not) const
+{
+ shared_ptr<DCPDecoder> decoder;
+ try {
+ decoder.reset (new DCPDecoder (shared_from_this(), film()->log(), 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 (bind (&check_audio, _1), _("it overlaps other audio content; remove the other content."), why_not);
+}
+
+static
+bool check_caption (shared_ptr<const Content> c)
+{
+ return !c->caption.empty();
+}
+bool
+DCPContent::can_reference_caption (CaptionType type, string& why_not) const
+{
+ shared_ptr<DCPDecoder> decoder;
+ try {
+ decoder.reset (new DCPDecoder (shared_from_this(), film()->log(), 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 == CAPTION_OPEN && !i->main_subtitle()) {
+ /// TRANSLATORS: this string will follow "Cannot reference this DCP: "
+ why_not = _("it does not have subtitles in all its reels.");
+ return false;
+ }
+ if (type == CAPTION_CLOSED && !i->closed_caption()) {
+ /// 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 (bind (&check_caption, _1), _("it overlaps other caption 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 < CAPTION_COUNT; ++i) {
+ _reference_caption[i] = dc->_reference_caption[i];
+ }
+}
+
+void
+DCPContent::set_cpl (string id)
+{
+ boost::mutex::scoped_lock lm (_mutex);
+ _cpl = id;