Use Film::length() rather than Playlist::length() (former is rounded up
authorCarl Hetherington <cth@carlh.net>
Wed, 12 Jul 2017 14:17:50 +0000 (15:17 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 12 Jul 2017 14:17:50 +0000 (15:17 +0100)
to the next video frame).  Fix thinko in ::done().  Fix initial value
of _position when the first empty period does not start at time 0.

src/lib/empty.cc
src/lib/empty.h

index 2233b43426e7d859875fae85792c693d5d04f832..98bf1f3d186e2619d864706e82dbebde22b2b108 100644 (file)
@@ -19,6 +19,7 @@
 */
 
 #include "empty.h"
+#include "film.h"
 #include "playlist.h"
 #include "content.h"
 #include "content_part.h"
@@ -33,16 +34,20 @@ using boost::shared_ptr;
 using boost::dynamic_pointer_cast;
 using boost::function;
 
-Empty::Empty (shared_ptr<const Playlist> playlist, function<shared_ptr<ContentPart> (Content *)> part)
+Empty::Empty (shared_ptr<const Film> film, function<shared_ptr<ContentPart> (Content *)> part)
 {
        list<DCPTimePeriod> full;
-       BOOST_FOREACH (shared_ptr<Content> i, playlist->content()) {
+       BOOST_FOREACH (shared_ptr<Content> i, film->content()) {
                if (part (i.get())) {
                        full.push_back (DCPTimePeriod (i->position(), i->end()));
                }
        }
 
-       _periods = subtract (DCPTimePeriod(DCPTime(), playlist->length()), coalesce(full));
+       _periods = subtract (DCPTimePeriod(DCPTime(), film->length()), coalesce(full));
+
+       if (!_periods.empty ()) {
+               _position = _periods.front().from;
+       }
 }
 
 void
@@ -79,11 +84,10 @@ Empty::period_at_position () const
 bool
 Empty::done () const
 {
+       DCPTime latest;
        BOOST_FOREACH (DCPTimePeriod i, _periods) {
-               if (i.contains(_position)) {
-                       return false;
-               }
+               latest = max (latest, i.to);
        }
 
-       return true;
+       return _position >= latest;
 }
index 3c676deeb6b2f4573537c2a45aea56fd6c203096..ee11714289eaa42fe729c20d0854f00e019a849c 100644 (file)
 #include <list>
 
 struct empty_test1;
+struct empty_test2;
+struct player_subframe_test;
 
 class Empty
 {
 public:
        Empty () {}
-       Empty (boost::shared_ptr<const Playlist> playlist, boost::function<boost::shared_ptr<ContentPart> (Content *)> part);
+       Empty (boost::shared_ptr<const Film> film, boost::function<boost::shared_ptr<ContentPart> (Content *)> part);
 
        DCPTime position () const {
                return _position;
@@ -43,6 +45,8 @@ public:
 
 private:
        friend struct ::empty_test1;
+       friend struct ::empty_test2;
+       friend struct ::player_subframe_test;
 
        std::list<DCPTimePeriod> _periods;
        DCPTime _position;