mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-20 15:27:07 +00:00
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.
This commit is contained in:
parent
0c952d0711
commit
fb01dd000b
4 changed files with 58 additions and 19 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue