[pulseaudio-commits] src/pulse

Tanu Kaskinen tanuk at kemper.freedesktop.org
Mon Jul 28 00:40:38 PDT 2014


 src/pulse/simple.c |   21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

New commits:
commit c0bda6a7abbc4f13eb5edd72c0364a5bf5cfaf95
Author: Tanu Kaskinen <tanu.kaskinen at linux.intel.com>
Date:   Sun Jul 13 17:48:59 2014 +0300

    simple: Take locally buffered data into account in pa_simple_get_latency()
    
    BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=81075

diff --git a/src/pulse/simple.c b/src/pulse/simple.c
index 1891131..f005cf8 100644
--- a/src/pulse/simple.c
+++ b/src/pulse/simple.c
@@ -454,17 +454,32 @@ unlock_and_fail:
 
 pa_usec_t pa_simple_get_latency(pa_simple *p, int *rerror) {
     pa_usec_t t;
-    int negative;
 
     pa_assert(p);
 
     pa_threaded_mainloop_lock(p->mainloop);
 
     for (;;) {
+        int negative;
+
         CHECK_DEAD_GOTO(p, rerror, unlock_and_fail);
 
-        if (pa_stream_get_latency(p->stream, &t, &negative) >= 0)
+        if (pa_stream_get_latency(p->stream, &t, &negative) >= 0) {
+            pa_usec_t extra = 0;
+
+            if (p->direction == PA_STREAM_RECORD)
+                extra = pa_bytes_to_usec(p->read_length, pa_stream_get_sample_spec(p->stream));
+
+            if (negative) {
+                if (extra > t)
+                    t = extra - t;
+                else
+                    t = 0;
+            } else
+                t += extra;
+
             break;
+        }
 
         CHECK_SUCCESS_GOTO(p, rerror, pa_context_errno(p->context) == PA_ERR_NODATA, unlock_and_fail);
 
@@ -474,7 +489,7 @@ pa_usec_t pa_simple_get_latency(pa_simple *p, int *rerror) {
 
     pa_threaded_mainloop_unlock(p->mainloop);
 
-    return negative ? 0 : t;
+    return t;
 
 unlock_and_fail:
 



More information about the pulseaudio-commits mailing list