]> code.delx.au - pulseaudio/commitdiff
pacmd: Add functions to handle the latency offset
authorpoljar <poljarinho@gmail.com>
Fri, 22 Jun 2012 18:55:55 +0000 (20:55 +0200)
committerTanu Kaskinen <tanuk@iki.fi>
Wed, 27 Jun 2012 11:24:56 +0000 (14:24 +0300)
pacmd was extended so it can handle the new latency offset.

A new function was added so we can set the latency also the list
commands were extended to print the latency offset on the ports.

src/pulsecore/cli-command.c
src/pulsecore/cli-text.c
src/utils/pacmd.c

index fc9465bce274342e5fc6f7323da5df1d3934c476..33f4d491de0be4985cb4675a105cf564527b7e85 100644 (file)
@@ -135,6 +135,7 @@ static int pa_cli_command_update_source_output_proplist(pa_core *c, pa_tokenizer
 static int pa_cli_command_card_profile(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail);
 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_dump_volumes(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail);
 
 /* A method table for all available commands */
@@ -168,6 +169,7 @@ static const struct command commands[] = {
     { "set-card-profile",        pa_cli_command_card_profile,       "Change the profile of a card (args: index|name, profile-name)", 3},
     { "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},
     { "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},
@@ -1723,6 +1725,52 @@ static int pa_cli_command_source_port(pa_core *c, pa_tokenizer *t, pa_strbuf *bu
     return 0;
 }
 
+static int pa_cli_command_port_offset(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail) {
+    const char *n, *p, *l;
+    pa_device_port *port;
+    pa_card *card;
+    int32_t offset;
+
+    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 (!(l = pa_tokenizer_get(t, 3))) {
+        pa_strbuf_puts(buf, "You need to specify a latency offset.\n");
+        return -1;
+    }
+
+    if (pa_atoi(l, &offset) < 0) {
+        pa_strbuf_puts(buf, "Failed to parse the latency offset.\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_latency_offset(port, (pa_usec_t) offset);
+
+    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;
index d234b96043e48bfccd013f89b40f1a4557ed1b4f..f322172f3ff1852cac57800e3038be65133e3f9b 100644 (file)
@@ -126,8 +126,9 @@ static void append_port_list(pa_strbuf *s, pa_hashmap *ports)
     pa_strbuf_puts(s, "\tports:\n");
     PA_HASHMAP_FOREACH(p, ports, state) {
         char *t = pa_proplist_to_string_sep(p->proplist, "\n\t\t\t\t");
-        pa_strbuf_printf(s, "\t\t%s: %s (priority %u, available: %s)\n",
-            p->name, p->description, p->priority, port_available_to_string(p->available));
+        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,
+            port_available_to_string(p->available));
         pa_strbuf_printf(s, "\t\t\tproperties:\n\t\t\t\t%s\n", t);
         pa_xfree(t);
     }
index c7c693b139c0cffcb55474f4fb581929c6e75813..a47a54a8b5a53e239563ab86040ee8ba97a9ff81 100644 (file)
@@ -73,6 +73,7 @@ static void help(const char *argv0) {
     printf("%s %s %s\n", argv0, "suspend", _("1|0"));
     printf("%s %s %s\n", argv0, "set-card-profile", _("CARD PROFILE"));
     printf("%s %s %s\n", argv0, "set-(sink|source)-port", _("NAME|#N PORT"));
+    printf("%s %s %s\n", argv0, "set-port-latency-offset", _("CARD-NAME|CARD-#N PORT OFFSET"));
     printf("%s %s %s\n", argv0, "set-log-level", _("NUMERIC LEVEL"));
     printf("%s %s %s\n", argv0, "set-log-meta", _("1|0"));
     printf("%s %s %s\n", argv0, "set-log-time", _("1|0"));