[pulseaudio-discuss] [V3 PATCH] module-switch-on-connect: add an argument for conditionally connecting

2014-09-21 Thread Hui Wang
On a machine without fixed connecting audio devices like internal
microphone or internal speaker, and when there is no external audio
devices plugging in, the default source/sink is alsa_input/alsa_output
and there is no input devices/output devices listed in the gnome
sound-setting.

Under this situation, if we connect a bluetooth headset, the gnome
sound-setting will list bluez input/output devices, but they are not
active devices by default. This looks very weird that sound-setting
lists only one input device and one output device, but they are not
active. To change this situation, we add an argument, the policy is
if a new source/sink is connected and current default source/sink's
active_port is AVAILABLE_NO, we let the new added one switch to
default one.

BugLink: http://bugs.launchpad.net/bugs/1369476
Signed-off-by: Hui Wang 
---
In the V3:
if the get_value_boolean fails, release the resource and return -1

 src/modules/module-switch-on-connect.c | 32 +++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/src/modules/module-switch-on-connect.c 
b/src/modules/module-switch-on-connect.c
index d9275d3..66f3f9b 100644
--- a/src/modules/module-switch-on-connect.c
+++ b/src/modules/module-switch-on-connect.c
@@ -38,11 +38,15 @@
 #include "module-switch-on-connect-symdef.h"
 
 PA_MODULE_AUTHOR("Michael Terry");
-PA_MODULE_DESCRIPTION("When a sink/source is added, switch to it");
+PA_MODULE_DESCRIPTION("When a sink/source is added, switch to it or 
conditionally switch to it");
 PA_MODULE_VERSION(PACKAGE_VERSION);
 PA_MODULE_LOAD_ONCE(true);
+PA_MODULE_USAGE(
+"only_from_unavailable= "
+);
 
 static const char* const valid_modargs[] = {
+"only_from_unavailable",
 NULL,
 };
 
@@ -50,6 +54,7 @@ struct userdata {
 pa_hook_slot
 *sink_put_slot,
 *source_put_slot;
+bool only_from_unavailable;
 };
 
 static pa_hook_result_t sink_put_hook_callback(pa_core *c, pa_sink *sink, 
void* userdata) {
@@ -57,9 +62,11 @@ static pa_hook_result_t sink_put_hook_callback(pa_core *c, 
pa_sink *sink, void*
 uint32_t idx;
 pa_sink *def;
 const char *s;
+struct userdata *u = userdata;
 
 pa_assert(c);
 pa_assert(sink);
+pa_assert(userdata);
 
 /* Don't want to run during startup or shutdown */
 if (c->state != PA_CORE_RUNNING)
@@ -77,6 +84,10 @@ static pa_hook_result_t sink_put_hook_callback(pa_core *c, 
pa_sink *sink, void*
 if (def == sink)
 return PA_HOOK_OK;
 
+if (u->only_from_unavailable)
+if (!def->active_port || def->active_port->available != 
PA_AVAILABLE_NO)
+return PA_HOOK_OK;
+
 /* Actually do the switch to the new sink */
 pa_namereg_set_default_sink(c, sink);
 
@@ -106,9 +117,11 @@ static pa_hook_result_t source_put_hook_callback(pa_core 
*c, pa_source *source,
 uint32_t idx;
 pa_source *def;
 const char *s;
+struct userdata *u = userdata;
 
 pa_assert(c);
 pa_assert(source);
+pa_assert(userdata);
 
 /* Don't want to run during startup or shutdown */
 if (c->state != PA_CORE_RUNNING)
@@ -130,6 +143,10 @@ static pa_hook_result_t source_put_hook_callback(pa_core 
*c, pa_source *source,
 if (def == source)
 return PA_HOOK_OK;
 
+if (u->only_from_unavailable)
+if (!def->active_port || def->active_port->available != 
PA_AVAILABLE_NO)
+return PA_HOOK_OK;
+
 /* Actually do the switch to the new source */
 pa_namereg_set_default_source(c, source);
 
@@ -171,8 +188,21 @@ int pa__init(pa_module*m) {
 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);
 
+if (pa_modargs_get_value_boolean(ma, "only_from_unavailable", 
&u->only_from_unavailable) < 0) {
+   pa_log ("Failed to get a boolean value for only_from_unavailable.");
+   goto fail;
+}
+
 pa_modargs_free(ma);
 return 0;
+
+fail:
+if (ma)
+pa_modargs_free(ma);
+
+pa__done(m);
+
+return -1;
 }
 
 void pa__done(pa_module*m) {
-- 
1.9.1

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


Re: [pulseaudio-discuss] [V3 PATCH] module-switch-on-connect: add an argument for conditionally connecting

2014-09-21 Thread hwang4

Sorry, please ignore this patch, and a follow-up V4  will be sent.

On 2014年09月22日 11:26, Hui Wang wrote:

On a machine without fixed connecting audio devices like internal
microphone or internal speaker, and when there is no external audio
devices plugging in, the default source/sink is alsa_input/alsa_output
and there is no input devices/output devices listed in the gnome
sound-setting.

Under this situation, if we connect a bluetooth headset, the gnome
sound-setting will list bluez input/output devices, but they are not
active devices by default. This looks very weird that sound-setting
lists only one input device and one output device, but they are not
active. To change this situation, we add an argument, the policy is
if a new source/sink is connected and current default source/sink's
active_port is AVAILABLE_NO, we let the new added one switch to
default one.

BugLink: http://bugs.launchpad.net/bugs/1369476
Signed-off-by: Hui Wang 
---
In the V3:
if the get_value_boolean fails, release the resource and return -1

  src/modules/module-switch-on-connect.c | 32 +++-
  1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/src/modules/module-switch-on-connect.c 
b/src/modules/module-switch-on-connect.c
index d9275d3..66f3f9b 100644
--- a/src/modules/module-switch-on-connect.c
+++ b/src/modules/module-switch-on-connect.c
@@ -38,11 +38,15 @@


  
+if (pa_modargs_get_value_boolean(ma, "only_from_unavailable", &u->only_from_unavailable) < 0) {

+   pa_log ("Failed to get a boolean value for only_from_unavailable.");

Will remove the space before ("

+   goto fail;
+}
+
  pa_modargs_free(ma);
  return 0;
+
+fail:
+if (ma)
+pa_modargs_free(ma);
+
+pa__done(m);
+
+return -1;
  }
  
  void pa__done(pa_module*m) {


___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss