summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Hervey <edward@centricular.com>2017-12-05 17:28:55 +0100
committerEdward Hervey <bilboed@bilboed.com>2017-12-05 18:19:32 +0100
commite5c15f6b9605a1e682a60ea1bfadae831e651a41 (patch)
tree5004ecda8f202da1cbf1f16a0fcdca52eb88e90d
parent16d9954dd5a294f0a1e320b37e2582413cc516a8 (diff)
utils: Never return a group_id of 0, add GST_GROUP_ID_INVALID
Various plugins use special values (0 or G_MAXUINT32) as an invalid/unset group_id, but nothing guarantees a groupid won't have that value. Instead define a value which group_id will never have and make gst_group_id_next() always return a value different from that. API: GST_GROUP_ID_INVALID
-rw-r--r--docs/gst/gstreamer-sections.txt1
-rw-r--r--gst/gstutils.c12
-rw-r--r--gst/gstutils.h12
3 files changed, 23 insertions, 2 deletions
diff --git a/docs/gst/gstreamer-sections.txt b/docs/gst/gstreamer-sections.txt
index 6385ca67e..52443e18f 100644
--- a/docs/gst/gstreamer-sections.txt
+++ b/docs/gst/gstreamer-sections.txt
@@ -3571,6 +3571,7 @@ GFLOAT_FROM_LE
GFLOAT_SWAP_LE_BE
GFLOAT_TO_BE
GFLOAT_TO_LE
+GST_GROUP_ID_INVALID
gst_guint64_to_gdouble
gst_gdouble_to_guint64
diff --git a/gst/gstutils.c b/gst/gstutils.c
index 143bed758..be45dec0f 100644
--- a/gst/gstutils.c
+++ b/gst/gstutils.c
@@ -4177,14 +4177,22 @@ gst_pad_get_stream (GstPad * pad)
* This function is used to generate a new group-id for the
* stream-start event.
*
+ * This function never returns %GST_GROUP_ID_INVALID (which is 0)
+ *
* Returns: A constantly incrementing unsigned integer, which might
* overflow back to 0 at some point.
*/
guint
gst_util_group_id_next (void)
{
- static gint counter = 0;
- return g_atomic_int_add (&counter, 1);
+ static gint counter = 1;
+ gint ret = g_atomic_int_add (&counter, 1);
+
+ /* Make sure we don't return GST_GROUP_ID_INVALID */
+ if (G_UNLIKELY (ret == GST_GROUP_ID_INVALID))
+ ret = g_atomic_int_add (&counter, 1);
+
+ return ret;
}
/* Compute log2 of the passed 64-bit number by finding the highest set bit */
diff --git a/gst/gstutils.h b/gst/gstutils.h
index e891f1b89..a9b9eee88 100644
--- a/gst/gstutils.h
+++ b/gst/gstutils.h
@@ -107,6 +107,18 @@ guint32 gst_util_seqnum_next (void);
GST_EXPORT
gint32 gst_util_seqnum_compare (guint32 s1, guint32 s2);
+/**
+ * GST_GROUP_ID_INVALID:
+ *
+ * A value which is guaranteed to never be returned by
+ * gst_util_group_id_next().
+ *
+ * Can be used as a default value in variables used to store group_id.
+ *
+ * Since: 1.14
+ */
+#define GST_GROUP_ID_INVALID (0)
+
GST_EXPORT
guint gst_util_group_id_next (void);