]> code.delx.au - pulseaudio/blobdiff - src/pulsecore/cli-command.c
introduce default channel map in addition to the default sample spec
[pulseaudio] / src / pulsecore / cli-command.c
index 8f5d9bddf543c2c7adaa5c90b6d7d0f33a45069a..7066e7e713c19a971f4641c4ffdabc44a8e35f57 100644 (file)
@@ -51,6 +51,7 @@
 #include <pulsecore/shared.h>
 #include <pulsecore/core-util.h>
 #include <pulsecore/core-error.h>
+#include <pulsecore/modinfo.h>
 
 #include "cli-command.h"
 
@@ -122,6 +123,7 @@ static int pa_cli_command_update_sink_proplist(pa_core *c, pa_tokenizer *t, pa_s
 static int pa_cli_command_update_source_proplist(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail);
 static int pa_cli_command_update_sink_input_proplist(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail);
 static int pa_cli_command_update_source_output_proplist(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail);
+static int pa_cli_command_card_profile(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail);
 
 /* A method table for all available commands */
 
@@ -172,6 +174,7 @@ static const struct command commands[] = {
     { "suspend-sink",            pa_cli_command_suspend_sink,       "Suspend sink (args: index|name, bool)", 3},
     { "suspend-source",          pa_cli_command_suspend_source,     "Suspend source (args: index|name, bool)", 3},
     { "suspend",                 pa_cli_command_suspend,            "Suspend all sinks and all sources (args: bool)", 2},
+    { "set-card-profile",        pa_cli_command_card_profile,       "Change the profile of a card (aargs: index, name)", 3},
     { "set-log-level",           pa_cli_command_log_level,          "Change the log level (args: numeric level)", 2},
     { "set-log-meta",            pa_cli_command_log_meta,           "Show source code location in log messages (args: bool)", 2},
     { "set-log-time",            pa_cli_command_log_time,           "Show timestamps in log messages (args: bool)", 2},
@@ -318,10 +321,13 @@ static int pa_cli_command_source_outputs(pa_core *c, pa_tokenizer *t, pa_strbuf
 }
 
 static int pa_cli_command_stat(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail) {
+    char ss[PA_SAMPLE_SPEC_SNPRINT_MAX];
+    char cm[PA_CHANNEL_MAP_SNPRINT_MAX];
     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",
@@ -359,14 +365,17 @@ static int pa_cli_command_stat(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_b
                      pa_bytes_snprint(s, sizeof(s), (unsigned) pa_scache_total_size(c)));
 
     pa_strbuf_printf(buf, "Default sample spec: %s\n",
-                     pa_sample_spec_snprint(s, sizeof(s), &c->default_sample_spec));
+                     pa_sample_spec_snprint(ss, sizeof(ss), &c->default_sample_spec));
 
-    def_sink = pa_namereg_get_default_sink_name(c);
-    def_source = pa_namereg_get_default_source_name(c);
+    pa_strbuf_printf(buf, "Default channel map: %s\n",
+                     pa_channel_map_snprint(cm, sizeof(cm), &c->default_channel_map));
+
+    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,
@@ -397,7 +406,6 @@ static int pa_cli_command_info(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_b
 }
 
 static int pa_cli_command_load(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail) {
-    pa_module *m;
     const char *name;
 
     pa_core_assert_ref(c);
@@ -410,7 +418,7 @@ static int pa_cli_command_load(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_b
         return -1;
     }
 
-    if (!(m = pa_module_load(c, name,  pa_tokenizer_get(t, 2)))) {
+    if (!pa_module_load(c, name,  pa_tokenizer_get(t, 2))) {
         pa_strbuf_puts(buf, "Module load failed.\n");
         return -1;
     }
@@ -515,7 +523,7 @@ static int pa_cli_command_sink_volume(pa_core *c, pa_tokenizer *t, pa_strbuf *bu
     }
 
     pa_cvolume_set(&cvolume, sink->sample_spec.channels, volume);
-    pa_sink_set_volume(sink, &cvolume);
+    pa_sink_set_volume(sink, &cvolume, TRUE, TRUE);
     return 0;
 }
 
@@ -557,7 +565,7 @@ static int pa_cli_command_sink_input_volume(pa_core *c, pa_tokenizer *t, pa_strb
     }
 
     pa_cvolume_set(&cvolume, si->sample_spec.channels, volume);
-    pa_sink_input_set_volume(si, &cvolume);
+    pa_sink_input_set_volume(si, &cvolume, TRUE);
     return 0;
 }
 
@@ -849,12 +857,13 @@ static int pa_cli_command_sink_input_mute(pa_core *c, pa_tokenizer *t, pa_strbuf
         return -1;
     }
 
-    pa_sink_input_set_mute(si, mute);
+    pa_sink_input_set_mute(si, mute, TRUE);
     return 0;
 }
 
 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);
