[pulseaudio-commits] [SCM] PulseAudio Sound Server branch, master, updated. v0.9.13-415-ga5401a5

Lennart Poettering gitmailer-noreply at 0pointer.de
Tue Jan 27 16:46:29 PST 2009


This is an automated email from the git hooks/post-receive script. It was
generated because of a push to the "PulseAudio Sound Server" repository.

The master branch has been updated
      from  fc3ff114186020637e1dfbe23ff01d00b0452ccf (commit)

- Log -----------------------------------------------------------------
a5401a5... store the default sink/source in proper pa_sink*/pa_source* pointers instead of a string
-----------------------------------------------------------------------

Summary of changes:
 src/daemon/main.c                           |    5 --
 src/modules/module-default-device-restore.c |   22 +++---
 src/pulsecore/cli-command.c                 |   33 ++++++---
 src/pulsecore/cli-text.c                    |    4 +-
 src/pulsecore/core.c                        |    7 +-
 src/pulsecore/core.h                        |   10 ++-
 src/pulsecore/namereg.c                     |  101 +++++++++++++--------------
 src/pulsecore/namereg.h                     |    8 ++-
 src/pulsecore/protocol-http.c               |   10 ++-
 src/pulsecore/protocol-native.c             |   29 ++++++--
 src/pulsecore/source-output.h               |    1 +
 11 files changed, 130 insertions(+), 100 deletions(-)

-----------------------------------------------------------------------

commit a5401a50a67ebf1d86e979ee5556961b24a25400
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Jan 28 01:46:27 2009 +0100

    store the default sink/source in proper pa_sink*/pa_source* pointers instead of a string

diff --git a/src/daemon/main.c b/src/daemon/main.c
index bd8ad1d..936c214 100644
--- a/src/daemon/main.c
+++ b/src/daemon/main.c
@@ -971,11 +971,6 @@ int main(int argc, char *argv[]) {
         goto finish;
     }
 
