2 Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
21 #include "dcp_subtitle_decoder.h"
22 #include "dcp_subtitle_content.h"
23 #include <dcp/interop_subtitle_asset.h>
28 using boost::shared_ptr;
31 DCPSubtitleDecoder::DCPSubtitleDecoder (shared_ptr<const DCPSubtitleContent> content, shared_ptr<Log> log)
38 bind (&DCPSubtitleDecoder::image_subtitles_during, this, _1, _2),
39 bind (&DCPSubtitleDecoder::text_subtitles_during, this, _1, _2)
43 shared_ptr<dcp::SubtitleAsset> c (load (content->path (0)));
44 _subtitles = c->subtitles ();
45 _next = _subtitles.begin ();
49 DCPSubtitleDecoder::seek (ContentTime time, bool accurate)
51 subtitle->seek (time, accurate);
53 _next = _subtitles.begin ();
54 list<dcp::SubtitleString>::const_iterator i = _subtitles.begin ();
55 while (i != _subtitles.end() && ContentTime::from_seconds (_next->in().as_seconds()) < time) {
61 DCPSubtitleDecoder::pass (PassReason, bool)
63 if (_next == _subtitles.end ()) {
67 /* Gather all subtitles with the same time period that are next
68 on the list. We must emit all subtitles for the same time
69 period with the same text_subtitle() call otherwise the
70 SubtitleDecoder will assume there is nothing else at the
71 time of emit the first.
74 list<dcp::SubtitleString> s;
75 ContentTimePeriod const p = content_time_period (*_next);
77 while (_next != _subtitles.end () && content_time_period (*_next) == p) {
82 subtitle->give_text (p, s);
87 list<ContentTimePeriod>
88 DCPSubtitleDecoder::image_subtitles_during (ContentTimePeriod, bool) const
90 return list<ContentTimePeriod> ();
93 list<ContentTimePeriod>
94 DCPSubtitleDecoder::text_subtitles_during (ContentTimePeriod p, bool starting) const
96 /* XXX: inefficient */
98 list<ContentTimePeriod> d;
100 for (list<dcp::SubtitleString>::const_iterator i = _subtitles.begin(); i != _subtitles.end(); ++i) {
101 ContentTimePeriod period = content_time_period (*i);
102 if ((starting && p.contains(period.from)) || (!starting && p.overlap(period))) {
103 d.push_back (period);
114 DCPSubtitleDecoder::content_time_period (dcp::SubtitleString s) const
116 return ContentTimePeriod (
117 ContentTime::from_seconds (s.in().as_seconds ()),
118 ContentTime::from_seconds (s.out().as_seconds ())