2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
4 * 2005 Wim Taymans <wim@fluendo.com>
6 * gstobject.h: Header for base GstObject
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
24 #ifndef __GST_OBJECT_H__
25 #define __GST_OBJECT_H__
27 #include <gst/gstconfig.h>
29 #include <glib-object.h>
33 #define GST_TYPE_OBJECT (gst_object_get_type ())
34 #define GST_IS_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_OBJECT))
35 #define GST_IS_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_OBJECT))
36 #define GST_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_OBJECT, GstObjectClass))
37 #define GST_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_OBJECT, GstObject))
38 #define GST_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_OBJECT, GstObjectClass))
39 #define GST_OBJECT_CAST(obj) ((GstObject*)(obj))
40 #define GST_OBJECT_CLASS_CAST(klass) ((GstObjectClass*)(klass))
44 * @GST_OBJECT_FLAG_MAY_BE_LEAKED: the object is expected to stay alive even
45 * after gst_deinit() has been called and so should be ignored by leak
46 * detection tools. (Since: 1.10)
47 * @GST_OBJECT_FLAG_LAST: subclasses can add additional flags starting from this flag
49 * The standard flags that an gstobject may have.
53 GST_OBJECT_FLAG_MAY_BE_LEAKED = (1 << 0),
55 GST_OBJECT_FLAG_LAST = (1<<4)
59 * GST_OBJECT_REFCOUNT:
62 * Get access to the reference count field of the object.
64 #define GST_OBJECT_REFCOUNT(obj) (((GObject*)(obj))->ref_count)
66 * GST_OBJECT_REFCOUNT_VALUE:
69 * Get the reference count value of the object.
71 #define GST_OBJECT_REFCOUNT_VALUE(obj) g_atomic_int_get ((gint *) &GST_OBJECT_REFCOUNT(obj))
73 /* we do a GST_OBJECT_CAST to avoid type checking, better call these
74 * function with a valid object! */
77 * GST_OBJECT_GET_LOCK:
80 * Acquire a reference to the mutex of this object.
82 #define GST_OBJECT_GET_LOCK(obj) (&GST_OBJECT_CAST(obj)->lock)
85 * @obj: a #GstObject to lock
87 * This macro will obtain a lock on the object, making serialization possible.
88 * It blocks until the lock can be obtained.
90 #define GST_OBJECT_LOCK(obj) g_mutex_lock(GST_OBJECT_GET_LOCK(obj))
95 * This macro will try to obtain a lock on the object, but will return with
96 * %FALSE if it can't get it immediately.
98 #define GST_OBJECT_TRYLOCK(obj) g_mutex_trylock(GST_OBJECT_GET_LOCK(obj))
101 * @obj: a #GstObject to unlock.
103 * This macro releases a lock on the object.
105 #define GST_OBJECT_UNLOCK(obj) g_mutex_unlock(GST_OBJECT_GET_LOCK(obj))
112 * Get the name of this object. This is not thread-safe by default
113 * (i.e. you will have to make sure the object lock is taken yourself).
114 * If in doubt use gst_object_get_name() instead.
116 #define GST_OBJECT_NAME(obj) (GST_OBJECT_CAST(obj)->name)
121 * Get the parent of this object. This is not thread-safe by default
122 * (i.e. you will have to make sure the object lock is taken yourself).
123 * If in doubt use gst_object_get_parent() instead.
125 #define GST_OBJECT_PARENT(obj) (GST_OBJECT_CAST(obj)->parent)
132 * This macro returns the entire set of flags for the object.
134 #define GST_OBJECT_FLAGS(obj) (GST_OBJECT_CAST (obj)->flags)
136 * GST_OBJECT_FLAG_IS_SET:
138 * @flag: Flag to check for
140 * This macro checks to see if the given flag is set.
142 #define GST_OBJECT_FLAG_IS_SET(obj,flag) ((GST_OBJECT_FLAGS (obj) & (flag)) == (flag))
144 * GST_OBJECT_FLAG_SET:
148 * This macro sets the given bits.
150 #define GST_OBJECT_FLAG_SET(obj,flag) (GST_OBJECT_FLAGS (obj) |= (flag))
152 * GST_OBJECT_FLAG_UNSET:
156 * This macro unsets the given bits.
158 #define GST_OBJECT_FLAG_UNSET(obj,flag) (GST_OBJECT_FLAGS (obj) &= ~(flag))
160 typedef struct _GstObject GstObject;
161 typedef struct _GstObjectClass GstObjectClass;
166 * @name: The name of the object
167 * @parent: this object's parent, weak ref
168 * @flags: flags for this object
170 * GStreamer base object class.
173 GInitiallyUnowned object;
175 /*< public >*/ /* with LOCK */
176 GMutex lock; /* object LOCK */
177 gchar *name; /* object name */
178 GstObject *parent; /* this object's parent, weak ref */
182 GList *control_bindings; /* List of GstControlBinding */
183 guint64 control_rate;
186 gpointer _gst_reserved;
191 * @parent_class: parent
192 * @path_string_separator: separator used by gst_object_get_path_string()
193 * @deep_notify: default signal handler
195 * GStreamer base object class.
197 struct _GstObjectClass {
198 GInitiallyUnownedClass parent_class;
200 const gchar *path_string_separator;
203 void (*deep_notify) (GstObject * object, GstObject * orig, GParamSpec * pspec);
206 /* virtual methods for subclasses */
209 gpointer _gst_reserved[GST_PADDING];
212 /* normal GObject stuff */
215 GType gst_object_get_type (void);
220 gboolean gst_object_set_name (GstObject *object, const gchar *name);
223 gchar* gst_object_get_name (GstObject *object);
225 /* parentage routines */
228 gboolean gst_object_set_parent (GstObject *object, GstObject *parent);
231 GstObject* gst_object_get_parent (GstObject *object);
234 void gst_object_unparent (GstObject *object);
237 gboolean gst_object_has_as_parent (GstObject *object, GstObject *parent);
240 gboolean gst_object_has_as_ancestor (GstObject *object, GstObject *ancestor);
242 GST_DEPRECATED_FOR(gst_object_has_as_ancestor)
243 gboolean gst_object_has_ancestor (GstObject *object, GstObject *ancestor);
246 void gst_object_default_deep_notify (GObject *object, GstObject *orig,
247 GParamSpec *pspec, gchar **excluded_props);
249 /* refcounting + life cycle */
252 gpointer gst_object_ref (gpointer object);
255 void gst_object_unref (gpointer object);
258 void gst_clear_object (GstObject **object_ptr);
259 #define gst_clear_object(object_ptr) g_clear_pointer ((object_ptr), gst_object_unref)
262 gpointer gst_object_ref_sink (gpointer object);
264 /* replace object pointer */
267 gboolean gst_object_replace (GstObject **oldobj, GstObject *newobj);
269 /* printing out the 'path' of the object */
272 gchar * gst_object_get_path_string (GstObject *object);
277 gboolean gst_object_check_uniqueness (GList *list, const gchar *name);
279 /* controller functions */
280 #include <gst/gstcontrolbinding.h>
281 #include <gst/gstcontrolsource.h>
284 GstClockTime gst_object_suggest_next_sync (GstObject * object);
287 gboolean gst_object_sync_values (GstObject * object, GstClockTime timestamp);
290 gboolean gst_object_has_active_control_bindings (GstObject *object);
293 void gst_object_set_control_bindings_disabled (GstObject *object, gboolean disabled);
296 void gst_object_set_control_binding_disabled (GstObject *object,
297 const gchar * property_name,
301 gboolean gst_object_add_control_binding (GstObject * object, GstControlBinding * binding);
305 gst_object_get_control_binding (GstObject *object, const gchar * property_name);
308 gboolean gst_object_remove_control_binding (GstObject * object, GstControlBinding * binding);
311 GValue * gst_object_get_value (GstObject * object, const gchar * property_name,
312 GstClockTime timestamp);
314 gboolean gst_object_get_value_array (GstObject * object, const gchar * property_name,
315 GstClockTime timestamp, GstClockTime interval,
316 guint n_values, gpointer values);
318 gboolean gst_object_get_g_value_array (GstObject * object, const gchar * property_name,
319 GstClockTime timestamp, GstClockTime interval,
320 guint n_values, GValue *values);
322 GstClockTime gst_object_get_control_rate (GstObject * object);
325 void gst_object_set_control_rate (GstObject * object, GstClockTime control_rate);
327 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstObject, gst_object_unref)
331 #endif /* __GST_OBJECT_H__ */