gstobject.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /* GStreamer
  2. * Copyright (C) 1999,2000 Erik Walthinsen <[email protected]>
  3. * 2000 Wim Taymans <[email protected]>
  4. * 2005 Wim Taymans <[email protected]>
  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
  98. */
  99. #define GST_OBJECT_NAME(obj) (GST_OBJECT_CAST(obj)->name)
  100. /**
  101. * GST_OBJECT_PARENT:
  102. * @obj: a #GstObject
  103. *
  104. * Get the parent of this object
  105. */
  106. #define GST_OBJECT_PARENT(obj) (GST_OBJECT_CAST(obj)->parent)
  107. /**
  108. * GST_OBJECT_FLAGS:
  109. * @obj: a #GstObject
  110. *
  111. * This macro returns the entire set of flags for the object.
  112. */
  113. #define GST_OBJECT_FLAGS(obj) (GST_OBJECT_CAST (obj)->flags)
  114. /**
  115. * GST_OBJECT_FLAG_IS_SET:
  116. * @obj: a #GstObject
  117. * @flag: Flag to check for
  118. *
  119. * This macro checks to see if the given flag is set.
  120. */
  121. #define GST_OBJECT_FLAG_IS_SET(obj,flag) ((GST_OBJECT_FLAGS (obj) & (flag)) == (flag))
  122. /**
  123. * GST_OBJECT_FLAG_SET:
  124. * @obj: a #GstObject
  125. * @flag: Flag to set
  126. *
  127. * This macro sets the given bits.
  128. */
  129. #define GST_OBJECT_FLAG_SET(obj,flag) (GST_OBJECT_FLAGS (obj) |= (flag))
  130. /**
  131. * GST_OBJECT_FLAG_UNSET:
  132. * @obj: a #GstObject
  133. * @flag: Flag to set
  134. *
  135. * This macro unsets the given bits.
  136. */
  137. #define GST_OBJECT_FLAG_UNSET(obj,flag) (GST_OBJECT_FLAGS (obj) &= ~(flag))
  138. typedef struct _GstObject GstObject;
  139. typedef struct _GstObjectClass GstObjectClass;
  140. /**
  141. * GstObject:
  142. * @lock: object LOCK
  143. * @name: The name of the object
  144. * @parent: this object's parent, weak ref
  145. * @flags: flags for this object
  146. *
  147. * GStreamer base object class.
  148. */
  149. struct _GstObject {
  150. GInitiallyUnowned object;
  151. /*< public >*/ /* with LOCK */
  152. GMutex lock; /* object LOCK */
  153. gchar *name; /* object name */
  154. GstObject *parent; /* this object's parent, weak ref */
  155. guint32 flags;
  156. /*< private >*/
  157. GList *control_bindings; /* List of GstControlBinding */
  158. guint64 control_rate;
  159. guint64 last_sync;
  160. gpointer _gst_reserved;
  161. };
  162. /**
  163. * GstObjectClass:
  164. * @parent_class: parent
  165. * @path_string_separator: separator used by gst_object_get_path_string()
  166. * @deep_notify: default signal handler
  167. *
  168. * GStreamer base object class.
  169. */
  170. struct _GstObjectClass {
  171. GInitiallyUnownedClass parent_class;
  172. const gchar *path_string_separator;
  173. /* signals */
  174. void (*deep_notify) (GstObject * object, GstObject * orig, GParamSpec * pspec);
  175. /*< public >*/
  176. /* virtual methods for subclasses */
  177. /*< private >*/
  178. gpointer _gst_reserved[GST_PADDING];
  179. };
  180. /* normal GObject stuff */
  181. GType gst_object_get_type (void);
  182. /* name routines */
  183. gboolean gst_object_set_name (GstObject *object, const gchar *name);
  184. gchar* gst_object_get_name (GstObject *object);
  185. /* parentage routines */
  186. gboolean gst_object_set_parent (GstObject *object, GstObject *parent);
  187. GstObject* gst_object_get_parent (GstObject *object);
  188. void gst_object_unparent (GstObject *object);
  189. gboolean gst_object_has_ancestor (GstObject *object, GstObject *ancestor);
  190. void gst_object_default_deep_notify (GObject *object, GstObject *orig,
  191. GParamSpec *pspec, gchar **excluded_props);
  192. /* refcounting + life cycle */
  193. gpointer gst_object_ref (gpointer object);
  194. void gst_object_unref (gpointer object);
  195. gpointer gst_object_ref_sink (gpointer object);
  196. /* replace object pointer */
  197. gboolean gst_object_replace (GstObject **oldobj, GstObject *newobj);
  198. /* printing out the 'path' of the object */
  199. gchar * gst_object_get_path_string (GstObject *object);
  200. /* misc utils */
  201. gboolean gst_object_check_uniqueness (GList *list, const gchar *name);
  202. /* controller functions */
  203. #include <gst/gstcontrolbinding.h>
  204. #include <gst/gstcontrolsource.h>
  205. GstClockTime gst_object_suggest_next_sync (GstObject * object);
  206. gboolean gst_object_sync_values (GstObject * object, GstClockTime timestamp);
  207. gboolean gst_object_has_active_control_bindings (GstObject *object);
  208. void gst_object_set_control_bindings_disabled (GstObject *object, gboolean disabled);
  209. void gst_object_set_control_binding_disabled (GstObject *object,
  210. const gchar * property_name,
  211. gboolean disabled);
  212. gboolean gst_object_add_control_binding (GstObject * object, GstControlBinding * binding);
  213. GstControlBinding *
  214. gst_object_get_control_binding (GstObject *object, const gchar * property_name);
  215. gboolean gst_object_remove_control_binding (GstObject * object, GstControlBinding * binding);
  216. GValue * gst_object_get_value (GstObject * object, const gchar * property_name,
  217. GstClockTime timestamp);
  218. gboolean gst_object_get_value_array (GstObject * object, const gchar * property_name,
  219. GstClockTime timestamp, GstClockTime interval,
  220. guint n_values, gpointer values);
  221. gboolean gst_object_get_g_value_array (GstObject * object, const gchar * property_name,
  222. GstClockTime timestamp, GstClockTime interval,
  223. guint n_values, GValue *values);
  224. GstClockTime gst_object_get_control_rate (GstObject * object);
  225. void gst_object_set_control_rate (GstObject * object, GstClockTime control_rate);
  226. G_END_DECLS
  227. #endif /* __GST_OBJECT_H__ */