From 45e495499e5dede1d7c0e8b18b4b2ef3df215d3e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 11 Aug 2007 23:43:39 +0000 Subject: [PATCH] fix latency reporting for oss and alsa modules git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/lennart@1645 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-alsa-sink.c | 13 +++++++------ src/modules/module-alsa-source.c | 13 +++++++------ src/modules/module-oss.c | 2 +- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/modules/module-alsa-sink.c b/src/modules/module-alsa-sink.c index 5491aac..cf999a9 100644 --- a/src/modules/module-alsa-sink.c +++ b/src/modules/module-alsa-sink.c @@ -217,17 +217,18 @@ static int mmap_write(struct userdata *u) { static pa_usec_t sink_get_latency(struct userdata *u) { pa_usec_t r = 0; + snd_pcm_status_t *status; snd_pcm_sframes_t frames = 0; int err; + + snd_pcm_status_alloca(&status); pa_assert(u); - snd_pcm_avail_update(u->pcm_handle); - - if ((err = snd_pcm_delay(u->pcm_handle, &frames)) < 0) { + if ((err = snd_pcm_status(u->pcm_handle, status)) < 0) pa_log("Failed to get delay: %s", snd_strerror(err)); - return 0; - } + else + frames = snd_pcm_status_get_delay(status); if (frames > 0) r = pa_bytes_to_usec(frames * u->frame_size, &u->sink->sample_spec); @@ -356,7 +357,7 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse *((pa_usec_t*) data) = r; - break; + return 0; } case PA_SINK_MESSAGE_SET_STATE: diff --git a/src/modules/module-alsa-source.c b/src/modules/module-alsa-source.c index b647185..8ff074d 100644 --- a/src/modules/module-alsa-source.c +++ b/src/modules/module-alsa-source.c @@ -209,17 +209,18 @@ static int mmap_read(struct userdata *u) { static pa_usec_t source_get_latency(struct userdata *u) { pa_usec_t r = 0; + snd_pcm_status_t *status; snd_pcm_sframes_t frames = 0; int err; + + snd_pcm_status_alloca(&status); pa_assert(u); - snd_pcm_avail_update(u->pcm_handle); - - if ((err = snd_pcm_delay(u->pcm_handle, &frames)) < 0) { + if ((err = snd_pcm_status(u->pcm_handle, status)) < 0) pa_log("Failed to get delay: %s", snd_strerror(err)); - return 0; - } + else + frames = snd_pcm_status_get_delay(status); if (frames > 0) r = pa_bytes_to_usec(frames * u->frame_size, &u->source->sample_spec); @@ -345,7 +346,7 @@ static int source_process_msg(pa_msgobject *o, int code, void *data, int64_t off *((pa_usec_t*) data) = r; - break; + return 0; } case PA_SOURCE_MESSAGE_SET_STATE: diff --git a/src/modules/module-oss.c b/src/modules/module-oss.c index 1a36663..d9b5b96 100644 --- a/src/modules/module-oss.c +++ b/src/modules/module-oss.c @@ -597,7 +597,7 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse *((pa_usec_t*) data) = r; - break; + return 0; } case PA_SINK_MESSAGE_SET_STATE: -- 2.7.4