clock: Add gst_clock_unadjust_with_calibration()
authorSebastian Dröge <sebastian@centricular.com>
Wed, 6 Jan 2016 14:19:22 +0000 (16:19 +0200)
committerSebastian Dröge <sebastian@centricular.com>
Wed, 6 Jan 2016 14:25:38 +0000 (16:25 +0200)
We already have gst_clock_adjust_with_calibration() and
gst_clock_unadjust_unlocked(), having the other variant is useful.

docs/gst/gstreamer-sections.txt
gst/gstclock.c
gst/gstclock.h
win32/common/libgstreamer.def

index 884c5c4..b9e68cc 100644 (file)
@@ -630,6 +630,7 @@ gst_clock_get_internal_time
 gst_clock_adjust_unlocked
 gst_clock_unadjust_unlocked
 gst_clock_adjust_with_calibration
+gst_clock_unadjust_with_calibration
 gst_clock_get_calibration
 gst_clock_set_calibration
 gst_clock_get_timeout
index 9663bb7..b89e255 100644 (file)
@@ -938,6 +938,53 @@ gst_clock_adjust_unlocked (GstClock * clock, GstClockTime internal)
 }
 
 /**
+ * gst_clock_unadjust_with_calibration:
+ * @clock: a #GstClock to use
+ * @external_target: a clock time
+ * @cinternal: a reference internal time
+ * @cexternal: a reference external time
+ * @cnum: the numerator of the rate of the clock relative to its
+ *        internal time
+ * @cdenom: the denominator of the rate of the clock
+ *
+ * Converts the given @external_target clock time to the internal time,
+ * using the passed calibration parameters. This function performs the
+ * same calculation as gst_clock_unadjust_unlocked() when called using the
+ * current calibration parameters.
+ *
+ * Returns: the converted time of the clock.
+ *
+ * Since: 1.8
+ */
+GstClockTime
+gst_clock_unadjust_with_calibration (GstClock * clock,
+    GstClockTime external_target, GstClockTime cinternal,
+    GstClockTime cexternal, GstClockTime cnum, GstClockTime cdenom)
+{
+  GstClockTime ret;
+
+  /* avoid divide by 0 */
+  if (G_UNLIKELY (cnum == 0))
+    cnum = cdenom = 1;
+
+  /* The formula is (external - cexternal) * cdenom / cnum + cinternal */
+  if (G_LIKELY (external_target >= cexternal)) {
+    ret = external_target - cexternal;
+    ret = gst_util_uint64_scale (ret, cdenom, cnum);
+    ret += cinternal;
+  } else {
+    ret = cexternal - external_target;
+    ret = gst_util_uint64_scale (ret, cdenom, cnum);
+    if (G_LIKELY (cinternal > ret))
+      ret = cinternal - ret;
+    else
+      ret = 0;
+  }
+
+  return ret;
+}
+
+/**
  * gst_clock_unadjust_unlocked:
  * @clock: a #GstClock to use
  * @external: an external clock time
@@ -954,7 +1001,7 @@ gst_clock_adjust_unlocked (GstClock * clock, GstClockTime internal)
 GstClockTime
 gst_clock_unadjust_unlocked (GstClock * clock, GstClockTime external)
 {
-  GstClockTime ret, cinternal, cexternal, cnum, cdenom;
+  GstClockTime cinternal, cexternal, cnum, cdenom;
   GstClockPrivate *priv = clock->priv;
 
   /* get calibration values for readability */
@@ -963,24 +1010,8 @@ gst_clock_unadjust_unlocked (GstClock * clock, GstClockTime external)
   cnum = priv->rate_numerator;
   cdenom = priv->rate_denominator;
 
-  /* avoid divide by 0 */
-  if (G_UNLIKELY (cnum == 0))
-    cnum = cdenom = 1;
-
-  /* The formula is (external - cexternal) * cdenom / cnum + cinternal */
-  if (G_LIKELY (external >= cexternal)) {
-    ret = external - cexternal;
-    ret = gst_util_uint64_scale (ret, cdenom, cnum);
-    ret += cinternal;
-  } else {
-    ret = cexternal - external;
-    ret = gst_util_uint64_scale (ret, cdenom, cnum);
-    if (G_LIKELY (cinternal > ret))
-      ret = cinternal - ret;
-    else
-      ret = 0;
-  }
-  return ret;
+  return gst_clock_unadjust_with_calibration (clock, external, cinternal,
+      cexternal, cnum, cdenom);
 }
 
 /**
index 9c2f888..dcd47c4 100644 (file)
@@ -535,6 +535,12 @@ GstClockTime            gst_clock_adjust_with_calibration (GstClock *clock,
                                                          GstClockTime cexternal,
                                                          GstClockTime cnum,
                                                          GstClockTime cdenom);
+GstClockTime            gst_clock_unadjust_with_calibration (GstClock *clock,
+                                                         GstClockTime external_target,
+                                                         GstClockTime cinternal,
+                                                         GstClockTime cexternal,
+                                                         GstClockTime cnum,
+                                                         GstClockTime cdenom);
 GstClockTime            gst_clock_unadjust_unlocked     (GstClock * clock, GstClockTime external);
 
 /* waiting for, signalling and checking for synchronization */
index ce553fa..2fa126a 100644 (file)
@@ -336,6 +336,7 @@ EXPORTS
        gst_clock_single_shot_id_reinit
        gst_clock_type_get_type
        gst_clock_unadjust_unlocked
+       gst_clock_unadjust_with_calibration
        gst_clock_wait_for_sync
        gst_context_get_context_type
        gst_context_get_structure