Lookup the correct DCNC code to use for languages rather than just
[dcpomatic.git] / src / lib / film.cc
index 5e99e466c4375a04d90484708f11d294321b8c68..ef64a91d339d1d479999496477e63d727967950f 100644 (file)
 #include <boost/filesystem.hpp>
 #include <boost/regex.hpp>
 #include <unistd.h>
-#include <stdexcept>
-#include <iostream>
 #include <algorithm>
 #include <cstdlib>
 #include <iomanip>
+#include <iostream>
 #include <set>
+#include <stdexcept>
 
 #include "i18n.h"
 
@@ -377,69 +377,6 @@ Film::subtitle_analysis_path (shared_ptr<const Content> content) const
 }
 
 
-/** Add suitable Jobs to the JobManager to create a DCP for this Film */
-void
-Film::make_dcp (TranscodeJob::ChangedBehaviour behaviour)
-{
-       if (dcp_name().find ("/") != string::npos) {
-               throw BadSettingError (_("name"), _("Cannot contain slashes"));
-       }
-
-       if (container() == nullptr) {
-               throw MissingSettingError (_("container"));
-       }
-
-       if (content().empty()) {
-               throw runtime_error (_("You must add some content to the DCP before creating it"));
-       }
-
-       if (length() == DCPTime()) {
-               throw runtime_error (_("The DCP is empty, perhaps because all the content has zero length."));
-       }
-
-       if (dcp_content_type() == nullptr) {
-               throw MissingSettingError (_("content type"));
-       }
-
-       if (name().empty()) {
-               set_name ("DCP");
-       }
-
-       for (auto i: content ()) {
-               if (!i->paths_valid()) {
-                       throw runtime_error (_("some of your content is missing"));
-               }
-               auto dcp = dynamic_pointer_cast<const DCPContent>(i);
-               if (dcp && dcp->needs_kdm()) {
-                       throw runtime_error (_("Some of your content needs a KDM"));
-               }
-               if (dcp && dcp->needs_assets()) {
-                       throw runtime_error (_("Some of your content needs an OV"));
-               }
-       }
-
-       set_isdcf_date_today ();
-
-       for (auto i: environment_info ()) {
-               LOG_GENERAL_NC (i);
-       }
-
-       for (auto i: content ()) {
-               LOG_GENERAL ("Content: %1", i->technical_summary());
-       }
-       LOG_GENERAL ("DCP video rate %1 fps", video_frame_rate());
-       if (Config::instance()->only_servers_encode ()) {
-               LOG_GENERAL_NC ("0 threads: ONLY SERVERS SET TO ENCODE");
-       } else {
-               LOG_GENERAL ("%1 threads", Config::instance()->master_encoding_threads());
-       }
-       LOG_GENERAL ("J2K bandwidth %1", j2k_bandwidth());
-
-       auto tj = make_shared<TranscodeJob>(shared_from_this(), behaviour);
-       tj->set_encoder (make_shared<DCPEncoder>(shared_from_this(), tj));
-       JobManager::instance()->add (tj);
-}
-
 /** Start a job to send our DCP to the configured TMS */
 void
 Film::send_dcp_to_tms ()
@@ -978,7 +915,18 @@ Film::isdcf_name (bool if_created_now) const
                }
        }
 
-       auto audio_language = (_audio_language && _audio_language->language()) ? _audio_language->language()->subtag() : "XX";
+       auto entry_for_language = [](dcp::LanguageTag const& tag) {
+               /* Look up what we should be using for this tag in the DCNC name */
+               for (auto const& dcnc: dcp::dcnc_tags()) {
+                       if (tag.to_string() == dcnc.first) {
+                               return dcnc.second;
+                       }
+               }
+               /* Fallback to the language subtag, if there is one */
+               return tag.language() ? tag.language()->subtag() : "XX";
+       };
+
+       auto audio_language = _audio_language ? entry_for_language(*_audio_language) : "XX";
 
        d += "_" + to_upper (audio_language);
 
@@ -1000,7 +948,7 @@ Film::isdcf_name (bool if_created_now) const
 
        auto sub_langs = subtitle_languages();
        if (sub_langs.first && sub_langs.first->language()) {
-               auto lang = sub_langs.first->language()->subtag();
+               auto lang = entry_for_language(*sub_langs.first);
                if (burnt_in) {
                        transform (lang.begin(), lang.end(), lang.begin(), ::tolower);
                } else {
@@ -1283,6 +1231,7 @@ Film::set_isdcf_date_today ()
        _isdcf_date = boost::gregorian::day_clock::local_day ();
 }
 
+
 boost::filesystem::path
 Film::j2c_path (int reel, Frame frame, Eyes eyes, bool tmp) const
 {