Setup SubtitleDecoder::_position correctly (in some cases).
[dcpomatic.git] / src / lib / dcp_subtitle_decoder.cc
index 9db3254019675061cc0f8095abb9f89604b111f1..965f9db61dc20d9719b16a2a0a2d8ecdc027fa0d 100644 (file)
@@ -30,16 +30,22 @@ using boost::bind;
 
 DCPSubtitleDecoder::DCPSubtitleDecoder (shared_ptr<const DCPSubtitleContent> content, shared_ptr<Log> log)
 {
-       subtitle.reset (new SubtitleDecoder (this, content->subtitle, log));
-
        shared_ptr<dcp::SubtitleAsset> c (load (content->path (0)));
        _subtitles = c->subtitles ();
        _next = _subtitles.begin ();
+
+       ContentTime first;
+       if (_next != _subtitles.end()) {
+               first = content_time_period(*_next).from;
+       }
+       subtitle.reset (new SubtitleDecoder (this, content->subtitle, log, first));
 }
 
 void
-DCPSubtitleDecoder::seek (ContentTime time, bool)
+DCPSubtitleDecoder::seek (ContentTime time, bool accurate)
 {
+       Decoder::seek (time, accurate);
+
        _next = _subtitles.begin ();
        list<dcp::SubtitleString>::const_iterator i = _subtitles.begin ();
        while (i != _subtitles.end() && ContentTime::from_seconds (_next->in().as_seconds()) < time) {
@@ -47,11 +53,11 @@ DCPSubtitleDecoder::seek (ContentTime time, bool)
        }
 }
 
-void
+bool
 DCPSubtitleDecoder::pass ()
 {
        if (_next == _subtitles.end ()) {
-               return;
+               return true;
        }
 
        /* Gather all subtitles with the same time period that are next
@@ -70,7 +76,7 @@ DCPSubtitleDecoder::pass ()
        }
 
        subtitle->emit_text (p, s);
-       subtitle->set_position (p.from);
+       return false;
 }
 
 ContentTimePeriod