Commit fb01dd00 authored by Sebastian Dröge's avatar Sebastian Dröge 🍵

clock: Add gst_clock_unadjust_with_calibration()

We already have gst_clock_adjust_with_calibration() and
gst_clock_unadjust_unlocked(), having the other variant is useful.
parent 0c952d07
......@@ -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
......
......@@ -937,6 +937,53 @@ gst_clock_adjust_unlocked (GstClock * clock, GstClockTime internal)
return priv->last_time;
}
/**
* 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
......@@ -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);
}
/**
......
......@@ -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 */
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment