Mostly-merge master.
[dcpomatic.git] / src / lib / decoder.cc
index c4044691943334d2cefb575b50f5a23e6716fb5c..0901f73b020027cc733ab325c2085f494db65d45 100644 (file)
  *  @brief Parent class for decoders of content.
  */
 
-#include <iostream>
-#include "film.h"
-#include "exceptions.h"
-#include "util.h"
 #include "decoder.h"
+#include "decoded.h"
 
 #include "i18n.h"
 
-using std::string;
+using std::cout;
 using boost::shared_ptr;
 
-/** @param f Film.
- *  @param o Decode options.
+/** @param o Decode options.
  */
-Decoder::Decoder (shared_ptr<const Film> f)
-       : _film (f)
+Decoder::Decoder ()
+       : _done (false)
 {
-       _film_connection = f->Changed.connect (bind (&Decoder::film_changed, this, _1));
+
 }
 
-/** Seek to a position as a source timestamp in seconds.
- *  @return true on error.
- */
-bool
-Decoder::seek (double)
+struct DecodedSorter
+{
+       bool operator() (shared_ptr<Decoded> a, shared_ptr<Decoded> b)
+       {
+               return a->dcp_time < b->dcp_time;
+       }
+};
+
+shared_ptr<Decoded>
+Decoder::peek ()
+{
+       while (!_done && _pending.empty ()) {
+               _done = pass ();
+       }
+
+       if (_done && _pending.empty ()) {
+               return shared_ptr<Decoded> ();
+       }
+
+       _pending.sort (DecodedSorter ());
+       return _pending.front ();
+}
+
+void
+Decoder::consume ()
 {
-       throw DecodeError (N_("decoder does not support seek"));
+       if (!_pending.empty ()) {
+               _pending.pop_front ();
+       }
 }
 
-/** Seek so that the next frame we will produce is the same as the last one.
- *  @return true on error.
- */
-bool
-Decoder::seek_to_last ()
+void
+Decoder::seek (ContentTime, bool)
 {
-       throw DecodeError (N_("decoder does not support seek"));
+       _pending.clear ();
+       _done = false;
 }