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.
This commit is contained in:
Gwenole Beauchesne 2014-07-25 10:55:53 +02:00
parent cafb25c4d1
commit 39ab75becd

View file

@ -48,6 +48,58 @@
static const guint g_display_types =
(1U << GST_VAAPI_DISPLAY_TYPE_X11) | (1U << GST_VAAPI_DISPLAY_TYPE_GLX);
static gboolean
parse_display_name (const gchar * name, guint * len_ptr, guint * id_ptr,
guint * screen_ptr)
{
gulong len, id = 0, screen = 0;
gchar *end;
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 *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);
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;
if (cached_id != tested_id)
return FALSE;
return TRUE;
}
static inline const gchar *
get_default_display_name (void)
{
@ -58,38 +110,6 @@ get_default_display_name (void)
return g_display_name;
}
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;
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 (cached_name_length != tested_name_length)
return FALSE;
if (strncmp (cached_name, tested_name, cached_name_length) != 0)
return FALSE;
/* XXX: handle screen number? */
return TRUE;
}
/* Reconstruct a display name without our prefix */
static const gchar *
get_display_name (GstVaapiDisplayX11 * display)