Fix checking of frame channels vs stream channels.
[dcpomatic.git] / src / lib / film.cc
index 1ea03a8d9a68684a4e6bd6cfefb690b564c28a29..4e133a90dd8e5b59abce153bba33d2d90be43c8f 100644 (file)
@@ -29,7 +29,6 @@
 #include "audio_content.h"
 #include "audio_processor.h"
 #include "change_signaller.h"
-#include "check_content_change_job.h"
 #include "cinema.h"
 #include "compose.hpp"
 #include "config.h"
@@ -482,7 +481,7 @@ Film::write_metadata (boost::filesystem::path path) const
 
 /** Write state to our `metadata' file */
 void
-Film::write_metadata () const
+Film::write_metadata ()
 {
        DCPOMATIC_ASSERT (directory());
        boost::filesystem::create_directories (directory().get());
@@ -535,6 +534,8 @@ Film::read_metadata (optional<boost::filesystem::path> path)
                }
        }
 
+       _last_written_by = f.optional_string_child("LastWrittenBy");
+
        _name = f.string_child ("Name");
        if (_state_version >= 9) {
                _use_isdcf_name = f.bool_child ("UseISDCFName");
@@ -972,7 +973,10 @@ Film::isdcf_name (bool if_created_now) const
                if (_ratings.empty ()) {
                        d += "-NR";
                } else {
-                       d += "-" + _ratings[0].label;
+                       auto label = _ratings[0].label;
+                       boost::erase_all(label, "+");
+                       boost::erase_all(label, "-");
+                       d += "-" + label;
                }
        }
 
@@ -1718,9 +1722,9 @@ Film::should_be_enough_disk_space (double& required, double& available, bool& ca
        boost::filesystem::path test = internal_video_asset_dir() / "test";
        boost::filesystem::path test2 = internal_video_asset_dir() / "test2";
        can_hard_link = true;
-       auto f = fopen_boost (test, "w");
+       dcp::File f(test, "w");
        if (f) {
-               fclose (f);
+               f.close();
                boost::system::error_code ec;
                boost::filesystem::create_hard_link (test, test2, ec);
                if (ec) {
@@ -1754,7 +1758,7 @@ Film::audio_output_names () const
        vector<NamedChannel> n;
 
        for (int i = 0; i < audio_channels(); ++i) {
-               if (i != 8 && i != 9 && i != 15) {
+               if (Config::instance()->use_all_audio_channels() || (i != 8 && i != 9 && i != 15)) {
                        n.push_back (NamedChannel(short_audio_channel_name(i), i));
                }
        }
@@ -2071,34 +2075,15 @@ Film::info_file_handle (DCPTimePeriod period, bool read) const
        return std::make_shared<InfoFileHandle>(_info_file_mutex, info_file(period), read);
 }
 
-InfoFileHandle::InfoFileHandle (boost::mutex& mutex, boost::filesystem::path file, bool read)
+InfoFileHandle::InfoFileHandle (boost::mutex& mutex, boost::filesystem::path path, bool read)
        : _lock (mutex)
-       , _file (file)
+       , _file (path, read ? "rb" : (boost::filesystem::exists(path) ? "r+b" : "wb"))
 {
-       if (read) {
-               _handle = fopen_boost (file, "rb");
-               if (!_handle) {
-                       throw OpenFileError (file, errno, OpenFileError::READ);
-               }
-       } else {
-               auto const exists = boost::filesystem::exists (file);
-               if (exists) {
-                       _handle = fopen_boost (file, "r+b");
-               } else {
-                       _handle = fopen_boost (file, "wb");
-               }
-
-               if (!_handle) {
-                       throw OpenFileError (file, errno, exists ? OpenFileError::READ_WRITE : OpenFileError::WRITE);
-               }
+       if (!_file) {
+               throw OpenFileError (path, errno, read ? OpenFileError::READ : (boost::filesystem::exists(path) ? OpenFileError::READ_WRITE : OpenFileError::WRITE));
        }
 }
 
-InfoFileHandle::~InfoFileHandle ()
-{
-       fclose (_handle);
-}
-
 
 /** Add FFOC and LFOC markers to a list if they are not already there */
 void
@@ -2178,8 +2163,50 @@ Film::set_sign_language_video_language (optional<dcp::LanguageTag> lang)
 
 
 void
-Film::set_dirty (bool dirty) const
+Film::set_dirty (bool dirty)
 {
+       auto const changed = dirty != _dirty;
        _dirty = dirty;
+       if (changed) {
+               emit (boost::bind(boost::ref(DirtyChange), _dirty));
+       }
+}
+
+
+/** @return true if the metadata was (probably) last written by a version earlier
+ *  than the given one; false if it definitely was not.
+ */
+bool
+Film::last_written_by_earlier_than(int major, int minor, int micro) const
+{
+       if (!_last_written_by) {
+               return true;
+       }
+
+       vector<string> parts;
+       boost::split(parts, *_last_written_by, boost::is_any_of("."));
+
+       if (parts.size() != 3) {
+               /* Not sure what's going on, so let's say it was written by an old version */
+               return true;
+       }
+
+       if (boost::ends_with(parts[2], "pre")) {
+               parts[2] = parts[2].substr(0, parts[2].length() - 3);
+       }
+
+       int our_major = dcp::raw_convert<int>(parts[0]);
+       int our_minor = dcp::raw_convert<int>(parts[1]);
+       int our_micro = dcp::raw_convert<int>(parts[2]);
+
+       if (our_major != major) {
+               return our_major < major;
+       }
+
+       if (our_minor != minor) {
+               return our_minor < minor;
+       }
+
+       return our_micro < micro;
 }