Merge master.
[dcpomatic.git] / src / lib / writer.cc
index 06acaa1f63109162c53521a55c513396f2096e39..7258826ba1774f5a9fd3e32656bb32a2a761edd3 100644 (file)
 #include <libdcp/sound_asset.h>
 #include <libdcp/picture_frame.h>
 #include <libdcp/reel.h>
+#include <libdcp/dcp.h>
 #include "writer.h"
 #include "compose.hpp"
 #include "film.h"
 #include "format.h"
 #include "log.h"
 #include "dcp_video_frame.h"
+#include "dcp_content_type.h"
+#include "player.h"
+#include "audio_mapping.h"
 
 #include "i18n.h"
 
@@ -74,16 +78,14 @@ Writer::Writer (shared_ptr<Film> f)
 
        _picture_asset_writer = _picture_asset->start_write (_first_nonexistant_frame > 0);
 
-       AudioMapping m (_film->audio_channels ());
-       
-       if (m.dcp_channels() > 0) {
+       if (_film->audio_channels() > 0) {
                _sound_asset.reset (
                        new libdcp::SoundAsset (
                                _film->dir (_film->dcp_name()),
                                N_("audio.mxf"),
                                _film->dcp_frame_rate (),
-                               m.dcp_channels (),
-                               dcp_audio_sample_rate (_film->audio_stream()->sample_rate())
+                               _film->audio_mapping().dcp_channels (),
+                               dcp_audio_sample_rate (_film->audio_frame_rate())
                                )
                        );
 
@@ -273,8 +275,14 @@ Writer::finish ()
        boost::filesystem::path to;
        to /= _film->dir (_film->dcp_name());
        to /= N_("video.mxf");
-       
-       boost::filesystem::create_hard_link (from, to);
+
+       boost::system::error_code ec;
+       boost::filesystem::create_hard_link (from, to, ec);
+       if (ec) {
+               /* hard link failed; copy instead */
+               boost::filesystem::copy_file (from, to);
+               _film->log()->log ("Hard-link failed; fell back to copying");
+       }
 
        /* And update the asset */