display: fix comparison of X11 display names.
authorGwenole Beauchesne <gwenole.beauchesne@intel.com>
Fri, 25 Jul 2014 08:55:53 +0000 (10:55 +0200)
committerGwenole Beauchesne <gwenole.beauchesne@intel.com>
Fri, 25 Jul 2014 15:35:53 +0000 (17:35 +0200)
Make sure to not only compare display host names, but also the actual
display number. The screen number does not need to be checked at this
time.

gst-libs/gst/vaapi/gstvaapidisplay_x11.c

index ba9ea26..9d4dfd0 100644 (file)
 static const guint g_display_types =
     (1U << GST_VAAPI_DISPLAY_TYPE_X11) | (1U << GST_VAAPI_DISPLAY_TYPE_GLX);
 
-static inline const gchar *
-get_default_display_name (void)
+static gboolean
+parse_display_name (const gchar * name, guint * len_ptr, guint * id_ptr,
+    guint * screen_ptr)
 {
-  static const gchar *g_display_name;
+  gulong len, id = 0, screen = 0;
+  gchar *end;
 
-  if (!g_display_name)
-    g_display_name = getenv ("DISPLAY");
-  return g_display_name;
+  end = strchr (name, ':');
+  len = end ? end - name : strlen (name);
+
+  if (end) {
+    id = strtoul (&end[1], &end, 10);
+    if (*end == '.')
+      screen = strtoul (&end[1], &end, 10);
+    if (*end != '\0')
+      return FALSE;
+  }
+
+  if (len_ptr)
+    *len_ptr = len;
+  if (id_ptr)
+    *id_ptr = id;
+  if (screen_ptr)
+    *screen_ptr = screen;
+  return TRUE;
 }
 
 static gint
 compare_display_name (gconstpointer a, gconstpointer b)
 {
   const GstVaapiDisplayInfo *const info = a;
-  const gchar *cached_name = info->display_name, *cached_name_end;
-  const gchar *tested_name = b, *tested_name_end;
-  guint cached_name_length, tested_name_length;
+  const gchar *const cached_name = info->display_name;
+  const gchar *const tested_name = b;
+  guint cached_name_length, cached_id;
+  guint tested_name_length, tested_id;
 
   g_return_val_if_fail (cached_name, FALSE);
   g_return_val_if_fail (tested_name, FALSE);
 
-  cached_name_end = strchr (cached_name, ':');
-  if (cached_name_end)
-    cached_name_length = cached_name_end - cached_name;
-  else
-    cached_name_length = strlen (cached_name);
-
-  tested_name_end = strchr (tested_name, ':');
-  if (tested_name_end)
-    tested_name_length = tested_name_end - tested_name;
-  else
-    tested_name_length = strlen (tested_name);
-
+  if (!parse_display_name (cached_name, &cached_name_length, &cached_id, NULL))
+    return FALSE;
+  if (!parse_display_name (tested_name, &tested_name_length, &tested_id, NULL))
+    return FALSE;
   if (cached_name_length != tested_name_length)
     return FALSE;
   if (strncmp (cached_name, tested_name, cached_name_length) != 0)
     return FALSE;
-
-  /* XXX: handle screen number? */
+  if (cached_id != tested_id)
+    return FALSE;
   return TRUE;
 }
 
+static inline const gchar *
+get_default_display_name (void)
+{
+  static const gchar *g_display_name;
+
+  if (!g_display_name)
+    g_display_name = getenv ("DISPLAY");
+  return g_display_name;
+}
+
 /* Reconstruct a display name without our prefix */
 static const gchar *
 get_display_name (GstVaapiDisplayX11 * display)