2 Copyright (C) 2013-2019 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 "compose.hpp"
23 #include "dcpomatic_assert.h"
25 #include <dcp/raw_convert.h>
28 #include <dcp/reel_file_asset.h>
29 #include <dcp/reel_asset.h>
30 DCPOMATIC_DISABLE_WARNINGS
31 #include <libxml++/libxml++.h>
32 DCPOMATIC_ENABLE_WARNINGS
33 #include <libcxml/cxml.h>
41 using std::shared_ptr;
43 using dcp::raw_convert;
45 bool operator== (Crop const & a, Crop const & b)
47 return (a.left == b.left && a.right == b.right && a.top == b.top && a.bottom == b.bottom);
50 bool operator!= (Crop const & a, Crop const & b)
55 /** @param r Resolution.
56 * @return Untranslated string representation.
59 resolution_to_string (Resolution r)
62 case Resolution::TWO_K:
64 case Resolution::FOUR_K:
68 DCPOMATIC_ASSERT (false);
74 string_to_resolution (string s)
77 return Resolution::TWO_K;
81 return Resolution::FOUR_K;
84 DCPOMATIC_ASSERT (false);
85 return Resolution::TWO_K;
88 Crop::Crop (shared_ptr<cxml::Node> node)
90 left = node->number_child<int> ("LeftCrop");
91 right = node->number_child<int> ("RightCrop");
92 top = node->number_child<int> ("TopCrop");
93 bottom = node->number_child<int> ("BottomCrop");
97 Crop::as_xml (xmlpp::Node* node) const
99 node->add_child("LeftCrop")->add_child_text (raw_convert<string> (left));
100 node->add_child("RightCrop")->add_child_text (raw_convert<string> (right));
101 node->add_child("TopCrop")->add_child_text (raw_convert<string> (top));
102 node->add_child("BottomCrop")->add_child_text (raw_convert<string> (bottom));
106 string_to_text_type (string s)
108 if (s == "unknown") {
109 return TextType::UNKNOWN;
110 } else if (s == "open-subtitle") {
111 return TextType::OPEN_SUBTITLE;
112 } else if (s == "closed-caption") {
113 return TextType::CLOSED_CAPTION;
115 throw MetadataError (String::compose ("Unknown text type %1", s));
120 text_type_to_string (TextType t)
123 case TextType::UNKNOWN:
125 case TextType::OPEN_SUBTITLE:
126 return "open-subtitle";
127 case TextType::CLOSED_CAPTION:
128 return "closed-caption";
130 DCPOMATIC_ASSERT (false);
135 text_type_to_name (TextType t)
138 case TextType::UNKNOWN:
139 return _("Timed text");
140 case TextType::OPEN_SUBTITLE:
141 return _("Open subtitles");
142 case TextType::CLOSED_CAPTION:
143 return _("Closed captions");
145 DCPOMATIC_ASSERT (false);
150 video_frame_type_to_string (VideoFrameType t)
153 case VideoFrameType::TWO_D:
155 case VideoFrameType::THREE_D:
157 case VideoFrameType::THREE_D_LEFT_RIGHT:
158 return "3d-left-right";
159 case VideoFrameType::THREE_D_TOP_BOTTOM:
160 return "3d-top-bottom";
161 case VideoFrameType::THREE_D_ALTERNATE:
162 return "3d-alternate";
163 case VideoFrameType::THREE_D_LEFT:
165 case VideoFrameType::THREE_D_RIGHT:
168 DCPOMATIC_ASSERT (false);
171 DCPOMATIC_ASSERT (false);
175 string_to_video_frame_type (string s)
178 return VideoFrameType::TWO_D;
179 } else if (s == "3d") {
180 return VideoFrameType::THREE_D;
181 } else if (s == "3d-left-right") {
182 return VideoFrameType::THREE_D_LEFT_RIGHT;
183 } else if (s == "3d-top-bottom") {
184 return VideoFrameType::THREE_D_TOP_BOTTOM;
185 } else if (s == "3d-alternate") {
186 return VideoFrameType::THREE_D_ALTERNATE;
187 } else if (s == "3d-left") {
188 return VideoFrameType::THREE_D_LEFT;
189 } else if (s == "3d-right") {
190 return VideoFrameType::THREE_D_RIGHT;
193 DCPOMATIC_ASSERT (false);
196 CPLSummary::CPLSummary (boost::filesystem::path p)
197 : dcp_directory (p.leaf().string())
201 vector<dcp::VerificationNote> notes;
203 for (auto i: notes) {
204 if (i.code() != dcp::VerificationNote::Code::EXTERNAL_ASSET) {
205 /* It's not just a warning about this DCP being a VF */
206 throw dcp::ReadError(dcp::note_to_string(i));
210 cpl_id = dcp.cpls().front()->id();
211 cpl_annotation_text = dcp.cpls().front()->annotation_text();
212 cpl_file = dcp.cpls().front()->file().get();
215 for (auto j: dcp.cpls()) {
216 for (auto k: j->reel_file_assets()) {
223 boost::system::error_code ec;
224 auto last_write = boost::filesystem::last_write_time (p, ec);
225 last_write_time = ec ? 0 : last_write;
229 bool operator== (NamedChannel const& a, NamedChannel const& b)
231 return a.name == b.name && a.index == b.index;
236 video_range_to_string (VideoRange r)
239 case VideoRange::FULL:
241 case VideoRange::VIDEO:
244 DCPOMATIC_ASSERT (false);
250 string_to_video_range (string s)
253 return VideoRange::FULL;
254 } else if (s == "video") {
255 return VideoRange::VIDEO;
258 DCPOMATIC_ASSERT (false);
259 return VideoRange::FULL;