summaryrefslogtreecommitdiffstats
path: root/gst-libs/gst
diff options
context:
space:
mode:
authorMartin Soto <martinsoto@users.sourceforge.net>2004-11-27 09:37:20 +0000
committerMartin Soto <martinsoto@users.sourceforge.net>2004-11-27 09:37:20 +0000
commit3b48708b7727cdf8827f0d7d9d108e0a090028dd (patch)
tree067e453052bfb786fcb9ab43e55f75fecd5209b4 /gst-libs/gst
parentaeb09d35abf17934407c8e1c826de3d8fab7193d (diff)
downloadgst-plugins-bad-3b48708b7727cdf8827f0d7d9d108e0a090028dd.tar.gz
gst-plugins-bad-3b48708b7727cdf8827f0d7d9d108e0a090028dd.tar.bz2
gst-plugins-bad-3b48708b7727cdf8827f0d7d9d108e0a090028dd.zip
gst-libs/gst/audio/audioclock.c (gst_audio_clock_set_active)
Original commit message from CVS: 2004-11-27 Martin Soto <martinsoto@users.sourceforge.net> * gst-libs/gst/audio/audioclock.c (gst_audio_clock_set_active) (gst_audio_clock_get_internal_time): Fix active <-> inactive transitions: ensure time value always grows and avoid abrupt value changes.
Diffstat (limited to 'gst-libs/gst')
-rw-r--r--gst-libs/gst/audio/audioclock.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/gst-libs/gst/audio/audioclock.c b/gst-libs/gst/audio/audioclock.c
index 75c4c1c5..65d2694f 100644
--- a/gst-libs/gst/audio/audioclock.c
+++ b/gst-libs/gst/audio/audioclock.c
@@ -109,22 +109,32 @@ gst_audio_clock_new (gchar * name, GstAudioClockGetTimeFunc func,
void
gst_audio_clock_set_active (GstAudioClock * aclock, gboolean active)
{
- GstClockTime time;
+ GstClockTime audio_time, system_time;
GstClock *clock;
+ GTimeVal timeval;
g_return_if_fail (GST_IS_AUDIO_CLOCK (aclock));
clock = GST_CLOCK (aclock);
- time = gst_clock_get_event_time (clock);
+ if (active == aclock->active) {
+ /* Nothing to do. */
+ return;
+ }
- if (active) {
- aclock->adjust = time - aclock->func (clock, aclock->user_data);
- } else {
- GTimeVal timeval;
+ audio_time = aclock->func (clock, aclock->user_data);
- g_get_current_time (&timeval);
+ g_get_current_time (&timeval);
+ system_time = GST_TIMEVAL_TO_TIME (timeval);
- aclock->adjust = GST_TIMEVAL_TO_TIME (timeval) - time;
+ /* Set the new adjust value in such a way that there's no abrupt
+ discontinuity, i.e. if gst_audio_clock_get_internal_time is
+ invoked right before and right after (de)activating the clock,
+ the values returned will be close to each other, and the second
+ value will be greater than or equal than the first. */
+ if (active) {
+ aclock->adjust = aclock->adjust + system_time - audio_time;
+ } else {
+ aclock->adjust = aclock->adjust + audio_time - system_time;
}
aclock->active = active;
@@ -141,7 +151,7 @@ gst_audio_clock_get_internal_time (GstClock * clock)
GTimeVal timeval;
g_get_current_time (&timeval);
- return GST_TIMEVAL_TO_TIME (timeval);
+ return GST_TIMEVAL_TO_TIME (timeval) + aclock->adjust;
}
}