Move digest calculation to a separate method.
authorCarl Hetherington <cth@carlh.net>
Tue, 20 Apr 2021 17:52:44 +0000 (19:52 +0200)
committerCarl Hetherington <cth@carlh.net>
Tue, 20 Apr 2021 22:52:07 +0000 (00:52 +0200)
src/lib/writer.cc
src/lib/writer.h

index 7208402e45704002fc3f635bd2d3e16755ff47b4..8fa9fbbca8b76893e913f63ac866ec5964095e42 100644 (file)
@@ -535,36 +535,9 @@ Writer::terminate_thread (bool can_throw)
 }
 
 
-/** @param output_dcp Path to DCP folder to write */
 void
-Writer::finish (boost::filesystem::path output_dcp)
+Writer::calculate_digests ()
 {
-       if (_thread.joinable()) {
-               LOG_GENERAL_NC ("Terminating writer thread");
-               terminate_thread (true);
-       }
-
-       LOG_GENERAL_NC ("Finishing ReelWriters");
-
-       for (auto& i: _reels) {
-               write_hanging_text (i);
-               i.finish (output_dcp);
-       }
-
-       LOG_GENERAL_NC ("Writing XML");
-
-       dcp::DCP dcp (output_dcp);
-
-       auto cpl = make_shared<dcp::CPL>(
-               film()->dcp_name(),
-               film()->dcp_content_type()->libdcp_kind(),
-               film()->interop() ? dcp::Standard::INTEROP : dcp::Standard::SMPTE
-               );
-
-       dcp.add (cpl);
-
-       /* Calculate digests for each reel in parallel */
-
        auto job = _job.lock ();
        if (job) {
                job->sub (_("Computing digests"));
@@ -575,7 +548,7 @@ Writer::finish (boost::filesystem::path output_dcp)
 
        auto work = make_shared<boost::asio::io_service::work>(service);
 
-       int const threads = max (1, Config::instance()->master_encoding_threads ());
+       int const threads = max (1, Config::instance()->master_encoding_threads());
 
        for (int i = 0; i < threads; ++i) {
                pool.create_thread (boost::bind (&boost::asio::io_service::run, &service));
@@ -594,8 +567,44 @@ Writer::finish (boost::filesystem::path output_dcp)
        service.post (boost::bind (&Writer::calculate_referenced_digests, this, set_progress));
 
        work.reset ();
-       pool.join_all ();
+
+       {
+               pool.join_all ();
+       }
+
        service.stop ();
+}
+
+
+/** @param output_dcp Path to DCP folder to write */
+void
+Writer::finish (boost::filesystem::path output_dcp)
+{
+       if (_thread.joinable()) {
+               LOG_GENERAL_NC ("Terminating writer thread");
+               terminate_thread (true);
+       }
+
+       LOG_GENERAL_NC ("Finishing ReelWriters");
+
+       for (auto& i: _reels) {
+               write_hanging_text (i);
+               i.finish (output_dcp);
+       }
+
+       LOG_GENERAL_NC ("Writing XML");
+
+       dcp::DCP dcp (output_dcp);
+
+       auto cpl = make_shared<dcp::CPL>(
+               film()->dcp_name(),
+               film()->dcp_content_type()->libdcp_kind(),
+               film()->interop() ? dcp::Standard::INTEROP : dcp::Standard::SMPTE
+               );
+
+       dcp.add (cpl);
+
+       calculate_digests ();
 
        /* Add reels */
 
index aab7d5fc78da6e1d5c4211093c34c04b2781d2ea..0ff011fa1de22037b392db91bfd479010362a91f 100644 (file)
@@ -130,6 +130,7 @@ private:
        void write_cover_sheet (boost::filesystem::path output_dcp);
        void calculate_referenced_digests (boost::function<void (float)> set_progress);
        void write_hanging_text (ReelWriter& reel);
+       void calculate_digests ();
 
        std::weak_ptr<Job> _job;
        std::vector<ReelWriter> _reels;