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;
36 using namespace dcpomatic;
40 push(Shuffler& s, int frame, Eyes eyes)
42 auto piece = make_shared<Piece>(shared_ptr<Content>(), shared_ptr<Decoder>(), FrameRateChange(24, 24));
44 cv.time = ContentTime::from_frames(frame, 24);
49 list<ContentVideo> pending_cv;
52 receive (weak_ptr<Piece>, ContentVideo cv)
54 pending_cv.push_back (cv);
58 check (int frame, Eyes eyes, int line)
60 auto const time = ContentTime::from_frames(frame, 24);
61 BOOST_REQUIRE_MESSAGE (!pending_cv.empty(), "Check at " << line << " failed.");
62 BOOST_CHECK_MESSAGE (pending_cv.front().time == time, "Check at " << line << " failed.");
63 BOOST_CHECK_MESSAGE (pending_cv.front().eyes == eyes, "Check at " << line << " failed.");
64 pending_cv.pop_front();
67 /** A perfect sequence */
68 BOOST_AUTO_TEST_CASE (shuffler_test1)
71 s.Video.connect (boost::bind (&receive, _1, _2));
73 for (int i = 0; i < 10; ++i) {
74 push (s, i, Eyes::LEFT);
75 push (s, i, Eyes::RIGHT);
76 check (i, Eyes::LEFT, __LINE__);
77 check (i, Eyes::RIGHT, __LINE__);
81 /** Everything present but some simple shuffling needed */
82 BOOST_AUTO_TEST_CASE (shuffler_test2)
85 s.Video.connect (boost::bind (&receive, _1, _2));
87 for (int i = 0; i < 10; i += 2) {
88 push (s, i, Eyes::LEFT);
89 push (s, i + 1, Eyes::LEFT);
90 push (s, i, Eyes::RIGHT);
91 push (s, i + 1, Eyes::RIGHT);
92 check (i, Eyes::LEFT, __LINE__);
93 check (i, Eyes::RIGHT, __LINE__);
94 check (i + 1, Eyes::LEFT, __LINE__);
95 check (i + 1, Eyes::RIGHT, __LINE__);
99 /** One missing left eye image */
100 BOOST_AUTO_TEST_CASE (shuffler_test3)
103 s.Video.connect (boost::bind (&receive, _1, _2));
105 push (s, 0, Eyes::LEFT);
106 check (0, Eyes::LEFT, __LINE__);
107 push (s, 0, Eyes::RIGHT);
108 check (0, Eyes::RIGHT, __LINE__);
109 push (s, 1, Eyes::LEFT);
110 check (1, Eyes::LEFT, __LINE__);
111 push (s, 1, Eyes::RIGHT);
112 check (1, Eyes::RIGHT, __LINE__);
113 push (s, 2, Eyes::RIGHT);
114 push (s, 3, Eyes::LEFT);
115 push (s, 3, Eyes::RIGHT);
116 push (s, 4, Eyes::LEFT);
117 push (s, 4, Eyes::RIGHT);
119 check (2, Eyes::RIGHT, __LINE__);
120 check (3, Eyes::LEFT, __LINE__);
121 check (3, Eyes::RIGHT, __LINE__);
122 check (4, Eyes::LEFT, __LINE__);
123 check (4, Eyes::RIGHT, __LINE__);
126 /** One missing right eye image */
127 BOOST_AUTO_TEST_CASE (shuffler_test4)
130 s.Video.connect (boost::bind (&receive, _1, _2));
132 push (s, 0, Eyes::LEFT);
133 check (0, Eyes::LEFT, __LINE__);
134 push (s, 0, Eyes::RIGHT);
135 check (0, Eyes::RIGHT, __LINE__);
136 push (s, 1, Eyes::LEFT);
137 check (1, Eyes::LEFT, __LINE__);
138 push (s, 1, Eyes::RIGHT);
139 check (1, Eyes::RIGHT, __LINE__);
140 push (s, 2, Eyes::LEFT);
141 push (s, 3, Eyes::LEFT);
142 push (s, 3, Eyes::RIGHT);
143 push (s, 4, Eyes::LEFT);
144 push (s, 4, Eyes::RIGHT);
146 check (2, Eyes::LEFT, __LINE__);
147 check (3, Eyes::LEFT, __LINE__);
148 check (3, Eyes::RIGHT, __LINE__);
149 check (4, Eyes::LEFT, __LINE__);
150 check (4, Eyes::RIGHT, __LINE__);
154 BOOST_AUTO_TEST_CASE (shuffler_test5)
157 s.Video.connect (boost::bind (&receive, _1, _2));
159 /* One left should come out straight away */
160 push (s, 0, Eyes::LEFT);
161 check (0, Eyes::LEFT, __LINE__);
163 /* More lefts should be kept in the shuffler in the hope that some rights arrive */
164 for (int i = 0; i < s._max_size; ++i) {
165 push (s, i + 1, Eyes::LEFT);
167 BOOST_CHECK (pending_cv.empty ());
169 /* If enough lefts come the shuffler should conclude that there's no rights and start
170 giving out the lefts.
172 push (s, s._max_size + 1, Eyes::LEFT);
173 check (1, Eyes::LEFT, __LINE__);
176 /** One complete frame (L+R) missing.
177 Shuffler should carry on, skipping this frame, as the player will cope with it.
179 BOOST_AUTO_TEST_CASE (shuffler_test6)
182 s.Video.connect (boost::bind (&receive, _1, _2));
184 push (s, 0, Eyes::LEFT);
185 check (0, Eyes::LEFT, __LINE__);
186 push (s, 0, Eyes::RIGHT);
187 check (0, Eyes::RIGHT, __LINE__);
189 push (s, 2, Eyes::LEFT);
190 push (s, 2, Eyes::RIGHT);
191 check (2, Eyes::LEFT, __LINE__);
192 check (2, Eyes::RIGHT, __LINE__);
194 push (s, 3, Eyes::LEFT);
195 check (3, Eyes::LEFT, __LINE__);
196 push (s, 3, Eyes::RIGHT);
197 check (3, Eyes::RIGHT, __LINE__);