Make Writer take an output DCP path rather than getting it from the
authorCarl Hetherington <cth@carlh.net>
Sun, 6 Dec 2020 23:08:33 +0000 (00:08 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 8 Dec 2020 13:09:02 +0000 (14:09 +0100)
film itself.

src/lib/dcp_encoder.cc
src/lib/reel_writer.cc
src/lib/reel_writer.h
src/lib/writer.cc
src/lib/writer.h

index 345e5511c41bc6ec73ec0b484c941596525c3bb4..1c5b00dd45e6c54d03a9d0407565f0158f670d98 100644 (file)
@@ -125,7 +125,7 @@ DCPEncoder::go ()
 
        _finishing = true;
        _j2k_encoder->end ();
-       _writer->finish ();
+       _writer->finish (_film->dir(_film->dcp_name()));
 }
 
 void
index c1c002d3025a994c8d972e19a386127e800f01e0..e12628c74ad24ac6f6596b035150591fa1bfc289 100644 (file)
@@ -347,7 +347,7 @@ ReelWriter::repeat_write (Frame frame, Eyes eyes)
 }
 
 void
-ReelWriter::finish ()
+ReelWriter::finish (boost::filesystem::path output_dcp)
 {
        if (_picture_asset_writer && !_picture_asset_writer->finalize ()) {
                /* Nothing was written to the picture asset */
@@ -364,8 +364,7 @@ ReelWriter::finish ()
        if (_picture_asset) {
                DCPOMATIC_ASSERT (_picture_asset->file());
                boost::filesystem::path video_from = _picture_asset->file().get();
-               boost::filesystem::path video_to;
-               video_to /= film()->dir(film()->dcp_name());
+               boost::filesystem::path video_to = output_dcp;
                video_to /= video_asset_filename (_picture_asset, _reel_index, _reel_count, _content_summary);
                /* There may be an existing "to" file if we are recreating a DCP in the same place without
                   changing any video.
@@ -399,8 +398,7 @@ ReelWriter::finish ()
 
        /* Move the audio asset into the DCP */
        if (_sound_asset) {
-               boost::filesystem::path audio_to;
-               audio_to /= film()->dir(film()->dcp_name ());
+               boost::filesystem::path audio_to = output_dcp;
                string const aaf = audio_asset_filename (_sound_asset, _reel_index, _reel_count, _content_summary);
                audio_to /= aaf;
 
@@ -417,8 +415,7 @@ ReelWriter::finish ()
 
        if (_atmos_asset) {
                _atmos_asset_writer->finalize ();
-               boost::filesystem::path atmos_to;
-               atmos_to /= film()->dir(film()->dcp_name());
+               boost::filesystem::path atmos_to = output_dcp;
                string const aaf = atmos_asset_filename (_atmos_asset, _reel_index, _reel_count, _content_summary);
                atmos_to /= aaf;
 
@@ -443,7 +440,8 @@ maybe_add_text (
        list<ReferencedReelAsset> const & refs,
        list<shared_ptr<Font> > const & fonts,
        shared_ptr<const Film> film,
-       DCPTimePeriod period
+       DCPTimePeriod period,
+       boost::filesystem::path output_dcp
        )
 {
        Frame const period_duration = period.duration().frames_round(film->video_frame_rate());
@@ -457,7 +455,7 @@ maybe_add_text (
                }
 
                if (dynamic_pointer_cast<dcp::InteropSubtitleAsset> (asset)) {
-                       boost::filesystem::path directory = film->dir (film->dcp_name ()) / asset->id ();
+                       boost::filesystem::path directory = output_dcp / asset->id ();
                        boost::filesystem::create_directories (directory);
                        asset->write (directory / ("sub_" + asset->id() + ".xml"));
                } else {
@@ -469,7 +467,7 @@ maybe_add_text (
                        dynamic_pointer_cast<dcp::SMPTESubtitleAsset>(asset)->set_intrinsic_duration (picture_duration);
 
                        asset->write (
-                               film->dir(film->dcp_name()) / ("sub_" + asset->id() + ".mxf")
+                               output_dcp / ("sub_" + asset->id() + ".mxf")
                                );
                }
 
@@ -607,16 +605,24 @@ ReelWriter::create_reel_sound (shared_ptr<dcp::Reel> reel, list<ReferencedReelAs
 
 
 void
-ReelWriter::create_reel_text (shared_ptr<dcp::Reel> reel, list<ReferencedReelAsset> const & refs, list<shared_ptr<Font> > const& fonts, int64_t duration) const
+ReelWriter::create_reel_text (
+       shared_ptr<dcp::Reel> reel,
+       list<ReferencedReelAsset> const & refs,
+       list<shared_ptr<Font> > const& fonts,
+       int64_t duration,
+       boost::filesystem::path output_dcp
+       ) const
 {
-       shared_ptr<dcp::ReelSubtitleAsset> subtitle = maybe_add_text<dcp::ReelSubtitleAsset> (_subtitle_asset, duration, reel, refs, fonts, film(), _period);
+       shared_ptr<dcp::ReelSubtitleAsset> subtitle = maybe_add_text<dcp::ReelSubtitleAsset> (
+               _subtitle_asset, duration, reel, refs, fonts, film(), _period, output_dcp
+               );
        if (subtitle && !film()->subtitle_languages().empty()) {
                subtitle->set_language (film()->subtitle_languages().front());
        }
 
        for (map<DCPTextTrack, shared_ptr<dcp::SubtitleAsset> >::const_iterator i = _closed_caption_assets.begin(); i != _closed_caption_assets.end(); ++i) {
                shared_ptr<dcp::ReelClosedCaptionAsset> a = maybe_add_text<dcp::ReelClosedCaptionAsset> (
-                       i->second, duration, reel, refs, fonts, film(), _period
+                       i->second, duration, reel, refs, fonts, film(), _period, output_dcp
                        );
                if (a) {
                        a->set_annotation_text (i->first.name);
@@ -655,14 +661,14 @@ ReelWriter::create_reel_markers (shared_ptr<dcp::Reel> reel) const
 
 
 shared_ptr<dcp::Reel>
-ReelWriter::create_reel (list<ReferencedReelAsset> const & refs, list<shared_ptr<Font> > const & fonts)
+ReelWriter::create_reel (list<ReferencedReelAsset> const & refs, list<shared_ptr<Font> > const & fonts, boost::filesystem::path output_dcp)
 {
        LOG_GENERAL ("create_reel for %1-%2; %3 of %4", _period.from.get(), _period.to.get(), _reel_index, _reel_count);
 
        shared_ptr<dcp::Reel> reel (new dcp::Reel());
        shared_ptr<dcp::ReelPictureAsset> reel_picture_asset = create_reel_picture (reel, refs);
        create_reel_sound (reel, refs);
-       create_reel_text (reel, refs, fonts, reel_picture_asset->actual_duration());
+       create_reel_text (reel, refs, fonts, reel_picture_asset->actual_duration(), output_dcp);
        create_reel_markers (reel);
 
        if (_atmos_asset) {
index 6acf0d21a37f79b310079beaf19fff3494126037..c65364567c792f05e1ced6eabebb3963d4334530 100644 (file)
@@ -74,8 +74,10 @@ public:
        void write (PlayerText text, TextType type, boost::optional<DCPTextTrack> track, dcpomatic::DCPTimePeriod period);
        void write (boost::shared_ptr<const dcp::AtmosFrame> atmos, AtmosMetadata metadata);
 
-       void finish ();
-       boost::shared_ptr<dcp::Reel> create_reel (std::list<ReferencedReelAsset> const & refs, std::list<boost::shared_ptr<dcpomatic::Font> > const & fonts);
+       void finish (boost::filesystem::path output_dcp);
+       boost::shared_ptr<dcp::Reel> create_reel (
+               std::list<ReferencedReelAsset> const & refs, std::list<boost::shared_ptr<dcpomatic::Font> > const & fonts, boost::filesystem::path output_dcp
+               );
        void calculate_digests (boost::function<void (float)> set_progress);
 
        Frame start () const;
@@ -104,7 +106,8 @@ private:
        void create_reel_text (
                boost::shared_ptr<dcp::Reel> reel,
                std::list<ReferencedReelAsset> const & refs, std::list<boost::shared_ptr<dcpomatic::Font> > const& fonts,
-               int64_t duration
+               int64_t duration,
+               boost::filesystem::path output_dcp
                ) const;
        void create_reel_markers (boost::shared_ptr<dcp::Reel> reel) const;
 
index f7d3bcd25a31205d9e0bd1726a17307c5d0a4abf..17184918fd733da9edfed66a846a37dc5ebb9ba5 100644 (file)
@@ -517,8 +517,10 @@ Writer::terminate_thread (bool can_throw)
        }
 }
 
+
+/** @param output_dcp Path to DCP folder to write */
 void
-Writer::finish ()
+Writer::finish (boost::filesystem::path output_dcp)
 {
        if (!_thread.joinable()) {
                return;
@@ -531,12 +533,12 @@ Writer::finish ()
        LOG_GENERAL_NC ("Finishing ReelWriters");
 
        BOOST_FOREACH (ReelWriter& i, _reels) {
-               i.finish ();
+               i.finish (output_dcp);
        }
 
        LOG_GENERAL_NC ("Writing XML");
 
-       dcp::DCP dcp (film()->dir(film()->dcp_name()));
+       dcp::DCP dcp (output_dcp);
 
        shared_ptr<dcp::CPL> cpl (
                new dcp::CPL (
@@ -584,7 +586,7 @@ Writer::finish ()
        /* Add reels */
 
        BOOST_FOREACH (ReelWriter& i, _reels) {
-               cpl->add (i.create_reel (_reel_assets, _fonts));
+               cpl->add (i.create_reel(_reel_assets, _fonts, output_dcp));
        }
 
        /* Add metadata */
@@ -662,11 +664,11 @@ Writer::finish ()
                N_("Wrote %1 FULL, %2 FAKE, %3 REPEAT, %4 pushed to disk"), _full_written, _fake_written, _repeat_written, _pushed_to_disk
                );
 
-       write_cover_sheet ();
+       write_cover_sheet (output_dcp);
 }
 
 void
-Writer::write_cover_sheet ()
+Writer::write_cover_sheet (boost::filesystem::path output_dcp)
 {
        boost::filesystem::path const cover = film()->file("COVER_SHEET.txt");
        FILE* f = fopen_boost (cover, "w");
@@ -689,7 +691,7 @@ Writer::write_cover_sheet ()
 
        boost::uintmax_t size = 0;
        for (
-               boost::filesystem::recursive_directory_iterator i = boost::filesystem::recursive_directory_iterator(film()->dir(film()->dcp_name()));
+               boost::filesystem::recursive_directory_iterator i = boost::filesystem::recursive_directory_iterator(output_dcp);
                i != boost::filesystem::recursive_directory_iterator();
                ++i) {
                if (boost::filesystem::is_regular_file (i->path ())) {
index 085cd2a32d1302afc2208bb1ecf6cfdc10ea0f0c..1c290e6ca1b82d3082ace04219452f25c0e1a11f 100644 (file)
@@ -115,7 +115,7 @@ public:
        void write (std::list<boost::shared_ptr<dcpomatic::Font> > fonts);
        void write (ReferencedReelAsset asset);
        void write (boost::shared_ptr<const dcp::AtmosFrame> atmos, dcpomatic::DCPTime time, AtmosMetadata metadata);
-       void finish ();
+       void finish (boost::filesystem::path output_dcp);
 
        void set_encoder_threads (int threads);
 
@@ -125,7 +125,7 @@ private:
        bool have_sequenced_image_at_queue_head ();
        size_t video_reel (int frame) const;
        void set_digest_progress (Job* job, float progress);
-       void write_cover_sheet ();
+       void write_cover_sheet (boost::filesystem::path output_dcp);
        void calculate_referenced_digests (boost::function<void (float)> set_progress);
 
        boost::weak_ptr<Job> _job;