More of previous.
authorCarl Hetherington <cth@carlh.net>
Mon, 16 May 2016 21:40:50 +0000 (22:40 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 18 May 2016 10:50:29 +0000 (11:50 +0100)
src/lib/dcp_content.cc
src/lib/dcp_content.h
src/lib/overlaps.h
src/lib/wscript

index b28e91dd5cb30d74bf964ae827efa771bb378124..023af8e951aab073a10ae383567a4271e5c80fdc 100644 (file)
@@ -48,6 +48,7 @@ using std::list;
 using boost::shared_ptr;
 using boost::scoped_ptr;
 using boost::optional;
+using boost::function;
 
 int const DCPContentProperty::CAN_BE_PLAYED      = 600;
 int const DCPContentProperty::REFERENCE_VIDEO    = 601;
@@ -327,9 +328,8 @@ DCPContent::reel_split_points () const
        return s;
 }
 
-template <class T>
 bool
-DCPContent::can_reference (string overlapping, list<string>& why_not) const
+DCPContent::can_reference (function<shared_ptr<ContentPart> (shared_ptr<const Content>)> part, string overlapping, list<string>& why_not) const
 {
        list<DCPTimePeriod> const fr = film()->reels ();
        /* fr must contain reels().  It can also contain other reels, but it must at
@@ -342,7 +342,7 @@ DCPContent::can_reference (string overlapping, list<string>& why_not) const
                }
        }
 
-       list<shared_ptr<T> > a = overlaps<T> (film()->content(), position(), end());
+       ContentList a = overlaps (film()->content(), part, position(), end());
        if (a.size() != 1 || a.front().get() != this) {
                why_not.push_back (overlapping);
                return false;
@@ -354,20 +354,33 @@ DCPContent::can_reference (string overlapping, list<string>& why_not) const
 bool
 DCPContent::can_reference_video (list<string>& why_not) const
 {
-       /* XXX: this needs to be fixed */
-       return true;
+       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
 {
-       /* XXX: this needs to be fixed */
-       return true;
+        DCPDecoder decoder (shared_from_this(), film()->log(), false);
+        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
 {
-       /* XXX: this needs to be fixed */
-       return true;
+        DCPDecoder decoder (shared_from_this(), film()->log(), false);
+        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);
 }
index 5c80587dd130f5a6e9f5be289d99be1b22ccc832..489151e03cb912c50afaab1a719b3415c2979559 100644 (file)
@@ -37,6 +37,8 @@ public:
        static int const REFERENCE_SUBTITLE;
 };
 
+class ContentPart;
+
 /** @class DCPContent
  *  @brief An existing DCP used as input.
  */
@@ -112,7 +114,11 @@ private:
 
        void read_directory (boost::filesystem::path);
        std::list<DCPTimePeriod> reels () const;
-       template <class T> bool can_reference (std::string overlapping, std::list<std::string>& why_not) const;
+       bool can_reference (
+               boost::function <boost::shared_ptr<ContentPart> (boost::shared_ptr<const Content>)>,
+               std::string overlapping,
+               std::list<std::string>& why_not
+               ) const;
 
        std::string _name;
        /** true if our DCP is encrypted */
index 6018af15f56ff7dec1b3b37bea5af8e38f4403c3..d8a44b554d76bbe12f4b0e2d63d5b836a0ee8d88 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2013-2015 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2013-2016 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 
 */
 
-/** @return Pieces of content type C that overlap a specified time range in the given ContentList */
-template<class C>
-std::list<boost::shared_ptr<C> >
-overlaps (ContentList cl, DCPTime from, DCPTime to)
-{
-       std::list<boost::shared_ptr<C> > overlaps;
-       DCPTimePeriod period (from, to);
-       for (typename ContentList::const_iterator i = cl.begin(); i != cl.end(); ++i) {
-               boost::shared_ptr<C> c = boost::dynamic_pointer_cast<C> (*i);
-               if (!c) {
-                       continue;
-               }
+#include "types.h"
+#include "dcpomatic_time.h"
 
-               if (DCPTimePeriod(c->position(), c->end()).overlaps (period)) {
-                       overlaps.push_back (c);
-               }
-       }
+class ContentPart;
 
-       return overlaps;
-}
+/** @return Pieces of content with a given part (video, audio,
+ * subtitle) that overlap a specified time range in the given
+ * ContentList */
+ContentList overlaps (
+       ContentList cl, boost::function<boost::shared_ptr<ContentPart> (boost::shared_ptr<const Content>)> part, DCPTime from, DCPTime to
+       );
index 4104e57a70496856af7e5590e0b25055a45aa03e..4b6754b2e9d7432f9a8d12985f632379d755f260 100644 (file)
@@ -94,6 +94,7 @@ sources = """
           magick_image_proxy.cc
           md5_digester.cc
           mid_side_decoder.cc
+          overlaps.cc
           player.cc
           player_subtitles.cc
           player_video.cc