]> code.delx.au - pulseaudio/blobdiff - src/modules/module-tunnel-source-new.c
tunnel-source-new: Fix shadow compiler warning
[pulseaudio] / src / modules / module-tunnel-source-new.c
index 8169b07f71b8a83615dc0d29ae807f14d13da65c..aacb7232788cf0ccbba53df77ca4e34b4298ce0f 100644 (file)
@@ -56,7 +56,8 @@ PA_MODULE_USAGE(
         "format=<sample format> "
         "channels=<number of channels> "
         "rate=<sample rate> "
-        "channel_map=<channel map>"
+        "channel_map=<channel map> "
+        "cookie=<cookie file path>"
         );
 
 #define TUNNEL_THREAD_FAILED_MAINLOOP 1
@@ -81,6 +82,7 @@ struct userdata {
     bool connected;
     bool new_data;
 
+    char *cookie_file;
     char *remote_server;
     char *remote_source_name;
 };
@@ -94,7 +96,7 @@ static const char* const valid_modargs[] = {
     "channels",
     "rate",
     "channel_map",
-   /* "cookie", unimplemented */
+    "cookie",
    /* "reconnect", reconnect if server comes back again - unimplemented */
     NULL,
 };
@@ -140,8 +142,8 @@ static void read_new_samples(struct userdata *u) {
 
     readable = pa_stream_readable_size(u->stream);
     while (readable > 0) {
-        size_t read = 0;
-        if (PA_UNLIKELY(pa_stream_peek(u->stream, &p, &read) != 0)) {
+        size_t nbytes = 0;
+        if (PA_UNLIKELY(pa_stream_peek(u->stream, &p, &nbytes) != 0)) {
             pa_log("pa_stream_peek() failed: %s", pa_strerror(pa_context_errno(u->context)));
             u->thread_mainloop_api->quit(u->thread_mainloop_api, TUNNEL_THREAD_FAILED_MAINLOOP);
             return;
@@ -149,14 +151,14 @@ static void read_new_samples(struct userdata *u) {
 
         if (PA_LIKELY(p)) {
             /* we have valid data */
-            memchunk.memblock = pa_memblock_new_fixed(u->module->core->mempool, (void *) p, read, true);
-            memchunk.length = read;
+            memchunk.memblock = pa_memblock_new_fixed(u->module->core->mempool, (void *) p, nbytes, true);
+            memchunk.length = nbytes;
             memchunk.index = 0;
 
             pa_source_post(u->source, &memchunk);
             pa_memblock_unref_fixed(memchunk.memblock);
         } else {
-            size_t bytes_to_generate = read;
+            size_t bytes_to_generate = nbytes;
 
             /* we have a hole. generate silence */
             memchunk = u->source->silence;
@@ -174,7 +176,7 @@ static void read_new_samples(struct userdata *u) {
         }
 
         pa_stream_drop(u->stream);
-        readable -= read;
+        readable -= nbytes;
     }
 }
 
@@ -198,6 +200,11 @@ static void thread_func(void *userdata) {
         goto fail;
     }
 
+    if (u->cookie_file && pa_context_load_cookie_from_file(u->context, u->cookie_file) != 0) {
+        pa_log_error("Can not load cookie file!");
+        goto fail;
+    }
+
     pa_context_set_state_callback(u->context, context_state_cb, u);
     if (pa_context_connect(u->context,
                            u->remote_server,
@@ -454,6 +461,7 @@ int pa__init(pa_module *m) {
         goto fail;
     }
     u->thread_mainloop_api = pa_mainloop_get_api(u->thread_mainloop);
+    u->cookie_file = pa_xstrdup(pa_modargs_get_value(ma, "cookie", NULL));
     u->remote_source_name = pa_xstrdup(pa_modargs_get_value(ma, "source", NULL));
 
     u->thread_mq = pa_xnew0(pa_thread_mq, 1);
@@ -543,6 +551,9 @@ void pa__done(pa_module *m) {
     if (u->thread_mainloop)
         pa_mainloop_free(u->thread_mainloop);
 
+    if (u->cookie_file)
+        pa_xfree(u->cookie_file);
+
     if (u->remote_source_name)
         pa_xfree(u->remote_source_name);