module-tunnel-sink-new: add a max_latency option

Submitted by John Smith on Dec. 20, 2018, 12:46 a.m.

Details

Message ID 20181220004639.3212-1-drefleladi@gmail.com
State New
Headers show
Series "module-tunnel-sink-new: add a max_latency option" ( rev: 1 ) in PulseAudio

Not browsing as part of any series.

Commit Message

John Smith Dec. 20, 2018, 12:46 a.m.
---
 src/modules/module-tunnel-sink-new.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/modules/module-tunnel-sink-new.c b/src/modules/module-tunnel-sink-new.c
index 802e6a59a..cf0f7905a 100644
--- a/src/modules/module-tunnel-sink-new.c
+++ b/src/modules/module-tunnel-sink-new.c
@@ -55,9 +55,10 @@  PA_MODULE_USAGE(
         "rate=<sample rate> "
         "channel_map=<channel map> "
         "cookie=<cookie file path>"
+	"max_latency=<latency in ms>"
         );
 
-#define MAX_LATENCY_USEC (200 * PA_USEC_PER_MSEC)
+#define DEFAULT_MAX_LATENCY_MSEC 200
 #define TUNNEL_THREAD_FAILED_MAINLOOP 1
 
 static void stream_state_cb(pa_stream *stream, void *userdata);
@@ -97,6 +98,7 @@  static const char* const valid_modargs[] = {
     "rate",
     "channel_map",
     "cookie",
+    "max_latency",
    /* "reconnect", reconnect if server comes back again - unimplemented */
     NULL,
 };
@@ -476,6 +478,7 @@  int pa__init(pa_module *m) {
     const char *remote_server = NULL;
     const char *sink_name = NULL;
     char *default_sink_name = NULL;
+    uint32_t max_latency_msec = DEFAULT_MAX_LATENCY_MSEC;
 
     pa_assert(m);
 
@@ -497,6 +500,11 @@  int pa__init(pa_module *m) {
         goto fail;
     }
 
+    if (pa_modargs_get_value_u32(ma, "max_latency", &max_latency_msec) < 0) {
+      pa_log("Failed to parse max_latency value.");
+      goto fail;
+    }
+
     u = pa_xnew0(struct userdata, 1);
     u->module = m;
     m->userdata = u;
@@ -561,7 +569,7 @@  int pa__init(pa_module *m) {
     u->sink->parent.process_msg = sink_process_msg_cb;
     u->sink->set_state_in_io_thread = sink_set_state_in_io_thread_cb;
     u->sink->update_requested_latency = sink_update_requested_latency_cb;
-    pa_sink_set_latency_range(u->sink, 0, MAX_LATENCY_USEC);
+    pa_sink_set_latency_range(u->sink, 0, max_latency_msec * PA_USEC_PER_MSEC);
 
     /* set thread message queue */
     pa_sink_set_asyncmsgq(u->sink, u->thread_mq->inq);