From 40494c3bc1f109b0d0d2e9e04cda814e9856ff1f Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 19 Jun 2006 12:37:43 +0000 Subject: * rework latency interpolation to make it smoother * increase latency update interval to 100ms git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1029 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/polyp/internal.h | 5 ++--- src/polyp/stream.c | 26 ++++++++++---------------- 2 files changed, 12 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/polyp/internal.h b/src/polyp/internal.h index 80c28616..e659553d 100644 --- a/src/polyp/internal.h +++ b/src/polyp/internal.h @@ -136,9 +136,8 @@ struct pa_stream { pa_time_event *auto_timing_update_event; int auto_timing_update_requested; - pa_usec_t ipol_usec; - int ipol_usec_valid; - struct timeval ipol_timestamp; + pa_usec_t cached_time; + int cached_time_valid; /* Callbacks */ pa_stream_notify_cb_t state_callback; diff --git a/src/polyp/stream.c b/src/polyp/stream.c index e3f40a3f..8927805e 100644 --- a/src/polyp/stream.c +++ b/src/polyp/stream.c @@ -38,7 +38,7 @@ #include "internal.h" -#define LATENCY_IPOL_INTERVAL_USEC (10000L) +#define LATENCY_IPOL_INTERVAL_USEC (100000L) pa_stream *pa_stream_new(pa_context *c, const char *name, const pa_sample_spec *ss, const pa_channel_map *map) { pa_stream *s; @@ -102,9 +102,7 @@ pa_stream *pa_stream_new(pa_context *c, const char *name, const pa_sample_spec * s->corked = 0; - s->ipol_usec_valid = 0; - s->ipol_timestamp.tv_sec = 0; - s->ipol_timestamp.tv_usec = 0; + s->cached_time_valid = 0; s->auto_timing_update_event = NULL; s->auto_timing_update_requested = 0; @@ -367,7 +365,7 @@ static void invalidate_indexes(pa_stream *s, int r, int w) { if ((s->direction == PA_STREAM_PLAYBACK && r) || (s->direction == PA_STREAM_RECORD && w)) - s->ipol_usec_valid = 0; + s->cached_time_valid = 0; request_auto_timing_update(s, 1); } @@ -855,8 +853,7 @@ static void stream_get_timing_info_callback(pa_pdispatch *pd, uint32_t command, i->read_index -= pa_memblockq_get_length(o->stream->record_memblockq); } - o->stream->ipol_timestamp = now; - o->stream->ipol_usec_valid = 0; + o->stream->cached_time_valid = 0; } o->stream->auto_timing_update_requested = 0; @@ -1203,8 +1200,9 @@ int pa_stream_get_time(pa_stream *s, pa_usec_t *r_usec) { PA_CHECK_VALIDITY(s->context, s->direction != PA_STREAM_PLAYBACK || !s->timing_info.read_index_corrupt, PA_ERR_NODATA); PA_CHECK_VALIDITY(s->context, s->direction != PA_STREAM_RECORD || !s->timing_info.write_index_corrupt, PA_ERR_NODATA); - if (s->flags & PA_STREAM_INTERPOLATE_TIMING && s->ipol_usec_valid) - usec = s->ipol_usec; + if (s->cached_time_valid) + /* We alredy calculated the time value for this timing info, so let's reuse it */ + usec = s->cached_time; else { if (s->direction == PA_STREAM_PLAYBACK) { /* The last byte that was written into the output device @@ -1247,10 +1245,8 @@ int pa_stream_get_time(pa_stream *s, pa_usec_t *r_usec) { } } - if (s->flags & PA_STREAM_INTERPOLATE_TIMING) { - s->ipol_usec = usec; - s->ipol_usec_valid = 1; - } + s->cached_time = usec; + s->cached_time_valid = 1; } /* Interpolate if requested */ @@ -1260,9 +1256,7 @@ int pa_stream_get_time(pa_stream *s, pa_usec_t *r_usec) { * current */ if (!s->corked) { struct timeval now; - - usec += pa_timeval_diff(pa_gettimeofday(&now), &s->ipol_timestamp); - s->ipol_timestamp = now; + usec += pa_timeval_diff(pa_gettimeofday(&now), &s->timing_info.timestamp); } } -- cgit