seqnum: Never return a seqnum of 0, reset GST_SEQNUM_INVALID

Various plugins use the value of '0' as an invalid seqnum value
(qtdemux for matching duplicated seek events, for example). Make
that behaviour explicit, create a GST_SEQNUM_INVALID value,
and ensure gst_util_seqnum_next never returns it.
This commit is contained in:
Jan Schmidt 2017-10-18 02:31:12 +11:00
parent 250d3e7284
commit 6adb6b478f
2 changed files with 13 additions and 3 deletions

View file

@ -770,15 +770,23 @@ gst_util_uint64_scale_int_ceil (guint64 val, gint num, gint denom)
* on a segment-done message to be the same as that of the last seek event, to
* indicate that event and the message correspond to the same segment.
*
* This function never returns GST_SEQNUM_INVALID (which is 0).
*
* Returns: A constantly incrementing 32-bit unsigned integer, which might
* overflow back to 0 at some point. Use gst_util_seqnum_compare() to make sure
* overflow at some point. Use gst_util_seqnum_compare() to make sure
* you handle wraparound correctly.
*/
guint32
gst_util_seqnum_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 0 */
if (G_UNLIKELY (ret == GST_SEQNUM_INVALID))
ret = g_atomic_int_add (&counter, 1);
return ret;
}
/**

View file

@ -96,6 +96,8 @@ guint64 gst_util_uint64_scale_int_round (guint64 val, gint num, gint den
GST_EXPORT
guint64 gst_util_uint64_scale_int_ceil (guint64 val, gint num, gint denom);
#define GST_SEQNUM_INVALID (0)
GST_EXPORT
guint32 gst_util_seqnum_next (void);