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_decoder.h"
21 #include "dcp_subtitle_content.h"
22 #include <dcp/interop_subtitle_asset.h>
27 using boost::shared_ptr;
29 DCPSubtitleDecoder::DCPSubtitleDecoder (shared_ptr<const DCPSubtitleContent> content)
30 : SubtitleDecoder (content)
32 shared_ptr<dcp::SubtitleAsset> c (load (content->path (0)));
33 _subtitles = c->subtitles ();
34 _next = _subtitles.begin ();
38 DCPSubtitleDecoder::seek (ContentTime time, bool accurate)
40 SubtitleDecoder::seek (time, accurate);
42 _next = _subtitles.begin ();
43 list<dcp::SubtitleString>::const_iterator i = _subtitles.begin ();
44 while (i != _subtitles.end() && ContentTime::from_seconds (_next->in().as_seconds()) < time) {
50 DCPSubtitleDecoder::pass ()
52 if (_next == _subtitles.end ()) {
56 /* Gather all subtitles with the same time period that are next
57 on the list. We must emit all subtitles for the same time
58 period with the same text_subtitle() call otherwise the
59 SubtitleDecoder will assume there is nothing else at the
60 time of emit the first.
63 list<dcp::SubtitleString> s;
64 ContentTimePeriod const p = content_time_period (*_next);
66 while (_next != _subtitles.end () && content_time_period (*_next) == p) {
76 list<ContentTimePeriod>
77 DCPSubtitleDecoder::image_subtitles_during (ContentTimePeriod, bool) const
79 return list<ContentTimePeriod> ();
82 list<ContentTimePeriod>
83 DCPSubtitleDecoder::text_subtitles_during (ContentTimePeriod p, bool starting) const
85 /* XXX: inefficient */
87 list<ContentTimePeriod> d;
89 for (list<dcp::SubtitleString>::const_iterator i = _subtitles.begin(); i != _subtitles.end(); ++i) {
90 ContentTimePeriod period = content_time_period (*i);
91 if ((starting && p.contains (period.from)) || (!starting && p.overlaps (period))) {
100 DCPSubtitleDecoder::content_time_period (dcp::SubtitleString s) const
102 return ContentTimePeriod (
103 ContentTime::from_seconds (s.in().as_seconds ()),
104 ContentTime::from_seconds (s.out().as_seconds ())