X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Ffilm.cc;h=475dd68448628afba155ac59981b133f1b1e84f7;hb=cb1dfa9ec09af2abf6d10e4bf2764476db83841b;hp=b01a70b7277789958ea2452687d7411ac82d254a;hpb=f0edd6ab35c3c2b7800a26ec8206adab75e5f633;p=dcpomatic.git diff --git a/src/lib/film.cc b/src/lib/film.cc index b01a70b72..475dd6844 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -30,7 +29,6 @@ #include #include #include -#include #include #include #include @@ -55,11 +53,11 @@ #include "ratio.h" #include "cross.h" #include "cinema.h" +#include "safe_stringstream.h" #include "i18n.h" using std::string; -using std::stringstream; using std::multimap; using std::pair; using std::map; @@ -77,9 +75,11 @@ using boost::to_upper_copy; using boost::ends_with; using boost::starts_with; using boost::optional; +using boost::is_any_of; using dcp::Size; using dcp::Signer; using dcp::raw_convert; +using dcp::raw_convert; #define LOG_GENERAL(...) log()->log (String::compose (__VA_ARGS__), Log::TYPE_GENERAL); #define LOG_GENERAL_NC(...) log()->log (__VA_ARGS__, Log::TYPE_GENERAL); @@ -119,6 +119,7 @@ Film::Film (boost::filesystem::path dir, bool log) , _three_d (false) , _sequence_video (true) , _interop (false) + , _burn_subtitles (false) , _state_version (current_state_version) , _dirty (false) { @@ -160,7 +161,7 @@ Film::video_identifier () const { assert (container ()); - stringstream s; + SafeStringStream s; s.imbue (std::locale::classic ()); s << container()->id() @@ -182,6 +183,10 @@ Film::video_identifier () const s << "_S"; } + if (_burn_subtitles) { + s << "_B"; + } + if (_three_d) { s << "_3D"; } @@ -223,6 +228,12 @@ Film::audio_mxf_filename () const return filename_safe_name() + "_audio.mxf"; } +boost::filesystem::path +Film::subtitle_xml_filename () const +{ + return filename_safe_name() + "_subtitle.xml"; +} + string Film::filename_safe_name () const { @@ -373,6 +384,7 @@ Film::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("BurnSubtitles")->add_child_text (_burn_subtitles ? "1" : "0"); root->add_child("Signed")->add_child_text (_signed ? "1" : "0"); root->add_child("Encrypted")->add_child_text (_encrypted ? "1" : "0"); root->add_child("Key")->add_child_text (_key.hex ()); @@ -444,6 +456,9 @@ Film::read_metadata () _sequence_video = f.bool_child ("SequenceVideo"); _three_d = f.bool_child ("ThreeD"); _interop = f.bool_child ("Interop"); + if (_state_version >= 32) { + _burn_subtitles = f.bool_child ("BurnSubtitles"); + } _key = dcp::Key (f.string_child ("Key")); list notes; @@ -488,19 +503,42 @@ Film::file (boost::filesystem::path f) const string Film::isdcf_name (bool if_created_now) const { - stringstream d; + SafeStringStream d; string raw_name = name (); + + /* Split the raw name up into words */ + vector words; + split (words, raw_name, is_any_of (" ")); + string fixed_name; - bool cap_next = true; - for (size_t i = 0; i < raw_name.length(); ++i) { - if (raw_name[i] == ' ') { - cap_next = true; - } else if (cap_next) { - fixed_name += toupper (raw_name[i]); - cap_next = false; - } else { - fixed_name += tolower (raw_name[i]); + + /* Add each word to fixed_name */ + for (vector::const_iterator i = words.begin(); i != words.end(); ++i) { + string w = *i; + + /* First letter is always capitalised */ + w[0] = toupper (w[0]); + + /* Count caps in w */ + size_t caps = 0; + for (size_t i = 0; i < w.size(); ++i) { + if (isupper (w[i])) { + ++caps; + } + } + + /* If w is all caps make the rest of it lower case, otherwise + leave it alone. + */ + if (caps == w.size ()) { + for (size_t i = 1; i < w.size(); ++i) { + w[i] = tolower (w[i]); + } + } + + for (size_t i = 0; i < w.size(); ++i) { + fixed_name += w[i]; } } @@ -553,18 +591,22 @@ Film::isdcf_name (bool if_created_now) const d << "_" << container()->isdcf_name(); } - /* XXX: this only works for content which has been scaled to a given ratio, - and uses the first bit of content only. - */ + /* XXX: this uses the first bit of content only */ /* The standard says we don't do this for trailers, for some strange reason */ if (dcp_content_type() && dcp_content_type()->libdcp_kind() != dcp::TRAILER) { ContentList cl = content (); Ratio const * content_ratio = 0; - for (ContentList::const_iterator i = cl.begin(); i != cl.end(); ++i) { + for (ContentList::iterator i = cl.begin(); i != cl.end(); ++i) { shared_ptr vc = dynamic_pointer_cast (*i); - if (vc && (content_ratio == 0 || vc->scale().ratio() != content_ratio)) { - content_ratio = vc->scale().ratio(); + if (vc) { + /* Here's the first piece of video content */ + if (vc->scale().ratio ()) { + content_ratio = vc->scale().ratio (); + } else { + content_ratio = Ratio::from_ratio (vc->video_size().ratio ()); + } + break; } } @@ -656,7 +698,6 @@ Film::dcp_name (bool if_created_now) const return name(); } - void Film::set_directory (boost::filesystem::path d) { @@ -748,6 +789,13 @@ Film::set_interop (bool i) signal_changed (INTEROP); } +void +Film::set_burn_subtitles (bool b) +{ + _burn_subtitles = b; + signal_changed (BURN_SUBTITLES); +} + void Film::signal_changed (Property p) { @@ -782,7 +830,7 @@ Film::info_path (int f, Eyes e) const boost::filesystem::path p; p /= info_dir (); - stringstream s; + SafeStringStream s; s.width (8); s << setfill('0') << f; @@ -809,7 +857,7 @@ Film::j2c_path (int f, Eyes e, bool t) const p /= "j2c"; p /= video_identifier (); - stringstream s; + SafeStringStream s; s.width (8); s << setfill('0') << f; @@ -829,7 +877,7 @@ Film::j2c_path (int f, Eyes e, bool t) const return file (p); } -/** Find all the DCPs in our directory that can be libdcp::DCP::read() and return details of their CPLs */ +/** Find all the DCPs in our directory that can be dcp::DCP::read() and return details of their CPLs */ vector Film::cpls () const { @@ -894,6 +942,13 @@ Film::content () const return _playlist->content (); } +void +Film::examine_content (shared_ptr c) +{ + shared_ptr j (new ExamineContentJob (shared_from_this(), c)); + JobManager::instance()->add (j); +} + void Film::examine_and_add_content (shared_ptr c) { @@ -1019,21 +1074,27 @@ Film::full_frame () const dcp::Size Film::frame_size () const { - return fit_ratio_within (container()->ratio(), full_frame ()); + return fit_ratio_within (container()->ratio(), full_frame (), 1); } dcp::EncryptedKDM Film::make_kdm ( - shared_ptr target, + dcp::Certificate target, boost::filesystem::path cpl_file, dcp::LocalTime from, - dcp::LocalTime until + dcp::LocalTime until, + dcp::Formulation formulation ) const { shared_ptr cpl (new dcp::CPL (cpl_file)); + shared_ptr signer = Config::instance()->signer(); + if (!signer->valid ()) { + throw InvalidSignerError (); + } + return dcp::DecryptedKDM ( - cpl, from, until, "DCP-o-matic", cpl->content_title_text(), dcp::LocalTime().as_string() - ).encrypt (make_signer(), target); + cpl, key(), from, until, "DCP-o-matic", cpl->content_title_text(), dcp::LocalTime().as_string() + ).encrypt (signer, target, formulation); } list @@ -1041,13 +1102,16 @@ Film::make_kdms ( list > screens, boost::filesystem::path dcp, dcp::LocalTime from, - dcp::LocalTime until + dcp::LocalTime until, + dcp::Formulation formulation ) const { list kdms; for (list >::iterator i = screens.begin(); i != screens.end(); ++i) { - kdms.push_back (make_kdm ((*i)->certificate, dcp, from, until)); + if ((*i)->certificate) { + kdms.push_back (make_kdm ((*i)->certificate.get(), dcp, from, until, formulation)); + } } return kdms;