Basic pass-through of font information when using DCP subtitles.
[dcpomatic.git] / src / lib / writer.cc
index c34a6a66d7350cd624f526b8de4b4689b2a11523..07b637d46369f3b0656f7db0af7aeeb7fc1020a5 100644 (file)
 
 */
 
-#include <fstream>
-#include <cerrno>
-#include <dcp/mono_picture_mxf.h>
-#include <dcp/stereo_picture_mxf.h>
-#include <dcp/sound_mxf.h>
-#include <dcp/sound_mxf_writer.h>
-#include <dcp/reel.h>
-#include <dcp/reel_mono_picture_asset.h>
-#include <dcp/reel_stereo_picture_asset.h>
-#include <dcp/reel_sound_asset.h>
-#include <dcp/reel_subtitle_asset.h>
-#include <dcp/dcp.h>
-#include <dcp/cpl.h>
-#include <dcp/signer.h>
 #include "writer.h"
 #include "compose.hpp"
 #include "film.h"
 #include "audio_buffers.h"
 #include "md5_digester.h"
 #include "encoded_data.h"
+#include "version.h"
+#include "font.h"
+#include <dcp/mono_picture_mxf.h>
+#include <dcp/stereo_picture_mxf.h>
+#include <dcp/sound_mxf.h>
+#include <dcp/sound_mxf_writer.h>
+#include <dcp/reel.h>
+#include <dcp/reel_mono_picture_asset.h>
+#include <dcp/reel_stereo_picture_asset.h>
+#include <dcp/reel_sound_asset.h>
+#include <dcp/reel_subtitle_asset.h>
+#include <dcp/dcp.h>
+#include <dcp/cpl.h>
+#include <dcp/signer.h>
+#include <dcp/interop_subtitle_content.h>
+#include <fstream>
+#include <cerrno>
 
 #include "i18n.h"
 
 #define LOG_GENERAL(...) _film->log()->log (String::compose (__VA_ARGS__), Log::TYPE_GENERAL);
 #define LOG_TIMING(...) _film->log()->microsecond_log (String::compose (__VA_ARGS__), Log::TYPE_TIMING);
 #define LOG_WARNING_NC(...) _film->log()->log (__VA_ARGS__, Log::TYPE_WARNING);
+#define LOG_ERROR(...) _film->log()->log (String::compose (__VA_ARGS__), Log::TYPE_ERROR);
 
 /* OS X strikes again */
 #undef set_key
@@ -60,7 +64,6 @@ using std::pair;
 using std::string;
 using std::list;
 using std::cout;
-using std::stringstream;
 using boost::shared_ptr;
 using boost::weak_ptr;
 using boost::dynamic_pointer_cast;
@@ -406,9 +409,12 @@ Writer::finish ()
        boost::system::error_code ec;
        boost::filesystem::create_hard_link (video_from, video_to, ec);
        if (ec) {
-               /* hard link failed; copy instead */
-               boost::filesystem::copy_file (video_from, video_to);
-               LOG_WARNING_NC ("Hard-link failed; fell back to copying");
+               LOG_WARNING_NC ("Hard-link failed; copying instead");
+               boost::filesystem::copy_file (video_from, video_to, ec);
+               if (ec) {
+                       LOG_ERROR ("Failed to copy video file from %1 to %2 (%3)", video_from.string(), video_to.string(), ec.message ());
+                       throw FileError (ec.message(), video_from);
+               }
        }
 
        _picture_mxf->set_file (video_to);
@@ -466,7 +472,7 @@ Writer::finish ()
                                   new dcp::ReelSubtitleAsset (
                                           _subtitle_content,
                                           dcp::Fraction (_film->video_frame_rate(), 1),
-                                          _subtitle_content->latest_subtitle_out().to_seconds() * _film->video_frame_rate(),
+                                          _picture_mxf->intrinsic_duration (),
                                           0
                                           )
                                   ));
@@ -487,7 +493,9 @@ Writer::finish ()
                _sound_mxf->hash (boost::bind (&Job::set_progress, job.get(), _1, false));
        }
 
-       dcp::XMLMetadata meta = Config::instance()->dcp_metadata ();
+       dcp::XMLMetadata meta;
+       meta.issuer = Config::instance()->dcp_issuer ();
+       meta.creator = String::compose ("DCP-o-matic %1 %2", dcpomatic_version, dcpomatic_git_commit);
        meta.set_issue_date_now ();
 
        shared_ptr<const dcp::Signer> signer;
@@ -609,9 +617,7 @@ Writer::write (PlayerSubtitles subs)
        }
        
        if (!_subtitle_content) {
-               _subtitle_content.reset (
-                       new dcp::SubtitleContent (_film->name(), _film->isdcf_metadata().subtitle_language)
-                       );
+               _subtitle_content.reset (new dcp::InteropSubtitleContent (_film->name(), _film->subtitle_language ()));
        }
        
        for (list<dcp::SubtitleString>::const_iterator i = subs.text.begin(); i != subs.text.end(); ++i) {
@@ -619,6 +625,19 @@ Writer::write (PlayerSubtitles subs)
        }
 }
 
+void
+Writer::write (list<shared_ptr<Font> > fonts)
+{
+       if (!_subtitle_content) {
+               _subtitle_content.reset (new dcp::InteropSubtitleContent (_film->name(), _film->subtitle_language ()));
+       }
+       
+       for (list<shared_ptr<Font> >::const_iterator i = fonts.begin(); i != fonts.end(); ++i) {
+               /* XXX: this LiberationSans-Regular needs to be a path to a DCP-o-matic-distributed copy */
+               _subtitle_content->add_font ((*i)->id, (*i)->file.get_value_or ("LiberationSans-Regular.ttf").leaf().string ());
+       }
+}
+
 bool
 operator< (QueueItem const & a, QueueItem const & b)
 {