X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=blobdiff_plain;f=src%2Flib%2Ffilm.cc;fp=src%2Flib%2Ffilm.cc;h=fb3423bb42c1c35707798ca0c4f23c363e3e5c86;hp=f0441c9e0b038733b86a7797cc32b3706cc5a028;hb=3031638f0ddf23654b72af2088a7616791307310;hpb=b9ee74b24dad91e3fee9ead44ea9a52328b20f25 diff --git a/src/lib/film.cc b/src/lib/film.cc index f0441c9e0..fb3423bb4 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -29,6 +29,10 @@ #include #include #include +#include +#include +#include +#include "cinema.h" #include "film.h" #include "format.h" #include "job.h" @@ -65,6 +69,7 @@ using std::ofstream; using std::setfill; using std::min; using std::make_pair; +using std::list; using std::cout; using boost::shared_ptr; using boost::lexical_cast; @@ -99,6 +104,7 @@ Film::Film (string d, bool must_exist) , _with_subtitles (false) , _subtitle_offset (0) , _subtitle_scale (1) + , _encrypted (false) , _colour_lut (0) , _j2k_bandwidth (200000000) , _frames_per_second (0) @@ -169,6 +175,7 @@ Film::Film (Film const & o) , _with_subtitles (o._with_subtitles) , _subtitle_offset (o._subtitle_offset) , _subtitle_scale (o._subtitle_scale) + , _encrypted (o._encrypted) , _colour_lut (o._colour_lut) , _j2k_bandwidth (o._j2k_bandwidth) , _audio_language (o._audio_language) @@ -434,6 +441,7 @@ Film::write_metadata () const f << "with_subtitles " << _with_subtitles << "\n"; f << "subtitle_offset " << _subtitle_offset << "\n"; f << "subtitle_scale " << _subtitle_scale << "\n"; + f << "encrypted " << _encrypted << "\n"; f << "colour_lut " << _colour_lut << "\n"; f << "j2k_bandwidth " << _j2k_bandwidth << "\n"; f << "audio_language " << _audio_language << "\n"; @@ -563,6 +571,8 @@ Film::read_metadata () _subtitle_offset = atoi (v.c_str ()); } else if (k == "subtitle_scale") { _subtitle_scale = atof (v.c_str ()); + } else if (k == "encrypted") { + _encrypted = (v == "1"); } else if (k == "colour_lut") { _colour_lut = atoi (v.c_str ()); } else if (k == "j2k_bandwidth") { @@ -1232,6 +1242,16 @@ Film::set_subtitle_scale (float s) signal_changed (SUBTITLE_SCALE); } +void +Film::set_encrypted (bool e) +{ + { + boost::mutex::scoped_lock lm (_state_mutex); + _encrypted = e; + } + signal_changed (ENCRYPTED); +} + void Film::set_colour_lut (int i) { @@ -1431,3 +1451,69 @@ Film::audio_stream () const return _external_audio_stream; } + +void +Film::make_kdms ( + list > 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 (new libdcp::Certificate (p.string ()))); + } + + { + boost::filesystem::path p (cd); + p /= "intermediate.signed.pem"; + chain.add (shared_ptr (new libdcp::Certificate (p.string ()))); + } + + { + boost::filesystem::path p (cd); + p /= "leaf.signed.pem"; + chain.add (shared_ptr (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 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 >::iterator i = screens.begin(); i != screens.end(); ++i) { + + libdcp::DCP dcp (dcps.front ()); + dcp.read (); + + /* XXX: single CPL only */ + shared_ptr 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()); + } +} +