summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/verify.cc12
-rw-r--r--src/verify_internal.h10
-rw-r--r--test/verify_test.cc40
3 files changed, 60 insertions, 2 deletions
diff --git a/src/verify.cc b/src/verify.cc
index b7ffeb0d..d3ab2c3f 100644
--- a/src/verify.cc
+++ b/src/verify.cc
@@ -533,7 +533,11 @@ verify_main_picture_asset(Context& context, shared_ptr<const ReelPictureAsset> r
auto asset = reel_asset->asset();
auto const file = *asset->file();
- if (context.options.check_asset_hashes && (!context.options.maximum_asset_size_for_hash_check || filesystem::file_size(file) < *context.options.maximum_asset_size_for_hash_check)) {
+ if (
+ context.options.check_asset_hashes &&
+ (!context.options.maximum_asset_size_for_hash_check || filesystem::file_size(file) < *context.options.maximum_asset_size_for_hash_check) &&
+ context.should_verify_asset(reel_asset->id())
+ ) {
context.stage("Checking picture asset hash", file);
string reference_hash;
string calculated_hash;
@@ -618,7 +622,11 @@ verify_main_sound_asset(Context& context, shared_ptr<const ReelSoundAsset> reel_
auto asset = reel_asset->asset();
auto const file = *asset->file();
- if (context.options.check_asset_hashes && (!context.options.maximum_asset_size_for_hash_check || filesystem::file_size(file) < *context.options.maximum_asset_size_for_hash_check)) {
+ if (
+ context.options.check_asset_hashes &&
+ (!context.options.maximum_asset_size_for_hash_check || filesystem::file_size(file) < *context.options.maximum_asset_size_for_hash_check) &&
+ context.should_verify_asset(reel_asset->id())
+ ) {
context.stage("Checking sound asset hash", file);
string reference_hash;
string calculated_hash;
diff --git a/src/verify_internal.h b/src/verify_internal.h
index 97c0e90f..d6e3c075 100644
--- a/src/verify_internal.h
+++ b/src/verify_internal.h
@@ -49,6 +49,7 @@
#include <boost/filesystem.hpp>
#include <boost/optional.hpp>
#include <memory>
+#include <unordered_set>
#include <vector>
@@ -131,6 +132,13 @@ public:
}
}
+ bool should_verify_asset(std::string const& id)
+ {
+ auto const should = verified_assets.find(id) == verified_assets.end();
+ verified_assets.insert(id);
+ return should;
+ }
+
std::vector<VerificationNote>& notes;
std::shared_ptr<const DCP> dcp;
std::shared_ptr<const CPL> cpl;
@@ -138,6 +146,8 @@ public:
std::function<void (std::string, boost::optional<boost::filesystem::path>)> stage;
std::function<void (float)> progress;
VerificationOptions options;
+ /** IDs of assets that have already been verified and need not be checked again */
+ std::unordered_set<std::string> verified_assets;
boost::optional<std::string> subtitle_language;
boost::optional<int> audio_channels;
diff --git a/test/verify_test.cc b/test/verify_test.cc
index af3d135e..5e5d89ba 100644
--- a/test/verify_test.cc
+++ b/test/verify_test.cc
@@ -5955,3 +5955,43 @@ BOOST_AUTO_TEST_CASE(multiple_metadata_property)
verify_extension_metadata(context);
}
+
+BOOST_AUTO_TEST_CASE(only_verify_assets_once)
+{
+ auto const dir = boost::filesystem::path("build/test/only_verify_assets_once");
+ prepare_directory(dir);
+
+ /* Make a DCP which re-uses two assets */
+
+ auto picture = simple_picture(dir, "foo");
+ auto sound = simple_sound(dir, "foo", dcp::MXFMetadata(), "de-DE", 24, 96000, boost::none);
+ auto cpl = make_shared<dcp::CPL>("hello", dcp::ContentKind::TRAILER, dcp::Standard::SMPTE);
+ for (int i = 0; i < 2; ++i) {
+ auto reel = make_shared<dcp::Reel>();
+ auto reel_picture = make_shared<dcp::ReelMonoPictureAsset>(picture, 0);
+ reel->add(reel_picture);
+ auto reel_sound = make_shared<dcp::ReelSoundAsset>(sound, 0);
+ reel->add(reel_sound);
+ reel->add(simple_markers());
+ cpl->add(reel);
+ }
+
+ auto dcp = make_shared<dcp::DCP>(dir);
+ dcp->add(cpl);
+ dcp->set_annotation_text("hello");
+ dcp->write_xml();
+
+ vector<string> stages;
+ auto stage = [&stages](std::string stage, boost::optional<boost::filesystem::path>) { stages.push_back(stage); };
+ auto progress = [](float) {};
+
+ dcp::verify({dir}, {}, stage, progress, {}, xsd_test);
+
+ BOOST_CHECK_EQUAL(std::count(stages.begin(), stages.end(), "Checking picture asset hash"), 1);
+ BOOST_CHECK_EQUAL(std::count(stages.begin(), stages.end(), "Checking sound asset hash"), 1);
+
+ for (auto i: stages) {
+ std::cout << i << "\n";
+ }
+}
+