@@ -866,12 +875,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);
@@ -883,7 +897,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;
 }
 
@@ -1166,7 +1183,7 @@ static int pa_cli_command_move_sink_input(pa_core *c, pa_tokenizer *t, pa_strbuf
         return -1;
     }
 
-    if (pa_sink_input_move_to(si, sink) < 0) {
+    if (pa_sink_input_move_to(si, sink, TRUE) < 0) {
         pa_strbuf_puts(buf, "Moved failed.\n");
         return -1;
     }
@@ -1209,7 +1226,7 @@ static int pa_cli_command_move_source_output(pa_core *c, pa_tokenizer *t, pa_str
         return -1;
     }
 
-    if (pa_source_output_move_to(so, source) < 0) {
+    if (pa_source_output_move_to(so, source, TRUE) < 0) {
         pa_strbuf_puts(buf, "Moved failed.\n");
         return -1;
     }
@@ -1410,12 +1427,44 @@ static int pa_cli_command_log_backtrace(pa_core *c, pa_tokenizer *t, pa_strbuf *
     return 0;
 }
 
+static int pa_cli_command_card_profile(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail) {
+    const char *n, *p;
+    pa_card *card;
+
+    pa_core_assert_ref(c);
+    pa_assert(t);
+    pa_assert(buf);
+    pa_assert(fail);
+
+    if (!(n = pa_tokenizer_get(t, 1))) {
+        pa_strbuf_puts(buf, "You need to specify a card either by its name or its index.\n");
+        return -1;
+    }
+
+    if (!(p = pa_tokenizer_get(t, 2))) {
+        pa_strbuf_puts(buf, "You need to specify a profile by its name.\n");
+        return -1;
+    }
+
+    if (!(card = pa_namereg_get(c, n, PA_NAMEREG_CARD))) {
+        pa_strbuf_puts(buf, "No card found by this name or index.\n");
+        return -1;
+    }
+
+    if (pa_card_set_profile(card, p) < 0) {
+        pa_strbuf_printf(buf, "Failed to set card profile to '%s'.\n", p);
+        return -1;
+    }
+
+    return 0;
+}
+
 static int pa_cli_command_dump(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail) {
     pa_module *m;
     pa_sink *sink;
     pa_source *source;
+    pa_card *card;
     int nl;
-    const char *p;
     uint32_t idx;
     char txt[256];
     time_t now;
@@ -1469,23 +1518,33 @@ static int pa_cli_command_dump(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_b
         pa_strbuf_printf(buf, "suspend-source %s %s\n", source->name, pa_yes_no(pa_source_get_state(source) == PA_SOURCE_SUSPENDED));
     }
 
+    for (card = pa_idxset_first(c->cards, &idx); card; card = pa_idxset_next(c->cards, &idx)) {
+
+        if (!nl) {
+            pa_strbuf_puts(buf, "\n");
+            nl = 1;
+        }
+
+        if (card->active_profile)
+            pa_strbuf_printf(buf, "set-card-profile %s %s\n", card->name, card->active_profile->name);
+    }
 
     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");