]> code.delx.au - pulseaudio/commitdiff
support for latency interpolation
authorLennart Poettering <lennart@poettering.net>
Wed, 27 Oct 2004 00:10:12 +0000 (00:10 +0000)
committerLennart Poettering <lennart@poettering.net>
Wed, 27 Oct 2004 00:10:12 +0000 (00:10 +0000)
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@256 fefdeb5f-60dc-0310-8127-8f9354f1896f

13 files changed:
doc/todo
polyp/pacat.c
polyp/polyplib-def.h
polyp/polyplib-internal.h
polyp/polyplib-simple.c
polyp/polyplib-stream.c
polyp/polyplib-stream.h
polyp/protocol-native.c
polyp/sample.h
polyp/tagstruct.c
polyp/tagstruct.h
polyp/util.c
polyp/util.h

index fde49d6696e6589ecaedb5e3abc9a7ad94be84f2..df710ecf45a2d02f9ae474e5d7ec79cf9e1c70e1 100644 (file)
--- a/doc/todo
+++ b/doc/todo
@@ -1,7 +1,6 @@
 *** $Id$ ***
 
 *** 0.6 ****
-- latency interpolation
 - per-channel volume
 - unix socket directories include user name
 - add sample directory
@@ -11,7 +10,9 @@
 - filter capture data in client through alignment
 - add radio module
 - make autoload list use idxset
-- enlarge mqmblockq sizes
+- enlarge memblockq sizes
+- add null-sink
+- add sync API
 
 ** later ***
 - xmlrpc/http
