diff options
author | Edward Hervey <edward@centricular.com> | 2017-12-05 17:28:55 +0100 |
---|---|---|
committer | Edward Hervey <bilboed@bilboed.com> | 2017-12-08 08:34:42 +0100 |
commit | 1a03a9d3af8148d5388dbdf5641462f6364b2296 (patch) | |
tree | 63ab6472bbc132e80fa3c502e4c1512d51400262 | |
parent | 091e6cbea803e0542e9bc1306e6bcc8bea77d76a (diff) |
utils: Never return a group_id of 0, add GST_GROUP_ID_INVALIDuridecodebin3-1.12
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-- | gst/gstutils.c | 12 | ||||
-rw-r--r-- | gst/gstutils.h | 2 |
2 files changed, 12 insertions, 2 deletions
diff --git a/gst/gstutils.c b/gst/gstutils.c index c56a66071..f0cd95159 100644 --- a/gst/gstutils.c +++ b/gst/gstutils.c @@ -4121,14 +4121,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 1e4af89b5..d574eddf2 100644 --- a/gst/gstutils.h +++ b/gst/gstutils.h @@ -81,6 +81,8 @@ guint64 gst_util_uint64_scale_int_ceil (guint64 val, gint num, gint den guint32 gst_util_seqnum_next (void); gint32 gst_util_seqnum_compare (guint32 s1, guint32 s2); +#define GST_GROUP_ID_INVALID (0) + guint gst_util_group_id_next (void); /** |