Merge 1.0 in.
[dcpomatic.git] / src / lib / film.cc
index 940e94fa7631053ffe1ac3070fbed1f0e7e855aa..e885fe5fd350f804fb8e0e8ec489005da6b4501d 100644 (file)
@@ -31,6 +31,8 @@
 #include <boost/date_time.hpp>
 #include <libxml++/libxml++.h>
 #include <libcxml/cxml.h>
+#include <libdcp/crypt_chain.h>
+#include <libdcp/cpl.h>
 #include "film.h"
 #include "job.h"
 #include "util.h"
@@ -49,6 +51,7 @@
 #include "dcp_content_type.h"
 #include "ratio.h"
 #include "cross.h"
+#include "cinema.h"
 
 #include "i18n.h"
 
@@ -91,6 +94,7 @@ Film::Film (boost::filesystem::path dir)
        , _resolution (RESOLUTION_2K)
        , _scaler (Scaler::from_id ("bicubic"))
        , _with_subtitles (false)
+       , _encrypted (false)
        , _j2k_bandwidth (Config::instance()->default_j2k_bandwidth ())
        , _dci_metadata (Config::instance()->default_dci_metadata ())
        , _video_frame_rate (24)
@@ -339,6 +343,7 @@ Film::write_metadata () const
        root->add_child("ThreeD")->add_child_text (_three_d ? "1" : "0");
        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");
        _playlist->as_xml (root->add_child ("Playlist"));
 
        doc.write_to_file_formatted (file ("metadata.xml"));
@@ -737,6 +742,13 @@ Film::make_player () const
        return shared_ptr<Player> (new Player (shared_from_this (), _playlist));
 }
 
+void
+Film::set_encrypted (bool e)
+{
+       _encrypted = e;
+       signal_changed (ENCRYPTED);
+}
+
 shared_ptr<Playlist>
 Film::playlist () const
 {
@@ -876,3 +888,71 @@ Film::full_frame () const
        assert (false);
        return libdcp::Size ();
 }
+
+void
+Film::make_kdms (
+       list<shared_ptr<Screen> > screens,
+       boost::posix_time::ptime from,
+       boost::posix_time::ptime until,
+       string directory
+       ) const
+{
+       string const cd = Config::instance()->crypt_chain_directory ();
+       if (boost::filesystem::is_empty (cd)) {
+               libdcp::make_crypt_chain (cd);
+       }
+
+       libdcp::CertificateChain chain;
+
+       {
+               boost::filesystem::path p (cd);
+               p /= "ca.self-signed.pem";
+               chain.add (shared_ptr<libdcp::Certificate> (new libdcp::Certificate (p.string ())));
+       }
+
+       {
+               boost::filesystem::path p (cd);
+               p /= "intermediate.signed.pem";
+               chain.add (shared_ptr<libdcp::Certificate> (new libdcp::Certificate (p.string ())));
+       }
+
+       {
+               boost::filesystem::path p (cd);
+               p /= "leaf.signed.pem";
+               chain.add (shared_ptr<libdcp::Certificate> (new libdcp::Certificate (p.string ())));
+       }
+
+       boost::filesystem::path signer_key (cd);
+       signer_key /= "leaf.key";
+
+       /* Find the DCP to make the KDM for */
+       string const dir = this->directory ();
+       list<string> 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 (dcps.empty()) {
+               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");
+       }
+
+       for (list<shared_ptr<Screen> >::iterator i = screens.begin(); i != screens.end(); ++i) {
+
+               libdcp::DCP dcp (dcps.front ());
+               dcp.read ();
+               
+               /* XXX: single CPL only */
+               shared_ptr<xmlpp::Document> kdm = dcp.cpls().front()->make_kdm (
+                       chain, signer_key.string(), (*i)->certificate, from, until, _interop, libdcp::MXFMetadata (), Config::instance()->dcp_metadata ()
+                       );
+
+               boost::filesystem::path out = directory;
+               out /= "kdm.xml";
+               kdm->write_to_file_formatted (out.string());
+       }
+}
+