X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fdcp_subtitle_decoder.cc;h=46256e93ef43f6d57607693f723658414b0d414e;hb=00ae2c28501bb757a6a45ba47ad4ecbe32412933;hp=81dfc6598ff345034636ac629905477a4297d39a;hpb=3828baf56467224f5d44049bf1e7a7ed11f43a05;p=dcpomatic.git diff --git a/src/lib/dcp_subtitle_decoder.cc b/src/lib/dcp_subtitle_decoder.cc index 81dfc6598..46256e93e 100644 --- a/src/lib/dcp_subtitle_decoder.cc +++ b/src/lib/dcp_subtitle_decoder.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2014-2016 Carl Hetherington + Copyright (C) 2014-2018 Carl Hetherington This file is part of DCP-o-matic. @@ -26,38 +26,36 @@ using std::list; using std::cout; using boost::shared_ptr; +using boost::dynamic_pointer_cast; using boost::bind; -DCPSubtitleDecoder::DCPSubtitleDecoder (shared_ptr content) +DCPSubtitleDecoder::DCPSubtitleDecoder (shared_ptr content, shared_ptr log) { - subtitle.reset ( - new SubtitleDecoder ( - this, - content->subtitle, - bind (&DCPSubtitleDecoder::image_subtitles_during, this, _1, _2), - bind (&DCPSubtitleDecoder::text_subtitles_during, this, _1, _2) - ) - ); - shared_ptr 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 accurate) { - subtitle->seek (time, accurate); + Decoder::seek (time, accurate); _next = _subtitles.begin (); - list::const_iterator i = _subtitles.begin (); - while (i != _subtitles.end() && ContentTime::from_seconds (_next->in().as_seconds()) < time) { + list >::const_iterator i = _subtitles.begin (); + while (i != _subtitles.end() && ContentTime::from_seconds ((*_next)->in().as_seconds()) < time) { ++i; } } bool -DCPSubtitleDecoder::pass (PassReason, bool) +DCPSubtitleDecoder::pass () { if (_next == _subtitles.end ()) { return true; @@ -74,43 +72,24 @@ DCPSubtitleDecoder::pass (PassReason, bool) ContentTimePeriod const p = content_time_period (*_next); while (_next != _subtitles.end () && content_time_period (*_next) == p) { - s.push_back (*_next); - ++_next; - } - - subtitle->give_text (p, s); - - return false; -} - -list -DCPSubtitleDecoder::image_subtitles_during (ContentTimePeriod, bool) const -{ - return list (); -} - -list -DCPSubtitleDecoder::text_subtitles_during (ContentTimePeriod p, bool starting) const -{ - /* XXX: inefficient */ - - list d; - - for (list::const_iterator i = _subtitles.begin(); i != _subtitles.end(); ++i) { - ContentTimePeriod period = content_time_period (*i); - if ((starting && p.contains (period.from)) || (!starting && p.overlaps (period))) { - d.push_back (period); + shared_ptr ns = dynamic_pointer_cast(*_next); + if (ns) { + s.push_back (*ns); + ++_next; } + + /* XXX: image subtitles */ } - return d; + subtitle->emit_text (p, s); + return false; } ContentTimePeriod -DCPSubtitleDecoder::content_time_period (dcp::SubtitleString s) const +DCPSubtitleDecoder::content_time_period (shared_ptr s) const { return ContentTimePeriod ( - ContentTime::from_seconds (s.in().as_seconds ()), - ContentTime::from_seconds (s.out().as_seconds ()) + ContentTime::from_seconds (s->in().as_seconds ()), + ContentTime::from_seconds (s->out().as_seconds ()) ); }