X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Futil.cc;h=20a96578144109bd613cbf2a98f6f5cb6df0ff18;hb=a31cfda11a8e3260cdf267be056cb9b4f4b158dd;hp=bab74583c52248d9cdd6fe569c3fba12468ba864;hpb=e571e2c52e93e0dc794a620a7bb6a67f4cf0adb2;p=dcpomatic.git diff --git a/src/lib/util.cc b/src/lib/util.cc index bab74583c..20a965781 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -47,6 +47,7 @@ #include "ratio.h" #include "rect.h" #include "render_text.h" +#include "scope_guard.h" #include "string_text.h" #include "text_decoder.h" #include "util.h" @@ -73,6 +74,7 @@ LIBDCP_ENABLE_WARNINGS #include #include #include +#include #include #include #include @@ -388,6 +390,31 @@ capture_asdcp_logs () } +static +void +ffmpeg_log_callback(void* ptr, int level, const char* fmt, va_list vl) +{ + if (level > AV_LOG_WARNING) { + return; + } + + char line[1024]; + static int prefix = 0; + av_log_format_line(ptr, level, fmt, vl, line, sizeof (line), &prefix); + string str(line); + boost::algorithm::trim(str); + dcpomatic_log->log(String::compose("FFmpeg: %1", str), LogEntry::TYPE_GENERAL); +} + + +static +void +capture_ffmpeg_logs() +{ + av_log_set_callback(ffmpeg_log_callback); +} + + /** Call the required functions to set up DCP-o-matic's static arrays, etc. * Must be called from the UI thread, if there is one. */ @@ -455,6 +482,7 @@ LIBDCP_ENABLE_WARNINGS ui_thread = boost::this_thread::get_id (); capture_asdcp_logs (); + capture_ffmpeg_logs(); } #ifdef DCPOMATIC_WINDOWS @@ -1053,3 +1081,38 @@ contains_assetmap(boost::filesystem::path dir) return boost::filesystem::is_regular_file(dir / "ASSETMAP") || boost::filesystem::is_regular_file(dir / "ASSETMAP.xml"); } + +string +word_wrap(string input, int columns) +{ + icu::Locale locale; + UErrorCode status = U_ZERO_ERROR; + auto iter = icu::BreakIterator::createLineInstance(locale, status); + ScopeGuard sg = [iter]() { delete iter; }; + if (U_FAILURE(status)) { + return input; + } + + auto input_icu = icu::UnicodeString::fromUTF8(icu::StringPiece(input)); + iter->setText(input_icu); + + int position = 0; + string output; + while (position < input_icu.length()) { + int end_of_line = iter->preceding(position + columns + 1); + icu::UnicodeString line; + if (end_of_line <= position) { + /* There's no good line-break position; just break in the middle of a word */ + line = input_icu.tempSubString(position, columns); + position += columns; + } else { + line = input_icu.tempSubString(position, end_of_line - position); + position = end_of_line; + } + line.toUTF8String(output); + output += "\n"; + } + + return output; +} +