From 39ab75becd530d5879d2c985c8ec1f9010ad973d Mon Sep 17 00:00:00 2001 From: Gwenole Beauchesne Date: Fri, 25 Jul 2014 10:55:53 +0200 Subject: [PATCH] display: fix comparison of X11 display names. 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 | 66 +++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 23 deletions(-) diff --git a/gst-libs/gst/vaapi/gstvaapidisplay_x11.c b/gst-libs/gst/vaapi/gstvaapidisplay_x11.c index ba9ea26..9d4dfd0 100644 --- a/gst-libs/gst/vaapi/gstvaapidisplay_x11.c +++ b/gst-libs/gst/vaapi/gstvaapidisplay_x11.c @@ -48,48 +48,68 @@ 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) -- 2.7.4