Move GValue specific stuff to a dedicated file.
[platform/upstream/gstreamer-vaapi.git] / gst-libs / gst / vaapi / gstvaapiobject.c
1 /*
2  *  gstvaapiobject.c - Base VA object
3  *
4  *  gstreamer-vaapi (C) 2010 Splitted-Desktop Systems
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program 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
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
19  */
20
21 /**
22  * SECTION:gstvaapiobject
23  * @short_description: Base VA object
24  */
25
26 #include "config.h"
27 #include "gstvaapiobject.h"
28 #include "gstvaapiobject_priv.h"
29 #include "gstvaapiparamspecs.h"
30 #include "gstvaapivalue.h"
31 #include "gstvaapimarshal.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 = VA_INVALID_ID;
73
74     if (priv->display) {
75         g_object_unref(priv->display);
76         priv->display = NULL;
77     }
78
79     G_OBJECT_CLASS(gst_vaapi_object_parent_class)->finalize(object);
80 }
81
82 static void
83 gst_vaapi_object_set_property(
84     GObject      *gobject,
85     guint         prop_id,
86     const GValue *value,
87     GParamSpec   *pspec
88 )
89 {
90     GstVaapiObject * const object = GST_VAAPI_OBJECT(gobject);
91
92     switch (prop_id) {
93     case PROP_DISPLAY:
94         object->priv->display = g_object_ref(g_value_get_object(value));
95         break;
96     case PROP_ID:
97         object->priv->id = gst_vaapi_value_get_id(value);
98         break;
99     default:
100         G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, pspec);
101         break;
102     }
103 }
104
105 static void
106 gst_vaapi_object_get_property(
107     GObject    *gobject,
108     guint       prop_id,
109     GValue     *value,
110     GParamSpec *pspec
111 )
112 {
113     GstVaapiObject * const object = GST_VAAPI_OBJECT(gobject);
114
115     switch (prop_id) {
116     case PROP_DISPLAY:
117         g_value_set_object(value, gst_vaapi_object_get_display(object));
118         break;
119     case PROP_ID:
120         gst_vaapi_value_set_id(value, gst_vaapi_object_get_id(object));
121         break;
122     default:
123         G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, pspec);
124         break;
125     }
126 }
127
128 static void
129 gst_vaapi_object_class_init(GstVaapiObjectClass *klass)
130 {
131     GObjectClass * const object_class = G_OBJECT_CLASS(klass);
132
133     g_type_class_add_private(klass, sizeof(GstVaapiObjectPrivate));
134
135     object_class->dispose      = gst_vaapi_object_dispose;
136     object_class->finalize     = gst_vaapi_object_finalize;
137     object_class->set_property = gst_vaapi_object_set_property;
138     object_class->get_property = gst_vaapi_object_get_property;
139
140     /**
141      * GstVaapiObject:display:
142      *
143      * The #GstVaapiDisplay this object is bound to.
144      */
145     g_object_class_install_property
146         (object_class,
147          PROP_DISPLAY,
148          g_param_spec_object("display",
149                              "Display",
150                              "The GstVaapiDisplay this object is bound to",
151                              GST_VAAPI_TYPE_DISPLAY,
152                              G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
153
154     /**
155      * GstVaapiObject:id:
156      *
157      * The #GstVaapiID contained in this object.
158      */
159     g_object_class_install_property
160         (object_class,
161          PROP_ID,
162          gst_vaapi_param_spec_id("id",
163                                  "ID",
164                                  "The GstVaapiID contained in this object",
165                                  VA_INVALID_ID,
166                                  G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
167
168     /**
169      * GstVaapiObject::destroy:
170      * @object: the object which received the signal
171      *
172      * The ::destroy signal is emitted when an object is destroyed,
173      * when the user released the last reference to @object.
174      */
175     object_signals[DESTROY] = g_signal_new(
176         "destroy",
177         G_TYPE_FROM_CLASS(object_class),
178         G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
179         G_STRUCT_OFFSET(GstVaapiObjectClass, destroy),
180         NULL, NULL,
181         gst_vaapi_marshal_VOID__VOID,
182         G_TYPE_NONE, 0
183     );
184 }
185
186 static void
187 gst_vaapi_object_init(GstVaapiObject *object)
188 {
189     GstVaapiObjectPrivate *priv = GST_VAAPI_OBJECT_GET_PRIVATE(object);
190
191     object->priv        = priv;
192     priv->display       = NULL;
193     priv->id            = VA_INVALID_ID;
194     priv->is_destroying = FALSE;
195 }
196
197 /**
198  * gst_vaapi_object_get_display:
199  * @object: a #GstVaapiObject
200  *
201  * Returns the #GstVaapiDisplay this @object is bound to.
202  *
203  * Return value: the parent #GstVaapiDisplay object
204  */
205 GstVaapiDisplay *
206 gst_vaapi_object_get_display(GstVaapiObject *object)
207 {
208     g_return_val_if_fail(GST_VAAPI_IS_OBJECT(object), NULL);
209
210     return object->priv->display;
211 }
212
213 /**
214  * gst_vaapi_object_get_id:
215  * @object: a #GstVaapiObject
216  *
217  * Returns the #GstVaapiID contained in the @object.
218  *
219  * Return value: the #GstVaapiID of the @object
220  */
221 GstVaapiID
222 gst_vaapi_object_get_id(GstVaapiObject *object)
223 {
224     g_return_val_if_fail(GST_VAAPI_IS_OBJECT(object), VA_INVALID_ID);
225
226     return object->priv->id;
227 }