summaryrefslogtreecommitdiff
path: root/src/asset_instance.cc
blob: 6892ea8fb6aa443b588ec7d19f57d380d47e3012 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
    Copyright (C) 2012-2013 Carl Hetherington <cth@carlh.net>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/

#include <libcxml/cxml.h>
#include "asset_instance.h"

using std::string;
using boost::shared_ptr;
using namespace libdcp;

AssetInstance::AssetInstance (shared_ptr<cxml::Node> node)
{
	id = node->string_child ("Id");
	annotation_text = node->optional_string_child ("AnnotationText").get_value_or ("");
	edit_rate = Fraction (node->string_child ("EditRate"));
	intrinsic_duration = node->number_child<int64_t> ("IntrinsicDuration");
	entry_point = node->number_child<int64_t> ("EntryPoint");
	duration = node->number_child<int64_t> ("Duration");
	frame_rate = Fraction (node->string_child ("FrameRate"));
	key_id = node->optional_string_child ("KeyId").get_value_or ("");

	node->ignore_child ("Hash");
	node->ignore_child ("ScreenAspectRatio");
	node->ignore_child ("Language");

	node->done ();
}

void
AssetInstance::write_to_cpl (xmlpp::Element* node, bool interop) const
{
	pair<string, string> const attr = cpl_node_attribute (interop);
	xmlpp::Element* a = node->add_child (cpl_node_name ());
	if (!attr.first.empty ()) {
		a->set_attribute (attr.first, attr.second);
	}
	a->add_child ("Id")->add_child_text ("urn:uuid:" + _uuid);
	a->add_child ("AnnotationText")->add_child_text (_file_name);
	a->add_child ("EditRate")->add_child_text (lexical_cast<string> (_edit_rate) + " 1");
	a->add_child ("IntrinsicDuration")->add_child_text (lexical_cast<string> (_intrinsic_duration));
	a->add_child ("EntryPoint")->add_child_text (lexical_cast<string> (_entry_point));
	a->add_child ("Duration")->add_child_text (lexical_cast<string> (_duration));
	if (_encrypted) {
		a->add_child("KeyId")->add_child_text ("urn:uuid:" + _key_id);
	}
}

bool
AssetInstance::equals (shared_ptr<const AssetInstance> other, EqualityOptions opt, boost::function<void (NoteType, string)> note) const
{
	if (id != other->id) {
		note (ERROR, "ids differ");
		return false;
	}

	/* XXX: to do */
	std::string annotation_text;

	if (edit_rate != other->edit_rate) {
		note (ERROR, "asset edit rates differ");
		return false;
	}
	
	if (intrinsic_duration != other->intrinsic_duration) {
		note (ERROR, "asset intrinsic durations differ");
	}

	if (duration != other->duration) {
		note (ERROR, "asset durations differ");
	}

	Fraction edit_rate;
	/** Duration of the whole thing */
	int64_t intrinsic_duration;
	/** Start point in frames */
	int64_t entry_point;
	/** Duration that will actually play */
	int64_t duration;
	Fraction frame_rate;
	std::string key_id;
	

	shared_ptr<const MXFAsset> other_mxf = dynamic_pointer_cast<const MXFAsset> (other);
	if (!other_mxf) {
		note (ERROR, "comparing an MXF asset with a non-MXF asset");
		return false;
	}
	
	if (_file_name != other_mxf->_file_name) {
		note (ERROR, "MXF names differ");
		if (!opt.mxf_names_can_differ) {
			return false;
		}
	}
	
	return true;

}