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