tests: Make loopback latency test more accurate master list upstream/4.0
authorArun Raghavan <arun.raghavan@collabora.co.uk>
Mon, 27 May 2013 08:57:42 +0000 (14:27 +0530)
committerArun Raghavan <arun.raghavan@collabora.co.uk>
Mon, 3 Jun 2013 19:08:44 +0000 (00:38 +0530)
This makes sure that we always take the timing at the point when we
write out the pulse, making the overall latency measurement more
accurate.

src/tests/lo-latency-test.c

index 124693d..ad5e7a5 100644 (file)
@@ -54,12 +54,17 @@ static void nop_free_cb(void *p) {
 static void write_cb(pa_stream *s, size_t nbytes, void *userdata) {
     pa_lo_test_context *ctx = (pa_lo_test_context *) userdata;
     static int ppos = 0;
-    int r, nsamp = nbytes / ctx->fs;
+    int r, nsamp;
+
+    /* Get the real requested bytes since the last write might have been
+     * incomplete if it caused a wrap around */
+    nbytes = pa_stream_writable_size(s);
+    nsamp = nbytes / ctx->fs;
 
     if (ppos + nsamp > N_OUT) {
-        r = pa_stream_write(s, &out[ppos][0], (N_OUT - ppos) * ctx->fs, nop_free_cb, 0, PA_SEEK_RELATIVE);
-        nbytes -= (N_OUT - ppos) * ctx->fs;
-        ppos = 0;
+        /* Wrap-around, write to end and exit. Next iteration will fill up the
+         * rest */
+        nbytes = (N_OUT - ppos) * ctx->fs;
     }
 
     if (ppos == 0)