Tizen 2.0 Release
[framework/multimedia/gstreamer-vaapi.git] / gst-libs / gst / vaapi / gstvaapiobject.c
1 /*
2  *  gstvaapiobject.c - Base VA object
3  *
4  *  Copyright (C) 2010-2011 Splitted-Desktop Systems
5  *
6  *  This library is free software; you can redistribute it and/or
7  *  modify it under the terms of the GNU Lesser General Public License
8  *  as published by the Free Software Foundation; either version 2.1
9  *  of the License, or (at your option) any later version.
10  *
11  *  This library is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  *  Lesser General Public License for more details.
15  *
16  *  You should have received a copy of the GNU Lesser General Public
17  *  License along with this library; if not, write to the Free
18  *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  *  Boston, MA 02110-1301 USA
20  */
21
22 /**
23  * SECTION:gstvaapiobject
24  * @short_description: Base VA object
25  */
26
27 #include "sysdeps.h"
28 #include "gstvaapiobject.h"
29 #include "gstvaapi_priv.h"
30 #include "gstvaapiparamspecs.h"
31 #include "gstvaapivalue.h"
32
33 #define DEBUG 1
34 #include "gstvaapidebug.h"
35
36 G_DEFINE_TYPE(GstVaapiObject, gst_vaapi_object, G_TYPE_OBJECT);
37
38 enum {
39     PROP_0,
40
41     PROP_DISPLAY,
42     PROP_ID
43 };
44
45 enum {
46     DESTROY,
47
48     LAST_SIGNAL
49 };
50
51 static guint object_signals[LAST_SIGNAL] = { 0, };
52
53 static void
54 gst_vaapi_object_dispose(GObject *object)
55 {
56     GstVaapiObjectPrivate * const priv = GST_VAAPI_OBJECT(object)->priv;
57
58     if (!priv->is_destroying) {
59         priv->is_destroying = TRUE;
60         g_signal_emit(object, object_signals[DESTROY], 0);
61         priv->is_destroying = FALSE;
62     }
63
64     G_OBJECT_CLASS(gst_vaapi_object_parent_class)->dispose(object);
65 }
66
67 static void
68 gst_vaapi_object_finalize(GObject *object)
69 {
70     GstVaapiObjectPrivate * const priv = GST_VAAPI_OBJECT(object)->priv;
71
72     priv->id = GST_VAAPI_ID_NONE;
73
74     g_clear_object(&priv->display);
75
76     G_OBJECT_CLASS(gst_vaapi_object_parent_class)->finalize(object);
77 }
78
79 static void
80 gst_vaapi_object_set_property(
81     GObject      *gobject,
82     guint         prop_id,
83     const GValue *value,
84     GParamSpec   *pspec
85 )
86 {
87     GstVaapiObject * const object = GST_VAAPI_OBJECT(gobject);
88
89     switch (prop_id) {
90     case PROP_DISPLAY:
91         object->priv->display = g_object_ref(g_value_get_object(value));
92         break;
93     case PROP_ID:
94         object->priv->id = gst_vaapi_value_get_id(value);
95         break;
96     default:
97         G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, pspec);
98         break;
99     }
100 }
101
102 static void
103 gst_vaapi_object_get_property(
104     GObject    *gobject,
105     guint       prop_id,
106     GValue     *value,
107     GParamSpec *pspec
108 )
109 {
110     GstVaapiObject * const object = GST_VAAPI_OBJECT(gobject);
111
112     switch (prop_id) {
113     case PROP_DISPLAY:
114         g_value_set_object(value, gst_vaapi_object_get_display(object));
115         break;
116     case PROP_ID:
117         gst_vaapi_value_set_id(value, gst_vaapi_object_get_id(object));
118         break;
119     default:
120         G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, pspec);
121         break;
122     }
123 }
124
125 static void
126 gst_vaapi_object_class_init(GstVaapiObjectClass *klass)
127 {
128     GObjectClass * const object_class = G_OBJECT_CLASS(klass);
129
130     g_type_class_add_private(klass, sizeof(GstVaapiObjectPrivate));
131
132     object_class->dispose      = gst_vaapi_object_dispose;
133     object_class->finalize     = gst_vaapi_object_finalize;
134     object_class->set_property = gst_vaapi_object_set_property;
135     object_class->get_property = gst_vaapi_object_get_property;
136
137     /**
138      * GstVaapiObject:display:
139      *
140      * The #GstVaapiDisplay this object is bound to.
141      */
142     g_object_class_install_property
143         (object_class,
144          PROP_DISPLAY,
145          g_param_spec_object("display",
146                              "Display",
147                              "The GstVaapiDisplay this object is bound to",
148                              GST_VAAPI_TYPE_DISPLAY,
149                              G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
150
151     /**
152      * GstVaapiObject:id:
153      *
154      * The #GstVaapiID contained in this object.
155      */
156     g_object_class_install_property
157         (object_class,
158          PROP_ID,
159          gst_vaapi_param_spec_id("id",
160                                  "ID",
161                                  "The GstVaapiID contained in this object",
162                                  GST_VAAPI_ID_NONE,
163                                  G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
164
165     /**
166      * GstVaapiObject::destroy:
167      * @object: the object which received the signal
168      *
169      * The ::destroy signal is emitted when an object is destroyed,
170      * when the user released the last reference to @object.
171      */
172     object_signals[DESTROY] = g_signal_new(
173         "destroy",
174         G_TYPE_FROM_CLASS(object_class),
175         G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
176         G_STRUCT_OFFSET(GstVaapiObjectClass, destroy),
177         NULL, NULL,
178         g_cclosure_marshal_VOID__VOID,
179         G_TYPE_NONE, 0
180     );
181 }
182
183 static void
184 gst_vaapi_object_init(GstVaapiObject *object)
185 {
186     GstVaapiObjectPrivate *priv = GST_VAAPI_OBJECT_GET_PRIVATE(object);
187
188     object->priv        = priv;
189     priv->display       = NULL;
190     priv->id            = GST_VAAPI_ID_NONE;
191     priv->is_destroying = FALSE;
192 }
193
194 /**
195  * gst_vaapi_object_get_display:
196  * @object: a #GstVaapiObject
197  *
198  * Returns the #GstVaapiDisplay this @object is bound to.
199  *
200  * Return value: the parent #GstVaapiDisplay object
201  */
202 GstVaapiDisplay *
203 gst_vaapi_object_get_display(GstVaapiObject *object)
204 {
205     g_return_val_if_fail(GST_VAAPI_IS_OBJECT(object), NULL);
206
207     return object->priv->display;
208 }
209
210 /**
211  * gst_vaapi_object_lock_display:
212  * @object: a #GstVaapiObject
213  *
214  * Locks @object parent display. If display is already locked by
215  * another thread, the current thread will block until display is
216  * unlocked by the other thread.
217  */
218 void
219 gst_vaapi_object_lock_display(GstVaapiObject *object)
220 {
221     g_return_if_fail(GST_VAAPI_IS_OBJECT(object));
222
223     GST_VAAPI_OBJECT_LOCK_DISPLAY(object);
224 }
225
226 /**
227  * gst_vaapi_object_unlock_display:
228  * @object: a #GstVaapiObject
229  *
230  * Unlocks @object parent display. If another thread is blocked in a
231  * gst_vaapi_object_lock_display() call, it will be woken and can lock
232  * display itself.
233  */
234 void
235 gst_vaapi_object_unlock_display(GstVaapiObject *object)
236 {
237     g_return_if_fail(GST_VAAPI_IS_OBJECT(object));
238
239     GST_VAAPI_OBJECT_UNLOCK_DISPLAY(object);
240 }
241
242 /**
243  * gst_vaapi_object_get_id:
244  * @object: a #GstVaapiObject
245  *
246  * Returns the #GstVaapiID contained in the @object.
247  *
248  * Return value: the #GstVaapiID of the @object
249  */
250 GstVaapiID
251 gst_vaapi_object_get_id(GstVaapiObject *object)
252 {
253     g_return_val_if_fail(GST_VAAPI_IS_OBJECT(object), GST_VAAPI_ID_NONE);
254
255     return object->priv->id;
256 }