Merge master.
[dcpomatic.git] / src / lib / film.cc
index 85dc5b168d2012e0d98d78606656fcc221225dd4..26810992175d8da91065dfc4052d7da424afa0a2 100644 (file)
@@ -22,7 +22,6 @@
 #include <algorithm>
 #include <fstream>
 #include <cstdlib>
-#include <sstream>
 #include <iomanip>
 #include <unistd.h>
 #include <boost/filesystem.hpp>
@@ -30,7 +29,6 @@
 #include <boost/lexical_cast.hpp>
 #include <libxml++/libxml++.h>
 #include <libcxml/cxml.h>
-#include <dcp/signer_chain.h>
 #include <dcp/cpl.h>
 #include <dcp/signer.h>
 #include <dcp/util.h>
 #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;
@@ -94,6 +92,8 @@ using dcp::raw_convert;
  * Use <Scale> tag in <VideoContent> rather than <Ratio>.
  * 8 -> 9
  * DCI -> ISDCF
+ * 9 -> 10
+ * Subtitle X and Y scale.
  *
  * Bumped to 32 for 2.0 branch; some times are expressed in Times rather
  * than frames now.
@@ -163,7 +163,7 @@ Film::video_identifier () const
 {
        assert (container ());
 
-       stringstream s;
+       SafeStringStream s;
        s.imbue (std::locale::classic ());
        
        s << container()->id()
@@ -505,7 +505,7 @@ Film::file (boost::filesystem::path f) const
 string
 Film::isdcf_name (bool if_created_now) const
 {
-       stringstream d;
+       SafeStringStream d;
 
        string raw_name = name ();
 
@@ -593,18 +593,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<VideoContent> vc = dynamic_pointer_cast<VideoContent> (*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;
                        }
                }
                
@@ -828,7 +832,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;
 
@@ -855,7 +859,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;
 
@@ -940,6 +944,13 @@ Film::content () const
        return _playlist->content ();
 }
 
+void
+Film::examine_content (shared_ptr<Content> c)
+{
+       shared_ptr<Job> j (new ExamineContentJob (shared_from_this(), c));
+       JobManager::instance()->add (j);
+}
+
 void
 Film::examine_and_add_content (shared_ptr<Content> c)
 {
@@ -1065,12 +1076,12 @@ 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<dcp::Certificate> target,
+       dcp::Certificate target,
        boost::filesystem::path cpl_file,
        dcp::LocalTime from,
        dcp::LocalTime until,
@@ -1078,9 +1089,14 @@ Film::make_kdm (
        ) const
 {
        shared_ptr<const dcp::CPL> cpl (new dcp::CPL (cpl_file));
+       shared_ptr<const dcp::Signer> 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, formulation);
+               cpl, key(), from, until, "DCP-o-matic", cpl->content_title_text(), dcp::LocalTime().as_string()
+               ).encrypt (signer, target, formulation);
 }
 
 list<dcp::EncryptedKDM>
@@ -1095,7 +1111,9 @@ Film::make_kdms (
        list<dcp::EncryptedKDM> kdms;
 
        for (list<shared_ptr<Screen> >::iterator i = screens.begin(); i != screens.end(); ++i) {
-               kdms.push_back (make_kdm ((*i)->certificate, dcp, from, until, formulation));
+               if ((*i)->certificate) {
+                       kdms.push_back (make_kdm ((*i)->certificate.get(), dcp, from, until, formulation));
+               }
        }
 
        return kdms;