avdevice/xcbgrab: Fix offset support
authorMichael Niedermayer <michaelni@gmx.at>
Thu, 30 Oct 2014 11:48:05 +0000 (12:48 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Thu, 30 Oct 2014 13:34:07 +0000 (14:34 +0100)
Found-by: carl
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
libavdevice/xcbgrab.c

index b162763..2fdb992 100644 (file)
@@ -491,7 +491,6 @@ static int create_stream(AVFormatContext *s)
 {
     XCBGrabContext *c = s->priv_data;
     AVStream *st      = avformat_new_stream(s, NULL);
-    const char *opts  = strchr(s->filename, '+');
     xcb_get_geometry_cookie_t gc;
     xcb_get_geometry_reply_t *geo;
     int ret;
@@ -507,9 +506,6 @@ static int create_stream(AVFormatContext *s)
     if (ret < 0)
         return ret;
 
-    if (opts)
-        sscanf(opts, "%d,%d", &c->x, &c->y);
-
     avpriv_set_pts_info(st, 64, 1, 1000000);
 
     gc  = xcb_get_geometry(c->conn, c->screen->root);
@@ -598,8 +594,20 @@ static av_cold int xcbgrab_read_header(AVFormatContext *s)
     XCBGrabContext *c = s->priv_data;
     int screen_num, ret;
     const xcb_setup_t *setup;
+    char *display_name = av_strdup(s->filename);
+
+    if (s->filename) {
+        if (!display_name)
+            return AVERROR(ENOMEM);
+
+        if (!sscanf(s->filename, "%[^+]+%d,%d", display_name, &c->x, &c->y)) {
+            *display_name = 0;
+            sscanf(s->filename, "+%d,%d", &c->x, &c->y);
+        }
+    }
 
-    c->conn = xcb_connect(s->filename, &screen_num);
+    c->conn = xcb_connect(display_name, &screen_num);
+    av_freep(&display_name);
     if ((ret = xcb_connection_has_error(c->conn))) {
         av_log(s, AV_LOG_ERROR, "Cannot open display %s, error %d.\n",
                s->filename ? s->filename : "default", ret);