e6e0fff53efcfaa078a6d695000dfdf71715c895
[libdcp.git] / src / reel_asset.h
1 /*
2     Copyright (C) 2014 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_REEL_ASSET_H
21 #define LIBDCP_REEL_ASSET_H
22
23 #include "object.h"
24 #include "util.h"
25 #include "ref.h"
26 #include <boost/shared_ptr.hpp>
27
28 namespace cxml {
29         class Node;
30 }
31
32 namespace xmlpp {
33         class Node;
34 }
35
36 namespace dcp {
37
38 class Content;
39
40 /** @class ReelAsset
41  *  @brief An entry in a &lt;Reel&gt; which refers to a use of a piece of content.
42  *
43  *  This class encapsulates the XML that exists in a &lt;Reel&gt; to say
44  *  that a piece of content is used in this reel.  It does not
45  *  describe the content itself (but links to a Content object which does).
46  */
47 class ReelAsset : public Object
48 {
49 public:
50         ReelAsset ();
51         ReelAsset (boost::shared_ptr<Content> content, int64_t entry_point);
52         ReelAsset (boost::shared_ptr<const cxml::Node>);
53
54         virtual void write_to_cpl (xmlpp::Node* node, Standard standard) const;
55
56         virtual bool equals (
57                 boost::shared_ptr<const ReelAsset>,
58                 EqualityOptions,
59                 boost::function<void (NoteType, std::string)>)
60                 const {
61                 
62                 return false;
63         }
64
65         /** @return a Ref to our actual content */
66         Ref<Content>& content () {
67                 return _content;
68         }
69
70         /** @return true if a KeyId is specified for this asset, implying
71          *  that its content is encrypted.
72          */
73         bool encrypted () const {
74                 return !_key_id.empty ();
75         }
76
77         int64_t duration () const {
78                 return _duration;
79         }
80
81         /** @return Key ID to describe the key that encrypts this asset's;
82          *  content.
83          */
84         std::string key_id () const {
85                 return _key_id;
86         }
87
88 protected:
89         /** @return the node name that this asset uses in the CPL's &lt;Reel&gt; node
90          *  e.g. MainPicture, MainSound etc.
91          */
92         virtual std::string cpl_node_name () const = 0;
93
94         /** @return Any attribute that should be used on the asset's node in the
95          *  CPL.
96          */
97         virtual std::pair<std::string, std::string> cpl_node_attribute () const;
98
99         /** Reference to the content (MXF or XML file) that this reel entry
100          *  applies to.
101          */
102         Ref<Content> _content;
103
104 private:
105         
106         std::string _annotation_text; ///< The &lt;AnnotationText&gt; from the reel's entry for this asset
107         Fraction _edit_rate;          ///< The &lt;EditRate&gt; from the reel's entry for this asset
108         int64_t _intrinsic_duration;  ///< The &lt;IntrinsicDuration&gt; from the reel's entry for this asset
109         int64_t _entry_point;         ///< The &lt;EntryPoint&gt; from the reel's entry for this asset
110         int64_t _duration;            ///< The &lt;Duration&gt; from the reel's entry for this asset
111         std::string _hash;            ///< The &lt;Hash&gt; from the reel's entry for this asset
112         std::string _key_id;          ///< The &lt;KeyId&gt; from the reel's entry for this asset, or empty if there isn't one
113 };
114
115 }
116
117 #endif