mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-28 20:51:13 +00:00
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
This commit is contained in:
parent
16d9954dd5
commit
e5c15f6b96
3 changed files with 23 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue