gstobject.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /* GStreamer
  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>
  5. *
  6. * gstobject.h: Header for base GstObject
  7. *
  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.
  12. *
  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.
  17. *
  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.
  22. */
  23. #ifndef __GST_OBJECT_H__
  24. #define __GST_OBJECT_H__
  25. #include <gst/gstconfig.h>
  26. #include <glib-object.h>
  27. G_BEGIN_DECLS
  28. #define GST_TYPE_OBJECT (gst_object_get_type ())
  29. #define GST_IS_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_OBJECT))
  30. #define GST_IS_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_OBJECT))
  31. #define GST_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_OBJECT, GstObjectClass))
  32. #define GST_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_OBJECT, GstObject))
  33. #define GST_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_OBJECT, GstObjectClass))
  34. #define GST_OBJECT_CAST(obj) ((GstObject*)(obj))
  35. #define GST_OBJECT_CLASS_CAST(klass) ((GstObjectClass*)(klass))
  36. /**
  37. * GstObjectFlags:
  38. * @GST_OBJECT_FLAG_LAST: subclasses can add additional flags starting from this flag
  39. *
  40. * The standard flags that an gstobject may have.
  41. */
  42. typedef enum
  43. {
  44. /* padding */
  45. GST_OBJECT_FLAG_LAST = (1<<4)
  46. } GstObjectFlags;
  47. /**
  48. * GST_OBJECT_REFCOUNT:
  49. * @obj: a #GstObject
  50. *
  51. * Get access to the reference count field of the object.
  52. */
  53. #define GST_OBJECT_REFCOUNT(obj) (((GObject*)(obj))->ref_count)
  54. /**
  55. * GST_OBJECT_REFCOUNT_VALUE:
  56. * @obj: a #GstObject
  57. *
  58. * Get the reference count value of the object.
  59. */
  60. #define GST_OBJECT_REFCOUNT_VALUE(obj) g_atomic_int_get ((gint *) &GST_OBJECT_REFCOUNT(obj))
  61. /* we do a GST_OBJECT_CAST to avoid type checking, better call these
  62. * function with a valid object! */
  63. /**
  64. * GST_OBJECT_GET_LOCK:
  65. * @obj: a #GstObject
  66. *
  67. * Acquire a reference to the mutex of this object.
  68. */
  69. #define GST_OBJECT_GET_LOCK(obj) (&GST_OBJECT_CAST(obj)->lock)
  70. /**
  71. * GST_OBJECT_LOCK:
  72. * @obj: a #GstObject to lock
  73. *
  74. * This macro will obtain a lock on the object, making serialization possible.
  75. * It blocks until the lock can be obtained.
  76. */
  77. #define GST_OBJECT_LOCK(obj) g_mutex_lock(GST_OBJECT_GET_LOCK(obj))
  78. /**
  79. * GST_OBJECT_TRYLOCK:
  80. * @obj: a #GstObject.
  81. *
  82. * This macro will try to obtain a lock on the object, but will return with
  83. * %FALSE if it can't get it immediately.
  84. */
  85. #define GST_OBJECT_TRYLOCK(obj) g_mutex_trylock(GST_OBJECT_GET_LOCK(obj))
  86. /**
  87. * GST_OBJECT_UNLOCK:
  88. * @obj: a #GstObject to unlock.
  89. *
  90. * This macro releases a lock on the object.
  91. */
  92. #define GST_OBJECT_UNLOCK(obj) g_mutex_unlock(GST_OBJECT_GET_LOCK(obj))
  93. /**
  94. * GST_OBJECT_NAME:
  95. * @obj: a #GstObject
  96. *
  97. * Get the name of this object. This is not thread-safe by default
  98. * (i.e. you will have to make sure the object lock is taken yourself).
  99. * If in doubt use gst_object_get_name() instead.
  100. */
  101. #define GST_OBJECT_NAME(obj) (GST_OBJECT_CAST(obj)->name)
  102. /**
  103. * GST_OBJECT_PARENT:
  104. * @obj: a #GstObject
  105. *
  106. * Get the parent of this object. This is not thread-safe by default
  107. * (i.e. you will have to make sure the object lock is taken yourself).
  108. * If in doubt use gst_object_get_parent() instead.
  109. */
  110. #define GST_OBJECT_PARENT(obj) (GST_OBJECT_CAST(obj)->parent)
  111. /**
  112. * GST_OBJECT_FLAGS:
  113. * @obj: a #GstObject
  114. *
  115. * This macro returns the entire set of flags for the object.
  116. */
  117. #define GST_OBJECT_FLAGS(obj) (GST_OBJECT_CAST (obj)->flags)
  118. /**
  119. * GST_OBJECT_FLAG_IS_SET:
  120. * @obj: a #GstObject
  121. * @flag: Flag to check for
  122. *
  123. * This macro checks to see if the given flag is set.
  124. */
  125. #define GST_OBJECT_FLAG_IS_SET(obj,flag) ((GST_OBJECT_FLAGS (obj) & (flag)) == (flag))
  126. /**
  127. * GST_OBJECT_FLAG_SET:
  128. * @obj: a #GstObject
  129. * @flag: Flag to set
  130. *
  131. * This macro sets the given bits.
  132. */
  133. #define GST_OBJECT_FLAG_SET(obj,flag) (GST_OBJECT_FLAGS (obj) |= (flag))
  134. /**
  135. * GST_OBJECT_FLAG_UNSET:
  136. * @obj: a #GstObject
  137. * @flag: Flag to set
  138. *
  139. * This macro unsets the given bits.
  140. */
  141. #define GST_OBJECT_FLAG_UNSET(obj,flag) (GST_OBJECT_FLAGS (obj) &= ~(flag))
  142. typedef struct _GstObject GstObject;
  143. typedef struct _GstObjectClass GstObjectClass;
  144. /**
  145. * GstObject:
  146. * @lock: object LOCK
  147. * @name: The name of the object
  148. * @parent: this object's parent, weak ref
  149. * @flags: flags for this object
  150. *
  151. * GStreamer base object class.
  152. */
  153. struct _GstObject {
  154. GInitiallyUnowned object;
  155. /*< public >*/ /* with LOCK */
  156. GMutex lock; /* object LOCK */
  157. gchar *name; /* object name */
  158. GstObject *parent; /* this object's parent, weak ref */
  159. guint32 flags;
  160. /*< private >*/
  161. GList *control_bindings; /* List of GstControlBinding */
  162. guint64 control_rate;
  163. guint64 last_sync;
  164. gpointer _gst_reserved;
  165. };
  166. /**
  167. * GstObjectClass:
  168. * @parent_class: parent
  169. * @path_string_separator: separator used by gst_object_get_path_string()
  170. * @deep_notify: default signal handler
  171. *
  172. * GStreamer base object class.
  173. */
  174. struct _GstObjectClass {
  175. GInitiallyUnownedClass parent_class;
  176. const gchar *path_string_separator;
  177. /* signals */
  178. void (*deep_notify) (GstObject * object, GstObject * orig, GParamSpec * pspec);
  179. /*< public >*/
  180. /* virtual methods for subclasses */
  181. /*< private >*/
  182. gpointer _gst_reserved[GST_PADDING];
  183. };
  184. /* normal GObject stuff */
  185. GType gst_object_get_type (void);
  186. /* name routines */
  187. gboolean gst_object_set_name (GstObject *object, const gchar *name);
  188. gchar* gst_object_get_name (GstObject *object);
  189. /* parentage routines */
  190. gboolean gst_object_set_parent (GstObject *object, GstObject *parent);
  191. GstObject* gst_object_get_parent (GstObject *object);
  192. void gst_object_unparent (GstObject *object);
  193. gboolean gst_object_has_as_parent (GstObject *object, GstObject *parent);
  194. gboolean gst_object_has_as_ancestor (GstObject *object, GstObject *ancestor);
  195. #ifndef GST_DISABLE_DEPRECATED
  196. gboolean gst_object_has_ancestor (GstObject *object, GstObject *ancestor);
  197. #endif
  198. void gst_object_default_deep_notify (GObject *object, GstObject *orig,
  199. GParamSpec *pspec, gchar **excluded_props);
  200. /* refcounting + life cycle */
  201. gpointer gst_object_ref (gpointer object);
  202. void gst_object_unref (gpointer object);
  203. gpointer gst_object_ref_sink (gpointer object);
  204. /* replace object pointer */
  205. gboolean gst_object_replace (GstObject **oldobj, GstObject *newobj);
  206. /* printing out the 'path' of the object */
  207. gchar * gst_object_get_path_string (GstObject *object);
  208. /* misc utils */
  209. gboolean gst_object_check_uniqueness (GList *list, const gchar *name);
  210. /* controller functions */
  211. #include <gst/gstcontrolbinding.h>
  212. #include <gst/gstcontrolsource.h>
  213. GstClockTime gst_object_suggest_next_sync (GstObject * object);
  214. gboolean gst_object_sync_values (GstObject * object, GstClockTime timestamp);
  215. gboolean gst_object_has_active_control_bindings (GstObject *object);
  216. void gst_object_set_control_bindings_disabled (GstObject *object, gboolean disabled);
  217. void gst_object_set_control_binding_disabled (GstObject *object,
  218. const gchar * property_name,
  219. gboolean disabled);
  220. gboolean gst_object_add_control_binding (GstObject * object, GstControlBinding * binding);
  221. GstControlBinding *
  222. gst_object_get_control_binding (GstObject *object, const gchar * property_name);
  223. gboolean gst_object_remove_control_binding (GstObject * object, GstControlBinding * binding);
  224. GValue * gst_object_get_value (GstObject * object, const gchar * property_name,
  225. GstClockTime timestamp);
  226. gboolean gst_object_get_value_array (GstObject * object, const gchar * property_name,
  227. GstClockTime timestamp, GstClockTime interval,
  228. guint n_values, gpointer values);
  229. gboolean gst_object_get_g_value_array (GstObject * object, const gchar * property_name,
  230. GstClockTime timestamp, GstClockTime interval,
  231. guint n_values, GValue *values);
  232. GstClockTime gst_object_get_control_rate (GstObject * object);
  233. void gst_object_set_control_rate (GstObject * object, GstClockTime control_rate);
  234. #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
  235. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstObject, gst_object_unref)
  236. #endif
  237. G_END_DECLS
  238. #endif /* __GST_OBJECT_H__ */