Merge branch 'master' into 1.0
[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 #include "key.h"
33 #include "asset.h"
34
35 namespace dcp {
36
37 namespace parse {
38         class AssetMap;
39         class AssetMapAsset;
40 }
41         
42 class Content;
43 class Reel;
44 class XMLMetadata;
45 class MXFMetadata;
46 class Signer;
47 class KDM;
48         
49 /** @class CPL
50  *  @brief A Composition Playlist.
51  */
52 class CPL : public Asset
53 {
54 public:
55         CPL (boost::filesystem::path directory, std::string name, ContentKind content_kind, int length, int frames_per_second);
56         CPL (boost::filesystem::path, std::string file, std::list<PathAssetMap> asset_maps, bool require_mxfs = true);
57
58         void add_reel (boost::shared_ptr<Reel> reel);
59         
60         /** @return the length in frames */
61         int length () const {
62                 return _length;
63         }
64
65         /** @return the type of the content, used by media servers
66          *  to categorise things (e.g. feature, trailer, etc.)
67          */
68         ContentKind content_kind () const {
69                 return _content_kind;
70         }
71
72         std::list<boost::shared_ptr<Reel> > reels () const {
73                 return _reels;
74         }
75
76         /** @return the CPL's name, as will be presented on projector
77          *  media servers and theatre management systems.
78          */
79         std::string name () const {
80                 return _name;
81         }
82
83         /** @return the number of frames per second */
84         int frames_per_second () const {
85                 return _fps;
86         }
87
88         std::list<boost::shared_ptr<const Content> > assets () const;
89
90         bool encrypted () const;
91
92         void set_mxf_keys (Key);
93
94         bool equals (CPL const & other, EqualityOptions options, boost::function<void (NoteType, std::string)> note) const;
95         
96         void write_xml (bool, XMLMetadata const &, boost::shared_ptr<const Signer>) const;
97         void write_to_assetmap (xmlpp::Node *) const;
98         void write_to_pkl (xmlpp::Node *) const;
99
100         void add_kdm (KDM const &);
101         
102 private:
103         std::pair<std::string, boost::shared_ptr<const parse::AssetMapAsset> > asset_from_id (std::list<PathAssetMap>, std::string id) const;
104         
105         boost::filesystem::path _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         /** a SHA1 digest of our XML */
118         mutable std::string _digest;
119 };
120
121 }
122
123 #endif