2 * gstvaapisurfaceproxy.c - VA surface proxy
4 * Copyright (C) 2010-2011 Splitted-Desktop Systems
5 * Author: Gwenole Beauchesne <gwenole.beauchesne@splitted-desktop.com>
6 * Copyright (C) 2011-2014 Intel Corporation
7 * Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301 USA
26 * SECTION:gstvaapisurfaceproxy
27 * @short_description: VA surface proxy
31 #include "gstvaapisurfaceproxy.h"
32 #include "gstvaapisurfaceproxy_priv.h"
33 #include "gstvaapivideopool_priv.h"
36 #include "gstvaapidebug.h"
39 gst_vaapi_surface_proxy_finalize(GstVaapiSurfaceProxy *proxy)
42 if (proxy->pool && !proxy->parent)
43 gst_vaapi_video_pool_put_object(proxy->pool, proxy->surface);
44 gst_vaapi_object_unref(proxy->surface);
45 proxy->surface = NULL;
47 gst_vaapi_video_pool_replace(&proxy->pool, NULL);
48 gst_vaapi_surface_proxy_replace(&proxy->parent, NULL);
50 /* Notify the user function that the object is now destroyed */
51 if (proxy->destroy_func)
52 proxy->destroy_func(proxy->destroy_data);
55 static inline const GstVaapiMiniObjectClass *
56 gst_vaapi_surface_proxy_class(void)
58 static const GstVaapiMiniObjectClass GstVaapiSurfaceProxyClass = {
59 sizeof(GstVaapiSurfaceProxy),
60 (GDestroyNotify)gst_vaapi_surface_proxy_finalize
62 return &GstVaapiSurfaceProxyClass;
66 * gst_vaapi_surface_proxy_new_from_pool:
67 * @pool: a #GstVaapiSurfacePool
69 * Allocates a new surface from the supplied surface @pool and creates
70 * the wrapped surface proxy object from it. When the last reference
71 * to the proxy object is released, then the underlying VA surface is
72 * pushed back to its parent pool.
74 * Returns: The same newly allocated @proxy object, or %NULL on error
76 GstVaapiSurfaceProxy *
77 gst_vaapi_surface_proxy_new_from_pool(GstVaapiSurfacePool *pool)
79 GstVaapiSurfaceProxy *proxy;
81 g_return_val_if_fail(pool != NULL, NULL);
83 proxy = (GstVaapiSurfaceProxy *)
84 gst_vaapi_mini_object_new(gst_vaapi_surface_proxy_class());
89 proxy->destroy_func = NULL;
90 proxy->pool = gst_vaapi_video_pool_ref(pool);
91 proxy->surface = gst_vaapi_video_pool_get_object(proxy->pool);
94 proxy->timestamp = GST_CLOCK_TIME_NONE;
95 proxy->duration = GST_CLOCK_TIME_NONE;
96 proxy->has_crop_rect = FALSE;
97 gst_vaapi_object_ref(proxy->surface);
101 gst_vaapi_surface_proxy_unref(proxy);
107 * gst_vaapi_surface_proxy_copy:
108 * @proxy: the parent #GstVaapiSurfaceProxy
110 * Creates are new VA surface proxy object from the supplied parent
111 * @proxy object with the same initial information, e.g. timestamp,
114 * Note: the destroy notify function is not copied into the new
115 * surface proxy object.
117 * Returns: The same newly allocated @proxy object, or %NULL on error
119 GstVaapiSurfaceProxy *
120 gst_vaapi_surface_proxy_copy(GstVaapiSurfaceProxy *proxy)
122 GstVaapiSurfaceProxy *copy;
124 g_return_val_if_fail(proxy != NULL, NULL);
126 copy = (GstVaapiSurfaceProxy *)
127 gst_vaapi_mini_object_new(gst_vaapi_surface_proxy_class());
131 GST_VAAPI_SURFACE_PROXY_FLAGS(copy) =
132 GST_VAAPI_SURFACE_PROXY_FLAGS(proxy);
134 copy->parent = gst_vaapi_surface_proxy_ref(proxy->parent ?
135 proxy->parent : proxy);
136 copy->pool = gst_vaapi_video_pool_ref(proxy->pool);
137 copy->surface = gst_vaapi_object_ref(proxy->surface);
138 copy->timestamp = proxy->timestamp;
139 copy->duration = proxy->duration;
140 copy->destroy_func = NULL;
141 copy->has_crop_rect = proxy->has_crop_rect;
142 if (copy->has_crop_rect)
143 copy->crop_rect = proxy->crop_rect;
148 * gst_vaapi_surface_proxy_ref:
149 * @proxy: a #GstVaapiSurfaceProxy
151 * Atomically increases the reference count of the given @proxy by one.
153 * Returns: The same @proxy argument
155 GstVaapiSurfaceProxy *
156 gst_vaapi_surface_proxy_ref(GstVaapiSurfaceProxy *proxy)
158 g_return_val_if_fail(proxy != NULL, NULL);
160 return GST_VAAPI_SURFACE_PROXY(gst_vaapi_mini_object_ref(
161 GST_VAAPI_MINI_OBJECT(proxy)));
165 * gst_vaapi_surface_proxy_unref:
166 * @proxy: a #GstVaapiSurfaceProxy
168 * Atomically decreases the reference count of the @proxy by one. If
169 * the reference count reaches zero, the object will be free'd.
172 gst_vaapi_surface_proxy_unref(GstVaapiSurfaceProxy *proxy)
174 g_return_if_fail(proxy != NULL);
176 gst_vaapi_mini_object_unref(GST_VAAPI_MINI_OBJECT(proxy));
180 * gst_vaapi_surface_proxy_replace:
181 * @old_proxy_ptr: a pointer to a #GstVaapiSurfaceProxy
182 * @new_proxy: a #GstVaapiSurfaceProxy
184 * Atomically replaces the proxy object held in @old_proxy_ptr with
185 * @new_proxy. This means that @old_proxy_ptr shall reference a valid
186 * object. However, @new_proxy can be NULL.
189 gst_vaapi_surface_proxy_replace(GstVaapiSurfaceProxy **old_proxy_ptr,
190 GstVaapiSurfaceProxy *new_proxy)
192 g_return_if_fail(old_proxy_ptr != NULL);
194 gst_vaapi_mini_object_replace((GstVaapiMiniObject **)old_proxy_ptr,
195 GST_VAAPI_MINI_OBJECT(new_proxy));
199 * gst_vaapi_surface_proxy_get_surface:
200 * @proxy: a #GstVaapiSurfaceProxy
202 * Returns the #GstVaapiSurface stored in the @proxy.
204 * Return value: the #GstVaapiSurface
207 gst_vaapi_surface_proxy_get_surface(GstVaapiSurfaceProxy *proxy)
209 g_return_val_if_fail(proxy != NULL, NULL);
211 return GST_VAAPI_SURFACE_PROXY_SURFACE(proxy);
215 * gst_vaapi_surface_proxy_get_flags:
216 * @proxy: a #GstVaapiSurfaceProxy
218 * Returns the #GstVaapiSurfaceProxyFlags associated with this surface
221 * Return value: the set of #GstVaapiSurfaceProxyFlags
224 gst_vaapi_surface_proxy_get_flags(GstVaapiSurfaceProxy *proxy)
226 g_return_val_if_fail(proxy != NULL, 0);
228 return GST_VAAPI_SURFACE_PROXY_FLAGS(proxy);
232 * gst_vaapi_surface_proxy_get_surface_id:
233 * @proxy: a #GstVaapiSurfaceProxy
235 * Returns the VA surface ID stored in the @proxy.
237 * Return value: the #GstVaapiID
240 gst_vaapi_surface_proxy_get_surface_id(GstVaapiSurfaceProxy *proxy)
242 g_return_val_if_fail(proxy != NULL, VA_INVALID_ID);
243 g_return_val_if_fail(proxy->surface != NULL, VA_INVALID_ID);
245 return GST_VAAPI_SURFACE_PROXY_SURFACE_ID(proxy);
249 * gst_vaapi_surface_proxy_get_timestamp:
250 * @proxy: a #GstVaapiSurfaceProxy
252 * Returns the presentation timestamp for this surface @proxy.
254 * Return value: the presentation timestamp
257 gst_vaapi_surface_proxy_get_timestamp(GstVaapiSurfaceProxy *proxy)
259 g_return_val_if_fail(proxy != NULL, 0);
261 return GST_VAAPI_SURFACE_PROXY_TIMESTAMP(proxy);
265 * gst_vaapi_surface_proxy_get_duration:
266 * @proxy: a #GstVaapiSurfaceProxy
268 * Returns the presentation duration for this surface @proxy.
270 * Return value: the presentation duration
273 gst_vaapi_surface_proxy_get_duration(GstVaapiSurfaceProxy *proxy)
275 g_return_val_if_fail(proxy != NULL, 0);
277 return GST_VAAPI_SURFACE_PROXY_DURATION(proxy);
281 * gst_vaapi_surface_proxy_set_destroy_notify:
282 * @proxy: a @GstVaapiSurfaceProxy
283 * @destroy_func: a #GDestroyNotify function
284 * @user_data: some extra data to pass to the @destroy_func function
286 * Sets @destroy_func as the function to call when the surface @proxy
287 * was released. At this point, the proxy object is considered
288 * released, i.e. the underlying data storage is no longer valid and
289 * the callback function shall not expect anything from that.
292 gst_vaapi_surface_proxy_set_destroy_notify(GstVaapiSurfaceProxy *proxy,
293 GDestroyNotify destroy_func, gpointer user_data)
295 g_return_if_fail(proxy != NULL);
297 proxy->destroy_func = destroy_func;
298 proxy->destroy_data = user_data;
302 * gst_vaapi_surface_proxy_get_crop_rect:
303 * @proxy: a #GstVaapiSurfaceProxy
305 * Returns the #GstVaapiRectangle stored in the @proxy and that
306 * represents the cropping rectangle for the underlying surface to be
307 * used for rendering.
309 * If no cropping rectangle was associated with the @proxy, then this
310 * function returns %NULL.
312 * Return value: the #GstVaapiRectangle, or %NULL if none was
313 * associated with the surface proxy
315 const GstVaapiRectangle *
316 gst_vaapi_surface_proxy_get_crop_rect(GstVaapiSurfaceProxy *proxy)
318 g_return_val_if_fail(proxy != NULL, NULL);
320 return GST_VAAPI_SURFACE_PROXY_CROP_RECT(proxy);
324 * gst_vaapi_surface_proxy_set_crop_rect:
325 * @proxy: #GstVaapiSurfaceProxy
326 * @crop_rect: the #GstVaapiRectangle to be stored in @proxy
328 * Associates the @crop_rect with the @proxy
331 gst_vaapi_surface_proxy_set_crop_rect(GstVaapiSurfaceProxy *proxy,
332 const GstVaapiRectangle *crop_rect)
334 g_return_if_fail(proxy != NULL);
336 proxy->has_crop_rect = crop_rect != NULL;
337 if (proxy->has_crop_rect)
338 proxy->crop_rect = *crop_rect;