[09/10] loopback: Add adjust_time_msec parameter to allow adjust times below 1s

Submitted by Georg Chini on April 9, 2018, 5:17 p.m.

Details

Message ID 20180409171707.17696-10-georg@chini.tk
State New
Headers show
Series "loopback: Optimize latency stabilization" ( rev: 1 ) in PulseAudio

Not browsing as part of any series.

Commit Message

Georg Chini April 9, 2018, 5:17 p.m.
A new parameter is introduced to allow specifying smaller adjust_time values
than 1s. This may be useful for a better latency control, although with alsa
devices and the current smoother code no improvement could be found.
This patch also changes the default adjust time to 1s, the old value of 10s
does not allow a tight control of the end to end latency and would lead to
unnecessary jitter.
---
 src/modules/module-loopback.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/modules/module-loopback.c b/src/modules/module-loopback.c
index 048fe4f9..fd3f794e 100644
--- a/src/modules/module-loopback.c
+++ b/src/modules/module-loopback.c
@@ -44,6 +44,7 @@  PA_MODULE_USAGE(
         "source=<source to connect to> "
         "sink=<sink to connect to> "
         "adjust_time=<how often to readjust rates in s> "
+        "adjust_time_msec=<how often to readjust rates in ms> "
         "latency_msec=<latency in ms> "
         "max_latency_msec=<maximum latency in ms> "
         "low_device_latency=<boolean, use half of the normal device latency> "
@@ -68,7 +69,7 @@  PA_MODULE_USAGE(
 
 #define MIN_DEVICE_LATENCY (2.5*PA_USEC_PER_MSEC)
 
-#define DEFAULT_ADJUST_TIME_USEC (10*PA_USEC_PER_SEC)
+#define DEFAULT_ADJUST_TIME_USEC (1*PA_USEC_PER_SEC)
 
 typedef struct loopback_msg loopback_msg;
 
@@ -189,6 +190,7 @@  static const char* const valid_modargs[] = {
     "source",
     "sink",
     "adjust_time",
+    "adjust_time_msec",
     "latency_msec",
     "max_latency_msec",
     "low_device_latency",
@@ -1489,6 +1491,7 @@  int pa__init(pa_module *m) {
     bool channels_set = false;
     pa_memchunk silence;
     uint32_t adjust_time_sec;
+    uint32_t adjust_time_msec;
     const char *n;
     bool remix = true;
     bool low_device_latency = false;
@@ -1618,10 +1621,18 @@  int pa__init(pa_module *m) {
         goto fail;
     }
 
-    if (adjust_time_sec != DEFAULT_ADJUST_TIME_USEC / PA_USEC_PER_SEC)
+    adjust_time_msec = DEFAULT_ADJUST_TIME_USEC / PA_USEC_PER_MSEC;
+    if (pa_modargs_get_value_u32(ma, "adjust_time_msec", &adjust_time_msec) < 0 || (adjust_time_msec != 0 && adjust_time_msec < 100)) {
+        pa_log("Failed to parse adjust_time_msec value");
+        goto fail;
+    }
+
+    /* If adjust_time and adjust_time_msec are both specified, prefer the adjust_time_msec value */
+    u->adjust_time = DEFAULT_ADJUST_TIME_USEC;
+    if (adjust_time_msec != DEFAULT_ADJUST_TIME_USEC / PA_USEC_PER_MSEC)
+        u->adjust_time = adjust_time_msec * PA_USEC_PER_MSEC;
+    else if (adjust_time_sec != DEFAULT_ADJUST_TIME_USEC / PA_USEC_PER_SEC)
         u->adjust_time = adjust_time_sec * PA_USEC_PER_SEC;
-    else
-        u->adjust_time = DEFAULT_ADJUST_TIME_USEC;
 
     u->real_adjust_time = u->adjust_time;