[pulseaudio-discuss] [PATCH 2/2] pactl: Add set-latency-offset command.

poljar (Damir Jelić) poljarinho at gmail.com
Thu Jun 28 06:00:46 PDT 2012


From: "poljar (Damir Jelic)" <poljarinho at gmail.com>

This introduces a new command to allow setting the latency offset.

Also the card list command now shows the latency offset on the ports.
---
 man/pactl.1.xml.in |  6 ++++++
 src/utils/pactl.c  | 33 ++++++++++++++++++++++++++++-----
 2 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/man/pactl.1.xml.in b/man/pactl.1.xml.in
index 5670f43..bae518c 100644
--- a/man/pactl.1.xml.in
+++ b/man/pactl.1.xml.in
@@ -173,6 +173,12 @@ USA.
     </option>
 
     <option>
+      <p><opt>set-port-latency-offset</opt> <arg>CARD</arg> <arg>PORT</arg> <arg>OFFSET</arg></p>
+      <optdesc><p>Set a latency offset to a specified port (identified by its symbolic name) that belongs to a card (identified by its symbolic name or numerical index).
+      <arg>OFFSET</arg> is a number which represents the latency offset in microseconds</p></optdesc>
+    </option>
+
+    <option>
       <p><opt>set-sink-volume</opt> <arg>SINK</arg> <arg>VOLUME</arg></p>
       <optdesc><p>Set the volume of the specified sink (identified by its symbolic name or numerical index).
       <arg>VOLUME</arg> can be specified as an integer (e.g. 2000, 16384), a linear factor (e.g. 0.4, 1.100), a percentage
diff --git a/src/utils/pactl.c b/src/utils/pactl.c
index 5346b94..7807b3a 100644
--- a/src/utils/pactl.c
+++ b/src/utils/pactl.c
@@ -67,6 +67,7 @@ static uint32_t
 
 static pa_bool_t short_list_format = FALSE;
 static uint32_t module_index;
+static int32_t latency_offset;
 static pa_bool_t suspend;
 static pa_bool_t mute;
 static pa_volume_t volume;
@@ -117,6 +118,7 @@ static enum {
     SET_SINK_INPUT_MUTE,
     SET_SOURCE_OUTPUT_MUTE,
     SET_SINK_FORMATS,
+    SET_PORT_LATENCY_OFFSET,
     SUBSCRIBE
 } action = NONE;
 
@@ -318,8 +320,8 @@ static void get_sink_info_callback(pa_context *c, const pa_sink_info *i, int is_
 
         printf(_("\tPorts:\n"));
         for (p = i->ports; *p; p++)
-            printf("\t\t%s: %s (priority: %u%s)\n", (*p)->name, (*p)->description, (*p)->priority,
-                get_available_str_ynonly((*p)->available));
+            printf("\t\t%s: %s (priority: %u%s)\n", (*p)->name, (*p)->description,
+                    (*p)->priority, get_available_str_ynonly((*p)->available));
     }
 
     if (i->active_port)
@@ -430,8 +432,8 @@ static void get_source_info_callback(pa_context *c, const pa_source_info *i, int
 
         printf(_("\tPorts:\n"));
         for (p = i->ports; *p; p++)
-            printf("\t\t%s: %s (priority: %u%s)\n", (*p)->name, (*p)->description, (*p)->priority,
-                get_available_str_ynonly((*p)->available));
+            printf("\t\t%s: %s (priority: %u%s)\n", (*p)->name, (*p)->description,
+                    (*p)->priority, get_available_str_ynonly((*p)->available));
     }
 
     if (i->active_port)
@@ -589,7 +591,8 @@ static void get_card_info_callback(pa_context *c, const pa_card_info *i, int is_
         printf(_("\tPorts:\n"));
         for (p = i->ports; *p; p++) {
             pa_card_profile_info **pr = (*p)->profiles;
-            printf(_("\t\t%s: %s (priority: %u%s)\n"), (*p)->name, (*p)->description, (*p)->priority,
+            printf("\t\t%s: %s (priority: %u, latency offset: %" PRId64 " usec%s)\n", (*p)->name,
+                (*p)->description, (*p)->priority, (*p)->latency_offset,
                 get_available_str_ynonly((*p)->available));
 
             if (pr) {
@@ -1270,6 +1273,10 @@ static void context_state_callback(pa_context *c, void *userdata) {
                     set_sink_formats(c, sink_idx, formats);
                     break;
 
+                case SET_PORT_LATENCY_OFFSET:
+                    pa_operation_unref(pa_context_set_port_latency_offset(c, card_name, port_name, latency_offset, simple_callback, NULL));
+                    break;
+
                 case SUBSCRIBE:
                     pa_context_set_subscribe_callback(c, context_subscribe_callback, NULL);
 
@@ -1384,6 +1391,7 @@ static void help(const char *argv0) {
     printf("%s %s %s %s\n", argv0, _("[options]"), "set-(sink|source)-mute", _("NAME|#N 1|0"));
     printf("%s %s %s %s\n", argv0, _("[options]"), "set-(sink-input|source-output)-mute", _("#N 1|0"));
     printf("%s %s %s %s\n", argv0, _("[options]"), "set-sink-formats", _("#N FORMATS"));
+    printf("%s %s %s %s\n", argv0, _("[options]"), "set-port-latency-offset", _("CARD-NAME|CARD-#N PORT OFFSET"));
     printf("%s %s %s\n",    argv0, _("[options]"), "subscribe");
 
     printf(_("\n"
@@ -1812,6 +1820,21 @@ int main(int argc, char *argv[]) {
             action = SET_SINK_FORMATS;
             formats = pa_xstrdup(argv[optind+2]);
 
+        } else if (pa_streq(argv[optind], "set-port-latency-offset")) {
+            action = SET_PORT_LATENCY_OFFSET;
+
+            if (argc != optind+4) {
+                pa_log(_("You have to specify a card name/index, a port name and a latency offset"));
+                goto quit;
+            }
+
+            card_name = pa_xstrdup(argv[optind+1]);
+            port_name = pa_xstrdup(argv[optind+2]);
+            if (pa_atoi(argv[optind + 3], &latency_offset) < 0) {
+                pa_log(_("Could not parse latency offset"));
+                goto quit;
+            }
+
         } else if (pa_streq(argv[optind], "help")) {
             help(bn);
             ret = 0;
-- 
1.7.11.1



More information about the pulseaudio-discuss mailing list