Working decryption via KDM.
[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 #include <list>
21 #include <boost/shared_ptr.hpp>
22 #include <boost/function.hpp>
23 #include <boost/date_time/posix_time/posix_time.hpp>
24 #include <libxml++/libxml++.h>
25 #include "types.h"
26 #include "certificates.h"
27
28 namespace libdcp {
29
30 namespace parse {
31         class AssetMap;
32 }
33         
34 class Asset;
35 class Reel;
36 class XMLMetadata;
37 class MXFMetadata;
38 class Encryption;
39 class KDM;
40         
41 /** @brief A CPL within a DCP */
42 class CPL
43 {
44 public:
45         CPL (std::string directory, std::string name, ContentKind content_kind, int length, int frames_per_second);
46         CPL (std::string directory, std::string file, boost::shared_ptr<const parse::AssetMap> asset_map, bool require_mxfs = true);
47
48         void add_reel (boost::shared_ptr<Reel> reel);
49         
50         /** @return the length in frames */
51         int length () const {
52                 return _length;
53         }
54
55         /** @return the type of the content, used by media servers
56          *  to categorise things (e.g. feature, trailer, etc.)
57          */
58         ContentKind content_kind () const {
59                 return _content_kind;
60         }
61
62         std::list<boost::shared_ptr<Reel> > reels () const {
63                 return _reels;
64         }
65
66         /** @return the CPL's name, as will be presented on projector
67          *  media servers and theatre management systems.
68          */
69         std::string name () const {
70                 return _name;
71         }
72
73         /** @return the number of frames per second */
74         int frames_per_second () const {
75                 return _fps;
76         }
77
78         std::list<boost::shared_ptr<const Asset> > assets () const;
79
80         bool encrypted () const;
81
82         std::string id () const {
83                 return _id;
84         }
85         
86         bool equals (CPL const & other, EqualityOptions options, boost::function<void (NoteType, std::string)> note) const;
87         
88         void write_xml (XMLMetadata const &, boost::shared_ptr<Encryption>) const;
89         void write_to_assetmap (xmlpp::Node *) const;
90         void write_to_pkl (xmlpp::Node *) const;
91
92         boost::shared_ptr<xmlpp::Document> make_kdm (
93                 CertificateChain const &,
94                 std::string const &,
95                 boost::shared_ptr<const Certificate>,
96                 boost::posix_time::ptime from,
97                 boost::posix_time::ptime until,
98                 MXFMetadata const &,
99                 XMLMetadata const &
100                 ) const;
101
102         void add_kdm (KDM const &);
103         
104 private:
105         std::string _directory;
106         /** the name of the DCP */
107         std::string _name;
108         /** the content kind of the CPL */
109         ContentKind _content_kind;
110         /** length in frames */
111         mutable int _length;
112         /** frames per second */
113         int _fps;
114         /** reels */
115         std::list<boost::shared_ptr<Reel> > _reels;
116
117         /** our UUID */
118         std::string _id;
119         /** a SHA1 digest of our XML */
120         mutable std::string _digest;
121 };
122
123 }