Extract resolution.h
[dcpomatic.git] / src / lib / types.cc
1 /*
2     Copyright (C) 2013-2019 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21 #include "types.h"
22 #include "compose.hpp"
23 #include "dcpomatic_assert.h"
24 #include <dcp/cpl.h>
25 #include <dcp/dcp.h>
26 #include <dcp/raw_convert.h>
27 #include <dcp/reel_asset.h>
28 #include <dcp/reel_file_asset.h>
29 #include <dcp/warnings.h>
30 LIBDCP_DISABLE_WARNINGS
31 #include <libxml++/libxml++.h>
32 LIBDCP_ENABLE_WARNINGS
33 #include <libcxml/cxml.h>
34
35 #include "i18n.h"
36
37 using std::max;
38 using std::min;
39 using std::string;
40 using std::list;
41 using std::shared_ptr;
42 using std::vector;
43 using dcp::raw_convert;
44
45
46 TextType
47 string_to_text_type (string s)
48 {
49         if (s == "unknown") {
50                 return TextType::UNKNOWN;
51         } else if (s == "open-subtitle") {
52                 return TextType::OPEN_SUBTITLE;
53         } else if (s == "closed-caption") {
54                 return TextType::CLOSED_CAPTION;
55         } else {
56                 throw MetadataError (String::compose ("Unknown text type %1", s));
57         }
58 }
59
60 string
61 text_type_to_string (TextType t)
62 {
63         switch (t) {
64         case TextType::UNKNOWN:
65                 return "unknown";
66         case TextType::OPEN_SUBTITLE:
67                 return "open-subtitle";
68         case TextType::CLOSED_CAPTION:
69                 return "closed-caption";
70         default:
71                 DCPOMATIC_ASSERT (false);
72         }
73 }
74
75 string
76 text_type_to_name (TextType t)
77 {
78         switch (t) {
79         case TextType::UNKNOWN:
80                 return _("Timed text");
81         case TextType::OPEN_SUBTITLE:
82                 return _("Open subtitles");
83         case TextType::CLOSED_CAPTION:
84                 return _("Closed captions");
85         default:
86                 DCPOMATIC_ASSERT (false);
87         }
88 }
89
90 string
91 video_frame_type_to_string (VideoFrameType t)
92 {
93         switch (t) {
94         case VideoFrameType::TWO_D:
95                 return "2d";
96         case VideoFrameType::THREE_D:
97                 return "3d";
98         case VideoFrameType::THREE_D_LEFT_RIGHT:
99                 return "3d-left-right";
100         case VideoFrameType::THREE_D_TOP_BOTTOM:
101                 return "3d-top-bottom";
102         case VideoFrameType::THREE_D_ALTERNATE:
103                 return "3d-alternate";
104         case VideoFrameType::THREE_D_LEFT:
105                 return "3d-left";
106         case VideoFrameType::THREE_D_RIGHT:
107                 return "3d-right";
108         default:
109                 DCPOMATIC_ASSERT (false);
110         }
111
112         DCPOMATIC_ASSERT (false);
113 }
114
115 VideoFrameType
116 string_to_video_frame_type (string s)
117 {
118         if (s == "2d") {
119                 return VideoFrameType::TWO_D;
120         } else if (s == "3d") {
121                 return VideoFrameType::THREE_D;
122         } else if (s == "3d-left-right") {
123                 return VideoFrameType::THREE_D_LEFT_RIGHT;
124         } else if (s == "3d-top-bottom") {
125                 return VideoFrameType::THREE_D_TOP_BOTTOM;
126         } else if (s == "3d-alternate") {
127                 return VideoFrameType::THREE_D_ALTERNATE;
128         } else if (s == "3d-left") {
129                 return VideoFrameType::THREE_D_LEFT;
130         } else if (s == "3d-right") {
131                 return VideoFrameType::THREE_D_RIGHT;
132         }
133
134         DCPOMATIC_ASSERT (false);
135 }
136
137 CPLSummary::CPLSummary (boost::filesystem::path p)
138         : dcp_directory (p.leaf().string())
139 {
140         dcp::DCP dcp (p);
141
142         vector<dcp::VerificationNote> notes;
143         dcp.read (&notes);
144         for (auto i: notes) {
145                 if (i.code() != dcp::VerificationNote::Code::EXTERNAL_ASSET) {
146                         /* It's not just a warning about this DCP being a VF */
147                         throw dcp::ReadError(dcp::note_to_string(i));
148                 }
149         }
150
151         cpl_id = dcp.cpls().front()->id();
152         cpl_annotation_text = dcp.cpls().front()->annotation_text();
153         cpl_file = dcp.cpls().front()->file().get();
154
155         encrypted = false;
156         for (auto j: dcp.cpls()) {
157                 for (auto k: j->reel_file_assets()) {
158                         if (k->encrypted()) {
159                                 encrypted = true;
160                         }
161                 }
162         }
163
164         boost::system::error_code ec;
165         auto last_write = boost::filesystem::last_write_time (p, ec);
166         last_write_time = ec ? 0 : last_write;
167 }
168
169
170 bool operator== (NamedChannel const& a, NamedChannel const& b)
171 {
172         return a.name == b.name && a.index == b.index;
173 }
174
175
176 string
177 video_range_to_string (VideoRange r)
178 {
179         switch (r) {
180         case VideoRange::FULL:
181                 return "full";
182         case VideoRange::VIDEO:
183                 return "video";
184         default:
185                 DCPOMATIC_ASSERT (false);
186         }
187 }
188
189
190 VideoRange
191 string_to_video_range (string s)
192 {
193         if (s == "full") {
194                 return VideoRange::FULL;
195         } else if (s == "video") {
196                 return VideoRange::VIDEO;
197         }
198
199         DCPOMATIC_ASSERT (false);
200         return VideoRange::FULL;
201 }
202