Clean up OS X build slightly. Better error on failure of xmlSecDSigCtxSign.
[libdcp.git] / src / asset.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 /** @file  src/asset.h
21  *  @brief Parent class for assets of DCPs.
22  */
23
24 #ifndef LIBDCP_ASSET_H
25 #define LIBDCP_ASSET_H
26
27 #include <string>
28 #include <list>
29 #include <boost/filesystem.hpp>
30 #include <boost/function.hpp>
31 #include <libxml++/libxml++.h>
32 #include "types.h"
33
34 namespace ASDCP {
35         struct WriterInfo;
36 }
37
38 namespace xmlpp {
39         class Element;
40 }
41
42 namespace libdcp
43 {
44
45 /** @brief Parent class for assets of DCPs
46  *
47  *  These are collections of pictures or sound.
48  */
49 class Asset
50 {
51 public:
52         /** Construct an Asset.
53          *  @param directory Directory where our XML or MXF file is.
54          *  @param file_name Name of our file within directory, or empty to make one up based on UUID.
55          */
56         Asset (boost::filesystem::path directory, boost::filesystem::path file_name = "");
57
58         virtual ~Asset() {}
59
60         /** Write details of the asset to a CPL AssetList node.
61          *  @param p Parent element.
62          */
63         virtual void write_to_cpl (xmlpp::Element* p) const = 0;
64
65         /** Write details of the asset to a PKL AssetList node.
66          *  @param p Parent node.
67          */
68         void write_to_pkl (xmlpp::Node *, bool interop) const;
69
70         /** Write details of the asset to a ASSETMAP stream.
71          *  @param s Stream.
72          */
73         void write_to_assetmap (xmlpp::Node *) const;
74
75         /** Compute the digest for this asset.  Calling this is optional: if
76          *  it is not called, the digest will be computed when required.  However,
77          *  calling this method allows the caller to see the progress of the
78          *  computation, which can be long for large assets.
79          *  @param Called with progress between 0 and 1.
80          */
81         void compute_digest (boost::function<void (float)> progress);
82
83         std::string uuid () const {
84                 return _uuid;
85         }
86
87         boost::filesystem::path path () const;
88
89         void set_directory (boost::filesystem::path d) {
90                 _directory = d;
91         }
92
93         void set_file_name (boost::filesystem::path f) {
94                 _file_name = f;
95         }
96
97         int entry_point () const {
98                 return _entry_point;
99         }
100
101         int duration () const {
102                 return _duration;
103         }
104         
105         int intrinsic_duration () const {
106                 return _intrinsic_duration;
107         }
108         
109         int edit_rate () const {
110                 return _edit_rate;
111         }
112
113         void set_entry_point (int e) {
114                 _entry_point = e;
115         }
116         
117         void set_duration (int d) {
118                 _duration = d;
119         }
120
121         void set_intrinsic_duration (int d) {
122                 _intrinsic_duration = d;
123         }
124
125         void set_edit_rate (int r) {
126                 _edit_rate = r;
127         }
128
129         virtual bool equals (boost::shared_ptr<const Asset> other, EqualityOptions opt, boost::function<void (NoteType, std::string)>) const;
130
131 protected:
132
133         /** @return Interop PKL asdcpKind for the &lt;Type&gt; tag e.g. Picture, Sound etc. */
134         virtual std::string asdcp_kind () const = 0;
135         
136         std::string digest () const;
137
138         /** Directory that our MXF or XML file is in */
139         boost::filesystem::path _directory;
140         /** Name of our MXF or XML file */
141         boost::filesystem::path _file_name;
142         /** Our UUID */
143         std::string _uuid;
144         /** The edit rate; this is normally equal to the number of video frames per second */
145         int _edit_rate;
146         /** Start point to present in frames */
147         int _entry_point;
148         /** Total length in frames */
149         int _intrinsic_duration;
150         /** Length to present in frames */
151         int _duration;
152
153 private:        
154         /** Digest of our MXF or XML file */
155         mutable std::string _digest;
156 };
157
158 }
159
160 #endif