Be more careful about allowing possibly-trouble-causing characters in DCP filenames.
[dcpomatic.git] / src / lib / subtitle_decoder.cc
index 4be5c96b36c7b28b8009e1bb850d9dc271ffd5d3..3e6ee92f1f0e6b33c89e919db8785dff2d62dc64 100644 (file)
@@ -21,6 +21,8 @@
 #include "subtitle_decoder.h"
 #include "subtitle_content.h"
 #include "util.h"
+#include "log.h"
+#include "compose.hpp"
 #include <sub/subtitle.h>
 #include <boost/shared_ptr.hpp>
 #include <boost/foreach.hpp>
@@ -38,10 +40,11 @@ using boost::function;
 SubtitleDecoder::SubtitleDecoder (
        Decoder* parent,
        shared_ptr<const SubtitleContent> c,
+       shared_ptr<Log> log,
        function<list<ContentTimePeriod> (ContentTimePeriod, bool)> image_during,
        function<list<ContentTimePeriod> (ContentTimePeriod, bool)> text_during
        )
-       : _parent (parent)
+       : DecoderPart (parent, log)
        , _content (c)
        , _image_during (image_during)
        , _text_during (text_during)
@@ -60,6 +63,7 @@ void
 SubtitleDecoder::give_image (ContentTimePeriod period, shared_ptr<Image> image, dcpomatic::Rect<double> rect)
 {
        _decoded_image.push_back (ContentImageSubtitle (period, image, rect));
+       _position = period.from;
 }
 
 void
@@ -76,6 +80,7 @@ SubtitleDecoder::give_text (ContentTimePeriod period, list<dcp::SubtitleString>
        }
 
        _decoded_text.push_back (ContentTextSubtitle (period, s));
+       _position = period.to;
 }
 
 /** Get the subtitles that correspond to a given list of periods.
@@ -99,12 +104,19 @@ SubtitleDecoder::get (list<T> const & subs, list<ContentTimePeriod> const & sp,
                }
                if (j == subs.end ()) {
                        missing = i.from;
+                       break;
                }
        }
 
        /* Suggest to our parent decoder that it might want to seek if we haven't got what we're being asked for */
        if (missing) {
-               _parent->maybe_seek (*missing, true);
+               _log->log (
+                       String::compose (
+                               "SD suggests seek to %1 from %2",
+                               to_string (*missing),
+                               position() ? to_string(*position()) : "nowhere"),
+                       LogEntry::TYPE_DEBUG_DECODE);
+               maybe_seek (*missing, true);
        }
 
        /* Now enough pass() calls will either:
@@ -160,9 +172,11 @@ SubtitleDecoder::get_image (ContentTimePeriod period, bool starting, bool accura
 }
 
 void
-SubtitleDecoder::seek (ContentTime, bool)
+SubtitleDecoder::seek (ContentTime t, bool)
 {
+       _log->log (String::compose ("SD seek to %1", to_string(t)), LogEntry::TYPE_DEBUG_DECODE);
        reset ();
+       _position.reset ();
 }
 
 void