[pulseaudio-discuss] [RFC v1 14/14] bluetooth: Update to volume control in BlueZ 5

Mikel Astiz mikel.astiz.oss at gmail.com
Mon Jan 14 07:41:38 PST 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 b0ce59f..4a5f1dd 100644
--- a/src/modules/bluetooth/bluetooth-util.c
+++ b/src/modules/bluetooth/bluetooth-util.c
@@ -1109,6 +1109,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;
@@ -1567,6 +1593,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);
 }
@@ -1577,6 +1611,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.7.11.7



More information about the pulseaudio-discuss mailing list