[pulseaudio-discuss] [PATCH 3/3] bluetooth: suspend source when stream stops
Frédéric Dalleau
frederic.dalleau at linux.intel.com
Thu May 3 09:17:41 PDT 2012
---
src/modules/bluetooth/module-bluetooth-device.c | 53 +++++++++++++++++++++++
1 files changed, 53 insertions(+), 0 deletions(-)
diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c
index 07fcb94..8e5a8f1 100644
--- a/src/modules/bluetooth/module-bluetooth-device.c
+++ b/src/modules/bluetooth/module-bluetooth-device.c
@@ -2795,6 +2795,57 @@ 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_CONNECTING:
+ goto fail;
+ case PA_BT_AUDIO_STATE_CONNECTED:
+ if (u->profile == PROFILE_A2DP_SOURCE) {
+ pa_source_suspend(u->source, TRUE, PA_SUSPEND_IDLE);
+ }
+ break;
+ case PA_BT_AUDIO_STATE_PLAYING:
+ if (u->profile == PROFILE_A2DP_SOURCE) {
+ pa_source_suspend(u->source, FALSE, PA_SUSPEND_IDLE);
+ }
+ break;
+ }
}
fail:
@@ -4030,6 +4081,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);
@@ -4104,6 +4156,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.AudioSource',member='PropertyChanged'",
NULL);
pa_xfree(speaker);
--
1.7.5.4
More information about the pulseaudio-discuss
mailing list