summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2014-05-02 10:42:06 +0100
committerCarl Hetherington <cth@carlh.net>2014-05-02 10:42:06 +0100
commit0ce7f98699ff7d72fc91e5c9781b431ca36d7af9 (patch)
tree773f8bc5caccbd1d3bf4c78634758fbc4953b98e /src
parentc7c2502bc261bf3d81e96ddde9e189b9527dbc9e (diff)
Add missing seek stuff to SubtitleDecoder.
Diffstat (limited to 'src')
-rw-r--r--src/lib/subrip_decoder.cc4
-rw-r--r--src/lib/subtitle_decoder.cc27
-rw-r--r--src/lib/subtitle_decoder.h6
3 files changed, 34 insertions, 3 deletions
diff --git a/src/lib/subrip_decoder.cc b/src/lib/subrip_decoder.cc
index 013c6fab7..cdc8ccbfe 100644
--- a/src/lib/subrip_decoder.cc
+++ b/src/lib/subrip_decoder.cc
@@ -31,8 +31,10 @@ SubRipDecoder::SubRipDecoder (shared_ptr<const SubRipContent> content)
}
void
-SubRipDecoder::seek (ContentTime time, bool)
+SubRipDecoder::seek (ContentTime time, bool accurate)
{
+ SubtitleDecoder::seek (time, accurate);
+
_next = 0;
list<SubRipSubtitlePiece>::const_iterator i = _subtitles[_next].pieces.begin();
while (i != _subtitles[_next].pieces.end() && _subtitles[_next].from < time) {
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 ();
+}
diff --git a/src/lib/subtitle_decoder.h b/src/lib/subtitle_decoder.h
index efa90fd92..a26348ee6 100644
--- a/src/lib/subtitle_decoder.h
+++ b/src/lib/subtitle_decoder.h
@@ -39,11 +39,17 @@ public:
std::list<boost::shared_ptr<ContentTextSubtitle> > get_text_subtitles (ContentTime from, ContentTime to);
protected:
+ void seek (ContentTime, bool);
+
void image_subtitle (ContentTime from, ContentTime to, boost::shared_ptr<Image>, dcpomatic::Rect<double>);
void text_subtitle (std::list<dcp::SubtitleString>);
std::list<boost::shared_ptr<ContentImageSubtitle> > _decoded_image_subtitles;
std::list<boost::shared_ptr<ContentTextSubtitle> > _decoded_text_subtitles;
+
+private:
+ template <class T>
+ std::list<boost::shared_ptr<T> > get (std::list<boost::shared_ptr<T> > const & subs, ContentTime from, ContentTime to);
};
#endif