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