72366ee3d9bbe0a2f6e996c4614a524fa212036b
[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 <boost/shared_ptr.hpp>
53 #include <list>
54 #include <vector>
55
56
57 namespace dcp {
58
59
60 class ReelMXF;
61 class Reel;
62 class MXFMetadata;
63 class CertificateChain;
64 class DecryptedKDM;
65
66
67 /** @class CPL
68  *  @brief A Composition Playlist.
69  */
70 class CPL : public Asset
71 {
72 public:
73         CPL (std::string annotation_text, ContentKind content_kind);
74         explicit CPL (boost::filesystem::path file);
75
76         bool equals (
77                 boost::shared_ptr<const Asset> other,
78                 EqualityOptions options,
79                 NoteHandler note
80                 ) const;
81
82         void add (boost::shared_ptr<Reel> reel);
83         void add (DecryptedKDM const &);
84
85         /** @return the reels in this CPL */
86         std::list<boost::shared_ptr<Reel> > reels () const {
87                 return _reels;
88         }
89
90         /** @return the ReelMXFs in this CPL in all reels */
91         std::list<boost::shared_ptr<const ReelMXF> > reel_mxfs () const;
92         std::list<boost::shared_ptr<ReelMXF> > reel_mxfs ();
93
94         bool encrypted () const;
95
96         void write_xml (
97                 boost::filesystem::path file,
98                 Standard standard,
99                 boost::shared_ptr<const CertificateChain>
100                 ) const;
101
102         void resolve_refs (std::list<boost::shared_ptr<Asset> >);
103
104         int64_t duration () const;
105
106         void set_issuer (std::string issuer) {
107                 _issuer = issuer;
108         }
109
110         void set_creator (std::string creator) {
111                 _creator = creator;
112         }
113
114         void set_issue_date (std::string issue_date) {
115                 _issue_date = issue_date;
116         }
117
118         /** @return contents of the &lt;AnnotationText&gt; node */
119         std::string annotation_text () const {
120                 return _annotation_text;
121         }
122
123         void set_annotation_text (std::string at) {
124                 _annotation_text = at;
125         }
126
127         /** @return contents of the &lt;ContentTitleText&gt; node */
128         std::string content_title_text () const {
129                 return _content_title_text;
130         }
131
132         void set_content_title_text (std::string ct) {
133                 _content_title_text = ct;
134         }
135
136         /** @return the type of the content, used by media servers
137          *  to categorise things (e.g. feature, trailer, etc.)
138          */
139         ContentKind content_kind () const {
140                 return _content_kind;
141         }
142
143         ContentVersion content_version () const;
144
145         std::vector<ContentVersion> content_versions () const {
146                 return _content_versions;
147         }
148
149         void set_content_version (ContentVersion v) {
150                 _content_versions.clear ();
151                 _content_versions.push_back (v);
152         }
153
154         void set_content_versions (std::vector<ContentVersion> v);
155
156         std::vector<Rating> ratings () const {
157                 return _ratings;
158         }
159
160         void set_ratings (std::vector<Rating> r) {
161                 _ratings = r;
162         }
163
164         boost::optional<std::string> full_content_title_text () const {
165                 return _full_content_title_text;
166         }
167
168         void set_full_content_title_text (std::string t) {
169                 _full_content_title_text = t;
170         }
171
172         boost::optional<std::string> full_content_title_text_language () const {
173                 return _full_content_title_text_language;
174         }
175
176         void set_full_content_title_text_language (dcp::LanguageTag l) {
177                 _full_content_title_text_language = l.to_string();
178         }
179
180         boost::optional<std::string> release_territory () const {
181                 return _release_territory;
182         }
183
184         void set_release_territory (dcp::LanguageTag::RegionSubtag t) {
185                 _release_territory = t.subtag();
186         }
187
188         boost::optional<int> version_number () const {
189                 return _version_number;
190         }
191
192         void set_version_number (int v);
193
194         boost::optional<Status> status () const {
195                 return _status;
196         }
197
198         void set_status (Status s) {
199                 _status = s;
200         }
201
202         boost::optional<std::string> chain () const {
203                 return _chain;
204         }
205
206         void set_chain (std::string c) {
207                 _chain = c;
208         }
209
210         boost::optional<std::string> distributor () const {
211                 return _distributor;
212         }
213
214         void set_distributor (std::string d) {
215                 _distributor = d;
216         }
217
218         boost::optional<std::string> facility () const {
219                 return _facility;
220         }
221
222         void set_facility (std::string f) {
223                 _facility = f;
224         }
225
226         boost::optional<Luminance> luminance () const {
227                 return _luminance;
228         }
229
230         void set_luminance (Luminance l) {
231                 _luminance = l;
232         }
233
234         boost::optional<std::string> main_sound_configuration () const {
235                 return _main_sound_configuration;
236         }
237
238         void set_main_sound_configuration (std::string c) {
239                 _main_sound_configuration = c;
240         }
241
242         boost::optional<int> main_sound_sample_rate () const {
243                 return _main_sound_sample_rate;
244         }
245
246         void set_main_sound_sample_rate (int r) {
247                 _main_sound_sample_rate = r;
248         }
249
250         boost::optional<dcp::Size> main_picture_stored_area () const {
251                 return _main_picture_stored_area;
252         }
253
254         void set_main_picture_stored_area (dcp::Size s) {
255                 _main_picture_stored_area = s;
256         }
257
258         boost::optional<dcp::Size> main_picture_active_area () const {
259                 return _main_picture_active_area;
260         }
261
262         void set_main_picture_active_area (dcp::Size s) {
263                 _main_picture_active_area = s;
264         }
265
266         std::vector<std::string> additional_subtitle_languages () const {
267                 return _additional_subtitle_languages;
268         }
269
270         void set_additional_subtitle_languages (std::vector<dcp::LanguageTag> const& lang);
271
272         boost::optional<Standard> standard () const {
273                 return _standard;
274         }
275
276         static std::string static_pkl_type (Standard standard);
277
278 protected:
279         /** @return type string for PKLs for this asset */
280         std::string pkl_type (Standard standard) const;
281
282 private:
283         void maybe_write_composition_metadata_asset (xmlpp::Element* node) const;
284         void read_composition_metadata_asset (cxml::ConstNodePtr node);
285
286         std::string _issuer;
287         std::string _creator;
288         std::string _issue_date;
289         std::string _annotation_text;
290         std::string _content_title_text;            ///< &lt;ContentTitleText&gt;
291         ContentKind _content_kind;                  ///< &lt;ContentKind&gt;
292         std::vector<ContentVersion> _content_versions;
293         std::vector<Rating> _ratings;
294         /** Human-readable name of the composition, without any metadata (i.e. no -FTR-EN-XX- etc.) */
295         boost::optional<std::string> _full_content_title_text;
296         boost::optional<std::string> _full_content_title_text_language;
297         /** This is stored and returned as a string so that we can tolerate non-RFC-5646 strings,
298          *  but must be set as a dcp::LanguageTag to try to ensure that we create compliant output.
299          */
300         boost::optional<std::string> _release_territory;
301         boost::optional<int> _version_number;
302         boost::optional<Status> _status;
303         boost::optional<std::string> _chain;
304         boost::optional<std::string> _distributor;
305         boost::optional<std::string> _facility;
306         boost::optional<Luminance> _luminance;
307         boost::optional<std::string> _main_sound_configuration;
308         boost::optional<int> _main_sound_sample_rate;
309         boost::optional<dcp::Size> _main_picture_stored_area;
310         boost::optional<dcp::Size> _main_picture_active_area;
311         /* See note for _release_territory above */
312         std::vector<std::string> _additional_subtitle_languages;
313
314         std::list<boost::shared_ptr<Reel> > _reels;
315
316         /** Standard of CPL that was read in */
317         boost::optional<Standard> _standard;
318 };
319
320
321 }
322
323
324 #endif