-    if (c->default_sink_name && !pa_namereg_get(c, c->default_sink_name, PA_NAMEREG_SINK) && conf->fail) {
-        pa_log_error(_("Default sink name (%s) does not exist in name register."), c->default_sink_name);
-        goto finish;
-    }
-
 #ifdef HAVE_FORK
     if (daemon_pipe[1] >= 0) {
         int ok = 0;
diff --git a/src/modules/module-default-device-restore.c b/src/modules/module-default-device-restore.c
index 97d3fb2..d299f40 100644
--- a/src/modules/module-default-device-restore.c
+++ b/src/modules/module-default-device-restore.c
@@ -57,10 +57,11 @@ static void load(struct userdata *u) {
 
     /* We never overwrite manually configured settings */
 
-    if (u->core->default_sink_name)
+    if (u->core->default_sink)
         pa_log_info("Manually configured default sink, not overwriting.");
     else if ((f = fopen(u->sink_filename, "r"))) {
         char ln[256] = "";
+        pa_sink *s;
 
         fgets(ln, sizeof(ln)-1, f);
         pa_strip_nl(ln);
@@ -68,8 +69,8 @@ static void load(struct userdata *u) {
 
         if (!ln[0])
             pa_log_info("No previous default sink setting, ignoring.");
-        else if (pa_namereg_get(u->core, ln, PA_NAMEREG_SINK)) {
-            pa_namereg_set_default(u->core, ln, PA_NAMEREG_SINK);
+        else if ((s = pa_namereg_get(u->core, ln, PA_NAMEREG_SINK))) {
+            pa_namereg_set_default_sink(u->core, s);
             pa_log_info("Restored default sink '%s'.", ln);
         } else
             pa_log_info("Saved default sink '%s' not existant, not restoring default sink setting.", ln);
@@ -77,10 +78,11 @@ static void load(struct userdata *u) {
     } else if (errno != ENOENT)
         pa_log("Failed to load default sink: %s", pa_cstrerror(errno));
 
-    if (u->core->default_source_name)
+    if (u->core->default_source)
         pa_log_info("Manually configured default source, not overwriting.");
     else if ((f = fopen(u->source_filename, "r"))) {
         char ln[256] = "";
+        pa_source *s;
 
         fgets(ln, sizeof(ln)-1, f);
         pa_strip_nl(ln);
@@ -88,8 +90,8 @@ static void load(struct userdata *u) {
 
         if (!ln[0])
             pa_log_info("No previous default source setting, ignoring.");
-        else if (pa_namereg_get(u->core, ln, PA_NAMEREG_SOURCE)) {
-            pa_namereg_set_default(u->core, ln, PA_NAMEREG_SOURCE);
+        else if ((s = pa_namereg_get(u->core, ln, PA_NAMEREG_SOURCE))) {
+            pa_namereg_set_default_source(u->core, s);
             pa_log_info("Restored default source '%s'.", ln);
         } else
             pa_log_info("Saved default source '%s' not existant, not restoring default source setting.", ln);
@@ -106,8 +108,8 @@ static void save(struct userdata *u) {
 
     if (u->sink_filename) {
         if ((f = fopen(u->sink_filename, "w"))) {
-            const char *n = pa_namereg_get_default_sink_name(u->core);
-            fprintf(f, "%s\n", pa_strempty(n));
+            pa_sink *s = pa_namereg_get_default_sink(u->core);
+            fprintf(f, "%s\n", s ? s->name : "");
             fclose(f);
         } else
             pa_log("Failed to save default sink: %s", pa_cstrerror(errno));
@@ -115,8 +117,8 @@ static void save(struct userdata *u) {
 
     if (u->source_filename) {
         if ((f = fopen(u->source_filename, "w"))) {
-            const char *n = pa_namereg_get_default_source_name(u->core);
-            fprintf(f, "%s\n", pa_strempty(n));
+            pa_source *s = pa_namereg_get_default_source(u->core);
+            fprintf(f, "%s\n", s ? s->name : "");
             fclose(f);
         } else
             pa_log("Failed to save default source: %s", pa_cstrerror(errno));
diff --git a/src/pulsecore/cli-command.c b/src/pulsecore/cli-command.c
index be5a394..1df0bd6 100644
--- a/src/pulsecore/cli-command.c
+++ b/src/pulsecore/cli-command.c
@@ -324,7 +324,8 @@ static int pa_cli_command_stat(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_b
     char s[256];
     const pa_mempool_stat *stat;
     unsigned k;
-    const char *def_sink, *def_source;
+    pa_sink *def_sink;
+    pa_source *def_source;
 
     static const char* const type_table[PA_MEMBLOCK_TYPE_MAX] = {
         [PA_MEMBLOCK_POOL] = "POOL",
@@ -364,12 +365,12 @@ static int pa_cli_command_stat(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_b
     pa_strbuf_printf(buf, "Default sample spec: %s\n",
                      pa_sample_spec_snprint(s, sizeof(s), &c->default_sample_spec));
 
-    def_sink = pa_namereg_get_default_sink_name(c);
-    def_source = pa_namereg_get_default_source_name(c);
+    def_sink = pa_namereg_get_default_sink(c);
+    def_source = pa_namereg_get_default_source(c);
     pa_strbuf_printf(buf, "Default sink name: %s\n"
                      "Default source name: %s\n",
-                     def_sink ? def_sink : "none",
-                     def_source ? def_source : "none");
+                     def_sink ? def_sink->name : "none",
+                     def_source ? def_source->name : "none");
 
     for (k = 0; k < PA_MEMBLOCK_TYPE_MAX; k++)
         pa_strbuf_printf(buf,
@@ -858,6 +859,7 @@ static int pa_cli_command_sink_input_mute(pa_core *c, pa_tokenizer *t, pa_strbuf
 
 static int pa_cli_command_sink_default(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail) {
     const char *n;
+    pa_sink *s;
 
     pa_core_assert_ref(c);
     pa_assert(t);
@@ -869,12 +871,17 @@ static int pa_cli_command_sink_default(pa_core *c, pa_tokenizer *t, pa_strbuf *b
         return -1;
     }
 
-    pa_namereg_set_default(c, n, PA_NAMEREG_SINK);
+    if ((s = pa_namereg_get(c, n, PA_NAMEREG_SINK)))
+        pa_namereg_set_default_sink(c, s);
+    else
+        pa_strbuf_printf(buf, "Sink %s does not exist.\n", n);
+
     return 0;
 }
 
 static int pa_cli_command_source_default(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail) {
     const char *n;
+    pa_source *s;
 
     pa_core_assert_ref(c);
     pa_assert(t);
@@ -886,7 +893,10 @@ static int pa_cli_command_source_default(pa_core *c, pa_tokenizer *t, pa_strbuf
         return -1;
     }
 
-    pa_namereg_set_default(c, n, PA_NAMEREG_SOURCE);
+    if ((s = pa_namereg_get(c, n, PA_NAMEREG_SOURCE)))
+        pa_namereg_set_default_source(c, s);
+    else
+        pa_strbuf_printf(buf, "Source %s does not exist.\n", n);
     return 0;
 }
 
@@ -1451,7 +1461,6 @@ static int pa_cli_command_dump(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_b
     pa_source *source;
     pa_card *card;
     int nl;
-    const char *p;
     uint32_t idx;
     char txt[256];
     time_t now;
@@ -1518,20 +1527,20 @@ static int pa_cli_command_dump(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_b
 
     nl = 0;
 
-    if ((p = pa_namereg_get_default_sink_name(c))) {
+    if ((sink = pa_namereg_get_default_sink(c))) {
         if (!nl) {
             pa_strbuf_puts(buf, "\n");
             nl = 1;
         }
-        pa_strbuf_printf(buf, "set-default-sink %s\n", p);
+        pa_strbuf_printf(buf, "set-default-sink %s\n", sink->name);
     }
 
-    if ((p = pa_namereg_get_default_source_name(c))) {
+    if ((source = pa_namereg_get_default_source(c))) {
         if (!nl) {
             pa_strbuf_puts(buf, "\n");
             nl = 1;
         }
-        pa_strbuf_printf(buf, "set-default-source %s\n", p);
+        pa_strbuf_printf(buf, "set-default-source %s\n", source->name);
     }
 
     pa_strbuf_puts(buf, "\n### EOF\n");
diff --git a/src/pulsecore/cli-text.c b/src/pulsecore/cli-text.c
index 647fc1b..57129d0 100644
--- a/src/pulsecore/cli-text.c
+++ b/src/pulsecore/cli-text.c
@@ -248,7 +248,7 @@ char *pa_sink_list_to_string(pa_core *c) {
             "\tchannel map: %s%s%s\n"
             "\tused by: %u\n"
             "\tlinked by: %u\n",
-            c->default_sink_name && !strcmp(sink->name, c->default_sink_name) ? '*' : ' ',
+            sink == c->default_sink ? '*' : ' ',
             sink->index,
             sink->name,
             sink->driver,
@@ -339,7 +339,7 @@ char *pa_source_list_to_string(pa_core *c) {
             "\tchannel map: %s%s%s\n"
             "\tused by: %u\n"
             "\tlinked by: %u\n",
-            c->default_source_name && !strcmp(source->name, c->default_source_name) ? '*' : ' ',
+            c->default_source == source ? '*' : ' ',
             source->index,
             source->name,
             source->driver,
diff --git a/src/pulsecore/core.c b/src/pulsecore/core.c
index 381a677..689fc8f 100644
--- a/src/pulsecore/core.c
+++ b/src/pulsecore/core.c
@@ -99,7 +99,8 @@ pa_core* pa_core_new(pa_mainloop_api *m, pa_bool_t shared, size_t shm_size) {
     c->sink_inputs = pa_idxset_new(NULL, NULL);
     c->cards = pa_idxset_new(NULL, NULL);
 
-    c->default_source_name = c->default_sink_name = NULL;
+    c->default_source = NULL;
+    c->default_sink = NULL;
 
     c->modules = NULL;
     c->namereg = NULL;
@@ -191,8 +192,8 @@ static void core_free(pa_object *o) {
     if (c->exit_event)
         c->mainloop->time_free(c->exit_event);
 
-    pa_xfree(c->default_source_name);
-    pa_xfree(c->default_sink_name);
+    pa_assert(!c->default_source);
+    pa_assert(!c->default_sink);
 
     pa_silence_cache_done(&c->silence_cache);
     pa_mempool_free(c->mempool);
diff --git a/src/pulsecore/core.h b/src/pulsecore/core.h
index e33a245..b349c6f 100644
--- a/src/pulsecore/core.h
+++ b/src/pulsecore/core.h
@@ -25,6 +25,8 @@
 #include <pulse/mainloop-api.h>
 #include <pulse/sample.h>
 
+typedef struct pa_core pa_core;
+
 #include <pulsecore/idxset.h>
 #include <pulsecore/hashmap.h>
 #include <pulsecore/memblock.h>
@@ -34,9 +36,8 @@
 #include <pulsecore/hook-list.h>
 #include <pulsecore/asyncmsgq.h>
 #include <pulsecore/sample-util.h>
-
-typedef struct pa_core pa_core;
-
+#include <pulsecore/sink.h>
+#include <pulsecore/source.h>
 #include <pulsecore/core-subscribe.h>
 #include <pulsecore/sink-input.h>
 #include <pulsecore/msgobject.h>
@@ -112,7 +113,8 @@ struct pa_core {
     pa_hashmap *namereg, *shared;
 
     /* The name of the default sink/source */
-    char *default_source_name, *default_sink_name;
+    pa_source *default_source;
+    pa_sink *default_sink;
 
     pa_sample_spec default_sample_spec;
     unsigned default_n_fragments, default_fragment_size_msec;
diff --git a/src/pulsecore/namereg.c b/src/pulsecore/namereg.c
index ed652ab..f3d5a8f 100644
--- a/src/pulsecore/namereg.c
+++ b/src/pulsecore/namereg.c
@@ -173,6 +173,11 @@ void pa_namereg_unregister(pa_core *c, const char *name) {
 
     pa_assert_se(e = pa_hashmap_remove(c->namereg, name));
 
+    if (c->default_sink == e->data)
+        pa_namereg_set_default_sink(c, NULL);
+    else if (c->default_source == e->data)
+        pa_namereg_set_default_source(c, NULL);
+
     pa_xfree(e->name);
     pa_xfree(e);
 }
@@ -182,32 +187,27 @@ void* pa_namereg_get(pa_core *c, const char *name, pa_namereg_type_t type) {
     uint32_t idx;
     pa_assert(c);
 
-    if (!name) {
+    if (type == PA_NAMEREG_SOURCE && (!name || pa_streq(name, "@DEFAULT_SOURCE@"))) {
+        pa_source *s;
 
-        if (type == PA_NAMEREG_SOURCE)
-            name = pa_namereg_get_default_source_name(c);
-        else if (type == PA_NAMEREG_SINK)
-            name = pa_namereg_get_default_sink_name(c);
+        if ((s = pa_namereg_get_default_source(c)))
+            return s;
 
-    } else if (strcmp(name, "@DEFAULT_SINK@") == 0) {
-        if (type == PA_NAMEREG_SINK)
-               name = pa_namereg_get_default_sink_name(c);
+    } else if (type == PA_NAMEREG_SINK && (!name || pa_streq(name, "@DEFAULT_SINK@"))) {
+        pa_sink *s;
 
-    } else if (strcmp(name, "@DEFAULT_SOURCE@") == 0) {
-        if (type == PA_NAMEREG_SOURCE)
-            name = pa_namereg_get_default_source_name(c);
+        if ((s = pa_namereg_get_default_sink(c)))
+            return s;
 
-    } else if (strcmp(name, "@DEFAULT_MONITOR@") == 0) {
-        if (type == PA_NAMEREG_SOURCE) {
-            pa_sink *k;
+    } else if (type == PA_NAMEREG_SOURCE && name && pa_streq(name, "@DEFAULT_MONITOR@")) {
+        pa_sink *s;
 
-            if ((k = pa_namereg_get(c, NULL, PA_NAMEREG_SINK)))
-                return k->monitor_source;
-        }
-    } else if (*name == '@')
-        name = NULL;
+        if ((s = pa_namereg_get(c, NULL, PA_NAMEREG_SINK)))
+            return s->monitor_source;
+
+    }
 
-    if (!name)
+    if (*name == '@' || !name || !pa_namereg_is_valid_name(name))
         return NULL;
 
     if (c->namereg && (e = pa_hashmap_get(c->namereg, name)))
@@ -229,62 +229,57 @@ void* pa_namereg_get(pa_core *c, const char *name, pa_namereg_type_t type) {
     return NULL;
 }
 
-int pa_namereg_set_default(pa_core*c, const char *name, pa_namereg_type_t type) {
-    char **s;
-
+pa_sink* pa_namereg_set_default_sink(pa_core*c, pa_sink *s) {
     pa_assert(c);
-    pa_assert(type == PA_NAMEREG_SINK || type == PA_NAMEREG_SOURCE);
-
-    s = type == PA_NAMEREG_SINK ? &c->default_sink_name : &c->default_source_name;
 
-    if (!name && !*s)
-        return 0;
+    if (c->default_sink != s) {
+        c->default_sink = s;
+        pa_subscription_post(c, PA_SUBSCRIPTION_EVENT_SERVER|PA_SUBSCRIPTION_EVENT_CHANGE, PA_INVALID_INDEX);
+    }
 
-    if (name && *s && !strcmp(name, *s))
-        return 0;
+    return s;
+}
 
-    if (!pa_namereg_is_valid_name(name))
-        return -1;
+pa_source* pa_namereg_set_default_source(pa_core*c, pa_source *s) {
+    pa_assert(c);
 
-    pa_xfree(*s);
-    *s = pa_xstrdup(name);
-    pa_subscription_post(c, PA_SUBSCRIPTION_EVENT_SERVER|PA_SUBSCRIPTION_EVENT_CHANGE, PA_INVALID_INDEX);
+    if (c->default_source != s) {
+        c->default_source = s;
+        pa_subscription_post(c, PA_SUBSCRIPTION_EVENT_SERVER|PA_SUBSCRIPTION_EVENT_CHANGE, PA_INVALID_INDEX);
+    }
 
-    return 0;
+    return s;
 }
 
-const char *pa_namereg_get_default_sink_name(pa_core *c) {
+pa_sink *pa_namereg_get_default_sink(pa_core *c) {
     pa_sink *s;
 
     pa_assert(c);
 
-    if (c->default_sink_name)
-        return c->default_sink_name;
+    if (c->default_sink)
+        return c->default_sink;
 
     if ((s = pa_idxset_first(c->sinks, NULL)))
-        pa_namereg_set_default(c, s->name, PA_NAMEREG_SINK);
+        return pa_namereg_set_default_sink(c, s);
 
-    return c->default_sink_name;
+    return NULL;
 }
 
-const char *pa_namereg_get_default_source_name(pa_core *c) {
+pa_source *pa_namereg_get_default_source(pa_core *c) {
     pa_source *s;
     uint32_t idx;
 
     pa_assert(c);
 
-    if (c->default_source_name)
-        return c->default_source_name;
+    if (c->default_source)
+        return c->default_source;
 
-    for (s = pa_idxset_first(c->sources, &idx); s; s = pa_idxset_next(c->sources, &idx))
-        if (!s->monitor_of) {
-            pa_namereg_set_default(c, s->name, PA_NAMEREG_SOURCE);
-            break;
-        }
+    for (s = PA_SOURCE(pa_idxset_first(c->sources, &idx)); s; s = PA_SOURCE(pa_idxset_next(c->sources, &idx)))
+        if (!s->monitor_of)
+            return pa_namereg_set_default_source(c, s);
 
-    if (!c->default_source_name)
-        if ((s = pa_idxset_first(c->sources, NULL)))
-            pa_namereg_set_default(c, s->name, PA_NAMEREG_SOURCE);
+    if ((s = pa_idxset_first(c->sources, NULL)))
+        return pa_namereg_set_default_source(c, s);
 
-    return c->default_source_name;
+    return NULL;
 }
diff --git a/src/pulsecore/namereg.h b/src/pulsecore/namereg.h
index 4205f2f..b91dd52 100644
--- a/src/pulsecore/namereg.h
+++ b/src/pulsecore/namereg.h
@@ -39,10 +39,12 @@ void pa_namereg_free(pa_core *c);
 const char *pa_namereg_register(pa_core *c, const char *name, pa_namereg_type_t type, void *data, pa_bool_t fail);
 void pa_namereg_unregister(pa_core *c, const char *name);
 void* pa_namereg_get(pa_core *c, const char *name, pa_namereg_type_t type);
-int pa_namereg_set_default(pa_core*c, const char *name, pa_namereg_type_t type);
 
-const char *pa_namereg_get_default_sink_name(pa_core *c);
-const char *pa_namereg_get_default_source_name(pa_core *c);
+pa_sink* pa_namereg_set_default_sink(pa_core*c, pa_sink *s);
+pa_source* pa_namereg_set_default_source(pa_core*c, pa_source *s);
+
+pa_sink *pa_namereg_get_default_sink(pa_core *c);
+pa_source *pa_namereg_get_default_source(pa_core *c);
 
 pa_bool_t pa_namereg_is_valid_name(const char *name);
 char* pa_namereg_make_valid_name(const char *name);
diff --git a/src/pulsecore/protocol-http.c b/src/pulsecore/protocol-http.c
index c89d48b..5379a36 100644
--- a/src/pulsecore/protocol-http.c
+++ b/src/pulsecore/protocol-http.c
@@ -156,6 +156,8 @@ static void line_callback(pa_ioline *line, const char *s, void *userdata) {
 
             if (!strcmp(c->url, URL_ROOT)) {
                 char txt[256];
+                pa_sink *def_sink;
+                pa_source *def_source;
                 http_response(c, 200, "OK", "text/html");
 
                 pa_ioline_puts(c->line,
@@ -173,8 +175,12 @@ static void line_callback(pa_ioline *line, const char *s, void *userdata) {
                 PRINTF_FIELD("User Name:", pa_get_user_name(txt, sizeof(txt)));
                 PRINTF_FIELD("Host name:", pa_get_host_name(txt, sizeof(txt)));
                 PRINTF_FIELD("Default Sample Specification:", pa_sample_spec_snprint(txt, sizeof(txt), &c->protocol->core->default_sample_spec));
-                PRINTF_FIELD("Default Sink:", pa_namereg_get_default_sink_name(c->protocol->core));
-                PRINTF_FIELD("Default Source:", pa_namereg_get_default_source_name(c->protocol->core));
+
+                def_sink = pa_namereg_get_default_sink(c->protocol->core);
+                def_source = pa_namereg_get_default_source(c->protocol->core);
+
+                PRINTF_FIELD("Default Sink:", def_sink ? def_sink->name : "n/a");
+                PRINTF_FIELD("Default Source:", def_source ? def_source->name : "n/a");
 
                 pa_ioline_puts(c->line, "</table>");
 
diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c
index c33d15e..c962165 100644
--- a/src/pulsecore/protocol-native.c
+++ b/src/pulsecore/protocol-native.c
@@ -3031,7 +3031,8 @@ static void command_get_server_info(pa_pdispatch *pd, uint32_t command, uint32_t
     pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
     pa_tagstruct *reply;
     char txt[256];
-    const char *n;
+    pa_sink *def_sink;
+    pa_source *def_source;
     pa_sample_spec fixed_ss;
 
     pa_native_connection_assert_ref(c);
@@ -3053,10 +3054,10 @@ static void command_get_server_info(pa_pdispatch *pd, uint32_t command, uint32_t
     fixup_sample_spec(c, &fixed_ss, &c->protocol->core->default_sample_spec);
     pa_tagstruct_put_sample_spec(reply, &fixed_ss);
 
-    n = pa_namereg_get_default_sink_name(c->protocol->core);
-    pa_tagstruct_puts(reply, n);
-    n = pa_namereg_get_default_source_name(c->protocol->core);
-    pa_tagstruct_puts(reply, n);
+    def_sink = pa_namereg_get_default_sink(c->protocol->core);
+    pa_tagstruct_puts(reply, def_sink ? def_sink->name : NULL);
+    def_source = pa_namereg_get_default_source(c->protocol->core);
+    pa_tagstruct_puts(reply, def_source ? def_source->name : NULL);
 
     pa_tagstruct_putu32(reply, c->protocol->core->cookie);
 
@@ -3671,7 +3672,23 @@ static void command_set_default_sink_or_source(pa_pdispatch *pd, uint32_t comman
     CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
     CHECK_VALIDITY(c->pstream, !s || pa_namereg_is_valid_name(s), tag, PA_ERR_INVALID);
 
-    pa_namereg_set_default(c->protocol->core, s, command == PA_COMMAND_SET_DEFAULT_SOURCE ? PA_NAMEREG_SOURCE : PA_NAMEREG_SINK);
+    if (command == PA_COMMAND_SET_DEFAULT_SOURCE) {
+        pa_source *source;
+
+        source = pa_namereg_get(c->protocol->core, s, PA_NAMEREG_SOURCE);
+        CHECK_VALIDITY(c->pstream, source, tag, PA_ERR_NOENTITY);
+
+        pa_namereg_set_default_source(c->protocol->core, source);
+    } else {
+        pa_sink *sink;
+        pa_assert(command == PA_COMMAND_SET_DEFAULT_SINK);
+
+        sink = pa_namereg_get(c->protocol->core, s, PA_NAMEREG_SINK);
+        CHECK_VALIDITY(c->pstream, sink, tag, PA_ERR_NOENTITY);
+
+        pa_namereg_set_default_sink(c->protocol->core, sink);
+    }
+
     pa_pstream_send_simple_ack(c->pstream, tag);
 }
 
diff --git a/src/pulsecore/source-output.h b/src/pulsecore/source-output.h
index 671894e..79b4926 100644
--- a/src/pulsecore/source-output.h
+++ b/src/pulsecore/source-output.h
@@ -32,6 +32,7 @@ typedef struct pa_source_output pa_source_output;
 #include <pulsecore/resampler.h>
 #include <pulsecore/module.h>
 #include <pulsecore/client.h>
+#include <pulsecore/sink-input.h>
 
 typedef enum pa_source_output_state {
     PA_SOURCE_OUTPUT_INIT,

-- 
hooks/post-receive
PulseAudio Sound Server



More information about the pulseaudio-commits mailing list