Missed update to private test repo version.
[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 #define SERVER_LINK_VERSION (64+0)
50
51 /** A film of F seconds at f FPS will be Ff frames;
52     Consider some delta FPS d, so if we run the same
53     film at (f + d) FPS it will last F(f + d) seconds.
54
55     Hence the difference in length over the length of the film will
56     be F(f + d) - Ff frames
57     = Ff + Fd - Ff frames
58     = Fd frames
59     = Fd/f seconds
60
61     So if we accept a difference of 1 frame, ie 1/f seconds, we can
62     say that
63
64     1/f = Fd/f
65     ie 1 = Fd
66     ie d = 1/F
67
68     So for a 3hr film, ie F = 3 * 60 * 60 = 10800, the acceptable
69     FPS error is 1/F ~= 0.0001 ~= 1e-4
70 */
71 #define VIDEO_FRAME_RATE_EPSILON (1e-4)
72
73 /** Port on which EncodeServer listens for frame encoding requests */
74 #define ENCODE_FRAME_PORT (Config::instance()->server_port_base())
75 /** Port on which EncodeServer listens for DCPOMATIC_HELLO from masters */
76 #define HELLO_PORT (Config::instance()->server_port_base()+1)
77 /** Port on which EncodeServerFinder in the main DCP-o-matic listens for replies to DCPOMATIC_HELLO from servers */
78 #define MAIN_SERVER_PRESENCE_PORT (Config::instance()->server_port_base()+2)
79 /** Port on which EncodeServerFinder in the batch converter listens for replies to DCPOMATIC_HELLO from servers */
80 #define BATCH_SERVER_PRESENCE_PORT (Config::instance()->server_port_base()+3)
81 /** Port on which batch converter listens for job requests */
82 #define BATCH_JOB_PORT (Config::instance()->server_port_base()+4)
83 /** Port on which player listens for play requests */
84 #define PLAYER_PLAY_PORT (Config::instance()->server_port_base()+5)
85
86 typedef std::vector<boost::shared_ptr<Content> > ContentList;
87 typedef std::vector<boost::shared_ptr<FFmpegContent> > FFmpegContentList;
88
89 typedef int64_t Frame;
90
91 enum VideoFrameType
92 {
93         VIDEO_FRAME_TYPE_2D,
94         /** `True' 3D content, e.g. 3D DCPs */
95         VIDEO_FRAME_TYPE_3D,
96         VIDEO_FRAME_TYPE_3D_LEFT_RIGHT,
97         VIDEO_FRAME_TYPE_3D_TOP_BOTTOM,
98         VIDEO_FRAME_TYPE_3D_ALTERNATE,
99         /** This content is all the left frames of some 3D */
100         VIDEO_FRAME_TYPE_3D_LEFT,
101         /** This content is all the right frames of some 3D */
102         VIDEO_FRAME_TYPE_3D_RIGHT
103 };
104
105 std::string video_frame_type_to_string (VideoFrameType);
106 VideoFrameType string_to_video_frame_type (std::string);
107
108 enum Eyes
109 {
110         EYES_BOTH,
111         EYES_LEFT,
112         EYES_RIGHT,
113         EYES_COUNT
114 };
115
116 enum Part
117 {
118         PART_LEFT_HALF,
119         PART_RIGHT_HALF,
120         PART_TOP_HALF,
121         PART_BOTTOM_HALF,
122         PART_WHOLE
123 };
124
125 enum ReelType
126 {
127         REELTYPE_SINGLE,
128         REELTYPE_BY_VIDEO_CONTENT,
129         REELTYPE_BY_LENGTH
130 };
131
132 enum ChangeType
133 {
134         CHANGE_TYPE_PENDING,
135         CHANGE_TYPE_DONE,
136         CHANGE_TYPE_CANCELLED
137 };
138
139 /** Type of captions.
140  *
141  *  The generally accepted definitions seem to be:
142  *  - subtitles: text for an audience who doesn't speak the film's language
143  *  - captions:  text for a hearing-impaired audience
144  *  - open:      on-screen
145  *  - closed:    only visible by some audience members
146  *
147  *  At the moment DoM supports open subtitles and closed captions.
148  *
149  *  There is some use of the word `subtitle' in the code which may mean
150  *  caption in some contexts.
151  */
152 enum TextType
153 {
154         TEXT_UNKNOWN,
155         TEXT_OPEN_SUBTITLE,
156         TEXT_CLOSED_CAPTION,
157         TEXT_COUNT
158 };
159
160 extern std::string text_type_to_string (TextType t);
161 extern std::string text_type_to_name (TextType t);
162 extern TextType string_to_text_type (std::string s);
163
164 enum ExportFormat
165 {
166         EXPORT_FORMAT_PRORES,
167         EXPORT_FORMAT_H264
168 };
169
170 /** @struct Crop
171  *  @brief A description of the crop of an image or video.
172  */
173 struct Crop
174 {
175         Crop () : left (0), right (0), top (0), bottom (0) {}
176         Crop (int l, int r, int t, int b) : left (l), right (r), top (t), bottom (b) {}
177         explicit Crop (boost::shared_ptr<cxml::Node>);
178
179         /** Number of pixels to remove from the left-hand side */
180         int left;
181         /** Number of pixels to remove from the right-hand side */
182         int right;
183         /** Number of pixels to remove from the top */
184         int top;
185         /** Number of pixels to remove from the bottom */
186         int bottom;
187
188         dcp::Size apply (dcp::Size s, int minimum = 4) const {
189                 s.width -= left + right;
190                 s.height -= top + bottom;
191
192                 if (s.width < minimum) {
193                         s.width = minimum;
194                 }
195
196                 if (s.height < minimum) {
197                         s.height = minimum;
198                 }
199
200                 return s;
201         }
202
203         void as_xml (xmlpp::Node *) const;
204 };
205
206 extern bool operator== (Crop const & a, Crop const & b);
207 extern bool operator!= (Crop const & a, Crop const & b);
208
209 struct CPLSummary
210 {
211         CPLSummary (boost::filesystem::path p);
212
213         CPLSummary (std::string d, std::string i, std::string a, boost::filesystem::path f, bool e, time_t t)
214                 : dcp_directory (d)
215                 , cpl_id (i)
216                 , cpl_annotation_text (a)
217                 , cpl_file (f)
218                 , encrypted (e)
219                 , last_write_time (t)
220         {}
221
222         std::string dcp_directory;
223         std::string cpl_id;
224         std::string cpl_annotation_text;
225         boost::filesystem::path cpl_file;
226         /** true if this CPL has any encrypted assets */
227         bool encrypted;
228         time_t last_write_time;
229 };
230
231 enum Resolution {
232         RESOLUTION_2K,
233         RESOLUTION_4K
234 };
235
236 std::string resolution_to_string (Resolution);
237 Resolution string_to_resolution (std::string);
238
239 enum FileTransferProtocol {
240         FILE_TRANSFER_PROTOCOL_SCP,
241         FILE_TRANSFER_PROTOCOL_FTP
242 };
243
244 enum EmailProtocol {
245         EMAIL_PROTOCOL_AUTO,
246         EMAIL_PROTOCOL_PLAIN,
247         EMAIL_PROTOCOL_STARTTLS,
248         EMAIL_PROTOCOL_SSL
249 };
250
251 #endif