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"
32 #include <libxml++/nodes/element.h>
37 using boost::shared_ptr;
38 using boost::dynamic_pointer_cast;
41 Reel::Reel (boost::shared_ptr<const cxml::Node> node)
42 : Object (node->string_child ("Id"))
44 shared_ptr<cxml::Node> asset_list = node->node_child ("AssetList");
46 shared_ptr<cxml::Node> main_picture = asset_list->optional_node_child ("MainPicture");
48 _main_picture.reset (new ReelMonoPictureAsset (main_picture));
51 shared_ptr<cxml::Node> main_stereoscopic_picture = asset_list->optional_node_child ("MainStereoscopicPicture");
52 if (main_stereoscopic_picture) {
53 _main_picture.reset (new ReelStereoPictureAsset (main_stereoscopic_picture));
56 shared_ptr<cxml::Node> main_sound = asset_list->optional_node_child ("MainSound");
58 _main_sound.reset (new ReelSoundAsset (main_sound));
61 shared_ptr<cxml::Node> main_subtitle = asset_list->optional_node_child ("MainSubtitle");
63 _main_subtitle.reset (new ReelSubtitleAsset (main_subtitle));
66 node->ignore_child ("AnnotationText");
71 Reel::write_to_cpl (xmlpp::Element* node, Standard standard) const
73 xmlpp::Element* reel = node->add_child ("Reel");
74 reel->add_child("Id")->add_child_text ("urn:uuid:" + make_uuid());
75 xmlpp::Element* asset_list = reel->add_child ("AssetList");
77 if (_main_picture && dynamic_pointer_cast<ReelMonoPictureAsset> (_main_picture)) {
78 /* Mono pictures come before other stuff... */
79 _main_picture->write_to_cpl (asset_list, standard);
83 _main_sound->write_to_cpl (asset_list, standard);
87 _main_subtitle->write_to_cpl (asset_list, standard);
90 if (_main_picture && dynamic_pointer_cast<ReelStereoPictureAsset> (_main_picture)) {
91 /* ... but stereo pictures must come after */
92 _main_picture->write_to_cpl (asset_list, standard);
97 Reel::equals (boost::shared_ptr<const Reel> other, EqualityOptions opt, boost::function<void (NoteType, string)> note) const
99 if ((_main_picture && !other->_main_picture) || (!_main_picture && other->_main_picture)) {
100 note (ERROR, "reel has different assets");
104 if (_main_picture && !_main_picture->equals (other->_main_picture, opt, note)) {
108 if ((_main_sound && !other->_main_sound) || (!_main_sound && other->_main_sound)) {
109 note (ERROR, "reel has different assets");
113 if (_main_sound && !_main_sound->equals (other->_main_sound, opt, note)) {
117 if ((_main_subtitle && !other->_main_subtitle) || (!_main_subtitle && other->_main_subtitle)) {
118 note (ERROR, "reel has different assets");
122 if (_main_subtitle && !_main_subtitle->equals (other->_main_subtitle, opt, note)) {
130 Reel::encrypted () const
132 return ((_main_picture && _main_picture->encrypted ()) || (_main_sound && _main_sound->encrypted ()));
136 Reel::add (KDM const & kdm)
138 list<KDMKey> keys = kdm.keys ();
140 for (list<KDMKey>::iterator i = keys.begin(); i != keys.end(); ++i) {
141 if (i->key_id() == _main_picture->key_id()) {
142 _main_picture->mxf()->set_key (i->key ());
144 if (i->key_id() == _main_sound->key_id()) {
145 _main_sound->mxf()->set_key (i->key ());
151 Reel::set_mxf_keys (Key key)
153 _main_picture->mxf()->set_key (key);
155 _main_sound->mxf()->set_key (key);
158 /* XXX: subtitle asset? */
162 Reel::add (shared_ptr<ReelAsset> asset)
164 shared_ptr<ReelPictureAsset> p = dynamic_pointer_cast<ReelPictureAsset> (asset);
165 shared_ptr<ReelSoundAsset> so = dynamic_pointer_cast<ReelSoundAsset> (asset);
166 shared_ptr<ReelSubtitleAsset> su = dynamic_pointer_cast<ReelSubtitleAsset> (asset);
177 Reel::resolve_refs (list<shared_ptr<Object> > objects)
180 _main_picture->content().resolve (objects);
184 _main_sound->content().resolve (objects);
187 if (_main_subtitle) {
188 _main_subtitle->content().resolve (objects);