Fix missing version string when Popen communicate returns byte strings.
[libdcp.git] / src / reel_asset.h
1 /*
2     Copyright (C) 2014-2015 Carl Hetherington <cth@carlh.net>
3
4     This file is part of libdcp.
5
6     libdcp is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     libdcp is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with libdcp.  If not, see <http://www.gnu.org/licenses/>.
18
19     In addition, as a special exception, the copyright holders give
20     permission to link the code of portions of this program with the
21     OpenSSL library under certain conditions as described in each
22     individual source file, and distribute linked combinations
23     including the two.
24
25     You must obey the GNU General Public License in all respects
26     for all of the code used other than OpenSSL.  If you modify
27     file(s) with this exception, you may extend this exception to your
28     version of the file(s), but you are not obligated to do so.  If you
29     do not wish to do so, delete this exception statement from your
30     version.  If you delete this exception statement from all source
31     files in the program, then also delete it here.
32 */
33
34 /** @file  src/reel_asset.h
35  *  @brief ReelAsset class.
36  */
37
38 #ifndef LIBDCP_REEL_ASSET_H
39 #define LIBDCP_REEL_ASSET_H
40
41 #include "object.h"
42 #include "util.h"
43 #include "ref.h"
44 #include <boost/shared_ptr.hpp>
45
46 namespace cxml {
47         class Node;
48 }
49
50 namespace xmlpp {
51         class Node;
52 }
53
54 namespace dcp {
55
56 class Asset;
57
58 /** @class ReelAsset
59  *  @brief An entry in a &lt;Reel&gt; which refers to a use of a piece of content.
60  *
61  *  This class encapsulates the XML that exists in a &lt;Reel&gt; to say
62  *  that a piece of content is used in this reel.  It does not
63  *  describe the content itself (but links to an Asset object which does).
64  */
65 class ReelAsset : public Object
66 {
67 public:
68         ReelAsset ();
69         ReelAsset (boost::shared_ptr<Asset> asset, Fraction edit_rate, int64_t intrinsic_duration, int64_t entry_point);
70         explicit ReelAsset (boost::shared_ptr<const cxml::Node>);
71
72         virtual xmlpp::Node* write_to_cpl (xmlpp::Node* node, Standard standard) const;
73         virtual bool equals (boost::shared_ptr<const ReelAsset>, EqualityOptions, NoteHandler) const;
74
75         /** @return a Ref to our actual asset */
76         Ref const & asset_ref () const {
77                 return _asset_ref;
78         }
79
80         /** @return a Ref to our actual asset */
81         Ref & asset_ref () {
82                 return _asset_ref;
83         }
84
85         Fraction edit_rate () const {
86                 return _edit_rate;
87         }
88
89         int64_t intrinsic_duration () const {
90                 return _intrinsic_duration;
91         }
92
93         void set_entry_point (int64_t e) {
94                 _entry_point = e;
95         }
96
97         int64_t entry_point () const {
98                 return _entry_point;
99         }
100
101         void set_duration (int64_t d) {
102                 _duration = d;
103         }
104
105         int64_t duration () const {
106                 return _duration;
107         }
108
109         /** @return the asset's hash, if this ReelAsset has been created from one,
110          *  otherwise the hash written to the CPL for this asset (if present).
111          */
112         boost::optional<std::string> hash () const {
113                 return _hash;
114         }
115
116         std::string annotation_text () const {
117                 return _annotation_text;
118         }
119
120         void set_annotation_text (std::string at) {
121                 _annotation_text = at;
122         }
123
124 protected:
125
126         template <class T>
127         boost::shared_ptr<T> asset_of_type () const {
128                 return boost::dynamic_pointer_cast<T> (_asset_ref.asset ());
129         }
130
131         template <class T>
132         boost::shared_ptr<T> asset_of_type () {
133                 return boost::dynamic_pointer_cast<T> (_asset_ref.asset ());
134         }
135
136         /** @return the node name that this asset uses in the CPL's &lt;Reel&gt; node
137          *  e.g. MainPicture, MainSound etc.
138          */
139         virtual std::string cpl_node_name (Standard) const = 0;
140
141         /** @return Any attribute that should be used on the asset's node in the CPL */
142         virtual std::pair<std::string, std::string> cpl_node_attribute (Standard) const;
143
144         /** @return Any namespace that should be used on the asset's node in the CPL */
145         virtual std::pair<std::string, std::string> cpl_node_namespace (Standard) const;
146
147         /** Reference to the asset (MXF or XML file) that this reel entry
148          *  applies to.
149          */
150         Ref _asset_ref;
151
152 private:
153         std::string _annotation_text; ///< The &lt;AnnotationText&gt; from the reel's entry for this asset
154         Fraction _edit_rate;          ///< The &lt;EditRate&gt; from the reel's entry for this asset
155         int64_t _intrinsic_duration;  ///< The &lt;IntrinsicDuration&gt; from the reel's entry for this asset
156         int64_t _entry_point;         ///< The &lt;EntryPoint&gt; from the reel's entry for this asset
157         int64_t _duration;            ///< The &lt;Duration&gt; from the reel's entry for this asset
158         /** Either our asset's computed hash or the hash read in from the CPL, if it's present */
159         boost::optional<std::string> _hash;
160 };
161
162 }
163
164 #endif