From 23b97d41cd9c1209e07713a80e17e2a68675b015 Mon Sep 17 00:00:00 2001 From: Daniel Schaal Date: Sat, 13 Aug 2011 17:07:52 +0200 Subject: [PATCH] switch-on-connect: add argument use_internal_devices to allow switching to internal devices --- src/modules/module-switch-on-connect.c | 29 ++++++++++++++++++++++++----- 1 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/modules/module-switch-on-connect.c b/src/modules/module-switch-on-connect.c index b121fd9..39080e0 100644 --- a/src/modules/module-switch-on-connect.c +++ b/src/modules/module-switch-on-connect.c @@ -40,8 +40,11 @@ PA_MODULE_AUTHOR("Michael Terry"); PA_MODULE_DESCRIPTION("When a sink/source is added, switch to it"); PA_MODULE_VERSION(PACKAGE_VERSION); PA_MODULE_LOAD_ONCE(TRUE); +PA_MODULE_USAGE( + "use_internal_devices="); static const char* const valid_modargs[] = { + "use_internal_devices", NULL, }; @@ -49,9 +52,11 @@ struct userdata { pa_hook_slot *sink_put_slot, *source_put_slot; + + pa_bool_t use_internal_devices:1; }; -static pa_hook_result_t sink_put_hook_callback(pa_core *c, pa_sink *sink, void* userdata) { +static pa_hook_result_t sink_put_hook_callback(pa_core *c, pa_sink *sink, struct userdata * u) { pa_sink_input *i; uint32_t idx; pa_sink *def; @@ -59,13 +64,14 @@ static pa_hook_result_t sink_put_hook_callback(pa_core *c, pa_sink *sink, void* pa_assert(c); pa_assert(sink); + pa_assert(u); /* Don't want to run during startup or shutdown */ if (c->state != PA_CORE_RUNNING) return PA_HOOK_OK; - /* Don't switch to any internal devices */ - if ((s = pa_proplist_gets(sink->proplist, PA_PROP_DEVICE_BUS))) { + /* Don't switch to any internal devices if use_internal_devices is FALSE */ + if (!u->use_internal_devices && (s = pa_proplist_gets(sink->proplist, PA_PROP_DEVICE_BUS))) { if (pa_streq(s, "pci")) return PA_HOOK_OK; else if (pa_streq(s, "isa")) @@ -150,24 +156,37 @@ static pa_hook_result_t source_put_hook_callback(pa_core *c, pa_source *source, } int pa__init(pa_module*m) { - pa_modargs *ma; + pa_modargs *ma = NULL; struct userdata *u; + pa_bool_t use_internal_devices = FALSE; pa_assert(m); if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { pa_log("Failed to parse module arguments"); - return -1; + goto fail; + } + + if (pa_modargs_get_value_boolean(ma, "use_internal_devices", &use_internal_devices) < 0) { + pa_log("Failed to parse use_internal_devices boolean parameter."); + goto fail; } m->userdata = u = pa_xnew(struct userdata, 1); + u->use_internal_devices = use_internal_devices; + /* A little bit later than module-rescue-streams... */ u->sink_put_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_PUT], PA_HOOK_LATE+30, (pa_hook_cb_t) sink_put_hook_callback, u); u->source_put_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_PUT], PA_HOOK_LATE+20, (pa_hook_cb_t) source_put_hook_callback, u); pa_modargs_free(ma); return 0; + +fail: + if(ma) + pa_modargs_free(ma); + return -1; } void pa__done(pa_module*m) { -- 1.7.5.4