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"
33 #include "gstvaapidebug.h"
35 G_DEFINE_TYPE(GstVaapiSurfaceProxy, gst_vaapi_surface_proxy, G_TYPE_OBJECT);
37 #define GST_VAAPI_SURFACE_PROXY_GET_PRIVATE(obj) \
38 (G_TYPE_INSTANCE_GET_PRIVATE((obj), \
39 GST_VAAPI_TYPE_SURFACE_PROXY, \
40 GstVaapiSurfaceProxyPrivate))
42 struct _GstVaapiSurfaceProxyPrivate {
43 GstVaapiContext *context;
44 GstVaapiSurface *surface;
45 GstClockTime timestamp;
57 gst_vaapi_surface_proxy_finalize(GObject *object)
59 GstVaapiSurfaceProxy * const proxy = GST_VAAPI_SURFACE_PROXY(object);
61 gst_vaapi_surface_proxy_set_surface(proxy, NULL);
62 gst_vaapi_surface_proxy_set_context(proxy, NULL);
64 G_OBJECT_CLASS(gst_vaapi_surface_proxy_parent_class)->finalize(object);
68 gst_vaapi_surface_proxy_set_property(
75 GstVaapiSurfaceProxy * const proxy = GST_VAAPI_SURFACE_PROXY(object);
79 gst_vaapi_surface_proxy_set_context(proxy, g_value_get_pointer(value));
82 gst_vaapi_surface_proxy_set_surface(proxy, g_value_get_pointer(value));
85 gst_vaapi_surface_proxy_set_timestamp(proxy, g_value_get_uint64(value));
88 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
94 gst_vaapi_surface_proxy_get_property(
101 GstVaapiSurfaceProxy * const proxy = GST_VAAPI_SURFACE_PROXY(object);
105 g_value_set_pointer(value, gst_vaapi_surface_proxy_get_context(proxy));
108 g_value_set_pointer(value, gst_vaapi_surface_proxy_get_surface(proxy));
111 g_value_set_uint64(value, gst_vaapi_surface_proxy_get_timestamp(proxy));
114 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
120 gst_vaapi_surface_proxy_class_init(GstVaapiSurfaceProxyClass *klass)
122 GObjectClass * const object_class = G_OBJECT_CLASS(klass);
124 g_type_class_add_private(klass, sizeof(GstVaapiSurfaceProxyPrivate));
126 object_class->finalize = gst_vaapi_surface_proxy_finalize;
127 object_class->set_property = gst_vaapi_surface_proxy_set_property;
128 object_class->get_property = gst_vaapi_surface_proxy_get_property;
130 g_object_class_install_property
133 g_param_spec_pointer("context",
135 "The context stored in the proxy",
138 g_object_class_install_property
141 g_param_spec_pointer("surface",
143 "The surface stored in the proxy",
146 g_object_class_install_property
149 g_param_spec_uint64("timestamp",
151 "The presentation time of the surface",
152 0, G_MAXUINT64, GST_CLOCK_TIME_NONE,
157 gst_vaapi_surface_proxy_init(GstVaapiSurfaceProxy *proxy)
159 GstVaapiSurfaceProxyPrivate *priv;
161 priv = GST_VAAPI_SURFACE_PROXY_GET_PRIVATE(proxy);
163 priv->context = NULL;
164 priv->surface = NULL;
165 priv->timestamp = GST_CLOCK_TIME_NONE;
169 * gst_vaapi_surface_proxy_new:
170 * @context: a #GstVaapiContext
171 * @surface: a #GstVaapiSurface
173 * Creates a new #GstVaapiSurfaceProxy with the specified context and
176 * Return value: the newly allocated #GstVaapiSurfaceProxy object
178 GstVaapiSurfaceProxy *
179 gst_vaapi_surface_proxy_new(GstVaapiContext *context, GstVaapiSurface *surface)
181 g_return_val_if_fail(GST_VAAPI_IS_CONTEXT(context), NULL);
182 g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), NULL);
184 return g_object_new(GST_VAAPI_TYPE_SURFACE_PROXY,
191 * gst_vaapi_surface_proxy_get_context:
192 * @proxy: a #GstVaapiSurfaceProxy
194 * Returns the #GstVaapiContext stored in the @proxy.
196 * Return value: the #GstVaapiContext
199 gst_vaapi_surface_proxy_get_context(GstVaapiSurfaceProxy *proxy)
201 g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy), NULL);
203 return proxy->priv->context;
207 * gst_vaapi_surface_proxy_set_context:
208 * @proxy: a #GstVaapiSurfaceProxy
209 * @context: the new #GstVaapiContext to be stored in @proxy
211 * Stores a new @context into the @proxy. The proxy releases the
212 * previous reference, if any, and then holds a reference to the new
216 gst_vaapi_surface_proxy_set_context(
217 GstVaapiSurfaceProxy *proxy,
218 GstVaapiContext *context
221 GstVaapiSurfaceProxyPrivate *priv;
223 g_return_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy));
228 g_object_unref(priv->context);
229 priv->context = NULL;
233 priv->context = g_object_ref(context);
237 * gst_vaapi_surface_proxy_get_surface:
238 * @proxy: a #GstVaapiSurfaceProxy
240 * Returns the #GstVaapiSurface stored in the @proxy.
242 * Return value: the #GstVaapiSurface
245 gst_vaapi_surface_proxy_get_surface(GstVaapiSurfaceProxy *proxy)
247 g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy), NULL);
249 return proxy->priv->surface;
253 * gst_vaapi_surface_proxy_get_surface_id:
254 * @proxy: a #GstVaapiSurfaceProxy
256 * Returns the VA surface ID stored in the @proxy.
258 * Return value: the #GstVaapiID
261 gst_vaapi_surface_proxy_get_surface_id(GstVaapiSurfaceProxy *proxy)
263 g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy), GST_VAAPI_ID_NONE);
264 g_return_val_if_fail(proxy->priv->surface != NULL, GST_VAAPI_ID_NONE);
266 return GST_VAAPI_OBJECT_ID(proxy->priv->surface);
270 * gst_vaapi_surface_proxy_set_surface:
271 * @proxy: a #GstVaapiSurfaceProxy
272 * @surface: the new #GstVaapiSurface to be stored in @proxy
274 * Stores a new @surface into the @proxy. The proxy releases the
275 * previous reference, if any, and then holds a reference to the new
279 gst_vaapi_surface_proxy_set_surface(
280 GstVaapiSurfaceProxy *proxy,
281 GstVaapiSurface *surface
284 GstVaapiSurfaceProxyPrivate *priv;
286 g_return_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy));
292 gst_vaapi_context_put_surface(priv->context, priv->surface);
293 g_object_unref(priv->surface);
294 priv->surface = NULL;
298 priv->surface = g_object_ref(surface);
302 * gst_vaapi_surface_proxy_get_timestamp:
303 * @proxy: a #GstVaapiSurfaceProxy
305 * Returns the presentation timestamp of the #GstVaapiSurface held by @proxy.
307 * Return value: the presentation timestamp of the surface, or
308 * %GST_CLOCK_TIME_NONE is none was set
311 gst_vaapi_surface_proxy_get_timestamp(GstVaapiSurfaceProxy *proxy)
313 g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy), GST_CLOCK_TIME_NONE);
315 return proxy->priv->timestamp;
319 * gst_vaapi_surface_proxy_set_timestamp:
320 * @proxy: a #GstVaapiSurfaceProxy
321 * @timestamp: the new presentation timestamp as a #GstClockTime
323 * Sets the presentation timestamp of the @proxy surface to @timestamp.
326 gst_vaapi_surface_proxy_set_timestamp(
327 GstVaapiSurfaceProxy *proxy,
328 GstClockTime timestamp
331 g_return_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy));
333 proxy->priv->timestamp = timestamp;