2 Copyright (C) 2020-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
22 #include "lib/content_video.h"
23 #include "lib/piece.h"
24 #include "lib/shuffler.h"
25 #include <boost/test/unit_test.hpp>
29 using std::make_shared;
30 using std::shared_ptr;
32 using boost::optional;
33 #if BOOST_VERSION >= 106100
34 using namespace boost::placeholders;
39 push (Shuffler& s, int frame, Eyes eyes)
41 auto piece = make_shared<Piece>(shared_ptr<Content>(), shared_ptr<Decoder>(), FrameRateChange(24, 24));
48 list<ContentVideo> pending_cv;
51 receive (weak_ptr<Piece>, ContentVideo cv)
53 pending_cv.push_back (cv);
57 check (int frame, Eyes eyes, int line)
59 BOOST_REQUIRE_MESSAGE (!pending_cv.empty(), "Check at " << line << " failed.");
60 BOOST_CHECK_MESSAGE (pending_cv.front().frame == frame, "Check at " << line << " failed.");
61 BOOST_CHECK_MESSAGE (pending_cv.front().eyes == eyes, "Check at " << line << " failed.");
62 pending_cv.pop_front();
65 /** A perfect sequence */
66 BOOST_AUTO_TEST_CASE (shuffler_test1)
69 s.Video.connect (boost::bind (&receive, _1, _2));
71 for (int i = 0; i < 10; ++i) {
72 push (s, i, Eyes::LEFT);
73 push (s, i, Eyes::RIGHT);
74 check (i, Eyes::LEFT, __LINE__);
75 check (i, Eyes::RIGHT, __LINE__);
79 /** Everything present but some simple shuffling needed */
80 BOOST_AUTO_TEST_CASE (shuffler_test2)
83 s.Video.connect (boost::bind (&receive, _1, _2));
85 for (int i = 0; i < 10; i += 2) {
86 push (s, i, Eyes::LEFT);
87 push (s, i + 1, Eyes::LEFT);
88 push (s, i, Eyes::RIGHT);
89 push (s, i + 1, Eyes::RIGHT);
90 check (i, Eyes::LEFT, __LINE__);
91 check (i, Eyes::RIGHT, __LINE__);
92 check (i + 1, Eyes::LEFT, __LINE__);
93 check (i + 1, Eyes::RIGHT, __LINE__);
97 /** One missing left eye image */
98 BOOST_AUTO_TEST_CASE (shuffler_test3)
101 s.Video.connect (boost::bind (&receive, _1, _2));
103 push (s, 0, Eyes::LEFT);
104 check (0, Eyes::LEFT, __LINE__);
105 push (s, 0, Eyes::RIGHT);
106 check (0, Eyes::RIGHT, __LINE__);
107 push (s, 1, Eyes::LEFT);
108 check (1, Eyes::LEFT, __LINE__);
109 push (s, 1, Eyes::RIGHT);
110 check (1, Eyes::RIGHT, __LINE__);
111 push (s, 2, Eyes::RIGHT);
112 push (s, 3, Eyes::LEFT);
113 push (s, 3, Eyes::RIGHT);
114 push (s, 4, Eyes::LEFT);
115 push (s, 4, Eyes::RIGHT);
117 check (2, Eyes::RIGHT, __LINE__);
118 check (3, Eyes::LEFT, __LINE__);
119 check (3, Eyes::RIGHT, __LINE__);
120 check (4, Eyes::LEFT, __LINE__);
121 check (4, Eyes::RIGHT, __LINE__);
124 /** One missing right eye image */
125 BOOST_AUTO_TEST_CASE (shuffler_test4)
128 s.Video.connect (boost::bind (&receive, _1, _2));
130 push (s, 0, Eyes::LEFT);
131 check (0, Eyes::LEFT, __LINE__);
132 push (s, 0, Eyes::RIGHT);
133 check (0, Eyes::RIGHT, __LINE__);
134 push (s, 1, Eyes::LEFT);
135 check (1, Eyes::LEFT, __LINE__);
136 push (s, 1, Eyes::RIGHT);
137 check (1, Eyes::RIGHT, __LINE__);
138 push (s, 2, Eyes::LEFT);
139 push (s, 3, Eyes::LEFT);
140 push (s, 3, Eyes::RIGHT);
141 push (s, 4, Eyes::LEFT);
142 push (s, 4, Eyes::RIGHT);
144 check (2, Eyes::LEFT, __LINE__);
145 check (3, Eyes::LEFT, __LINE__);
146 check (3, Eyes::RIGHT, __LINE__);
147 check (4, Eyes::LEFT, __LINE__);
148 check (4, Eyes::RIGHT, __LINE__);
152 BOOST_AUTO_TEST_CASE (shuffler_test5)
155 s.Video.connect (boost::bind (&receive, _1, _2));
157 /* One left should come out straight away */
158 push (s, 0, Eyes::LEFT);
159 check (0, Eyes::LEFT, __LINE__);
161 /* More lefts should be kept in the shuffler in the hope that some rights arrive */
162 for (int i = 0; i < s._max_size; ++i) {
163 push (s, i + 1, Eyes::LEFT);
165 BOOST_CHECK (pending_cv.empty ());
167 /* If enough lefts come the shuffler should conclude that there's no rights and start
168 giving out the lefts.
170 push (s, s._max_size + 1, Eyes::LEFT);
171 check (1, Eyes::LEFT, __LINE__);
174 /** One complete frame (L+R) missing.
175 Shuffler should carry on, skipping this frame, as the player will cope with it.
177 BOOST_AUTO_TEST_CASE (shuffler_test6)
180 s.Video.connect (boost::bind (&receive, _1, _2));
182 push (s, 0, Eyes::LEFT);
183 check (0, Eyes::LEFT, __LINE__);
184 push (s, 0, Eyes::RIGHT);
185 check (0, Eyes::RIGHT, __LINE__);
187 push (s, 2, Eyes::LEFT);
188 push (s, 2, Eyes::RIGHT);
189 check (2, Eyes::LEFT, __LINE__);
190 check (2, Eyes::RIGHT, __LINE__);
192 push (s, 3, Eyes::LEFT);
193 check (3, Eyes::LEFT, __LINE__);
194 push (s, 3, Eyes::RIGHT);
195 check (3, Eyes::RIGHT, __LINE__);