Report progress with done/total rather than a float.
authorCarl Hetherington <cth@carlh.net>
Sun, 12 Nov 2023 21:24:12 +0000 (22:24 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 19 Nov 2023 21:34:01 +0000 (22:34 +0100)
src/asset.cc
src/asset.h
src/util.cc
src/util.h
src/verify.cc
tools/dcprecover.cc

index 15f810154c1c9939e6969c0e3c3d3e0c44356070..ef06ea8d6b49c24bfa9820f791e4d2036253b01b 100644 (file)
@@ -131,7 +131,7 @@ Asset::add_file_to_assetmap(AssetMap& asset_map, boost::filesystem::path root, b
 
 
 string
-Asset::hash (function<void (float)> progress) const
+Asset::hash(function<void (int64_t, int64_t)> progress) const
 {
        DCP_ASSERT (_file);
 
index 29cd69ebbac2d97d5c9d072869e098afba902da7..390b667100a10a9d0a2dac563e3f88762d2af775 100644 (file)
@@ -128,11 +128,11 @@ public:
 
        /** Calculate the hash of this asset's file, if it has not already been calculated,
         *  then return it
-        *  @param progress Function that will be called with a parameter between 0 and 1 to indicate
-        *  progress in the calculation
+        *  @param progress Function that will be called with the number of bytes calculated
+        *  and the total number of bytes
         *  @return the hash
         */
-       std::string hash (boost::function<void (float)> progress = {}) const;
+       std::string hash(boost::function<void (int64_t, int64_t)> progress = {}) const;
 
        void set_hash (std::string hash);
        void unset_hash();
index 1ff36f598f0f9afc44946b1d165cc65217b9c6f2..a030ecb098ab930364b5d57a8e4a550cd112eba7 100644 (file)
@@ -117,7 +117,7 @@ dcp::make_digest (ArrayData data)
 
 
 string
-dcp::make_digest (boost::filesystem::path filename, function<void (float)> progress)
+dcp::make_digest(boost::filesystem::path filename, function<void (int64_t, int64_t)> progress)
 {
        Kumu::FileReader reader;
        auto r = reader.OpenRead(dcp::filesystem::fix_long_path(filename).string().c_str());
@@ -146,7 +146,7 @@ dcp::make_digest (boost::filesystem::path filename, function<void (float)> progr
                SHA1_Update (&sha, read_buffer.Data(), read);
 
                if (progress) {
-                       progress (float (done) / size);
+                       progress(done, size);
                        done += read;
                }
        }
index ccbe6083a057ba3c86dbe5ffb8bf859311128c5a..551eed071eb158b9455136a2aed903a0961ed28c 100644 (file)
@@ -85,11 +85,11 @@ extern std::string make_uuid ();
 
 /** Create a digest for a file
  *  @param filename File name
- *  @param progress Optional progress reporting function.  The function will be called
- *  with a progress value between 0 and 1
+ *  @param progress Optional progress reporting function, called with a number of bytes done
+ *  and a total number of bytes.
  *  @return Digest
  */
-extern std::string make_digest (boost::filesystem::path filename, boost::function<void (float)>);
+extern std::string make_digest(boost::filesystem::path filename, boost::function<void (int64_t, int64_t)>);
 
 extern std::string make_digest (ArrayData data);
 
index dba5dfb13b76cd35a0a3e35ea225067631fb17fb..9a1c0dcc7a7bddc9e0860fb38c9741f08b422ef5 100644 (file)
@@ -393,7 +393,9 @@ verify_asset (shared_ptr<const DCP> dcp, shared_ptr<const ReelFileAsset> reel_fi
         * call to hash().
         */
        reel_file_asset->asset_ref()->unset_hash();
-       auto const actual_hash = reel_file_asset->asset_ref()->hash(progress);
+       auto const actual_hash = reel_file_asset->asset_ref()->hash([progress](int64_t done, int64_t total) {
+               progress(float(done) / total);
+       });
 
        auto pkls = dcp->pkls();
        /* We've read this DCP in so it must have at least one PKL */
index b78846ff7712e18dd50e7bafd72722686dc082cc..779cab609a966823872e38b17582b34baeb4a35a 100644 (file)
@@ -65,12 +65,6 @@ help (string n)
 }
 
 
-void progress (float f)
-{
-       cout << (f * 100) << "%               \r";
-}
-
-
 int
 main (int argc, char* argv[])
 {
@@ -153,7 +147,9 @@ main (int argc, char* argv[])
                                        auto asset = dcp::asset_factory(i.path(), true);
                                        asset->set_file (*output / i.path().filename());
                                        cout << "Hashing " << i.path().filename() << "\n";
-                                       asset->hash (&progress);
+                                       asset->hash([](int64_t done, int64_t size) {
+                                               cout << (float(done) * 100 / size) << "%               \r";
+                                       });
                                        cout << "100%                     \n";
                                        assets.push_back (asset);
                                } catch (dcp::ReadError& e) {