gstpad: Probes that return HANDLED can reset the data info field
[platform/upstream/gstreamer.git] / gst / gststreams.c
index b3f4864..503ce22 100644 (file)
@@ -26,6 +26,7 @@
 
 /**
  * SECTION:gststreams
+ * @title: GstStreams
  * @short_description: Base class for stream objects
  *
  * A #GstStream is a high-level object defining a stream of data which is, or
@@ -41,6 +42,8 @@
  * Elements that do not modify the nature of the stream can add extra information
  * on it (such as enrich the #GstCaps, or #GstTagList). This is typically done
  * by parsing elements.
+ *
+ * Since: 1.10
  */
 
 #include "gst_private.h"
@@ -52,9 +55,6 @@
 GST_DEBUG_CATEGORY_STATIC (streams_debug);
 #define GST_CAT_DEFAULT streams_debug
 
-#define GST_STREAM_GET_PRIVATE(obj)  \
-   (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_STREAM, GstStreamPrivate))
-
 struct _GstStreamPrivate
 {
   GstStreamFlags flags;
@@ -101,7 +101,8 @@ static void gst_stream_get_property (GObject * object, guint prop_id,
 }
 
 #define gst_stream_parent_class parent_class
-G_DEFINE_TYPE_WITH_CODE (GstStream, gst_stream, GST_TYPE_OBJECT, _do_init);
+G_DEFINE_TYPE_WITH_CODE (GstStream, gst_stream, GST_TYPE_OBJECT,
+    G_ADD_PRIVATE (GstStream) _do_init);
 
 static void
 gst_stream_class_init (GstStreamClass * klass)
@@ -110,8 +111,6 @@ gst_stream_class_init (GstStreamClass * klass)
 
   gobject_class = (GObjectClass *) klass;
 
-  g_type_class_add_private (klass, sizeof (GstStreamPrivate));
-
   gobject_class->set_property = gst_stream_set_property;
   gobject_class->get_property = gst_stream_get_property;
 
@@ -179,7 +178,7 @@ gst_stream_class_init (GstStreamClass * klass)
 static void
 gst_stream_init (GstStream * stream)
 {
-  stream->priv = GST_STREAM_GET_PRIVATE (stream);
+  stream->priv = gst_stream_get_instance_private (stream);
   stream->priv->type = GST_STREAM_TYPE_UNKNOWN;
 }
 
@@ -207,25 +206,36 @@ gst_stream_finalize (GObject * object)
  * Create a new #GstStream for the given @stream_id, @caps, @type
  * and @flags
  *
- * Returns: The new #GstStream
+ * Returns: (transfer full): The new #GstStream
+ *
+ * Since: 1.10
  */
 GstStream *
 gst_stream_new (const gchar * stream_id, GstCaps * caps, GstStreamType type,
     GstStreamFlags flags)
 {
-  return g_object_new (GST_TYPE_STREAM, "stream-id", stream_id, "caps", caps,
+  GstStream *stream;
+
+  stream = g_object_new (GST_TYPE_STREAM, "stream-id", stream_id, "caps", caps,
       "stream-type", type, "stream-flags", flags, NULL);
+
+  /* Clear floating flag */
+  gst_object_ref_sink (stream);
+
+  return stream;
 }
 
 static void
 gst_stream_set_stream_id (GstStream * stream, const gchar * stream_id)
 {
+  g_return_if_fail (GST_IS_STREAM (stream));
+
   GST_OBJECT_LOCK (stream);
   g_assert (stream->stream_id == NULL);
   if (stream_id)
     stream->stream_id = g_strdup (stream_id);
   else {
-    /* Create a randoom stream_id if NULL */
+    /* Create a random stream_id if NULL */
     GST_FIXME_OBJECT (stream, "Creating random stream-id, consider "
         "implementing a deterministic way of creating a stream-id");
     stream->stream_id =
@@ -244,10 +254,14 @@ gst_stream_set_stream_id (GstStream * stream, const gchar * stream_id)
  *
  * Returns: (transfer none) (nullable): the stream ID of @stream. Only valid
  * during the lifetime of @stream.
+ *
+ * Since: 1.10
  */
 const gchar *
 gst_stream_get_stream_id (GstStream * stream)
 {
+  g_return_val_if_fail (GST_IS_STREAM (stream), NULL);
+
   return stream->stream_id;
 }
 
@@ -257,10 +271,14 @@ gst_stream_get_stream_id (GstStream * stream)
  * @flags: the flags to set on @stream
  *
  * Set the @flags for the @stream.
+ *
+ * Since: 1.10
  */
 void
 gst_stream_set_stream_flags (GstStream * stream, GstStreamFlags flags)
 {
+  g_return_if_fail (GST_IS_STREAM (stream));
+
   GST_OBJECT_LOCK (stream);
   stream->priv->flags = flags;
   GST_OBJECT_UNLOCK (stream);
@@ -277,12 +295,15 @@ gst_stream_set_stream_flags (GstStream * stream, GstStreamFlags flags)
  *
  * Returns: The #GstStreamFlags for @stream
  *
+ * Since: 1.10
  */
 GstStreamFlags
 gst_stream_get_stream_flags (GstStream * stream)
 {
   GstStreamFlags res;
 
+  g_return_val_if_fail (GST_IS_STREAM (stream), GST_STREAM_FLAG_NONE);
+
   GST_OBJECT_LOCK (stream);
   res = stream->priv->flags;
   GST_OBJECT_UNLOCK (stream);
@@ -296,10 +317,14 @@ gst_stream_get_stream_flags (GstStream * stream)
  * @stream_type: the type to set on @stream
  *
  * Set the stream type of @stream
+ *
+ * Since: 1.10
  */
 void
 gst_stream_set_stream_type (GstStream * stream, GstStreamType stream_type)
 {
+  g_return_if_fail (GST_IS_STREAM (stream));
+
   GST_OBJECT_LOCK (stream);
   stream->priv->type = stream_type;
   GST_OBJECT_UNLOCK (stream);
@@ -316,12 +341,15 @@ gst_stream_set_stream_type (GstStream * stream, GstStreamType stream_type)
  *
  * Returns: The #GstStreamType for @stream
  *
+ * Since: 1.10
  */
 GstStreamType
 gst_stream_get_stream_type (GstStream * stream)
 {
   GstStreamType res;
 
+  g_return_val_if_fail (GST_IS_STREAM (stream), GST_STREAM_TYPE_UNKNOWN);
+
   GST_OBJECT_LOCK (stream);
   res = stream->priv->type;
   GST_OBJECT_UNLOCK (stream);
@@ -336,15 +364,26 @@ gst_stream_get_stream_type (GstStream * stream)
  *
  * Set the tags for the #GstStream
  *
+ * Since: 1.10
  */
 void
 gst_stream_set_tags (GstStream * stream, GstTagList * tags)
 {
+  gboolean notify = FALSE;
+
+  g_return_if_fail (GST_IS_STREAM (stream));
+
   GST_OBJECT_LOCK (stream);
-  gst_mini_object_replace ((GstMiniObject **) & stream->priv->tags,
-      (GstMiniObject *) tags);
+  if (stream->priv->tags == NULL || tags == NULL
+      || !gst_tag_list_is_equal (stream->priv->tags, tags)) {
+    gst_mini_object_replace ((GstMiniObject **) & stream->priv->tags,
+        (GstMiniObject *) tags);
+    notify = TRUE;
+  }
   GST_OBJECT_UNLOCK (stream);
-  g_object_notify_by_pspec (G_OBJECT (stream), gst_stream_pspecs[PROP_TAGS]);
+
+  if (notify)
+    g_object_notify_by_pspec (G_OBJECT (stream), gst_stream_pspecs[PROP_TAGS]);
 }
 
 /**
@@ -355,12 +394,15 @@ gst_stream_set_tags (GstStream * stream, GstTagList * tags)
  *
  * Returns: (transfer full) (nullable): The #GstTagList for @stream
  *
+ * Since: 1.10
  */
 GstTagList *
 gst_stream_get_tags (GstStream * stream)
 {
   GstTagList *res = NULL;
 
+  g_return_val_if_fail (GST_IS_STREAM (stream), NULL);
+
   GST_OBJECT_LOCK (stream);
   if (stream->priv->tags)
     res = gst_tag_list_ref (stream->priv->tags);
@@ -376,12 +418,15 @@ gst_stream_get_tags (GstStream * stream)
  *
  * Set the caps for the #GstStream
  *
+ * Since: 1.10
  */
 void
 gst_stream_set_caps (GstStream * stream, GstCaps * caps)
 {
   gboolean notify = FALSE;
 
+  g_return_if_fail (GST_IS_STREAM (stream));
+
   GST_OBJECT_LOCK (stream);
   if (stream->priv->caps == NULL || (caps
           && !gst_caps_is_equal (stream->priv->caps, caps))) {
@@ -403,12 +448,15 @@ gst_stream_set_caps (GstStream * stream, GstCaps * caps)
  *
  * Returns: (transfer full) (nullable): The #GstCaps for @stream
  *
+ * Since: 1.10
  */
 GstCaps *
 gst_stream_get_caps (GstStream * stream)
 {
   GstCaps *res = NULL;
 
+  g_return_val_if_fail (GST_IS_STREAM (stream), NULL);
+
   GST_OBJECT_LOCK (stream);
   if (stream->priv->caps)
     res = gst_caps_ref (stream->priv->caps);
@@ -493,7 +541,9 @@ gst_stream_get_property (GObject * object, guint prop_id,
  *
  * Get a descriptive string for a given #GstStreamType
  *
- * Returns: A string describing the stream type
+ * Returns: (nullable): A string describing the stream type
+ *
+ * Since: 1.10
  */
 const gchar *
 gst_stream_type_get_name (GstStreamType stype)