Add issuer() and creator() getters to CPL.
[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_invalid_language3;
57
58
59 namespace dcp {
60
61
62 class ReelFileAsset;
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, Standard standard);
76
77         /** Construct a CPL object from a XML file */
78         explicit CPL (boost::filesystem::path file);
79
80         bool equals (
81                 std::shared_ptr<const Asset> other,
82                 EqualityOptions options,
83                 NoteHandler note
84                 ) const override;
85
86         /** Add a reel to this CPL
87          *  @param reel Reel to add
88          */
89         void add (std::shared_ptr<Reel> reel);
90
91         /** Add a KDM to this CPL.  If the KDM is for any of this CPLs assets it will be used
92          *  to decrypt those assets.
93          *  @param kdm KDM.
94          */
95         void add (DecryptedKDM const &);
96
97         /** @return the reels in this CPL */
98         std::vector<std::shared_ptr<Reel>> reels () const {
99                 return _reels;
100         }
101
102         /** @return the ReelFileAssets in this CPL in all reels */
103         std::vector<std::shared_ptr<const ReelFileAsset>> reel_file_assets () const;
104         std::vector<std::shared_ptr<ReelFileAsset>> reel_file_assets ();
105
106         /** @return true if we have any encrypted content */
107         bool any_encrypted () const;
108
109         /** @return true if we have all our encryptable content is encrypted */
110         bool all_encrypted () const;
111
112         /** Write an CompositonPlaylist XML file
113          *
114          *  @param file Filename to write
115          *  @param signer Signer to sign the CPL, or 0 to add no signature
116          */
117         void write_xml (
118                 boost::filesystem::path file,
119                 std::shared_ptr<const CertificateChain>
120                 ) const;
121
122         void resolve_refs (std::vector<std::shared_ptr<Asset>>);
123
124         int64_t duration () const;
125
126         std::string issuer () const {
127                 return _issuer;
128         }
129
130         void set_issuer (std::string issuer) {
131                 _issuer = issuer;
132         }
133
134         std::string creator () const {
135                 return _creator;
136         }
137
138         void set_creator (std::string creator) {
139                 _creator = creator;
140         }
141
142         void set_issue_date (std::string issue_date) {
143                 _issue_date = issue_date;
144         }
145
146         /** @return contents of the &lt;AnnotationText&gt; node, if present */
147         boost::optional<std::string> annotation_text () const {
148                 return _annotation_text;
149         }
150
151         void set_annotation_text (std::string at) {
152                 _annotation_text = at;
153         }
154
155         /** @return contents of the &lt;ContentTitleText&gt; node */
156         std::string content_title_text () const {
157                 return _content_title_text;
158         }
159
160         void set_content_title_text (std::string ct) {
161                 _content_title_text = ct;
162         }
163
164         void set_content_kind (dcp::ContentKind k) {
165                 _content_kind = k;
166         }
167
168         /** @return the type of the content, used by media servers
169          *  to categorise things (e.g. feature, trailer, etc.)
170          */
171         ContentKind content_kind () const {
172                 return _content_kind;
173         }
174
175         boost::optional<ContentVersion> content_version () const;
176
177         std::vector<ContentVersion> content_versions () const {
178                 return _content_versions;
179         }
180
181         void set_content_version (ContentVersion v) {
182                 _content_versions.clear ();
183                 _content_versions.push_back (v);
184         }
185
186         void set_content_versions (std::vector<ContentVersion> v);
187
188         std::vector<Rating> ratings () const {
189                 return _ratings;
190         }
191
192         void set_ratings (std::vector<Rating> r) {
193                 _ratings = r;
194         }
195
196         boost::optional<std::string> full_content_title_text () const {
197                 return _full_content_title_text;
198         }
199
200         void set_full_content_title_text (std::string t) {
201                 _full_content_title_text = t;
202         }
203
204         boost::optional<std::string> full_content_title_text_language () const {
205                 return _full_content_title_text_language;
206         }
207
208         void set_full_content_title_text_language (dcp::LanguageTag l) {
209                 _full_content_title_text_language = l.to_string();
210         }
211
212         boost::optional<std::string> release_territory () const {
213                 return _release_territory;
214         }
215
216         void set_release_territory (dcp::LanguageTag::RegionSubtag t) {
217                 _release_territory = t.subtag();
218         }
219
220         boost::optional<std::string> release_territory_scope () const {
221                 return _release_territory_scope;
222         }
223
224         boost::optional<int> version_number () const {
225                 return _version_number;
226         }
227
228         void set_version_number (int v);
229
230         void unset_version_number ();
231
232         boost::optional<Status> status () const {
233                 return _status;
234         }
235
236         void set_status (Status s) {
237                 _status = s;
238         }
239
240         boost::optional<std::string> chain () const {
241                 return _chain;
242         }
243
244         void set_chain (std::string c) {
245                 _chain = c;
246         }
247
248         boost::optional<std::string> distributor () const {
249                 return _distributor;
250         }
251
252         void set_distributor (std::string d) {
253                 _distributor = d;
254         }
255
256         boost::optional<std::string> facility () const {
257                 return _facility;
258         }
259
260         void set_facility (std::string f) {
261                 _facility = f;
262         }
263
264         boost::optional<Luminance> luminance () const {
265                 return _luminance;
266         }
267
268         void set_luminance (Luminance l) {
269                 _luminance = l;
270         }
271
272         boost::optional<std::string> main_sound_configuration () const {
273                 return _main_sound_configuration;
274         }
275
276         void set_main_sound_configuration (std::string c) {
277                 _main_sound_configuration = c;
278         }
279
280         boost::optional<int> main_sound_sample_rate () const {
281                 return _main_sound_sample_rate;
282         }
283
284         void set_main_sound_sample_rate (int r) {
285                 _main_sound_sample_rate = r;
286         }
287
288         boost::optional<dcp::Size> main_picture_stored_area () const {
289                 return _main_picture_stored_area;
290         }
291
292         void set_main_picture_stored_area (dcp::Size s) {
293                 _main_picture_stored_area = s;
294         }
295
296         boost::optional<dcp::Size> main_picture_active_area () const {
297                 return _main_picture_active_area;
298         }
299
300         void set_main_picture_active_area (dcp::Size s) {
301                 _main_picture_active_area = s;
302         }
303
304         std::vector<std::string> additional_subtitle_languages () const {
305                 return _additional_subtitle_languages;
306         }
307
308         void set_additional_subtitle_languages (std::vector<dcp::LanguageTag> const& lang);
309
310         Standard standard () const {
311                 return _standard;
312         }
313
314         static std::string static_pkl_type (Standard standard);
315
316 protected:
317         /** @return type string for PKLs for this asset */
318         std::string pkl_type (Standard standard) const override;
319
320 private:
321         friend struct ::verify_invalid_language3;
322
323         void maybe_write_composition_metadata_asset (xmlpp::Element* node) const;
324         void read_composition_metadata_asset (cxml::ConstNodePtr node);
325
326         std::string _issuer;
327         std::string _creator;
328         std::string _issue_date;
329         boost::optional<std::string> _annotation_text;
330         std::string _content_title_text;            ///< &lt;ContentTitleText&gt;
331         ContentKind _content_kind;                  ///< &lt;ContentKind&gt;
332         std::vector<ContentVersion> _content_versions;
333         std::vector<Rating> _ratings;
334         /** ID for CompositionMetadataAsset tag; either a random one, ready for writing a new tag,
335          *  or the one read in from the existing CPL.
336          */
337         std::string _cpl_metadata_id = make_uuid();
338         /** Human-readable name of the composition, without any metadata (i.e. no -FTR-EN-XX- etc.) */
339         boost::optional<std::string> _full_content_title_text;
340         boost::optional<std::string> _full_content_title_text_language;
341         /** This is stored and returned as a string so that we can tolerate non-RFC-5646 strings,
342          *  but must be set as a dcp::LanguageTag to try to ensure that we create compliant output.
343          */
344         boost::optional<std::string> _release_territory;
345         boost::optional<std::string> _release_territory_scope;
346         boost::optional<int> _version_number;
347         boost::optional<Status> _status;
348         boost::optional<std::string> _chain;
349         boost::optional<std::string> _distributor;
350         boost::optional<std::string> _facility;
351         boost::optional<Luminance> _luminance;
352         boost::optional<std::string> _main_sound_configuration;
353         boost::optional<int> _main_sound_sample_rate;
354         boost::optional<dcp::Size> _main_picture_stored_area;
355         boost::optional<dcp::Size> _main_picture_active_area;
356         /* See note for _release_territory above */
357         std::vector<std::string> _additional_subtitle_languages;
358
359         std::vector<std::shared_ptr<Reel>> _reels;
360
361         /** Standard of CPL that was read in */
362         Standard _standard;
363 };
364
365
366 }
367
368
369 #endif