Rename Encryption -> Signer; move some methods into it.
[libdcp.git] / src / cpl.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 #ifndef LIBDCP_CPL_H
21 #define LIBDCP_CPL_H
22
23 #include <list>
24 #include <boost/shared_ptr.hpp>
25 #include <boost/function.hpp>
26 #include <boost/date_time/posix_time/posix_time.hpp>
27 #include <boost/optional.hpp>
28 #include <boost/filesystem.hpp>
29 #include <libxml++/libxml++.h>
30 #include "types.h"
31 #include "certificates.h"
32
33 namespace libdcp {
34
35 namespace parse {
36         class AssetMap;
37         class AssetMapAsset;
38 }
39         
40 class Asset;
41 class Reel;
42 class XMLMetadata;
43 class MXFMetadata;
44 class Signer;
45 class KDM;
46         
47 /** @brief A CPL within a DCP */
48 class CPL
49 {
50 public:
51         CPL (std::string directory, std::string name, ContentKind content_kind, int length, int frames_per_second);
52         CPL (std::string directory, std::string file, std::list<PathAssetMap> asset_maps, bool require_mxfs = true);
53
54         void add_reel (boost::shared_ptr<Reel> reel);
55         
56         /** @return the length in frames */
57         int length () const {
58                 return _length;
59         }
60
61         /** @return the type of the content, used by media servers
62          *  to categorise things (e.g. feature, trailer, etc.)
63          */
64         ContentKind content_kind () const {
65                 return _content_kind;
66         }
67
68         std::list<boost::shared_ptr<Reel> > reels () const {
69                 return _reels;
70         }
71
72         /** @return the CPL's name, as will be presented on projector
73          *  media servers and theatre management systems.
74          */
75         std::string name () const {
76                 return _name;
77         }
78
79         /** @return the number of frames per second */
80         int frames_per_second () const {
81                 return _fps;
82         }
83
84         std::list<boost::shared_ptr<const Asset> > assets () const;
85
86         bool encrypted () const;
87
88         std::string id () const {
89                 return _id;
90         }
91         
92         bool equals (CPL const & other, EqualityOptions options, boost::function<void (NoteType, std::string)> note) const;
93         
94         void write_xml (bool, XMLMetadata const &, boost::shared_ptr<const Signer>) const;
95         void write_to_assetmap (xmlpp::Node *) const;
96         void write_to_pkl (xmlpp::Node *) const;
97
98         /** Make a KDM for this CPL.
99          *  @param signer Details of the certificates and private key to sign the KDM with.
100          *  @param recipient_cert The certificate of the projector that this KDM is targeted at.  This will contain the
101          *  projector's public key which is used to encrypt the content keys.
102          *  @param from Time that the KDM should be valid from.
103          *  @param until Time that the KDM should be valid until.
104          *  @param interop true to generate an interop KDM, false for SMPTE.
105          */
106         boost::shared_ptr<xmlpp::Document> make_kdm (
107                 boost::shared_ptr<const Signer> signer,
108                 boost::shared_ptr<const Certificate> recipient_cert,
109                 boost::posix_time::ptime from,
110                 boost::posix_time::ptime until,
111                 bool interop,
112                 MXFMetadata const &,
113                 XMLMetadata const &
114                 ) const;
115
116         void add_kdm (KDM const &);
117         
118 private:
119         std::pair<std::string, boost::shared_ptr<const parse::AssetMapAsset> > asset_from_id (std::list<PathAssetMap>, std::string id) const;
120         
121         std::string _directory;
122         /** the name of the DCP */
123         std::string _name;
124         /** the content kind of the CPL */
125         ContentKind _content_kind;
126         /** length in frames */
127         mutable int _length;
128         /** frames per second */
129         int _fps;
130         /** reels */
131         std::list<boost::shared_ptr<Reel> > _reels;
132
133         /** our UUID */
134         std::string _id;
135         /** a SHA1 digest of our XML */
136         mutable std::string _digest;
137 };
138
139 }
140
141 #endif