mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 20:21:24 +00:00
libs: display: remove cache
Remove a bunch of code that handles the VADisplay cache, since the context sharing should be doing this correctly. https://bugzilla.gnome.org/show_bug.cgi?id=747946
This commit is contained in:
parent
dd78e03859
commit
ec3e10f666
8 changed files with 16 additions and 758 deletions
|
@ -58,7 +58,6 @@ libgstvaapi_source_c = \
|
|||
gstvaapidecoder_unit.c \
|
||||
gstvaapidecoder_vc1.c \
|
||||
gstvaapidisplay.c \
|
||||
gstvaapidisplaycache.c \
|
||||
gstvaapifilter.c \
|
||||
gstvaapiimage.c \
|
||||
gstvaapiimagepool.c \
|
||||
|
@ -130,7 +129,6 @@ libgstvaapi_source_priv_h = \
|
|||
gstvaapidecoder_priv.h \
|
||||
gstvaapidecoder_unit.h \
|
||||
gstvaapidisplay_priv.h \
|
||||
gstvaapidisplaycache.h \
|
||||
gstvaapiimage_priv.h \
|
||||
gstvaapiminiobject.h \
|
||||
gstvaapiobject_priv.h \
|
||||
|
|
|
@ -95,9 +95,6 @@ enum
|
|||
N_PROPERTIES
|
||||
};
|
||||
|
||||
static GstVaapiDisplayCache *g_display_cache;
|
||||
static GMutex g_display_cache_lock;
|
||||
|
||||
static GParamSpec *g_properties[N_PROPERTIES] = { NULL, };
|
||||
|
||||
static void gst_vaapi_display_properties_init (void);
|
||||
|
@ -130,29 +127,6 @@ libgstvaapi_init_once (void)
|
|||
g_once_init_leave (&g_once, TRUE);
|
||||
}
|
||||
|
||||
static GstVaapiDisplayCache *
|
||||
get_display_cache (void)
|
||||
{
|
||||
GstVaapiDisplayCache *cache = NULL;
|
||||
|
||||
g_mutex_lock (&g_display_cache_lock);
|
||||
if (!g_display_cache)
|
||||
g_display_cache = gst_vaapi_display_cache_new ();
|
||||
if (g_display_cache)
|
||||
cache = gst_vaapi_display_cache_ref (g_display_cache);
|
||||
g_mutex_unlock (&g_display_cache_lock);
|
||||
return cache;
|
||||
}
|
||||
|
||||
static void
|
||||
free_display_cache (void)
|
||||
{
|
||||
g_mutex_lock (&g_display_cache_lock);
|
||||
if (g_display_cache && gst_vaapi_display_cache_is_empty (g_display_cache))
|
||||
gst_vaapi_display_cache_replace (&g_display_cache, NULL);
|
||||
g_mutex_unlock (&g_display_cache_lock);
|
||||
}
|
||||
|
||||
/* GstVaapiDisplayType enumerations */
|
||||
GType
|
||||
gst_vaapi_display_type_get_type (void)
|
||||
|
@ -874,14 +848,6 @@ gst_vaapi_display_destroy (GstVaapiDisplay * display)
|
|||
priv->vendor_string = NULL;
|
||||
|
||||
gst_vaapi_display_replace_internal (&priv->parent, NULL);
|
||||
|
||||
if (priv->cache) {
|
||||
gst_vaapi_display_cache_lock (priv->cache);
|
||||
gst_vaapi_display_cache_remove (priv->cache, display);
|
||||
gst_vaapi_display_cache_unlock (priv->cache);
|
||||
}
|
||||
gst_vaapi_display_cache_replace (&priv->cache, NULL);
|
||||
free_display_cache ();
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -892,7 +858,6 @@ gst_vaapi_display_create_unlocked (GstVaapiDisplay * display,
|
|||
const GstVaapiDisplayClass *const klass =
|
||||
GST_VAAPI_DISPLAY_GET_CLASS (display);
|
||||
GstVaapiDisplayInfo info;
|
||||
const GstVaapiDisplayInfo *cached_info = NULL;
|
||||
|
||||
memset (&info, 0, sizeof (info));
|
||||
info.display = display;
|
||||
|
@ -928,23 +893,11 @@ gst_vaapi_display_create_unlocked (GstVaapiDisplay * display,
|
|||
if (!priv->display)
|
||||
return FALSE;
|
||||
|
||||
cached_info = gst_vaapi_display_cache_lookup_by_va_display (priv->cache,
|
||||
info.va_display);
|
||||
if (cached_info) {
|
||||
gst_vaapi_display_replace_internal (&priv->parent, cached_info->display);
|
||||
priv->display_type = cached_info->display_type;
|
||||
}
|
||||
|
||||
if (!priv->parent) {
|
||||
if (!vaapi_initialize (priv->display))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!cached_info) {
|
||||
if (!gst_vaapi_display_cache_add (priv->cache, &info))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
GST_INFO_OBJECT (display, "new display addr=%p", display);
|
||||
g_free (priv->display_name);
|
||||
priv->display_name = g_strdup (info.display_name);
|
||||
|
@ -955,20 +908,7 @@ static gboolean
|
|||
gst_vaapi_display_create (GstVaapiDisplay * display,
|
||||
GstVaapiDisplayInitType init_type, gpointer init_value)
|
||||
{
|
||||
GstVaapiDisplayPrivate *const priv = GST_VAAPI_DISPLAY_GET_PRIVATE (display);
|
||||
GstVaapiDisplayCache *cache;
|
||||
gboolean success;
|
||||
|
||||
cache = get_display_cache ();
|
||||
if (!cache)
|
||||
return FALSE;
|
||||
gst_vaapi_display_cache_replace (&priv->cache, cache);
|
||||
gst_vaapi_display_cache_unref (cache);
|
||||
|
||||
gst_vaapi_display_cache_lock (cache);
|
||||
success = gst_vaapi_display_create_unlocked (display, init_type, init_value);
|
||||
gst_vaapi_display_cache_unlock (cache);
|
||||
return success;
|
||||
return gst_vaapi_display_create_unlocked (display, init_type, init_value);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -1128,16 +1068,6 @@ error:
|
|||
GstVaapiDisplay *
|
||||
gst_vaapi_display_new_with_display (VADisplay va_display)
|
||||
{
|
||||
GstVaapiDisplayCache *const cache = get_display_cache ();
|
||||
const GstVaapiDisplayInfo *info;
|
||||
|
||||
g_return_val_if_fail (va_display != NULL, NULL);
|
||||
g_return_val_if_fail (cache != NULL, NULL);
|
||||
|
||||
info = gst_vaapi_display_cache_lookup_by_va_display (cache, va_display);
|
||||
if (info)
|
||||
return gst_vaapi_display_ref_internal (info->display);
|
||||
|
||||
return gst_vaapi_display_new (g_object_new (GST_TYPE_VAAPI_DISPLAY, NULL),
|
||||
GST_VAAPI_DISPLAY_INIT_FROM_VA_DISPLAY, va_display);
|
||||
}
|
||||
|
|
|
@ -48,8 +48,6 @@
|
|||
G_DEFINE_TYPE_WITH_CODE (GstVaapiDisplayDRM, gst_vaapi_display_drm,
|
||||
GST_TYPE_VAAPI_DISPLAY, _do_init);
|
||||
|
||||
static const guint g_display_types = 1U << GST_VAAPI_DISPLAY_TYPE_DRM;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
DRM_DEVICE_LEGACY = 1,
|
||||
|
@ -265,23 +263,15 @@ gst_vaapi_display_drm_open_display (GstVaapiDisplay * display,
|
|||
{
|
||||
GstVaapiDisplayDRMPrivate *const priv =
|
||||
GST_VAAPI_DISPLAY_DRM_PRIVATE (display);
|
||||
GstVaapiDisplayCache *const cache = GST_VAAPI_DISPLAY_CACHE (display);
|
||||
const GstVaapiDisplayInfo *info;
|
||||
|
||||
if (!set_device_path (display, name))
|
||||
return FALSE;
|
||||
|
||||
info = gst_vaapi_display_cache_lookup_by_name (cache, priv->device_path,
|
||||
g_display_types);
|
||||
if (info) {
|
||||
priv->drm_device = GPOINTER_TO_INT (info->native_display);
|
||||
priv->use_foreign_display = TRUE;
|
||||
} else {
|
||||
priv->drm_device = open (get_device_path (display), O_RDWR | O_CLOEXEC);
|
||||
if (priv->drm_device < 0)
|
||||
return FALSE;
|
||||
priv->use_foreign_display = FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -314,18 +304,7 @@ gst_vaapi_display_drm_get_display_info (GstVaapiDisplay * display,
|
|||
{
|
||||
GstVaapiDisplayDRMPrivate *const priv =
|
||||
GST_VAAPI_DISPLAY_DRM_PRIVATE (display);
|
||||
GstVaapiDisplayCache *const cache = GST_VAAPI_DISPLAY_CACHE (display);
|
||||
const GstVaapiDisplayInfo *cached_info;
|
||||
|
||||
/* Return any cached info even if child has its own VA display */
|
||||
cached_info = gst_vaapi_display_cache_lookup_by_native_display (cache,
|
||||
GINT_TO_POINTER (priv->drm_device), g_display_types);
|
||||
if (cached_info) {
|
||||
*info = *cached_info;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Otherwise, create VA display if there is none already */
|
||||
info->native_display = GINT_TO_POINTER (priv->drm_device);
|
||||
info->display_name = priv->device_path;
|
||||
if (!info->va_display) {
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
#define GST_VAAPI_DISPLAY_PRIV_H
|
||||
|
||||
#include <gst/vaapi/gstvaapidisplay.h>
|
||||
#include <gst/vaapi/gstvaapidisplaycache.h>
|
||||
#include <gst/vaapi/gstvaapiwindow.h>
|
||||
#include <gst/vaapi/gstvaapitexture.h>
|
||||
#include <gst/vaapi/gstvaapitexturemap.h>
|
||||
|
@ -108,21 +107,9 @@ typedef enum _GstVaapiDisplayInitType GstVaapiDisplayInitType;
|
|||
#define GST_VAAPI_DISPLAY_HAS_VPP(display) \
|
||||
gst_vaapi_display_has_video_processing (GST_VAAPI_DISPLAY_CAST (display))
|
||||
|
||||
/**
|
||||
* GST_VAAPI_DISPLAY_CACHE:
|
||||
* @display: a @GstVaapiDisplay
|
||||
*
|
||||
* Returns the #GstVaapiDisplayCache attached to the supplied @display object.
|
||||
* This is an internal macro that does not do any run-time type check.
|
||||
*/
|
||||
#undef GST_VAAPI_DISPLAY_CACHE
|
||||
#define GST_VAAPI_DISPLAY_CACHE(display) \
|
||||
(GST_VAAPI_DISPLAY_GET_PRIVATE (display)->cache)
|
||||
|
||||
struct _GstVaapiDisplayPrivate
|
||||
{
|
||||
GstVaapiDisplay *parent;
|
||||
GstVaapiDisplayCache *cache;
|
||||
GRecMutex mutex;
|
||||
GstVaapiDisplayType display_type;
|
||||
gchar *display_name;
|
||||
|
|
|
@ -42,8 +42,6 @@
|
|||
G_DEFINE_TYPE_WITH_CODE (GstVaapiDisplayWayland, gst_vaapi_display_wayland,
|
||||
GST_TYPE_VAAPI_DISPLAY, _do_init);
|
||||
|
||||
static const guint g_display_types = 1U << GST_VAAPI_DISPLAY_TYPE_WAYLAND;
|
||||
|
||||
static inline const gchar *
|
||||
get_default_display_name (void)
|
||||
{
|
||||
|
@ -54,39 +52,6 @@ get_default_display_name (void)
|
|||
return g_display_name;
|
||||
}
|
||||
|
||||
static inline guint
|
||||
get_display_name_length (const gchar * display_name)
|
||||
{
|
||||
const gchar *str;
|
||||
|
||||
str = strchr (display_name, '-');
|
||||
if (str)
|
||||
return str - display_name;
|
||||
return strlen (display_name);
|
||||
}
|
||||
|
||||
static gint
|
||||
compare_display_name (gconstpointer a, gconstpointer b)
|
||||
{
|
||||
const GstVaapiDisplayInfo *const info = a;
|
||||
const gchar *cached_name = info->display_name;
|
||||
const gchar *tested_name = b;
|
||||
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_length = get_display_name_length (cached_name);
|
||||
tested_name_length = get_display_name_length (tested_name);
|
||||
|
||||
/* XXX: handle screen number and default WAYLAND_DISPLAY name */
|
||||
if (cached_name_length != tested_name_length)
|
||||
return FALSE;
|
||||
if (strncmp (cached_name, tested_name, cached_name_length) != 0)
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Mangle display name with our prefix */
|
||||
static gboolean
|
||||
set_display_name (GstVaapiDisplay * display, const gchar * display_name)
|
||||
|
@ -211,29 +176,15 @@ gst_vaapi_display_wayland_open_display (GstVaapiDisplay * display,
|
|||
{
|
||||
GstVaapiDisplayWaylandPrivate *const priv =
|
||||
GST_VAAPI_DISPLAY_WAYLAND_GET_PRIVATE (display);
|
||||
GstVaapiDisplayCache *const cache = GST_VAAPI_DISPLAY_CACHE (display);
|
||||
const GstVaapiDisplayInfo *info;
|
||||
int dsp_error = 0;
|
||||
|
||||
if (!set_display_name (display, name))
|
||||
return FALSE;
|
||||
|
||||
info = gst_vaapi_display_cache_lookup_custom (cache, compare_display_name,
|
||||
priv->display_name, g_display_types);
|
||||
if (info) {
|
||||
wl_display_roundtrip (info->native_display);
|
||||
if ((dsp_error = wl_display_get_error (info->native_display)))
|
||||
GST_ERROR ("wayland display error detected: %d", dsp_error);
|
||||
}
|
||||
if (info && !dsp_error) {
|
||||
priv->wl_display = info->native_display;
|
||||
priv->use_foreign_display = TRUE;
|
||||
} else {
|
||||
priv->wl_display = wl_display_connect (name);
|
||||
if (!priv->wl_display)
|
||||
return FALSE;
|
||||
priv->use_foreign_display = FALSE;
|
||||
}
|
||||
|
||||
return gst_vaapi_display_wayland_setup (display);
|
||||
}
|
||||
|
||||
|
@ -281,18 +232,7 @@ gst_vaapi_display_wayland_get_display_info (GstVaapiDisplay * display,
|
|||
{
|
||||
GstVaapiDisplayWaylandPrivate *const priv =
|
||||
GST_VAAPI_DISPLAY_WAYLAND_GET_PRIVATE (display);
|
||||
GstVaapiDisplayCache *const cache = GST_VAAPI_DISPLAY_CACHE (display);
|
||||
const GstVaapiDisplayInfo *cached_info;
|
||||
|
||||
/* Return any cached info even if child has its own VA display */
|
||||
cached_info = gst_vaapi_display_cache_lookup_by_native_display (cache,
|
||||
priv->wl_display, g_display_types);
|
||||
if (cached_info) {
|
||||
*info = *cached_info;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Otherwise, create VA display if there is none already */
|
||||
info->native_display = priv->wl_display;
|
||||
info->display_name = priv->display_name;
|
||||
if (!info->va_display) {
|
||||
|
|
|
@ -52,60 +52,6 @@
|
|||
G_DEFINE_TYPE_WITH_CODE (GstVaapiDisplayX11, gst_vaapi_display_x11,
|
||||
GST_TYPE_VAAPI_DISPLAY, _do_init);
|
||||
|
||||
static const guint g_display_types = 1U << GST_VAAPI_DISPLAY_TYPE_X11;
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -203,23 +149,14 @@ gst_vaapi_display_x11_open_display (GstVaapiDisplay * base_display,
|
|||
GstVaapiDisplayX11 *const display = GST_VAAPI_DISPLAY_X11_CAST (base_display);
|
||||
GstVaapiDisplayX11Private *const priv = display->priv;
|
||||
|
||||
GstVaapiDisplayCache *const cache = GST_VAAPI_DISPLAY_CACHE (display);
|
||||
const GstVaapiDisplayInfo *info;
|
||||
|
||||
if (!set_display_name (display, name))
|
||||
return FALSE;
|
||||
|
||||
info = gst_vaapi_display_cache_lookup_custom (cache, compare_display_name,
|
||||
priv->display_name, g_display_types);
|
||||
if (info) {
|
||||
priv->x11_display = info->native_display;
|
||||
priv->use_foreign_display = TRUE;
|
||||
} else {
|
||||
priv->x11_display = XOpenDisplay (get_display_name (display));
|
||||
if (!priv->x11_display)
|
||||
return FALSE;
|
||||
priv->use_foreign_display = FALSE;
|
||||
}
|
||||
|
||||
priv->x11_screen = DefaultScreen (priv->x11_display);
|
||||
|
||||
check_extensions (display);
|
||||
|
@ -281,18 +218,7 @@ gst_vaapi_display_x11_get_display_info (GstVaapiDisplay * display,
|
|||
{
|
||||
GstVaapiDisplayX11Private *const priv =
|
||||
GST_VAAPI_DISPLAY_X11_PRIVATE (display);
|
||||
GstVaapiDisplayCache *const cache = GST_VAAPI_DISPLAY_CACHE (display);
|
||||
const GstVaapiDisplayInfo *cached_info;
|
||||
|
||||
/* Return any cached info even if child has its own VA display */
|
||||
cached_info = gst_vaapi_display_cache_lookup_by_native_display (cache,
|
||||
priv->x11_display, g_display_types);
|
||||
if (cached_info) {
|
||||
*info = *cached_info;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Otherwise, create VA display if there is none already */
|
||||
info->native_display = priv->x11_display;
|
||||
info->display_name = priv->display_name;
|
||||
if (!info->va_display) {
|
||||
|
|
|
@ -1,415 +0,0 @@
|
|||
/*
|
||||
* gstvaapidisplaycache.c - VA display cache
|
||||
*
|
||||
* Copyright (C) 2012-2013 Intel Corporation
|
||||
* Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "sysdeps.h"
|
||||
#include <glib.h>
|
||||
#include <string.h>
|
||||
#include "gstvaapidisplaycache.h"
|
||||
|
||||
#define DEBUG 1
|
||||
#include "gstvaapidebug.h"
|
||||
|
||||
typedef struct _CacheEntry CacheEntry;
|
||||
struct _CacheEntry
|
||||
{
|
||||
GstVaapiDisplayInfo info;
|
||||
};
|
||||
|
||||
struct _GstVaapiDisplayCache
|
||||
{
|
||||
GstVaapiMiniObject parent_instance;
|
||||
GRecMutex mutex;
|
||||
GList *list;
|
||||
};
|
||||
|
||||
static void
|
||||
cache_entry_free (CacheEntry * entry)
|
||||
{
|
||||
GstVaapiDisplayInfo *info;
|
||||
|
||||
if (!entry)
|
||||
return;
|
||||
|
||||
info = &entry->info;
|
||||
|
||||
if (info->display_name) {
|
||||
g_free (info->display_name);
|
||||
info->display_name = NULL;
|
||||
}
|
||||
g_slice_free (CacheEntry, entry);
|
||||
}
|
||||
|
||||
static CacheEntry *
|
||||
cache_entry_new (const GstVaapiDisplayInfo * di)
|
||||
{
|
||||
GstVaapiDisplayInfo *info;
|
||||
CacheEntry *entry;
|
||||
|
||||
entry = g_slice_new (CacheEntry);
|
||||
if (!entry)
|
||||
return NULL;
|
||||
|
||||
info = &entry->info;
|
||||
info->display = di->display;
|
||||
info->va_display = di->va_display;
|
||||
info->native_display = di->native_display;
|
||||
info->display_type = di->display_type;
|
||||
info->display_name = NULL;
|
||||
|
||||
if (di->display_name) {
|
||||
info->display_name = g_strdup (di->display_name);
|
||||
if (!info->display_name)
|
||||
goto error;
|
||||
}
|
||||
return entry;
|
||||
|
||||
/* ERRORS */
|
||||
error:
|
||||
{
|
||||
cache_entry_free (entry);
|
||||
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, guint display_types)
|
||||
{
|
||||
GList *l;
|
||||
|
||||
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;
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
static inline const GstVaapiDisplayInfo *
|
||||
cache_lookup (GstVaapiDisplayCache * cache, GCompareFunc func,
|
||||
gconstpointer data, guint display_types)
|
||||
{
|
||||
GList *const m = cache_lookup_1 (cache, func, data, display_types);
|
||||
|
||||
return m ? &((CacheEntry *) m->data)->info : NULL;
|
||||
}
|
||||
|
||||
static gint
|
||||
compare_display (gconstpointer a, gconstpointer display)
|
||||
{
|
||||
const GstVaapiDisplayInfo *const info = a;
|
||||
|
||||
return info->display == display;
|
||||
}
|
||||
|
||||
static gint
|
||||
compare_va_display (gconstpointer a, gconstpointer va_display)
|
||||
{
|
||||
const GstVaapiDisplayInfo *const info = a;
|
||||
|
||||
return info->va_display == va_display;
|
||||
}
|
||||
|
||||
static gint
|
||||
compare_native_display (gconstpointer a, gconstpointer native_display)
|
||||
{
|
||||
const GstVaapiDisplayInfo *const info = a;
|
||||
|
||||
return info->native_display == native_display;
|
||||
}
|
||||
|
||||
static gint
|
||||
compare_display_name (gconstpointer a, gconstpointer b)
|
||||
{
|
||||
const GstVaapiDisplayInfo *const info = a;
|
||||
const gchar *const display_name = b;
|
||||
|
||||
if (info->display_name == NULL && display_name == NULL)
|
||||
return TRUE;
|
||||
if (!info->display_name || !display_name)
|
||||
return FALSE;
|
||||
return strcmp (info->display_name, display_name) == 0;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_vaapi_display_cache_finalize (GstVaapiDisplayCache * cache)
|
||||
{
|
||||
GList *l;
|
||||
|
||||
if (cache->list) {
|
||||
for (l = cache->list; l != NULL; l = l->next)
|
||||
cache_entry_free (l->data);
|
||||
g_list_free (cache->list);
|
||||
cache->list = NULL;
|
||||
}
|
||||
g_rec_mutex_clear (&cache->mutex);
|
||||
}
|
||||
|
||||
static const GstVaapiMiniObjectClass *
|
||||
gst_vaapi_display_cache_class (void)
|
||||
{
|
||||
static const GstVaapiMiniObjectClass GstVaapiDisplayCacheClass = {
|
||||
.size = sizeof (GstVaapiDisplayCache),
|
||||
.finalize = (GDestroyNotify) gst_vaapi_display_cache_finalize
|
||||
};
|
||||
return &GstVaapiDisplayCacheClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_vaapi_display_cache_new:
|
||||
*
|
||||
* Creates a new VA display cache.
|
||||
*
|
||||
* Return value: the newly created #GstVaapiDisplayCache object
|
||||
*/
|
||||
GstVaapiDisplayCache *
|
||||
gst_vaapi_display_cache_new (void)
|
||||
{
|
||||
GstVaapiDisplayCache *cache;
|
||||
|
||||
cache = (GstVaapiDisplayCache *)
|
||||
gst_vaapi_mini_object_new (gst_vaapi_display_cache_class ());
|
||||
if (!cache)
|
||||
return NULL;
|
||||
|
||||
g_rec_mutex_init (&cache->mutex);
|
||||
cache->list = NULL;
|
||||
return cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_vaapi_display_cache_lock:
|
||||
* @cache: the #GstVaapiDisplayCache
|
||||
*
|
||||
* Locks the display cache @cache.
|
||||
*/
|
||||
void
|
||||
gst_vaapi_display_cache_lock (GstVaapiDisplayCache * cache)
|
||||
{
|
||||
g_return_if_fail (cache != NULL);
|
||||
|
||||
g_rec_mutex_lock (&cache->mutex);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_vaapi_display_cache_unlock:
|
||||
* @cache: the #GstVaapiDisplayCache
|
||||
*
|
||||
* Unlocks the display cache @cache.
|
||||
*/
|
||||
void
|
||||
gst_vaapi_display_cache_unlock (GstVaapiDisplayCache * cache)
|
||||
{
|
||||
g_return_if_fail (cache != NULL);
|
||||
|
||||
g_rec_mutex_unlock (&cache->mutex);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_vaapi_display_cache_is_empty:
|
||||
* @cache: the #GstVaapiDisplayCache
|
||||
*
|
||||
* Checks whether the display cache @cache is empty.
|
||||
*
|
||||
* Return value: %TRUE if the display @cache is empty, %FALSE otherwise.
|
||||
*/
|
||||
gboolean
|
||||
gst_vaapi_display_cache_is_empty (GstVaapiDisplayCache * cache)
|
||||
{
|
||||
g_return_val_if_fail (cache != NULL, 0);
|
||||
|
||||
return cache->list == NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_vaapi_display_cache_add:
|
||||
* @cache: the #GstVaapiDisplayCache
|
||||
* @info: the display cache info to add
|
||||
*
|
||||
* Adds a new entry with data from @info. The display @info data is
|
||||
* copied into the newly created cache entry.
|
||||
*
|
||||
* Return value: %TRUE on success
|
||||
*/
|
||||
gboolean
|
||||
gst_vaapi_display_cache_add (GstVaapiDisplayCache * cache,
|
||||
GstVaapiDisplayInfo * info)
|
||||
{
|
||||
CacheEntry *entry;
|
||||
|
||||
g_return_val_if_fail (cache != NULL, FALSE);
|
||||
g_return_val_if_fail (info != NULL, FALSE);
|
||||
|
||||
entry = cache_entry_new (info);
|
||||
if (!entry)
|
||||
return FALSE;
|
||||
|
||||
cache->list = g_list_prepend (cache->list, entry);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_vaapi_display_cache_remove:
|
||||
* @cache: the #GstVaapiDisplayCache
|
||||
* @display: the display to remove from cache
|
||||
*
|
||||
* Removes any cache entry that matches the specified #GstVaapiDisplay.
|
||||
*/
|
||||
void
|
||||
gst_vaapi_display_cache_remove (GstVaapiDisplayCache * cache,
|
||||
GstVaapiDisplay * display)
|
||||
{
|
||||
GList *m;
|
||||
|
||||
m = cache_lookup_1 (cache, compare_display, display,
|
||||
GST_VAAPI_DISPLAY_TYPE_ANY);
|
||||
if (!m)
|
||||
return;
|
||||
|
||||
cache_entry_free (m->data);
|
||||
cache->list = g_list_delete_link (cache->list, m);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_vaapi_display_cache_lookup:
|
||||
* @cache: the #GstVaapiDisplayCache
|
||||
* @display: the display to find
|
||||
*
|
||||
* Looks up the display cache for the specified #GstVaapiDisplay.
|
||||
*
|
||||
* Return value: a #GstVaapiDisplayInfo matching @display, or %NULL if
|
||||
* none was found
|
||||
*/
|
||||
const GstVaapiDisplayInfo *
|
||||
gst_vaapi_display_cache_lookup (GstVaapiDisplayCache * cache,
|
||||
GstVaapiDisplay * display)
|
||||
{
|
||||
g_return_val_if_fail (cache != NULL, NULL);
|
||||
g_return_val_if_fail (display != NULL, NULL);
|
||||
|
||||
return cache_lookup (cache, compare_display, display,
|
||||
GST_VAAPI_DISPLAY_TYPE_ANY);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_vaapi_display_cache_lookup_custom:
|
||||
* @cache: the #GstVaapiDisplayCache
|
||||
* @func: an comparison function
|
||||
* @data: user data passed to the function
|
||||
*
|
||||
* Looks up an element in the display @cache using the supplied
|
||||
* function @func to find the desired element. It iterates over all
|
||||
* elements in cache, calling the given function which should return
|
||||
* %TRUE when the desired element is found.
|
||||
*
|
||||
* The comparison function takes two gconstpointer arguments, a
|
||||
* #GstVaapiDisplayInfo as the first argument, and that is used to
|
||||
* compare against the given user @data argument as the second
|
||||
* argument.
|
||||
*
|
||||
* Return value: a #GstVaapiDisplayInfo causing @func to succeed
|
||||
* (i.e. returning %TRUE), or %NULL if none was found
|
||||
*/
|
||||
const GstVaapiDisplayInfo *
|
||||
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, display_types);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_vaapi_display_cache_lookup_by_va_display:
|
||||
* @cache: the #GstVaapiDisplayCache
|
||||
* @va_display: the VA display to find
|
||||
*
|
||||
* Looks up the display cache for the specified VA display.
|
||||
*
|
||||
* Return value: a #GstVaapiDisplayInfo matching @va_display, or %NULL
|
||||
* if none was found
|
||||
*/
|
||||
const GstVaapiDisplayInfo *
|
||||
gst_vaapi_display_cache_lookup_by_va_display (GstVaapiDisplayCache * cache,
|
||||
VADisplay 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,
|
||||
GST_VAAPI_DISPLAY_TYPE_ANY);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_vaapi_display_cache_lookup_by_native_display:
|
||||
* @cache: the #GstVaapiDisplayCache
|
||||
* @native_display: the native display to find
|
||||
*
|
||||
* Looks up the display cache for the specified native display.
|
||||
*
|
||||
* Return value: a #GstVaapiDisplayInfo matching @native_display, or
|
||||
* %NULL if none was found
|
||||
*/
|
||||
const GstVaapiDisplayInfo *
|
||||
gst_vaapi_display_cache_lookup_by_native_display (GstVaapiDisplayCache * cache,
|
||||
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,
|
||||
display_types);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_vaapi_display_cache_lookup_by_name:
|
||||
* @cache: the #GstVaapiDisplayCache
|
||||
* @display_name: the display name to match
|
||||
*
|
||||
* Looks up the display cache for the specified display name.
|
||||
*
|
||||
* Return value: a #GstVaapiDisplayInfo matching @display_name, or
|
||||
* %NULL if none was found
|
||||
*/
|
||||
const GstVaapiDisplayInfo *
|
||||
gst_vaapi_display_cache_lookup_by_name (GstVaapiDisplayCache * cache,
|
||||
const gchar * display_name, guint display_types)
|
||||
{
|
||||
g_return_val_if_fail (cache != NULL, NULL);
|
||||
|
||||
return cache_lookup (cache, compare_display_name, display_name,
|
||||
display_types);
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
/*
|
||||
* gstvaapidisplaycache.h - VA display cache
|
||||
*
|
||||
* Copyright (C) 2012-2013 Intel Corporation
|
||||
* Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef GSTVAAPIDISPLAYCACHE_H
|
||||
#define GSTVAAPIDISPLAYCACHE_H
|
||||
|
||||
#include "libgstvaapi_priv_check.h"
|
||||
#include <gst/vaapi/gstvaapidisplay.h>
|
||||
#include "gstvaapiminiobject.h"
|
||||
|
||||
typedef struct _GstVaapiDisplayCache GstVaapiDisplayCache;
|
||||
|
||||
G_GNUC_INTERNAL
|
||||
GstVaapiDisplayCache *
|
||||
gst_vaapi_display_cache_new (void);
|
||||
|
||||
#define gst_vaapi_display_cache_ref(cache) \
|
||||
((GstVaapiDisplayCache *) gst_vaapi_mini_object_ref ( \
|
||||
GST_VAAPI_MINI_OBJECT (cache)))
|
||||
#define gst_vaapi_display_cache_unref(cache) \
|
||||
gst_vaapi_mini_object_unref (GST_VAAPI_MINI_OBJECT (cache))
|
||||
#define gst_vaapi_display_cache_replace(old_cache_ptr, new_cache) \
|
||||
gst_vaapi_mini_object_replace ((GstVaapiMiniObject **) (old_cache_ptr), \
|
||||
GST_VAAPI_MINI_OBJECT (new_cache))
|
||||
|
||||
G_GNUC_INTERNAL
|
||||
void
|
||||
gst_vaapi_display_cache_lock (GstVaapiDisplayCache * cache);
|
||||
|
||||
G_GNUC_INTERNAL
|
||||
void
|
||||
gst_vaapi_display_cache_unlock (GstVaapiDisplayCache * cache);
|
||||
|
||||
G_GNUC_INTERNAL
|
||||
gboolean
|
||||
gst_vaapi_display_cache_is_empty (GstVaapiDisplayCache * cache);
|
||||
|
||||
G_GNUC_INTERNAL
|
||||
gboolean
|
||||
gst_vaapi_display_cache_add (GstVaapiDisplayCache * cache,
|
||||
GstVaapiDisplayInfo * info);
|
||||
|
||||
G_GNUC_INTERNAL
|
||||
void
|
||||
gst_vaapi_display_cache_remove (GstVaapiDisplayCache * cache,
|
||||
GstVaapiDisplay * display);
|
||||
|
||||
const GstVaapiDisplayInfo *
|
||||
gst_vaapi_display_cache_lookup (GstVaapiDisplayCache
|
||||
* cache, GstVaapiDisplay * display);
|
||||
|
||||
const GstVaapiDisplayInfo *
|
||||
gst_vaapi_display_cache_lookup_custom (GstVaapiDisplayCache * cache,
|
||||
GCompareFunc func, gconstpointer data, guint display_types);
|
||||
|
||||
const GstVaapiDisplayInfo *
|
||||
gst_vaapi_display_cache_lookup_by_va_display (GstVaapiDisplayCache * cache,
|
||||
VADisplay va_display);
|
||||
|
||||
const GstVaapiDisplayInfo *
|
||||
gst_vaapi_display_cache_lookup_by_native_display (GstVaapiDisplayCache *
|
||||
cache, gpointer native_display, guint display_types);
|
||||
|
||||
const GstVaapiDisplayInfo *
|
||||
gst_vaapi_display_cache_lookup_by_name (GstVaapiDisplayCache * cache,
|
||||
const gchar * display_name, guint display_types);
|
||||
|
||||
#endif /* GSTVAAPIDISPLAYCACHE_H */
|
Loading…
Reference in a new issue