From fbefe67d52eb89a429505c653d1ea4ce73d4f4e7 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 13 Sep 2004 13:26:44 +0000 Subject: correct latency calculation git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@197 fefdeb5f-60dc-0310-8127-8f9354f1896f --- doc/todo | 1 + polyp/module-alsa-sink.c | 8 +++++++- polyp/module-oss.c | 8 +++++++- polyp/sink-input.c | 8 ++++++-- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/doc/todo b/doc/todo index c09d423a..61cee844 100644 --- a/doc/todo +++ b/doc/todo @@ -19,6 +19,7 @@ - input latency - fix tcp/native - suid +- add volume to create_stream command in native protocol ** later *** - xmlrpc/http diff --git a/polyp/module-alsa-sink.c b/polyp/module-alsa-sink.c index 95bb81f1..55e719c9 100644 --- a/polyp/module-alsa-sink.c +++ b/polyp/module-alsa-sink.c @@ -144,6 +144,7 @@ static void io_callback(struct pa_mainloop_api*a, struct pa_io_event *e, int fd, } static pa_usec_t sink_get_latency_cb(struct pa_sink *s) { + pa_usec_t r = 0; struct userdata *u = s->userdata; snd_pcm_sframes_t frames; assert(s && u && u->sink); @@ -157,7 +158,12 @@ static pa_usec_t sink_get_latency_cb(struct pa_sink *s) { if (frames < 0) frames = 0; - return pa_bytes_to_usec(frames * u->frame_size, &s->sample_spec); + r += pa_bytes_to_usec(frames * u->frame_size, &s->sample_spec); + + if (u->memchunk.memblock) + r += pa_bytes_to_usec(u->memchunk.length, &s->sample_spec); + + return r; } int pa__init(struct pa_core *c, struct pa_module*m) { diff --git a/polyp/module-oss.c b/polyp/module-oss.c index 51cc42ef..b4e011d8 100644 --- a/polyp/module-oss.c +++ b/polyp/module-oss.c @@ -162,6 +162,7 @@ static void io_callback(struct pa_iochannel *io, void*userdata) { } static pa_usec_t sink_get_latency_cb(struct pa_sink *s) { + pa_usec_t r = 0; int arg; struct userdata *u = s->userdata; assert(s && u && u->sink); @@ -172,7 +173,12 @@ static pa_usec_t sink_get_latency_cb(struct pa_sink *s) { return 0; } - return pa_bytes_to_usec(arg, &s->sample_spec); + r += pa_bytes_to_usec(arg, &s->sample_spec); + + if (u->memchunk.memblock) + r += pa_bytes_to_usec(u->memchunk.length, &s->sample_spec); + + return r; } int pa__init(struct pa_core *c, struct pa_module*m) { diff --git a/polyp/sink-input.c b/polyp/sink-input.c index b0096182..7763f261 100644 --- a/polyp/sink-input.c +++ b/polyp/sink-input.c @@ -112,12 +112,16 @@ void pa_sink_input_kill(struct pa_sink_input*i) { } pa_usec_t pa_sink_input_get_latency(struct pa_sink_input *i) { + pa_usec_t r = 0; assert(i); if (i->get_latency) - return i->get_latency(i); + r += i->get_latency(i); - return 0; + if (i->resampled_chunk.memblock) + r += pa_bytes_to_usec(i->resampled_chunk.length, &i->sample_spec); + + return r; } int pa_sink_input_peek(struct pa_sink_input *i, struct pa_memchunk *chunk) { -- cgit