Cleanup: move EqualityOptions into its own file.
[libdcp.git] / src / dcp.h
1 /*
2     Copyright (C) 2012-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/dcp.h
36  *  @brief DCP class
37  */
38
39
40 #ifndef LIBDCP_DCP_H
41 #define LIBDCP_DCP_H
42
43
44 #include "asset_map.h"
45 #include "certificate.h"
46 #include "compose.hpp"
47 #include "metadata.h"
48 #include "name_format.h"
49 #include "types.h"
50 #include "util.h"
51 #include "verify.h"
52 #include "version.h"
53 #include <boost/signals2.hpp>
54 #include <memory>
55 #include <string>
56 #include <vector>
57
58
59 namespace xmlpp {
60         class Document;
61         class Element;
62 }
63
64
65 /** @brief Namespace for everything in libdcp */
66 namespace dcp
67 {
68
69
70 class Asset;
71 class CPL;
72 class CertificateChain;
73 class Content;
74 class DecryptedKDM;
75 class EqualityOptions;
76 class PKL;
77 class ReadError;
78 class Reel;
79
80
81 /** @class DCP
82  *  @brief A class to create or read a DCP
83  */
84 class DCP
85 {
86 public:
87         /** Construct a DCP.  You can pass an existing DCP's directory
88          *  as the parameter; alternatively, directory will be created
89          *  if it does not exist.  Note that if you pass an existing DCP
90          *  into this constructor it will not be read until you call ::read().
91          *
92          *  @param directory Directory containing the DCP's files.
93          */
94         explicit DCP (boost::filesystem::path directory);
95
96         DCP (DCP const&) = delete;
97         DCP& operator= (DCP const&) = delete;
98
99         DCP (DCP &&);
100         DCP& operator= (DCP &&);
101
102         /** Read a DCP.  This method does not do any deep checking of the DCP's validity, but
103          *  if it comes across any bad things it will do one of two things.
104          *
105          *  Errors that are so serious that they prevent the method from working will result
106          *  in an exception being thrown.  For example, a missing ASSETMAP means that the DCP
107          *  can't be read without a lot of guesswork, so this will throw.
108          *
109          *  Errors that are not fatal will be added to notes, if it's non-null.  For example,
110          *  if the DCP contains a mixture of Interop and SMPTE elements this will result
111          *  in a note being added to the vector.
112          *
113          *  For more thorough checking of a DCP's contents, see dcp::verify().
114          *
115          *  @param notes List of notes that will be added to if non-0.
116          *  @param ignore_incorrect_picture_mxf_type true to try loading MXF files marked as monoscopic
117          *  as stereoscopic if the monoscopic load fails; fixes problems some 3D DCPs that (I think)
118          *  have an incorrect descriptor in their MXF.
119          */
120         void read (std::vector<VerificationNote>* notes = nullptr, bool ignore_incorrect_picture_mxf_type = false);
121
122         /** Compare this DCP with another, according to various options.
123          *  @param other DCP to compare this one to.
124          *  @param options Options to define what "equality" means.
125          *  @param note Functor to handle notes made by the equality operation.
126          *  @return true if the DCPs are equal according to EqualityOptions, otherwise false.
127          */
128         bool equals(DCP const & other, EqualityOptions const& options, NoteHandler note) const;
129
130         void add (std::shared_ptr<CPL> cpl);
131
132         std::vector<std::shared_ptr<CPL>> cpls () const;
133
134         /** @param ignore_unresolved true to silently ignore unresolved assets, otherwise
135          *  an exception is thrown if they are found.
136          *  @return All assets (including CPLs).
137          */
138         std::vector<std::shared_ptr<Asset>> assets (bool ignore_unresolved = false) const;
139
140         bool any_encrypted () const;
141         bool all_encrypted () const;
142
143         /** Add a KDM to decrypt this DCP.  This method must be called after DCP::read()
144          *  or the KDM you specify will be ignored.
145          *  @param kdm KDM to use.
146          */
147         void add (DecryptedKDM const &);
148
149         void set_issuer(std::string issuer);
150         void set_creator(std::string creator);
151         void set_issue_date(std::string issue_date);
152         void set_annotation_text(std::string annotation_text);
153
154         /** Write all the XML files for this DCP.
155          *  @param signer Signer to use
156          *  @param include_mca_subdescriptors true to write MCA subdescriptors to CPLs.
157          *  @param name_format Name format to use for the CPL and PKL filenames
158          */
159         void write_xml(
160                 std::shared_ptr<const CertificateChain> signer = std::shared_ptr<const CertificateChain>(),
161                 bool include_mca_subdescriptors = true,
162                 NameFormat name_format = NameFormat("%t")
163         );
164
165         void resolve_refs (std::vector<std::shared_ptr<Asset>> assets);
166
167         /** @return Standard of a DCP that was read in */
168         boost::optional<Standard> standard () const {
169                 if (!_asset_map) {
170                         return {};
171                 }
172
173                 return _asset_map->standard();
174         }
175
176         boost::filesystem::path directory () const {
177                 return _directory;
178         }
179
180         /** @return PKLs if this DCP was read from an existing one, or if write_xml() has been called on it.
181          *  If neither is true, this method returns an empty vector.
182          */
183         std::vector<std::shared_ptr<PKL>> pkls () const {
184                 return _pkls;
185         }
186
187         boost::optional<boost::filesystem::path> asset_map_file() const {
188                 if (!_asset_map) {
189                         return {};
190                 }
191
192                 return _asset_map->file();
193         }
194
195         boost::optional<AssetMap> asset_map() const {
196                 return _asset_map;
197         }
198
199         static std::vector<boost::filesystem::path> directories_from_files (std::vector<boost::filesystem::path> files);
200
201 private:
202
203         void write_volindex (Standard standard) const;
204
205         /** The directory that we are writing to */
206         boost::filesystem::path _directory;
207         /** The CPLs that make up this DCP */
208         std::vector<std::shared_ptr<CPL>> _cpls;
209         /** The PKLs that make up this DCP */
210         std::vector<std::shared_ptr<PKL>> _pkls;
211         boost::optional<AssetMap> _asset_map;
212
213         /* Metadata to use for newly created PKLs and AssetMaps */
214         boost::optional<std::string> _new_issuer;
215         boost::optional<std::string> _new_creator;
216         boost::optional<std::string> _new_issue_date;
217         boost::optional<std::string> _new_annotation_text;
218 };
219
220
221 }
222
223
224 #endif