2 Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
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.
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.
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.
20 #include "reel_asset.h"
22 #include "compose.hpp"
23 #include <libcxml/cxml.h>
28 using boost::shared_ptr;
29 using boost::lexical_cast;
32 ReelAsset::ReelAsset ()
33 : Object (make_uuid ())
35 , _edit_rate (Fraction (24, 1))
36 , _intrinsic_duration (0)
43 ReelAsset::ReelAsset (boost::shared_ptr<Content> content, int64_t entry_point)
44 : Object (content->id ())
46 , _edit_rate (content->edit_rate ())
47 , _intrinsic_duration (content->intrinsic_duration ())
48 , _entry_point (entry_point)
49 , _duration (_intrinsic_duration - _entry_point)
50 , _hash (make_digest (content->file (), 0))
55 ReelAsset::ReelAsset (boost::shared_ptr<const cxml::Node> node)
56 : Object (node->string_child ("Id"))
58 , _annotation_text (node->optional_string_child ("AnnotationText").get_value_or (""))
59 , _edit_rate (Fraction (node->string_child ("EditRate")))
60 , _intrinsic_duration (node->number_child<int64_t> ("IntrinsicDuration"))
61 , _entry_point (node->number_child<int64_t> ("EntryPoint"))
62 , _duration (node->number_child<int64_t> ("Duration"))
63 , _hash (node->string_child ("Hash"))
64 , _key_id (node->optional_string_child ("KeyId").get_value_or (""))
66 if (_id.length() > 9) {
68 _content.set_id (_id);
71 if (_key_id.length() > 9) {
72 _key_id = _key_id.substr (9);
77 ReelAsset::write_to_cpl (xmlpp::Node* node, Standard) const
79 pair<string, string> const attr = cpl_node_attribute ();
80 xmlpp::Element* a = node->add_child (cpl_node_name ());
81 if (!attr.first.empty ()) {
82 a->set_attribute (attr.first, attr.second);
84 a->add_child("Id")->add_child_text ("urn:uuid:" + _id);
85 a->add_child("AnnotationText")->add_child_text (_annotation_text);
86 a->add_child("EditRate")->add_child_text (String::compose ("%1 %2", _edit_rate.numerator, _edit_rate.denominator));
87 a->add_child("IntrinsicDuration")->add_child_text (lexical_cast<string> (_intrinsic_duration));
88 a->add_child("EntryPoint")->add_child_text (lexical_cast<string> (_entry_point));
89 a->add_child("Duration")->add_child_text (lexical_cast<string> (_duration));
90 if (!_key_id.empty ()) {
91 a->add_child("KeyId")->add_child_text ("urn:uuid:" + _key_id);
96 ReelAsset::cpl_node_attribute () const
98 return make_pair ("", "");