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