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