From bcc2162fb4686cc3a7383847e4d2cc166c88e442 Mon Sep 17 00:00:00 2001 From: Ben Buchwald Date: Tue, 18 Dec 2018 16:40:59 -0500 Subject: [PATCH] module-jackdbus-detect: Separate sink/source channels arguments If a channels argument is passed module-jackdbus-detect, it is passed to both module-jack-sink and module-jack-source when those are started. This is a problem if you want a different number of input channels from output channels. In particular, if you want more of one than you physically have of the other, it will fail. This commit adds separate source_channels and sink_channels arguments to be able to specify the channels arguments to module-jack-source and module-jack-sink separately. The combined channels argument is kept for backwards compatibility and will be used as a default for source_channels and sink_channels if either of them is omitted. --- src/modules/jack/module-jackdbus-detect.c | 28 +++++++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/modules/jack/module-jackdbus-detect.c b/src/modules/jack/module-jackdbus-detect.c index 425b97ff4..63c430748 100644 --- a/src/modules/jack/module-jackdbus-detect.c +++ b/src/modules/jack/module-jackdbus-detect.c @@ -38,6 +38,8 @@ PA_MODULE_LOAD_ONCE(true); PA_MODULE_VERSION(PACKAGE_VERSION); PA_MODULE_USAGE( "channels= " + "source_channels= " + "sink_channels= " "connect="); #define JACK_SERVICE_NAME "org.jackaudio.service" @@ -59,6 +61,8 @@ PA_MODULE_USAGE( static const char* const valid_modargs[] = { "channels", + "source_channels", + "sink_channels", "connect", NULL }; @@ -79,7 +83,7 @@ struct userdata { bool filter_added, match_added; bool is_service_started; bool autoconnect_ports; - uint32_t channels; + uint32_t channels[JACK_SS_COUNT]; /* Using index here protects us from module unloading without us knowing */ int jack_module_index[JACK_SS_COUNT]; }; @@ -104,8 +108,8 @@ static void ensure_ports_started(struct userdata* u) { if (!u->jack_module_index[i]) { char* args; pa_module* m; - if (u->channels > 0) { - args = pa_sprintf_malloc("connect=%s channels=%" PRIu32, pa_yes_no(u->autoconnect_ports), u->channels); + if (u->channels[i] > 0) { + args = pa_sprintf_malloc("connect=%s channels=%" PRIu32, pa_yes_no(u->autoconnect_ports), u->channels[i]); } else { args = pa_sprintf_malloc("connect=%s", pa_yes_no(u->autoconnect_ports)); } @@ -213,6 +217,8 @@ int pa__init(pa_module *m) { pa_dbus_connection *connection = NULL; struct userdata *u = NULL; pa_modargs *ma; + uint32_t channels = 0; + int i; pa_assert(m); @@ -227,17 +233,29 @@ int pa__init(pa_module *m) { u->core = m->core; u->module = m; u->autoconnect_ports = true; - u->channels = 0; if (pa_modargs_get_value_boolean(ma, "connect", &u->autoconnect_ports) < 0) { pa_log("Failed to parse connect= argument."); goto fail; } - if (pa_modargs_get_value_u32(ma, "channels", &u->channels) < 0 || (u->channels > 0 && !pa_channels_valid(u->channels))) { + if (pa_modargs_get_value_u32(ma, "channels", &channels) < 0 || (channels > 0 && !pa_channels_valid(channels))) { pa_log("Failed to parse channels= argument."); goto fail; } + for (i = 0; i < JACK_SS_COUNT; i++) { + u->channels[i] = channels; + } + + if (pa_modargs_get_value_u32(ma, "source_channels", &u->channels[JACK_SS_SOURCE]) < 0 || (u->channels[JACK_SS_SOURCE] > 0 && !pa_channels_valid(u->channels[JACK_SS_SOURCE]))) { + pa_log("Failed to parse source_channels= argument."); + goto fail; + } + + if (pa_modargs_get_value_u32(ma, "sink_channels", &u->channels[JACK_SS_SINK]) < 0 || (u->channels[JACK_SS_SINK] > 0 && !pa_channels_valid(u->channels[JACK_SS_SINK]))) { + pa_log("Failed to parse sink_channels= argument."); + goto fail; + } if (!(connection = pa_dbus_bus_get(m->core, DBUS_BUS_SESSION, &error)) || dbus_error_is_set(&error)) {