Bv2.1 6.2.1: Check that release territory conforms to RFC 5646.
[libdcp.git] / src / cpl.h
1 /*
2     Copyright (C) 2014-2020 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 <list>
54 #include <vector>
55
56
57 struct verify_various_invalid_languages;
58
59
60 namespace dcp {
61
62
63 class ReelMXF;
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);
77         explicit CPL (boost::filesystem::path file);
78
79         bool equals (
80                 std::shared_ptr<const Asset> other,
81                 EqualityOptions options,
82                 NoteHandler note
83                 ) const;
84
85         void add (std::shared_ptr<Reel> reel);
86         void add (DecryptedKDM const &);
87
88         /** @return the reels in this CPL */
89         std::list<std::shared_ptr<Reel> > reels () const {
90                 return _reels;
91         }
92
93         /** @return the ReelMXFs in this CPL in all reels */
94         std::list<std::shared_ptr<const ReelMXF> > reel_mxfs () const;
95         std::list<std::shared_ptr<ReelMXF> > reel_mxfs ();
96
97         bool 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::list<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 */
122         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         /** @return the type of the content, used by media servers
140          *  to categorise things (e.g. feature, trailer, etc.)
141          */
142         ContentKind content_kind () const {
143                 return _content_kind;
144         }
145
146         boost::optional<ContentVersion> content_version () const;
147
148         std::vector<ContentVersion> content_versions () const {
149                 return _content_versions;
150         }
151
152         void set_content_version (ContentVersion v) {
153                 _content_versions.clear ();
154                 _content_versions.push_back (v);
155         }
156
157         void set_content_versions (std::vector<ContentVersion> v);
158
159         std::vector<Rating> ratings () const {
160                 return _ratings;
161         }
162
163         void set_ratings (std::vector<Rating> r) {
164                 _ratings = r;
165         }
166
167         boost::optional<std::string> full_content_title_text () const {
168                 return _full_content_title_text;
169         }
170
171         void set_full_content_title_text (std::string t) {
172                 _full_content_title_text = t;
173         }
174
175         boost::optional<std::string> full_content_title_text_language () const {
176                 return _full_content_title_text_language;
177         }
178
179         void set_full_content_title_text_language (dcp::LanguageTag l) {
180                 _full_content_title_text_language = l.to_string();
181         }
182
183         boost::optional<std::string> release_territory () const {
184                 return _release_territory;
185         }
186
187         void set_release_territory (dcp::LanguageTag::RegionSubtag t) {
188                 _release_territory = t.subtag();
189         }
190
191         boost::optional<int> version_number () const {
192                 return _version_number;
193         }
194
195         void set_version_number (int v);
196
197         boost::optional<Status> status () const {
198                 return _status;
199         }
200
201         void set_status (Status s) {
202                 _status = s;
203         }
204
205         boost::optional<std::string> chain () const {
206                 return _chain;
207         }
208
209         void set_chain (std::string c) {
210                 _chain = c;
211         }
212
213         boost::optional<std::string> distributor () const {
214                 return _distributor;
215         }
216
217         void set_distributor (std::string d) {
218                 _distributor = d;
219         }
220
221         boost::optional<std::string> facility () const {
222                 return _facility;
223         }
224
225         void set_facility (std::string f) {
226                 _facility = f;
227         }
228
229         boost::optional<Luminance> luminance () const {
230                 return _luminance;
231         }
232
233         void set_luminance (Luminance l) {
234                 _luminance = l;
235         }
236
237         boost::optional<std::string> main_sound_configuration () const {
238                 return _main_sound_configuration;
239         }
240
241         void set_main_sound_configuration (std::string c) {
242                 _main_sound_configuration = c;
243         }
244
245         boost::optional<int> main_sound_sample_rate () const {
246                 return _main_sound_sample_rate;
247         }
248
249         void set_main_sound_sample_rate (int r) {
250                 _main_sound_sample_rate = r;
251         }
252
253         boost::optional<dcp::Size> main_picture_stored_area () const {
254                 return _main_picture_stored_area;
255         }
256
257         void set_main_picture_stored_area (dcp::Size s) {
258                 _main_picture_stored_area = s;
259         }
260
261         boost::optional<dcp::Size> main_picture_active_area () const {
262                 return _main_picture_active_area;
263         }
264
265         void set_main_picture_active_area (dcp::Size s) {
266                 _main_picture_active_area = s;
267         }
268
269         std::vector<std::string> additional_subtitle_languages () const {
270                 return _additional_subtitle_languages;
271         }
272
273         void set_additional_subtitle_languages (std::vector<dcp::LanguageTag> const& lang);
274
275         boost::optional<Standard> standard () const {
276                 return _standard;
277         }
278
279         static std::string static_pkl_type (Standard standard);
280
281 protected:
282         /** @return type string for PKLs for this asset */
283         std::string pkl_type (Standard standard) const;
284
285 private:
286         friend struct ::verify_various_invalid_languages;
287
288         void maybe_write_composition_metadata_asset (xmlpp::Element* node) const;
289         void read_composition_metadata_asset (cxml::ConstNodePtr node);
290
291         std::string _issuer;
292         std::string _creator;
293         std::string _issue_date;
294         std::string _annotation_text;
295         std::string _content_title_text;            ///< &lt;ContentTitleText&gt;
296         ContentKind _content_kind;                  ///< &lt;ContentKind&gt;
297         std::vector<ContentVersion> _content_versions;
298         std::vector<Rating> _ratings;
299         /** Human-readable name of the composition, without any metadata (i.e. no -FTR-EN-XX- etc.) */
300         boost::optional<std::string> _full_content_title_text;
301         boost::optional<std::string> _full_content_title_text_language;
302         /** This is stored and returned as a string so that we can tolerate non-RFC-5646 strings,
303          *  but must be set as a dcp::LanguageTag to try to ensure that we create compliant output.
304          */
305         boost::optional<std::string> _release_territory;
306         boost::optional<int> _version_number;
307         boost::optional<Status> _status;
308         boost::optional<std::string> _chain;
309         boost::optional<std::string> _distributor;
310         boost::optional<std::string> _facility;
311         boost::optional<Luminance> _luminance;
312         boost::optional<std::string> _main_sound_configuration;
313         boost::optional<int> _main_sound_sample_rate;
314         boost::optional<dcp::Size> _main_picture_stored_area;
315         boost::optional<dcp::Size> _main_picture_active_area;
316         /* See note for _release_territory above */
317         std::vector<std::string> _additional_subtitle_languages;
318
319         std::list<std::shared_ptr<Reel> > _reels;
320
321         /** Standard of CPL that was read in */
322         boost::optional<Standard> _standard;
323 };
324
325
326 }
327
328
329 #endif