summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-01-11 00:24:34 +0000
committerCarl Hetherington <cth@carlh.net>2013-01-11 00:24:34 +0000
commitfad726e94700bccdae0d301d54cdb1eab51cc71f (patch)
tree375b2a042acb72f1076415f1c2ac499be1821641 /src
parent0b45af42b5a30c3a71d2e1de491843d125e46793 (diff)
Some work on making KDMs in Film
Diffstat (limited to 'src')
-rw-r--r--src/lib/cinema.h2
-rw-r--r--src/lib/config.cc32
-rw-r--r--src/lib/config.h5
-rw-r--r--src/lib/exceptions.h8
-rw-r--r--src/lib/film.cc62
5 files changed, 102 insertions, 7 deletions
diff --git a/src/lib/cinema.h b/src/lib/cinema.h
index 02b38c496..0cec01384 100644
--- a/src/lib/cinema.h
+++ b/src/lib/cinema.h
@@ -8,7 +8,7 @@ public:
{}
std::string name;
- libdcp::Certificate certificate;
+ boost::shared_ptr<libdcp::Certificate> certificate;
};
class Cinema
diff --git a/src/lib/config.cc b/src/lib/config.cc
index 80d357e1a..fe50a5cc2 100644
--- a/src/lib/config.cc
+++ b/src/lib/config.cc
@@ -48,7 +48,7 @@ Config::Config ()
, _tms_path (".")
, _sound_processor (SoundProcessor::from_id ("dolby_cp750"))
{
- ifstream f (file().c_str ());
+ ifstream f (read_file().c_str ());
string line;
shared_ptr<Cinema> cinema;
@@ -117,14 +117,40 @@ Config::Config ()
/** @return Filename to write configuration to */
string
-Config::file () const
+Config::write_file () const
{
boost::filesystem::path p;
p /= g_get_user_config_dir ();
+ p /= "dvdomatic";
+ boost::filesystem::create_directory (p);
+ p /= "config";
+ return p.string ();
+}
+
+string
+Config::read_file () const
+{
+ if (boost::filesystem::exists (write_file ())) {
+ return write_file ();
+ }
+
+ boost::filesystem::path p;
+ p /= g_get_user_config_dir ();
p /= ".dvdomatic";
return p.string ();
}
+string
+Config::crypt_chain_directory () const
+{
+ boost::filesystem::path p;
+ p /= g_get_user_config_dir ();
+ p /= "dvdomatic";
+ p /= "crypt";
+ boost::filesystem::create_directories (p);
+ return p.string ();
+}
+
/** @return Singleton instance */
Config *
Config::instance ()
@@ -140,7 +166,7 @@ Config::instance ()
void
Config::write () const
{
- ofstream f (file().c_str ());
+ ofstream f (write_file().c_str ());
f << "num_local_encoding_threads " << _num_local_encoding_threads << "\n"
<< "default_directory " << _default_directory << "\n"
<< "server_port " << _server_port << "\n"
diff --git a/src/lib/config.h b/src/lib/config.h
index 2d5b82ac5..785fff137 100644
--- a/src/lib/config.h
+++ b/src/lib/config.h
@@ -179,11 +179,14 @@ public:
void write () const;
+ std::string crypt_chain_directory () const;
+
static Config* instance ();
private:
Config ();
- std::string file () const;
+ std::string read_file () const;
+ std::string write_file () const;
/** number of threads to use for J2K encoding on the local machine */
int _num_local_encoding_threads;
diff --git a/src/lib/exceptions.h b/src/lib/exceptions.h
index bf8e85f0b..06177863a 100644
--- a/src/lib/exceptions.h
+++ b/src/lib/exceptions.h
@@ -224,3 +224,11 @@ public:
: StringError (s)
{}
};
+
+class KDMError : public StringError
+{
+public:
+ KDMError (std::string s)
+ : StringError (s)
+ {}
+};
diff --git a/src/lib/film.cc b/src/lib/film.cc
index 012495226..48677ba61 100644
--- a/src/lib/film.cc
+++ b/src/lib/film.cc
@@ -29,6 +29,10 @@
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/date_time.hpp>
+#include <libxml++/libxml++.h>
+#include <libdcp/crypt_chain.h>
+#include <libdcp/certificates.h>
+#include "cinema.h"
#include "film.h"
#include "format.h"
#include "job.h"
@@ -1388,12 +1392,66 @@ Film::audio_stream () const
void
Film::make_kdms (
- list<shared_ptr<Screen> >,
+ 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);
+
+ boost::filesystem::path out = directory;
+ out /= "kdm.xml";
+ kdm->write_to_file_formatted (out.string());
+ }
}