5d087c039da724e76d3bc9a6d606487b276f06fb
[libdcp.git] / src / cpl.h
1 /*
2     Copyright (C) 2014-2021 Carl Hetherington <cth@carlh.net>
3
4     This file is part of libdcp.
5
6     libdcp 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     libdcp 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 libdcp.  If not, see <http://www.gnu.org/licenses/>.
18
19     In addition, as a special exception, the copyright holders give
20     permission to link the code of portions of this program with the
21     OpenSSL library under certain conditions as described in each
22     individual source file, and distribute linked combinations
23     including the two.
24
25     You must obey the GNU General Public License in all respects
26     for all of the code used other than OpenSSL.  If you modify
27     file(s) with this exception, you may extend this exception to your
28     version of the file(s), but you are not obligated to do so.  If you
29     do not wish to do so, delete this exception statement from your
30     version.  If you delete this exception statement from all source
31     files in the program, then also delete it here.
32 */
33
34
35 /** @file  src/cpl.h
36  *  @brief CPL class.
37  */
38
39
40 #ifndef LIBDCP_CPL_H
41 #define LIBDCP_CPL_H
42
43
44 #include "asset.h"
45 #include "certificate.h"
46 #include "key.h"
47 #include "language_tag.h"
48 #include "types.h"
49 #include <boost/filesystem.hpp>
50 #include <boost/function.hpp>
51 #include <boost/optional.hpp>
52 #include <memory>
53 #include <vector>
54
55
56 struct verify_various_invalid_languages;
57
58
59 namespace dcp {
60
61
62 class ReelMXF;
63 class Reel;
64 class MXFMetadata;
65 class CertificateChain;
66 class DecryptedKDM;
67
68
69 /** @class CPL
70  *  @brief A Composition Playlist.
71  */
72 class CPL : public Asset
73 {
74 public:
75         CPL (std::string annotation_text, ContentKind content_kind);
76         explicit CPL (boost::filesystem::path file);
77
78         bool equals (
79                 std::shared_ptr<const Asset> other,
80                 EqualityOptions options,
81                 NoteHandler note
82                 ) const;
83
84         void add (std::shared_ptr<Reel> reel);
85         void add (DecryptedKDM const &);
86
87         /** @return the reels in this CPL */
88         std::vector<std::shared_ptr<Reel>> reels () const {
89                 return _reels;
90         }
91
92         /** @return the ReelMXFs in this CPL in all reels */
93         std::vector<std::shared_ptr<const ReelMXF>> reel_mxfs () const;
94         std::vector<std::shared_ptr<ReelMXF>> reel_mxfs ();
95
96         bool any_encrypted () const;
97         bool all_encrypted () const;
98
99         void write_xml (
100                 boost::filesystem::path file,
101                 Standard standard,
102                 std::shared_ptr<const CertificateChain>
103                 ) const;
104
105         void resolve_refs (std::vector<std::shared_ptr<Asset>>);
106
107         int64_t duration () const;
108
109         void set_issuer (std::string issuer) {
110                 _issuer = issuer;
111         }
112
113         void set_creator (std::string creator) {
114                 _creator = creator;
115         }
116
117         void set_issue_date (std::string issue_date) {
118                 _issue_date = issue_date;
119         }
120
121         /** @return contents of the &lt;AnnotationText&gt; node, if present */
122         boost::optional<std::string> annotation_text () const {
123                 return _annotation_text;
124         }
125
126         void set_annotation_text (std::string at) {
127                 _annotation_text = at;
128         }
129
130         /** @return contents of the &lt;ContentTitleText&gt; node */
131         std::string content_title_text () const {
132                 return _content_title_text;
133         }
134
135         void set_content_title_text (std::string ct) {
136                 _content_title_text = ct;
137         }
138
139         void set_content_kind (dcp::ContentKind k) {
140                 _content_kind = k;
141         }
142
143         /** @return the type of the content, used by media servers
144          *  to categorise things (e.g. feature, trailer, etc.)
145          */
146         ContentKind content_kind () const {
147                 return _content_kind;
148         }
149
150         boost::optional<ContentVersion> content_version () const;
151
152         std::vector<ContentVersion> content_versions () const {
153                 return _content_versions;
154         }
155
156         void set_content_version (ContentVersion v) {
157                 _content_versions.clear ();
158                 _content_versions.push_back (v);
159         }
160
161         void set_content_versions (std::vector<ContentVersion> v);
162
163         std::vector<Rating> ratings () const {
164                 return _ratings;
165         }
166
167         void set_ratings (std::vector<Rating> r) {
168                 _ratings = r;
169         }
170
171         boost::optional<std::string> full_content_title_text () const {
172                 return _full_content_title_text;
173         }
174
175         void set_full_content_title_text (std::string t) {
176                 _full_content_title_text = t;
177         }
178
179         boost::optional<std::string> full_content_title_text_language () const {
180                 return _full_content_title_text_language;
181         }
182
183         void set_full_content_title_text_language (dcp::LanguageTag l) {
184                 _full_content_title_text_language = l.to_string();
185         }
186
187         boost::optional<std::string> release_territory () const {
188                 return _release_territory;
189         }
190
191         void set_release_territory (dcp::LanguageTag::RegionSubtag t) {
192                 _release_territory = t.subtag();
193         }
194
195         boost::optional<std::string> release_territory_scope () const {
196                 return _release_territory_scope;
197         }
198
199         boost::optional<int> version_number () const {
200                 return _version_number;
201         }
202
203         void set_version_number (int v);
204
205         void unset_version_number ();
206
207         boost::optional<Status> status () const {
208                 return _status;
209         }
210
211         void set_status (Status s) {
212                 _status = s;
213         }
214
215         boost::optional<std::string> chain () const {
216                 return _chain;
217         }
218
219         void set_chain (std::string c) {
220                 _chain = c;
221         }
222
223         boost::optional<std::string> distributor () const {
224                 return _distributor;
225         }
226
227         void set_distributor (std::string d) {
228                 _distributor = d;
229         }
230
231         boost::optional<std::string> facility () const {
232                 return _facility;
233         }
234
235         void set_facility (std::string f) {
236                 _facility = f;
237         }
238
239         boost::optional<Luminance> luminance () const {
240                 return _luminance;
241         }
242
243         void set_luminance (Luminance l) {
244                 _luminance = l;
245         }
246
247         boost::optional<std::string> main_sound_configuration () const {
248                 return _main_sound_configuration;
249         }
250
251         void set_main_sound_configuration (std::string c) {
252                 _main_sound_configuration = c;
253         }
254
255         boost::optional<int> main_sound_sample_rate () const {
256                 return _main_sound_sample_rate;
257         }
258
259         void set_main_sound_sample_rate (int r) {
260                 _main_sound_sample_rate = r;
261         }
262
263         boost::optional<dcp::Size> main_picture_stored_area () const {
264                 return _main_picture_stored_area;
265         }
266
267         void set_main_picture_stored_area (dcp::Size s) {
268                 _main_picture_stored_area = s;
269         }
270
271         boost::optional<dcp::Size> main_picture_active_area () const {
272                 return _main_picture_active_area;
273         }
274
275         void set_main_picture_active_area (dcp::Size s) {
276                 _main_picture_active_area = s;
277         }
278
279         std::vector<std::string> additional_subtitle_languages () const {
280                 return _additional_subtitle_languages;
281         }
282
283         void set_additional_subtitle_languages (std::vector<dcp::LanguageTag> const& lang);
284
285         boost::optional<Standard> standard () const {
286                 return _standard;
287         }
288
289         static std::string static_pkl_type (Standard standard);
290
291 protected:
292         /** @return type string for PKLs for this asset */
293         std::string pkl_type (Standard standard) const;
294
295 private:
296         friend struct ::verify_various_invalid_languages;
297
298         void maybe_write_composition_metadata_asset (xmlpp::Element* node) const;
299         void read_composition_metadata_asset (cxml::ConstNodePtr node);
300
301         std::string _issuer;
302         std::string _creator;
303         std::string _issue_date;
304         boost::optional<std::string> _annotation_text;
305         std::string _content_title_text;            ///< &lt;ContentTitleText&gt;
306         ContentKind _content_kind;                  ///< &lt;ContentKind&gt;
307         std::vector<ContentVersion> _content_versions;
308         std::vector<Rating> _ratings;
309         /** Human-readable name of the composition, without any metadata (i.e. no -FTR-EN-XX- etc.) */
310         boost::optional<std::string> _full_content_title_text;
311         boost::optional<std::string> _full_content_title_text_language;
312         /** This is stored and returned as a string so that we can tolerate non-RFC-5646 strings,
313          *  but must be set as a dcp::LanguageTag to try to ensure that we create compliant output.
314          */
315         boost::optional<std::string> _release_territory;
316         boost::optional<std::string> _release_territory_scope;
317         boost::optional<int> _version_number;
318         boost::optional<Status> _status;
319         boost::optional<std::string> _chain;
320         boost::optional<std::string> _distributor;
321         boost::optional<std::string> _facility;
322         boost::optional<Luminance> _luminance;
323         boost::optional<std::string> _main_sound_configuration;
324         boost::optional<int> _main_sound_sample_rate;
325         boost::optional<dcp::Size> _main_picture_stored_area;
326         boost::optional<dcp::Size> _main_picture_active_area;
327         /* See note for _release_territory above */
328         std::vector<std::string> _additional_subtitle_languages;
329
330         std::vector<std::shared_ptr<Reel>> _reels;
331
332         /** Standard of CPL that was read in */
333         boost::optional<Standard> _standard;
334 };
335
336
337 }
338
339
340 #endif