Fix assertion failure when content has more than one audio stream.
[dcpomatic.git] / src / lib / decoder.cc
index 70eb5b61a3f34b4fad30cc22f82683f448789751..6078141dcfab4d0f84fff1026154106ff389595d 100644 (file)
 #include "decoder.h"
 #include "video_decoder.h"
 #include "audio_decoder.h"
-#include "caption_decoder.h"
+#include "text_decoder.h"
 #include <boost/optional.hpp>
 #include <iostream>
 
 using std::cout;
 using boost::optional;
+using boost::shared_ptr;
 
 /** @return Earliest time of content that the next pass() will emit */
 ContentTime
@@ -42,8 +43,10 @@ Decoder::position () const
                pos = audio->position();
        }
 
-       if (caption && !caption->ignore() && (!pos || caption->position() < *pos)) {
-               pos = caption->position();
+       BOOST_FOREACH (shared_ptr<TextDecoder> i, text) {
+               if (!i->ignore() && (!pos || i->position() < *pos)) {
+                       pos = i->position();
+               }
        }
 
        return pos.get_value_or(ContentTime());
@@ -58,7 +61,17 @@ Decoder::seek (ContentTime, bool)
        if (audio) {
                audio->seek ();
        }
-       if (caption) {
-               caption->seek ();
+       BOOST_FOREACH (shared_ptr<TextDecoder> i, text) {
+               i->seek ();
        }
 }
+
+shared_ptr<TextDecoder>
+Decoder::only_text () const
+{
+       DCPOMATIC_ASSERT (text.size() < 2);
+       if (text.empty ()) {
+               return shared_ptr<TextDecoder> ();
+       }
+       return text.front ();
+}