Mostly-merge master.
[dcpomatic.git] / src / lib / decoder.cc
index 7102f2aa4cdad341e69c5db352a52d4b9b587d54..0901f73b020027cc733ab325c2085f494db65d45 100644 (file)
  *  @brief Parent class for decoders of content.
  */
 
-#include "film.h"
 #include "decoder.h"
 #include "decoded.h"
 
 #include "i18n.h"
 
+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)
 {
 
 }
 
+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 (_pending.empty() && !pass ()) {}
+       while (!_done && _pending.empty ()) {
+               _done = pass ();
+       }
 
-       if (_pending.empty ()) {
+       if (_done && _pending.empty ()) {
                return shared_ptr<Decoded> ();
        }
 
+       _pending.sort (DecodedSorter ());
        return _pending.front ();
 }
 
@@ -62,4 +72,5 @@ void
 Decoder::seek (ContentTime, bool)
 {
        _pending.clear ();
+       _done = false;
 }