surfaceproxy: add TFF property.
[platform/upstream/gstreamer-vaapi.git] / gst-libs / gst / vaapi / gstvaapisurfaceproxy.c
1 /*
2  *  gstvaapisurfaceproxy.c - VA surface proxy
3  *
4  *  Copyright (C) 2010-2011 Splitted-Desktop Systems
5  *  Copyright (C) 2011-2012 Intel Corporation
6  *
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.
11  *
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.
16  *
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
21  */
22
23 /**
24  * SECTION:gstvaapisurfaceproxy
25  * @short_description: VA surface proxy
26  */
27
28 #include "sysdeps.h"
29 #include "gstvaapisurfaceproxy.h"
30 #include "gstvaapiobject_priv.h"
31
32 #define DEBUG 1
33 #include "gstvaapidebug.h"
34
35 G_DEFINE_TYPE(GstVaapiSurfaceProxy, gst_vaapi_surface_proxy, G_TYPE_OBJECT);
36
37 #define GST_VAAPI_SURFACE_PROXY_GET_PRIVATE(obj)                \
38     (G_TYPE_INSTANCE_GET_PRIVATE((obj),                         \
39                                  GST_VAAPI_TYPE_SURFACE_PROXY,  \
40                                  GstVaapiSurfaceProxyPrivate))
41
42 struct _GstVaapiSurfaceProxyPrivate {
43     GstVaapiContext    *context;
44     GstVaapiSurface    *surface;
45     GstClockTime        timestamp;
46     gboolean            tff;
47 };
48
49 enum {
50     PROP_0,
51
52     PROP_CONTEXT,
53     PROP_SURFACE,
54     PROP_TIMESTAMP,
55     PROP_TFF
56 };
57
58 static void
59 gst_vaapi_surface_proxy_finalize(GObject *object)
60 {
61     GstVaapiSurfaceProxy * const proxy = GST_VAAPI_SURFACE_PROXY(object);
62
63     gst_vaapi_surface_proxy_set_surface(proxy, NULL);
64     gst_vaapi_surface_proxy_set_context(proxy, NULL);
65
66     G_OBJECT_CLASS(gst_vaapi_surface_proxy_parent_class)->finalize(object);
67 }
68
69 static void
70 gst_vaapi_surface_proxy_set_property(
71     GObject      *object,
72     guint         prop_id,
73     const GValue *value,
74     GParamSpec   *pspec
75 )
76 {
77     GstVaapiSurfaceProxy * const proxy = GST_VAAPI_SURFACE_PROXY(object);
78
79     switch (prop_id) {
80     case PROP_CONTEXT:
81         gst_vaapi_surface_proxy_set_context(proxy, g_value_get_pointer(value));
82         break;
83     case PROP_SURFACE:
84         gst_vaapi_surface_proxy_set_surface(proxy, g_value_get_pointer(value));
85         break;
86     case PROP_TIMESTAMP:
87         gst_vaapi_surface_proxy_set_timestamp(proxy, g_value_get_uint64(value));
88         break;
89     case PROP_TFF:
90         gst_vaapi_surface_proxy_set_tff(proxy, g_value_get_boolean(value));
91         break;
92     default:
93         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
94         break;
95     }
96 }
97
98 static void
99 gst_vaapi_surface_proxy_get_property(
100     GObject    *object,
101     guint       prop_id,
102     GValue     *value,
103     GParamSpec *pspec
104 )
105 {
106     GstVaapiSurfaceProxy * const proxy = GST_VAAPI_SURFACE_PROXY(object);
107
108     switch (prop_id) {
109     case PROP_CONTEXT:
110         g_value_set_pointer(value, gst_vaapi_surface_proxy_get_context(proxy));
111         break;
112     case PROP_SURFACE:
113         g_value_set_pointer(value, gst_vaapi_surface_proxy_get_surface(proxy));
114         break;
115     case PROP_TIMESTAMP:
116         g_value_set_uint64(value, gst_vaapi_surface_proxy_get_timestamp(proxy));
117         break;
118     case PROP_TFF:
119         g_value_set_boolean(value, gst_vaapi_surface_proxy_get_tff(proxy));
120         break;
121     default:
122         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
123         break;
124     }
125 }
126
127 static void
128 gst_vaapi_surface_proxy_class_init(GstVaapiSurfaceProxyClass *klass)
129 {
130     GObjectClass * const object_class = G_OBJECT_CLASS(klass);
131
132     g_type_class_add_private(klass, sizeof(GstVaapiSurfaceProxyPrivate));
133
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;
137
138     g_object_class_install_property
139         (object_class,
140          PROP_CONTEXT,
141          g_param_spec_pointer("context",
142                               "Context",
143                               "The context stored in the proxy",
144                               G_PARAM_READWRITE));
145
146     g_object_class_install_property
147         (object_class,
148          PROP_SURFACE,
149          g_param_spec_pointer("surface",
150                               "Surface",
151                               "The surface stored in the proxy",
152                               G_PARAM_READWRITE));
153
154     g_object_class_install_property
155         (object_class,
156          PROP_TIMESTAMP,
157          g_param_spec_uint64("timestamp",
158                              "Timestamp",
159                              "The presentation time of the surface",
160                              0, G_MAXUINT64, GST_CLOCK_TIME_NONE,
161                              G_PARAM_READWRITE));
162
163     g_object_class_install_property
164         (object_class,
165          PROP_TFF,
166          g_param_spec_boolean("tff",
167                               "Top-Field-First",
168                               "Flag indicating for interlaced surfaces whether Top Field is First",
169                               FALSE,
170                               G_PARAM_READWRITE));
171 }
172
173 static void
174 gst_vaapi_surface_proxy_init(GstVaapiSurfaceProxy *proxy)
175
176     GstVaapiSurfaceProxyPrivate *priv;
177
178     priv                = GST_VAAPI_SURFACE_PROXY_GET_PRIVATE(proxy);
179     proxy->priv         = priv;
180     priv->context       = NULL;
181     priv->surface       = NULL;
182     priv->timestamp     = GST_CLOCK_TIME_NONE;
183     priv->tff           = FALSE;
184 }
185
186 /**
187  * gst_vaapi_surface_proxy_new:
188  * @context: a #GstVaapiContext
189  * @surface: a #GstVaapiSurface
190  *
191  * Creates a new #GstVaapiSurfaceProxy with the specified context and
192  * surface.
193  *
194  * Return value: the newly allocated #GstVaapiSurfaceProxy object
195  */
196 GstVaapiSurfaceProxy *
197 gst_vaapi_surface_proxy_new(GstVaapiContext *context, GstVaapiSurface *surface)
198 {
199     g_return_val_if_fail(GST_VAAPI_IS_CONTEXT(context), NULL);
200     g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), NULL);
201
202     return g_object_new(GST_VAAPI_TYPE_SURFACE_PROXY,
203                         "context",  context,
204                         "surface",  surface,
205                         NULL);
206 }
207
208 /**
209  * gst_vaapi_surface_proxy_get_context:
210  * @proxy: a #GstVaapiSurfaceProxy
211  *
212  * Returns the #GstVaapiContext stored in the @proxy.
213  *
214  * Return value: the #GstVaapiContext
215  */
216 GstVaapiContext *
217 gst_vaapi_surface_proxy_get_context(GstVaapiSurfaceProxy *proxy)
218 {
219     g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy), NULL);
220
221     return proxy->priv->context;
222 }
223
224 /**
225  * gst_vaapi_surface_proxy_set_context:
226  * @proxy: a #GstVaapiSurfaceProxy
227  * @context: the new #GstVaapiContext to be stored in @proxy
228  *
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
231  * @context.
232  */
233 void
234 gst_vaapi_surface_proxy_set_context(
235     GstVaapiSurfaceProxy *proxy,
236     GstVaapiContext      *context
237 )
238 {
239     GstVaapiSurfaceProxyPrivate *priv;
240
241     g_return_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy));
242
243     priv = proxy->priv;
244
245     if (priv->context) {
246         g_object_unref(priv->context);
247         priv->context = NULL;
248     }
249
250     if (context)
251         priv->context = g_object_ref(context);
252 }
253
254 /**
255  * gst_vaapi_surface_proxy_get_surface:
256  * @proxy: a #GstVaapiSurfaceProxy
257  *
258  * Returns the #GstVaapiSurface stored in the @proxy.
259  *
260  * Return value: the #GstVaapiSurface
261  */
262 GstVaapiSurface *
263 gst_vaapi_surface_proxy_get_surface(GstVaapiSurfaceProxy *proxy)
264 {
265     g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy), NULL);
266
267     return proxy->priv->surface;
268 }
269
270 /**
271  * gst_vaapi_surface_proxy_get_surface_id:
272  * @proxy: a #GstVaapiSurfaceProxy
273  *
274  * Returns the VA surface ID stored in the @proxy.
275  *
276  * Return value: the #GstVaapiID
277  */
278 GstVaapiID
279 gst_vaapi_surface_proxy_get_surface_id(GstVaapiSurfaceProxy *proxy)
280 {
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);
283
284     return GST_VAAPI_OBJECT_ID(proxy->priv->surface);
285 }
286
287 /**
288  * gst_vaapi_surface_proxy_set_surface:
289  * @proxy: a #GstVaapiSurfaceProxy
290  * @surface: the new #GstVaapiSurface to be stored in @proxy
291  *
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
294  * @surface.
295  */
296 void
297 gst_vaapi_surface_proxy_set_surface(
298     GstVaapiSurfaceProxy *proxy,
299     GstVaapiSurface      *surface
300 )
301 {
302     GstVaapiSurfaceProxyPrivate *priv;
303
304     g_return_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy));
305
306     priv = proxy->priv;
307
308     if (priv->surface) {
309         if (priv->context)
310             gst_vaapi_context_put_surface(priv->context, priv->surface);
311         g_object_unref(priv->surface);
312         priv->surface = NULL;
313     }
314
315     if (surface)
316         priv->surface = g_object_ref(surface);
317 }
318
319 /**
320  * gst_vaapi_surface_proxy_get_timestamp:
321  * @proxy: a #GstVaapiSurfaceProxy
322  *
323  * Returns the presentation timestamp of the #GstVaapiSurface held by @proxy.
324  *
325  * Return value: the presentation timestamp of the surface, or
326  *   %GST_CLOCK_TIME_NONE is none was set
327  */
328 GstClockTime
329 gst_vaapi_surface_proxy_get_timestamp(GstVaapiSurfaceProxy *proxy)
330 {
331     g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy), GST_CLOCK_TIME_NONE);
332
333     return proxy->priv->timestamp;
334 }
335
336 /**
337  * gst_vaapi_surface_proxy_set_timestamp:
338  * @proxy: a #GstVaapiSurfaceProxy
339  * @timestamp: the new presentation timestamp as a #GstClockTime
340  *
341  * Sets the presentation timestamp of the @proxy surface to @timestamp.
342  */
343 void
344 gst_vaapi_surface_proxy_set_timestamp(
345     GstVaapiSurfaceProxy *proxy,
346     GstClockTime          timestamp
347 )
348 {
349     g_return_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy));
350
351     proxy->priv->timestamp = timestamp;
352 }
353
354 /**
355  * gst_vaapi_surface_proxy_get_tff:
356  * @proxy: a #GstVaapiSurfaceProxy
357  *
358  * Returns the TFF flag of the #GstVaapiSurface held by @proxy.
359  *
360  * Return value: the TFF flag of the surface
361  */
362 gboolean
363 gst_vaapi_surface_proxy_get_tff(GstVaapiSurfaceProxy *proxy)
364 {
365     g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy), FALSE);
366
367     return proxy->priv->tff;
368 }
369
370 /**
371  * gst_vaapi_surface_proxy_set_tff:
372  * @proxy: a #GstVaapiSurfaceProxy
373  * @tff: the new value of the TFF flag
374  *
375  * Sets the TFF flag of the @proxy surface to @tff.
376  */
377 void
378 gst_vaapi_surface_proxy_set_tff(GstVaapiSurfaceProxy *proxy, gboolean tff)
379 {
380     g_return_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy));
381
382     proxy->priv->tff = tff;
383 }