2
* gstvaapidisplaycache.c - VA display cache
4
* Copyright (C) 2012 Intel Corporation
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Lesser General Public License
8
* as published by the Free Software Foundation; either version 2.1
9
* of the License, or (at your option) any later version.
11
* This library is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* Lesser General Public License for more details.
16
* You should have received a copy of the GNU Lesser General Public
17
* License along with this library; if not, write to the Free
18
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
* Boston, MA 02110-1301 USA
25
#include "gstvaapidisplaycache.h"
28
#include "gstvaapidebug.h"
30
typedef struct _CacheEntry CacheEntry;
32
GstVaapiDisplayInfo info;
35
struct _GstVaapiDisplayCache {
41
cache_entry_free(CacheEntry *entry)
43
GstVaapiDisplayInfo *info;
50
if (info->display_name) {
51
g_free(info->display_name);
52
info->display_name = NULL;
54
g_slice_free(CacheEntry, entry);
58
cache_entry_new(const GstVaapiDisplayInfo *di)
60
GstVaapiDisplayInfo *info;
63
entry = g_slice_new(CacheEntry);
68
info->display = di->display;
69
info->va_display = di->va_display;
70
info->native_display = di->native_display;
71
info->display_name = NULL;
73
if (di->display_name) {
74
info->display_name = g_strdup(di->display_name);
75
if (!info->display_name)
81
cache_entry_free(entry);
85
#define CACHE_LOOKUP(cache, res, prop, comp_func, comp_data, user_data) do { \
88
g_static_mutex_lock(&(cache)->mutex); \
89
for (l = (cache)->list; l != NULL; l = l->next) { \
90
GstVaapiDisplayInfo * const info = \
91
&((CacheEntry *)l->data)->info; \
92
if (comp_func(info->prop, comp_data, user_data)) \
95
g_static_mutex_unlock(&(cache)->mutex); \
99
#define compare_equal(a, b, user_data) \
102
#define compare_string(a, b, user_data) \
103
((a) == (b) || ((a) && (b) && strcmp(a, b) == 0))
106
cache_lookup_display(GstVaapiDisplayCache *cache, GstVaapiDisplay *display)
110
CACHE_LOOKUP(cache, m, display, compare_equal, display, NULL);
115
cache_lookup_va_display(GstVaapiDisplayCache *cache, VADisplay va_display)
119
CACHE_LOOKUP(cache, m, va_display, compare_equal, va_display, NULL);
124
cache_lookup_native_display(GstVaapiDisplayCache *cache, gpointer native_display)
128
CACHE_LOOKUP(cache, m, native_display, compare_equal, native_display, NULL);
133
* gst_vaapi_display_cache_new:
135
* Creates a new VA display cache.
137
* Return value: the newly created #GstVaapiDisplayCache object
139
GstVaapiDisplayCache *
140
gst_vaapi_display_cache_new(void)
142
GstVaapiDisplayCache *cache;
144
cache = g_slice_new0(GstVaapiDisplayCache);
148
g_static_mutex_init(&cache->mutex);
153
* gst_vaapi_display_cache_new:
154
* @cache: the #GstVaapiDisplayCache to destroy
156
* Destroys a VA display cache.
159
gst_vaapi_display_cache_free(GstVaapiDisplayCache *cache)
167
for (l = cache->list; l != NULL; l = l->next)
168
cache_entry_free(l->data);
169
g_list_free(cache->list);
172
g_slice_free(GstVaapiDisplayCache, cache);
176
* gst_vaapi_display_cache_get_size:
177
* @cache: the #GstVaapiDisplayCache
179
* Gets the size of the display cache @cache.
181
* Return value: the size of the display cache
184
gst_vaapi_display_cache_get_size(GstVaapiDisplayCache *cache)
188
g_return_val_if_fail(cache != NULL, 0);
190
g_static_mutex_lock(&cache->mutex);
191
size = g_list_length(cache->list);
192
g_static_mutex_unlock(&cache->mutex);
197
* gst_vaapi_display_cache_add:
198
* @cache: the #GstVaapiDisplayCache
199
* @info: the display cache info to add
201
* Adds a new entry with data from @info. The display @info data is
202
* copied into the newly created cache entry.
204
* Return value: %TRUE on success
207
gst_vaapi_display_cache_add(
208
GstVaapiDisplayCache *cache,
209
GstVaapiDisplayInfo *info
214
g_return_val_if_fail(cache != NULL, FALSE);
215
g_return_val_if_fail(info != NULL, FALSE);
217
entry = cache_entry_new(info);
221
g_static_mutex_lock(&cache->mutex);
222
cache->list = g_list_prepend(cache->list, entry);
223
g_static_mutex_unlock(&cache->mutex);
228
* gst_vaapi_display_cache_remove:
229
* @cache: the #GstVaapiDisplayCache
230
* @display: the display to remove from cache
232
* Removes any cache entry that matches the specified #GstVaapiDisplay.
235
gst_vaapi_display_cache_remove(
236
GstVaapiDisplayCache *cache,
237
GstVaapiDisplay *display
242
m = cache_lookup_display(cache, display);
246
cache_entry_free(m->data);
247
g_static_mutex_lock(&cache->mutex);
248
cache->list = g_list_delete_link(cache->list, m);
249
g_static_mutex_unlock(&cache->mutex);
253
* gst_vaapi_display_cache_lookup:
254
* @cache: the #GstVaapiDisplayCache
255
* @display: the display to find
257
* Looks up the display cache for the specified #GstVaapiDisplay.
259
* Return value: a #GstVaapiDisplayInfo matching @display, or %NULL if
262
const GstVaapiDisplayInfo *
263
gst_vaapi_display_cache_lookup(
264
GstVaapiDisplayCache *cache,
265
GstVaapiDisplay *display
271
g_return_val_if_fail(cache != NULL, NULL);
272
g_return_val_if_fail(display != NULL, NULL);
274
m = cache_lookup_display(cache, display);
283
* gst_vaapi_display_cache_lookup_by_va_display:
284
* @cache: the #GstVaapiDisplayCache
285
* @va_display: the VA display to find
287
* Looks up the display cache for the specified VA display.
289
* Return value: a #GstVaapiDisplayInfo matching @va_display, or %NULL
292
const GstVaapiDisplayInfo *
293
gst_vaapi_display_cache_lookup_by_va_display(
294
GstVaapiDisplayCache *cache,
301
g_return_val_if_fail(cache != NULL, NULL);
302
g_return_val_if_fail(va_display != NULL, NULL);
304
m = cache_lookup_va_display(cache, va_display);
313
* gst_vaapi_display_cache_lookup_by_native_display:
314
* @cache: the #GstVaapiDisplayCache
315
* @native_display: the native display to find
317
* Looks up the display cache for the specified native display.
319
* Return value: a #GstVaapiDisplayInfo matching @native_display, or
320
* %NULL if none was found
322
const GstVaapiDisplayInfo *
323
gst_vaapi_display_cache_lookup_by_native_display(
324
GstVaapiDisplayCache *cache,
325
gpointer native_display
331
g_return_val_if_fail(cache != NULL, NULL);
332
g_return_val_if_fail(native_display != NULL, NULL);
334
m = cache_lookup_native_display(cache, native_display);
343
* gst_vaapi_display_cache_lookup_by_name:
344
* @cache: the #GstVaapiDisplayCache
345
* @display_name: the display name to match
346
* @compare_func: an optional string comparison function
347
* @user_data: any relevant data pointer to the comparison function
349
* Looks up the display cache for the specified display name. A
350
* specific comparison function can be provided to avoid a plain
353
* Return value: a #GstVaapiDisplayInfo matching @display_name, or
354
* %NULL if none was found
356
const GstVaapiDisplayInfo *
357
gst_vaapi_display_cache_lookup_by_name(
358
GstVaapiDisplayCache *cache,
359
const gchar *display_name,
360
GCompareDataFunc compare_func,
367
g_return_val_if_fail(cache != NULL, NULL);
370
CACHE_LOOKUP(cache, m, display_name, compare_func, display_name, user_data);
372
CACHE_LOOKUP(cache, m, display_name, compare_string, display_name, NULL);