swaroop: allow ScreenKDM subclasses for different KDM types.
authorCarl Hetherington <cth@carlh.net>
Mon, 13 May 2019 20:52:27 +0000 (21:52 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 13 May 2019 20:52:27 +0000 (21:52 +0100)
13 files changed:
src/lib/cinema_kdms.cc
src/lib/cinema_kdms.h
src/lib/encrypted_ecinema_kdm.cc
src/lib/encrypted_ecinema_kdm.h
src/lib/film.cc
src/lib/film.h
src/lib/screen_kdm.cc
src/lib/screen_kdm.h
src/lib/wscript
src/tools/dcpomatic_kdm.cc
src/wx/kdm_dialog.cc
src/wx/kdm_output_panel.cc
src/wx/kdm_output_panel.h

index 7952b7ab22e3f22e3b75f7bb03ea084791234721..32879cf6b5763355378e6ddc58432b8095d8ef52 100644 (file)
@@ -56,8 +56,8 @@ CinemaKDMs::make_zip_file (boost::filesystem::path zip_file, dcp::NameFormat nam
 
        name_values['c'] = cinema->name;
 
-       BOOST_FOREACH (ScreenKDM const & i, screen_kdms) {
-               shared_ptr<string> kdm (new string (i.kdm.as_xml ()));
+       BOOST_FOREACH (shared_ptr<ScreenKDM> i, screen_kdms) {
+               shared_ptr<string> kdm (new string(i->kdm_as_xml()));
                kdm_strings.push_back (kdm);
 
                struct zip_source* source = zip_source_buffer (zip, kdm->c_str(), kdm->length(), 0);
@@ -65,8 +65,8 @@ CinemaKDMs::make_zip_file (boost::filesystem::path zip_file, dcp::NameFormat nam
                        throw runtime_error ("could not create ZIP source");
                }
 
-               name_values['s'] = i.screen->name;
-               name_values['i'] = i.kdm.id ();
+               name_values['s'] = i->screen->name;
+               name_values['i'] = i->kdm_id ();
                string const name = careful_string_filter(name_format.get(name_values, ".xml"));
                if (zip_add (zip, name.c_str(), source) == -1) {
                        throw runtime_error ("failed to add KDM to ZIP archive");
@@ -82,7 +82,7 @@ CinemaKDMs::make_zip_file (boost::filesystem::path zip_file, dcp::NameFormat nam
  *  CinemaKDM contains the KDMs for its cinema.
  */
 list<CinemaKDMs>
-CinemaKDMs::collect (list<ScreenKDM> screen_kdms)
+CinemaKDMs::collect (list<shared_ptr<ScreenKDM> > screen_kdms)
 {
        list<CinemaKDMs> cinema_kdms;
 
@@ -92,17 +92,17 @@ CinemaKDMs::collect (list<ScreenKDM> screen_kdms)
 
                CinemaKDMs ck;
 
-               list<ScreenKDM>::iterator i = screen_kdms.begin ();
-               ck.cinema = i->screen->cinema;
+               list<shared_ptr<ScreenKDM> >::iterator i = screen_kdms.begin ();
+               ck.cinema = (*i)->screen->cinema;
                ck.screen_kdms.push_back (*i);
-               list<ScreenKDM>::iterator j = i;
+               list<shared_ptr<ScreenKDM> >::iterator j = i;
                ++i;
                screen_kdms.remove (*j);
 
                while (i != screen_kdms.end ()) {
-                       if (i->screen->cinema == ck.cinema) {
+                       if ((*i)->screen->cinema == ck.cinema) {
                                ck.screen_kdms.push_back (*i);
-                               list<ScreenKDM>::iterator j = i;
+                               list<shared_ptr<ScreenKDM> >::iterator j = i;
                                ++i;
                                screen_kdms.remove (*j);
                        } else {
@@ -230,8 +230,8 @@ CinemaKDMs::email (
                boost::algorithm::replace_all (body, "$CINEMA_NAME", i.cinema->name);
 
                string screens;
-               BOOST_FOREACH (ScreenKDM const & j, i.screen_kdms) {
-                       screens += j.screen->name + ", ";
+               BOOST_FOREACH (shared_ptr<ScreenKDM> j, i.screen_kdms) {
+                       screens += j->screen->name + ", ";
                }
                boost::algorithm::replace_all (body, "$SCREENS", screens.substr (0, screens.length() - 2));
 
index 566b947a23e22208a64a774a3fe7752b6fcb22d3..2b82cdab6e7662a5b5a5f7d58993ca672d31e74b 100644 (file)
@@ -29,7 +29,7 @@ class CinemaKDMs
 public:
        void make_zip_file (boost::filesystem::path zip_file, dcp::NameFormat name_format, dcp::NameFormat::Map name_values) const;
 
-       static std::list<CinemaKDMs> collect (std::list<ScreenKDM> kdms);
+       static std::list<CinemaKDMs> collect (std::list<boost::shared_ptr<ScreenKDM> > kdms);
 
        static int write_directories (
                std::list<CinemaKDMs> cinema_kdms,
@@ -58,5 +58,5 @@ public:
                );
 
        boost::shared_ptr<Cinema> cinema;
-       std::list<ScreenKDM> screen_kdms;
+       std::list<boost::shared_ptr<ScreenKDM> > screen_kdms;
 };
index e4e19d7fb3de57426fd4707a0763b00cb2bb1864..f0502ab31ddde720d1e50f57dd7bfd444a79e2ac 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "encrypted_ecinema_kdm.h"
 #include "exceptions.h"
+#include "cross.h"
 #include <dcp/key.h>
 #include <dcp/certificate.h>
 #include <dcp/util.h>
@@ -85,4 +86,13 @@ EncryptedECinemaKDM::as_xml () const
        return document.write_to_string ("UTF-8");
 }
 
+void
+EncryptedECinemaKDM::as_xml (boost::filesystem::path path) const
+{
+       FILE* f = fopen_boost (path, "w");
+       string const x = as_xml ();
+       fwrite (x.c_str(), 1, x.length(), f);
+       fclose (f);
+}
+
 #endif
index 0bcbc4117f0bbe7172b18f6a025813193161febf..c65620c8b2970de2a8a4529e37eb1fe458725f1e 100644 (file)
@@ -35,6 +35,7 @@ public:
        explicit EncryptedECinemaKDM (std::string xml);
 
        std::string as_xml () const;
+       void as_xml (boost::filesystem::path out) const;
 
        std::string id () const {
                return _id;
index efc89e0eb6be3b27c6a7c04a31b82ee32c68f54b..e54268805ca9c71d752ecd89026d84cf6ebdc6ca 100644 (file)
@@ -1420,7 +1420,7 @@ Film::make_kdm (
  *  @param disable_forensic_marking_audio if not set, don't disable forensic marking of audio.  If set to 0,
  *  disable all forensic marking; if set above 0, disable forensic marking above that channel.
  */
-list<ScreenKDM>
+list<shared_ptr<ScreenKDM> >
 Film::make_kdms (
        list<shared_ptr<Screen> > screens,
        boost::filesystem::path cpl_file,
@@ -1431,7 +1431,7 @@ Film::make_kdms (
        optional<int> disable_forensic_marking_audio
        ) const
 {
-       list<ScreenKDM> kdms;
+       list<shared_ptr<ScreenKDM> > kdms;
 
        BOOST_FOREACH (shared_ptr<Screen> i, screens) {
                if (i->recipient) {
@@ -1446,7 +1446,7 @@ Film::make_kdms (
                                disable_forensic_marking_audio
                                );
 
-                       kdms.push_back (ScreenKDM (i, kdm));
+                       kdms.push_back (shared_ptr<ScreenKDM>(new DCPScreenKDM(i, kdm)));
                }
        }
 
index 87ea700b7cc19e4d52e4ea8fcdeaf79eab8dd852..876d312ae427666c23649aca3db4e5690d0e36f1 100644 (file)
@@ -142,7 +142,7 @@ public:
                boost::optional<int> disable_forensic_marking_audio
                ) const;
 
-       std::list<ScreenKDM> make_kdms (
+       std::list<boost::shared_ptr<ScreenKDM> > make_kdms (
                std::list<boost::shared_ptr<dcpomatic::Screen> > screens,
                boost::filesystem::path cpl_file,
                boost::posix_time::ptime from,
index 5b7692469a8d68a3be03929f00e980b7f586d27d..f9a3fa36eb2720fa0d04d597486248ecdb68a338 100644 (file)
@@ -29,15 +29,9 @@ using std::cout;
 using std::list;
 using boost::shared_ptr;
 
-bool
-operator== (ScreenKDM const & a, ScreenKDM const & b)
-{
-       return a.screen == b.screen && a.kdm == b.kdm;
-}
-
 int
 ScreenKDM::write_files (
-       list<ScreenKDM> screen_kdms,
+       list<shared_ptr<ScreenKDM> > screen_kdms,
        boost::filesystem::path directory,
        dcp::NameFormat name_format,
        dcp::NameFormat::Map name_values,
@@ -48,8 +42,8 @@ ScreenKDM::write_files (
 
        if (directory == "-") {
                /* Write KDMs to the stdout */
-               BOOST_FOREACH (ScreenKDM const & i, screen_kdms) {
-                       cout << i.kdm.as_xml ();
+               BOOST_FOREACH (shared_ptr<ScreenKDM> i, screen_kdms) {
+                       cout << i->kdm_as_xml ();
                        ++written;
                }
 
@@ -61,13 +55,13 @@ ScreenKDM::write_files (
        }
 
        /* Write KDMs to the specified directory */
-       BOOST_FOREACH (ScreenKDM const & i, screen_kdms) {
-               name_values['c'] = i.screen->cinema ? i.screen->cinema->name : "";
-               name_values['s'] = i.screen->name;
-               name_values['i'] = i.kdm.id ();
+       BOOST_FOREACH (shared_ptr<ScreenKDM> i, screen_kdms) {
+               name_values['c'] = i->screen->cinema ? i->screen->cinema->name : "";
+               name_values['s'] = i->screen->name;
+               name_values['i'] = i->kdm_id ();
                boost::filesystem::path out = directory / careful_string_filter(name_format.get(name_values, ".xml"));
                if (!boost::filesystem::exists (out) || confirm_overwrite (out)) {
-                       i.kdm.as_xml (out);
+                       i->kdm_as_xml (out);
                        ++written;
                }
        }
index 351c2f1c2617de141a79a097184fc59a2f088a8c..6a102557ffd0f9491028eba64f94a7f300cdc195 100644 (file)
@@ -21,6 +21,9 @@
 #ifndef DCPOMATIC_SCREEN_KDM_H
 #define DCPOMATIC_SCREEN_KDM_H
 
+#ifdef DCPOMATIC_VARIANT_SWAROOP
+#include "encrypted_ecinema_kdm.h"
+#endif
 #include <dcp/encrypted_kdm.h>
 #include <dcp/name_format.h>
 #include <boost/shared_ptr.hpp>
@@ -33,21 +36,69 @@ namespace dcpomatic {
 class ScreenKDM
 {
 public:
-       ScreenKDM (boost::shared_ptr<dcpomatic::Screen> s, dcp::EncryptedKDM k)
+       ScreenKDM (boost::shared_ptr<dcpomatic::Screen> s)
                : screen (s)
-               , kdm (k)
        {}
 
+       virtual std::string kdm_as_xml () const = 0;
+       virtual void kdm_as_xml (boost::filesystem::path out) const = 0;
+       virtual std::string kdm_id () const = 0;
+
        static int write_files (
-               std::list<ScreenKDM> screen_kdms, boost::filesystem::path directory,
+               std::list<boost::shared_ptr<ScreenKDM> > screen_kdms, boost::filesystem::path directory,
                dcp::NameFormat name_format, dcp::NameFormat::Map name_values,
                boost::function<bool (boost::filesystem::path)> confirm_overwrite
                );
 
        boost::shared_ptr<dcpomatic::Screen> screen;
+};
+
+class DCPScreenKDM : public ScreenKDM
+{
+public:
+       DCPScreenKDM (boost::shared_ptr<dcpomatic::Screen> s, dcp::EncryptedKDM k)
+               : ScreenKDM (s)
+               , kdm (k)
+       {}
+
+       std::string kdm_as_xml () const {
+               return kdm.as_xml ();
+       }
+
+       void kdm_as_xml (boost::filesystem::path out) const {
+               return kdm.as_xml (out);
+       }
+
+       std::string kdm_id () const {
+               return kdm.cpl_id ();
+       }
+
        dcp::EncryptedKDM kdm;
 };
 
-extern bool operator== (ScreenKDM const & a, ScreenKDM const & b);
+#ifdef DCPOMATIC_VARIANT_SWAROOP
+class ECinemaScreenKDM : public ScreenKDM
+{
+public:
+       ECinemaScreenKDM (boost::shared_ptr<dcpomatic::Screen> s, EncryptedECinemaKDM k)
+               : ScreenKDM (s)
+               , kdm (k)
+       {}
+
+       std::string kdm_as_xml () const {
+               return kdm.as_xml ();
+       }
+
+       void kdm_as_xml (boost::filesystem::path out) const {
+               return kdm.as_xml (out);
+       }
+
+       std::string kdm_id () const {
+               return kdm.id ();
+       }
+
+       EncryptedECinemaKDM kdm;
+};
+#endif
 
 #endif
index 37b942400ab4f0887234f660c07cc691d0707604..c5a270f6536cac8972d043f362c9984f78fdc6af 100644 (file)
@@ -77,7 +77,6 @@ sources = """
           digester.cc
           dkdm_wrapper.cc
           dolby_cp750.cc
-          ecinema_screen_kdm.cc
           edid.cc
           emailer.cc
           empty.cc
index 60bb54f5914c3b9c0e1a876b0420cd71b4089e1b..fc4282535664e2b00d54777e7b12aa7709485f74 100644 (file)
@@ -313,7 +313,7 @@ private:
                                throw InvalidSignerError ();
                        }
 
-                       list<ScreenKDM> screen_kdms;
+                       list<shared_ptr<ScreenKDM> > screen_kdms;
                        BOOST_FOREACH (shared_ptr<Screen> i, _screens->screens()) {
 
                                if (!i->recipient) {
@@ -336,11 +336,13 @@ private:
 
                                /* Encrypt */
                                screen_kdms.push_back (
-                                       ScreenKDM (
-                                               i,
-                                               kdm.encrypt (
-                                                       signer, i->recipient.get(), i->trusted_device_thumbprints(), _output->formulation(),
-                                                       !_output->forensic_mark_video(), _output->forensic_mark_audio() ? boost::optional<int>() : 0
+                                       shared_ptr<ScreenKDM>(
+                                               new DCPScreenKDM(
+                                                       i,
+                                                       kdm.encrypt(
+                                                               signer, i->recipient.get(), i->trusted_device_thumbprints(), _output->formulation(),
+                                                               !_output->forensic_mark_video(), _output->forensic_mark_audio() ? boost::optional<int>() : 0
+                                                               )
                                                        )
                                                )
                                        );
index 920f54a3e9a4619074ace225f095756a5a86c690..55b89a37128925841dafbcada17040c9faac4508 100644 (file)
@@ -149,7 +149,7 @@ KDMDialog::make_clicked ()
        shared_ptr<const Film> film = _film.lock ();
        DCPOMATIC_ASSERT (film);
 
-       list<ScreenKDM> screen_kdms;
+       list<shared_ptr<ScreenKDM> > screen_kdms;
        try {
 
                screen_kdms = film->make_kdms (
index 8763291234a8d9787c17f9b379c1c62ea7bc4f8f..181ca74f4008cd897b75861eaba37d676534677f 100644 (file)
@@ -181,7 +181,7 @@ KDMOutputPanel::kdm_write_type_changed ()
 
 pair<shared_ptr<Job>, int>
 KDMOutputPanel::make (
-       list<ScreenKDM> screen_kdms, string name, KDMTimingPanel* timing, function<bool (boost::filesystem::path)> confirm_overwrite
+       list<shared_ptr<ScreenKDM> > screen_kdms, string name, KDMTimingPanel* timing, function<bool (boost::filesystem::path)> confirm_overwrite
        )
 {
        list<CinemaKDMs> const cinema_kdms = CinemaKDMs::collect (screen_kdms);
index ed162e0535bc19d32f78978206495ef7519478e5..c52fa7a1530ca6418b1493e194f36cb87604c511 100644 (file)
@@ -49,7 +49,7 @@ public:
        }
 
        std::pair<boost::shared_ptr<Job>, int> make (
-               std::list<ScreenKDM> screen_kdms,
+               std::list<boost::shared_ptr<ScreenKDM> > screen_kdms,
                std::string name,
                KDMTimingPanel* timing,
                boost::function<bool (boost::filesystem::path)> confirm_overwrite