index a2687116c9189116024c47ec79584317a0d3738e..a37f5dda9f9d054fcc8b9aeaf6c74975f377a67a 100644 (file)
@@ -297,7 +297,8 @@ static void exit_signal_callback(struct pa_mainloop_api*m, struct pa_signal_even
 
 /* Show the current latency */
 static void stream_get_latency_callback(struct pa_stream *s, const struct pa_latency_info *i, void *userdata) {
-    double total;
+    pa_usec_t total;
+    int negative = 0;
     assert(s);
 
     if (!i) {
@@ -306,20 +307,17 @@ static void stream_get_latency_callback(struct pa_stream *s, const struct pa_lat
         return;
     }
 
-    if (mode == PLAYBACK)
-        total = (double) i->sink_usec + i->buffer_usec + i->transport_usec;
-    else
-        total = (double) i->source_usec + i->buffer_usec + i->transport_usec - i->sink_usec;
+    total = pa_stream_get_latency(s, i, &negative);
 
     fprintf(stderr, "Latency: buffer: %0.0f usec; sink: %0.0f usec; source: %0.0f usec; transport: %0.0f usec; total: %0.0f usec; synchronized clocks: %s.\n",
-            (float) i->buffer_usec, (float) i->sink_usec, (float) i->source_usec, (float) i->transport_usec, total,
+            (float) i->buffer_usec, (float) i->sink_usec, (float) i->source_usec, (float) i->transport_usec, (float) total * (negative?-1:1),
             i->synchronized_clocks ? "yes" : "no");
 }
 
 /* Someone requested that the latency is shown */
 static void sigusr1_signal_callback(struct pa_mainloop_api*m, struct pa_signal_event *e, int sig, void *userdata) {
     fprintf(stderr, "Got SIGUSR1, requesting latency.\n");
-    pa_operation_unref(pa_stream_get_latency(stream, stream_get_latency_callback, NULL));
+    pa_operation_unref(pa_stream_get_latency_info(stream, stream_get_latency_callback, NULL));
 }
 
 
index cd0662ddaf459afb5a8591b6844454e2d85c4440..ffa44188330ebed1be30133ddd1a8a9c0c425e4e 100644 (file)
@@ -74,7 +74,22 @@ enum pa_stream_direction {
 
 /** Some special flags for stream connections. \since 0.6 */
 enum pa_stream_flags {
-    PA_STREAM_START_CORKED = 1,   /**< Create the stream corked, requiring an explicit pa_stream_cork() call to uncork it. */
+    PA_STREAM_START_CORKED = 1,       /**< Create the stream corked, requiring an explicit pa_stream_cork() call to uncork it. */
+    PA_STREAM_INTERPOLATE_LATENCY = 2 /**< Interpolate the latency for
+                                       * this stream. When enabled,
+                                       * you can use
+                                       * pa_stream_interpolated_xxx()
+                                       * for synchronization. Using
+                                       * these functions instead of
+                                       * pa_stream_get_latency() has
+                                       * the advantage of not
+                                       * requiring a whole roundtrip
+                                       * for responses. Consider using
+                                       * this option when frequently
+                                       * requesting latency
+                                       * information. This is
+                                       * especially useful on long latency
+                                       * network connections. */
 };
 
 /** Playback and record buffer metrics */
@@ -171,6 +186,7 @@ struct pa_latency_info {
                                * limited und unreliable itself. \since
                                * 0.5 */
     struct timeval timestamp; /**< The time when this latency info was current */
+    uint64_t counter;         /**< The byte counter current when the latency info was requested. \since 0.6 */
 };
 
 /** A structure for the spawn api. This may be used to integrate auto
index 8a7bf6fbc580f6e415b0ce017ac7f37598807222..e49b25d40ad607fa92692d568aca9ea3de987b4c 100644 (file)
@@ -81,6 +81,7 @@ struct pa_context {
 struct pa_stream {
     int ref;
     struct pa_context *context;
+    struct pa_mainloop_api *mainloop;
     PA_LLIST_FIELDS(struct pa_stream);
 
     char *name;
@@ -95,6 +96,13 @@ struct pa_stream {
     pa_usec_t previous_time;
     enum pa_stream_state state;
 
+    int interpolate;
+    int corked;
+
+    uint32_t ipol_usec;
+    struct timeval ipol_timestamp;
+    struct pa_time_event *ipol_event;
+    
     void (*state_callback)(struct pa_stream*c, void *userdata);
     void *state_userdata;
 
@@ -103,6 +111,7 @@ struct pa_stream {
 
     void (*write_callback)(struct pa_stream *p, size_t length, void *userdata);
     void *write_userdata;
+
 };
 
 struct pa_operation {
@@ -135,4 +144,7 @@ struct pa_operation* pa_context_send_simple_command(struct pa_context *c, uint32
 
 void pa_stream_set_state(struct pa_stream *s, enum pa_stream_state st);
 
+void pa_stream_trash_ipol(struct pa_stream *s);
+
+
 #endif
index 9e111e2a12cd32bf990b61c7116af76dbecb5ebf..0e180af04161a7e2b30728abbab0aceb41cb3c6b 100644 (file)
@@ -341,7 +341,7 @@ pa_usec_t pa_simple_get_playback_latency(struct pa_simple *p, int *perror) {
     }
 
     p->latency = 0;
-    o = pa_stream_get_latency(p->stream, latency_complete, p);
+    o = pa_stream_get_latency_info(p->stream, latency_complete, p);
     
     while (pa_operation_get_state(o) == PA_OPERATION_RUNNING) {
 
index 291c3cd39d002c81dace32856e618bec91e0d0d9..68035b0fe0b1d25d19059e06240f04a67d4a954b 100644 (file)
 #include <assert.h>
 #include <string.h>
 #include <stdio.h>
+#include <string.h>
 
 #include "polyplib-internal.h"
 #include "xmalloc.h"
 #include "pstream-util.h"
 #include "util.h"
 
+#define LATENCY_IPOL_INTERVAL_USEC (100000L)
+
 struct pa_stream *pa_stream_new(struct pa_context *c, const char *name, const struct pa_sample_spec *ss) {
     struct pa_stream *s;
     assert(c && ss);
@@ -39,6 +42,7 @@ struct pa_stream *pa_stream_new(struct pa_context *c, const char *name, const st
     s = pa_xmalloc(sizeof(struct pa_stream));
     s->ref = 1;
     s->context = c;
+    s->mainloop = c->mainloop;
 
     s->read_callback = NULL;
     s->read_userdata = NULL;
@@ -60,6 +64,13 @@ struct pa_stream *pa_stream_new(struct pa_context *c, const char *name, const st
     s->counter = 0;
     s->previous_time = 0;
 
+    s->corked = 0;
+    s->interpolate = 0;
+
+    s->ipol_usec = 0;
+    memset(&s->ipol_timestamp, 0, sizeof(s->ipol_timestamp));
+    s->ipol_event = NULL;
+
     PA_LLIST_PREPEND(struct pa_stream, c->streams, s);
 
     return pa_stream_ref(s);
@@ -67,6 +78,12 @@ struct pa_stream *pa_stream_new(struct pa_context *c, const char *name, const st
 
 static void stream_free(struct pa_stream *s) {
     assert(s);
+
+    if (s->ipol_event) {
+        assert(s->mainloop);
+        s->mainloop->time_free(s->ipol_event);
+    }
+    
     pa_xfree(s->name);
     pa_xfree(s);
 }
@@ -181,6 +198,22 @@ finish:
     pa_context_unref(c);
 }
 
+static void ipol_callback(struct pa_mainloop_api *m, struct pa_time_event *e, const struct timeval *tv, void *userdata) {
+    struct timeval tv2;
+    struct pa_stream *s = userdata;
+
+    pa_stream_ref(s);
+    pa_operation_unref(pa_stream_get_latency_info(s, NULL, NULL));
+
+    gettimeofday(&tv2, NULL);
+    tv2.tv_usec += LATENCY_IPOL_INTERVAL_USEC;
+
+    m->time_restart(e, &tv2);
+    
+    pa_stream_unref(s);
+}
+
+
 void pa_create_stream_callback(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata) {
     struct pa_stream *s = userdata;
     assert(pd && s && s->state == PA_STREAM_CREATING);
@@ -207,6 +240,17 @@ void pa_create_stream_callback(struct pa_pdispatch *pd, uint32_t command, uint32
     pa_dynarray_put((s->direction == PA_STREAM_RECORD) ? s->context->record_streams : s->context->playback_streams, s->channel, s);
     pa_stream_set_state(s, PA_STREAM_READY);
 
+    if (s->interpolate) {
+        struct timeval tv;
+        pa_operation_unref(pa_stream_get_latency_info(s, NULL, NULL));
+
+        gettimeofday(&tv, NULL);
+        tv.tv_usec += LATENCY_IPOL_INTERVAL_USEC; /* every 100 ms */
+
+        assert(!s->ipol_event);
+        s->ipol_event = s->mainloop->time_new(s->mainloop, &tv, &ipol_callback, s);
+    }
+
     if (s->requested_bytes && s->ref > 1 && s->write_callback)
         s->write_callback(s, s->requested_bytes, s->write_userdata);
 
@@ -221,6 +265,9 @@ static void create_stream(struct pa_stream *s, const char *dev, const struct pa_
 
     pa_stream_ref(s);
 
+    s->interpolate = !!(flags & PA_STREAM_INTERPOLATE_LATENCY);
+    pa_stream_trash_ipol(s);
+    
     if (attr)
         s->buffer_attr = *attr;
     else {
@@ -330,7 +377,7 @@ struct pa_operation * pa_stream_drain(struct pa_stream *s, void (*cb) (struct pa
     return pa_operation_ref(o);
 }
 
-static void stream_get_latency_callback(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata) {
+static void stream_get_latency_info_callback(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata) {
     struct pa_operation *o = userdata;
     struct pa_latency_info i, *p = NULL;
     struct timeval local, remote, now;
@@ -347,32 +394,39 @@ static void stream_get_latency_callback(struct pa_pdispatch *pd, uint32_t comman
                pa_tagstruct_getu32(t, &i.queue_length) < 0 ||
                pa_tagstruct_get_timeval(t, &local) < 0 ||
                pa_tagstruct_get_timeval(t, &remote) < 0 ||
+               pa_tagstruct_getu64(t, &i.counter) < 0 ||
                !pa_tagstruct_eof(t)) {
         pa_context_fail(o->context, PA_ERROR_PROTOCOL);
         goto finish;
-    } else
-        p = &i;
-
-    gettimeofday(&now, NULL);
-
-    if (pa_timeval_cmp(&local, &remote) < 0 && pa_timeval_cmp(&remote, &now)) {
-        /* local and remote seem to have synchronized clocks */
-
-        if (o->stream->direction == PA_STREAM_PLAYBACK)
-            i.transport_usec = pa_timeval_diff(&remote, &local);
-        else
-            i.transport_usec = pa_timeval_diff(&now, &remote);
-        
-        i.synchronized_clocks = 1;
-        i.timestamp = remote;
     } else {
-        /* clocks are not synchronized, let's estimate latency then */
-        i.transport_usec = pa_timeval_diff(&now, &local)/2;
-        i.synchronized_clocks = 0;
-        i.timestamp = local;
-        pa_timeval_add(&i.timestamp, i.transport_usec);
-    }
+        gettimeofday(&now, NULL);
+        
+        if (pa_timeval_cmp(&local, &remote) < 0 && pa_timeval_cmp(&remote, &now)) {
+            /* local and remote seem to have synchronized clocks */
+            
+            if (o->stream->direction == PA_STREAM_PLAYBACK)
+                i.transport_usec = pa_timeval_diff(&remote, &local);
+            else
+                i.transport_usec = pa_timeval_diff(&now, &remote);
+            
+            i.synchronized_clocks = 1;
+            i.timestamp = remote;
+        } else {
+            /* clocks are not synchronized, let's estimate latency then */
+            i.transport_usec = pa_timeval_diff(&now, &local)/2;
+            i.synchronized_clocks = 0;
+            i.timestamp = local;
+            pa_timeval_add(&i.timestamp, i.transport_usec);
+        }
+        
+        if (o->stream->interpolate) {
+            o->stream->ipol_timestamp = now;
+            o->stream->ipol_usec = pa_stream_get_time(o->stream, &i);
+        }
 
+        p = &i;
+    }
+    
     if (o->callback) {
         void (*cb)(struct pa_stream *s, const struct pa_latency_info *i, void *userdata) = o->callback;
         cb(o->stream, p, o->userdata);
@@ -383,7 +437,7 @@ finish:
     pa_operation_unref(o);
 }
 
-struct pa_operation* pa_stream_get_latency(struct pa_stream *s, void (*cb)(struct pa_stream *p, const struct pa_latency_info*i, void *userdata), void *userdata) {
+struct pa_operation* pa_stream_get_latency_info(struct pa_stream *s, void (*cb)(struct pa_stream *p, const struct pa_latency_info*i, void *userdata), void *userdata) {
     uint32_t tag;
     struct pa_operation *o;
     struct pa_tagstruct *t;
@@ -403,9 +457,10 @@ struct pa_operation* pa_stream_get_latency(struct pa_stream *s, void (*cb)(struc
 
     gettimeofday(&now, NULL);
     pa_tagstruct_put_timeval(t, &now);
+    pa_tagstruct_putu64(t, s->counter);
     
     pa_pstream_send_tagstruct(s->context->pstream, t);
-    pa_pdispatch_register_reply(s->context->pdispatch, tag, DEFAULT_TIMEOUT, stream_get_latency_callback, o);
+    pa_pdispatch_register_reply(s->context->pdispatch, tag, DEFAULT_TIMEOUT, stream_get_latency_info_callback, o);
 
     return pa_operation_ref(o);
 }
@@ -505,6 +560,13 @@ struct pa_operation* pa_stream_cork(struct pa_stream *s, int b, void (*cb) (stru
     uint32_t tag;
     assert(s && s->ref >= 1 && s->state == PA_STREAM_READY);
 
+    if (!s->corked && b)
+        s->ipol_usec = pa_stream_get_interpolated_time(s);
+    else if (s->corked && !b)
+        gettimeofday(&s->ipol_timestamp, NULL);
+
+    s->corked = b;
+    
     o = pa_operation_new(s->context, s);
     assert(o);
     o->callback = cb;
@@ -519,6 +581,8 @@ struct pa_operation* pa_stream_cork(struct pa_stream *s, int b, void (*cb) (stru
     pa_pstream_send_tagstruct(s->context->pstream, t);
     pa_pdispatch_register_reply(s->context->pdispatch, tag, DEFAULT_TIMEOUT, pa_stream_simple_ack_callback, o);
 
+    pa_operation_unref(pa_stream_get_latency_info(s, NULL, NULL));
+    
     return pa_operation_ref(o);
 }
 
@@ -543,15 +607,24 @@ struct pa_operation* pa_stream_send_simple_command(struct pa_stream *s, uint32_t
 }
 
 struct pa_operation* pa_stream_flush(struct pa_stream *s, void (*cb)(struct pa_stream *s, int success, void *userdata), void *userdata) {
-    return pa_stream_send_simple_command(s, s->direction == PA_STREAM_PLAYBACK ? PA_COMMAND_FLUSH_PLAYBACK_STREAM : PA_COMMAND_FLUSH_RECORD_STREAM, cb, userdata);
+    struct pa_operation *o;
+    o = pa_stream_send_simple_command(s, s->direction == PA_STREAM_PLAYBACK ? PA_COMMAND_FLUSH_PLAYBACK_STREAM : PA_COMMAND_FLUSH_RECORD_STREAM, cb, userdata);
+    pa_operation_unref(pa_stream_get_latency_info(s, NULL, NULL));
+    return o;
 }
 
 struct pa_operation* pa_stream_prebuf(struct pa_stream *s, void (*cb)(struct pa_stream *s, int success, void *userdata), void *userdata) {
-    return pa_stream_send_simple_command(s, PA_COMMAND_PREBUF_PLAYBACK_STREAM, cb, userdata);
+    struct pa_operation *o;
+    o = pa_stream_send_simple_command(s, PA_COMMAND_PREBUF_PLAYBACK_STREAM, cb, userdata);
+    pa_operation_unref(pa_stream_get_latency_info(s, NULL, NULL));
+    return o;
 }
 
 struct pa_operation* pa_stream_trigger(struct pa_stream *s, void (*cb)(struct pa_stream *s, int success, void *userdata), void *userdata) {
-    return pa_stream_send_simple_command(s, PA_COMMAND_TRIGGER_PLAYBACK_STREAM, cb, userdata);
+    struct pa_operation *o;
+    o = pa_stream_send_simple_command(s, PA_COMMAND_TRIGGER_PLAYBACK_STREAM, cb, userdata);
+    pa_operation_unref(pa_stream_get_latency_info(s, NULL, NULL));
+    return o;
 }
 
 struct pa_operation* pa_stream_set_name(struct pa_stream *s, const char *name, void(*cb)(struct pa_stream*c, int success,  void *userdata), void *userdata) {
@@ -582,12 +655,6 @@ uint64_t pa_stream_get_counter(struct pa_stream *s) {
     return s->counter;
 }
 
-void pa_stream_reset_counter(struct pa_stream *s) {
-    assert(s);
-    s->counter = 0;
-    s->previous_time = 0;
-}
-
 pa_usec_t pa_stream_get_time(struct pa_stream *s, const struct pa_latency_info *i) {
     pa_usec_t usec;
     assert(s);
@@ -620,27 +687,22 @@ pa_usec_t pa_stream_get_time(struct pa_stream *s, const struct pa_latency_info *
     return usec;
 }
 
-pa_usec_t pa_stream_get_total_latency(struct pa_stream *s, const struct pa_latency_info *i, int *negative) {
+pa_usec_t pa_stream_get_latency(struct pa_stream *s, const struct pa_latency_info *i, int *negative) {
+    pa_usec_t t, c;
     assert(s && i);
 
-    if (s->direction == PA_STREAM_PLAYBACK) {
+    t = pa_stream_get_time(s, i);
+    c = pa_bytes_to_usec(s->counter, &s->sample_spec);
+
+    if (t <= c) {
         if (negative)
-            *negative = 0;
-        
-        return i->transport_usec + i->buffer_usec + i->sink_usec;
-    } else if (s->direction == PA_STREAM_RECORD) {
-        pa_usec_t usec = i->source_usec + i->buffer_usec + i->transport_usec;
-
-        if (usec >= i->sink_usec) {
-            if (negative)
-                *negative = 0;
-            return usec - i->sink_usec;
-        } else {
-            if (negative)
-                *negative = 1;
+            *negative = 1;
 
-            return i->sink_usec - usec;
-        }
+        return c-t;
+    } else {
+        if (negative)
+            *negative = 0;
+        return t-c;
     }
 
     return 0;
@@ -650,3 +712,52 @@ const struct pa_sample_spec* pa_stream_get_sample_spec(struct pa_stream *s) {
     assert(s);
     return &s->sample_spec;
 }
+
+void pa_stream_trash_ipol(struct pa_stream *s) {
+    assert(s);
+
+    if (!s->interpolate)
+        return;
+
+    memset(&s->ipol_timestamp, 0, sizeof(s->ipol_timestamp));
+    s->ipol_usec = 0;
+}
+
+pa_usec_t pa_stream_get_interpolated_time(struct pa_stream *s) {
+    pa_usec_t usec;
+    assert(s && s->interpolate);
+
+    if (s->corked)
+        usec = s->ipol_usec;
+    else {
+        if (s->ipol_timestamp.tv_sec == 0)
+            usec = 0;
+        else
+            usec = s->ipol_usec + pa_timeval_age(&s->ipol_timestamp);
+    }
+    
+    if (usec < s->previous_time)
+        usec = s->previous_time;
+
+    s->previous_time = usec;
+    return usec;
+}
+
+pa_usec_t pa_stream_get_interpolated_latency(struct pa_stream *s, int *negative) {
+    pa_usec_t t, c;
+    assert(s && s->interpolate);
+
+    t = pa_stream_get_interpolated_time(s);
+    c = pa_bytes_to_usec(s->counter, &s->sample_spec);
+
+    if (t <= c) {
+        if (negative)
+            *negative = 1;
+
+        return c-t;
+    } else {
+        if (negative)
+            *negative = 0;
+        return t-c;
+    }
+}
index e095d7fa0dace3db63f4dc49e7862158be81ed2a..4ccc0c23814b7e18264fb6bf0accf431585a89ac 100644 (file)
@@ -102,7 +102,7 @@ size_t pa_stream_writable_size(struct pa_stream *p);
 struct pa_operation* pa_stream_drain(struct pa_stream *s, void (*cb) (struct pa_stream*s, int success, void *userdata), void *userdata);
 
 /** Get the playback latency of a stream */
-struct pa_operation* pa_stream_get_latency(struct pa_stream *p, void (*cb)(struct pa_stream *p, const struct pa_latency_info *i, void *userdata), void *userdata);
+struct pa_operation* pa_stream_get_latency_info(struct pa_stream *p, void (*cb)(struct pa_stream *p, const struct pa_latency_info *i, void *userdata), void *userdata);
 
 /** Set the callback function that is called whenever the state of the stream changes */
 void pa_stream_set_state_callback(struct pa_stream *s, void (*cb)(struct pa_stream *s, void *userdata), void *userdata);
@@ -138,9 +138,6 @@ struct pa_operation* pa_stream_set_name(struct pa_stream *s, const char *name, v
  * this yourself using pa_stream_reset_counter(). \since 0.6 */
 uint64_t pa_stream_get_counter(struct pa_stream *s);
 
-/** Reset the total byte count to 0. \since 0.6 */
-void pa_stream_reset_counter(struct pa_stream *s);
-
 /** Return the current playback/recording time. This is based on the
  * counter accessible with pa_stream_get_counter(). This function
  * requires a pa_latency_info structure as argument, which should be
@@ -152,7 +149,18 @@ pa_usec_t pa_stream_get_time(struct pa_stream *s, const struct pa_latency_info *
  * using pa_stream_get_latency(). In case the stream is a monitoring
  * stream the result can be negative, i.e. the captured samples are
  * not yet played. In this case *negative is set to 1. \since 0.6 */
-pa_usec_t pa_stream_get_total_latency(struct pa_stream *s, const struct pa_latency_info *i, int *negative);
+pa_usec_t pa_stream_get_latency(struct pa_stream *s, const struct pa_latency_info *i, int *negative);
+
+/** Return the interpolated playback/recording time. Requires the
+ *  PA_STREAM_INTERPOLATE_LATENCY bit set when creating the stream. In
+ *  contrast to pa_stream_get_latency() this function doesn't require
+ *  a whole roundtrip for response. \since 0.6 */
+pa_usec_t pa_stream_get_interpolated_time(struct pa_stream *s);
+
+/** Return the interpolated playback/recording latency. Requires the
+ * PA_STREAM_INTERPOLATE_LATENCY bit set when creating the
+ * stream. \since 0.6 */
+pa_usec_t pa_stream_get_interpolated_latency(struct pa_stream *s, int *negative);
 
 /** Return a pointer to the streams sample specification. \since 0.6 */
 const struct pa_sample_spec* pa_stream_get_sample_spec(struct pa_stream *s);
index 3b81641939133e08c666e513c05030e43e141245..31ab4ab8c548e85e4f499ed7b1df112956f70ba3 100644 (file)
@@ -875,11 +875,13 @@ static void command_get_playback_latency(struct pa_pdispatch *pd, uint32_t comma
     struct pa_tagstruct *reply;
     struct playback_stream *s;
     struct timeval tv, now;
+    uint64_t counter;
     uint32_t index;
     assert(c && t);
     
     if (pa_tagstruct_getu32(t, &index) < 0 ||
         pa_tagstruct_get_timeval(t, &tv) < 0 ||
+        pa_tagstruct_getu64(t, &counter) < 0 ||
         !pa_tagstruct_eof(t)) {
         protocol_error(c);
         return;
@@ -907,6 +909,7 @@ static void command_get_playback_latency(struct pa_pdispatch *pd, uint32_t comma
     pa_tagstruct_put_timeval(reply, &tv);
     gettimeofday(&now, NULL);
     pa_tagstruct_put_timeval(reply, &now);
+    pa_tagstruct_putu64(reply, counter);
     pa_pstream_send_tagstruct(c->pstream, reply);
 }
 
@@ -915,11 +918,13 @@ static void command_get_record_latency(struct pa_pdispatch *pd, uint32_t command
     struct pa_tagstruct *reply;
     struct record_stream *s;
     struct timeval tv, now;
+    uint64_t counter;
     uint32_t index;
     assert(c && t);
 
     if (pa_tagstruct_getu32(t, &index) < 0 ||
         pa_tagstruct_get_timeval(t, &tv) < 0 ||
+        pa_tagstruct_getu64(t, &counter) < 0 ||
         !pa_tagstruct_eof(t)) {
         protocol_error(c);
         return;
@@ -947,6 +952,7 @@ static void command_get_record_latency(struct pa_pdispatch *pd, uint32_t command
     pa_tagstruct_put_timeval(reply, &tv);
     gettimeofday(&now, NULL);
     pa_tagstruct_put_timeval(reply, &now);
+    pa_tagstruct_putu64(reply, counter);
     pa_pstream_send_tagstruct(c->pstream, reply);
 }
 
index 4ab0b5657c5c202fa8613edab5f8b9c5810a48d0..a02a50feccbc31034b4615cf28e9b64522e7e346 100644 (file)
@@ -68,10 +68,10 @@ struct pa_sample_spec {
     uint8_t channels;              /**< Audio channels. (1 for mono, 2 for stereo, ...) */
 };
 
-/** Type for usec specifications. May be either 32 or 64 bit, depending on the architecture */
+/** Type for usec specifications (unsigned). May be either 32 or 64 bit, depending on the architecture */
 typedef uint64_t pa_usec_t;
 
-/** Return the amount of bytes playback of a second of audio with the speicified sample type takes */
+/** Return the amount of bytes playback of a second of audio with the specified sample type takes */
 size_t pa_bytes_per_second(const struct pa_sample_spec *spec);
 
 /** Return the size of a frame with the specific sample type */
index bbebdab3470ddb7d531ab8dd6620a81dd5fba72d..b9ab55f0cefbce360517783c371afb61445d3ca4 100644 (file)
@@ -176,6 +176,15 @@ void pa_tagstruct_put_usec(struct pa_tagstruct*t, pa_usec_t u) {
     t->length += 9;
 }
 
+void pa_tagstruct_putu64(struct pa_tagstruct*t, uint64_t u) {
+    assert(t);
+    extend(t, 9);
+    t->data[t->length] = TAG_U64;
+    *((uint32_t*) (t->data+t->length+1)) = htonl((uint32_t) (u >> 32));
+    *((uint32_t*) (t->data+t->length+5)) = htonl((uint32_t) u);
+    t->length += 9;
+}
+
 int pa_tagstruct_gets(struct pa_tagstruct*t, const char **s) {
     int error = 0;
     size_t n;
@@ -332,3 +341,18 @@ int pa_tagstruct_get_usec(struct pa_tagstruct*t, pa_usec_t *u) {
     t->rindex +=9;
     return 0;
 }
+
+int pa_tagstruct_getu64(struct pa_tagstruct*t, uint64_t *u) {
+    assert(t && u);
+
+    if (t->rindex+9 > t->length)
+        return -1;
+
+    if (t->data[t->rindex] != TAG_U64)
+        return -1;
+
+    *u = (uint64_t) ntohl(*((uint32_t*) (t->data+t->rindex+1))) << 32;
+    *u |= (uint64_t) ntohl(*((uint32_t*) (t->data+t->rindex+5)));
+    t->rindex +=9;
+    return 0;
+}
index e50551c41490a0585acd82a8c356a5a9daa9bccf..b943345bb3f93a917ded73006a3b330de7e61e81 100644 (file)
@@ -36,8 +36,9 @@ void pa_tagstruct_free(struct pa_tagstruct*t);
 uint8_t* pa_tagstruct_free_data(struct pa_tagstruct*t, size_t *l);
 
 void pa_tagstruct_puts(struct pa_tagstruct*t, const char *s);
-void pa_tagstruct_putu32(struct pa_tagstruct*t, uint32_t i);
 void pa_tagstruct_putu8(struct pa_tagstruct*t, uint8_t c);
+void pa_tagstruct_putu32(struct pa_tagstruct*t, uint32_t i);
+void pa_tagstruct_putu64(struct pa_tagstruct*t, uint64_t i);
 void pa_tagstruct_put_sample_spec(struct pa_tagstruct *t, const struct pa_sample_spec *ss);
 void pa_tagstruct_put_arbitrary(struct pa_tagstruct*t, const void *p, size_t length);
 void pa_tagstruct_put_boolean(struct pa_tagstruct*t, int b);
@@ -45,8 +46,9 @@ void pa_tagstruct_put_timeval(struct pa_tagstruct*t, const struct timeval *tv);
 void pa_tagstruct_put_usec(struct pa_tagstruct*t, pa_usec_t u);
 
 int pa_tagstruct_gets(struct pa_tagstruct*t, const char **s);
-int pa_tagstruct_getu32(struct pa_tagstruct*t, uint32_t *i);
 int pa_tagstruct_getu8(struct pa_tagstruct*t, uint8_t *c);
+int pa_tagstruct_getu32(struct pa_tagstruct*t, uint32_t *i);
+int pa_tagstruct_getu64(struct pa_tagstruct*t, uint64_t *i);
 int pa_tagstruct_get_sample_spec(struct pa_tagstruct *t, struct pa_sample_spec *ss);
 int pa_tagstruct_get_arbitrary(struct pa_tagstruct *t, const void **p, size_t length);
 int pa_tagstruct_get_boolean(struct pa_tagstruct *t, int *b);
index 70ec120d338d51aa2cc3fa432147ad9fc2989534..9697a1ebe6e40a3c0f468491653892f7b72fe4f8 100644 (file)
@@ -266,7 +266,7 @@ int pa_timeval_cmp(const struct timeval *a, const struct timeval *b) {
     return 0;
 }
 
-pa_usec_t pa_age(const struct timeval *tv) {
+pa_usec_t pa_timeval_age(const struct timeval *tv) {
     struct timeval now;
     assert(tv);
     gettimeofday(&now, NULL);
index b0a1a0337d374116fa1980787a847ba468fde37a..c5ffa75536021956f1a0ae41c7a9d4a8e64c56e2 100644 (file)
@@ -49,7 +49,7 @@ char *pa_path_get_filename(const char *p);
 
 pa_usec_t pa_timeval_diff(const struct timeval *a, const struct timeval *b);
 int pa_timeval_cmp(const struct timeval *a, const struct timeval *b);
-pa_usec_t pa_age(const struct timeval *tv);
+pa_usec_t pa_timeval_age(const struct timeval *tv);
 void pa_timeval_add(struct timeval *tv, pa_usec_t v);
 
 void pa_raise_priority(void);