2 Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <dcp/subtitle_content.h>
21 #include "dcp_subtitle_decoder.h"
22 #include "dcp_subtitle_content.h"
25 using boost::shared_ptr;
27 DCPSubtitleDecoder::DCPSubtitleDecoder (shared_ptr<const DCPSubtitleContent> content)
28 : SubtitleDecoder (content)
30 dcp::SubtitleContent c (content->path (0), false);
31 _subtitles = c.subtitles ();
32 _next = _subtitles.begin ();
36 DCPSubtitleDecoder::seek (ContentTime time, bool accurate)
38 SubtitleDecoder::seek (time, accurate);
40 _next = _subtitles.begin ();
41 list<dcp::SubtitleString>::const_iterator i = _subtitles.begin ();
42 while (i != _subtitles.end() && ContentTime::from_seconds (_next->in().to_seconds()) < time) {
48 DCPSubtitleDecoder::pass ()
50 if (_next == _subtitles.end ()) {
54 list<dcp::SubtitleString> s;
62 list<ContentTimePeriod>
63 DCPSubtitleDecoder::subtitles_during (ContentTimePeriod p, bool starting) const
65 /* XXX: inefficient */
67 list<ContentTimePeriod> d;
69 for (list<dcp::SubtitleString>::const_iterator i = _subtitles.begin(); i != _subtitles.end(); ++i) {
70 ContentTimePeriod period (
71 ContentTime::from_seconds (i->in().to_seconds ()),
72 ContentTime::from_seconds (i->out().to_seconds ())
75 if ((starting && p.contains (period.from)) || (!starting && p.overlaps (period))) {