Handle vertical alignment of subs correctly wrt the difference between Interop and...
[dcpomatic.git] / src / lib / util.cc
index 7d0d2bf606c698d3a2a4881f2336c4e156456899..cfeacdb92cece74e3c0049081bba2964ace11fdb 100644 (file)
@@ -34,6 +34,7 @@
 #include "cross.h"
 #include "crypto.h"
 #include "dcp_content_type.h"
+#include "dcpomatic_log.h"
 #include "digester.h"
 #include "exceptions.h"
 #include "ffmpeg_image_proxy.h"
@@ -410,8 +411,8 @@ LIBDCP_ENABLE_WARNINGS
                optional<string>(), false, false, false, dcp::Colour(), 42, 1, dcp::Time(), dcp::Time(), 0, dcp::HAlign::CENTER, 0, dcp::VAlign::CENTER, dcp::Direction::LTR,
                "Hello dolly", dcp::Effect::NONE, dcp::Colour(), dcp::Time(), dcp::Time(), 0
                );
-       subs.push_back (StringText(ss, 0));
-       render_text (subs, list<shared_ptr<Font>>(), dcp::Size(640, 480), DCPTime(), 24);
+       subs.push_back (StringText(ss, 0, {}, dcp::Standard::SMPTE));
+       render_text (subs, dcp::Size(640, 480), DCPTime(), 24);
 #endif
 
        Ratio::setup_ratios ();
@@ -424,6 +425,8 @@ LIBDCP_ENABLE_WARNINGS
        curl_global_init (CURL_GLOBAL_ALL);
 
        ui_thread = boost::this_thread::get_id ();
+
+       capture_asdcp_logs ();
 }
 
 #ifdef DCPOMATIC_WINDOWS
@@ -591,14 +594,14 @@ short_audio_channel_name (int c)
                _("Rs"),
                _("HI"),
                _("VI"),
-               _("Lc"),
-               _("Rc"),
+               _("9"),
+               _("10"),
                _("BsL"),
                _("BsR"),
                _("DBP"),
                _("DBS"),
                _("Sign"),
-               ""
+               _("16")
        };
 
        return channels[c];
@@ -705,44 +708,47 @@ split_get_request (string url)
        return r;
 }
 
+
+static
 string
-video_asset_filename (shared_ptr<dcp::PictureAsset> asset, int reel_index, int reel_count, optional<string> summary)
+asset_filename (shared_ptr<dcp::Asset> asset, string type, int reel_index, int reel_count, optional<string> summary, string extension)
 {
        dcp::NameFormat::Map values;
-       values['t'] = "j2c";
-       values['r'] = raw_convert<string> (reel_index + 1);
-       values['n'] = raw_convert<string> (reel_count);
+       values['t'] = type;
+       values['r'] = raw_convert<string>(reel_index + 1);
+       values['n'] = raw_convert<string>(reel_count);
        if (summary) {
-               values['c'] = careful_string_filter (summary.get());
+               values['c'] = careful_string_filter(summary.get());
        }
-       return Config::instance()->dcp_asset_filename_format().get(values, "_" + asset->id() + ".mxf");
+       return Config::instance()->dcp_asset_filename_format().get(values, "_" + asset->id() + extension);
+}
+
+
+string
+video_asset_filename (shared_ptr<dcp::PictureAsset> asset, int reel_index, int reel_count, optional<string> summary)
+{
+       return asset_filename(asset, "j2c", reel_index, reel_count, summary, ".mxf");
 }
 
+
 string
 audio_asset_filename (shared_ptr<dcp::SoundAsset> asset, int reel_index, int reel_count, optional<string> summary)
 {
-       dcp::NameFormat::Map values;
-       values['t'] = "pcm";
-       values['r'] = raw_convert<string> (reel_index + 1);
-       values['n'] = raw_convert<string> (reel_count);
-       if (summary) {
-               values['c'] = careful_string_filter (summary.get());
-       }
-       return Config::instance()->dcp_asset_filename_format().get(values, "_" + asset->id() + ".mxf");
+       return asset_filename(asset, "pcm", reel_index, reel_count, summary, ".mxf");
+}
+
+
+string
+subtitle_asset_filename (shared_ptr<dcp::SubtitleAsset> asset, int reel_index, int reel_count, optional<string> summary, string extension)
+{
+       return asset_filename(asset, "sub", reel_index, reel_count, summary, extension);
 }
 
 
 string
 atmos_asset_filename (shared_ptr<dcp::AtmosAsset> asset, int reel_index, int reel_count, optional<string> summary)
 {
-       dcp::NameFormat::Map values;
-       values['t'] = "atmos";
-       values['r'] = raw_convert<string> (reel_index + 1);
-       values['n'] = raw_convert<string> (reel_count);
-       if (summary) {
-               values['c'] = careful_string_filter (summary.get());
-       }
-       return Config::instance()->dcp_asset_filename_format().get(values, "_" + asset->id() + ".mxf");
+       return asset_filename(asset, "atmos", reel_index, reel_count, summary, ".mxf");
 }
 
 
@@ -791,7 +797,7 @@ careful_string_filter (string s)
        /* Then remove anything that's not in a very limited character set */
        wstring out;
        wstring const allowed = L"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_%.+";
-       for (size_t i = 0; i < transliterated_more.length(); ++i) {
+       for (int i = 0; i < transliterated_more.length(); ++i) {
                wchar_t c = transliterated_more[i];
                if (allowed.find(c) != string::npos) {
                        out += c;
@@ -1115,6 +1121,9 @@ default_font_file ()
        if (!boost::filesystem::exists(liberation_normal)) {
                liberation_normal = "/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf";
        }
+       if (!boost::filesystem::exists(liberation_normal)) {
+               liberation_normal = "/usr/share/fonts/liberation-sans/LiberationSans-Regular.ttf";
+       }
 
        return liberation_normal;
 }
@@ -1145,3 +1154,36 @@ start_of_thread (string)
 }
 #endif
 
+
+class LogSink : public Kumu::ILogSink
+{
+public:
+       LogSink () {}
+       LogSink (LogSink const&) = delete;
+       LogSink& operator= (LogSink const&) = delete;
+
+       void WriteEntry(const Kumu::LogEntry& entry) override {
+               Kumu::AutoMutex L(m_lock);
+               WriteEntryToListeners(entry);
+               if (entry.TestFilter(m_filter)) {
+                       string buffer;
+                       entry.CreateStringWithOptions(buffer, m_options);
+                       LOG_GENERAL("asdcplib: %1", buffer);
+               }
+       }
+};
+
+
+void
+capture_asdcp_logs ()
+{
+       static LogSink log_sink;
+       Kumu::SetDefaultLogSink(&log_sink);
+}
+
+
+string
+error_details(boost::system::error_code ec)
+{
+       return String::compose("%1:%2:%3", ec.category().name(), ec.value(), ec.message());
+}