[polypaudio-commits] r976 - in /trunk: configure.ac src/polyp/internal.h src/polyp/stream.c src/polyp/stream.h src/polypcore/memblockq.c src/polypcore/memblockq.h src/polypcore/protocol-native.c src/utils/pacat.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Thu May 25 16:20:29 PDT 2006


Author: lennart
Date: Fri May 26 01:20:28 2006
New Revision: 976

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=976&root=polypaudio&view=rev
Log:
* add new API function pa_stream_get_buffer_attr().
* modify pacat.c to make use of that new API
* extend protocol to allow transfer of the necessary information
* update protocol version accordingly

Modified:
    trunk/configure.ac
    trunk/src/polyp/internal.h
    trunk/src/polyp/stream.c
    trunk/src/polyp/stream.h
    trunk/src/polypcore/memblockq.c
    trunk/src/polypcore/memblockq.h
    trunk/src/polypcore/protocol-native.c
    trunk/src/utils/pacat.c

Modified: trunk/configure.ac
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/configure.ac?rev=976&root=polypaudio&r1=975&r2=976&view=diff
==============================================================================
--- trunk/configure.ac (original)
+++ trunk/configure.ac Fri May 26 01:20:28 2006
@@ -34,7 +34,7 @@
 AC_SUBST(PACKAGE_URL, [http://0pointer.de/lennart/projects/polypaudio/])
 
 AC_SUBST(PA_API_VERSION, 9)
-AC_SUBST(PA_PROTOCOL_VERSION, 8)
+AC_SUBST(PA_PROTOCOL_VERSION, 9)
 
 AC_SUBST(LIBPOLYP_VERSION_INFO, [0:0:0])
 AC_SUBST(LIBPOLYPCORE_VERSION_INFO, [0:0:0])

Modified: trunk/src/polyp/internal.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polyp/internal.h?rev=976&root=polypaudio&r1=975&r2=976&view=diff
==============================================================================
--- trunk/src/polyp/internal.h (original)
+++ trunk/src/polyp/internal.h Fri May 26 01:20:28 2006
@@ -100,6 +100,7 @@
 
     char *name;
     pa_buffer_attr buffer_attr;
+    int buffer_attr_from_server;
     pa_sample_spec sample_spec;
     pa_channel_map channel_map;
     pa_stream_flags_t flags;

Modified: trunk/src/polyp/stream.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polyp/stream.c?rev=976&root=polypaudio&r1=975&r2=976&view=diff
==============================================================================
--- trunk/src/polyp/stream.c (original)
+++ trunk/src/polyp/stream.c Fri May 26 01:20:28 2006
@@ -84,6 +84,7 @@
     s->requested_bytes = 0;
     s->state = PA_STREAM_UNCONNECTED;
     memset(&s->buffer_attr, 0, sizeof(s->buffer_attr));
+    s->buffer_attr_from_server = 0;
 
     s->peek_memchunk.index = 0;
     s->peek_memchunk.length = 0;
@@ -401,10 +402,41 @@
 
     if (pa_tagstruct_getu32(t, &s->channel) < 0 ||
         ((s->direction != PA_STREAM_UPLOAD) && pa_tagstruct_getu32(t, &s->device_index) < 0) ||
-        ((s->direction != PA_STREAM_RECORD) && pa_tagstruct_getu32(t, &s->requested_bytes) < 0) ||
-        !pa_tagstruct_eof(t)) {
+        ((s->direction != PA_STREAM_RECORD) && pa_tagstruct_getu32(t, &s->requested_bytes) < 0)) {
         pa_context_fail(s->context, PA_ERR_PROTOCOL);
         goto finish;
+    }
+
+    if (!pa_tagstruct_eof(t)) {
+        
+        if (s->direction == PA_STREAM_PLAYBACK) {
+
+            /* This is a server 0.9.0 or later */
+            if (pa_tagstruct_getu32(t, &s->buffer_attr.maxlength) < 0 ||
+                pa_tagstruct_getu32(t, &s->buffer_attr.tlength) < 0 ||
+                pa_tagstruct_getu32(t, &s->buffer_attr.prebuf) < 0 ||
+                pa_tagstruct_getu32(t, &s->buffer_attr.minreq) < 0 ||
+                !pa_tagstruct_eof(t)) {
+                pa_context_fail(s->context, PA_ERR_PROTOCOL);
+                goto finish;
+            }
+
+            s->buffer_attr_from_server = 1;
+        } else if (s->direction == PA_STREAM_RECORD) {
+            
+            /* This is a server 0.9.0 or later */
+            if (pa_tagstruct_getu32(t, &s->buffer_attr.maxlength) < 0 ||
+                pa_tagstruct_getu32(t, &s->buffer_attr.fragsize) < 0 ||
+                !pa_tagstruct_eof(t)) {
+                pa_context_fail(s->context, PA_ERR_PROTOCOL);
+                goto finish;
+            }
+
+            s->buffer_attr_from_server = 1;
+        } else {
+            pa_context_fail(s->context, PA_ERR_PROTOCOL);
+            goto finish;
+        }
     }
 
     if (s->direction == PA_STREAM_RECORD) {
@@ -1336,3 +1368,14 @@
 
     return &s->channel_map;
 }
+
+const pa_buffer_attr* pa_stream_get_buffer_attr(pa_stream *s) {
+    assert(s);
+    assert(s->ref >= 1);
+
+    PA_CHECK_VALIDITY_RETURN_NULL(s->context, s->state == PA_STREAM_READY, PA_ERR_BADSTATE);
+    PA_CHECK_VALIDITY_RETURN_NULL(s->context, s->direction != PA_STREAM_UPLOAD, PA_ERR_BADSTATE);
+    PA_CHECK_VALIDITY_RETURN_NULL(s->context, s->buffer_attr_from_server, PA_ERR_NODATA);
+
+    return &s->buffer_attr;
+}

Modified: trunk/src/polyp/stream.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polyp/stream.h?rev=976&root=polypaudio&r1=975&r2=976&view=diff
==============================================================================
--- trunk/src/polyp/stream.h (original)
+++ trunk/src/polyp/stream.h Fri May 26 01:20:28 2006
@@ -439,6 +439,11 @@
 /** Return a pointer to the stream's channel map. \since 0.8 */
 const pa_channel_map* pa_stream_get_channel_map(pa_stream *s);
 
+/** Return the buffer metrics of the stream. Only valid after the
+ * stream has been connected successfuly and if the server is at least
+ * Polypaudio 0.9. \since 0.9.0 */
+const pa_buffer_attr* pa_stream_get_buffer_attr(pa_stream *s);
+
 PA_C_DECL_END
 
 #endif

Modified: trunk/src/polypcore/memblockq.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polypcore/memblockq.c?rev=976&root=polypaudio&r1=975&r2=976&view=diff
==============================================================================
--- trunk/src/polypcore/memblockq.c (original)
+++ trunk/src/polypcore/memblockq.c Fri May 26 01:20:28 2006
@@ -622,3 +622,15 @@
     if (bq->state == RUNNING && bq->prebuf > 0)
         bq->state = PREBUF;
 }
+
+size_t pa_memblockq_get_maxlength(pa_memblockq *bq) {
+    assert(bq);
+
+    return bq->maxlength;
+}
+
+size_t pa_memblockq_get_prebuf(pa_memblockq *bq) {
+    assert(bq);
+
+    return bq->prebuf;
+}

Modified: trunk/src/polypcore/memblockq.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polypcore/memblockq.h?rev=976&root=polypaudio&r1=975&r2=976&view=diff
==============================================================================
--- trunk/src/polypcore/memblockq.h (original)
+++ trunk/src/polypcore/memblockq.h Fri May 26 01:20:28 2006
@@ -131,4 +131,10 @@
 /* Force prebuf */
 void pa_memblockq_prebuf_force(pa_memblockq *bq);
 
+/* Return the maximum length of the queue in bytes */
+size_t pa_memblockq_get_maxlength(pa_memblockq *bq);
+
+/* Return the prebuffer length in bytes */
+size_t pa_memblockq_get_prebuf(pa_memblockq *bq);
+
 #endif

Modified: trunk/src/polypcore/protocol-native.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polypcore/protocol-native.c?rev=976&root=polypaudio&r1=975&r2=976&view=diff
==============================================================================
--- trunk/src/polypcore/protocol-native.c (original)
+++ trunk/src/polypcore/protocol-native.c Fri May 26 01:20:28 2006
@@ -755,6 +755,16 @@
     assert(s->sink_input);
     pa_tagstruct_putu32(reply, s->sink_input->index);
     pa_tagstruct_putu32(reply, s->requested_bytes = pa_memblockq_missing(s->memblockq));
+
+    if (c->version >= 9) {
+        /* Since 0.9 we support sending the buffer metrics back to the client */
+
+        pa_tagstruct_putu32(reply, (uint32_t) pa_memblockq_get_maxlength(s->memblockq));
+        pa_tagstruct_putu32(reply, (uint32_t) pa_memblockq_get_tlength(s->memblockq));
+        pa_tagstruct_putu32(reply, (uint32_t) pa_memblockq_get_prebuf(s->memblockq));
+        pa_tagstruct_putu32(reply, (uint32_t) pa_memblockq_get_minreq(s->memblockq));
+    }
+    
     pa_pstream_send_tagstruct(c->pstream, reply);
     request_bytes(s);
 }
