decoder: drop obsolete functions.
[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 #include "gstvaapiminiobject.h"
32
33 #define DEBUG 1
34 #include "gstvaapidebug.h"
35
36 #define GST_VAAPI_SURFACE_PROXY(obj) \
37     ((GstVaapiSurfaceProxy *)(obj))
38
39 #define GST_VAAPI_IS_SURFACE_PROXY(obj) \
40     (GST_VAAPI_SURFACE_PROXY(obj) != NULL)
41
42 struct _GstVaapiSurfaceProxy {
43     /*< private >*/
44     GstVaapiMiniObject  parent_instance;
45
46     GstVaapiVideoPool  *pool;
47     GstVaapiSurface    *surface;
48 };
49
50 static void
51 gst_vaapi_surface_proxy_finalize(GstVaapiSurfaceProxy *proxy)
52 {
53     if (proxy->surface) {
54         if (proxy->pool)
55             gst_vaapi_video_pool_put_object(proxy->pool, proxy->surface);
56         g_object_unref(proxy->surface);
57         proxy->surface = NULL;
58     }
59     g_clear_object(&proxy->pool);
60 }
61
62 static inline const GstVaapiMiniObjectClass *
63 gst_vaapi_surface_proxy_class(void)
64 {
65     static const GstVaapiMiniObjectClass GstVaapiSurfaceProxyClass = {
66         sizeof(GstVaapiSurfaceProxy),
67         (GDestroyNotify)gst_vaapi_surface_proxy_finalize
68     };
69     return &GstVaapiSurfaceProxyClass;
70 }
71
72 GstVaapiSurfaceProxy *
73 gst_vaapi_surface_proxy_new_from_pool(GstVaapiSurfacePool *pool)
74 {
75     GstVaapiSurfaceProxy *proxy;
76
77     g_return_val_if_fail(GST_VAAPI_IS_SURFACE_POOL(pool), NULL);
78
79     proxy = (GstVaapiSurfaceProxy *)
80         gst_vaapi_mini_object_new(gst_vaapi_surface_proxy_class());
81     if (!proxy)
82         return NULL;
83
84     proxy->pool    = g_object_ref(pool);
85     proxy->surface = gst_vaapi_video_pool_get_object(proxy->pool);
86     if (!proxy->surface)
87         goto error;
88     g_object_ref(proxy->surface);
89     return proxy;
90
91 error:
92     gst_vaapi_surface_proxy_unref(proxy);
93     return NULL;
94 }
95
96 /**
97  * gst_vaapi_surface_proxy_ref:
98  * @proxy: a #GstVaapiSurfaceProxy
99  *
100  * Atomically increases the reference count of the given @proxy by one.
101  *
102  * Returns: The same @proxy argument
103  */
104 GstVaapiSurfaceProxy *
105 gst_vaapi_surface_proxy_ref(GstVaapiSurfaceProxy *proxy)
106 {
107     g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy), NULL);
108
109     return GST_VAAPI_SURFACE_PROXY(gst_vaapi_mini_object_ref(
110                                        GST_VAAPI_MINI_OBJECT(proxy)));
111 }
112
113 /**
114  * gst_vaapi_surface_proxy_unref:
115  * @proxy: a #GstVaapiSurfaceProxy
116  *
117  * Atomically decreases the reference count of the @proxy by one. If
118  * the reference count reaches zero, the object will be free'd.
119  */
120 void
121 gst_vaapi_surface_proxy_unref(GstVaapiSurfaceProxy *proxy)
122 {
123     g_return_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy));
124
125     gst_vaapi_mini_object_unref(GST_VAAPI_MINI_OBJECT(proxy));
126 }
127
128 /**
129  * gst_vaapi_surface_proxy_replace:
130  * @old_proxy_ptr: a pointer to a #GstVaapiSurfaceProxy
131  * @new_proxy: a #GstVaapiSurfaceProxy
132  *
133  * Atomically replaces the proxy object held in @old_proxy_ptr with
134  * @new_proxy. This means that @old_proxy_ptr shall reference a valid
135  * object. However, @new_proxy can be NULL.
136  */
137 void
138 gst_vaapi_surface_proxy_replace(GstVaapiSurfaceProxy **old_proxy_ptr,
139     GstVaapiSurfaceProxy *new_proxy)
140 {
141     g_return_if_fail(old_proxy_ptr != NULL);
142
143     gst_vaapi_mini_object_replace((GstVaapiMiniObject **)old_proxy_ptr,
144         GST_VAAPI_MINI_OBJECT(new_proxy));
145 }
146
147 /**
148  * gst_vaapi_surface_proxy_get_user_data:
149  * @proxy: a #GstVaapiSurfaceProxy
150  *
151  * Gets user-provided data set on the object via a previous call to
152  * gst_vaapi_surface_proxy_set_user_data().
153  *
154  * Returns: (transfer none): The previously set user_data
155  */
156 gpointer
157 gst_vaapi_surface_proxy_get_user_data(GstVaapiSurfaceProxy *proxy)
158 {
159     g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy), NULL);
160
161     return gst_vaapi_mini_object_get_user_data(GST_VAAPI_MINI_OBJECT(proxy));
162 }
163
164 /**
165  * gst_vaapi_surface_proxy_set_user_data:
166  * @proxy: a #GstVaapiSurfaceProxy
167  * @user_data: user-provided data
168  * @destroy_notify: (closure user_data): a #GDestroyNotify
169  *
170  * Sets @user_data on the object and the #GDestroyNotify that will be
171  * called when the data is freed.
172  *
173  * If some @user_data was previously set, then the former @destroy_notify
174  * function will be called before the @user_data is replaced.
175  */
176 void
177 gst_vaapi_surface_proxy_set_user_data(GstVaapiSurfaceProxy *proxy,
178     gpointer user_data, GDestroyNotify destroy_notify)
179 {
180     g_return_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy));
181
182     gst_vaapi_mini_object_set_user_data(GST_VAAPI_MINI_OBJECT(proxy),
183         user_data, destroy_notify);
184 }
185
186 /**
187  * gst_vaapi_surface_proxy_get_surface:
188  * @proxy: a #GstVaapiSurfaceProxy
189  *
190  * Returns the #GstVaapiSurface stored in the @proxy.
191  *
192  * Return value: the #GstVaapiSurface
193  */
194 GstVaapiSurface *
195 gst_vaapi_surface_proxy_get_surface(GstVaapiSurfaceProxy *proxy)
196 {
197     g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy), NULL);
198
199     return proxy->surface;
200 }
201
202 /**
203  * gst_vaapi_surface_proxy_get_surface_id:
204  * @proxy: a #GstVaapiSurfaceProxy
205  *
206  * Returns the VA surface ID stored in the @proxy.
207  *
208  * Return value: the #GstVaapiID
209  */
210 GstVaapiID
211 gst_vaapi_surface_proxy_get_surface_id(GstVaapiSurfaceProxy *proxy)
212 {
213     g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy), GST_VAAPI_ID_NONE);
214     g_return_val_if_fail(proxy->surface != NULL, GST_VAAPI_ID_NONE);
215
216     return GST_VAAPI_OBJECT_ID(proxy->surface);
217 }