summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Schmidt <jan@centricular.com>2014-12-16 22:51:22 +1100
committerJan Schmidt <jan@centricular.com>2015-01-21 22:27:18 +1100
commitb79b14815e14cab41c84db41cabab7673f7f49bb (patch)
tree0e411e545febf4656e82b32fd689cfdb59c14812
parent50de594718ae41426a4c98687355021271658b6d (diff)
clock: Add gst_clock_adjust_with_calibration()
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
-rw-r--r--gst/gstclock.c76
-rw-r--r--gst/gstclock.h6
-rw-r--r--win32/common/libgstreamer.def1
3 files changed, 62 insertions, 21 deletions
diff --git a/gst/gstclock.c b/gst/gstclock.c
index d413dff0e..89b00517e 100644
--- a/gst/gstclock.c
+++ b/gst/gstclock.c
@@ -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);
diff --git a/gst/gstclock.h b/gst/gstclock.h
index 2fbe90c3e..005916bdc 100644
--- a/gst/gstclock.h
+++ b/gst/gstclock.h
@@ -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);
diff --git a/win32/common/libgstreamer.def b/win32/common/libgstreamer.def
index 98cb12dd6..d0a9f1977 100644
--- a/win32/common/libgstreamer.def
+++ b/win32/common/libgstreamer.def
@@ -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