util: apply the upstream 1.14.4 93/200293/2
authorEunhae Choi <eunhae1.choi@samsung.com>
Thu, 21 Feb 2019 07:56:38 +0000 (16:56 +0900)
committerEunhae Choi <eunhae1.choi@samsung.com>
Thu, 21 Feb 2019 08:10:26 +0000 (17:10 +0900)
- get upstream 1.14.4 patches
  to avoid return the invalid group id or seqnum.

Change-Id: I1d7f74ec9870c3ac3b281c04f1fa76b966eb44e5

gst/gstutils.c
gst/gstutils.h

index bcbac2c..dd83f7d 100644 (file)
@@ -780,8 +780,14 @@ gst_util_uint64_scale_int_ceil (guint64 val, gint num, gint denom)
 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;
 }
 
 /**
@@ -2367,6 +2373,8 @@ gst_element_query_position (GstElement * element, GstFormat format,
   GstQuery *query;
   gboolean ret;
 
+  if (cur != NULL)
+    *cur = GST_CLOCK_TIME_NONE;
   g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
   g_return_val_if_fail (format != GST_FORMAT_UNDEFINED, FALSE);
 
@@ -2404,6 +2412,8 @@ gst_element_query_duration (GstElement * element, GstFormat format,
 {
   GstQuery *query;
   gboolean ret;
+  if (duration != NULL)
+    *duration = GST_CLOCK_TIME_NONE;
 
   g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
   g_return_val_if_fail (format != GST_FORMAT_UNDEFINED, FALSE);
@@ -2775,6 +2785,8 @@ gst_pad_query_position (GstPad * pad, GstFormat format, gint64 * cur)
   GstQuery *query;
   gboolean ret;
 
+  if (cur != NULL)
+    *cur = GST_CLOCK_TIME_NONE;
   g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
   g_return_val_if_fail (format != GST_FORMAT_UNDEFINED, FALSE);
 
@@ -2804,6 +2816,8 @@ gst_pad_peer_query_position (GstPad * pad, GstFormat format, gint64 * cur)
   GstQuery *query;
   gboolean ret = FALSE;
 
+  if (cur != NULL)
+    *cur = GST_CLOCK_TIME_NONE;
   g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
   g_return_val_if_fail (format != GST_FORMAT_UNDEFINED, FALSE);
 
@@ -2832,6 +2846,8 @@ gst_pad_query_duration (GstPad * pad, GstFormat format, gint64 * duration)
   GstQuery *query;
   gboolean ret;
 
+  if (duration != NULL)
+    *duration = GST_CLOCK_TIME_NONE;
   g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
   g_return_val_if_fail (format != GST_FORMAT_UNDEFINED, FALSE);
 
@@ -2860,6 +2876,8 @@ gst_pad_peer_query_duration (GstPad * pad, GstFormat format, gint64 * duration)
 {
   GstQuery *query;
   gboolean ret = FALSE;
+  if (duration != NULL)
+    *duration = GST_CLOCK_TIME_NONE;
 
   g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
   g_return_val_if_fail (GST_PAD_IS_SINK (pad), FALSE);
@@ -3400,10 +3418,7 @@ gst_util_get_timestamp (void)
   clock_gettime (CLOCK_MONOTONIC, &now);
   return GST_TIMESPEC_TO_TIME (now);
 #else
-  GTimeVal now;
-
-  g_get_current_time (&now);
-  return GST_TIMEVAL_TO_TIME (now);
+  return g_get_monotonic_time () * 1000;
 #endif
 }
 
@@ -4122,8 +4137,14 @@ gst_pad_get_stream (GstPad * pad)
 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 */
@@ -4307,7 +4328,7 @@ gst_calculate_linear_regression (const GstClockTime * xy,
           tmp /= 4;
         } while (G_MAXINT64 - sxx <= tmp);
         break;
-      } else if (G_UNLIKELY (tmp < 0 && sxx < 0 && (G_MAXINT64 - sxx >= tmp))) {
+      } else if (G_UNLIKELY (tmp < 0 && sxx < 0 && (G_MININT64 - sxx >= tmp))) {
         do {
           /* Drop some precision and restart */
           pshift++;
@@ -4326,7 +4347,7 @@ gst_calculate_linear_regression (const GstClockTime * xy,
           tmp /= 4;
         } while (G_MAXINT64 - syy <= tmp);
         break;
-      } else if (G_UNLIKELY (tmp < 0 && syy < 0 && (G_MAXINT64 - syy >= tmp))) {
+      } else if (G_UNLIKELY (tmp < 0 && syy < 0 && (G_MININT64 - syy >= tmp))) {
         do {
           pshift++;
           syy /= 4;
index bf859b1..dbb2e66 100644 (file)
@@ -76,6 +76,17 @@ guint64         gst_util_uint64_scale_int       (guint64 val, gint num, gint den
 guint64         gst_util_uint64_scale_int_round (guint64 val, gint num, gint denom);
 guint64         gst_util_uint64_scale_int_ceil  (guint64 val, gint num, gint denom);
 
+/**
+ * GST_SEQNUM_INVALID:
+ *
+ * A value which is guaranteed to never be returned by
+ * gst_util_seqnum_next().
+ *
+ * Can be used as a default value in variables used to store seqnum.
+ *
+ * Since: 1.14
+ */
+#define GST_SEQNUM_INVALID (0)
 guint32         gst_util_seqnum_next            (void);
 gint32          gst_util_seqnum_compare         (guint32 s1, guint32 s2);