[pulseaudio-discuss] [RFC v1 10/14] bluetooth: Support media transport's State property

Mikel Astiz mikel.astiz.oss at gmail.com
Mon Jan 14 07:41:34 PST 2013


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

BlueZ 5 exposes a 'State' property in the media transport interface.
With regard to PA, this replaces the profile-specific interfaces, since
they were being used to know if the audio was streaming or not.
---
 src/modules/bluetooth/bluetooth-util.c | 37 +++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c
index c4235d5..bd5b315 100644
--- a/src/modules/bluetooth/bluetooth-util.c
+++ b/src/modules/bluetooth/bluetooth-util.c
@@ -125,6 +125,20 @@ static pa_bt_audio_state_t audio_state_from_string(const char* value) {
     return PA_BT_AUDIO_STATE_INVALID;
 }
 
+static int transport_state_from_string(const char* value, pa_bluetooth_transport_state_t *state) {
+    pa_assert(value);
+    pa_assert(state);
+
+    if (pa_streq(value, "idle"))
+        *state = PA_BLUETOOTH_TRANSPORT_STATE_IDLE;
+    else if (pa_streq(value, "pending") || pa_streq(value, "active")) /* We don't need such a separation */
+        *state = PA_BLUETOOTH_TRANSPORT_STATE_PLAYING;
+    else
+        return -1;
+
+    return 0;
+}
+
 const char *pa_bt_profile_to_string(enum profile profile) {
     switch(profile) {
         case PROFILE_A2DP:
@@ -1077,6 +1091,24 @@ static int transport_parse_property(pa_bluetooth_transport *t, DBusMessageIter *
 
             break;
          }
+
+        case DBUS_TYPE_STRING: {
+
+            const char *value;
+            dbus_message_iter_get_basic(&variant_i, &value);
+
+            if (pa_streq(key, "State")) { /* Added in BlueZ 5.0 */
+                if (transport_state_from_string(value, &t->state) < 0) {
+                    pa_log("Transport %s has an invalid state: '%s'", t->path, value);
+                    return -1;
+                }
+
+                pa_log_debug("dbus: transport %s set to state '%s'", t->path, value);
+                pa_hook_fire(&t->device->discovery->hooks[PA_BLUETOOTH_HOOK_TRANSPORT_STATE_CHANGED], t);
+            }
+
+            break;
+        }
     }
 
     return 0;
@@ -1546,7 +1578,10 @@ static pa_bluetooth_transport *transport_new(pa_bluetooth_device *d, const char
         memcpy(t->config, config, size);
     }
 
-    t->state = audio_state_to_transport_state(d->profile_state[p]);
+    if (d->discovery->version == BLUEZ_VERSION_4)
+        t->state = audio_state_to_transport_state(d->profile_state[p]);
+    else
+        t->state = PA_BLUETOOTH_TRANSPORT_STATE_IDLE;
 
     return t;
 }
-- 
1.7.11.7



More information about the pulseaudio-discuss mailing list