element: Enforce that elements created by gst_element_factory_create/make() are floating
[platform/upstream/gstreamer.git] / gst / gstobject.c
index 5c5c90a..3aa20c4 100644 (file)
@@ -23,6 +23,7 @@
 
 /**
  * SECTION:gstobject
+ * @title: GstObject
  * @short_description: Base class for the GStreamer object hierarchy
  *
  * #GstObject provides a root for the object hierarchy tree filed in by the
@@ -42,9 +43,8 @@
  * gst_object_set_name() and gst_object_get_name() are used to set/get the name
  * of the object.
  *
- * <refsect2>
- * <title>controlled properties</title>
- * <para>
+ * ## controlled properties
+ *
  * Controlled properties offers a lightweight way to adjust gobject properties
  * over stream-time. It works by using time-stamped value pairs that are queued
  * for element-properties. At run-time the elements continuously pull value
  *
  * What needs to be changed in a #GstElement?
  * Very little - it is just two steps to make a plugin controllable!
- * <orderedlist>
- *   <listitem><para>
- *     mark gobject-properties paramspecs that make sense to be controlled,
+ *
+ *   * mark gobject-properties paramspecs that make sense to be controlled,
  *     by GST_PARAM_CONTROLLABLE.
- *   </para></listitem>
- *   <listitem><para>
- *     when processing data (get, chain, loop function) at the beginning call
+ *
+ *   * when processing data (get, chain, loop function) at the beginning call
  *     gst_object_sync_values(element,timestamp).
  *     This will make the controller update all GObject properties that are
  *     under its control with the current values based on the timestamp.
- *   </para></listitem>
- * </orderedlist>
- *
- * What needs to be done in applications?
- * Again it's not a lot to change.
- * <orderedlist>
- *   <listitem><para>
- *     create a #GstControlSource.
+ *
+ * What needs to be done in applications? Again it's not a lot to change.
+ *
+ *   * create a #GstControlSource.
  *     csource = gst_interpolation_control_source_new ();
  *     g_object_set (csource, "mode", GST_INTERPOLATION_MODE_LINEAR, NULL);
- *   </para></listitem>
- *   <listitem><para>
- *     Attach the #GstControlSource on the controller to a property.
+ *
+ *   * Attach the #GstControlSource on the controller to a property.
  *     gst_object_add_control_binding (object, gst_direct_control_binding_new (object, "prop1", csource));
- *   </para></listitem>
- *   <listitem><para>
- *     Set the control values
+ *
+ *   * Set the control values
  *     gst_timed_value_control_source_set ((GstTimedValueControlSource *)csource,0 * GST_SECOND, value1);
  *     gst_timed_value_control_source_set ((GstTimedValueControlSource *)csource,1 * GST_SECOND, value2);
- *   </para></listitem>
- *   <listitem><para>
- *     start your pipeline
- *   </para></listitem>
- * </orderedlist>
- * </para>
- * </refsect2>
+ *
+ *   * start your pipeline
  */
 
 #include "gst_private.h"
@@ -244,6 +231,7 @@ gst_object_ref (gpointer object)
 {
   g_return_val_if_fail (object != NULL, NULL);
 
+  GST_TRACER_OBJECT_REFFED (object, ((GObject *) object)->ref_count + 1);
 #ifdef DEBUG_REFCOUNT
   GST_CAT_TRACE_OBJECT (GST_CAT_REFCOUNTING, object, "%p ref %d->%d", object,
       ((GObject *) object)->ref_count, ((GObject *) object)->ref_count + 1);
@@ -270,6 +258,7 @@ gst_object_unref (gpointer object)
   g_return_if_fail (object != NULL);
   g_return_if_fail (((GObject *) object)->ref_count > 0);
 
+  GST_TRACER_OBJECT_UNREFFED (object, ((GObject *) object)->ref_count - 1);
 #ifdef DEBUG_REFCOUNT
   GST_CAT_TRACE_OBJECT (GST_CAT_REFCOUNTING, object, "%p unref %d->%d", object,
       ((GObject *) object)->ref_count, ((GObject *) object)->ref_count - 1);
@@ -289,6 +278,9 @@ gst_object_unref (gpointer object)
  * the floating flag while leaving the reference count unchanged. If the object
  * is not floating, then this call adds a new normal reference increasing the
  * reference count by one.
+ *
+ * For more background on "floating references" please see the #GObject
+ * documentation.
  */
 gpointer
 gst_object_ref_sink (gpointer object)
@@ -304,6 +296,30 @@ gst_object_ref_sink (gpointer object)
 }
 
 /**
+ * gst_clear_object: (skip)
+ * @object_ptr: a pointer to a #GstObject reference
+ *
+ * Clears a reference to a #GstObject.
+ *
+ * @object_ptr must not be %NULL.
+ *
+ * If the reference is %NULL then this function does nothing.
+ * Otherwise, the reference count of the object is decreased using
+ * gst_object_unref() and the pointer is set to %NULL.
+ *
+ * A macro is also included that allows this function to be used without
+ * pointer casts.
+ *
+ * Since: 1.16
+ **/
+#undef gst_clear_object
+void
+gst_clear_object (GstObject ** object_ptr)
+{
+  g_clear_pointer (object_ptr, gst_object_unref);
+}
+
+/**
  * gst_object_replace:
  * @oldobj: (inout) (transfer full) (nullable): pointer to a place of
  *     a #GstObject to replace
@@ -661,7 +677,7 @@ gst_object_get_name (GstObject * object)
 
 /**
  * gst_object_set_parent:
- * @object: a #GstObject
+ * @object: (transfer floating): a #GstObject
  * @parent: new parent of object
  *
  * Sets the parent of @object to @parent. The object's reference count will
@@ -704,6 +720,8 @@ had_parent:
   {
     GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, object,
         "set parent failed, object already had a parent");
+    gst_object_ref_sink (object);
+    gst_object_unref (object);
     GST_OBJECT_UNLOCK (object);
     return FALSE;
   }
@@ -846,11 +864,7 @@ gst_object_has_as_ancestor (GstObject * object, GstObject * ancestor)
  *
  * MT safe. Grabs and releases @object's locks.
  */
