Use MXFAsset::_interop to decide on whether to write asset XML as Interop or SMPTE.
[libdcp.git] / src / reel.cc
index c8ea54ebca5be8a915857877d6328a00541c3243..ff51c025b78dd664ebd9a47e827e77b042bf42c0 100644 (file)
@@ -21,6 +21,8 @@
 #include "reel.h"
 #include "util.h"
 #include "picture_asset.h"
+#include "mono_picture_asset.h"
+#include "stereo_picture_asset.h"
 #include "sound_asset.h"
 #include "subtitle_asset.h"
 #include "kdm.h"
@@ -29,16 +31,18 @@ using std::string;
 using std::list;
 using std::cout;
 using boost::shared_ptr;
+using boost::dynamic_pointer_cast;
 using namespace libdcp;
 
 void
-Reel::write_to_cpl (xmlpp::Node* node) const
+Reel::write_to_cpl (xmlpp::Element* node) const
 {
-       xmlpp::Node* reel = node->add_child ("Reel");
+       xmlpp::Element* reel = node->add_child ("Reel");
        reel->add_child("Id")->add_child_text ("urn:uuid:" + make_uuid());
-       xmlpp::Node* asset_list = reel->add_child ("AssetList");
+       xmlpp::Element* asset_list = reel->add_child ("AssetList");
        
-       if (_main_picture) {
+       if (_main_picture && dynamic_pointer_cast<MonoPictureAsset> (_main_picture)) {
+               /* Mono pictures come before other stuff... */
                _main_picture->write_to_cpl (asset_list);
        }
 
@@ -49,6 +53,11 @@ Reel::write_to_cpl (xmlpp::Node* node) const
        if (_main_subtitle) {
                _main_subtitle->write_to_cpl (asset_list);
        }
+
+       if (_main_picture && dynamic_pointer_cast<StereoPictureAsset> (_main_picture)) {
+               /* ... but stereo pictures must come after */
+               _main_picture->write_to_cpl (asset_list);
+       }
 }
        
 bool
@@ -93,14 +102,25 @@ Reel::encrypted () const
 void
 Reel::add_kdm (KDM const & kdm)
 {
-       list<KDMCipher> ciphers = kdm.ciphers ();
+       list<KDMKey> keys = kdm.keys ();
        
-       for (list<KDMCipher>::iterator i = ciphers.begin(); i != ciphers.end(); ++i) {
+       for (list<KDMKey>::iterator i = keys.begin(); i != keys.end(); ++i) {
                if (i->key_id() == _main_picture->key_id()) {
-                       _main_picture->set_kdm_cipher (*i);
+                       _main_picture->set_key (i->key ());
                }
                if (i->key_id() == _main_sound->key_id()) {
-                       _main_sound->set_kdm_cipher (*i);
+                       _main_sound->set_key (i->key ());
                }
        }
 }
+
+void
+Reel::set_mxf_keys (Key key)
+{
+       _main_picture->set_key (key);
+       if (_main_sound) {
+               _main_sound->set_key (key);
+       }
+
+       /* XXX: subtitle asset? */
+}