Different configuration of filename format for assets / metadata (since CPL/PKL files...
[dcpomatic.git] / src / lib / reel_writer.cc
index eff5c48eeede1342e2b61f2dee07abb9f3abbd74..fa2813837bf065d4f57af3f00575367dedd4f107 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
@@ -42,7 +42,6 @@
 #include <dcp/interop_subtitle_asset.h>
 #include <dcp/smpte_subtitle_asset.h>
 #include <boost/foreach.hpp>
-#include <boost/make_shared.hpp>
 
 #include "i18n.h"
 
@@ -55,20 +54,24 @@ using std::list;
 using std::string;
 using std::cout;
 using boost::shared_ptr;
-using boost::make_shared;
 using boost::optional;
 using boost::dynamic_pointer_cast;
 using dcp::Data;
 
 int const ReelWriter::_info_size = 48;
 
-ReelWriter::ReelWriter (shared_ptr<const Film> film, DCPTimePeriod period, shared_ptr<Job> job)
+ReelWriter::ReelWriter (
+       shared_ptr<const Film> film, DCPTimePeriod period, shared_ptr<Job> job, int reel_index, int reel_count, optional<string> content_summary
+       )
        : _film (film)
        , _period (period)
        , _first_nonexistant_frame (0)
        , _last_written_video_frame (-1)
        , _last_written_eyes (EYES_RIGHT)
        , _total_written_audio_frames (0)
+       , _reel_index (reel_index)
+       , _reel_count (reel_count)
+       , _content_summary (content_summary)
 {
        /* Create our picture asset in a subdirectory, named according to those
           film's parameters which affect the video output.  We will hard-link
@@ -113,7 +116,7 @@ ReelWriter::ReelWriter (shared_ptr<const Film> film, DCPTimePeriod period, share
                   of the DCP directory until the last minute.
                */
                _sound_asset_writer = _sound_asset->start_write (
-                       _film->directory() / audio_asset_filename (_sound_asset),
+                       _film->directory() / audio_asset_filename (_sound_asset, _reel_index, _reel_count, _content_summary),
                        _film->interop() ? dcp::INTEROP : dcp::SMPTE
                        );
        }
@@ -268,7 +271,7 @@ ReelWriter::finish ()
                boost::filesystem::path video_from = _picture_asset->file ();
                boost::filesystem::path video_to;
                video_to /= _film->dir (_film->dcp_name());
-               video_to /= video_asset_filename (_picture_asset);
+               video_to /= video_asset_filename (_picture_asset, _reel_index, _reel_count, _content_summary);
 
                boost::system::error_code ec;
                boost::filesystem::create_hard_link (video_from, video_to, ec);
@@ -288,13 +291,14 @@ ReelWriter::finish ()
        if (_sound_asset) {
                boost::filesystem::path audio_to;
                audio_to /= _film->dir (_film->dcp_name ());
-               audio_to /= audio_asset_filename (_sound_asset);
+               string const aaf = audio_asset_filename (_sound_asset, _reel_index, _reel_count, _content_summary);
+               audio_to /= aaf;
 
                boost::system::error_code ec;
-               boost::filesystem::rename (_film->file (audio_asset_filename (_sound_asset)), audio_to, ec);
+               boost::filesystem::rename (_film->file (aaf), audio_to, ec);
                if (ec) {
                        throw FileError (
-                               String::compose (_("could not move audio asset into the DCP (%1)"), ec.value ()), audio_asset_filename (_sound_asset)
+                               String::compose (_("could not move audio asset into the DCP (%1)"), ec.value ()), aaf
                                );
                }
 
@@ -305,7 +309,7 @@ ReelWriter::finish ()
 shared_ptr<dcp::Reel>
 ReelWriter::create_reel (list<ReferencedReelAsset> const & refs, list<shared_ptr<Font> > const & fonts)
 {
-       shared_ptr<dcp::Reel> reel = make_shared<dcp::Reel> ();
+       shared_ptr<dcp::Reel> reel (new dcp::Reel ());
 
        shared_ptr<dcp::ReelPictureAsset> reel_picture_asset;
 
@@ -330,7 +334,9 @@ ReelWriter::create_reel (list<ReferencedReelAsset> const & refs, list<shared_ptr
                }
        }
 
+       DCPOMATIC_ASSERT (reel_picture_asset);
        reel->add (reel_picture_asset);
+
        /* If we have a hash for this asset in the CPL, assume that it is correct */
        if (reel_picture_asset->hash()) {
                reel_picture_asset->asset_ref()->set_hash (reel_picture_asset->hash().get());
@@ -338,7 +344,7 @@ ReelWriter::create_reel (list<ReferencedReelAsset> const & refs, list<shared_ptr
 
        if (_sound_asset) {
                /* We have made a sound asset of our own.  Put it into the reel */
-               reel->add (make_shared<dcp::ReelSoundAsset> (_sound_asset, 0));
+               reel->add (shared_ptr<dcp::ReelSoundAsset> (new dcp::ReelSoundAsset (_sound_asset, 0)));
        } else {
                /* We don't have a sound asset of our own; hopefully we have one to reference */
                BOOST_FOREACH (ReferencedReelAsset j, refs) {
@@ -419,16 +425,14 @@ ReelWriter::create_reel (list<ReferencedReelAsset> const & refs, list<shared_ptr
 }
 
 void
-ReelWriter::calculate_digests (shared_ptr<Job> job)
+ReelWriter::calculate_digests (boost::function<void (float)> set_progress)
 {
-       job->sub (_("Computing image digest"));
        if (_picture_asset) {
-               _picture_asset->hash (boost::bind (&Job::set_progress, job.get(), _1, false));
+               _picture_asset->hash (set_progress);
        }
 
        if (_sound_asset) {
-               job->sub (_("Computing audio digest"));
-               _sound_asset->hash (boost::bind (&Job::set_progress, job.get(), _1, false));
+               _sound_asset->hash (set_progress);
        }
 }
 
@@ -462,13 +466,13 @@ ReelWriter::write (PlayerSubtitles subs)
                        lang = "Unknown";
                }
                if (_film->interop ()) {
-                       shared_ptr<dcp::InteropSubtitleAsset> s = make_shared<dcp::InteropSubtitleAsset> ();
+                       shared_ptr<dcp::InteropSubtitleAsset> s (new dcp::InteropSubtitleAsset ());
                        s->set_movie_title (_film->name ());
                        s->set_language (lang);
                        s->set_reel_number ("1");
                        _subtitle_asset = s;
                } else {
-                       shared_ptr<dcp::SMPTESubtitleAsset> s = make_shared<dcp::SMPTESubtitleAsset> ();
+                       shared_ptr<dcp::SMPTESubtitleAsset> s (new dcp::SMPTESubtitleAsset ());
                        s->set_content_title_text (_film->name ());
                        s->set_language (lang);
                        s->set_edit_rate (dcp::Fraction (_film->video_frame_rate (), 1));