-/* FIXME 2.0: remove */
 #ifndef GST_REMOVE_DEPRECATED
-#ifdef GST_DISABLE_DEPRECATED
-gboolean gst_object_has_ancestor (GstObject * object, GstObject * ancestor);
-#endif
 gboolean
 gst_object_has_ancestor (GstObject * object, GstObject * ancestor)
 {
@@ -1215,12 +1229,13 @@ gst_object_set_control_binding_disabled (GstObject * object,
 /**
  * gst_object_add_control_binding:
  * @object: the controller object
- * @binding: (transfer full): the #GstControlBinding that should be used
+ * @binding: (transfer floating): the #GstControlBinding that should be used
  *
  * Attach the #GstControlBinding to the object. If there already was a
  * #GstControlBinding for this property it will be replaced.
  *
- * The @object will take ownership of the @binding.
+ * The object's reference count will be incremented, and any floating
+ * reference will be removed (see gst_object_ref_sink())
  *
  * Returns: %FALSE if the given @binding has not been setup for this object or
  * has been setup for a non suitable property, %TRUE otherwise.
@@ -1282,7 +1297,7 @@ gst_object_get_control_binding (GstObject * object, const gchar * property_name)
  * @binding: the binding
  *
  * Removes the corresponding #GstControlBinding. If it was the
- * last ref of the binding, it will be disposed.  
+ * last ref of the binding, it will be disposed.
  *
  * Returns: %TRUE if the binding could be removed.
  */
@@ -1341,7 +1356,7 @@ gst_object_get_value (GstObject * object, const gchar * property_name,
 }
 
 /**
- * gst_object_get_value_array:
+ * gst_object_get_value_array: (skip)
  * @object: the object that has controlled properties
  * @property_name: the name of the property to get
  * @timestamp: the time that should be processed
@@ -1356,7 +1371,7 @@ gst_object_get_value (GstObject * object, const gchar * property_name,
  * This function is useful if one wants to e.g. draw a graph of the control
  * curve or apply a control curve sample by sample.
  *
- * The values are unboxed and ready to be used. The similar function 
+ * The values are unboxed and ready to be used. The similar function
  * gst_object_get_g_value_array() returns the array as #GValues and is
  * better suites for bindings.
  *
@@ -1392,7 +1407,7 @@ gst_object_get_value_array (GstObject * object, const gchar * property_name,
  * @timestamp: the time that should be processed
  * @interval: the time spacing between subsequent values
  * @n_values: the number of values
- * @values: array to put control-values in
+ * @values: (array length=n_values): array to put control-values in
  *
  * Gets a number of #GValues for the given controlled property starting at the
  * requested time. The array @values need to hold enough space for @n_values of
@@ -1433,7 +1448,7 @@ gst_object_get_g_value_array (GstObject * object, const gchar * property_name,
  *
  * Obtain the control-rate for this @object. Audio processing #GstElement
  * objects will use this rate to sub-divide their processing loop and call
- * gst_object_sync_values() inbetween. The length of the processing segment
+ * gst_object_sync_values() in between. The length of the processing segment
  * should be up to @control-rate nanoseconds.
  *
  * If the @object is not under property control, this will return
@@ -1459,7 +1474,7 @@ gst_object_get_control_rate (GstObject * object)
  *
  * Change the control-rate for this @object. Audio processing #GstElement
  * objects will use this rate to sub-divide their processing loop and call
- * gst_object_sync_values() inbetween. The length of the processing segment
+ * gst_object_sync_values() in between. The length of the processing segment
  * should be up to @control-rate nanoseconds.
  *
  * The control-rate should not change if the element is in %GST_STATE_PAUSED or