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;
59 gst_vaapi_surface_proxy_finalize(GObject *object)
61 GstVaapiSurfaceProxy * const proxy = GST_VAAPI_SURFACE_PROXY(object);
63 gst_vaapi_surface_proxy_set_surface(proxy, NULL);
64 gst_vaapi_surface_proxy_set_context(proxy, NULL);
66 G_OBJECT_CLASS(gst_vaapi_surface_proxy_parent_class)->finalize(object);
70 gst_vaapi_surface_proxy_set_property(
77 GstVaapiSurfaceProxy * const proxy = GST_VAAPI_SURFACE_PROXY(object);
81 gst_vaapi_surface_proxy_set_context(proxy, g_value_get_pointer(value));
84 gst_vaapi_surface_proxy_set_surface(proxy, g_value_get_pointer(value));
87 gst_vaapi_surface_proxy_set_timestamp(proxy, g_value_get_uint64(value));
90 gst_vaapi_surface_proxy_set_tff(proxy, g_value_get_boolean(value));
93 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
99 gst_vaapi_surface_proxy_get_property(
106 GstVaapiSurfaceProxy * const proxy = GST_VAAPI_SURFACE_PROXY(object);
110 g_value_set_pointer(value, gst_vaapi_surface_proxy_get_context(proxy));
113 g_value_set_pointer(value, gst_vaapi_surface_proxy_get_surface(proxy));
116 g_value_set_uint64(value, gst_vaapi_surface_proxy_get_timestamp(proxy));
119 g_value_set_boolean(value, gst_vaapi_surface_proxy_get_tff(proxy));
122 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
128 gst_vaapi_surface_proxy_class_init(GstVaapiSurfaceProxyClass *klass)
130 GObjectClass * const object_class = G_OBJECT_CLASS(klass);
132 g_type_class_add_private(klass, sizeof(GstVaapiSurfaceProxyPrivate));
134 object_class->finalize = gst_vaapi_surface_proxy_finalize;
135 object_class->set_property = gst_vaapi_surface_proxy_set_property;
136 object_class->get_property = gst_vaapi_surface_proxy_get_property;
138 g_object_class_install_property
141 g_param_spec_pointer("context",
143 "The context stored in the proxy",
146 g_object_class_install_property
149 g_param_spec_pointer("surface",
151 "The surface stored in the proxy",
154 g_object_class_install_property
157 g_param_spec_uint64("timestamp",
159 "The presentation time of the surface",
160 0, G_MAXUINT64, GST_CLOCK_TIME_NONE,
163 g_object_class_install_property
166 g_param_spec_boolean("tff",
168 "Flag indicating for interlaced surfaces whether Top Field is First",
174 gst_vaapi_surface_proxy_init(GstVaapiSurfaceProxy *proxy)
176 GstVaapiSurfaceProxyPrivate *priv;
178 priv = GST_VAAPI_SURFACE_PROXY_GET_PRIVATE(proxy);
180 priv->context = NULL;
181 priv->surface = NULL;
182 priv->timestamp = GST_CLOCK_TIME_NONE;
187 * gst_vaapi_surface_proxy_new:
188 * @context: a #GstVaapiContext
189 * @surface: a #GstVaapiSurface
191 * Creates a new #GstVaapiSurfaceProxy with the specified context and
194 * Return value: the newly allocated #GstVaapiSurfaceProxy object
196 GstVaapiSurfaceProxy *
197 gst_vaapi_surface_proxy_new(GstVaapiContext *context, GstVaapiSurface *surface)
199 g_return_val_if_fail(GST_VAAPI_IS_CONTEXT(context), NULL);
200 g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), NULL);
202 return g_object_new(GST_VAAPI_TYPE_SURFACE_PROXY,
209 * gst_vaapi_surface_proxy_get_context:
210 * @proxy: a #GstVaapiSurfaceProxy
212 * Returns the #GstVaapiContext stored in the @proxy.
214 * Return value: the #GstVaapiContext
217 gst_vaapi_surface_proxy_get_context(GstVaapiSurfaceProxy *proxy)
219 g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy), NULL);
221 return proxy->priv->context;
225 * gst_vaapi_surface_proxy_set_context:
226 * @proxy: a #GstVaapiSurfaceProxy
227 * @context: the new #GstVaapiContext to be stored in @proxy
229 * Stores a new @context into the @proxy. The proxy releases the
230 * previous reference, if any, and then holds a reference to the new
234 gst_vaapi_surface_proxy_set_context(
235 GstVaapiSurfaceProxy *proxy,
236 GstVaapiContext *context
239 GstVaapiSurfaceProxyPrivate *priv;
241 g_return_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy));
246 g_object_unref(priv->context);
247 priv->context = NULL;
251 priv->context = g_object_ref(context);
255 * gst_vaapi_surface_proxy_get_surface:
256 * @proxy: a #GstVaapiSurfaceProxy
258 * Returns the #GstVaapiSurface stored in the @proxy.
260 * Return value: the #GstVaapiSurface
263 gst_vaapi_surface_proxy_get_surface(GstVaapiSurfaceProxy *proxy)
265 g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy), NULL);
267 return proxy->priv->surface;
271 * gst_vaapi_surface_proxy_get_surface_id:
272 * @proxy: a #GstVaapiSurfaceProxy
274 * Returns the VA surface ID stored in the @proxy.
276 * Return value: the #GstVaapiID
279 gst_vaapi_surface_proxy_get_surface_id(GstVaapiSurfaceProxy *proxy)
281 g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy), GST_VAAPI_ID_NONE);
282 g_return_val_if_fail(proxy->priv->surface != NULL, GST_VAAPI_ID_NONE);
284 return GST_VAAPI_OBJECT_ID(proxy->priv->surface);
288 * gst_vaapi_surface_proxy_set_surface:
289 * @proxy: a #GstVaapiSurfaceProxy
290 * @surface: the new #GstVaapiSurface to be stored in @proxy
292 * Stores a new @surface into the @proxy. The proxy releases the
293 * previous reference, if any, and then holds a reference to the new
297 gst_vaapi_surface_proxy_set_surface(
298 GstVaapiSurfaceProxy *proxy,
299 GstVaapiSurface *surface
302 GstVaapiSurfaceProxyPrivate *priv;
304 g_return_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy));
310 gst_vaapi_context_put_surface(priv->context, priv->surface);
311 g_object_unref(priv->surface);
312 priv->surface = NULL;
316 priv->surface = g_object_ref(surface);
320 * gst_vaapi_surface_proxy_get_timestamp:
321 * @proxy: a #GstVaapiSurfaceProxy
323 * Returns the presentation timestamp of the #GstVaapiSurface held by @proxy.
325 * Return value: the presentation timestamp of the surface, or
326 * %GST_CLOCK_TIME_NONE is none was set
329 gst_vaapi_surface_proxy_get_timestamp(GstVaapiSurfaceProxy *proxy)
331 g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy), GST_CLOCK_TIME_NONE);
333 return proxy->priv->timestamp;
337 * gst_vaapi_surface_proxy_set_timestamp:
338 * @proxy: a #GstVaapiSurfaceProxy
339 * @timestamp: the new presentation timestamp as a #GstClockTime
341 * Sets the presentation timestamp of the @proxy surface to @timestamp.
344 gst_vaapi_surface_proxy_set_timestamp(
345 GstVaapiSurfaceProxy *proxy,
346 GstClockTime timestamp
349 g_return_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy));
351 proxy->priv->timestamp = timestamp;
355 * gst_vaapi_surface_proxy_get_tff:
356 * @proxy: a #GstVaapiSurfaceProxy
358 * Returns the TFF flag of the #GstVaapiSurface held by @proxy.
360 * Return value: the TFF flag of the surface
363 gst_vaapi_surface_proxy_get_tff(GstVaapiSurfaceProxy *proxy)
365 g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy), FALSE);
367 return proxy->priv->tff;
371 * gst_vaapi_surface_proxy_set_tff:
372 * @proxy: a #GstVaapiSurfaceProxy
373 * @tff: the new value of the TFF flag
375 * Sets the TFF flag of the @proxy surface to @tff.
378 gst_vaapi_surface_proxy_set_tff(GstVaapiSurfaceProxy *proxy, gboolean tff)
380 g_return_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy));
382 proxy->priv->tff = tff;