[polypaudio-commits] r507 - in /trunk/src: Makefile.am polyp/context.c polyp/internal.h polyp/stream.c polyp/stream.h utils/pacat.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Fri Feb 17 07:42:48 PST 2006


Author: ossman
Date: Fri Feb 17 16:42:47 2006
New Revision: 507

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=507&root=polypaudio&view=rev
Log:
Have a memblock queue on the client side during recording. This makes the
record callback optional in stead of mandatory.

For applications that wish to retain the old behaviour, simply call
pa_stream_peek() followed by pa_stream_drop() in the callback.

Modified:
    trunk/src/Makefile.am
    trunk/src/polyp/context.c
    trunk/src/polyp/internal.h
    trunk/src/polyp/stream.c
    trunk/src/polyp/stream.h
    trunk/src/utils/pacat.c

Modified: trunk/src/Makefile.am
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/Makefile.am?rev=507&root=polypaudio&r1=506&r2=507&view=diff
==============================================================================
--- trunk/src/Makefile.am (original)
+++ trunk/src/Makefile.am Fri Feb 17 16:42:47 2006
@@ -330,6 +330,7 @@
 		polypcore/log.c polypcore/log.h \
 		polypcore/mcalign.c polypcore/mcalign.h \
 		polypcore/memblock.c polypcore/memblock.h \
+		polypcore/memblockq.c polypcore/memblockq.h \
 		polypcore/memchunk.c polypcore/memchunk.h \
 		polypcore/native-common.h \
 		polypcore/packet.c polypcore/packet.h \

Modified: trunk/src/polyp/context.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polyp/context.c?rev=507&root=polypaudio&r1=506&r2=507&view=diff
==============================================================================
--- trunk/src/polyp/context.c (original)
+++ trunk/src/polyp/context.c Fri Feb 17 16:42:47 2006
@@ -273,11 +273,11 @@
 
             if (pa_mcalign_pop(s->mcalign, &t) < 0)
                 break;
-        
-            if (s->read_callback) {
-                s->read_callback(s, (uint8_t*) t.memblock->data + t.index, t.length, s->read_userdata);
-                s->counter += chunk->length;
-            }
+
+            assert(s->record_memblockq);
+            pa_memblockq_push(s->record_memblockq, &t, t.length);
+            if (s->read_callback)
+                s->read_callback(s, pa_stream_readable_size(s), s->read_userdata);
 
             pa_memblock_unref(t.memblock);
         }

Modified: trunk/src/polyp/internal.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polyp/internal.h?rev=507&root=polypaudio&r1=506&r2=507&view=diff
==============================================================================
--- trunk/src/polyp/internal.h (original)
+++ trunk/src/polyp/internal.h Fri Feb 17 16:42:47 2006
@@ -35,6 +35,7 @@
 #include <polypcore/native-common.h>
 #include <polypcore/strlist.h>
 #include <polypcore/mcalign.h>
+#include <polypcore/memblockq.h>
 
 #include "client-conf.h"
 
@@ -98,6 +99,8 @@
     pa_usec_t previous_ipol_time;
     pa_stream_state_t state;
     pa_mcalign *mcalign;
+    pa_memchunk peek_memchunk;
+    pa_memblockq *record_memblockq;
 
     int interpolate;
     int corked;
@@ -110,7 +113,7 @@
     void (*state_callback)(pa_stream*c, void *userdata);
     void *state_userdata;
 
-    void (*read_callback)(pa_stream *p, const void*data, size_t length, void *userdata);
+    void (*read_callback)(pa_stream *p, size_t length, void *userdata);
     void *read_userdata;
 
     void (*write_callback)(pa_stream *p, size_t length, void *userdata);

Modified: trunk/src/polyp/stream.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polyp/stream.c?rev=507&root=polypaudio&r1=506&r2=507&view=diff
==============================================================================
--- trunk/src/polyp/stream.c (original)
+++ trunk/src/polyp/stream.c Fri Feb 17 16:42:47 2006
@@ -103,6 +103,12 @@
         s->mainloop->time_free(s->ipol_event);
     }
 
+    if (s->peek_memchunk.memblock)
+        pa_memblock_unref(s->peek_memchunk.memblock);
+
+    if (s->record_memblockq)
+        pa_memblockq_free(s->record_memblockq);
+
     pa_mcalign_free(s->mcalign);
     
     pa_xfree(s->name);
@@ -261,6 +267,13 @@
         !pa_tagstruct_eof(t)) {
         pa_context_fail(s->context, PA_ERROR_PROTOCOL);
         goto finish;
+    }
+
+    if (s->direction == PA_STREAM_RECORD) {
+        assert(!s->record_memblockq);
+        s->record_memblockq = pa_memblockq_new(s->buffer_attr.maxlength, 0,
+            pa_frame_size(&s->sample_spec), 0, 0, s->context->memblock_stat);
+        assert(s->record_memblockq);
     }
 
     s->channel_valid = 1;
@@ -391,9 +404,55 @@
     s->counter += length;
 }
 
