[pulseaudio-discuss] [RFC next v4 16/16] bluetooth: Update to volume control in BlueZ 5

Mikel Astiz mikel.astiz.oss at gmail.com
Mon Apr 29 09:28:13 PDT 2013


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

In BlueZ 5, the microphone and speaker gains are exposed as properties
of the MediaTransport1 interface.
---
 src/modules/bluetooth/bluetooth-util.c | 41 ++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c
index a6559cb..049c479 100644
--- a/src/modules/bluetooth/bluetooth-util.c
+++ b/src/modules/bluetooth/bluetooth-util.c
@@ -1154,6 +1154,32 @@ static int transport_parse_property(pa_bluetooth_transport *t, DBusMessageIter *
 
             break;
         }
+
+        case DBUS_TYPE_BYTE: {
+            uint8_t value;
+
+            dbus_message_iter_get_basic(&variant_i, &value);
+
+            if (pa_streq(key, "MicrophoneGain")) {
+                uint8_t gain;
+
+                if ((gain = PA_MIN(value, HSP_MAX_GAIN)) == t->microphone_gain)
+                    break;
+
+                t->microphone_gain = gain;
+                pa_hook_fire(&t->device->discovery->hooks[PA_BLUETOOTH_HOOK_TRANSPORT_MICROPHONE_GAIN_CHANGED], t);
+            } else if (pa_streq(key, "SpeakerGain")) {
+                uint8_t gain;
+
+                if ((gain = PA_MIN(value, HSP_MAX_GAIN)) == t->speaker_gain)
+                    break;
+
+                t->speaker_gain = gain;
+                pa_hook_fire(&t->device->discovery->hooks[PA_BLUETOOTH_HOOK_TRANSPORT_SPEAKER_GAIN_CHANGED], t);
+            }
+
+            break;
+        }
     }
 
     return 0;
@@ -1617,6 +1643,14 @@ void pa_bluetooth_transport_set_microphone_gain(pa_bluetooth_transport *t, uint1
     pa_assert(t);
     pa_assert(t->profile == PROFILE_HSP);
 
+    if (t->device->discovery->version >= BLUEZ_VERSION_5) {
+        uint8_t g = (uint8_t) gain;
+
+        set_property(t->device->discovery, t->owner, t->path, "org.bluez.MediaTransport1",
+                     "MicrophoneGain", DBUS_TYPE_BYTE, &g);
+        return;
+    }
+
     set_property(t->device->discovery, "org.bluez", t->device->path, "org.bluez.Headset",
                  "MicrophoneGain", DBUS_TYPE_UINT16, &gain);
 }
@@ -1627,6 +1661,13 @@ void pa_bluetooth_transport_set_speaker_gain(pa_bluetooth_transport *t, uint16_t
     pa_assert(t);
     pa_assert(t->profile == PROFILE_HSP);
 
+    if (t->device->discovery->version >= BLUEZ_VERSION_5) {
+        uint8_t g = (uint8_t) gain;
+
+        set_property(t->device->discovery, t->owner, t->path, "org.bluez.MediaTransport1", "SpeakerGain", DBUS_TYPE_BYTE, &g);
+        return;
+    }
+
     set_property(t->device->discovery, "org.bluez", t->device->path, "org.bluez.Headset",
                  "SpeakerGain", DBUS_TYPE_UINT16, &gain);
 }
-- 
1.8.1.4



More information about the pulseaudio-discuss mailing list