Move some CPL writing from picture/sound assets to the MXF. Pick up key_id from...
[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         
40 /** @brief A CPL within a DCP */
41 class CPL
42 {
43 public:
44         CPL (std::string directory, std::string name, ContentKind content_kind, int length, int frames_per_second);
45         CPL (std::string directory, std::string file, boost::shared_ptr<const parse::AssetMap> asset_map, bool require_mxfs = true);
46
47         void add_reel (boost::shared_ptr<const Reel> reel);
48         
49         /** @return the length in frames */
50         int length () const {
51                 return _length;
52         }
53
54         /** @return the type of the content, used by media servers
55          *  to categorise things (e.g. feature, trailer, etc.)
56          */
57         ContentKind content_kind () const {
58                 return _content_kind;
59         }
60
61         std::list<boost::shared_ptr<const Reel> > reels () const {
62                 return _reels;
63         }
64
65         /** @return the CPL's name, as will be presented on projector
66          *  media servers and theatre management systems.
67          */
68         std::string name () const {
69                 return _name;
70         }
71
72         /** @return the number of frames per second */
73         int frames_per_second () const {
74                 return _fps;
75         }
76
77         std::list<boost::shared_ptr<const Asset> > assets () const;
78
79         bool encrypted () const;
80         
81         bool equals (CPL const & other, EqualityOptions options, boost::function<void (NoteType, std::string)> note) const;
82         
83         void write_xml (XMLMetadata const &, boost::shared_ptr<Encryption>) const;
84         void write_to_assetmap (xmlpp::Node *) const;
85         void write_to_pkl (xmlpp::Node *) const;
86
87         boost::shared_ptr<xmlpp::Document> make_kdm (
88                 CertificateChain const &,
89                 std::string const &,
90                 boost::shared_ptr<const Certificate>,
91                 boost::posix_time::ptime from,
92                 boost::posix_time::ptime until,
93                 MXFMetadata const &,
94                 XMLMetadata const &
95                 ) const;
96         
97 private:
98         std::string _directory;
99         /** the name of the DCP */
100         std::string _name;
101         /** the content kind of the CPL */
102         ContentKind _content_kind;
103         /** length in frames */
104         mutable int _length;
105         /** frames per second */
106         int _fps;
107         /** reels */
108         std::list<boost::shared_ptr<const Reel> > _reels;
109
110         /** our UUID */
111         std::string _uuid;
112         /** a SHA1 digest of our XML */
113         mutable std::string _digest;
114 };
115
116 }