diff options
| author | Carl Hetherington <cth@carlh.net> | 2014-05-02 10:42:06 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2014-05-02 10:42:06 +0100 |
| commit | 0ce7f98699ff7d72fc91e5c9781b431ca36d7af9 (patch) | |
| tree | 773f8bc5caccbd1d3bf4c78634758fbc4953b98e /src/lib/subtitle_decoder.cc | |
| parent | c7c2502bc261bf3d81e96ddde9e189b9527dbc9e (diff) | |
Add missing seek stuff to SubtitleDecoder.
Diffstat (limited to 'src/lib/subtitle_decoder.cc')
| -rw-r--r-- | src/lib/subtitle_decoder.cc | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/src/lib/subtitle_decoder.cc b/src/lib/subtitle_decoder.cc index 3daa6e431..92355ad62 100644 --- a/src/lib/subtitle_decoder.cc +++ b/src/lib/subtitle_decoder.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013 Carl Hetherington <cth@carlh.net> + Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -21,6 +21,7 @@ #include "subtitle_decoder.h" using std::list; +using std::cout; using boost::shared_ptr; using boost::optional; @@ -46,9 +47,24 @@ SubtitleDecoder::text_subtitle (list<dcp::SubtitleString> s) template <class T> list<shared_ptr<T> > -get (list<shared_ptr<T> > const & subs, ContentTime from, ContentTime to) +SubtitleDecoder::get (list<shared_ptr<T> > const & subs, ContentTime from, ContentTime to) { + if (subs.empty() || from < subs.front()->from() || to > (subs.back()->to() + ContentTime::from_seconds (10))) { + /* Either we have no decoded data, or what we do have is a long way from what we want: seek */ + seek (from, true); + } + + /* Now enough pass() calls will either: + * (a) give us what we want, or + * (b) hit the end of the decoder. + * + * XXX: with subs being sparse, this may need more care... + */ + while (!pass() && (subs.front()->from() > from || to < subs.back()->to())) {} + + /* Now look for what we wanted in the data we have collected */ /* XXX: inefficient */ + list<shared_ptr<T> > out; for (typename list<shared_ptr<T> >::const_iterator i = subs.begin(); i != subs.end(); ++i) { if ((*i)->from() <= to && (*i)->to() >= from) { @@ -70,3 +86,10 @@ SubtitleDecoder::get_image_subtitles (ContentTime from, ContentTime to) { return get<ContentImageSubtitle> (_decoded_image_subtitles, from, to); } + +void +SubtitleDecoder::seek (ContentTime, bool) +{ + _decoded_text_subtitles.clear (); + _decoded_image_subtitles.clear (); +} |
