protocol changes for new latency API (partial!)
authorLennart Poettering <lennart@poettering.net>
Thu, 2 Mar 2006 14:22:25 +0000 (14:22 +0000)
committerLennart Poettering <lennart@poettering.net>
Thu, 2 Mar 2006 14:22:25 +0000 (14:22 +0000)
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@616 fefdeb5f-60dc-0310-8127-8f9354f1896f

src/polypcore/memblockq.c
src/polypcore/protocol-native.c
src/polypcore/tagstruct.c
src/polypcore/tagstruct.h

index 38403ec..517495e 100644 (file)
@@ -547,7 +547,6 @@ void pa_memblockq_flush(pa_memblockq *bq) {
         drop_block(bq, bq->blocks);
 
     assert(bq->n_blocks == 0);
-    bq->write_index = bq->read_index;
 
     pa_memblockq_prebuf_force(bq);
 }
index 20ba513..76761b7 100644 (file)
@@ -1031,13 +1031,11 @@ static void command_get_playback_latency(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_
     pa_tagstruct *reply;
     struct playback_stream *s;
     struct timeval tv, now;
-    uint64_t counter;
     uint32_t idx;
     assert(c && t);
     
     if (pa_tagstruct_getu32(t, &idx) < 0 ||
         pa_tagstruct_get_timeval(t, &tv) < 0 ||
-        pa_tagstruct_getu64(t, &counter) < 0 ||
         !pa_tagstruct_eof(t)) {
         protocol_error(c);
         return;
@@ -1057,7 +1055,8 @@ static void command_get_playback_latency(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_
     pa_tagstruct_put_timeval(reply, &tv);
     pa_gettimeofday(&now);
     pa_tagstruct_put_timeval(reply, &now);
-    pa_tagstruct_putu64(reply, counter);
+    pa_tagstruct_puts64(reply, pa_memblockq_get_write_index(s->memblockq));
+    pa_tagstruct_puts64(reply, pa_memblockq_get_read_index(s->memblockq));
     pa_pstream_send_tagstruct(c->pstream, reply);
 }
 
@@ -1066,13 +1065,11 @@ static void command_get_record_latency(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UN
     pa_tagstruct *reply;
     struct record_stream *s;
     struct timeval tv, now;
-    uint64_t counter;
     uint32_t idx;
     assert(c && t);
 
     if (pa_tagstruct_getu32(t, &idx) < 0 ||
         pa_tagstruct_get_timeval(t, &tv) < 0 ||
-        pa_tagstruct_getu64(t, &counter) < 0 ||
         !pa_tagstruct_eof(t)) {
         protocol_error(c);
         return;
@@ -1091,7 +1088,8 @@ static void command_get_record_latency(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UN
     pa_tagstruct_put_timeval(reply, &tv);
     pa_gettimeofday(&now);
     pa_tagstruct_put_timeval(reply, &now);
-    pa_tagstruct_putu64(reply, counter);
+    pa_tagstruct_puts64(reply, pa_memblockq_get_write_index(s->memblockq));
+    pa_tagstruct_puts64(reply, pa_memblockq_get_read_index(s->memblockq));
     pa_pstream_send_tagstruct(c->pstream, reply);
 }
 
index 1f5f370..3035626 100644 (file)
@@ -189,6 +189,18 @@ void pa_tagstruct_putu64(pa_tagstruct*t, uint64_t u) {
     t->length += 9;
 }
 
+void pa_tagstruct_puts64(pa_tagstruct*t, int64_t u) {
+    uint32_t tmp;
+    assert(t);
+    extend(t, 9);
+    t->data[t->length] = PA_TAG_S64;
+    tmp = htonl((uint32_t) ((uint64_t) u >> 32));
+    memcpy(t->data+t->length+1, &tmp, 4);
+    tmp = htonl((uint32_t) ((uint64_t) u));
+    memcpy(t->data+t->length+5, &tmp, 4);
+    t->length += 9;
+}
+
 void pa_tagstruct_put_channel_map(pa_tagstruct *t, const pa_channel_map *map) {
     unsigned i;
     
@@ -399,9 +411,27 @@ int pa_tagstruct_getu64(pa_tagstruct*t, uint64_t *u) {
         return -1;
 
     memcpy(&tmp, t->data+t->rindex+1, 4);
-    *u = (pa_usec_t) ntohl(tmp) << 32;
+    *u = (uint64_t) ntohl(tmp) << 32;
     memcpy(&tmp, t->data+t->rindex+5, 4);
-    *u |= (pa_usec_t) ntohl(tmp);
+    *u |= (uin64_t) ntohl(tmp);
+    t->rindex +=9;
+    return 0;
+}
+
+int pa_tagstruct_gets64(pa_tagstruct*t, int64_t *u) {
+    uint32_t tmp;
+    assert(t && u);
+
+    if (t->rindex+9 > t->length)
+        return -1;
+
+    if (t->data[t->rindex] != PA_TAG_S64)
+        return -1;
+
+    memcpy(&tmp, t->data+t->rindex+1, 4);
+    *u = (int64_t) ((uint64_t) ntohl(tmp) << 32);
+    memcpy(&tmp, t->data+t->rindex+5, 4);
+    *u |= (int64_t) ntohl(tmp);
     t->rindex +=9;
     return 0;
 }
index 0ed7517..d5e6050 100644 (file)
@@ -40,6 +40,7 @@ enum {
     PA_TAG_U32 = 'L',
     PA_TAG_U8 = 'B',
     PA_TAG_U64 = 'R',
+    PA_TAG_S64 = 'r',
     PA_TAG_SAMPLE_SPEC = 'a',
     PA_TAG_ARBITRARY = 'x',
     PA_TAG_BOOLEAN_TRUE = '1',
@@ -64,6 +65,7 @@ void pa_tagstruct_puts(pa_tagstruct*t, const char *s);
 void pa_tagstruct_putu8(pa_tagstruct*t, uint8_t c);
 void pa_tagstruct_putu32(pa_tagstruct*t, uint32_t i);
 void pa_tagstruct_putu64(pa_tagstruct*t, uint64_t i);
+void pa_tagstruct_puts64(pa_tagstruct*t, int64_t i);
 void pa_tagstruct_put_sample_spec(pa_tagstruct *t, const pa_sample_spec *ss);
 void pa_tagstruct_put_arbitrary(pa_tagstruct*t, const void *p, size_t length);
 void pa_tagstruct_put_boolean(pa_tagstruct*t, int b);
@@ -78,6 +80,7 @@ int pa_tagstruct_gets(pa_tagstruct*t, const char **s);
 int pa_tagstruct_getu8(pa_tagstruct*t, uint8_t *c);
 int pa_tagstruct_getu32(pa_tagstruct*t, uint32_t *i);
 int pa_tagstruct_getu64(pa_tagstruct*t, uint64_t *i);
+int pa_tagstruct_gets64(pa_tagstruct*t, int64_t *i);
 int pa_tagstruct_get_sample_spec(pa_tagstruct *t, pa_sample_spec *ss);
 int pa_tagstruct_get_arbitrary(pa_tagstruct *t, const void **p, size_t length);
 int pa_tagstruct_get_boolean(pa_tagstruct *t, int *b);