summaryrefslogtreecommitdiff
path: root/src/lib/shuffler.cc
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 /src/lib/shuffler.cc
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 'src/lib/shuffler.cc')
-rw-r--r--src/lib/shuffler.cc93
1 files changed, 93 insertions, 0 deletions
diff --git a/src/lib/shuffler.cc b/src/lib/shuffler.cc
new file mode 100644
index 000000000..997d91fb1
--- /dev/null
+++ b/src/lib/shuffler.cc
@@ -0,0 +1,93 @@
+/*
+ Copyright (C) 2018 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 "shuffler.h"
+#include "content_video.h"
+#include "dcpomatic_assert.h"
+#include <boost/foreach.hpp>
+#include <iostream>
+
+using std::make_pair;
+using boost::weak_ptr;
+using boost::shared_ptr;
+using boost::optional;
+
+struct Comparator
+{
+ bool operator()(Shuffler::Store const & a, Shuffler::Store const & b) {
+ if (a.second.frame != b.second.frame) {
+ return a.second.frame < b.second.frame;
+ }
+ return a.second.eyes < b.second.eyes;
+ }
+};
+
+void
+Shuffler::video (weak_ptr<Piece> weak_piece, ContentVideo video)
+{
+ std::cout << "shuffler gets " << video.frame << " " << video.eyes << "\n";
+
+ /* Something has gong wrong if our store gets too big */
+ DCPOMATIC_ASSERT (_store.size() != 8);
+ /* We should only ever see 3D_LEFT / 3D_RIGHT */
+ DCPOMATIC_ASSERT (video.eyes == EYES_LEFT || video.eyes == EYES_RIGHT);
+
+ shared_ptr<Piece> piece = weak_piece.lock ();
+ DCPOMATIC_ASSERT (piece);
+
+ if (!_last) {
+ /* We haven't seen anything since the last clear() so assume everything is OK */
+ Video (weak_piece, video);
+ _last = video;
+ return;
+ }
+
+ _store.push_back (make_pair (weak_piece, video));
+ _store.sort (Comparator());
+
+ while (
+ !_store.empty() &&
+ (
+ (_store.front().second.frame == _last->frame && _store.front().second.eyes == EYES_RIGHT && _last->eyes == EYES_LEFT) ||
+ (_store.front().second.frame == (_last->frame + 1) && _store.front().second.eyes == EYES_LEFT && _last->eyes == EYES_RIGHT) ||
+ _store.size() > 8
+ )
+ ) {
+
+ std::cout << "shuffler emits " << _store.front().second.frame << " " << _store.front().second.eyes << "\n";
+ Video (_store.front().first, _store.front().second);
+ _last = _store.front().second;
+ _store.pop_front ();
+ }
+}
+
+void
+Shuffler::clear ()
+{
+ _last = optional<ContentVideo>();
+}
+
+void
+Shuffler::flush ()
+{
+ BOOST_FOREACH (Store i, _store) {
+ Video (i.first, i.second);
+ }
+}