2 * gstvaapisurfaceproxy.c - VA surface proxy
4 * Copyright (C) 2010-2011 Splitted-Desktop Systems
5 * Copyright (C) 2011-2012 Intel Corporation
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * as published by the Free Software Foundation; either version 2.1
10 * of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301 USA
24 * SECTION:gstvaapisurfaceproxy
25 * @short_description: VA surface proxy
29 #include "gstvaapisurfaceproxy.h"
30 #include "gstvaapiobject_priv.h"
31 #include "gstvaapiminiobject.h"
34 #include "gstvaapidebug.h"
36 #define GST_VAAPI_SURFACE_PROXY(obj) \
37 ((GstVaapiSurfaceProxy *)(obj))
39 #define GST_VAAPI_IS_SURFACE_PROXY(obj) \
40 (GST_VAAPI_SURFACE_PROXY(obj) != NULL)
42 struct _GstVaapiSurfaceProxy {
44 GstVaapiMiniObject parent_instance;
46 GstVaapiVideoPool *pool;
47 GstVaapiSurface *surface;
51 gst_vaapi_surface_proxy_finalize(GstVaapiSurfaceProxy *proxy)
55 gst_vaapi_video_pool_put_object(proxy->pool, proxy->surface);
56 g_object_unref(proxy->surface);
57 proxy->surface = NULL;
59 g_clear_object(&proxy->pool);
62 static inline const GstVaapiMiniObjectClass *
63 gst_vaapi_surface_proxy_class(void)
65 static const GstVaapiMiniObjectClass GstVaapiSurfaceProxyClass = {
66 sizeof(GstVaapiSurfaceProxy),
67 (GDestroyNotify)gst_vaapi_surface_proxy_finalize
69 return &GstVaapiSurfaceProxyClass;
72 GstVaapiSurfaceProxy *
73 gst_vaapi_surface_proxy_new_from_pool(GstVaapiSurfacePool *pool)
75 GstVaapiSurfaceProxy *proxy;
77 g_return_val_if_fail(GST_VAAPI_IS_SURFACE_POOL(pool), NULL);
79 proxy = (GstVaapiSurfaceProxy *)
80 gst_vaapi_mini_object_new(gst_vaapi_surface_proxy_class());
84 proxy->pool = g_object_ref(pool);
85 proxy->surface = gst_vaapi_video_pool_get_object(proxy->pool);
88 g_object_ref(proxy->surface);
92 gst_vaapi_surface_proxy_unref(proxy);
97 * gst_vaapi_surface_proxy_ref:
98 * @proxy: a #GstVaapiSurfaceProxy
100 * Atomically increases the reference count of the given @proxy by one.
102 * Returns: The same @proxy argument
104 GstVaapiSurfaceProxy *
105 gst_vaapi_surface_proxy_ref(GstVaapiSurfaceProxy *proxy)
107 g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy), NULL);
109 return GST_VAAPI_SURFACE_PROXY(gst_vaapi_mini_object_ref(
110 GST_VAAPI_MINI_OBJECT(proxy)));
114 * gst_vaapi_surface_proxy_unref:
115 * @proxy: a #GstVaapiSurfaceProxy
117 * Atomically decreases the reference count of the @proxy by one. If
118 * the reference count reaches zero, the object will be free'd.
121 gst_vaapi_surface_proxy_unref(GstVaapiSurfaceProxy *proxy)
123 g_return_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy));
125 gst_vaapi_mini_object_unref(GST_VAAPI_MINI_OBJECT(proxy));
129 * gst_vaapi_surface_proxy_replace:
130 * @old_proxy_ptr: a pointer to a #GstVaapiSurfaceProxy
131 * @new_proxy: a #GstVaapiSurfaceProxy
133 * Atomically replaces the proxy object held in @old_proxy_ptr with
134 * @new_proxy. This means that @old_proxy_ptr shall reference a valid
135 * object. However, @new_proxy can be NULL.
138 gst_vaapi_surface_proxy_replace(GstVaapiSurfaceProxy **old_proxy_ptr,
139 GstVaapiSurfaceProxy *new_proxy)
141 g_return_if_fail(old_proxy_ptr != NULL);
143 gst_vaapi_mini_object_replace((GstVaapiMiniObject **)old_proxy_ptr,
144 GST_VAAPI_MINI_OBJECT(new_proxy));
148 * gst_vaapi_surface_proxy_get_user_data:
149 * @proxy: a #GstVaapiSurfaceProxy
151 * Gets user-provided data set on the object via a previous call to
152 * gst_vaapi_surface_proxy_set_user_data().
154 * Returns: (transfer none): The previously set user_data
157 gst_vaapi_surface_proxy_get_user_data(GstVaapiSurfaceProxy *proxy)
159 g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy), NULL);
161 return gst_vaapi_mini_object_get_user_data(GST_VAAPI_MINI_OBJECT(proxy));
165 * gst_vaapi_surface_proxy_set_user_data:
166 * @proxy: a #GstVaapiSurfaceProxy
167 * @user_data: user-provided data
168 * @destroy_notify: (closure user_data): a #GDestroyNotify
170 * Sets @user_data on the object and the #GDestroyNotify that will be
171 * called when the data is freed.
173 * If some @user_data was previously set, then the former @destroy_notify
174 * function will be called before the @user_data is replaced.
177 gst_vaapi_surface_proxy_set_user_data(GstVaapiSurfaceProxy *proxy,
178 gpointer user_data, GDestroyNotify destroy_notify)
180 g_return_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy));
182 gst_vaapi_mini_object_set_user_data(GST_VAAPI_MINI_OBJECT(proxy),
183 user_data, destroy_notify);
187 * gst_vaapi_surface_proxy_get_surface:
188 * @proxy: a #GstVaapiSurfaceProxy
190 * Returns the #GstVaapiSurface stored in the @proxy.
192 * Return value: the #GstVaapiSurface
195 gst_vaapi_surface_proxy_get_surface(GstVaapiSurfaceProxy *proxy)
197 g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy), NULL);
199 return proxy->surface;
203 * gst_vaapi_surface_proxy_get_surface_id:
204 * @proxy: a #GstVaapiSurfaceProxy
206 * Returns the VA surface ID stored in the @proxy.
208 * Return value: the #GstVaapiID
211 gst_vaapi_surface_proxy_get_surface_id(GstVaapiSurfaceProxy *proxy)
213 g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy), GST_VAAPI_ID_NONE);
214 g_return_val_if_fail(proxy->surface != NULL, GST_VAAPI_ID_NONE);
216 return GST_VAAPI_OBJECT_ID(proxy->surface);