Hand-apply bbfb370d7de28ec1e8f307865cc6253bb5d4366e from master; quicker digest calcu...
[dcpomatic.git] / src / lib / film.cc
index 26810992175d8da91065dfc4052d7da424afa0a2..ecc98d7dc698be487248ce5870636cde9be334cc 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 
 */
 
-#include <stdexcept>
-#include <iostream>
-#include <algorithm>
-#include <fstream>
-#include <cstdlib>
-#include <iomanip>
-#include <unistd.h>
-#include <boost/filesystem.hpp>
-#include <boost/algorithm/string.hpp>
-#include <boost/lexical_cast.hpp>
-#include <libxml++/libxml++.h>
-#include <libcxml/cxml.h>
-#include <dcp/cpl.h>
-#include <dcp/signer.h>
-#include <dcp/util.h>
-#include <dcp/local_time.h>
-#include <dcp/raw_convert.h>
+/** @file  src/film.cc
+ *  @brief A representation of some audio and video content, and details of
+ *  how they should be presented in a DCP.
+ */
+
 #include "film.h"
 #include "job.h"
 #include "util.h"
 #include "cross.h"
 #include "cinema.h"
 #include "safe_stringstream.h"
+#include <libcxml/cxml.h>
+#include <dcp/cpl.h>
+#include <dcp/signer.h>
+#include <dcp/util.h>
+#include <dcp/local_time.h>
+#include <dcp/raw_convert.h>
+#include <dcp/decrypted_kdm.h>
+#include <libxml++/libxml++.h>
+#include <boost/filesystem.hpp>
+#include <boost/algorithm/string.hpp>
+#include <boost/lexical_cast.hpp>
+#include <boost/foreach.hpp>
+#include <unistd.h>
+#include <stdexcept>
+#include <iostream>
+#include <algorithm>
+#include <fstream>
+#include <cstdlib>
+#include <iomanip>
+#include <set>
 
 #include "i18n.h"
 
@@ -68,6 +76,7 @@ using std::make_pair;
 using std::endl;
 using std::cout;
 using std::list;
+using std::set;
 using boost::shared_ptr;
 using boost::weak_ptr;
 using boost::dynamic_pointer_cast;
@@ -148,7 +157,7 @@ Film::Film (boost::filesystem::path dir, bool log)
                }
        }
 
-       set_directory (result);
+       set_directory (result.make_preferred ());
        if (log) {
                _log.reset (new FileLog (file ("log")));
        } else {
@@ -161,7 +170,7 @@ Film::Film (boost::filesystem::path dir, bool log)
 string
 Film::video_identifier () const
 {
-       assert (container ());
+       DCPOMATIC_ASSERT (container ());
 
        SafeStringStream s;
        s.imbue (std::locale::classic ());
@@ -268,11 +277,6 @@ Film::make_dcp ()
                throw BadSettingError (_("name"), _("cannot contain slashes"));
        }
 
-       /* It seems to make sense to auto-save metadata here, since the make DCP may last
-          a long time, and crashes/power failures are moderately likely.
-        */
-       write_metadata ();
-
        LOG_GENERAL ("DCP-o-matic %1 git %2 using %3", dcpomatic_version, dcpomatic_git_commit, dependency_version_summary());
 
        {
@@ -467,6 +471,9 @@ Film::read_metadata ()
        /* This method is the only one that can return notes (so far) */
        _playlist->set_from_xml (shared_from_this(), f.node_child ("Playlist"), _state_version, notes);
 
+       /* Write backtraces to this film's directory, until another film is loaded */
+       set_backtrace_file (file ("backtrace.txt"));
+
        _dirty = false;
        return notes;
 }
@@ -1068,7 +1075,7 @@ Film::full_frame () const
                return dcp::Size (4096, 2160);
        }
 
-       assert (false);
+       DCPOMATIC_ASSERT (false);
        return dcp::Size ();
 }
 
@@ -1143,3 +1150,28 @@ Film::should_be_enough_disk_space (double& required, double& available) const
        available = double (s.available) / 1073741824.0f;
        return (available - required) > 1;
 }
+
+string
+Film::subtitle_language () const
+{
+       set<string> languages;
+       
+       ContentList cl = content ();
+       BOOST_FOREACH (shared_ptr<Content>& c, cl) {
+               shared_ptr<SubtitleContent> sc = dynamic_pointer_cast<SubtitleContent> (c);
+               if (sc) {
+                       languages.insert (sc->subtitle_language ());
+               }
+       }
+
+       string all;
+       BOOST_FOREACH (string s, languages) {
+               if (!all.empty ()) {
+                       all += "/" + s;
+               } else {
+                       all += s;
+               }
+       }
+
+       return all;
+}