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;
46 guint is_interlaced : 1;
61 gst_vaapi_surface_proxy_finalize(GObject *object)
63 GstVaapiSurfaceProxy * const proxy = GST_VAAPI_SURFACE_PROXY(object);
65 gst_vaapi_surface_proxy_set_surface(proxy, NULL);
66 gst_vaapi_surface_proxy_set_context(proxy, NULL);
68 G_OBJECT_CLASS(gst_vaapi_surface_proxy_parent_class)->finalize(object);
72 gst_vaapi_surface_proxy_set_property(
79 GstVaapiSurfaceProxy * const proxy = GST_VAAPI_SURFACE_PROXY(object);
83 gst_vaapi_surface_proxy_set_context(proxy, g_value_get_pointer(value));
86 gst_vaapi_surface_proxy_set_surface(proxy, g_value_get_pointer(value));
89 gst_vaapi_surface_proxy_set_timestamp(proxy, g_value_get_uint64(value));
92 gst_vaapi_surface_proxy_set_interlaced(proxy, g_value_get_boolean(value));
95 gst_vaapi_surface_proxy_set_tff(proxy, g_value_get_boolean(value));
98 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
104 gst_vaapi_surface_proxy_get_property(
111 GstVaapiSurfaceProxy * const proxy = GST_VAAPI_SURFACE_PROXY(object);
115 g_value_set_pointer(value, gst_vaapi_surface_proxy_get_context(proxy));
118 g_value_set_pointer(value, gst_vaapi_surface_proxy_get_surface(proxy));
121 g_value_set_uint64(value, gst_vaapi_surface_proxy_get_timestamp(proxy));
123 case PROP_INTERLACED:
124 g_value_set_boolean(value, gst_vaapi_surface_proxy_get_interlaced(proxy));
127 g_value_set_boolean(value, gst_vaapi_surface_proxy_get_tff(proxy));
130 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
136 gst_vaapi_surface_proxy_class_init(GstVaapiSurfaceProxyClass *klass)
138 GObjectClass * const object_class = G_OBJECT_CLASS(klass);
140 g_type_class_add_private(klass, sizeof(GstVaapiSurfaceProxyPrivate));
142 object_class->finalize = gst_vaapi_surface_proxy_finalize;
143 object_class->set_property = gst_vaapi_surface_proxy_set_property;
144 object_class->get_property = gst_vaapi_surface_proxy_get_property;
146 g_object_class_install_property
149 g_param_spec_pointer("context",
151 "The context stored in the proxy",
154 g_object_class_install_property
157 g_param_spec_pointer("surface",
159 "The surface stored in the proxy",
162 g_object_class_install_property
165 g_param_spec_uint64("timestamp",
167 "The presentation time of the surface",
168 0, G_MAXUINT64, GST_CLOCK_TIME_NONE,
171 g_object_class_install_property
174 g_param_spec_boolean("interlaced",
176 "Flag indicating whether surface is interlaced",
180 g_object_class_install_property
183 g_param_spec_boolean("tff",
185 "Flag indicating for interlaced surfaces whether Top Field is First",
191 gst_vaapi_surface_proxy_init(GstVaapiSurfaceProxy *proxy)
193 GstVaapiSurfaceProxyPrivate *priv;
195 priv = GST_VAAPI_SURFACE_PROXY_GET_PRIVATE(proxy);
197 priv->context = NULL;
198 priv->surface = NULL;
199 priv->timestamp = GST_CLOCK_TIME_NONE;
200 priv->is_interlaced = FALSE;
205 * gst_vaapi_surface_proxy_new:
206 * @context: a #GstVaapiContext
207 * @surface: a #GstVaapiSurface
209 * Creates a new #GstVaapiSurfaceProxy with the specified context and
212 * Return value: the newly allocated #GstVaapiSurfaceProxy object
214 GstVaapiSurfaceProxy *
215 gst_vaapi_surface_proxy_new(GstVaapiContext *context, GstVaapiSurface *surface)
217 g_return_val_if_fail(GST_VAAPI_IS_CONTEXT(context), NULL);
218 g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), NULL);
220 return g_object_new(GST_VAAPI_TYPE_SURFACE_PROXY,
227 * gst_vaapi_surface_proxy_get_context:
228 * @proxy: a #GstVaapiSurfaceProxy
230 * Returns the #GstVaapiContext stored in the @proxy.
232 * Return value: the #GstVaapiContext
235 gst_vaapi_surface_proxy_get_context(GstVaapiSurfaceProxy *proxy)
237 g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy), NULL);
239 return proxy->priv->context;
243 * gst_vaapi_surface_proxy_set_context:
244 * @proxy: a #GstVaapiSurfaceProxy
245 * @context: the new #GstVaapiContext to be stored in @proxy
247 * Stores a new @context into the @proxy. The proxy releases the
248 * previous reference, if any, and then holds a reference to the new
252 gst_vaapi_surface_proxy_set_context(
253 GstVaapiSurfaceProxy *proxy,
254 GstVaapiContext *context
257 GstVaapiSurfaceProxyPrivate *priv;
259 g_return_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy));
263 g_clear_object(&priv->context);
266 priv->context = g_object_ref(context);
270 * gst_vaapi_surface_proxy_get_surface:
271 * @proxy: a #GstVaapiSurfaceProxy
273 * Returns the #GstVaapiSurface stored in the @proxy.
275 * Return value: the #GstVaapiSurface
278 gst_vaapi_surface_proxy_get_surface(GstVaapiSurfaceProxy *proxy)
280 g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy), NULL);
282 return proxy->priv->surface;
286 * gst_vaapi_surface_proxy_get_surface_id:
287 * @proxy: a #GstVaapiSurfaceProxy
289 * Returns the VA surface ID stored in the @proxy.
291 * Return value: the #GstVaapiID
294 gst_vaapi_surface_proxy_get_surface_id(GstVaapiSurfaceProxy *proxy)
296 g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy), GST_VAAPI_ID_NONE);
297 g_return_val_if_fail(proxy->priv->surface != NULL, GST_VAAPI_ID_NONE);
299 return GST_VAAPI_OBJECT_ID(proxy->priv->surface);
303 * gst_vaapi_surface_proxy_set_surface:
304 * @proxy: a #GstVaapiSurfaceProxy
305 * @surface: the new #GstVaapiSurface to be stored in @proxy
307 * Stores a new @surface into the @proxy. The proxy releases the
308 * previous reference, if any, and then holds a reference to the new
312 gst_vaapi_surface_proxy_set_surface(
313 GstVaapiSurfaceProxy *proxy,
314 GstVaapiSurface *surface
317 GstVaapiSurfaceProxyPrivate *priv;
319 g_return_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy));
325 gst_vaapi_context_put_surface(priv->context, priv->surface);
326 g_object_unref(priv->surface);
327 priv->surface = NULL;
331 priv->surface = g_object_ref(surface);
335 * gst_vaapi_surface_proxy_get_timestamp:
336 * @proxy: a #GstVaapiSurfaceProxy
338 * Returns the presentation timestamp of the #GstVaapiSurface held by @proxy.
340 * Return value: the presentation timestamp of the surface, or
341 * %GST_CLOCK_TIME_NONE is none was set
344 gst_vaapi_surface_proxy_get_timestamp(GstVaapiSurfaceProxy *proxy)
346 g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy), GST_CLOCK_TIME_NONE);
348 return proxy->priv->timestamp;
352 * gst_vaapi_surface_proxy_set_timestamp:
353 * @proxy: a #GstVaapiSurfaceProxy
354 * @timestamp: the new presentation timestamp as a #GstClockTime
356 * Sets the presentation timestamp of the @proxy surface to @timestamp.
359 gst_vaapi_surface_proxy_set_timestamp(
360 GstVaapiSurfaceProxy *proxy,
361 GstClockTime timestamp
364 g_return_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy));
366 proxy->priv->timestamp = timestamp;
370 * gst_vaapi_surface_proxy_get_interlaced:
371 * @proxy: a #GstVaapiSurfaceProxy
373 * Returns whether the @proxy holds an interlaced #GstVaapiSurface or not.
375 * Return value: %TRUE if the underlying surface is interlaced, %FALSE
379 gst_vaapi_surface_proxy_get_interlaced(GstVaapiSurfaceProxy *proxy)
381 g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy), FALSE);
383 return proxy->priv->is_interlaced;
387 * gst_vaapi_surface_proxy_set_interlaced:
388 * @proxy: a #GstVaapiSurfaceProxy
389 * @b: a boolean value
391 * Sets whether the underlying #GstVaapiSurface for @proxy is interlaced
395 gst_vaapi_surface_proxy_set_interlaced(GstVaapiSurfaceProxy *proxy, gboolean b)
397 g_return_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy));
399 proxy->priv->is_interlaced = b;
403 * gst_vaapi_surface_proxy_get_tff:
404 * @proxy: a #GstVaapiSurfaceProxy
406 * Returns the TFF flag of the #GstVaapiSurface held by @proxy.
408 * Return value: the TFF flag of the surface
411 gst_vaapi_surface_proxy_get_tff(GstVaapiSurfaceProxy *proxy)
413 g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy), FALSE);
415 return proxy->priv->is_interlaced && proxy->priv->tff;
419 * gst_vaapi_surface_proxy_set_tff:
420 * @proxy: a #GstVaapiSurfaceProxy
421 * @tff: the new value of the TFF flag
423 * Sets the TFF flag of the @proxy surface to @tff.
426 gst_vaapi_surface_proxy_set_tff(GstVaapiSurfaceProxy *proxy, gboolean tff)
428 g_return_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy));
430 proxy->priv->tff = tff;