Add duration() methods to CPL and Reel.
authorCarl Hetherington <cth@carlh.net>
Wed, 16 Dec 2015 21:39:01 +0000 (21:39 +0000)
committerCarl Hetherington <cth@carlh.net>
Wed, 16 Dec 2015 21:39:01 +0000 (21:39 +0000)
src/cpl.cc
src/cpl.h
src/reel.cc
src/reel.h

index 24c8a18af0068939af0161330349a3ed31048fa2..9633abc45293245b79857926812e605c589c91b1 100644 (file)
@@ -255,3 +255,13 @@ CPL::pkl_type (Standard standard) const
                DCP_ASSERT (false);
        }
 }
+
+int64_t
+CPL::duration () const
+{
+       int64_t d = 0;
+       BOOST_FOREACH (shared_ptr<Reel> i, _reels) {
+               d += i->duration ();
+       }
+       return d;
+}
index d38c0090bd451f999b959ba87d7f8bc0d81e25c3..b616aeaae7146dc25ebcae83e5b627d45e31bd5c 100644 (file)
--- a/src/cpl.h
+++ b/src/cpl.h
@@ -113,6 +113,8 @@ public:
 
        void resolve_refs (std::list<boost::shared_ptr<Asset> >);
 
+       int64_t duration () const;
+
 protected:
        /** @return type string for PKLs for this asset */
        std::string pkl_type (Standard standard) const;
index ddab12d39481ae774c2cbfecd8142945cc31f62e..3ab9993f9bab14c0ed769772effee05040965a32 100644 (file)
@@ -36,6 +36,7 @@
 using std::string;
 using std::list;
 using std::cout;
+using std::max;
 using boost::shared_ptr;
 using boost::dynamic_pointer_cast;
 using namespace dcp;
@@ -185,3 +186,21 @@ Reel::resolve_refs (list<shared_ptr<Asset> > assets)
                }
        }
 }
+
+int64_t
+Reel::duration () const
+{
+       int64_t d = 0;
+
+       if (_main_picture) {
+               d = max (d, _main_picture->duration ());
+       }
+       if (_main_sound) {
+               d = max (d, _main_sound->duration ());
+       }
+       if (_main_subtitle) {
+               d = max (d, _main_subtitle->duration ());
+       }
+
+       return d;
+}
index 3b3673efb41f975bb1b2cca413e18bbf1137a0ee..7711d1012c4ed4927eea12957286b7de7636cbf0 100644 (file)
@@ -71,6 +71,8 @@ public:
                return _main_subtitle;
        }
 
+       int64_t duration () const;
+
        void add (boost::shared_ptr<ReelAsset> asset);
 
        void write_to_cpl (xmlpp::Element* node, Standard standard) const;