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.
22 #include "picture_mxf.h"
23 #include "mono_picture_mxf.h"
24 #include "stereo_picture_mxf.h"
25 #include "sound_mxf.h"
26 #include "subtitle_content.h"
27 #include "reel_mono_picture_asset.h"
28 #include "reel_stereo_picture_asset.h"
29 #include "reel_sound_asset.h"
30 #include "reel_subtitle_asset.h"
31 #include "decrypted_kdm_key.h"
32 #include "decrypted_kdm.h"
33 #include <libxml++/nodes/element.h>
38 using boost::shared_ptr;
39 using boost::dynamic_pointer_cast;
42 Reel::Reel (boost::shared_ptr<const cxml::Node> node)
43 : Object (node->string_child ("Id"))
45 shared_ptr<cxml::Node> asset_list = node->node_child ("AssetList");
47 shared_ptr<cxml::Node> main_picture = asset_list->optional_node_child ("MainPicture");
49 _main_picture.reset (new ReelMonoPictureAsset (main_picture));
52 shared_ptr<cxml::Node> main_stereoscopic_picture = asset_list->optional_node_child ("MainStereoscopicPicture");
53 if (main_stereoscopic_picture) {
54 _main_picture.reset (new ReelStereoPictureAsset (main_stereoscopic_picture));
57 shared_ptr<cxml::Node> main_sound = asset_list->optional_node_child ("MainSound");
59 _main_sound.reset (new ReelSoundAsset (main_sound));
62 shared_ptr<cxml::Node> main_subtitle = asset_list->optional_node_child ("MainSubtitle");
64 _main_subtitle.reset (new ReelSubtitleAsset (main_subtitle));
67 node->ignore_child ("AnnotationText");
72 Reel::write_to_cpl (xmlpp::Element* node, Standard standard) const
74 xmlpp::Element* reel = node->add_child ("Reel");
75 reel->add_child("Id")->add_child_text ("urn:uuid:" + make_uuid());
76 xmlpp::Element* asset_list = reel->add_child ("AssetList");
78 if (_main_picture && dynamic_pointer_cast<ReelMonoPictureAsset> (_main_picture)) {
79 /* Mono pictures come before other stuff... */
80 _main_picture->write_to_cpl (asset_list, standard);
84 _main_sound->write_to_cpl (asset_list, standard);
88 _main_subtitle->write_to_cpl (asset_list, standard);
91 if (_main_picture && dynamic_pointer_cast<ReelStereoPictureAsset> (_main_picture)) {
92 /* ... but stereo pictures must come after */
93 _main_picture->write_to_cpl (asset_list, standard);
98 Reel::equals (boost::shared_ptr<const Reel> other, EqualityOptions opt, boost::function<void (NoteType, string)> note) const
100 if ((_main_picture && !other->_main_picture) || (!_main_picture && other->_main_picture)) {
101 note (ERROR, "reel has different assets");
105 if (_main_picture && !_main_picture->equals (other->_main_picture, opt, note)) {
109 if ((_main_sound && !other->_main_sound) || (!_main_sound && other->_main_sound)) {
110 note (ERROR, "reel has different assets");
114 if (_main_sound && !_main_sound->equals (other->_main_sound, opt, note)) {
118 if ((_main_subtitle && !other->_main_subtitle) || (!_main_subtitle && other->_main_subtitle)) {
119 note (ERROR, "reel has different assets");
123 if (_main_subtitle && !_main_subtitle->equals (other->_main_subtitle, opt, note)) {
131 Reel::encrypted () const
133 return ((_main_picture && _main_picture->encrypted ()) || (_main_sound && _main_sound->encrypted ()));
137 Reel::add (DecryptedKDM const & kdm)
139 list<DecryptedKDMKey> keys = kdm.keys ();
141 for (list<DecryptedKDMKey>::iterator i = keys.begin(); i != keys.end(); ++i) {
142 if (i->id() == _main_picture->key_id()) {
143 _main_picture->mxf()->set_key (i->key ());
145 if (i->id() == _main_sound->key_id()) {
146 _main_sound->mxf()->set_key (i->key ());
152 Reel::set_mxf_keys (Key key)
154 _main_picture->mxf()->set_key (key);
156 _main_sound->mxf()->set_key (key);
159 /* XXX: subtitle asset? */
163 Reel::add (shared_ptr<ReelAsset> asset)
165 shared_ptr<ReelPictureAsset> p = dynamic_pointer_cast<ReelPictureAsset> (asset);
166 shared_ptr<ReelSoundAsset> so = dynamic_pointer_cast<ReelSoundAsset> (asset);
167 shared_ptr<ReelSubtitleAsset> su = dynamic_pointer_cast<ReelSubtitleAsset> (asset);
178 Reel::resolve_refs (list<shared_ptr<Object> > objects)
181 _main_picture->content().resolve (objects);
185 _main_sound->content().resolve (objects);
188 if (_main_subtitle) {
189 _main_subtitle->content().resolve (objects);