Use plain git hash for VERSION when there is no exact tag.
[dcpomatic.git] / src / lib / reel_writer.cc
index 9383f7c838a551ca8545e602776b4c985da1b7f3..1b33cae852eedcbb1ed5330d9e20bf52bc77bd03 100644 (file)
@@ -194,16 +194,11 @@ ReelWriter::ReelWriter (
                DCPOMATIC_ASSERT (film()->directory());
 
                std::vector<dcp::Channel> extra_active_channels;
-               auto add_if_mapped = [this, &extra_active_channels](dcp::Channel channel) {
+               for (auto channel: std::vector<dcp::Channel>{dcp::Channel::HI, dcp::Channel::VI, dcp::Channel::BSL, dcp::Channel::BSR}) {
                        if (channel_is_mapped(film(), channel)) {
                                extra_active_channels.push_back(channel);
                        }
-               };
-
-               add_if_mapped(dcp::Channel::HI);
-               add_if_mapped(dcp::Channel::VI);
-               add_if_mapped(dcp::Channel::BSL);
-               add_if_mapped(dcp::Channel::BSR);
+               }
 
                /* Write the sound asset into the film directory so that we leave the creation
                   of the DCP directory until the last minute.
@@ -778,21 +773,39 @@ ReelWriter::create_reel (
        return reel;
 }
 
+
+/** @param set_progress Method to call with progress; first parameter is the number of bytes
+ *  done, second parameter is the number of bytes in total.
+ */
 void
-ReelWriter::calculate_digests (std::function<void (float)> set_progress)
+ReelWriter::calculate_digests(std::function<void (int64_t, int64_t)> set_progress)
 try
 {
+       vector<shared_ptr<const dcp::Asset>> assets;
+
        if (_picture_asset) {
-               _picture_asset->hash (set_progress);
+               assets.push_back(_picture_asset);
        }
-
        if (_sound_asset) {
-               _sound_asset->hash (set_progress);
+               assets.push_back(_sound_asset);
        }
-
        if (_atmos_asset) {
-               _atmos_asset->hash (set_progress);
+               assets.push_back(_atmos_asset);
        }
+
+       int64_t total_size = 0;
+       for (auto asset: assets) {
+               total_size += asset->file() ? boost::filesystem::file_size(*asset->file()) : 0;
+       }
+
+       int64_t total_done = 0;
+       for (auto asset: assets) {
+               asset->hash([&total_done, total_size, set_progress](int64_t done, int64_t) {
+                       set_progress(total_done + done, total_size);
+               });
+               total_done += asset->file() ? boost::filesystem::file_size(*asset->file()) : 0;
+       }
+
 } catch (boost::thread_interrupted) {
        /* set_progress contains an interruption_point, so any of these methods
         * may throw thread_interrupted, at which point we just give up.
@@ -878,7 +891,8 @@ ReelWriter::empty_text_asset (TextType type, optional<DCPTextTrack> track, bool
                                dcp::Colour(),
                                dcp::Time(),
                                dcp::Time(),
-                               0
+                               0,
+                               std::vector<dcp::Ruby>()
                                )
                       );