: 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) {
}
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->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
{
ContentTime::from_seconds (s.to.all_as_seconds())
);
}
-
-void
-TextSubtitleDecoder::reset ()
-{
- subtitle->reset ();
-}