seqnum: Never return a seqnum of 0, reset GST_SEQNUM_INVALID
authorJan Schmidt <jan@centricular.com>
Tue, 17 Oct 2017 15:31:12 +0000 (02:31 +1100)
committerJan Schmidt <jan@centricular.com>
Tue, 17 Oct 2017 15:31:12 +0000 (02:31 +1100)
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.

gst/gstutils.c
gst/gstutils.h

index 173509f..601d553 100644 (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;
 }
 
 /**
index 1a83eb6..1ff94e3 100644 (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);