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