legal: fix year for some copyright notices.
[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 "config.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 };
47
48 enum {
49     PROP_0,
50
51     PROP_CONTEXT,
52     PROP_SURFACE,
53     PROP_TIMESTAMP
54 };
55
56 static void
57 gst_vaapi_surface_proxy_finalize(GObject *object)
58 {
59     GstVaapiSurfaceProxy * const proxy = GST_VAAPI_SURFACE_PROXY(object);
60
61     gst_vaapi_surface_proxy_set_surface(proxy, NULL);
62     gst_vaapi_surface_proxy_set_context(proxy, NULL);
63
64     G_OBJECT_CLASS(gst_vaapi_surface_proxy_parent_class)->finalize(object);
65 }
66
67 static void
68 gst_vaapi_surface_proxy_set_property(
69     GObject      *object,
70     guint         prop_id,
71     const GValue *value,
72     GParamSpec   *pspec
73 )
74 {
75     GstVaapiSurfaceProxy * const proxy = GST_VAAPI_SURFACE_PROXY(object);
76
77     switch (prop_id) {
78     case PROP_CONTEXT:
79         gst_vaapi_surface_proxy_set_context(proxy, g_value_get_pointer(value));
80         break;
81     case PROP_SURFACE:
82         gst_vaapi_surface_proxy_set_surface(proxy, g_value_get_pointer(value));
83         break;
84     case PROP_TIMESTAMP:
85         gst_vaapi_surface_proxy_set_timestamp(proxy, g_value_get_uint64(value));
86         break;
87     default:
88         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
89         break;
90     }
91 }
92
93 static void
94 gst_vaapi_surface_proxy_get_property(
95     GObject    *object,
96     guint       prop_id,
97     GValue     *value,
98     GParamSpec *pspec
99 )
100 {
101     GstVaapiSurfaceProxy * const proxy = GST_VAAPI_SURFACE_PROXY(object);
102
103     switch (prop_id) {
104     case PROP_CONTEXT:
105         g_value_set_pointer(value, gst_vaapi_surface_proxy_get_context(proxy));
106         break;
107     case PROP_SURFACE:
108         g_value_set_pointer(value, gst_vaapi_surface_proxy_get_surface(proxy));
109         break;
110     case PROP_TIMESTAMP:
111         g_value_set_uint64(value, gst_vaapi_surface_proxy_get_timestamp(proxy));
112         break;
113     default:
114         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
115         break;
116     }
117 }
118
119 static void
120 gst_vaapi_surface_proxy_class_init(GstVaapiSurfaceProxyClass *klass)
121 {
122     GObjectClass * const object_class = G_OBJECT_CLASS(klass);
123
124     g_type_class_add_private(klass, sizeof(GstVaapiSurfaceProxyPrivate));
125
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;
129
130     g_object_class_install_property
131         (object_class,
132          PROP_CONTEXT,
133          g_param_spec_pointer("context",
134                               "Context",
135                               "The context stored in the proxy",
136                               G_PARAM_READWRITE));
137
138     g_object_class_install_property
139         (object_class,
140          PROP_SURFACE,
141          g_param_spec_pointer("surface",
142                               "Surface",
143                               "The surface stored in the proxy",
144                               G_PARAM_READWRITE));
145
146     g_object_class_install_property
147         (object_class,
148          PROP_TIMESTAMP,
149          g_param_spec_uint64("timestamp",
150                              "Timestamp",
151                              "The presentation time of the surface",
152                              0, G_MAXUINT64, GST_CLOCK_TIME_NONE,
153                              G_PARAM_READWRITE));
154 }
155
156 static void
157 gst_vaapi_surface_proxy_init(GstVaapiSurfaceProxy *proxy)
158
159     GstVaapiSurfaceProxyPrivate *priv;
160
161     priv                = GST_VAAPI_SURFACE_PROXY_GET_PRIVATE(proxy);
162     proxy->priv         = priv;
163     priv->context       = NULL;
164     priv->surface       = NULL;
165     priv->timestamp     = GST_CLOCK_TIME_NONE;
166 }
167
168 /**
169  * gst_vaapi_surface_proxy_new:
170  * @context: a #GstVaapiContext
171  * @surface: a #GstVaapiSurface
172  *
173  * Creates a new #GstVaapiSurfaceProxy with the specified context and
174  * surface.
175  *
176  * Return value: the newly allocated #GstVaapiSurfaceProxy object
177  */
178 GstVaapiSurfaceProxy *
179 gst_vaapi_surface_proxy_new(GstVaapiContext *context, GstVaapiSurface *surface)
180 {
181     g_return_val_if_fail(GST_VAAPI_IS_CONTEXT(context), NULL);
182     g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), NULL);
183
184     return g_object_new(GST_VAAPI_TYPE_SURFACE_PROXY,
185                         "context",  context,
186                         "surface",  surface,
187                         NULL);
188 }
189
190 /**
191  * gst_vaapi_surface_proxy_get_context:
192  * @proxy: a #GstVaapiSurfaceProxy
193  *
194  * Returns the #GstVaapiContext stored in the @proxy.
195  *
196  * Return value: the #GstVaapiContext
197  */
198 GstVaapiContext *
199 gst_vaapi_surface_proxy_get_context(GstVaapiSurfaceProxy *proxy)
200 {
201     g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy), NULL);
202
203     return proxy->priv->context;
204 }
205
206 /**
207  * gst_vaapi_surface_proxy_set_context:
208  * @proxy: a #GstVaapiSurfaceProxy
209  * @context: the new #GstVaapiContext to be stored in @proxy
210  *
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
213  * @context.
214  */
215 void
216 gst_vaapi_surface_proxy_set_context(
217     GstVaapiSurfaceProxy *proxy,
218     GstVaapiContext      *context
219 )
220 {
221     GstVaapiSurfaceProxyPrivate *priv;
222
223     g_return_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy));
224
225     priv = proxy->priv;
226
227     if (priv->context) {
228         g_object_unref(priv->context);
229         priv->context = NULL;
230     }
231
232     if (context)
233         priv->context = g_object_ref(context);
234 }
235
236 /**
237  * gst_vaapi_surface_proxy_get_surface:
238  * @proxy: a #GstVaapiSurfaceProxy
239  *
240  * Returns the #GstVaapiSurface stored in the @proxy.
241  *
242  * Return value: the #GstVaapiSurface
243  */
244 GstVaapiSurface *
245 gst_vaapi_surface_proxy_get_surface(GstVaapiSurfaceProxy *proxy)
246 {
247     g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy), NULL);
248
249     return proxy->priv->surface;
250 }
251
252 /**
253  * gst_vaapi_surface_proxy_get_surface_id:
254  * @proxy: a #GstVaapiSurfaceProxy
255  *
256  * Returns the VA surface ID stored in the @proxy.
257  *
258  * Return value: the #GstVaapiID
259  */
260 GstVaapiID
261 gst_vaapi_surface_proxy_get_surface_id(GstVaapiSurfaceProxy *proxy)
262 {
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);
265
266     return GST_VAAPI_OBJECT_ID(proxy->priv->surface);
267 }
268
269 /**
270  * gst_vaapi_surface_proxy_set_surface:
271  * @proxy: a #GstVaapiSurfaceProxy
272  * @surface: the new #GstVaapiSurface to be stored in @proxy
273  *
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
276  * @surface.
277  */
278 void
279 gst_vaapi_surface_proxy_set_surface(
280     GstVaapiSurfaceProxy *proxy,
281     GstVaapiSurface      *surface
282 )
283 {
284     GstVaapiSurfaceProxyPrivate *priv;
285
286     g_return_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy));
287
288     priv = proxy->priv;
289
290     if (priv->surface) {
291         if (priv->context)
292             gst_vaapi_context_put_surface(priv->context, priv->surface);
293         g_object_unref(priv->surface);
294         priv->surface = NULL;
295     }
296
297     if (surface)
298         priv->surface = g_object_ref(surface);
299 }
300
301 /**
302  * gst_vaapi_surface_proxy_get_timestamp:
303  * @proxy: a #GstVaapiSurfaceProxy
304  *
305  * Returns the presentation timestamp of the #GstVaapiSurface held by @proxy.
306  *
307  * Return value: the presentation timestamp of the surface, or
308  *   %GST_CLOCK_TIME_NONE is none was set
309  */
310 GstClockTime
311 gst_vaapi_surface_proxy_get_timestamp(GstVaapiSurfaceProxy *proxy)
312 {
313     g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy), GST_CLOCK_TIME_NONE);
314
315     return proxy->priv->timestamp;
316 }
317
318 /**
319  * gst_vaapi_surface_proxy_set_timestamp:
320  * @proxy: a #GstVaapiSurfaceProxy
321  * @timestamp: the new presentation timestamp as a #GstClockTime
322  *
323  * Sets the presentation timestamp of the @proxy surface to @timestamp.
324  */
325 void
326 gst_vaapi_surface_proxy_set_timestamp(
327     GstVaapiSurfaceProxy *proxy,
328     GstClockTime          timestamp
329 )
330 {
331     g_return_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy));
332
333     proxy->priv->timestamp = timestamp;
334 }