Fix build on OS X.
[libdcp.git] / src / cpl.cc
index 4c4d2e756adaea268c197f65ef167752d3f85195..29214ca6b4c9f3458a485f837c1e3cd3dcba8184 100644 (file)
 
 */
 
-#include <fstream>
 #include <libxml/parser.h>
 #include "cpl.h"
 #include "parse/cpl.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 "parse/asset_map.h"
@@ -34,7 +34,6 @@
 
 using std::string;
 using std::stringstream;
-using std::ofstream;
 using std::ostream;
 using std::list;
 using std::pair;
@@ -107,15 +106,13 @@ CPL::CPL (boost::filesystem::path directory, string file, list<PathAssetMap> ass
 
                if (!(*i)->asset_list->main_stereoscopic_picture && p->edit_rate == p->frame_rate) {
 
-                       pair<string, shared_ptr<const parse::AssetMapAsset> > asset = asset_from_id (asset_maps, p->id);
-
                        try {
-                               picture.reset (new MonoPictureAsset (
-                                                      asset.first,
-                                                      asset.second->chunks.front()->path
-                                                      )
-                                       );
+                               pair<string, shared_ptr<const parse::AssetMapAsset> > asset = asset_from_id (asset_maps, p->id);
+
+                               picture.reset (new MonoPictureAsset (asset.first, asset.second->chunks.front()->path));
 
+                               picture->read ();
+                               picture->set_edit_rate (_fps);
                                picture->set_entry_point (p->entry_point);
                                picture->set_duration (p->duration);
                                if (p->key_id.length() > 9) {
@@ -132,14 +129,10 @@ CPL::CPL (boost::filesystem::path directory, string file, list<PathAssetMap> ass
                        try {
                                pair<string, shared_ptr<const parse::AssetMapAsset> > asset = asset_from_id (asset_maps, p->id);
 
-                               picture.reset (new StereoPictureAsset (
-                                                      asset.first,
-                                                      asset.second->chunks.front()->path,
-                                                      _fps,
-                                                      p->duration
-                                                      )
-                                       );
+                               picture.reset (new StereoPictureAsset (asset.first, asset.second->chunks.front()->path));
 
+                               picture->read ();
+                               picture->set_edit_rate (_fps);
                                picture->set_entry_point (p->entry_point);
                                picture->set_duration (p->duration);
                                if (p->key_id.length() > 9) {
@@ -160,14 +153,10 @@ CPL::CPL (boost::filesystem::path directory, string file, list<PathAssetMap> ass
                        try {
                                pair<string, shared_ptr<const parse::AssetMapAsset> > asset = asset_from_id (asset_maps, (*i)->asset_list->main_sound->id);
                        
-                               sound.reset (new SoundAsset (
-                                                    asset.first,
-                                                    asset.second->chunks.front()->path
-                                                    )
-                                       );
-
+                               sound.reset (new SoundAsset (asset.first, asset.second->chunks.front()->path));
                                shared_ptr<parse::MainSound> s = (*i)->asset_list->main_sound;
 
+                               sound->read ();
                                sound->set_entry_point (s->entry_point);
                                sound->set_duration (s->duration);
                                if (s->key_id.length() > 9) {
@@ -185,11 +174,7 @@ CPL::CPL (boost::filesystem::path directory, string file, list<PathAssetMap> ass
                        
                        pair<string, shared_ptr<const parse::AssetMapAsset> > asset = asset_from_id (asset_maps, (*i)->asset_list->main_subtitle->id);
 
-                       subtitle.reset (new SubtitleAsset (
-                                               asset.first,
-                                               asset.second->chunks.front()->path
-                                               )
-                               );
+                       subtitle.reset (new SubtitleAsset (asset.first, asset.second->chunks.front()->path));
 
                        subtitle->set_entry_point ((*i)->asset_list->main_subtitle->entry_point);
                        subtitle->set_duration ((*i)->asset_list->main_subtitle->duration);
@@ -250,7 +235,8 @@ CPL::write_xml (bool interop, XMLMetadata const & metadata, shared_ptr<const Sig
                signer->sign (root, interop);
        }
 
-       doc.write_to_file_formatted (p.string (), "UTF-8");
+       /* This must not be the _formatted version otherwise signature digests will be wrong */
+       doc.write_to_file (p.string (), "UTF-8");
 
        _digest = make_digest (p.string (), 0);
        _length = boost::filesystem::file_size (p.string ());
@@ -377,3 +363,11 @@ CPL::asset_from_id (list<PathAssetMap> asset_maps, string id) const
 
        return make_pair ("", shared_ptr<const parse::AssetMapAsset> ());
 }
+
+void
+CPL::set_mxf_keys (Key key)
+{
+       for (list<shared_ptr<Reel> >::const_iterator i = _reels.begin(); i != _reels.end(); ++i) {
+               (*i)->set_mxf_keys (key);
+       }
+}