X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Ftext_subtitle_decoder.cc;h=6188d524f97b101344138f83bacfaaa14dacc13b;hb=00ae2c28501bb757a6a45ba47ad4ecbe32412933;hp=ec60bd36b52327a838cf73460c01f0ad74c04b16;hpb=878e19aabf2278828a3c9b518e0804b2cef0c01e;p=dcpomatic.git diff --git a/src/lib/text_subtitle_decoder.cc b/src/lib/text_subtitle_decoder.cc index ec60bd36b..6188d524f 100644 --- a/src/lib/text_subtitle_decoder.cc +++ b/src/lib/text_subtitle_decoder.cc @@ -38,21 +38,25 @@ TextSubtitleDecoder::TextSubtitleDecoder (shared_ptr : 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 -TextSubtitleDecoder::image_subtitles_during (ContentTimePeriod, bool) const -{ - return list (); -} - -list -TextSubtitleDecoder::text_subtitles_during (ContentTimePeriod p, bool starting) const -{ - /* XXX: inefficient */ - - list 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::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 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 (); -}