041db1786ea6c2653eba64c97161898b530a76c7
[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 SubtitleContent;
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 typedef std::vector<boost::shared_ptr<Content> > ContentList;
74 typedef std::vector<boost::shared_ptr<FFmpegContent> > FFmpegContentList;
75
76 typedef int64_t Frame;
77
78 enum VideoFrameType
79 {
80         VIDEO_FRAME_TYPE_2D,
81         /** `True' 3D content, e.g. 3D DCPs */
82         VIDEO_FRAME_TYPE_3D,
83         VIDEO_FRAME_TYPE_3D_LEFT_RIGHT,
84         VIDEO_FRAME_TYPE_3D_TOP_BOTTOM,
85         VIDEO_FRAME_TYPE_3D_ALTERNATE,
86         /** This content is all the left frames of some 3D */
87         VIDEO_FRAME_TYPE_3D_LEFT,
88         /** This content is all the right frames of some 3D */
89         VIDEO_FRAME_TYPE_3D_RIGHT
90 };
91
92 std::string video_frame_type_to_string (VideoFrameType);
93 VideoFrameType string_to_video_frame_type (std::string);
94
95 enum Eyes
96 {
97         EYES_BOTH,
98         EYES_LEFT,
99         EYES_RIGHT,
100         EYES_COUNT
101 };
102
103 enum Part
104 {
105         PART_LEFT_HALF,
106         PART_RIGHT_HALF,
107         PART_TOP_HALF,
108         PART_BOTTOM_HALF,
109         PART_WHOLE
110 };
111
112 enum ReelType
113 {
114         REELTYPE_SINGLE,
115         REELTYPE_BY_VIDEO_CONTENT,
116         REELTYPE_BY_LENGTH
117 };
118
119 /** @struct Crop
120  *  @brief A description of the crop of an image or video.
121  */
122 struct Crop
123 {
124         Crop () : left (0), right (0), top (0), bottom (0) {}
125         Crop (int l, int r, int t, int b) : left (l), right (r), top (t), bottom (b) {}
126         Crop (boost::shared_ptr<cxml::Node>);
127
128         /** Number of pixels to remove from the left-hand side */
129         int left;
130         /** Number of pixels to remove from the right-hand side */
131         int right;
132         /** Number of pixels to remove from the top */
133         int top;
134         /** Number of pixels to remove from the bottom */
135         int bottom;
136
137         dcp::Size apply (dcp::Size s, int minimum = 4) const {
138                 s.width -= left + right;
139                 s.height -= top + bottom;
140
141                 if (s.width < minimum) {
142                         s.width = minimum;
143                 }
144
145                 if (s.height < minimum) {
146                         s.height = minimum;
147                 }
148
149                 return s;
150         }
151
152         void as_xml (xmlpp::Node *) const;
153 };
154
155 struct CPLSummary
156 {
157         CPLSummary (std::string d, std::string i, std::string a, boost::filesystem::path f)
158                 : dcp_directory (d)
159                 , cpl_id (i)
160                 , cpl_annotation_text (a)
161                 , cpl_file (f)
162         {}
163
164         std::string dcp_directory;
165         std::string cpl_id;
166         std::string cpl_annotation_text;
167         boost::filesystem::path cpl_file;
168 };
169
170 extern bool operator== (Crop const & a, Crop const & b);
171 extern bool operator!= (Crop const & a, Crop const & b);
172
173 enum Resolution {
174         RESOLUTION_2K,
175         RESOLUTION_4K
176 };
177
178 std::string resolution_to_string (Resolution);
179 Resolution string_to_resolution (std::string);
180
181 enum Protocol {
182         PROTOCOL_SCP,
183         PROTOCOL_FTP
184 };
185
186 #endif