[pulseaudio-discuss] [PATCH v2 5/5] bluetooth: Do not switch to a2dp_source unless Playing

Mikel Astiz mikel.astiz.oss at gmail.com
Fri Jul 27 07:41:24 PDT 2012


From: Mikel Astiz <mikel.astiz at bmw-carit.de>

If no audio stream exists to the remote device during discovery,
setting the profile to a2dp_source would request it. To be consistent
with how hfgw is handled, this patch proposed that the switch will be
performed only after the state property change to "Playing", in the
org.bluez.AudioSource interface.
---
 src/modules/bluetooth/module-bluetooth-device.c   |   52 +++++++++++++++++++++
 src/modules/bluetooth/module-bluetooth-discover.c |    2 +-
 2 files changed, 53 insertions(+), 1 deletions(-)

diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c
index ff1e51b..d03fdec 100644
--- a/src/modules/bluetooth/module-bluetooth-device.c
+++ b/src/modules/bluetooth/module-bluetooth-device.c
@@ -1230,6 +1230,56 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *us
                 }
                 break;
         }
+    } else if (dbus_message_is_signal(m, "org.bluez.AudioSource", "PropertyChanged")) {
+        const char *key;
+        DBusMessageIter iter;
+        DBusMessageIter variant;
+        pa_bt_audio_state_t state = PA_BT_AUDIO_STATE_INVALID;
+
+        if (!dbus_message_iter_init(m, &iter)) {
+            pa_log("Failed to parse PropertyChanged: %s", err.message);
+            goto fail;
+        }
+
+        if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) {
+            pa_log("Property name not a string.");
+            goto fail;
+        }
+
+        dbus_message_iter_get_basic(&iter, &key);
+
+        if (!dbus_message_iter_next(&iter)) {
+            pa_log("Property value missing");
+            goto fail;
+        }
+
+        dbus_message_iter_recurse(&iter, &variant);
+
+        if (dbus_message_iter_get_arg_type(&variant) == DBUS_TYPE_STRING) {
+            const char *value;
+            dbus_message_iter_get_basic(&variant, &value);
+
+            if (pa_streq(key, "State")) {
+                pa_log_debug("dbus: AudioSource property 'State' changed to value '%s'", value);
+                state = pa_bt_audio_state_from_string(value);
+            }
+        }
+
+        switch(state) {
+            case PA_BT_AUDIO_STATE_INVALID:
+            case PA_BT_AUDIO_STATE_DISCONNECTED:
+            case PA_BT_AUDIO_STATE_CONNECTED:
+            case PA_BT_AUDIO_STATE_CONNECTING:
+                goto fail;
+
+            case PA_BT_AUDIO_STATE_PLAYING:
+                if (u->card && u->profile == PROFILE_OFF) {
+                    pa_log_debug("Changing profile to a2dp_source");
+                    if (pa_card_set_profile(u->card, "a2dp_source", FALSE) < 0)
+                        pa_log("Failed to change profile to a2dp_source");
+                }
+                break;
+        }
     }
 
 fail:
@@ -2391,6 +2441,7 @@ int pa__init(pa_module* m) {
                 mike,
                 "type='signal',sender='org.bluez',interface='org.bluez.MediaTransport',member='PropertyChanged'",
                 "type='signal',sender='org.bluez',interface='org.bluez.HandsfreeGateway',member='PropertyChanged'",
+                "type='signal',sender='org.bluez',interface='org.bluez.AudioSource',member='PropertyChanged'",
                 NULL) < 0) {
 
         pa_xfree(speaker);
@@ -2462,6 +2513,7 @@ void pa__done(pa_module *m) {
             pa_dbus_remove_matches(pa_dbus_connection_get(u->connection), speaker, mike,
                 "type='signal',sender='org.bluez',interface='org.bluez.MediaTransport',member='PropertyChanged'",
                 "type='signal',sender='org.bluez',interface='org.bluez.HandsfreeGateway',member='PropertyChanged'",
+                "type='signal',sender='org.bluez',interface='org.bluez.AudioSoure',member='PropertyChanged'",
                 NULL);
 
             pa_xfree(speaker);
diff --git a/src/modules/bluetooth/module-bluetooth-discover.c b/src/modules/bluetooth/module-bluetooth-discover.c
index 695fc14..93dfbb3 100644
--- a/src/modules/bluetooth/module-bluetooth-discover.c
+++ b/src/modules/bluetooth/module-bluetooth-discover.c
@@ -109,7 +109,7 @@ static pa_hook_result_t load_module_for_device(pa_bluetooth_discovery *y, const
 
             if (d->hfgw_state >= PA_BT_AUDIO_STATE_PLAYING)
                 args = pa_sprintf_malloc("%s profile=\"hfgw\"", args);
-            else if (d->audio_source_state >= PA_BT_AUDIO_STATE_CONNECTED)
+            else if (d->audio_source_state >= PA_BT_AUDIO_STATE_PLAYING)
                 args = pa_sprintf_malloc("%s profile=\"a2dp_source\" auto_connect=no", args);
 
             pa_log_debug("Loading module-bluetooth-device %s", args);
-- 
1.7.7.6



More information about the pulseaudio-discuss mailing list