+ locked_stringstream s;
+ s << Content::identifier() << "_" << video->identifier() << "_";
+ if (subtitle) {
+ s << subtitle->identifier () << " ";
+ }
+ s << (_reference_video ? "1" : "0")
+ << (_reference_subtitle ? "1" : "0");
+ return s.str ();
+}
+
+void
+DCPContent::add_kdm (dcp::EncryptedKDM k)
+{
+ _kdm = k;
+}
+
+bool
+DCPContent::can_be_played () const
+{
+ boost::mutex::scoped_lock lm (_mutex);
+ return !_encrypted || _kdm_valid;
+}
+
+boost::filesystem::path
+DCPContent::directory () const
+{
+ optional<size_t> smallest;
+ boost::filesystem::path dir;
+ for (size_t i = 0; i < number_of_paths(); ++i) {
+ boost::filesystem::path const p = path (i).parent_path ();
+ size_t const d = distance (p.begin(), p.end());
+ if (!smallest || d < smallest.get ()) {
+ dir = p;
+ }
+ }
+
+ return dir;
+}
+
+void
+DCPContent::add_properties (list<UserProperty>& p) const
+{
+ Content::add_properties (p);
+ video->add_properties (p);
+ audio->add_properties (p);
+}
+
+void
+DCPContent::set_default_colour_conversion ()
+{
+ /* Default to no colour conversion for DCPs */
+ 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_subtitle (bool r)
+{
+ {
+ boost::mutex::scoped_lock lm (_mutex);
+ _reference_subtitle = r;
+ }
+
+ signal_changed (DCPContentProperty::REFERENCE_SUBTITLE);
+}
+
+list<DCPTimePeriod>
+DCPContent::reels () const
+{
+ list<DCPTimePeriod> p;
+ scoped_ptr<DCPDecoder> decoder;
+ try {
+ decoder.reset (new DCPDecoder (shared_from_this(), film()->log()));
+ } catch (...) {
+ /* Could not load the DCP; guess reels */
+ list<DCPTimePeriod> p;
+ p.push_back (DCPTimePeriod (position(), end()));
+ return p;
+ }
+
+ DCPTime from = position ();
+ BOOST_FOREACH (shared_ptr<dcp::Reel> i, decoder->reels()) {
+ DCPTime const to = from + DCPTime::from_frames (i->main_picture()->duration(), film()->video_frame_rate());
+ p.push_back (DCPTimePeriod (from, to));
+ from = 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<shared_ptr<ContentPart> (shared_ptr<const Content>)> part, string overlapping, list<string>& why_not) const
+{
+ /* We must be using the same standard as the film */
+ if (_standard) {
+ if (_standard.get() == dcp::INTEROP && !film()->interop()) {
+ why_not.push_back (_("The film is set to SMPTE and this DCP is Interop."));
+ return false;
+ } else if (_standard.get() == dcp::SMPTE && film()->interop()) {
+ why_not.push_back (_("The film is set to Interop and this DCP is SMPTE."));
+ return false;
+ }
+ }
+
+ list<DCPTimePeriod> const fr = film()->reels ();
+ /* fr must contain reels(). It can also contain other reels, but it must at
+ least contain reels().
+ */
+ BOOST_FOREACH (DCPTimePeriod i, reels()) {
+ if (find (fr.begin(), fr.end(), i) == fr.end ()) {
+ why_not.push_back (_("Reel lengths in the film differ from those in the DCP; 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.push_back (overlapping);
+ return false;
+ }
+
+ return true;
+}
+
+bool
+DCPContent::can_reference_video (list<string>& why_not) const
+{
+ return can_reference (bind (&Content::video, _1), _("There is other video content overlapping this DCP; remove it."), why_not);
+}
+
+bool
+DCPContent::can_reference_audio (list<string>& why_not) const
+{
+ DCPDecoder decoder (shared_from_this(), film()->log());
+ BOOST_FOREACH (shared_ptr<dcp::Reel> i, decoder.reels()) {
+ if (!i->main_sound()) {
+ why_not.push_back (_("The DCP does not have sound in all reels."));
+ return false;
+ }
+ }
+
+ return can_reference (bind (&Content::audio, _1), _("There is other audio content overlapping this DCP; remove it."), why_not);
+}
+
+bool
+DCPContent::can_reference_subtitle (list<string>& why_not) const
+{
+ DCPDecoder decoder (shared_from_this(), film()->log());
+ BOOST_FOREACH (shared_ptr<dcp::Reel> i, decoder.reels()) {
+ if (!i->main_subtitle()) {
+ why_not.push_back (_("The DCP does not have subtitles in all reels."));
+ return false;
+ }
+ }
+
+ return can_reference (bind (&Content::subtitle, _1), _("There is other subtitle content overlapping this DCP; remove it."), why_not);