Rename encrypted() to any_encrypted() and add all_encrypted().
[libdcp.git] / src / dcp.h
1 /*
2     Copyright (C) 2012-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 /** @file  src/dcp.h
35  *  @brief DCP class.
36  */
37
38 #ifndef LIBDCP_DCP_H
39 #define LIBDCP_DCP_H
40
41 #include "compose.hpp"
42 #include "types.h"
43 #include "util.h"
44 #include "certificate.h"
45 #include "metadata.h"
46 #include "name_format.h"
47 #include "verify.h"
48 #include "version.h"
49 #include <memory>
50 #include <boost/signals2.hpp>
51 #include <string>
52 #include <vector>
53
54 namespace xmlpp {
55         class Document;
56         class Element;
57 }
58
59 /** @brief Namespace for everything in libdcp */
60 namespace dcp
61 {
62
63 class PKL;
64 class Content;
65 class Reel;
66 class CPL;
67 class CertificateChain;
68 class DecryptedKDM;
69 class Asset;
70 class ReadError;
71
72 /** @class DCP
73  *  @brief A class to create or read a DCP.
74  */
75
76 class DCP : public boost::noncopyable
77 {
78 public:
79         /** Construct a DCP.  You can pass an existing DCP's directory
80          *  as the parameter; alternatively, directory will be created
81          *  if it does not exist.  Note that if you pass an existing DCP
82          *  into this constructor it will not be read until you call ::read().
83          *
84          *  @param directory Directory containing the DCP's files.
85          */
86         explicit DCP (boost::filesystem::path directory);
87
88         /** Read the DCP's structure into this object.
89          *  @param notes List of notes that will be added to if non-0.
90          *  @param ignore_incorrect_picture_mxf_type true to try loading MXF files marked as monoscopic
91          *  as stereoscopic if the monoscopic load fails; fixes problems some 3D DCPs that (I think)
92          *  have an incorrect descriptor in their MXF.
93          */
94         void read (std::vector<VerificationNote>* notes = 0, bool ignore_incorrect_picture_mxf_type = false);
95
96         /** Compare this DCP with another, according to various options.
97          *  @param other DCP to compare this one to.
98          *  @param options Options to define what "equality" means.
99          *  @param note Functor to handle notes made by the equality operation.
100          *  @return true if the DCPs are equal according to EqualityOptions, otherwise false.
101          */
102         bool equals (DCP const & other, EqualityOptions options, NoteHandler note) const;
103
104         void add (std::shared_ptr<CPL> cpl);
105
106         std::vector<std::shared_ptr<CPL>> cpls () const;
107         std::vector<std::shared_ptr<Asset>> assets (bool ignore_unresolved = false) const;
108
109         bool any_encrypted () const;
110         bool all_encrypted () const;
111
112         void add (DecryptedKDM const &);
113
114         void write_xml (
115                 Standard standard,
116                 std::string issuer = String::compose("libdcp %1", dcp::version),
117                 std::string creator = String::compose("libdcp %1", dcp::version),
118                 std::string issue_date = LocalTime().as_string(),
119                 std::string annotation_text = String::compose("Created by libdcp %1", dcp::version),
120                 std::shared_ptr<const CertificateChain> signer = std::shared_ptr<const CertificateChain> (),
121                 NameFormat name_format = NameFormat("%t")
122         );
123
124         void resolve_refs (std::vector<std::shared_ptr<Asset>> assets);
125
126         /** @return Standard of a DCP that was read in */
127         boost::optional<Standard> standard () const {
128                 return _standard;
129         }
130
131         boost::filesystem::path directory () const {
132                 return _directory;
133         }
134
135         /** @return PKLs if this DCP was read from an existing one, or if write_xml() has been called on it.
136          *  If neither is true, this method returns an empty vector.
137          */
138         std::vector<std::shared_ptr<PKL>> pkls () const {
139                 return _pkls;
140         }
141
142         boost::optional<boost::filesystem::path> asset_map_path () {
143                 return _asset_map;
144         }
145
146         static std::vector<boost::filesystem::path> directories_from_files (std::vector<boost::filesystem::path> files);
147
148 private:
149
150         void write_volindex (Standard standard) const;
151
152         /** Write the ASSETMAP file.
153          *  @param pkl_uuid UUID of our PKL.
154          *  @param pkl_path Pathname of our PKL file.
155          */
156         void write_assetmap (
157                 Standard standard, std::string pkl_uuid, boost::filesystem::path pkl_path,
158                 std::string issuer, std::string creator, std::string issue_date, std::string annotation_text
159                 ) const;
160
161         /** The directory that we are writing to */
162         boost::filesystem::path _directory;
163         /** The CPLs that make up this DCP */
164         std::vector<std::shared_ptr<CPL>> _cpls;
165         /** The PKLs that make up this DCP */
166         std::vector<std::shared_ptr<PKL>> _pkls;
167         /** File that the ASSETMAP was read from or last written to */
168         mutable boost::optional<boost::filesystem::path> _asset_map;
169
170         /** Standard of DCP that was read in */
171         boost::optional<Standard> _standard;
172 };
173
174 }
175
176 #endif