libdcp
reel_asset.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2022 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 
40 #include "asset.h"
41 #include "compose.hpp"
42 #include "dcp_assert.h"
43 #include "raw_convert.h"
44 #include "reel_asset.h"
45 #include "warnings.h"
46 #include <libcxml/cxml.h>
47 LIBDCP_DISABLE_WARNINGS
48 #include <libxml++/libxml++.h>
49 LIBDCP_ENABLE_WARNINGS
50 
51 
52 using std::pair;
53 using std::string;
54 using std::make_pair;
55 using std::shared_ptr;
56 using boost::optional;
57 using namespace dcp;
58 
59 
60 ReelAsset::ReelAsset (string id, Fraction edit_rate, int64_t intrinsic_duration, int64_t entry_point)
61  : Object (id)
62  , _intrinsic_duration (intrinsic_duration)
63  , _duration (intrinsic_duration - entry_point)
64  , _edit_rate (edit_rate)
65  , _entry_point (entry_point)
66 {
67  DCP_ASSERT (_entry_point <= _intrinsic_duration);
68 }
69 
70 
71 ReelAsset::ReelAsset (shared_ptr<const cxml::Node> node)
72  : Object (remove_urn_uuid (node->string_child ("Id")))
73  , _intrinsic_duration (node->number_child<int64_t> ("IntrinsicDuration"))
74  , _duration (node->optional_number_child<int64_t>("Duration"))
75  , _annotation_text (node->optional_string_child("AnnotationText"))
76  , _edit_rate (Fraction (node->string_child ("EditRate")))
77  , _entry_point (node->optional_number_child<int64_t>("EntryPoint"))
78 {
79 
80 }
81 
82 
83 xmlpp::Node*
84 ReelAsset::write_to_cpl (xmlpp::Node* node, Standard standard) const
85 {
86  auto a = node->add_child (cpl_node_name (standard));
87  auto const attr = cpl_node_attribute (standard);
88  if (!attr.first.empty ()) {
89  a->set_attribute (attr.first, attr.second);
90  }
91  auto const ns = cpl_node_namespace ();
92  if (!ns.first.empty()) {
93  a->set_namespace_declaration (ns.first, ns.second);
94  }
95  a->add_child("Id")->add_child_text ("urn:uuid:" + _id);
96  /* Empty <AnnotationText> tags cause refusal to play on some Sony SRX320 / LMT3000 systems (DoM bug #2124) */
97  if (_annotation_text && !_annotation_text->empty()) {
98  a->add_child("AnnotationText")->add_child_text(*_annotation_text);
99  }
100  a->add_child("EditRate")->add_child_text (_edit_rate.as_string());
101  a->add_child("IntrinsicDuration")->add_child_text (raw_convert<string> (_intrinsic_duration));
102  if (_entry_point) {
103  a->add_child("EntryPoint")->add_child_text(raw_convert<string>(*_entry_point));
104  }
105  if (_duration) {
106  a->add_child("Duration")->add_child_text(raw_convert<string>(*_duration));
107  }
108  return a;
109 }
110 
111 
112 pair<string, string>
114 {
115  return make_pair ("", "");
116 }
117 
118 
119 pair<string, string>
121 {
122  return make_pair ("", "");
123 }
124 
125 
126 bool
127 ReelAsset::asset_equals (shared_ptr<const ReelAsset> other, EqualityOptions opt, NoteHandler note) const
128 {
129  if (_annotation_text != other->_annotation_text) {
130  string const s = "Reel: annotation texts differ (" + _annotation_text.get_value_or("") + " vs " + other->_annotation_text.get_value_or("") + ")\n";
132  note (NoteType::ERROR, s);
133  return false;
134  } else {
135  note (NoteType::NOTE, s);
136  }
137  }
138 
139  if (_edit_rate != other->_edit_rate) {
140  note (NoteType::ERROR, "Reel: edit rates differ");
141  return false;
142  }
143 
144  if (_intrinsic_duration != other->_intrinsic_duration) {
145  note (NoteType::ERROR, String::compose ("Reel: intrinsic durations differ (%1 vs %2)", _intrinsic_duration, other->_intrinsic_duration));
146  return false;
147  }
148 
149  if (_entry_point != other->_entry_point) {
150  note (NoteType::ERROR, "Reel: entry points differ");
151  return false;
152  }
153 
154  if (_duration != other->_duration) {
155  note (NoteType::ERROR, "Reel: durations differ");
156  return false;
157  }
158 
159  return true;
160 }
161 
162 
163 int64_t
165 {
166  if (_duration) {
167  return *_duration;
168  }
169 
170  return _intrinsic_duration - _entry_point.get_value_or(0);
171 }
Asset class.
A fraction (i.e. a thing with an integer numerator and an integer denominator).
Definition: types.h:214
Some part of a DCP that has a UUID.
Definition: object.h:63
virtual std::pair< std::string, std::string > cpl_node_attribute(Standard) const
Definition: reel_asset.cc:113
virtual std::string cpl_node_name(Standard) const =0
boost::optional< int64_t > _entry_point
The <EntryPoint> from the reel's entry for this asset.
Definition: reel_asset.h:156
ReelAsset(std::string id, Fraction edit_rate, int64_t intrinsic_duration, int64_t entry_point)
Definition: reel_asset.cc:60
virtual std::pair< std::string, std::string > cpl_node_namespace() const
Definition: reel_asset.cc:120
Fraction _edit_rate
The <EditRate> from the reel's entry for this asset.
Definition: reel_asset.h:155
boost::optional< std::string > _annotation_text
The <AnnotationText> from the reel's entry for this asset.
Definition: reel_asset.h:154
int64_t actual_duration() const
Definition: reel_asset.cc:164
int64_t _intrinsic_duration
The <IntrinsicDuration> from the reel's entry for this asset.
Definition: reel_asset.h:150
boost::optional< int64_t > _duration
The <Duration> from the reel's entry for this asset, if present.
Definition: reel_asset.h:151
DCP_ASSERT macro.
Namespace for everything in libdcp.
Definition: array_data.h:50
Methods for conversion to/from string.
ReelAsset class.
A class to describe what "equality" means for a particular test.
Definition: types.h:249
bool reel_annotation_texts_can_differ
Definition: types.h:262