}
/**
- * 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))
* 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))
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);