[FFmpeg-cvslog] avutil/log: add support for multibyte console log for win32

Marton Balint git at videolan.org
Sun Feb 9 21:48:09 EET 2020


ffmpeg | branch: master | Marton Balint <cus at passwd.hu> | Wed Jan 29 01:10:38 2020 +0100| [cbf2a9bfac60e400980b503061922aedeedd9e28] | committer: Marton Balint

avutil/log: add support for multibyte console log for win32

Fixes ticket #5398.

Signed-off-by: Marton Balint <cus at passwd.hu>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=cbf2a9bfac60e400980b503061922aedeedd9e28
---

 libavutil/log.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/libavutil/log.c b/libavutil/log.c
index 213594c2a5..78e703b9e9 100644
--- a/libavutil/log.c
+++ b/libavutil/log.c
@@ -120,6 +120,31 @@ static const uint32_t color[16 + AV_CLASS_CATEGORY_NB] = {
 #endif
 static int use_color = -1;
 
+#if defined(_WIN32) && HAVE_SETCONSOLETEXTATTRIBUTE && HAVE_GETSTDHANDLE
+static void win_console_puts(const char *str)
+{
+    const uint8_t *q = str;
+    uint16_t line[LINE_SZ];
+
+    while (*q) {
+        uint16_t *buf = line;
+        DWORD nb_chars = 0;
+        DWORD written;
+
+        while (*q && nb_chars < LINE_SZ - 1) {
+            uint32_t ch;
+            uint16_t tmp;
+
+            GET_UTF8(ch, *q ? *q++ : 0, ch = 0xfffd; goto continue_on_invalid;)
+continue_on_invalid:
+            PUT_UTF16(ch, tmp, *buf++ = tmp; nb_chars++;)
+        }
+
+        WriteConsoleW(con, line, nb_chars, &written, NULL);
+    }
+}
+#endif
+
 static void check_color_terminal(void)
 {
     char *term = getenv("TERM");
@@ -195,7 +220,7 @@ static void colored_fputs(int level, int tint, const char *str)
     if (con != INVALID_HANDLE_VALUE) {
         if (local_use_color)
             SetConsoleTextAttribute(con, background | color[level]);
-        fputs(str, stderr);
+        win_console_puts(str);
         if (local_use_color)
             SetConsoleTextAttribute(con, attr_orig);
     } else {



More information about the ffmpeg-cvslog mailing list