KDM / libdcp API changes.
[dcpomatic.git] / src / lib / film.cc
index 4f57f202a5d4c8e02365f54fcf1051c60d20e43d..bceaef96e98656615387e16bbab2f75dd0490da7 100644 (file)
@@ -34,6 +34,8 @@
 #include <libdcp/signer_chain.h>
 #include <libdcp/cpl.h>
 #include <libdcp/signer.h>
+#include <libdcp/util.h>
+#include <libdcp/kdm.h>
 #include "film.h"
 #include "job.h"
 #include "util.h"
@@ -346,6 +348,7 @@ Film::write_metadata () const
        root->add_child("SequenceVideo")->add_child_text (_sequence_video ? "1" : "0");
        root->add_child("Interop")->add_child_text (_interop ? "1" : "0");
        root->add_child("Encrypted")->add_child_text (_encrypted ? "1" : "0");
+       root->add_child("Key")->add_child_text (_key.hex ());
        _playlist->as_xml (root->add_child ("Playlist"));
 
        doc.write_to_file_formatted (file ("metadata.xml"));
@@ -390,11 +393,12 @@ Film::read_metadata ()
        _dci_metadata = DCIMetadata (f.node_child ("DCIMetadata"));
        _video_frame_rate = f.number_child<int> ("VideoFrameRate");
        _dci_date = boost::gregorian::from_undelimited_string (f.string_child ("DCIDate"));
+       _encrypted = f.bool_child ("Encrypted");
        _audio_channels = f.number_child<int> ("AudioChannels");
        _sequence_video = f.bool_child ("SequenceVideo");
        _three_d = f.bool_child ("ThreeD");
        _interop = f.bool_child ("Interop");
-
+       _key = libdcp::Key (f.string_child ("Key"));
        _playlist->set_from_xml (shared_from_this(), f.node_child ("Playlist"));
 
        _dirty = false;
@@ -891,72 +895,60 @@ Film::full_frame () const
        return libdcp::Size ();
 }
 
-void
-Film::make_kdms (
-       list<shared_ptr<Screen> > screens,
+libdcp::KDM
+Film::make_kdm (
+       shared_ptr<libdcp::Certificate> target,
        boost::posix_time::ptime from,
-       boost::posix_time::ptime until,
-       string directory
+       boost::posix_time::ptime until
        ) const
 {
-       boost::filesystem::path const sd = Config::instance()->signer_chain_directory ();
-       if (boost::filesystem::is_empty (sd)) {
-               libdcp::make_signer_chain (sd);
-       }
-
-       libdcp::CertificateChain chain;
-
-       {
-               boost::filesystem::path p (sd);
-               p /= "ca.self-signed.pem";
-               chain.add (shared_ptr<libdcp::Certificate> (new libdcp::Certificate (p.string ())));
-       }
-
-       {
-               boost::filesystem::path p (sd);
-               p /= "intermediate.signed.pem";
-               chain.add (shared_ptr<libdcp::Certificate> (new libdcp::Certificate (p.string ())));
-       }
-
-       {
-               boost::filesystem::path p (sd);
-               p /= "leaf.signed.pem";
-               chain.add (shared_ptr<libdcp::Certificate> (new libdcp::Certificate (p.string ())));
-       }
-
-       boost::filesystem::path signer_key (sd);
-       signer_key /= "leaf.key";
-
-       shared_ptr<const Signer> signer (new Signer (chain, signer_key));
+       shared_ptr<const Signer> signer = make_signer ();
 
        /* Find the DCP to make the KDM for */
        string const dir = this->directory ();
-       list<string> dcps;
+       list<boost::filesystem::path> dcps;
        for (boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator(dir); i != boost::filesystem::directory_iterator(); ++i) {
-               if (boost::filesystem::is_directory (*i) && i->path().leaf() != "j2c" && i->path().leaf() != "wavs") {
-                       dcps.push_back (i->path().string());
+               if (boost::filesystem::is_directory (*i) && i->path().leaf() != "j2c" && i->path().leaf() != "video" && i->path().leaf() != "info") {
+                       dcps.push_back (i->path());
                }
        }
 
        if (dcps.empty()) {
-               throw KDMError ("Could not find DCP to make KDM for");
+               throw KDMError (_("Could not find DCP to make KDM for"));
        } else if (dcps.size() > 1) {
-               throw KDMError ("More than one possible DCP to make KDM for");
+               throw KDMError (_("More than one possible DCP to make KDM for"));
        }
 
-       for (list<shared_ptr<Screen> >::iterator i = screens.begin(); i != screens.end(); ++i) {
-
-               libdcp::DCP dcp (dcps.front ());
+       libdcp::DCP dcp (dcps.front ());
+       
+       try {
                dcp.read ();
-               
-               /* XXX: single CPL only */
-               shared_ptr<xmlpp::Document> kdm = dcp.cpls().front()->make_kdm (
-                       signer, (*i)->certificate, from, until, _interop, libdcp::MXFMetadata (), Config::instance()->dcp_metadata ()
-                       );
+       } catch (...) {
+               throw KDMError (_("Could not read DCP to make KDM for"));
+       }
+       
+       time_t now = time (0);
+       struct tm* tm = localtime (&now);
+       string const issue_date = libdcp::tm_to_string (tm);
+       
+       dcp.cpls().front()->set_mxf_keys (key ());
+       
+       return libdcp::KDM (dcp.cpls().front(), signer, target, from, until, "DCP-o-matic", issue_date);
+}
 
-               boost::filesystem::path out = directory;
-               out /= "kdm.xml";
-               kdm->write_to_file_formatted (out.string());
+list<libdcp::KDM>
+Film::make_kdms (
+       list<shared_ptr<Screen> > screens,
+       boost::posix_time::ptime from,
+       boost::posix_time::ptime until
+       ) const
+{
+       list<libdcp::KDM> kdms;
+
+       for (list<shared_ptr<Screen> >::iterator i = screens.begin(); i != screens.end(); ++i) {
+               kdms.push_back (make_kdm ((*i)->certificate, from, until));
        }
+
+       return kdms;
 }