From: "poljar (Damir Jeli?)" <poljarinho@xxxxxxxxx> pacmd was extended to handle maximum volumes for ports. The maximum volume is printed with the card info in the port section. --- src/pulsecore/cli-command.c | 52 +++++++++++++++++++++++++++++++++++++++++++++ src/pulsecore/cli-text.c | 10 +++++++-- 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/src/pulsecore/cli-command.c b/src/pulsecore/cli-command.c index 130185a..71a17c8 100644 --- a/src/pulsecore/cli-command.c +++ b/src/pulsecore/cli-command.c @@ -136,6 +136,7 @@ static int pa_cli_command_card_profile(pa_core *c, pa_tokenizer *t, pa_strbuf *b static int pa_cli_command_sink_port(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail); static int pa_cli_command_source_port(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail); static int pa_cli_command_port_offset(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail); +static int pa_cli_command_port_max_volume(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail); static int pa_cli_command_dump_volumes(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail); /* A method table for all available commands */ @@ -170,6 +171,7 @@ static const struct command commands[] = { { "set-sink-port", pa_cli_command_sink_port, "Change the port of a sink (args: index|name, port-name)", 3}, { "set-source-port", pa_cli_command_source_port, "Change the port of a source (args: index|name, port-name)", 3}, { "set-port-latency-offset", pa_cli_command_port_offset, "Change the latency of a port (args: card-index|card-name, port-name, latency-offset)", 4}, + { "set-port-max-volume", pa_cli_command_port_max_volume, "Change the maximum volume of a port (args: card-index|card-name, port-name, max-volume)", 4}, { "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}, @@ -1771,6 +1773,56 @@ static int pa_cli_command_port_offset(pa_core *c, pa_tokenizer *t, pa_strbuf *bu return 0; } +static int pa_cli_command_port_max_volume(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail) { + const char *n, *v, *p; + pa_device_port *port; + pa_card *card; + pa_volume_t volume; + + 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 port by its name.\n"); + return -1; + } + + if (!(v = pa_tokenizer_get(t, 3))) { + pa_strbuf_puts(buf, "You need to specify a volume >= 0. (0 is no maximum, 0x10000 is normal volume)\n"); + return -1; + } + + if (pa_atou(v, &volume) < 0) { + pa_strbuf_puts(buf, "Failed to parse volume.\n"); + return -1; + } + + if (!PA_VOLUME_IS_VALID(volume)) { + pa_strbuf_puts(buf, "Volume outside permissible range.\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 (!(port = pa_hashmap_get(card->ports, p))) { + pa_strbuf_puts(buf, "No port found by this name.\n"); + return -1; + } + + pa_device_port_set_max_volume(port, volume); + 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; diff --git a/src/pulsecore/cli-text.c b/src/pulsecore/cli-text.c index 0df17e5..c0f1571 100644 --- a/src/pulsecore/cli-text.c +++ b/src/pulsecore/cli-text.c @@ -127,9 +127,15 @@ static void append_port_list(pa_strbuf *s, pa_hashmap *ports) pa_strbuf_puts(s, "\tports:\n"); PA_HASHMAP_FOREACH(p, ports, state) { + char v[PA_VOLUME_SNPRINT_MAX]; char *t = pa_proplist_to_string_sep(p->proplist, "\n\t\t\t\t"); - pa_strbuf_printf(s, "\t\t%s: %s (priority %u, latency offset %" PRId64 " usec, available: %s)\n", - p->name, p->description, p->priority, p->latency_offset, + + pa_volume_snprint(v, sizeof(v), p->max_volume); + if (pa_streq(v, "(invalid)")) + pa_strlcpy(v, "off", 4); + + pa_strbuf_printf(s, "\t\t%s: %s (priority %u, latency offset %" PRId64 " usec, max volume %s available: %s)\n", + p->name, p->description, p->priority, p->latency_offset, v, port_available_to_string(p->available)); pa_strbuf_printf(s, "\t\t\tproperties:\n\t\t\t\t%s\n", t); pa_xfree(t); -- 1.7.11.4