From cbf25c8c6021af9ff7cd8bafd82b6a13c56ff2d6 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 16 May 2006 20:27:24 +0000 Subject: make use of new latency update callback git-svn-id: file:///home/lennart/svn/public/gst-pulse/trunk@30 bb39ca4e-bce3-0310-b5d4-eea78a553289 --- src/polypsink.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/polypsink.c b/src/polypsink.c index 02cb3d7..d3d03b0 100644 --- a/src/polypsink.c +++ b/src/polypsink.c @@ -303,6 +303,12 @@ static void gst_polypsink_stream_request_cb(pa_stream *s, size_t length, void *u pa_threaded_mainloop_signal(polypsink->mainloop, 0); } +static void gst_polypsink_stream_latency_update_cb(pa_stream *s, void *userdata) { + GstPolypSink *polypsink = GST_POLYPSINK(userdata); + + pa_threaded_mainloop_signal(polypsink->mainloop, 0); +} + static gboolean gst_polypsink_open(GstAudioSink *asink) { GstPolypSink *polypsink = GST_POLYPSINK(asink); gchar *name = gst_polyp_client_name(); @@ -374,6 +380,7 @@ static gboolean gst_polypsink_prepare(GstAudioSink *asink, GstRingBufferSpec *sp pa_stream_set_state_callback(polypsink->stream, gst_polypsink_stream_state_cb, polypsink); pa_stream_set_write_callback(polypsink->stream, gst_polypsink_stream_request_cb, polypsink); + pa_stream_set_latency_update_callback(polypsink->stream, gst_polypsink_stream_latency_update_cb, polypsink); memset(&buf_attr, 0, sizeof(buf_attr)); buf_attr.tlength = spec->segtotal*spec->segsize; @@ -459,7 +466,7 @@ static guint gst_polypsink_write(GstAudioSink *asink, gpointer data, guint lengt sum += l; } - + pa_threaded_mainloop_unlock(polypsink->mainloop); return sum; @@ -476,17 +483,18 @@ static guint gst_polypsink_delay(GstAudioSink *asink) { pa_threaded_mainloop_lock(polypsink->mainloop); - CHECK_DEAD_GOTO(polypsink, unlock_and_fail); - - if (pa_stream_get_latency(polypsink->stream, &t, NULL) < 0) { + for (;;) { + CHECK_DEAD_GOTO(polypsink, unlock_and_fail); + + if (pa_stream_get_latency(polypsink->stream, &t, NULL) >= 0) + break; if (pa_context_errno(polypsink->context) != PA_ERR_NODATA) { GST_ELEMENT_ERROR(polypsink, RESOURCE, FAILED, ("pa_stream_get_latency() failed: %s", pa_strerror(pa_context_errno(polypsink->context))), (NULL)); goto unlock_and_fail; } - GST_WARNING("Not data while querying latency"); - t = 0; + pa_threaded_mainloop_wait(polypsink->mainloop); } pa_threaded_mainloop_unlock(polypsink->mainloop); @@ -530,7 +538,7 @@ static void gst_polypsink_reset(GstAudioSink *asink) { GST_ELEMENT_ERROR(polypsink, RESOURCE, FAILED, ("Flush failed: %s", pa_strerror(pa_context_errno(polypsink->context))), (NULL)); goto unlock_and_fail; } - + unlock_and_fail: if (o) { -- cgit