+void pa_stream_peek(pa_stream *s, void **data, size_t *length) {
+    assert(s && s->record_memblockq && data && length && s->state == PA_STREAM_READY && s->ref >= 1);
+
+    if (!s->peek_memchunk.memblock) {
+        *data = NULL;
+        *length = 0;
+
+        if (pa_memblockq_peek(s->record_memblockq, &s->peek_memchunk) < 0)
+            return;
+
+        pa_memblockq_drop(s->record_memblockq, &s->peek_memchunk, s->peek_memchunk.length);
+    }
+
+    *data = (char*)s->peek_memchunk.memblock->data + s->peek_memchunk.index;
+    *length = s->peek_memchunk.length;
+}
+
+void pa_stream_drop(pa_stream *s) {
+    assert(s && s->peek_memchunk.memblock && s->state == PA_STREAM_READY && s->ref >= 1);
+
+    s->counter += s->peek_memchunk.length;
+
+    pa_memblock_unref(s->peek_memchunk.memblock);
+
+    s->peek_memchunk.length = 0;
+    s->peek_memchunk.memblock = NULL;
+}
+
 size_t pa_stream_writable_size(pa_stream *s) {
     assert(s && s->ref >= 1);
     return s->state == PA_STREAM_READY ? s->requested_bytes : 0;
+}
+
+size_t pa_stream_readable_size(pa_stream *s) {
+    size_t sz;
+
+    assert(s && s->ref >= 1);
+
+    if (s->state != PA_STREAM_READY)
+        return 0;
+
+    assert(s->record_memblockq);
+
+    sz = (size_t)pa_memblockq_get_length(s->record_memblockq);
+
+    if (s->peek_memchunk.memblock)
+        sz += s->peek_memchunk.length;
+
+    return sz;
 }
 
 pa_operation * pa_stream_drain(pa_stream *s, void (*cb) (pa_stream*s, int success, void *userdata), void *userdata) {
@@ -554,7 +613,7 @@
     pa_stream_unref(s);
 }
 
-void pa_stream_set_read_callback(pa_stream *s, void (*cb)(pa_stream *p, const void*data, size_t length, void *userdata), void *userdata) {
+void pa_stream_set_read_callback(pa_stream *s, void (*cb)(pa_stream *p, size_t length, void *userdata), void *userdata) {
     assert(s && s->ref >= 1);
     s->read_callback = cb;
     s->read_userdata = userdata;

Modified: trunk/src/polyp/stream.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polyp/stream.h?rev=507&root=polypaudio&r1=506&r2=507&view=diff
==============================================================================
--- trunk/src/polyp/stream.h (original)
+++ trunk/src/polyp/stream.h Fri Feb 17 16:42:47 2006
@@ -106,8 +106,24 @@
                                                  value is ignored on
                                                  upload streams. */);
 
+/** Read the next fragment from the buffer (for capture sources).
+ * data will point to the actual data and length will contain the size
+ * of the data in bytes (which can be less than a complete framgnet).
+ * Use pa_stream_drop() to actually remove the data from the buffer.
+ * \since 0.8 */ 
+void pa_stream_peek(pa_stream *p                 /**< The stream to use */,
+                     void **data                 /**< Pointer to pointer that will point to data */,
+                     size_t *length              /**< The length of the data read */);
+
+/** Remove the current fragment. It is invalid to do this without first
+ * calling pa_stream_peek(). \since 0.8 */
+void pa_stream_drop(pa_stream *p);
+
 /** Return the amount of bytes that may be written using pa_stream_write() */
 size_t pa_stream_writable_size(pa_stream *p);
+
+/** Return the ammount of bytes that may be read using pa_stream_read() \since 0.8 */
+size_t pa_stream_readable_size(pa_stream *p);
 
 /** Drain a playback stream */
 pa_operation* pa_stream_drain(pa_stream *s, void (*cb) (pa_stream*s, int success, void *userdata), void *userdata);
@@ -122,8 +138,10 @@
  * written to the stream. */
 void pa_stream_set_write_callback(pa_stream *p, void (*cb)(pa_stream *p, size_t length, void *userdata), void *userdata);
 
-/** Set the callback function that is called when new data is available from the stream */
-void pa_stream_set_read_callback(pa_stream *p, void (*cb)(pa_stream *p, const void*data, size_t length, void *userdata), void *userdata);
+/** Set the callback function that is called when new data is available from the stream.
+ * Return the number of bytes read. \since 0.8
+ */
+void pa_stream_set_read_callback(pa_stream *p, void (*cb)(pa_stream *p, size_t length, void *userdata), void *userdata);
 
 /** Pause (or resume) playback of this stream temporarily. Available on both playback and recording streams. \since 0.3 */
 pa_operation* pa_stream_cork(pa_stream *s, int b, void (*cb) (pa_stream*s, int success, void *userdata), void *userdata);

Modified: trunk/src/utils/pacat.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/utils/pacat.c?rev=507&root=polypaudio&r1=506&r2=507&view=diff
==============================================================================
--- trunk/src/utils/pacat.c (original)
+++ trunk/src/utils/pacat.c Fri Feb 17 16:42:47 2006
@@ -105,14 +105,19 @@
 }
 
 /* This is called whenever new data may is available */
-static void stream_read_callback(pa_stream *s, const void*data, size_t length, void *userdata) {
-    assert(s && data && length);
+static void stream_read_callback(pa_stream *s, size_t length, void *userdata) {
+    assert(s && length);
+    void *data;
 
     if (stdio_event)
         mainloop_api->io_enable(stdio_event, PA_IO_EVENT_OUTPUT);
 
+    pa_stream_peek(s, &data, &length);
+    assert(data && length);
+
     if (buffer) {
         fprintf(stderr, "Buffer overrun, dropping incoming data\n");
+        pa_stream_drop(s);
         return;
     }
 
@@ -120,6 +125,7 @@
     assert(buffer);
     memcpy(buffer, data, length);
     buffer_index = 0;
+    pa_stream_drop(s);
 }
 
 /* This routine is called whenever the stream state changes */




More information about the pulseaudio-commits mailing list