X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Ffilm.cc;h=bb210350e6fae4f4dc3baef7e1ee53db6f70be72;hb=8dddd2d1fef983f60df1f90984dd47f9e95256d6;hp=940e94fa7631053ffe1ac3070fbed1f0e7e855aa;hpb=944cee945a1f923614783471d472db0896f6877a;p=dcpomatic.git diff --git a/src/lib/film.cc b/src/lib/film.cc index 940e94fa7..bb210350e 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -31,6 +31,11 @@ #include #include #include +#include +#include +#include +#include +#include #include "film.h" #include "job.h" #include "util.h" @@ -49,6 +54,7 @@ #include "dcp_content_type.h" #include "ratio.h" #include "cross.h" +#include "cinema.h" #include "i18n.h" @@ -75,6 +81,7 @@ using boost::ends_with; using boost::starts_with; using boost::optional; using libdcp::Size; +using libdcp::Signer; int const Film::state_version = 4; @@ -91,6 +98,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) @@ -123,7 +131,7 @@ Film::Film (boost::filesystem::path dir) } } - set_directory (result.string ()); + set_directory (result); _log.reset (new FileLog (file ("log"))); _playlist->set_sequence_video (_sequence_video); @@ -305,13 +313,13 @@ Film::encoded_frames () const 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"); @@ -339,6 +347,8 @@ 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"); + root->add_child("Key")->add_child_text (_key.hex ()); _playlist->as_xml (root->add_child ("Playlist")); doc.write_to_file_formatted (file ("metadata.xml")); @@ -383,11 +393,12 @@ Film::read_metadata () _dci_metadata = DCIMetadata (f.node_child ("DCIMetadata")); _video_frame_rate = f.number_child ("VideoFrameRate"); _dci_date = boost::gregorian::from_undelimited_string (f.string_child ("DCIDate")); + _encrypted = f.bool_child ("Encrypted"); _audio_channels = f.number_child ("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; @@ -535,7 +546,7 @@ Film::dcp_name (bool if_created_now) const void -Film::set_directory (string d) +Film::set_directory (boost::filesystem::path d) { _directory = d; _dirty = true; @@ -713,22 +724,30 @@ Film::j2c_path (int f, Eyes e, bool t) const 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 +Film::dcps () const { - try { - libdcp::DCP dcp (dir (dcp_name())); - dcp.read (); - } catch (...) { - return false; - } + list 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 @@ -737,6 +756,13 @@ Film::make_player () const return shared_ptr (new Player (shared_from_this (), _playlist)); } +void +Film::set_encrypted (bool e) +{ + _encrypted = e; + signal_changed (ENCRYPTED); +} + shared_ptr Film::playlist () const { @@ -788,6 +814,18 @@ Film::remove_content (shared_ptr c) _playlist->remove (c); } +void +Film::move_content_earlier (shared_ptr c) +{ + _playlist->move_earlier (c); +} + +void +Film::move_content_later (shared_ptr c) +{ + _playlist->move_later (c); +} + Time Film::length () const { @@ -876,3 +914,47 @@ Film::full_frame () const assert (false); return libdcp::Size (); } + +libdcp::KDM +Film::make_kdm ( + shared_ptr target, + boost::filesystem::path dcp_dir, + boost::posix_time::ptime from, + boost::posix_time::ptime until + ) const +{ + shared_ptr 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 +Film::make_kdms ( + list > screens, + boost::filesystem::path dcp, + boost::posix_time::ptime from, + boost::posix_time::ptime until + ) const +{ + list kdms; + + for (list >::iterator i = screens.begin(); i != screens.end(); ++i) { + kdms.push_back (make_kdm ((*i)->certificate, dcp, from, until)); + } + + return kdms; +}