From e330669de0f5d7d9d922dc69945cca74ac9800d9 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 16 Dec 2015 21:39:01 +0000 Subject: Add duration() methods to CPL and Reel. --- src/cpl.cc | 10 ++++++++++ src/cpl.h | 2 ++ src/reel.cc | 19 +++++++++++++++++++ src/reel.h | 2 ++ 4 files changed, 33 insertions(+) (limited to 'src') diff --git a/src/cpl.cc b/src/cpl.cc index 24c8a18a..9633abc4 100644 --- a/src/cpl.cc +++ b/src/cpl.cc @@ -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 i, _reels) { + d += i->duration (); + } + return d; +} diff --git a/src/cpl.h b/src/cpl.h index d38c0090..b616aeaa 100644 --- a/src/cpl.h +++ b/src/cpl.h @@ -113,6 +113,8 @@ public: void resolve_refs (std::list >); + int64_t duration () const; + protected: /** @return type string for PKLs for this asset */ std::string pkl_type (Standard standard) const; diff --git a/src/reel.cc b/src/reel.cc index ddab12d3..3ab9993f 100644 --- a/src/reel.cc +++ b/src/reel.cc @@ -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 > 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; +} diff --git a/src/reel.h b/src/reel.h index 3b3673ef..7711d101 100644 --- a/src/reel.h +++ b/src/reel.h @@ -71,6 +71,8 @@ public: return _main_subtitle; } + int64_t duration () const; + void add (boost::shared_ptr asset); void write_to_cpl (xmlpp::Element* node, Standard standard) const; -- cgit v1.2.3