Partial hacks to use of libdcp 1.0.
[dcpomatic.git] / src / lib / film.cc
index 932048d8b2997418bcb3b8902777c4631d8fdb60..774c1b392c715c7da834d6b0dd0dce1886477cd1 100644 (file)
@@ -78,10 +78,15 @@ using boost::to_upper_copy;
 using boost::ends_with;
 using boost::starts_with;
 using boost::optional;
-using libdcp::Size;
-using libdcp::Signer;
+using dcp::Size;
+using dcp::Signer;
 
-int const Film::state_version = 5;
+/* 5 -> 6
+ * AudioMapping XML changed.
+ * 6 -> 7
+ * Subtitle offset changed to subtitle y offset, and subtitle x offset added.
+ */
+int const Film::state_version = 7;
 
 /** Construct a Film object in a given directory.
  *
@@ -262,6 +267,14 @@ Film::make_dcp ()
 #else
        log()->log ("libdcp built in optimised mode.");
 #endif
+
+#ifdef DCPOMATIC_WINDOWS
+       OSVERSIONINFO info;
+       info.dwOSVersionInfoSize = sizeof (info);
+       GetVersionEx (&info);
+       log()->log (String::compose ("Windows version %1.%2.%3 SP %4", info.dwMajorVersion, info.dwMinorVersion, info.dwBuildNumber, info.szCSDVersion));
+#endif 
+       
        log()->log (String::compose ("CPU: %1, %2 processors", cpu_info(), boost::thread::hardware_concurrency ()));
        list<pair<string, string> > const m = mount_info ();
        for (list<pair<string, string> >::const_iterator i = m.begin(); i != m.end(); ++i) {
@@ -407,7 +420,7 @@ Film::read_metadata ()
        _sequence_video = f.bool_child ("SequenceVideo");
        _three_d = f.bool_child ("ThreeD");
        _interop = f.bool_child ("Interop");
-       _key = libdcp::Key (f.string_child ("Key"));
+       _key = dcp::Key (f.string_child ("Key"));
        _playlist->set_from_xml (shared_from_this(), f.node_child ("Playlist"), version);
 
        _dirty = false;
@@ -733,7 +746,7 @@ Film::j2c_path (int f, Eyes e, bool t) const
        return file (p);
 }
 
-/** @return List of subdirectories (not full paths) containing DCPs that can be successfully libdcp::DCP::read() */
+/** @return List of subdirectories (not full paths) containing DCPs that can be successfully dcp::DCP::read() */
 list<boost::filesystem::path>
 Film::dcps () const
 {
@@ -747,7 +760,7 @@ Film::dcps () const
                        ) {
 
                        try {
-                               libdcp::DCP dcp (*i);
+                               dcp::DCP dcp (*i);
                                dcp.read ();
                                out.push_back (i->path().leaf ());
                        } catch (...) {
@@ -923,23 +936,23 @@ Film::set_sequence_video (bool s)
        signal_changed (SEQUENCE_VIDEO);
 }
 
-libdcp::Size
+dcp::Size
 Film::full_frame () const
 {
        switch (_resolution) {
        case RESOLUTION_2K:
-               return libdcp::Size (2048, 1080);
+               return dcp::Size (2048, 1080);
        case RESOLUTION_4K:
-               return libdcp::Size (4096, 2160);
+               return dcp::Size (4096, 2160);
        }
 
        assert (false);
-       return libdcp::Size ();
+       return dcp::Size ();
 }
 
-libdcp::KDM
+dcp::KDM
 Film::make_kdm (
-       shared_ptr<libdcp::Certificate> target,
+       shared_ptr<dcp::Certificate> target,
        boost::filesystem::path dcp_dir,
        boost::posix_time::ptime from,
        boost::posix_time::ptime until
@@ -947,7 +960,7 @@ Film::make_kdm (
 {
        shared_ptr<const Signer> signer = make_signer ();
 
-       libdcp::DCP dcp (dir (dcp_dir.string ()));
+       dcp::DCP dcp (dir (dcp_dir.string ()));
        
        try {
                dcp.read ();
@@ -957,14 +970,14 @@ Film::make_kdm (
        
        time_t now = time (0);
        struct tm* tm = localtime (&now);
-       string const issue_date = libdcp::tm_to_string (tm);
+       string const issue_date = dcp::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);
+       return dcp::KDM (dcp.cpls().front(), signer, target, from, until, "DCP-o-matic", issue_date);
 }
 
-list<libdcp::KDM>
+list<dcp::KDM>
 Film::make_kdms (
        list<shared_ptr<Screen> > screens,
        boost::filesystem::path dcp,
@@ -972,7 +985,7 @@ Film::make_kdms (
        boost::posix_time::ptime until
        ) const
 {
-       list<libdcp::KDM> kdms;
+       list<dcp::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));
@@ -980,3 +993,28 @@ Film::make_kdms (
 
        return kdms;
 }
+
+/** @return The approximate disk space required to encode a DCP of this film with the
+ *  current settings, in bytes.
+ */
+uint64_t
+Film::required_disk_space () const
+{
+       return uint64_t (j2k_bandwidth() / 8) * length() / TIME_HZ;
+}
+
+/** This method checks the disk that the Film is on and tries to decide whether or not
+ *  there will be enough space to make a DCP for it.  If so, true is returned; if not,
+ *  false is returned and required and availabe are filled in with the amount of disk space
+ *  required and available respectively (in Gb).
+ *
+ *  Note: the decision made by this method isn't, of course, 100% reliable.
+ */
+bool
+Film::should_be_enough_disk_space (double& required, double& available) const
+{
+       boost::filesystem::space_info s = boost::filesystem::space (internal_video_mxf_dir ());
+       required = double (required_disk_space ()) / 1073741824.0f;
+       available = double (s.available) / 1073741824.0f;
+       return (available - required) > 1;
+}