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