Change how video timing is done.
[dcpomatic.git] / test / shuffler_test.cc
index f6a2a358cd6ff0c6e114395f0134855fc3e54f34..37d6749c38fd36bb2fb46e435385166bb3a2f039 100644 (file)
@@ -1,23 +1,47 @@
-#include "lib/shuffler.h"
-#include "lib/piece.h"
+/*
+    Copyright (C) 2020-2021 Carl Hetherington <cth@carlh.net>
+
+    This file is part of DCP-o-matic.
+
+    DCP-o-matic is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    DCP-o-matic is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+
 #include "lib/content_video.h"
+#include "lib/piece.h"
+#include "lib/shuffler.h"
 #include <boost/test/unit_test.hpp>
 
+
 using std::list;
+using std::make_shared;
 using std::shared_ptr;
 using std::weak_ptr;
 using boost::optional;
 #if BOOST_VERSION >= 106100
 using namespace boost::placeholders;
 #endif
+using namespace dcpomatic;
 
 
 static void
-push (Shuffler& s, int frame, Eyes eyes)
+push(Shuffler& s, int frame, Eyes eyes)
 {
-       shared_ptr<Piece> piece (new Piece (shared_ptr<Content>(), shared_ptr<Decoder>(), FrameRateChange(24, 24)));
+       auto piece = make_shared<Piece>(shared_ptr<Content>(), shared_ptr<Decoder>(), FrameRateChange(24, 24));
        ContentVideo cv;
-       cv.frame = frame;
+       cv.time = ContentTime::from_frames(frame, 24);
        cv.eyes = eyes;
        s.video (piece, cv);
 }
@@ -33,8 +57,9 @@ receive (weak_ptr<Piece>, ContentVideo cv)
 static void
 check (int frame, Eyes eyes, int line)
 {
+       auto const time = ContentTime::from_frames(frame, 24);
        BOOST_REQUIRE_MESSAGE (!pending_cv.empty(), "Check at " << line << " failed.");
-       BOOST_CHECK_MESSAGE (pending_cv.front().frame == frame, "Check at " << line << " failed.");
+       BOOST_CHECK_MESSAGE (pending_cv.front().time == time, "Check at " << line << " failed.");
        BOOST_CHECK_MESSAGE (pending_cv.front().eyes == eyes, "Check at " << line << " failed.");
        pending_cv.pop_front();
 }
@@ -46,10 +71,10 @@ BOOST_AUTO_TEST_CASE (shuffler_test1)
        s.Video.connect (boost::bind (&receive, _1, _2));
 
        for (int i = 0; i < 10; ++i) {
-               push (s, i, EYES_LEFT);
-               push (s, i, EYES_RIGHT);
-               check (i, EYES_LEFT, __LINE__);
-               check (i, EYES_RIGHT, __LINE__);
+               push (s, i, Eyes::LEFT);
+               push (s, i, Eyes::RIGHT);
+               check (i, Eyes::LEFT, __LINE__);
+               check (i, Eyes::RIGHT, __LINE__);
        }
 }
 
@@ -60,14 +85,14 @@ BOOST_AUTO_TEST_CASE (shuffler_test2)
        s.Video.connect (boost::bind (&receive, _1, _2));
 
        for (int i = 0; i < 10; i += 2) {
-               push (s, i, EYES_LEFT);
-               push (s, i + 1, EYES_LEFT);
-               push (s, i, EYES_RIGHT);
-               push (s, i + 1, EYES_RIGHT);
-               check (i, EYES_LEFT, __LINE__);
-               check (i, EYES_RIGHT, __LINE__);
-               check (i + 1, EYES_LEFT, __LINE__);
-               check (i + 1, EYES_RIGHT, __LINE__);
+               push (s, i, Eyes::LEFT);
+               push (s, i + 1, Eyes::LEFT);
+               push (s, i, Eyes::RIGHT);
+               push (s, i + 1, Eyes::RIGHT);
+               check (i, Eyes::LEFT, __LINE__);
+               check (i, Eyes::RIGHT, __LINE__);
+               check (i + 1, Eyes::LEFT, __LINE__);
+               check (i + 1, Eyes::RIGHT, __LINE__);
        }
 }
 
@@ -77,25 +102,25 @@ BOOST_AUTO_TEST_CASE (shuffler_test3)
        Shuffler s;
        s.Video.connect (boost::bind (&receive, _1, _2));
 
-       push (s, 0, EYES_LEFT);
-       check (0, EYES_LEFT, __LINE__);
-       push (s, 0, EYES_RIGHT);
-       check (0, EYES_RIGHT, __LINE__);
-       push (s, 1, EYES_LEFT);
-       check (1, EYES_LEFT, __LINE__);
-       push (s, 1, EYES_RIGHT);
-       check (1, EYES_RIGHT, __LINE__);
-       push (s, 2, EYES_RIGHT);
-       push (s, 3, EYES_LEFT);
-       push (s, 3, EYES_RIGHT);
-       push (s, 4, EYES_LEFT);
-       push (s, 4, EYES_RIGHT);
+       push (s, 0, Eyes::LEFT);
+       check (0, Eyes::LEFT, __LINE__);
+       push (s, 0, Eyes::RIGHT);
+       check (0, Eyes::RIGHT, __LINE__);
+       push (s, 1, Eyes::LEFT);
+       check (1, Eyes::LEFT, __LINE__);
+       push (s, 1, Eyes::RIGHT);
+       check (1, Eyes::RIGHT, __LINE__);
+       push (s, 2, Eyes::RIGHT);
+       push (s, 3, Eyes::LEFT);
+       push (s, 3, Eyes::RIGHT);
+       push (s, 4, Eyes::LEFT);
+       push (s, 4, Eyes::RIGHT);
        s.flush ();
-       check (2, EYES_RIGHT, __LINE__);
-       check (3, EYES_LEFT, __LINE__);
-       check (3, EYES_RIGHT, __LINE__);
-       check (4, EYES_LEFT, __LINE__);
-       check (4, EYES_RIGHT, __LINE__);
+       check (2, Eyes::RIGHT, __LINE__);
+       check (3, Eyes::LEFT, __LINE__);
+       check (3, Eyes::RIGHT, __LINE__);
+       check (4, Eyes::LEFT, __LINE__);
+       check (4, Eyes::RIGHT, __LINE__);
 }
 
 /** One missing right eye image */
