Hopefully improve subtitle decoder seeking etc.
[dcpomatic.git] / src / lib / subrip_decoder.cc
index cdc8ccbfe4613f9a745966121101be82fb640a1c..370118d3065debae3aee18dfae4bcf33cc00fa06 100644 (file)
 
 #include <dcp/subtitle_string.h>
 #include "subrip_decoder.h"
+#include "subrip_content.h"
 
 using std::list;
+using std::vector;
 using boost::shared_ptr;
 
 SubRipDecoder::SubRipDecoder (shared_ptr<const SubRipContent> content)
-       : SubRip (content)
+       : SubtitleDecoder (content)
+       , SubRip (content)
        , _next (0)
 {
 
@@ -37,7 +40,7 @@ SubRipDecoder::seek (ContentTime time, bool accurate)
        
        _next = 0;
        list<SubRipSubtitlePiece>::const_iterator i = _subtitles[_next].pieces.begin();
-       while (i != _subtitles[_next].pieces.end() && _subtitles[_next].from < time) {
+       while (i != _subtitles[_next].pieces.end() && _subtitles[_next].period.from < time) {
                ++i;
        }
        
@@ -58,8 +61,8 @@ SubRipDecoder::pass ()
                                i->italic,
                                dcp::Color (255, 255, 255),
                                72,
-                               dcp::Time (rint (_subtitles[_next].from.seconds() * 250)),
-                               dcp::Time (rint (_subtitles[_next].to.seconds() * 250)),
+                               dcp::Time (rint (_subtitles[_next].period.from.seconds() * 250)),
+                               dcp::Time (rint (_subtitles[_next].period.to.seconds() * 250)),
                                0.9,
                                dcp::BOTTOM,
                                i->text,
@@ -75,3 +78,19 @@ SubRipDecoder::pass ()
        _next++;
        return false;
 }
+
+list<ContentTimePeriod>
+SubRipDecoder::subtitles_during (ContentTimePeriod p) const
+{
+       /* XXX: inefficient */
+
+       list<ContentTimePeriod> d;
+
+       for (vector<SubRipSubtitle>::const_iterator i = _subtitles.begin(); i != _subtitles.end(); ++i) {
+               if (p.overlaps (i->period)) {
+                       d.push_back (i->period);
+               }
+       }
+
+       return d;
+}