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