#include <boost/date_time.hpp>
#include <libxml++/libxml++.h>
#include <libcxml/cxml.h>
+#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"
#include "dcp_content_type.h"
#include "ratio.h"
#include "cross.h"
+#include "cinema.h"
#include "i18n.h"
using boost::starts_with;
using boost::optional;
using libdcp::Size;
+using libdcp::Signer;
int const Film::state_version = 4;
, _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)
}
}
- set_directory (result.string ());
+ set_directory (result);
_log.reset (new FileLog (file ("log")));
_playlist->set_sequence_video (_sequence_video);
void
Film::write_metadata () const
{
- if (!boost::filesystem::exists (directory())) {
- boost::filesystem::create_directory (directory());
+ if (!boost::filesystem::exists (directory ())) {
+ boost::filesystem::create_directory (directory ());
}
LocaleGuard lg;
- boost::filesystem::create_directories (directory());
+ boost::filesystem::create_directories (directory ());
xmlpp::Document doc;
xmlpp::Element* root = doc.create_root_node ("Metadata");
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");
+ root->add_child("Key")->add_child_text (_key.hex ());
_playlist->as_xml (root->add_child ("Playlist"));
doc.write_to_file_formatted (file ("metadata.xml"));
throw StringError (_("This film was created with an older version of DCP-o-matic, and unfortunately it cannot be loaded into this version. You will need to create a new Film, re-add your content and set it up again. Sorry!"));
}
- cxml::File f (file ("metadata.xml"), "Metadata");
+ cxml::Document f ("Metadata");
+ f.read_file (file ("metadata.xml"));
_name = f.string_child ("Name");
_use_dci_name = f.bool_child ("UseDCIName");
_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;
if (dcp_content_type()) {
d << "_" << dcp_content_type()->dci_name();
+ d << "-" << dci_metadata().content_version;
}
if (three_d ()) {
void
-Film::set_directory (string d)
+Film::set_directory (boost::filesystem::path d)
{
_directory = d;
_dirty = true;
return file (p.string ());
}
-/** Make an educated guess as to whether we have a complete DCP
- * or not.
- * @return true if we do.
- */
-
-bool
-Film::have_dcp () const
+/** @return List of subdirectories (not full paths) containing DCPs that can be successfully libdcp::DCP::read() */
+list<boost::filesystem::path>
+Film::dcps () const
{
- try {
- libdcp::DCP dcp (dir (dcp_name()));
- dcp.read ();
- } catch (...) {
- return false;
- }
+ list<boost::filesystem::path> out;
+
+ boost::filesystem::path const dir = directory ();
+ 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() != "video" && i->path().leaf() != "info" && i->path().leaf() != "analysis"
+ ) {
+
+ try {
+ libdcp::DCP dcp (*i);
+ dcp.read ();
+ out.push_back (i->path().leaf ());
+ } catch (...) {
- return true;
+ }
+ }
+ }
+
+ return out;
}
shared_ptr<Player>
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
{
_playlist->remove (c);
}
+void
+Film::move_content_earlier (shared_ptr<Content> c)
+{
+ _playlist->move_earlier (c);
+}
+
+void
+Film::move_content_later (shared_ptr<Content> c)
+{
+ _playlist->move_later (c);
+}
+
Time
Film::length () const
{
assert (false);
return libdcp::Size ();
}
+
+libdcp::KDM
+Film::make_kdm (
+ shared_ptr<libdcp::Certificate> target,
+ boost::filesystem::path dcp_dir,
+ boost::posix_time::ptime from,
+ boost::posix_time::ptime until
+ ) const
+{
+ shared_ptr<const Signer> signer = make_signer ();
+
+ libdcp::DCP dcp (dir (dcp_dir.string ()));
+
+ try {
+ dcp.read ();
+ } 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);
+}
+
+list<libdcp::KDM>
+Film::make_kdms (
+ list<shared_ptr<Screen> > screens,
+ boost::filesystem::path dcp,
+ 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, dcp, from, until));
+ }
+
+ return kdms;
+}