@@ -852,6 +862,14 @@
     pa_tagstruct_putu32(reply, s->index);
     assert(s->source_output);
     pa_tagstruct_putu32(reply, s->source_output->index);
+
+    if (c->version >= 9) {
+        /* Since 0.9 we support sending the buffer metrics back to the client */
+
+        pa_tagstruct_putu32(reply, (uint32_t) pa_memblockq_get_maxlength(s->memblockq));
+        pa_tagstruct_putu32(reply, (uint32_t) s->fragment_size);
+    }
+    
     pa_pstream_send_tagstruct(c->pstream, reply);
 }
 
@@ -2215,7 +2233,8 @@
         c->auth_timeout_event = p->core->mainloop->time_new(p->core->mainloop, &tv, auth_timeout, c);
     } else
         c->auth_timeout_event = NULL;
-    
+
+    c->version = 8;
     c->protocol = p;
     assert(p->core);
     c->client = pa_client_new(p->core, __FILE__, "Client");

Modified: trunk/src/utils/pacat.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/utils/pacat.c?rev=976&root=polypaudio&r1=975&r2=976&view=diff
==============================================================================
--- trunk/src/utils/pacat.c (original)
+++ trunk/src/utils/pacat.c Fri May 26 01:20:28 2006
@@ -154,8 +154,26 @@
             break;
 
         case PA_STREAM_READY:
-            if (verbose)
+            if (verbose) {
+                pa_buffer_attr *a;
+                
                 fprintf(stderr, "Stream successfully created.\n");
+
+                if (!(a = pa_stream_get_buffer_attr(s)))
+                    fprintf(stderr, "pa_stream_get_buffer_attr() failed: %s\n", pa_strerror(pa_context_errno(pa_stream_get_context(s))));
+                else {
+
+                    if (mode == PLAYBACK)
+                        fprintf(stderr, "Buffer metrics: maxlength=%u, tlength=%u, prebuf=%u, minreq=%u\n", a->maxlength, a->tlength, a->prebuf, a->minreq);
+                    else {
+                        assert(mode == RECORD);
+                        fprintf(stderr, "Buffer metrics: maxlength=%u, fragsize=%u\n", a->maxlength, a->fragsize);
+                    }
+                    
+                }
+
+            }
+            
             break;
             
         case PA_STREAM_FAILED:




More information about the pulseaudio-commits mailing list