summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2006-05-16 00:06:02 +0000
committerLennart Poettering <lennart@poettering.net>2006-05-16 00:06:02 +0000
commit23e74545adce1e23f6d3e09a0cbb9f1d98a7b933 (patch)
tree8161df971f7224524849335c3bc5461f48ed2ba3
parent724cd9d811c3847c6e46233185f27b4c5201c260 (diff)
use the new latency update callback to be notified when latency data becomes
available again after PA_ERR_NODATA is returned by pa_stream_get_latency() git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@876 fefdeb5f-60dc-0310-8127-8f9354f1896f
-rw-r--r--src/polyp/simple.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/src/polyp/simple.c b/src/polyp/simple.c
index 97dcaf11..1f25869b 100644
--- a/src/polyp/simple.c
+++ b/src/polyp/simple.c
@@ -125,6 +125,14 @@ static void stream_request_cb(pa_stream *s, size_t length, void *userdata) {
pa_threaded_mainloop_signal(p->mainloop, 0);
}
+static void stream_latency_update_cb(pa_stream *s, void *userdata) {
+ pa_simple *p = userdata;
+
+ assert(p);
+
+ pa_threaded_mainloop_signal(p->mainloop, 0);
+}
+
pa_simple* pa_simple_new(
const char *server,
const char *name,
@@ -184,6 +192,7 @@ pa_simple* pa_simple_new(
pa_stream_set_state_callback(p->stream, stream_state_cb, p);
pa_stream_set_read_callback(p->stream, stream_request_cb, p);
pa_stream_set_write_callback(p->stream, stream_request_cb, p);
+ pa_stream_set_latency_update_callback(p->stream, stream_latency_update_cb, p);
if (dir == PA_STREAM_PLAYBACK)
r = pa_stream_connect_playback(p->stream, dev, attr, PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_AUTO_TIMING_UPDATE, NULL, NULL);
@@ -414,17 +423,25 @@ unlock_and_fail:
pa_usec_t pa_simple_get_playback_latency(pa_simple *p, int *rerror) {
pa_usec_t t;
- int r, negative;
+ int negative;
assert(p);
CHECK_VALIDITY_RETURN_ANY(rerror, p->direction == PA_STREAM_PLAYBACK, PA_ERR_BADSTATE, (pa_usec_t) -1);
pa_threaded_mainloop_lock(p->mainloop);
- CHECK_DEAD_GOTO(p, rerror, unlock_and_fail);
- r = pa_stream_get_latency(p->stream, &t, &negative);
- CHECK_SUCCESS_GOTO(p, rerror, r >= 0, unlock_and_fail);
+ for (;;) {
+ CHECK_DEAD_GOTO(p, rerror, unlock_and_fail);
+
+ if (pa_stream_get_latency(p->stream, &t, &negative) >= 0)
+ break;
+
+ CHECK_SUCCESS_GOTO(p, rerror, pa_context_errno(p->context) == PA_ERR_NODATA, unlock_and_fail);
+
+ /* Wait until latency data is available again */
+ pa_threaded_mainloop_wait(p->mainloop);
+ }
pa_threaded_mainloop_unlock(p->mainloop);