element: Enforce that elements created by gst_element_factory_create/make() are floating
[platform/upstream/gstreamer.git] / gst / gststreamcollection.c
index f466851..ec12e4a 100644 (file)
 
 /**
  * SECTION:gststreamcollection
+ * @title: GstStreamCollection
  * @short_description: Base class for collection of streams
  *
+ * Since: 1.10
  */
 
 #include "gst_private.h"
 GST_DEBUG_CATEGORY_STATIC (stream_collection_debug);
 #define GST_CAT_DEFAULT stream_collection_debug
 
-#define GST_STREAM_COLLECTION_GET_PRIVATE(obj)  \
-   (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_STREAM_COLLECTION, GstStreamCollectionPrivate))
-
 struct _GstStreamCollectionPrivate
 {
   /* Maybe switch this to a GArray if performance is
    * ever an issue? */
-  GQueue *streams;
+  GQueue streams;
 };
 
 /* stream signals and properties */
@@ -85,7 +84,7 @@ proxy_stream_notify_cb (GstStream * stream, GParamSpec * pspec,
 
 #define gst_stream_collection_parent_class parent_class
 G_DEFINE_TYPE_WITH_CODE (GstStreamCollection, gst_stream_collection,
-    GST_TYPE_OBJECT, _do_init);
+    GST_TYPE_OBJECT, G_ADD_PRIVATE (GstStreamCollection) _do_init);
 
 static void
 gst_stream_collection_class_init (GstStreamCollectionClass * klass)
@@ -94,8 +93,6 @@ gst_stream_collection_class_init (GstStreamCollectionClass * klass)
 
   gobject_class = (GObjectClass *) klass;
 
-  g_type_class_add_private (klass, sizeof (GstStreamCollectionPrivate));
-
   gobject_class->set_property = gst_stream_collection_set_property;
   gobject_class->get_property = gst_stream_collection_get_property;
 
@@ -132,8 +129,8 @@ gst_stream_collection_class_init (GstStreamCollectionClass * klass)
 static void
 gst_stream_collection_init (GstStreamCollection * collection)
 {
-  collection->priv = GST_STREAM_COLLECTION_GET_PRIVATE (collection);
-  collection->priv->streams = g_queue_new ();
+  collection->priv = gst_stream_collection_get_instance_private (collection);
+  g_queue_init (&collection->priv->streams);
 }
 
 static void
@@ -154,12 +151,9 @@ gst_stream_collection_dispose (GObject * object)
     collection->upstream_id = NULL;
   }
 
-  if (collection->priv->streams) {
-    g_queue_foreach (collection->priv->streams,
-        (GFunc) release_gst_stream, collection);
-    g_queue_free (collection->priv->streams);
-    collection->priv->streams = NULL;
-  }
+  g_queue_foreach (&collection->priv->streams,
+      (GFunc) release_gst_stream, collection);
+  g_queue_clear (&collection->priv->streams);
 
   G_OBJECT_CLASS (parent_class)->dispose (object);
 }
@@ -170,13 +164,23 @@ gst_stream_collection_dispose (GObject * object)
  *
  * Create a new #GstStreamCollection.
  *
- * Returns: The new #GstStreamCollection.
+ * Returns: (transfer full): The new #GstStreamCollection.
+ *
+ * Since: 1.10
  */
 GstStreamCollection *
 gst_stream_collection_new (const gchar * upstream_id)
 {
-  return g_object_new (GST_TYPE_STREAM_COLLECTION, "upstream-id", upstream_id,
+  GstStreamCollection *collection;
+
+  collection =
+      g_object_new (GST_TYPE_STREAM_COLLECTION, "upstream-id", upstream_id,
       NULL);
+
+  /* Clear floating flag */
+  g_object_ref_sink (collection);
+
+  return collection;
 }
 
 static void
@@ -201,6 +205,8 @@ gst_stream_collection_set_upstream_id (GstStreamCollection * collection,
  * Returns the upstream id of the @collection.
  *
  * Returns: (transfer none): The upstream id
+ *
+ * Since: 1.10
  */
 const gchar *
 gst_stream_collection_get_upstream_id (GstStreamCollection * collection)
@@ -268,6 +274,8 @@ proxy_stream_notify_cb (GstStream * stream, GParamSpec * pspec,
  * Add the given @stream to the @collection.
  *
  * Returns: %TRUE if the @stream was properly added, else %FALSE
+ *
+ * Since: 1.10
  */
 gboolean
 gst_stream_collection_add_stream (GstStreamCollection * collection,
@@ -275,11 +283,10 @@ gst_stream_collection_add_stream (GstStreamCollection * collection,
 {
   g_return_val_if_fail (GST_IS_STREAM_COLLECTION (collection), FALSE);
   g_return_val_if_fail (GST_IS_STREAM (stream), FALSE);
-  g_return_val_if_fail (collection->priv->streams, FALSE);
 
   GST_DEBUG_OBJECT (collection, "Adding stream %" GST_PTR_FORMAT, stream);
 
-  g_queue_push_tail (collection->priv->streams, stream);
+  g_queue_push_tail (&collection->priv->streams, stream);
   g_signal_connect (stream, "notify", (GCallback) proxy_stream_notify_cb,
       collection);
 
@@ -293,14 +300,15 @@ gst_stream_collection_add_stream (GstStreamCollection * collection,
  * Get the number of streams this collection contains
  *
  * Returns: The number of streams that @collection contains
+ *
+ * Since: 1.10
  */
 guint
 gst_stream_collection_get_size (GstStreamCollection * collection)
 {
   g_return_val_if_fail (GST_IS_STREAM_COLLECTION (collection), 0);
-  g_return_val_if_fail (collection->priv->streams, 0);
 
-  return g_queue_get_length (collection->priv->streams);
+  return g_queue_get_length (&collection->priv->streams);
 }
 
 /**
@@ -312,13 +320,14 @@ gst_stream_collection_get_size (GstStreamCollection * collection)
  *
  * The caller should not modify the returned #GstStream
  *
- * Returns: (transfer none): A #GstStream
+ * Returns: (transfer none) (nullable): A #GstStream
+ *
+ * Since: 1.10
  */
 GstStream *
 gst_stream_collection_get_stream (GstStreamCollection * collection, guint index)
 {
   g_return_val_if_fail (GST_IS_STREAM_COLLECTION (collection), NULL);
-  g_return_val_if_fail (collection->priv->streams, NULL);
 
-  return g_queue_peek_nth (collection->priv->streams, index);
+  return g_queue_peek_nth (&collection->priv->streams, index);
 }