summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2018-01-16 21:01:30 +0000
committerCarl Hetherington <cth@carlh.net>2018-01-16 21:01:30 +0000
commit1aad2c33896ce6222f3c929c7af7fe4ff5fda0f2 (patch)
treeb766282ac0b735b6e4450b91939607affdaa351d /test
parent598483f71fabde104250296ab4bfe4ec70d82d66 (diff)
In general the player assumes that it won't receive out of order video.
This clearly can happen with separate L/R sources. A pass in L might emit two frames which means the arrivals can't possibly be in order. This commit fixes this by introducing a Shuffler which all alternate-3D sources send their video to. The Shuffler re-orders things before they arrive at the player. It also fixes the code which inserts video frames before one that arrives after a gap. This didn't cope with 3D right before. The audio code solves a similar (perhaps the same?) problem with the AudioMerger; perhaps we should have a similar thing for video and make the player emit complete 3D frames. Should help with #976.
Diffstat (limited to 'test')
-rw-r--r--test/shuffler_test.cc122
-rw-r--r--test/wscript1
2 files changed, 123 insertions, 0 deletions
diff --git a/test/shuffler_test.cc b/test/shuffler_test.cc
new file mode 100644
index 000000000..879f2e079
--- /dev/null
+++ b/test/shuffler_test.cc
@@ -0,0 +1,122 @@
+#include "lib/shuffler.h"
+#include "lib/piece.h"
+#include "lib/content_video.h"
+#include <boost/test/unit_test.hpp>
+
+using std::list;
+using boost::shared_ptr;
+using boost::weak_ptr;
+using boost::optional;
+
+static void
+push (Shuffler& s, int frame, Eyes eyes)
+{
+ shared_ptr<Piece> piece (new Piece (shared_ptr<Content>(), shared_ptr<Decoder>(), FrameRateChange(24, 24)));
+ ContentVideo cv;
+ cv.frame = frame;
+ cv.eyes = eyes;
+ s.video (piece, cv);
+}
+
+list<ContentVideo> pending_cv;
+
+static void
+receive (weak_ptr<Piece>, ContentVideo cv)
+{
+ pending_cv.push_back (cv);
+}
+
+static void
+check (int frame, Eyes eyes, int line)
+{
+ 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().eyes == eyes, "Check at " << line << " failed.");
+ pending_cv.pop_front();
+}
+
+/** A perfect sequence */
+BOOST_AUTO_TEST_CASE (shuffler_test1)
+{
+ Shuffler s;
+ 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__);
+ }
+}
+
+/** Everything present but some simple shuffling needed */
+BOOST_AUTO_TEST_CASE (shuffler_test2)
+{
+ Shuffler s;
+ 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__);
+ }
+}
+
+/** One missing left eye image */
+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);
+ 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__);
+}
+
+/** One missing right eye image */
+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);
+ 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__);
+}
diff --git a/test/wscript b/test/wscript
index f0533cfa1..fef16dbed 100644
--- a/test/wscript
+++ b/test/wscript
@@ -93,6 +93,7 @@ def build(bld):
render_subtitles_test.cc
scaling_test.cc
silence_padding_test.cc
+ shuffler_test.cc
skip_frame_test.cc
srt_subtitle_test.cc
ssa_subtitle_test.cc