@@ -104,25 +129,25 @@ BOOST_AUTO_TEST_CASE (shuffler_test4)
        Shuffler s;
        s.Video.connect (boost::bind (&receive, _1, _2));
 
-       push (s, 0, EYES_LEFT);
-       check (0, EYES_LEFT, __LINE__);
-       push (s, 0, EYES_RIGHT);
-       check (0, EYES_RIGHT, __LINE__);
-       push (s, 1, EYES_LEFT);
-       check (1, EYES_LEFT, __LINE__);
-       push (s, 1, EYES_RIGHT);
-       check (1, EYES_RIGHT, __LINE__);
-       push (s, 2, EYES_LEFT);
-       push (s, 3, EYES_LEFT);
-       push (s, 3, EYES_RIGHT);
-       push (s, 4, EYES_LEFT);
-       push (s, 4, EYES_RIGHT);
+       push (s, 0, Eyes::LEFT);
+       check (0, Eyes::LEFT, __LINE__);
+       push (s, 0, Eyes::RIGHT);
+       check (0, Eyes::RIGHT, __LINE__);
+       push (s, 1, Eyes::LEFT);
+       check (1, Eyes::LEFT, __LINE__);
+       push (s, 1, Eyes::RIGHT);
+       check (1, Eyes::RIGHT, __LINE__);
+       push (s, 2, Eyes::LEFT);
+       push (s, 3, Eyes::LEFT);
+       push (s, 3, Eyes::RIGHT);
+       push (s, 4, Eyes::LEFT);
+       push (s, 4, Eyes::RIGHT);
        s.flush ();
-       check (2, EYES_LEFT, __LINE__);
-       check (3, EYES_LEFT, __LINE__);
-       check (3, EYES_RIGHT, __LINE__);
-       check (4, EYES_LEFT, __LINE__);
-       check (4, EYES_RIGHT, __LINE__);
+       check (2, Eyes::LEFT, __LINE__);
+       check (3, Eyes::LEFT, __LINE__);
+       check (3, Eyes::RIGHT, __LINE__);
+       check (4, Eyes::LEFT, __LINE__);
+       check (4, Eyes::RIGHT, __LINE__);
 }
 
 /** Only one eye */
@@ -132,20 +157,20 @@ BOOST_AUTO_TEST_CASE (shuffler_test5)
        s.Video.connect (boost::bind (&receive, _1, _2));
 
        /* One left should come out straight away */
-       push (s, 0, EYES_LEFT);
-       check (0, EYES_LEFT, __LINE__);
+       push (s, 0, Eyes::LEFT);
+       check (0, Eyes::LEFT, __LINE__);
 
        /* More lefts should be kept in the shuffler in the hope that some rights arrive */
        for (int i = 0; i < s._max_size; ++i) {
-               push (s, i + 1, EYES_LEFT);
+               push (s, i + 1, Eyes::LEFT);
        }
        BOOST_CHECK (pending_cv.empty ());
 
        /* If enough lefts come the shuffler should conclude that there's no rights and start
           giving out the lefts.
        */
-       push (s, s._max_size + 1, EYES_LEFT);
-       check (1, EYES_LEFT, __LINE__);
+       push (s, s._max_size + 1, Eyes::LEFT);
+       check (1, Eyes::LEFT, __LINE__);
 }
 
 /** One complete frame (L+R) missing.
@@ -156,18 +181,18 @@ BOOST_AUTO_TEST_CASE (shuffler_test6)
        Shuffler s;
        s.Video.connect (boost::bind (&receive, _1, _2));
 
-       push (s, 0, EYES_LEFT);
-       check (0, EYES_LEFT, __LINE__);
-       push (s, 0, EYES_RIGHT);
-       check (0, EYES_RIGHT, __LINE__);
+       push (s, 0, Eyes::LEFT);
+       check (0, Eyes::LEFT, __LINE__);
+       push (s, 0, Eyes::RIGHT);
+       check (0, Eyes::RIGHT, __LINE__);
 
-       push (s, 2, EYES_LEFT);
-       push (s, 2, EYES_RIGHT);
-       check (2, EYES_LEFT, __LINE__);
-       check (2, EYES_RIGHT, __LINE__);
+       push (s, 2, Eyes::LEFT);
+       push (s, 2, Eyes::RIGHT);
+       check (2, Eyes::LEFT, __LINE__);
+       check (2, Eyes::RIGHT, __LINE__);
 
-       push (s, 3, EYES_LEFT);
-       check (3, EYES_LEFT, __LINE__);
-       push (s, 3, EYES_RIGHT);
-       check (3, EYES_RIGHT, __LINE__);
+       push (s, 3, Eyes::LEFT);
+       check (3, Eyes::LEFT, __LINE__);
+       push (s, 3, Eyes::RIGHT);
+       check (3, Eyes::RIGHT, __LINE__);
 }