clock: Add gst_clock_adjust_with_calibration()
authorJan Schmidt <jan@centricular.com>
Tue, 16 Dec 2014 11:51:22 +0000 (22:51 +1100)
committerJan Schmidt <jan@centricular.com>
Wed, 21 Jan 2015 11:27:18 +0000 (22:27 +1100)
gst_clock_adjust_with_calibration() uses directly passed calibration
parameters, instead of using the clock's current calibration,
allowing for calculations using pending or old calibration params

gst/gstclock.c
gst/gstclock.h
win32/common/libgstreamer.def

index d413dff..89b0051 100644 (file)
@@ -818,30 +818,31 @@ gst_clock_get_resolution (GstClock * clock)
 }
 
 /**
- * gst_clock_adjust_unlocked:
+ * gst_clock_adjust_with_calibration:
  * @clock: a #GstClock to use
- * @internal: a clock time
- *
- * Converts the given @internal clock time to the external time, adjusting for the
- * rate and reference time set with gst_clock_set_calibration() and making sure
- * that the returned time is increasing. This function should be called with the
- * clock's OBJECT_LOCK held and is mainly used by clock subclasses.
- *
- * This function is the reverse of gst_clock_unadjust_unlocked().
+ * @internal_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 @internal_target clock time to the external time,
+ * using the passed calibration parameters. This function performs the
+ * same calculation as gst_clock_adjust_unlocked() when called using the
+ * current calibration parameters, but doesn't ensure a monotonically
+ * increasing result as gst_clock_adjust_unlocked() does.
  *
  * Returns: the converted time of the clock.
+ *
+ * Since: 1.6
  */
 GstClockTime
-gst_clock_adjust_unlocked (GstClock * clock, GstClockTime internal)
+gst_clock_adjust_with_calibration (GstClock * clock,
+    GstClockTime internal_target, GstClockTime cinternal,
+    GstClockTime cexternal, GstClockTime cnum, GstClockTime cdenom)
 {
-  GstClockTime ret, cinternal, cexternal, cnum, cdenom;
-  GstClockPrivate *priv = clock->priv;
-
-  /* get calibration values for readability */
-  cinternal = priv->internal_calibration;
-  cexternal = priv->external_calibration;
-  cnum = priv->rate_numerator;
-  cdenom = priv->rate_denominator;
+  GstClockTime ret;
 
   /* avoid divide by 0 */
   if (G_UNLIKELY (cdenom == 0))
@@ -853,12 +854,12 @@ gst_clock_adjust_unlocked (GstClock * clock, GstClockTime internal)
    * internal < cinternal to get the sign right. this case is not very common,
    * though.
    */
-  if (G_LIKELY (internal >= cinternal)) {
-    ret = internal - cinternal;
+  if (G_LIKELY (internal_target >= cinternal)) {
+    ret = internal_target - cinternal;
     ret = gst_util_uint64_scale (ret, cnum, cdenom);
     ret += cexternal;
   } else {
-    ret = cinternal - internal;
+    ret = cinternal - internal_target;
     ret = gst_util_uint64_scale (ret, cnum, cdenom);
     /* clamp to 0 */
     if (G_LIKELY (cexternal > ret))
@@ -867,6 +868,39 @@ gst_clock_adjust_unlocked (GstClock * clock, GstClockTime internal)
       ret = 0;
   }
 
+  return ret;
+}
+
+/**
+ * gst_clock_adjust_unlocked:
+ * @clock: a #GstClock to use
+ * @internal: a clock time
+ *
+ * Converts the given @internal clock time to the external time, adjusting for the
+ * rate and reference time set with gst_clock_set_calibration() and making sure
+ * that the returned time is increasing. This function should be called with the
+ * clock's OBJECT_LOCK held and is mainly used by clock subclasses.
+ *
+ * This function is the reverse of gst_clock_unadjust_unlocked().
+ *
+ * Returns: the converted time of the clock.
+ */
+GstClockTime
+gst_clock_adjust_unlocked (GstClock * clock, GstClockTime internal)
+{
+  GstClockTime ret, cinternal, cexternal, cnum, cdenom;
+  GstClockPrivate *priv = clock->priv;
+
+  /* get calibration values for readability */
+  cinternal = priv->internal_calibration;
+  cexternal = priv->external_calibration;
+  cnum = priv->rate_numerator;
+  cdenom = priv->rate_denominator;
+
+  ret =
+      gst_clock_adjust_with_calibration (clock, internal, cinternal, cexternal,
+      cnum, cdenom);
+
   /* make sure the time is increasing */
   priv->last_time = MAX (ret, priv->last_time);
 
index 2fbe90c..005916b 100644 (file)
@@ -482,6 +482,12 @@ gboolean                gst_clock_add_observation       (GstClock *clock, GstClo
 /* getting and adjusting internal/external time */
 GstClockTime            gst_clock_get_internal_time     (GstClock *clock);
 GstClockTime            gst_clock_adjust_unlocked       (GstClock *clock, GstClockTime internal);
+GstClockTime            gst_clock_adjust_with_calibration (GstClock *clock,
+                                                         GstClockTime internal_target,
+                                                         GstClockTime cinternal,
+                                                         GstClockTime cexternal,
+                                                         GstClockTime cnum,
+                                                         GstClockTime cdenom);
 GstClockTime            gst_clock_unadjust_unlocked     (GstClock * clock, GstClockTime external);
 
 
index 98cb12d..d0a9f19 100644 (file)
@@ -299,6 +299,7 @@ EXPORTS
        gst_child_proxy_set_valist
        gst_clock_add_observation
        gst_clock_adjust_unlocked
+       gst_clock_adjust_with_calibration
        gst_clock_entry_type_get_type
        gst_clock_flags_get_type
        gst_clock_get_calibration