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