display: make it possible to lookup the display cache by type.

Make it possible to add extra an extra filter to most of display cache
lookup functions so that the GstVaapiDisplay instance can really match
a compatible and existing display by type, instead of relying on extra
string tags (e.g. "X11:" prefix, etc.).
This commit is contained in:
Gwenole Beauchesne 2013-05-27 13:17:31 +02:00
parent c957823e8a
commit 71ab07d9c6
7 changed files with 87 additions and 22 deletions

View file

@ -42,6 +42,8 @@
#define NAME_PREFIX "DRM:"
#define NAME_PREFIX_LENGTH 4
static const guint g_display_types = 1U << GST_VAAPI_DISPLAY_TYPE_DRM;
static inline gboolean
is_device_path(const gchar *device_path)
{
@ -239,7 +241,8 @@ gst_vaapi_display_drm_open_display(GstVaapiDisplay *display, const gchar *name)
if (!set_device_path(display, name))
return FALSE;
info = gst_vaapi_display_cache_lookup_by_name(cache, priv->device_path);
info = gst_vaapi_display_cache_lookup_by_name(cache, priv->device_path,
GST_VAAPI_DISPLAY_TYPES(display));
if (info) {
priv->drm_device = GPOINTER_TO_INT(info->native_display);
priv->use_foreign_display = TRUE;
@ -290,7 +293,8 @@ gst_vaapi_display_drm_get_display_info(GstVaapiDisplay *display,
if (!cache)
return FALSE;
cached_info = gst_vaapi_display_cache_lookup_by_native_display(
cache, GINT_TO_POINTER(priv->drm_device));
cache, GINT_TO_POINTER(priv->drm_device),
GST_VAAPI_DISPLAY_TYPES(display));
if (cached_info) {
*info = *cached_info;
return TRUE;
@ -327,6 +331,7 @@ gst_vaapi_display_drm_class_init(GstVaapiDisplayDRMClass *klass)
gst_vaapi_display_class_init(&klass->parent_class);
object_class->size = sizeof(GstVaapiDisplayDRM);
dpy_class->display_types = g_display_types;
dpy_class->init = gst_vaapi_display_drm_init;
dpy_class->bind_display = gst_vaapi_display_drm_bind_display;
dpy_class->open_display = gst_vaapi_display_drm_open_display;

View file

@ -37,6 +37,8 @@
#define DEBUG 1
#include "gstvaapidebug.h"
static const guint g_display_types = 1U << GST_VAAPI_DISPLAY_TYPE_GLX;
static gboolean
gst_vaapi_display_glx_get_display_info(
GstVaapiDisplay *display,
@ -64,6 +66,7 @@ gst_vaapi_display_glx_class_init(GstVaapiDisplayGLXClass *klass)
object_class->size = sizeof(GstVaapiDisplayGLX);
klass->parent_get_display = dpy_class->get_display;
dpy_class->display_types = g_display_types;
dpy_class->get_display = gst_vaapi_display_glx_get_display_info;
}

View file

@ -96,6 +96,16 @@ typedef void (*GstVaapiDisplayGetSizeMFunc)(GstVaapiDisplay *display,
#define GST_VAAPI_DISPLAY_UNLOCK(display) \
gst_vaapi_display_unlock(GST_VAAPI_DISPLAY_CAST(display))
/**
* GST_VAAPI_DISPLAY_TYPES:
* @display: a #GstVaapiDisplay
*
* Returns compatible @display types as a set of flags
*/
#undef GST_VAAPI_DISPLAY_TYPES
#define GST_VAAPI_DISPLAY_TYPES(display) \
gst_vaapi_display_get_display_types(GST_VAAPI_DISPLAY_CAST(display))
struct _GstVaapiDisplayPrivate {
GstVaapiDisplay *parent;
GRecMutex mutex;
@ -145,6 +155,9 @@ struct _GstVaapiDisplayClass {
/*< private >*/
GstVaapiMiniObjectClass parent_class;
/*< protected >*/
guint display_types;
/*< public >*/
GstVaapiDisplayInitFunc init;
GstVaapiDisplayBindFunc bind_display;
@ -176,6 +189,15 @@ gst_vaapi_display_new(const GstVaapiDisplayClass *klass,
GstVaapiDisplayCache *
gst_vaapi_display_get_cache(void);
static inline guint
gst_vaapi_display_get_display_types(GstVaapiDisplay *display)
{
const GstVaapiDisplayClass * const dpy_class =
GST_VAAPI_DISPLAY_GET_CLASS(display);
return dpy_class->display_types;
}
/* Inline reference counting for core libgstvaapi library */
#ifdef GST_VAAPI_CORE
#define gst_vaapi_display_ref_internal(display) \

View file

@ -36,6 +36,8 @@
#define NAME_PREFIX "WLD:"
#define NAME_PREFIX_LENGTH 4
static const guint g_display_types = 1U << GST_VAAPI_DISPLAY_TYPE_WAYLAND;
static inline gboolean
is_display_name(const gchar *display_name)
{
@ -250,7 +252,7 @@ gst_vaapi_display_wayland_open_display(GstVaapiDisplay *display,
return FALSE;
info = gst_vaapi_display_cache_lookup_custom(cache, compare_display_name,
priv->display_name);
priv->display_name, GST_VAAPI_DISPLAY_TYPES(display));
if (info) {
priv->wl_display = info->native_display;
priv->use_foreign_display = TRUE;
@ -303,7 +305,7 @@ gst_vaapi_display_wayland_get_display_info(
if (!cache)
return FALSE;
cached_info = gst_vaapi_display_cache_lookup_by_native_display(cache,
priv->wl_display);
priv->wl_display, GST_VAAPI_DISPLAY_TYPES(display));
if (cached_info) {
*info = *cached_info;
return TRUE;
@ -380,6 +382,7 @@ gst_vaapi_display_wayland_class_init(GstVaapiDisplayWaylandClass * klass)
gst_vaapi_display_class_init(&klass->parent_class);
object_class->size = sizeof(GstVaapiDisplayWayland);
dpy_class->display_types = g_display_types;
dpy_class->init = gst_vaapi_display_wayland_init;
dpy_class->bind_display = gst_vaapi_display_wayland_bind_display;
dpy_class->open_display = gst_vaapi_display_wayland_open_display;

View file

@ -42,6 +42,10 @@
#define NAME_PREFIX "X11:"
#define NAME_PREFIX_LENGTH 4
static const guint g_display_types =
(1U << GST_VAAPI_DISPLAY_TYPE_X11) |
(1U << GST_VAAPI_DISPLAY_TYPE_GLX);
static inline gboolean
is_display_name(const gchar *display_name)
{
@ -198,7 +202,7 @@ gst_vaapi_display_x11_open_display(GstVaapiDisplay *base_display,
return FALSE;
info = gst_vaapi_display_cache_lookup_custom(cache, compare_display_name,
priv->display_name);
priv->display_name, GST_VAAPI_DISPLAY_TYPES(display));
if (info) {
priv->x11_display = info->native_display;
priv->use_foreign_display = TRUE;
@ -275,7 +279,7 @@ gst_vaapi_display_x11_get_display_info(
if (!cache)
return FALSE;
cached_info = gst_vaapi_display_cache_lookup_by_native_display(
cache, priv->x11_display);
cache, priv->x11_display, GST_VAAPI_DISPLAY_TYPES(display));
if (cached_info) {
*info = *cached_info;
return TRUE;
@ -380,6 +384,7 @@ gst_vaapi_display_x11_class_init(GstVaapiDisplayX11Class *klass)
gst_vaapi_display_class_init(&klass->parent_class);
object_class->size = sizeof(GstVaapiDisplayX11);
dpy_class->display_types = g_display_types;
dpy_class->bind_display = gst_vaapi_display_x11_bind_display;
dpy_class->open_display = gst_vaapi_display_x11_open_display;
dpy_class->close_display = gst_vaapi_display_x11_close_display;

View file

@ -83,15 +83,28 @@ error:
return NULL;
}
static inline gboolean
is_compatible_display_type(const GstVaapiDisplayType display_type,
guint display_types)
{
if (display_type == GST_VAAPI_DISPLAY_TYPE_ANY)
return TRUE;
if (display_types == GST_VAAPI_DISPLAY_TYPE_ANY)
return TRUE;
return ((1U << display_type) & display_types) != 0;
}
static GList *
cache_lookup_1(GstVaapiDisplayCache *cache, GCompareFunc func,
gconstpointer data)
gconstpointer data, guint display_types)
{
GList *l;
g_mutex_lock(&cache->mutex);
for (l = cache->list; l != NULL; l = l->next) {
GstVaapiDisplayInfo * const info = &((CacheEntry *)l->data)->info;
if (!is_compatible_display_type(info->display_type, display_types))
continue;
if (func(info, data))
break;
}
@ -101,9 +114,9 @@ cache_lookup_1(GstVaapiDisplayCache *cache, GCompareFunc func,
static inline const GstVaapiDisplayInfo *
cache_lookup(GstVaapiDisplayCache *cache, GCompareFunc func,
gconstpointer data)
gconstpointer data, guint display_types)
{
GList * const m = cache_lookup_1(cache, func, data);
GList * const m = cache_lookup_1(cache, func, data, display_types);
return m ? &((CacheEntry *)m->data)->info : NULL;
}
@ -256,7 +269,8 @@ gst_vaapi_display_cache_remove(
{
GList *m;
m = cache_lookup_1(cache, compare_display, display);
m = cache_lookup_1(cache, compare_display, display,
GST_VAAPI_DISPLAY_TYPE_ANY);
if (!m)
return;
@ -285,7 +299,8 @@ gst_vaapi_display_cache_lookup(
g_return_val_if_fail(cache != NULL, NULL);
g_return_val_if_fail(display != NULL, NULL);
return cache_lookup(cache, compare_display, display);
return cache_lookup(cache, compare_display, display,
GST_VAAPI_DISPLAY_TYPE_ANY);
}
/**
@ -308,13 +323,17 @@ gst_vaapi_display_cache_lookup(
* (i.e. returning %TRUE), or %NULL if none was found
*/
const GstVaapiDisplayInfo *
gst_vaapi_display_cache_lookup_custom(GstVaapiDisplayCache *cache,
GCompareFunc func, gconstpointer data)
gst_vaapi_display_cache_lookup_custom(
GstVaapiDisplayCache *cache,
GCompareFunc func,
gconstpointer data,
guint display_types
)
{
g_return_val_if_fail(cache != NULL, NULL);
g_return_val_if_fail(func != NULL, NULL);
return cache_lookup(cache, func, data);
return cache_lookup(cache, func, data, display_types);
}
/**
@ -336,7 +355,8 @@ gst_vaapi_display_cache_lookup_by_va_display(
g_return_val_if_fail(cache != NULL, NULL);
g_return_val_if_fail(va_display != NULL, NULL);
return cache_lookup(cache, compare_va_display, va_display);
return cache_lookup(cache, compare_va_display, va_display,
GST_VAAPI_DISPLAY_TYPE_ANY);
}
/**
@ -352,13 +372,15 @@ gst_vaapi_display_cache_lookup_by_va_display(
const GstVaapiDisplayInfo *
gst_vaapi_display_cache_lookup_by_native_display(
GstVaapiDisplayCache *cache,
gpointer native_display
gpointer native_display,
guint display_types
)
{
g_return_val_if_fail(cache != NULL, NULL);
g_return_val_if_fail(native_display != NULL, NULL);
return cache_lookup(cache, compare_native_display, native_display);
return cache_lookup(cache, compare_native_display, native_display,
display_types);
}
/**
@ -374,10 +396,12 @@ gst_vaapi_display_cache_lookup_by_native_display(
const GstVaapiDisplayInfo *
gst_vaapi_display_cache_lookup_by_name(
GstVaapiDisplayCache *cache,
const gchar *display_name
const gchar *display_name,
guint display_types
)
{
g_return_val_if_fail(cache != NULL, NULL);
return cache_lookup(cache, compare_display_name, display_name);
return cache_lookup(cache, compare_display_name, display_name,
display_types);
}

View file

@ -57,7 +57,8 @@ const GstVaapiDisplayInfo *
gst_vaapi_display_cache_lookup_custom(
GstVaapiDisplayCache *cache,
GCompareFunc func,
gconstpointer data
gconstpointer data,
guint display_types
);
const GstVaapiDisplayInfo *
@ -69,13 +70,15 @@ gst_vaapi_display_cache_lookup_by_va_display(
const GstVaapiDisplayInfo *
gst_vaapi_display_cache_lookup_by_native_display(
GstVaapiDisplayCache *cache,
gpointer native_display
gpointer native_display,
guint display_types
);
const GstVaapiDisplayInfo *
gst_vaapi_display_cache_lookup_by_name(
GstVaapiDisplayCache *cache,
const gchar *display_name
const gchar *display_name,
guint display_types
);
#endif /* GSTVAAPIDISPLAYCACHE_H */