[PATCH] switch-on-connect: add option to ignore virtual sinks/sources

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



module-switch-on-connect would switch to any new sink, even if the sink
was a filter or a null-sink.

This patch adds a command line option ignore_virtual to the module, which
lets module-switch-on-connect ignore virtual sinks and sources. The flag
is true by default because the purpose of the module is to switch to new
hardware when it becomes available.
---
 src/modules/module-switch-on-connect.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/src/modules/module-switch-on-connect.c b/src/modules/module-switch-on-connect.c
index 640024e9..0e2b32a9 100644
--- a/src/modules/module-switch-on-connect.c
+++ b/src/modules/module-switch-on-connect.c
@@ -41,15 +41,18 @@ PA_MODULE_VERSION(PACKAGE_VERSION);
 PA_MODULE_LOAD_ONCE(true);
 PA_MODULE_USAGE(
         "only_from_unavailable=<boolean, only switch from unavailable ports> "
+        "ignore_virtual=<boolean, ignore new virtual sinks and sources, defaults to true> "
 );
 
 static const char* const valid_modargs[] = {
     "only_from_unavailable",
+    "ignore_virtual",
     NULL,
 };
 
 struct userdata {
     bool only_from_unavailable;
+    bool ignore_virtual;
 };
 
 static pa_hook_result_t sink_put_hook_callback(pa_core *c, pa_sink *sink, void* userdata) {
@@ -75,6 +78,10 @@ static pa_hook_result_t sink_put_hook_callback(pa_core *c, pa_sink *sink, void*
             return PA_HOOK_OK;
     }
 
+    /* Ignore virtual sinks if not configured otherwise on the command line */
+    if (u->ignore_virtual && !(sink->flags & PA_SINK_HARDWARE))
+        return PA_HOOK_OK;
+
     /* No default sink, nothing to move away, just set the new default */
     if (!c->default_sink) {
         pa_core_set_configured_default_sink(c, sink->name);
@@ -141,6 +148,10 @@ static pa_hook_result_t source_put_hook_callback(pa_core *c, pa_source *source,
             return PA_HOOK_OK;
     }
 
+    /* Ignore virtual sources if not configured otherwise on the command line */
+    if (u->ignore_virtual && !(source->flags & PA_SOURCE_HARDWARE))
+        return PA_HOOK_OK;
+
     /* No default source, nothing to move away, just set the new default */
     if (!c->default_source) {
         pa_core_set_configured_default_source(c, source->name);
@@ -202,6 +213,12 @@ int pa__init(pa_module*m) {
 	goto fail;
     }
 
+    u->ignore_virtual = true;
+    if (pa_modargs_get_value_boolean(ma, "ignore_virtual", &u->ignore_virtual) < 0) {
+	pa_log("Failed to get a boolean value for ignore_virtual.");
+	goto fail;
+    }
+
     pa_modargs_free(ma);
     return 0;
 
-- 
2.14.1



[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux