Fix paths in OV DCP searches.
[libdcp.git] / src / dcp.h
1 /*
2     Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 /** @file  src/dcp.h
21  *  @brief A class to create a DCP.
22  */
23
24 #ifndef LIBDCP_DCP_H
25 #define LIBDCP_DCP_H
26
27 #include <string>
28 #include <vector>
29 #include <boost/shared_ptr.hpp>
30 #include <boost/signals2.hpp>
31 #include "types.h"
32 #include "certificates.h"
33
34 namespace xmlpp {
35         class Document;
36         class Element;
37 }
38
39 /** @brief Namespace for everything in libdcp */
40 namespace libdcp
41 {
42
43 class Asset;    
44 class PictureAsset;
45 class SoundAsset;
46 class SubtitleAsset;
47 class Reel;
48 class CPL;
49 class XMLMetadata;
50 class Encryption;
51 class KDM;
52
53 namespace parse {
54         class AssetMap;
55 }
56
57 /** @class DCP
58  *  @brief A class to create or read a DCP.
59  */
60         
61 class DCP : public boost::noncopyable
62 {
63 public:
64         /** Construct a DCP.  You can pass an existing DCP's directory
65          *  as the parameter, or a non-existant folder to create a new
66          *  DCP in.
67          *
68          *  @param directory Directory containing the DCP's files.
69          */
70         DCP (std::string directory);
71
72         /** Read an existing DCP's data.
73          *
74          *  The DCP's XML metadata will be examined, and you can then look at the contents
75          *  of the DCP.
76          *
77          *  @param require_mxfs true to throw an exception if MXF files are missing; setting to false
78          *  can be useful for testing, but normally it should be set to true.
79          */
80         void read (bool require_mxfs = true);
81
82         /** Write the required XML files to the directory that was
83          *  passed into the constructor.
84          */
85         void write_xml (bool interop, XMLMetadata const &, boost::shared_ptr<Encryption> crypt = boost::shared_ptr<Encryption> ()) const;
86
87         /** Compare this DCP with another, according to various options.
88          *  @param other DCP to compare this one to.
89          *  @param options Options to define what "equality" means.
90          *  @return true if the DCPs are equal according to EqualityOptions, otherwise false.
91          */
92         bool equals (DCP const & other, EqualityOptions options, boost::function<void (NoteType, std::string)> note) const;
93
94         /** Add a CPL to this DCP.
95          *  @param cpl CPL to add.
96          */
97         void add_cpl (boost::shared_ptr<CPL> cpl);
98
99         /** @return The list of CPLs in this DCP */
100         std::list<boost::shared_ptr<CPL> > cpls () const {
101                 return _cpls;
102         }
103
104         /** Add another DCP as a source of assets for this DCP.  This should be called before
105          *  ::read() on the DCP that needs the extra assets.  For example
106          *
107          *  DCP original_version ("my_dcp_OV");
108          *  DCP supplemental ("my_dcp_VF");
109          *  supplemental.add_assets_from (original_version);
110          *  supplemental.read ();
111          */
112         void add_assets_from (libdcp::DCP const &);
113
114         bool encrypted () const;
115
116         void add_kdm (KDM const &);
117
118         /** Emitted with a parameter between 0 and 1 to indicate progress
119          *  for long jobs.
120          */
121         boost::signals2::signal<void (float)> Progress;
122
123 private:
124
125         /** Write the PKL file.
126          *  @param pkl_uuid UUID to use.
127          */
128         std::string write_pkl (std::string pkl_uuid, bool, XMLMetadata const &, boost::shared_ptr<Encryption>) const;
129         
130         /** Write the VOLINDEX file */
131         void write_volindex () const;
132
133         /** Write the ASSETMAP file.
134          *  @param pkl_uuid UUID of our PKL.
135          *  @param pkl_length Length of our PKL in bytes.
136          */
137         void write_assetmap (std::string pkl_uuid, int pkl_length, bool, XMLMetadata const &) const;
138
139         /** @return Assets in all the CPLs in this DCP */
140         std::list<boost::shared_ptr<const Asset> > assets () const;
141
142         struct Files {
143                 std::list<std::string> cpls;
144                 std::string pkl;
145                 std::string asset_map;
146         };
147
148         /** the directory that we are writing to */
149         std::string _directory;
150         /** our CPLs */
151         std::list<boost::shared_ptr<CPL> > _cpls;
152
153         std::list<PathAssetMap> _asset_maps;
154 };
155
156 }
157
158 #endif