Supporters update.
[dcpomatic.git] / src / lib / dcp_content.h
1 /*
2     Copyright (C) 2014-2022 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
22 #ifndef DCPOMATIC_DCP_CONTENT_H
23 #define DCPOMATIC_DCP_CONTENT_H
24
25
26 /** @file  src/lib/dcp_content.h
27  *  @brief DCPContent class.
28  */
29
30
31 #include "content.h"
32 #include "enum_indexed_vector.h"
33 #include "font.h"
34 #include "resolution.h"
35 #include <libcxml/cxml.h>
36 #include <dcp/content_kind.h>
37 #include <dcp/encrypted_kdm.h>
38 #include <dcp/rating.h>
39
40
41 class DCPContentProperty
42 {
43 public:
44         static int const NEEDS_KDM;
45         static int const NEEDS_ASSETS;
46         static int const REFERENCE_VIDEO;
47         static int const REFERENCE_AUDIO;
48         static int const REFERENCE_TEXT;
49         static int const NAME;
50         static int const TEXTS;
51         static int const CPL;
52 };
53
54
55 /** @class DCPContent
56  *  @brief An existing DCP used as input.
57  */
58 class DCPContent : public Content
59 {
60 public:
61         DCPContent (boost::filesystem::path p);
62         DCPContent (cxml::ConstNodePtr, int version);
63
64         std::shared_ptr<DCPContent> shared_from_this () {
65                 return std::dynamic_pointer_cast<DCPContent> (Content::shared_from_this ());
66         }
67
68         std::shared_ptr<const DCPContent> shared_from_this () const {
69                 return std::dynamic_pointer_cast<const DCPContent> (Content::shared_from_this ());
70         }
71
72         dcpomatic::DCPTime full_length (std::shared_ptr<const Film> film) const override;
73         dcpomatic::DCPTime approximate_length () const override;
74
75         void examine (std::shared_ptr<const Film> film, std::shared_ptr<Job>) override;
76         std::string summary () const override;
77         std::string technical_summary () const override;
78         void as_xml (xmlpp::Node *, bool with_paths) const override;
79         std::string identifier () const override;
80         void take_settings_from (std::shared_ptr<const Content> c) override;
81
82         void set_default_colour_conversion ();
83         std::list<dcpomatic::DCPTime> reel_split_points (std::shared_ptr<const Film> film) const override;
84
85         std::vector<boost::filesystem::path> directories () const;
86
87         bool encrypted () const {
88                 boost::mutex::scoped_lock lm (_mutex);
89                 return _encrypted;
90         }
91
92         void add_kdm (dcp::EncryptedKDM);
93         void add_ov (boost::filesystem::path ov);
94
95         boost::optional<dcp::EncryptedKDM> kdm () const {
96                 return _kdm;
97         }
98
99         bool can_be_played () const override;
100         bool needs_kdm () const;
101         bool needs_assets () const;
102
103         void set_reference_video (bool r);
104
105         bool reference_video () const {
106                 boost::mutex::scoped_lock lm (_mutex);
107                 return _reference_video;
108         }
109
110         bool can_reference_video (std::shared_ptr<const Film> film, std::string &) const;
111
112         void set_reference_audio (bool r);
113
114         bool reference_audio () const {
115                 boost::mutex::scoped_lock lm (_mutex);
116                 return _reference_audio;
117         }
118
119         bool can_reference_audio (std::shared_ptr<const Film> film, std::string &) const;
120
121         void set_reference_text (TextType type, bool r);
122
123         /** @param type Original type of texts in the DCP.
124          *  @return true if these texts are to be referenced.
125          */
126         bool reference_text (TextType type) const {
127                 boost::mutex::scoped_lock lm (_mutex);
128                 return _reference_text[type];
129         }
130
131         bool can_reference_text (std::shared_ptr<const Film> film, TextType type, std::string &) const;
132
133         void set_cpl (std::string id);
134
135         boost::optional<std::string> cpl () const {
136                 boost::mutex::scoped_lock lm (_mutex);
137                 return _cpl;
138         }
139
140         std::string name () const {
141                 boost::mutex::scoped_lock lm (_mutex);
142                 return _name;
143         }
144
145         bool three_d () const {
146                 boost::mutex::scoped_lock lm (_mutex);
147                 return _three_d;
148         }
149
150         boost::optional<dcp::ContentKind> content_kind () const {
151                 boost::mutex::scoped_lock lm (_mutex);
152                 return _content_kind;
153         }
154
155         dcp::Standard standard () const {
156                 boost::mutex::scoped_lock lm (_mutex);
157                 DCPOMATIC_ASSERT (_standard);
158                 return _standard.get ();
159         }
160
161         std::map<dcp::Marker, dcpomatic::ContentTime> markers () const {
162                 return _markers;
163         }
164
165         bool kdm_timing_window_valid () const;
166
167         Resolution resolution () const;
168
169         std::vector<dcp::Rating> ratings () const {
170                 return _ratings;
171         }
172
173         std::vector<std::string> content_versions () const {
174                 return _content_versions;
175         }
176
177         int active_audio_channels() const;
178
179         void check_font_ids();
180
181 private:
182         friend struct reels_test5;
183
184         void add_properties (std::shared_ptr<const Film> film, std::list<UserProperty>& p) const override;
185
186         void read_directory (boost::filesystem::path);
187         void read_sub_directory (boost::filesystem::path);
188         std::list<dcpomatic::DCPTimePeriod> reels (std::shared_ptr<const Film> film) const;
189         bool can_reference (
190                 std::shared_ptr<const Film> film,
191                 std::function <bool (std::shared_ptr<const Content>)>,
192                 std::string overlapping,
193                 std::string& why_not
194                 ) const;
195
196         std::string _name;
197         /** true if our DCP is encrypted */
198         bool _encrypted;
199         /** true if this DCP needs more assets before it can be played */
200         bool _needs_assets;
201         boost::optional<dcp::EncryptedKDM> _kdm;
202         /** true if _kdm successfully decrypts the first frame of our DCP */
203         bool _kdm_valid;
204         /** true if the video in this DCP should be included in the output by reference
205          *  rather than by rewrapping.
206          */
207         bool _reference_video;
208         /** true if the audio in this DCP should be included in the output by reference
209          *  rather than by rewrapping.
210          */
211         bool _reference_audio;
212         /** true if the texts in this DCP should be included in the output by reference
213          *  rather than by rewrapping.  The types here are the original text types,
214          *  not what they are being used for.
215          */
216         EnumIndexedVector<bool, TextType> _reference_text;
217
218         boost::optional<dcp::Standard> _standard;
219         boost::optional<dcp::ContentKind> _content_kind;
220         bool _three_d;
221         /** ID of the CPL to use; older metadata might not specify this: in that case
222          *  just use the only CPL.
223          */
224         boost::optional<std::string> _cpl;
225         /** List of the lengths of the reels in this DCP */
226         std::list<int64_t> _reel_lengths;
227         std::map<dcp::Marker, dcpomatic::ContentTime> _markers;
228         std::vector<dcp::Rating> _ratings;
229         std::vector<std::string> _content_versions;
230
231         boost::optional<int> _active_audio_channels;
232 };
233
234
235 #endif