[pulseaudio-commits] 2 commits - src/modules

Tanu Kaskinen tanuk at kemper.freedesktop.org
Thu Jul 17 03:01:23 PDT 2014


 src/modules/module-tunnel-sink-new.c   |   94 +++++++++++++++++++++------------
 src/modules/module-tunnel-source-new.c |   35 +++++++++++-
 2 files changed, 94 insertions(+), 35 deletions(-)

New commits:
commit c187441ff9cc068dbc1bbf41c7a8ef70d6199f0b
Author: Alexander Couzens <lynxis at fe80.eu>
Date:   Mon Nov 25 19:44:14 2013 +0100

    tunnel-new: remove uncorking in thread_func. Now handled by state change callback.
    
    tunnel-new handled a corked stream conditional in the thread_func to be
    sure the stream isn't corked. Un/Corking is now handled in the
    state change callback.
    
    Signed-off-by: Alexander Couzens <lynxis at fe80.eu>

diff --git a/src/modules/module-tunnel-sink-new.c b/src/modules/module-tunnel-sink-new.c
index 75dd19f..c74a7c1 100644
--- a/src/modules/module-tunnel-sink-new.c
+++ b/src/modules/module-tunnel-sink-new.c
@@ -181,39 +181,34 @@ static void thread_func(void *userdata) {
         if (u->connected &&
                 pa_stream_get_state(u->stream) == PA_STREAM_READY &&
                 PA_SINK_IS_LINKED(u->sink->thread_info.state)) {
-            /* TODO: Cork the stream when the sink is suspended. */
-
-            if (pa_stream_is_corked(u->stream)) {
-                cork_stream(u, false);
-            } else {
-                size_t writable;
-
-                writable = pa_stream_writable_size(u->stream);
-                if (writable > 0) {
-                    pa_memchunk memchunk;
-                    const void *p;
-
-                    pa_sink_render_full(u->sink, writable, &memchunk);
-
-                    pa_assert(memchunk.length > 0);
-
-                    /* we have new data to write */
-                    p = pa_memblock_acquire(memchunk.memblock);
-                    /* TODO: Use pa_stream_begin_write() to reduce copying. */
-                    ret = pa_stream_write(u->stream,
-                                          (uint8_t*) p + memchunk.index,
-                                          memchunk.length,
-                                          NULL,     /**< A cleanup routine for the data or NULL to request an internal copy */
-                                          0,        /** offset */
-                                          PA_SEEK_RELATIVE);
-                    pa_memblock_release(memchunk.memblock);
-                    pa_memblock_unref(memchunk.memblock);
-
-                    if (ret != 0) {
-                        pa_log_error("Could not write data into the stream ... ret = %i", ret);
-                        u->thread_mainloop_api->quit(u->thread_mainloop_api, TUNNEL_THREAD_FAILED_MAINLOOP);
-                    }
+            size_t writable;
+
+            writable = pa_stream_writable_size(u->stream);
+            if (writable > 0) {
+                pa_memchunk memchunk;
+                const void *p;
+
+                pa_sink_render_full(u->sink, writable, &memchunk);
+
+                pa_assert(memchunk.length > 0);
+
+                /* we have new data to write */
+                p = pa_memblock_acquire(memchunk.memblock);
+                /* TODO: Use pa_stream_begin_write() to reduce copying. */
+                ret = pa_stream_write(u->stream,
+                                      (uint8_t*) p + memchunk.index,
+                                      memchunk.length,
+                                      NULL,     /**< A cleanup routine for the data or NULL to request an internal copy */
+                                      0,        /** offset */
+                                      PA_SEEK_RELATIVE);
+                pa_memblock_release(memchunk.memblock);
+                pa_memblock_unref(memchunk.memblock);
+
+                if (ret != 0) {
+                    pa_log_error("Could not write data into the stream ... ret = %i", ret);
+                    u->thread_mainloop_api->quit(u->thread_mainloop_api, TUNNEL_THREAD_FAILED_MAINLOOP);
                 }
+
             }
         }
     }

commit 5170df86b37438cd88c7d11361825d4a74058fd6
Author: Alexander Couzens <lynxis at fe80.eu>
Date:   Mon Nov 25 19:42:51 2013 +0100

    tunnel-new: add un/corking to the state change callback
    
    The stream is now corked when the sink or source becomes suspended and
    uncorked when it's back idle/ready.
    
    Signed-off-by: Alexander Couzens <lynxis at fe80.eu>

diff --git a/src/modules/module-tunnel-sink-new.c b/src/modules/module-tunnel-sink-new.c
index 484e538..75dd19f 100644
--- a/src/modules/module-tunnel-sink-new.c
+++ b/src/modules/module-tunnel-sink-new.c
@@ -102,6 +102,16 @@ static const char* const valid_modargs[] = {
     NULL,
 };
 
+static void cork_stream(struct userdata *u, bool cork) {
+    pa_operation *operation;
+
+    pa_assert(u);
+    pa_assert(u->stream);
+
+    if ((operation = pa_stream_cork(u->stream, cork, NULL, NULL)))
+        pa_operation_unref(operation);
+}
+
 static void reset_bufferattr(pa_buffer_attr *bufferattr) {
     pa_assert(bufferattr);
     bufferattr->fragsize = (uint32_t) -1;
@@ -174,9 +184,7 @@ static void thread_func(void *userdata) {
             /* TODO: Cork the stream when the sink is suspended. */
 
             if (pa_stream_is_corked(u->stream)) {
-                pa_operation *operation;
-                if ((operation = pa_stream_cork(u->stream, 0, NULL, NULL)))
-                    pa_operation_unref(operation);
+                cork_stream(u, false);
             } else {
                 size_t writable;
 
@@ -244,6 +252,9 @@ static void stream_state_cb(pa_stream *stream, void *userdata) {
             pa_log_debug("Stream terminated.");
             break;
         case PA_STREAM_READY:
+            if (PA_SINK_IS_OPENED(u->sink->thread_info.state))
+                cork_stream(u, false);
+
             /* Only call our requested_latency_cb when requested_latency
              * changed between PA_STREAM_CREATING -> PA_STREAM_READY, because
              * we don't want to override the initial tlength set by the server
@@ -415,6 +426,26 @@ static int sink_process_msg_cb(pa_msgobject *o, int code, void *data, int64_t of
             *((pa_usec_t*) data) = remote_latency;
             return 0;
         }
+        case PA_SINK_MESSAGE_SET_STATE:
+            if (!u->stream || pa_stream_get_state(u->stream) != PA_STREAM_READY)
+                break;
+
+            switch ((pa_sink_state_t) PA_PTR_TO_UINT(data)) {
+                case PA_SINK_SUSPENDED: {
+                    cork_stream(u, true);
+                    break;
+                }
+                case PA_SINK_IDLE:
+                case PA_SINK_RUNNING: {
+                    cork_stream(u, false);
+                    break;
+                }
+                case PA_SINK_INVALID_STATE:
+                case PA_SINK_INIT:
+                case PA_SINK_UNLINKED:
+                    break;
+            }
+            break;
     }
     return pa_sink_process_msg(o, code, data, offset, chunk);
 }
diff --git a/src/modules/module-tunnel-source-new.c b/src/modules/module-tunnel-source-new.c
index aacb723..c6580eb 100644
--- a/src/modules/module-tunnel-source-new.c
+++ b/src/modules/module-tunnel-source-new.c
@@ -101,6 +101,16 @@ static const char* const valid_modargs[] = {
     NULL,
 };
 
+static void cork_stream(struct userdata *u, bool cork) {
+    pa_operation *operation;
+
+    pa_assert(u);
+    pa_assert(u->stream);
+
+    if ((operation = pa_stream_cork(u->stream, cork, NULL, NULL)))
+        pa_operation_unref(operation);
+}
+
 static void reset_bufferattr(pa_buffer_attr *bufferattr) {
     pa_assert(bufferattr);
     bufferattr->fragsize = (uint32_t) -1;
@@ -262,6 +272,9 @@ static void stream_state_cb(pa_stream *stream, void *userdata) {
             pa_log_debug("Stream terminated.");
             break;
         case PA_STREAM_READY:
+            if (PA_SOURCE_IS_OPENED(u->source->thread_info.state))
+                cork_stream(u, false);
+
             /* Only call our requested_latency_cb when requested_latency
              * changed between PA_STREAM_CREATING -> PA_STREAM_READY, because
              * we don't want to override the initial fragsize set by the server
@@ -325,7 +338,7 @@ static void context_state_cb(pa_context *c, void *userdata) {
             if (pa_stream_connect_record(u->stream,
                                          u->remote_source_name,
                                          &bufferattr,
-                                         PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_DONT_MOVE|PA_STREAM_AUTO_TIMING_UPDATE) < 0) {
+                                         PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_DONT_MOVE|PA_STREAM_AUTO_TIMING_UPDATE|PA_STREAM_START_CORKED) < 0) {
                 pa_log_debug("Could not create stream: %s", pa_strerror(pa_context_errno(u->context)));
                 u->thread_mainloop_api->quit(u->thread_mainloop_api, TUNNEL_THREAD_FAILED_MAINLOOP);
             }
@@ -417,6 +430,26 @@ static int source_process_msg_cb(pa_msgobject *o, int code, void *data, int64_t
 
             return 0;
         }
+        case PA_SOURCE_MESSAGE_SET_STATE:
+            if (!u->stream || pa_stream_get_state(u->stream) != PA_STREAM_READY)
+                break;
+
+            switch ((pa_source_state_t) PA_PTR_TO_UINT(data)) {
+                case PA_SOURCE_SUSPENDED: {
+                    cork_stream(u, true);
+                    break;
+                }
+                case PA_SOURCE_IDLE:
+                case PA_SOURCE_RUNNING: {
+                    cork_stream(u, false);
+                    break;
+                }
+                case PA_SOURCE_INVALID_STATE:
+                case PA_SOURCE_INIT:
+                case PA_SOURCE_UNLINKED:
+                    break;
+            }
+            break;
     }
     return pa_source_process_msg(o, code, data, offset, chunk);
 }



More information about the pulseaudio-commits mailing list