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 "gstvaapisurfaceproxy_priv.h"
31 #include "gstvaapivideopool_priv.h"
34 #include "gstvaapidebug.h"
37 set_crop_rect_from_surface(GstVaapiSurfaceProxy *proxy)
39 proxy->crop_rect.x = 0;
40 proxy->crop_rect.y = 0;
41 proxy->crop_rect.width = GST_VAAPI_SURFACE_WIDTH(proxy->surface);
42 proxy->crop_rect.height = GST_VAAPI_SURFACE_HEIGHT(proxy->surface);
46 set_crop_rect(GstVaapiSurfaceProxy *proxy, const GstVaapiRectangle *crop_rect)
49 proxy->crop_rect = *crop_rect;
51 set_crop_rect_from_surface(proxy);
55 gst_vaapi_surface_proxy_finalize(GstVaapiSurfaceProxy *proxy)
57 if (proxy->destroy_func)
58 proxy->destroy_func(proxy->destroy_data);
62 gst_vaapi_video_pool_put_object(proxy->pool, proxy->surface);
63 gst_vaapi_object_unref(proxy->surface);
64 proxy->surface = NULL;
66 gst_vaapi_video_pool_replace(&proxy->pool, NULL);
69 static inline const GstVaapiMiniObjectClass *
70 gst_vaapi_surface_proxy_class(void)
72 static const GstVaapiMiniObjectClass GstVaapiSurfaceProxyClass = {
73 sizeof(GstVaapiSurfaceProxy),
74 (GDestroyNotify)gst_vaapi_surface_proxy_finalize
76 return &GstVaapiSurfaceProxyClass;
79 GstVaapiSurfaceProxy *
80 gst_vaapi_surface_proxy_new_from_pool(GstVaapiSurfacePool *pool)
82 GstVaapiSurfaceProxy *proxy;
84 g_return_val_if_fail(pool != NULL, NULL);
86 proxy = (GstVaapiSurfaceProxy *)
87 gst_vaapi_mini_object_new(gst_vaapi_surface_proxy_class());
91 proxy->pool = gst_vaapi_video_pool_ref(pool);
92 proxy->surface = gst_vaapi_video_pool_get_object(proxy->pool);
95 set_crop_rect_from_surface(proxy);
97 proxy->timestamp = GST_CLOCK_TIME_NONE;
98 proxy->duration = GST_CLOCK_TIME_NONE;
99 proxy->destroy_func = NULL;
100 gst_vaapi_object_ref(proxy->surface);
104 gst_vaapi_surface_proxy_unref(proxy);
109 * gst_vaapi_surface_proxy_ref:
110 * @proxy: a #GstVaapiSurfaceProxy
112 * Atomically increases the reference count of the given @proxy by one.
114 * Returns: The same @proxy argument
116 GstVaapiSurfaceProxy *
117 gst_vaapi_surface_proxy_ref(GstVaapiSurfaceProxy *proxy)
119 g_return_val_if_fail(proxy != NULL, NULL);
121 return GST_VAAPI_SURFACE_PROXY(gst_vaapi_mini_object_ref(
122 GST_VAAPI_MINI_OBJECT(proxy)));
126 * gst_vaapi_surface_proxy_unref:
127 * @proxy: a #GstVaapiSurfaceProxy
129 * Atomically decreases the reference count of the @proxy by one. If
130 * the reference count reaches zero, the object will be free'd.
133 gst_vaapi_surface_proxy_unref(GstVaapiSurfaceProxy *proxy)
135 g_return_if_fail(proxy != NULL);
137 gst_vaapi_mini_object_unref(GST_VAAPI_MINI_OBJECT(proxy));
141 * gst_vaapi_surface_proxy_replace:
142 * @old_proxy_ptr: a pointer to a #GstVaapiSurfaceProxy
143 * @new_proxy: a #GstVaapiSurfaceProxy
145 * Atomically replaces the proxy object held in @old_proxy_ptr with
146 * @new_proxy. This means that @old_proxy_ptr shall reference a valid
147 * object. However, @new_proxy can be NULL.
150 gst_vaapi_surface_proxy_replace(GstVaapiSurfaceProxy **old_proxy_ptr,
151 GstVaapiSurfaceProxy *new_proxy)
153 g_return_if_fail(old_proxy_ptr != NULL);
155 gst_vaapi_mini_object_replace((GstVaapiMiniObject **)old_proxy_ptr,
156 GST_VAAPI_MINI_OBJECT(new_proxy));
160 * gst_vaapi_surface_proxy_get_surface:
161 * @proxy: a #GstVaapiSurfaceProxy
163 * Returns the #GstVaapiSurface stored in the @proxy.
165 * Return value: the #GstVaapiSurface
168 gst_vaapi_surface_proxy_get_surface(GstVaapiSurfaceProxy *proxy)
170 g_return_val_if_fail(proxy != NULL, NULL);
172 return GST_VAAPI_SURFACE_PROXY_SURFACE(proxy);
176 * gst_vaapi_surface_proxy_get_flags:
177 * @proxy: a #GstVaapiSurfaceProxy
179 * Returns the #GstVaapiSurfaceProxyFlags associated with this surface
182 * Return value: the set of #GstVaapiSurfaceProxyFlags
185 gst_vaapi_surface_proxy_get_flags(GstVaapiSurfaceProxy *proxy)
187 g_return_val_if_fail(proxy != NULL, 0);
189 return GST_VAAPI_SURFACE_PROXY_FLAGS(proxy);
193 * gst_vaapi_surface_proxy_get_surface_id:
194 * @proxy: a #GstVaapiSurfaceProxy
196 * Returns the VA surface ID stored in the @proxy.
198 * Return value: the #GstVaapiID
201 gst_vaapi_surface_proxy_get_surface_id(GstVaapiSurfaceProxy *proxy)
203 g_return_val_if_fail(proxy != NULL, 0);
204 g_return_val_if_fail(proxy->surface != NULL, 0);
206 return GST_VAAPI_SURFACE_PROXY_SURFACE_ID(proxy);
210 * gst_vaapi_surface_proxy_get_timestamp:
211 * @proxy: a #GstVaapiSurfaceProxy
213 * Returns the presentation timestamp for this surface @proxy.
215 * Return value: the presentation timestamp
218 gst_vaapi_surface_proxy_get_timestamp(GstVaapiSurfaceProxy *proxy)
220 g_return_val_if_fail(proxy != NULL, 0);
222 return GST_VAAPI_SURFACE_PROXY_TIMESTAMP(proxy);
226 * gst_vaapi_surface_proxy_get_duration:
227 * @proxy: a #GstVaapiSurfaceProxy
229 * Returns the presentation duration for this surface @proxy.
231 * Return value: the presentation duration
234 gst_vaapi_surface_proxy_get_duration(GstVaapiSurfaceProxy *proxy)
236 g_return_val_if_fail(proxy != NULL, 0);
238 return GST_VAAPI_SURFACE_PROXY_DURATION(proxy);
242 * gst_vaapi_surface_proxy_set_destroy_notify:
243 * @proxy: a @GstVaapiSurfaceProxy
244 * @destroy_func: a #GDestroyNotify function
245 * @user_data: some extra data to pass to the @destroy_func function
247 * Sets @destroy_func as the function to call when the surface @proxy
248 * was released. At this point, the proxy object is considered
249 * released, i.e. the underlying data storage is no longer valid and
250 * the callback function shall not expect anything from that.
253 gst_vaapi_surface_proxy_set_destroy_notify(GstVaapiSurfaceProxy *proxy,
254 GDestroyNotify destroy_func, gpointer user_data)
256 g_return_if_fail(proxy != NULL);
258 proxy->destroy_func = destroy_func;
259 proxy->destroy_data = user_data;
263 * gst_vaapi_surface_proxy_get_crop_rect:
264 * @proxy: a #GstVaapiSurfaceProxy
266 * Returns the #GstVaapiRectangle stored in the @proxy and that
267 * represents the cropping rectangle for the underlying surface to be
268 * used for rendering.
270 * Return value: the #GstVaapiRectangle
272 const GstVaapiRectangle *
273 gst_vaapi_surface_proxy_get_crop_rect(GstVaapiSurfaceProxy *proxy)
275 g_return_val_if_fail(proxy != NULL, NULL);
277 return GST_VAAPI_SURFACE_PROXY_CROP_RECT(proxy);
281 * gst_vaapi_surface_proxy_set_crop_rect:
282 * @proxy: #GstVaapiSurfaceProxy
283 * @crop_rect: the #GstVaapiRectangle to be stored in @proxy
285 * Associates the @crop_rect with the @proxy
288 gst_vaapi_surface_proxy_set_crop_rect(GstVaapiSurfaceProxy *proxy,
289 const GstVaapiRectangle *crop_rect)
291 g_return_if_fail(proxy != NULL);
293 set_crop_rect(proxy, crop_rect);