Merge branch 'master' of ssh://git.carlh.net/home/carl/git/dcpomatic
[dcpomatic.git] / src / lib / decoder.cc
index cba674d0415ed9df573c5fb955cd3ea72104392b..0d4f4babfa9db0831650529ae4ead927260dc7f3 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
 */
 
 #include "decoder.h"
-
-void
-Decoder::maybe_seek (ContentTime time, bool accurate)
+#include "video_decoder.h"
+#include "audio_decoder.h"
+#include "subtitle_decoder.h"
+#include <boost/optional.hpp>
+#include <iostream>
+
+using std::cout;
+using boost::optional;
+
+/** @return Earliest time of content that the next pass() will emit */
+ContentTime
+Decoder::position () const
 {
-       if (!_position) {
-               /* A seek has just happened */
-               return;
+       optional<ContentTime> pos;
+
+       if (video && !video->ignore() && (!pos || video->position() < *pos)) {
+               pos = video->position();
        }
 
-       if (time >= *_position && time < (*_position + ContentTime::from_seconds(1))) {
-               /* No need to seek: caller should just pass() */
-               return;
+       if (audio && !audio->ignore() && (!pos || audio->position() < *pos)) {
+               pos = audio->position();
        }
 
-       _position.reset ();
-       seek (time, accurate);
+       if (subtitle && !subtitle->ignore() && (!pos || subtitle->position() < *pos)) {
+               pos = subtitle->position();
+       }
+
+       return pos.get_value_or(ContentTime());
+}
+
+void
+Decoder::seek (ContentTime, bool)
+{
+       if (audio) {
+               audio->seek ();
+       }
+       if (subtitle) {
+               subtitle->seek ();
+       }
 }