Pass make_kdm as a function into kdm_for_screen().
authorCarl Hetherington <cth@carlh.net>
Sat, 28 Jan 2023 23:45:43 +0000 (00:45 +0100)
committerCarl Hetherington <cth@carlh.net>
Sat, 11 Feb 2023 21:26:38 +0000 (22:26 +0100)
src/lib/kdm_cli.cc
src/lib/screen.cc
src/lib/screen.h
src/wx/kdm_dialog.cc
test/kdm_naming_test.cc

index dc74e716155357e619a89b61ad3da08b4bdf34eb..9256261199621261ae335b27eaf96c9eb81161a7 100644 (file)
@@ -245,7 +245,10 @@ from_film (
        try {
                list<KDMWithMetadataPtr> kdms;
                for (auto i: screens) {
-                       auto p = kdm_for_screen(film, cpl, i, valid_from, valid_to, formulation, disable_forensic_marking_picture, disable_forensic_marking_audio, period_checks);
+                       std::function<dcp::DecryptedKDM (dcp::LocalTime, dcp::LocalTime)> make_kdm = [film, cpl](dcp::LocalTime begin, dcp::LocalTime end) {
+                               return film->make_kdm(cpl, begin, end);
+                       };
+                       auto p = kdm_for_screen(make_kdm, i, valid_from, valid_to, formulation, disable_forensic_marking_picture, disable_forensic_marking_audio, period_checks);
                        if (p) {
                                kdms.push_back (p);
                        }
index 5ef007214b874c02cbe52f8f5b4433a071a6a552..dbf013111e3465637ddcd210405fe5536e5aa9ee 100644 (file)
@@ -75,8 +75,7 @@ Screen::trusted_device_thumbprints () const
 
 KDMWithMetadataPtr
 kdm_for_screen (
-       shared_ptr<const Film> film,
-       boost::filesystem::path cpl,
+       std::function<dcp::DecryptedKDM (dcp::LocalTime, dcp::LocalTime)> make_kdm,
        shared_ptr<const dcpomatic::Screen> screen,
        boost::posix_time::ptime valid_from,
        boost::posix_time::ptime valid_to,
@@ -101,8 +100,9 @@ kdm_for_screen (
                throw InvalidSignerError();
        }
 
-       auto const decrypted_kdm = film->make_kdm(cpl, begin, end);
-       auto kdm = decrypted_kdm.encrypt(signer, screen->recipient.get(), screen->trusted_device_thumbprints(), formulation, disable_forensic_marking_picture, disable_forensic_marking_audio);
+       auto kdm = make_kdm(begin, end).encrypt(
+               signer, screen->recipient.get(), screen->trusted_device_thumbprints(), formulation, disable_forensic_marking_picture, disable_forensic_marking_audio
+               );
 
        dcp::NameFormat::Map name_values;
        if (cinema) {
index 7cbeb1d153cf979af5d982d96703ba8a05ee26cb..7f01cdf2792abb802f200b40fb1045f21b89a7c2 100644 (file)
@@ -28,6 +28,7 @@
 #include "kdm_util.h"
 #include "trusted_device.h"
 #include <dcp/certificate.h>
+#include <dcp/decrypted_kdm.h>
 #include <libcxml/cxml.h>
 #include <boost/optional.hpp>
 #include <string>
@@ -75,8 +76,7 @@ public:
 
 KDMWithMetadataPtr
 kdm_for_screen (
-       std::shared_ptr<const Film> film,
-       boost::filesystem::path cpl,
+       std::function<dcp::DecryptedKDM (dcp::LocalTime, dcp::LocalTime)> make_kdm,
        std::shared_ptr<const dcpomatic::Screen> screen,
        boost::posix_time::ptime valid_from,
        boost::posix_time::ptime valid_to,
index 2687d126162560682bd5bcf1fb948228697fe36a..f01c47ffbba3ad86636295695b4a0f16b70adf9d 100644 (file)
@@ -174,8 +174,12 @@ KDMDialog::make_clicked ()
 
                vector<KDMCertificatePeriod> period_checks;
 
+               std::function<dcp::DecryptedKDM (dcp::LocalTime, dcp::LocalTime)> make_kdm = [film, this](dcp::LocalTime begin, dcp::LocalTime end) {
+                       return film->make_kdm(_cpl->cpl(), begin, end);
+               };
+
                for (auto i: _screens->screens()) {
-                       auto p = kdm_for_screen(film, _cpl->cpl(), i, _timing->from(), _timing->until(), _output->formulation(), !_output->forensic_mark_video(), for_audio, period_checks);
+                       auto p = kdm_for_screen(make_kdm, i, _timing->from(), _timing->until(), _output->formulation(), !_output->forensic_mark_video(), for_audio, period_checks);
                        if (p) {
                                kdms.push_back (p);
                        }
index 994217a14e7a02878fde4a341ee72cd7cdd48fac..30356afbfe36015dcd6e03c06af3abd123145869 100644 (file)
@@ -101,9 +101,11 @@ BOOST_AUTO_TEST_CASE (single_kdm_naming_test)
        std::vector<KDMCertificatePeriod> period_checks;
 
        auto cpl = cpls.front().cpl_file;
+       std::function<dcp::DecryptedKDM (dcp::LocalTime, dcp::LocalTime)> make_kdm = [film, cpl](dcp::LocalTime begin, dcp::LocalTime end) {
+               return film->make_kdm(cpl, begin, end);
+       };
        auto kdm = kdm_for_screen (
-                       film,
-                       cpls.front().cpl_file,
+                       make_kdm,
                        cinema_a_screen_1,
                        boost::posix_time::time_from_string(from_string),
                        boost::posix_time::time_from_string(until_string),
@@ -167,10 +169,14 @@ BOOST_AUTO_TEST_CASE (directory_kdm_naming_test, * boost::unit_test::depends_on(
 
        std::vector<KDMCertificatePeriod> period_checks;
        list<KDMWithMetadataPtr> kdms;
+
+       std::function<dcp::DecryptedKDM (dcp::LocalTime, dcp::LocalTime)> make_kdm = [film, cpls](dcp::LocalTime begin, dcp::LocalTime end) {
+               return film->make_kdm(cpls.front().cpl_file, begin, end);
+       };
+
        for (auto i: screens) {
                auto kdm = kdm_for_screen (
-                               film,
-                               cpls.front().cpl_file,
+                               make_kdm,
                                i,
                                boost::posix_time::time_from_string(from_string),
                                boost::posix_time::time_from_string(until_string),