2 Copyright (C) 2014-2018 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;
29 using boost::dynamic_pointer_cast;
32 DCPSubtitleDecoder::DCPSubtitleDecoder (shared_ptr<const Film> film, shared_ptr<const DCPSubtitleContent> content)
35 shared_ptr<dcp::SubtitleAsset> c (load (content->path (0)));
36 _subtitles = c->subtitles ();
37 _next = _subtitles.begin ();
40 if (_next != _subtitles.end()) {
41 first = content_time_period(*_next).from;
43 text.push_back (shared_ptr<TextDecoder> (new TextDecoder (this, content->only_text(), first)));
47 DCPSubtitleDecoder::seek (ContentTime time, bool accurate)
49 Decoder::seek (time, accurate);
51 _next = _subtitles.begin ();
52 list<shared_ptr<dcp::Subtitle> >::const_iterator i = _subtitles.begin ();
53 while (i != _subtitles.end() && ContentTime::from_seconds ((*_next)->in().as_seconds()) < time) {
59 DCPSubtitleDecoder::pass ()
61 if (_next == _subtitles.end ()) {
65 /* Gather all subtitles with the same time period that are next
66 on the list. We must emit all subtitles for the same time
67 period with the same plain_text() call otherwise the
68 TextDecoder will assume there is nothing else at the
69 time of emit the first.
72 list<dcp::SubtitleString> s;
73 ContentTimePeriod const p = content_time_period (*_next);
75 while (_next != _subtitles.end () && content_time_period (*_next) == p) {
76 shared_ptr<dcp::SubtitleString> ns = dynamic_pointer_cast<dcp::SubtitleString>(*_next);
82 /* XXX: image subtitles */
85 only_text()->emit_plain (p, s);
90 DCPSubtitleDecoder::content_time_period (shared_ptr<dcp::Subtitle> s) const
92 return ContentTimePeriod (
93 ContentTime::from_seconds (s->in().as_seconds ()),
94 ContentTime::from_seconds (s->out().as_seconds ())