CCAP doc tweaks.
[dcpomatic.git] / src / lib / text_subtitle_decoder.cc
index ec60bd36b52327a838cf73460c01f0ad74c04b16..6188d524f97b101344138f83bacfaaa14dacc13b 100644 (file)
@@ -38,21 +38,25 @@ TextSubtitleDecoder::TextSubtitleDecoder (shared_ptr<const TextSubtitleContent>
        : TextSubtitle (content)
        , _next (0)
 {
-       subtitle.reset (
-               new SubtitleDecoder (
-                       this,
-                       content->subtitle,
-                       log,
-                       bind (&TextSubtitleDecoder::image_subtitles_during, this, _1, _2),
-                       bind (&TextSubtitleDecoder::text_subtitles_during, this, _1, _2)
-                       )
-               );
+       ContentTime first;
+       if (!_subtitles.empty()) {
+               first = content_time_period(_subtitles[0]).from;
+       }
+       subtitle.reset (new SubtitleDecoder (this, content->subtitle, log, first));
 }
 
 void
 TextSubtitleDecoder::seek (ContentTime time, bool accurate)
 {
-       subtitle->seek (time, accurate);
+       /* It's worth back-tracking a little here as decoding is cheap and it's nice if we don't miss
+          too many subtitles when seeking.
+       */
+       time -= ContentTime::from_seconds (5);
+       if (time < ContentTime()) {
+               time = ContentTime();
+       }
+
+       Decoder::seek (time, accurate);
 
        _next = 0;
        while (_next < _subtitles.size() && ContentTime::from_seconds (_subtitles[_next].from.all_as_seconds ()) < time) {
@@ -61,53 +65,19 @@ TextSubtitleDecoder::seek (ContentTime time, bool accurate)
 }
 
 bool
-TextSubtitleDecoder::pass (PassReason, bool)
+TextSubtitleDecoder::pass ()
 {
        if (_next >= _subtitles.size ()) {
                return true;
        }
 
        ContentTimePeriod const p = content_time_period (_subtitles[_next]);
-       subtitle->give_text (p, _subtitles[_next]);
-       subtitle->set_position (p.from);
+       subtitle->emit_text (p, _subtitles[_next]);
 
        ++_next;
        return false;
 }
 
-list<ContentTimePeriod>
-TextSubtitleDecoder::image_subtitles_during (ContentTimePeriod, bool) const
-{
-       return list<ContentTimePeriod> ();
-}
-
-list<ContentTimePeriod>
-TextSubtitleDecoder::text_subtitles_during (ContentTimePeriod p, bool starting) const
-{
-       /* XXX: inefficient */
-
-       list<ContentTimePeriod> d;
-
-       /* Only take `during' (not starting) subs if they overlap more than half the requested period;
-          here's the threshold for being significant.
-       */
-       ContentTime const significant (p.duration().get() / 2);
-
-       for (vector<sub::Subtitle>::const_iterator i = _subtitles.begin(); i != _subtitles.end(); ++i) {
-               ContentTimePeriod t = content_time_period (*i);
-               if (starting && p.contains(t.from)) {
-                       d.push_back (t);
-               } else if (!starting) {
-                       optional<ContentTimePeriod> const o = p.overlap (t);
-                       if (o && o->duration() > significant) {
-                               d.push_back (t);
-                       }
-               }
-       }
-
-       return d;
-}
-
 ContentTimePeriod
 TextSubtitleDecoder::content_time_period (sub::Subtitle s) const
 {
@@ -116,9 +86,3 @@ TextSubtitleDecoder::content_time_period (sub::Subtitle s) const
                ContentTime::from_seconds (s.to.all_as_seconds())
                );
 }
-
-void
-TextSubtitleDecoder::reset ()
-{
-       subtitle->reset ();
-}