2 Copyright (C) 2017-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/>.
22 #include "active_text.h"
23 #include "text_content.h"
30 using std::shared_ptr;
31 using boost::optional;
32 using namespace dcpomatic;
35 ActiveText::ActiveText(ActiveText&& other)
36 : _data(std::move(other._data))
43 ActiveText::operator=(ActiveText&& other)
46 _data = std::move(other._data);
52 /** Get the open captions that should be burnt into a given period.
53 * @param period Period of interest.
54 * @param always_burn_captions Always burn captions even if their content is not set to burn.
57 ActiveText::get_burnt (DCPTimePeriod period, bool always_burn_captions) const
59 boost::mutex::scoped_lock lm (_mutex);
63 for (auto const& i: _data) {
65 auto caption = i.first.lock ();
70 if (!caption->use() || (!always_burn_captions && !caption->burn())) {
71 /* Not burning this content */
75 for (auto j: i.second) {
76 DCPTimePeriod test (j.from, j.to.get_value_or(DCPTime::max()));
77 auto overlap = period.overlap (test);
78 if (overlap && overlap->duration() > DCPTime(period.duration().get() / 2)) {
79 ps.push_back (j.subs);
88 /** Remove subtitles that finish before a given time from our list.
89 * @param time Time to remove before.
92 ActiveText::clear_before (DCPTime time)
94 boost::mutex::scoped_lock lm (_mutex);
97 for (auto const& i: _data) {
99 for (auto j: i.second) {
100 if (!j.to || j.to.get() >= time) {
105 updated[i.first] = as;
112 /** Add a new subtitle with a from time.
113 * @param content Content that the subtitle is from.
114 * @param ps Subtitles.
115 * @param from From time for these subtitles.
118 ActiveText::add_from (weak_ptr<const TextContent> content, PlayerText ps, DCPTime from)
120 boost::mutex::scoped_lock lm (_mutex);
122 if (_data.find(content) == _data.end()) {
123 _data[content] = list<Period>();
125 _data[content].push_back (Period (ps, from));
129 /** Add the to time for the last subtitle added from a piece of content.
130 * @param content Content that the subtitle is from.
131 * @param to To time for the last subtitle submitted to add_from for this content.
132 * @return Return the corresponding subtitles and their from time.
134 pair<PlayerText, DCPTime>
135 ActiveText::add_to (weak_ptr<const TextContent> content, DCPTime to)
137 boost::mutex::scoped_lock lm (_mutex);
139 DCPOMATIC_ASSERT (_data.find(content) != _data.end());
141 _data[content].back().to = to;
143 for (auto& i: _data[content].back().subs.string) {
144 i.set_out (dcp::Time(to.seconds(), 1000));
147 return make_pair (_data[content].back().subs, _data[content].back().from);
151 /** @param content Some content.
152 * @return true if we have any active subtitles from this content.
155 ActiveText::have (weak_ptr<const TextContent> content) const
157 boost::mutex::scoped_lock lm (_mutex);
159 auto i = _data.find(content);
160 if (i == _data.end()) {
164 return !i->second.empty();
171 boost::mutex::scoped_lock lm (_mutex);