Obey requests to change the video range of RGB content.
[dcpomatic.git] / src / lib / types.h
1 /*
2     Copyright (C) 2013-2016 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 #ifndef DCPOMATIC_TYPES_H
22 #define DCPOMATIC_TYPES_H
23
24 #include "position.h"
25 #include "rect.h"
26 #include <dcp/util.h>
27 #include <boost/shared_ptr.hpp>
28 #include <vector>
29 #include <stdint.h>
30
31 class Content;
32 class VideoContent;
33 class AudioContent;
34 class TextContent;
35 class FFmpegContent;
36
37 namespace cxml {
38         class Node;
39 }
40
41 namespace xmlpp {
42         class Node;
43 }
44
45 /** The version number of the protocol used to communicate
46  *  with servers.  Intended to be bumped when incompatibilities
47  *  are introduced.  v2 uses 64+n
48  *
49  *  64 - first version used
50  *  65 - v2.16.0 - checksums added to communication
51  */
52 #define SERVER_LINK_VERSION (64+1)
53
54 /** A film of F seconds at f FPS will be Ff frames;
55     Consider some delta FPS d, so if we run the same
56     film at (f + d) FPS it will last F(f + d) seconds.
57
58     Hence the difference in length over the length of the film will
59     be F(f + d) - Ff frames
60     = Ff + Fd - Ff frames
61     = Fd frames
62     = Fd/f seconds
63
64     So if we accept a difference of 1 frame, ie 1/f seconds, we can
65     say that
66
67     1/f = Fd/f
68     ie 1 = Fd
69     ie d = 1/F
70
71     So for a 3hr film, ie F = 3 * 60 * 60 = 10800, the acceptable
72     FPS error is 1/F ~= 0.0001 ~= 1e-4
73 */
74 #define VIDEO_FRAME_RATE_EPSILON (1e-4)
75
76 /** Port on which EncodeServer listens for frame encoding requests */
77 #define ENCODE_FRAME_PORT (Config::instance()->server_port_base())
78 /** Port on which EncodeServer listens for DCPOMATIC_HELLO from masters */
79 #define HELLO_PORT (Config::instance()->server_port_base()+1)
80 /** Port on which EncodeServerFinder in the main DCP-o-matic listens for replies to DCPOMATIC_HELLO from servers */
81 #define MAIN_SERVER_PRESENCE_PORT (Config::instance()->server_port_base()+2)
82 /** Port on which EncodeServerFinder in the batch converter listens for replies to DCPOMATIC_HELLO from servers */
83 #define BATCH_SERVER_PRESENCE_PORT (Config::instance()->server_port_base()+3)
84 /** Port on which batch converter listens for job requests */
85 #define BATCH_JOB_PORT (Config::instance()->server_port_base()+4)
86 /** Port on which player listens for play requests */
87 #define PLAYER_PLAY_PORT (Config::instance()->server_port_base()+5)
88
89 typedef std::vector<boost::shared_ptr<Content> > ContentList;
90 typedef std::vector<boost::shared_ptr<FFmpegContent> > FFmpegContentList;
91
92 typedef int64_t Frame;
93
94 enum VideoFrameType
95 {
96         VIDEO_FRAME_TYPE_2D,
97         /** `True' 3D content, e.g. 3D DCPs */
98         VIDEO_FRAME_TYPE_3D,
99         VIDEO_FRAME_TYPE_3D_LEFT_RIGHT,
100         VIDEO_FRAME_TYPE_3D_TOP_BOTTOM,
101         VIDEO_FRAME_TYPE_3D_ALTERNATE,
102         /** This content is all the left frames of some 3D */
103         VIDEO_FRAME_TYPE_3D_LEFT,
104         /** This content is all the right frames of some 3D */
105         VIDEO_FRAME_TYPE_3D_RIGHT
106 };
107
108 std::string video_frame_type_to_string (VideoFrameType);
109 VideoFrameType string_to_video_frame_type (std::string);
110
111 enum Eyes
112 {
113         EYES_BOTH,
114         EYES_LEFT,
115         EYES_RIGHT,
116         EYES_COUNT
117 };
118
119 enum Part
120 {
121         PART_LEFT_HALF,
122         PART_RIGHT_HALF,
123         PART_TOP_HALF,
124         PART_BOTTOM_HALF,
125         PART_WHOLE
126 };
127
128 enum ReelType
129 {
130         REELTYPE_SINGLE,
131         REELTYPE_BY_VIDEO_CONTENT,
132         REELTYPE_BY_LENGTH
133 };
134
135 enum ChangeType
136 {
137         CHANGE_TYPE_PENDING,
138         CHANGE_TYPE_DONE,
139         CHANGE_TYPE_CANCELLED
140 };
141
142
143 enum VideoRange
144 {
145         VIDEO_RANGE_FULL, ///< full,  or "JPEG" (0-255 for 8-bit)
146         VIDEO_RANGE_VIDEO ///< video, or "MPEG" (16-235 for 8-bit)
147 };
148
149 extern std::string video_range_to_string (VideoRange r);
150 extern VideoRange string_to_video_range (std::string s);
151
152
153 /** Type of captions.
154  *
155  *  The generally accepted definitions seem to be:
156  *  - subtitles: text for an audience who doesn't speak the film's language
157  *  - captions:  text for a hearing-impaired audience
158  *  - open:      on-screen
159  *  - closed:    only visible by some audience members
160  *
161  *  At the moment DoM supports open subtitles and closed captions.
162  *
163  *  There is some use of the word `subtitle' in the code which may mean
164  *  caption in some contexts.
165  */
166 enum TextType
167 {
168         TEXT_UNKNOWN,
169         TEXT_OPEN_SUBTITLE,
170         TEXT_CLOSED_CAPTION,
171         TEXT_COUNT
172 };
173
174 extern std::string text_type_to_string (TextType t);
175 extern std::string text_type_to_name (TextType t);
176 extern TextType string_to_text_type (std::string s);
177
178 enum ExportFormat
179 {
180         EXPORT_FORMAT_PRORES,
181         EXPORT_FORMAT_H264_AAC,
182         EXPORT_FORMAT_H264_PCM,
183         EXPORT_FORMAT_SUBTITLES_DCP
184 };
185
186 /** @struct Crop
187  *  @brief A description of the crop of an image or video.
188  */
189 struct Crop
190 {
191         Crop () : left (0), right (0), top (0), bottom (0) {}
192         Crop (int l, int r, int t, int b) : left (l), right (r), top (t), bottom (b) {}
193         explicit Crop (boost::shared_ptr<cxml::Node>);
194
195         /** Number of pixels to remove from the left-hand side */
196         int left;
197         /** Number of pixels to remove from the right-hand side */
198         int right;
199         /** Number of pixels to remove from the top */
200         int top;
201         /** Number of pixels to remove from the bottom */
202         int bottom;
203
204         dcp::Size apply (dcp::Size s, int minimum = 4) const {
205                 s.width -= left + right;
206                 s.height -= top + bottom;
207
208                 if (s.width < minimum) {
209                         s.width = minimum;
210                 }
211
212                 if (s.height < minimum) {
213                         s.height = minimum;
214                 }
215
216                 return s;
217         }
218
219         void as_xml (xmlpp::Node *) const;
220 };
221
222 extern bool operator== (Crop const & a, Crop const & b);
223 extern bool operator!= (Crop const & a, Crop const & b);
224
225 struct CPLSummary
226 {
227         CPLSummary (boost::filesystem::path p);
228
229         CPLSummary (std::string d, std::string i, std::string a, boost::filesystem::path f, bool e, time_t t)
230                 : dcp_directory (d)
231                 , cpl_id (i)
232                 , cpl_annotation_text (a)
233                 , cpl_file (f)
234                 , encrypted (e)
235                 , last_write_time (t)
236         {}
237
238         std::string dcp_directory;
239         std::string cpl_id;
240         std::string cpl_annotation_text;
241         boost::filesystem::path cpl_file;
242         /** true if this CPL has any encrypted assets */
243         bool encrypted;
244         time_t last_write_time;
245 };
246
247 enum Resolution {
248         RESOLUTION_2K,
249         RESOLUTION_4K
250 };
251
252 std::string resolution_to_string (Resolution);
253 Resolution string_to_resolution (std::string);
254
255 enum FileTransferProtocol {
256         FILE_TRANSFER_PROTOCOL_SCP,
257         FILE_TRANSFER_PROTOCOL_FTP
258 };
259
260 enum EmailProtocol {
261         EMAIL_PROTOCOL_AUTO,
262         EMAIL_PROTOCOL_PLAIN,
263         EMAIL_PROTOCOL_STARTTLS,
264         EMAIL_PROTOCOL_SSL
265 };
266
267
268 class NamedChannel
269 {
270 public:
271         NamedChannel (std::string name_, int index_)
272                 : name(name_)
273                 , index(index_)
274         {}
275
276         std::string name;
277         int index;
278 };
279
280
281 bool operator== (NamedChannel const& a, NamedChannel const& b);
282
283 #endif