WIP: allow Piece to take multiple content/decoder.
[dcpomatic.git] / test / shuffler_test.cc
index 6d90ba27d99092f32dc3d850bb49c882fe7f1043..16b6dc0bdb847f286bbe37a927f858602ae8cd7d 100644 (file)
@@ -1,27 +1,60 @@
-#include "lib/shuffler.h"
+/*
+    Copyright (C) 2013-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/decoder_factory.h"
+#include "lib/image_content.h"
 #include "lib/piece.h"
-#include "lib/content_video.h"
+#include "lib/piece_video.h"
+#include "lib/shuffler.h"
+#include "test.h"
 #include <boost/test/unit_test.hpp>
 
+
 using std::list;
-using boost::shared_ptr;
-using boost::weak_ptr;
+using std::make_shared;
+using std::shared_ptr;
+using std::weak_ptr;
 using boost::optional;
+#if BOOST_VERSION >= 106100
+using namespace boost::placeholders;
+#endif
+
 
 static void
-push (Shuffler& s, int frame, Eyes eyes)
+push (Shuffler& s, shared_ptr<Film> film, shared_ptr<Content> content, shared_ptr<Decoder> decoder, int frame, Eyes eyes)
 {
-       shared_ptr<Piece> piece (new Piece (shared_ptr<Content>(), shared_ptr<Decoder>(), FrameRateChange(24, 24)));
-       ContentVideo cv;
+       auto pc = {
+               Piece::Pair(content, decoder)
+       };
+       auto piece = make_shared<Piece>(film, pc, FrameRateChange(24, 24), false);
+       PieceVideo cv;
        cv.frame = frame;
        cv.eyes = eyes;
        s.video (piece, cv);
 }
 
-list<ContentVideo> pending_cv;
+list<PieceVideo> pending_cv;
 
 static void
-receive (weak_ptr<Piece>, ContentVideo cv)
+receive (weak_ptr<Piece>, PieceVideo cv)
 {
        pending_cv.push_back (cv);
 }
@@ -41,11 +74,16 @@ BOOST_AUTO_TEST_CASE (shuffler_test1)
        Shuffler s;
        s.Video.connect (boost::bind (&receive, _1, _2));
 
+       auto film = new_test_film2 ("shuffler_test1");
+       auto content = make_shared<ImageContent>("test/data/flat_red.png");
+       auto decoder = decoder_factory (film, content, true, {});
+       BOOST_REQUIRE (decoder);
+
        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, film, content, decoder, i, Eyes::LEFT);
+               push (s, film, content, decoder, i, Eyes::RIGHT);
+               check (i, Eyes::LEFT, __LINE__);
+               check (i, Eyes::RIGHT, __LINE__);
        }
 }
 
@@ -55,15 +93,19 @@ BOOST_AUTO_TEST_CASE (shuffler_test2)
        Shuffler s;
        s.Video.connect (boost::bind (&receive, _1, _2));
 
+       auto film = new_test_film2 ("shuffler_test2");
+       auto content = make_shared<ImageContent>("test/data/flat_red.png");
+       auto decoder = decoder_factory (film, content, true, {});
+
        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, film, content, decoder, i, Eyes::LEFT);
+               push (s, film, content, decoder, i + 1, Eyes::LEFT);
+               push (s, film, content, decoder, i, Eyes::RIGHT);
+               push (s, film, content, decoder, 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__);
        }
 }
 
@@ -73,25 +115,29 @@ 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);
+       auto film = new_test_film2 ("shuffler_test3");
+       auto content = make_shared<ImageContent>("test/data/flat_red.png");
+       auto decoder = decoder_factory (film, content, true, {});
+
+       push (s, film, content, decoder, 0, Eyes::LEFT);
+       check (0, Eyes::LEFT, __LINE__);
+       push (s, film, content, decoder, 0, Eyes::RIGHT);
+       check (0, Eyes::RIGHT, __LINE__);
+       push (s, film, content, decoder, 1, Eyes::LEFT);
+       check (1, Eyes::LEFT, __LINE__);
+       push (s, film, content, decoder, 1, Eyes::RIGHT);
+       check (1, Eyes::RIGHT, __LINE__);
+       push (s, film, content, decoder, 2, Eyes::RIGHT);
+       push (s, film, content, decoder, 3, Eyes::LEFT);
+       push (s, film, content, decoder, 3, Eyes::RIGHT);
+       push (s, film, content, decoder, 4, Eyes::LEFT);
+       push (s, film, content, decoder, 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 */
@@ -100,25 +146,29 @@ 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);
+       auto film = new_test_film2 ("shuffler_test3");
+       auto content = make_shared<ImageContent>("test/data/flat_red.png");
+       auto decoder = decoder_factory (film, content, true, {});
+
+       push (s, film, content, decoder, 0, Eyes::LEFT);
+       check (0, Eyes::LEFT, __LINE__);
+       push (s, film, content, decoder, 0, Eyes::RIGHT);
+       check (0, Eyes::RIGHT, __LINE__);
+       push (s, film, content, decoder, 1, Eyes::LEFT);
+       check (1, Eyes::LEFT, __LINE__);
+       push (s, film, content, decoder, 1, Eyes::RIGHT);
+       check (1, Eyes::RIGHT, __LINE__);
+       push (s, film, content, decoder, 2, Eyes::LEFT);
+       push (s, film, content, decoder, 3, Eyes::LEFT);
+       push (s, film, content, decoder, 3, Eyes::RIGHT);
+       push (s, film, content, decoder, 4, Eyes::LEFT);
+       push (s, film, content, decoder, 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 */
@@ -127,21 +177,25 @@ BOOST_AUTO_TEST_CASE (shuffler_test5)
        Shuffler s;
        s.Video.connect (boost::bind (&receive, _1, _2));
 
+       auto film = new_test_film2 ("shuffler_test3");
+       auto content = make_shared<ImageContent>("test/data/flat_red.png");
+       auto decoder = decoder_factory (film, content, true, {});
+
        /* One left should come out straight away */
-       push (s, 0, EYES_LEFT);
-       check (0, EYES_LEFT, __LINE__);
+       push (s, film, content, decoder, 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, film, content, decoder, 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, film, content, decoder, s._max_size + 1, Eyes::LEFT);
+       check (1, Eyes::LEFT, __LINE__);
 }
 
 /** One complete frame (L+R) missing.
@@ -152,18 +206,22 @@ 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__);
+       auto film = new_test_film2 ("shuffler_test3");
+       auto content = make_shared<ImageContent>("test/data/flat_red.png");
+       auto decoder = decoder_factory (film, content, true, {});
+
+       push (s, film, content, decoder, 0, Eyes::LEFT);
+       check (0, Eyes::LEFT, __LINE__);
+       push (s, film, content, decoder, 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, film, content, decoder, 2, Eyes::LEFT);
+       push (s, film, content, decoder, 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, film, content, decoder, 3, Eyes::LEFT);
+       check (3, Eyes::LEFT, __LINE__);
+       push (s, film, content, decoder, 3, Eyes::RIGHT);
+       check (3, Eyes::RIGHT, __LINE__);
 }