X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=blobdiff_plain;f=src%2Flib%2Fsubtitle_decoder.cc;h=c437ec9457b839c8095c444cc1bca828639d4a77;hp=3e6ee92f1f0e6b33c89e919db8785dff2d62dc64;hb=de2af791bdfdcd653752cba970e59efc7bf810c7;hpb=06152300e69e8faca44ff8d7f12a6fd354848b9a diff --git a/src/lib/subtitle_decoder.cc b/src/lib/subtitle_decoder.cc index 3e6ee92f1..c437ec945 100644 --- a/src/lib/subtitle_decoder.cc +++ b/src/lib/subtitle_decoder.cc @@ -40,14 +40,10 @@ using boost::function; SubtitleDecoder::SubtitleDecoder ( Decoder* parent, shared_ptr c, - shared_ptr log, - function (ContentTimePeriod, bool)> image_during, - function (ContentTimePeriod, bool)> text_during + shared_ptr log ) : DecoderPart (parent, log) , _content (c) - , _image_during (image_during) - , _text_during (text_during) { } @@ -60,14 +56,13 @@ SubtitleDecoder::SubtitleDecoder ( * of the video frame) */ void -SubtitleDecoder::give_image (ContentTimePeriod period, shared_ptr image, dcpomatic::Rect rect) +SubtitleDecoder::emit_image (ContentTimePeriod period, shared_ptr image, dcpomatic::Rect rect) { - _decoded_image.push_back (ContentImageSubtitle (period, image, rect)); - _position = period.from; + ImageData (ContentImageSubtitle (period, image, rect)); } void -SubtitleDecoder::give_text (ContentTimePeriod period, list s) +SubtitleDecoder::emit_text (ContentTimePeriod period, list s) { /* We must escape < and > in strings, otherwise they might confuse our subtitle renderer (which uses some HTML-esque markup to do bold/italic etc.) @@ -79,115 +74,11 @@ SubtitleDecoder::give_text (ContentTimePeriod period, list i.set_text (t); } - _decoded_text.push_back (ContentTextSubtitle (period, s)); - _position = period.to; -} - -/** Get the subtitles that correspond to a given list of periods. - * @param subs Subtitles. - * @param sp Periods for which to extract subtitles from subs. - */ -template -list -SubtitleDecoder::get (list const & subs, list const & sp, ContentTimePeriod period, bool accurate) -{ - if (sp.empty ()) { - return list (); - } - - /* Find the time of the first subtitle we don't have in subs */ - optional missing; - BOOST_FOREACH (ContentTimePeriod i, sp) { - typename list::const_iterator j = subs.begin(); - while (j != subs.end() && j->period() != i) { - ++j; - } - if (j == subs.end ()) { - missing = i.from; - break; - } - } - - /* Suggest to our parent decoder that it might want to seek if we haven't got what we're being asked for */ - if (missing) { - _log->log ( - String::compose ( - "SD suggests seek to %1 from %2", - to_string (*missing), - position() ? to_string(*position()) : "nowhere"), - LogEntry::TYPE_DEBUG_DECODE); - maybe_seek (*missing, true); - } - - /* Now enough pass() calls will either: - * (a) give us what we want, or - * (b) hit the end of the decoder. - */ - while (!_parent->pass(Decoder::PASS_REASON_SUBTITLE, accurate) && (subs.empty() || (subs.back().period().to < sp.back().to))) {} - - /* Now look for what we wanted in the data we have collected */ - /* XXX: inefficient */ - - list out; - BOOST_FOREACH (ContentTimePeriod i, sp) { - typename list::const_iterator j = subs.begin(); - while (j != subs.end() && j->period() != i) { - ++j; - } - if (j != subs.end()) { - out.push_back (*j); - } - } - - /* Discard anything in _decoded_image_subtitles that is outside 5 seconds either side of period */ - - list::iterator i = _decoded_image.begin(); - while (i != _decoded_image.end()) { - list::iterator tmp = i; - ++tmp; - - if ( - i->period().to < (period.from - ContentTime::from_seconds (5)) || - i->period().from > (period.to + ContentTime::from_seconds (5)) - ) { - _decoded_image.erase (i); - } - - i = tmp; - } - - return out; -} - -list -SubtitleDecoder::get_text (ContentTimePeriod period, bool starting, bool accurate) -{ - return get (_decoded_text, _text_during (period, starting), period, accurate); -} - -list -SubtitleDecoder::get_image (ContentTimePeriod period, bool starting, bool accurate) -{ - return get (_decoded_image, _image_during (period, starting), period, accurate); -} - -void -SubtitleDecoder::seek (ContentTime t, bool) -{ - _log->log (String::compose ("SD seek to %1", to_string(t)), LogEntry::TYPE_DEBUG_DECODE); - reset (); - _position.reset (); -} - -void -SubtitleDecoder::reset () -{ - _decoded_text.clear (); - _decoded_image.clear (); + TextData (ContentTextSubtitle (period, s)); } void -SubtitleDecoder::give_text (ContentTimePeriod period, sub::Subtitle const & subtitle) +SubtitleDecoder::emit_text (ContentTimePeriod period, sub::Subtitle const & subtitle) { /* See if our next subtitle needs to be placed on screen by us */ bool needs_placement = false; @@ -295,5 +186,5 @@ SubtitleDecoder::give_text (ContentTimePeriod period, sub::Subtitle const & subt } } - give_text (period, out); + emit_text (period, out); }