diff mbox series

[FFmpeg-devel] libavdevice/gdigrab: fix capture window title contain non-ASCII chars

Message ID tencent_43ED2E0911C0B17B972CDCBC8DF2639E3A0A@qq.com
State New
Headers show
Series [FFmpeg-devel] libavdevice/gdigrab: fix capture window title contain non-ASCII chars
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

1160386205@qq.com March 19, 2021, 6:13 p.m. UTC
From: He Yang <1160386205@qq.com>

Signed-off-by: He Yang <1160386205@qq.com>
---
 libavdevice/gdigrab.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/libavdevice/gdigrab.c b/libavdevice/gdigrab.c
index 9b2c55fe90..ff4055c925 100644
--- a/libavdevice/gdigrab.c
+++ b/libavdevice/gdigrab.c
@@ -230,9 +230,10 @@  gdigrab_read_header(AVFormatContext *s1)
     HBITMAP hbmp   = NULL;
     void *buffer   = NULL;
 
-    const char *filename = s1->url;
-    const char *name     = NULL;
-    AVStream   *st       = NULL;
+    const char *filename  = s1->url;
+    const char *name      = NULL;
+    const wchar_t *name_w = NULL;
+    AVStream   *st        = NULL;
 
     int bpp;
     int horzres;
@@ -246,7 +247,17 @@  gdigrab_read_header(AVFormatContext *s1)
 
     if (!strncmp(filename, "title=", 6)) {
         name = filename + 6;
-        hwnd = FindWindow(NULL, name);
+        if(utf8towchar(name, &name_w)) {
+            ret = AVERROR(ENOMEM);
+            goto error;
+        }
+        if(!name_w) {
+            ret = AVERROR(EINVAL);
+            goto error;
+        }
+        hwnd = FindWindowW(NULL, name_w);
+        av_free(name_w);
+        name_w = NULL;
         if (!hwnd) {
             av_log(s1, AV_LOG_ERROR,
                    "Can't find window '%s', aborting.\n", name);