2 Copyright (C) 2017-2021 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/>.
23 #include "content_part.h"
24 #include "dcp_content.h"
25 #include "dcpomatic_time_coalesce.h"
26 #include "empty_video.h"
30 #include "video_content.h"
35 using std::dynamic_pointer_cast;
40 using std::shared_ptr;
41 using namespace dcpomatic;
44 EmptyVideo::EmptyVideo (shared_ptr<const Film> film, shared_ptr<const Playlist> playlist, DCPTime length)
46 list<DCPTimePeriod> full_left;
47 list<DCPTimePeriod> full_right;
48 list<DCPTimePeriod> full_both;
49 for (auto i: playlist->content()) {
50 if (i->video && i->video->use() && i->can_be_played() && i->paths_valid()) {
51 auto period = DCPTimePeriod(i->position(), i->end(film));
52 if (i->video->frame_type() == VideoFrameType::THREE_D_LEFT) {
53 full_left.push_back (period);
54 } else if (i->video->frame_type() == VideoFrameType::THREE_D_RIGHT) {
55 full_right.push_back (period);
57 full_both.push_back (period);
62 auto const whole = DCPTimePeriod(DCPTime(), length);
64 auto empty_both = subtract(subtract(subtract({whole}, full_left), full_right), full_both);
65 auto empty_left = subtract(subtract(subtract({whole}, full_left), full_both), empty_both);
66 auto empty_right = subtract(subtract(subtract({whole}, full_right), full_both), empty_both);
68 for (auto left: empty_left) {
69 _periods.push_back (make_pair(left, Eyes::LEFT));
72 for (auto right: empty_right) {
73 _periods.push_back (make_pair(right, Eyes::RIGHT));
76 for (auto both: empty_both) {
77 _periods.push_back (make_pair(both, Eyes::BOTH));
80 _periods.sort([](std::pair<DCPTimePeriod, Eyes> const& a, std::pair<DCPTimePeriod, Eyes> const& b) {
81 return a.first < b.first;
84 if (!_periods.empty()) {
85 _position = _periods.front().first.from;
91 EmptyVideo::set_position (DCPTime position)
95 for (auto i: _periods) {
96 if (i.first.contains(_position)) {
101 for (auto i: _periods) {
102 if (i.first.from > _position) {
103 _position = i.first.from;
110 pair<DCPTimePeriod, Eyes>
111 EmptyVideo::period_at_position () const
113 for (auto i: _periods) {
114 if (i.first.contains(_position)) {
115 return make_pair(DCPTimePeriod(_position, i.first.to), i.second);
119 DCPOMATIC_ASSERT (false);
124 EmptyVideo::done () const
127 for (auto i: _periods) {
128 latest = max (latest, i.first.to);
131 return _position >= latest;