From: Mikel Astiz <mikel.astiz@xxxxxxxxxxxx> Similarly to the microphone gain, the speaker gain can be abstracted inside the transport object, even though the actual D-Bus interface in BlueZ differs. --- src/modules/bluetooth/bluetooth-util.c | 25 +++++++++++++++++++++++++ src/modules/bluetooth/bluetooth-util.h | 3 +++ 2 files changed, 28 insertions(+) diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c index 644d9b9..e2ea58c 100644 --- a/src/modules/bluetooth/bluetooth-util.c +++ b/src/modules/bluetooth/bluetooth-util.c @@ -549,6 +549,21 @@ static int parse_audio_property(pa_bluetooth_device *d, const char *interface, D transport->microphone_gain = gain; pa_hook_fire(&d->discovery->hooks[PA_BLUETOOTH_HOOK_TRANSPORT_MICROPHONE_GAIN_CHANGED], transport); + } else if (pa_streq(key, "SpeakerGain")) { + uint16_t gain; + + pa_log_debug("dbus: property '%s' changed to value '%u'", key, value); + + if (!transport) { + pa_log("Volume change does not have an associated transport"); + return -1; + } + + if ((gain = PA_MIN(value, HSP_MAX_GAIN)) == transport->speaker_gain) + break; + + transport->speaker_gain = gain; + pa_hook_fire(&d->discovery->hooks[PA_BLUETOOTH_HOOK_TRANSPORT_SPEAKER_GAIN_CHANGED], transport); } break; @@ -1141,6 +1156,16 @@ void pa_bluetooth_transport_set_microphone_gain(pa_bluetooth_transport *t, uint1 "MicrophoneGain", DBUS_TYPE_UINT16, &gain); } +void pa_bluetooth_transport_set_speaker_gain(pa_bluetooth_transport *t, uint16_t value) { + dbus_uint16_t gain = PA_MIN(value, HSP_MAX_GAIN); + + pa_assert(t); + pa_assert(t->profile == PROFILE_HSP); + + set_property(t->device->discovery, "org.bluez", t->device->path, "org.bluez.Headset", + "SpeakerGain", DBUS_TYPE_UINT16, &gain); +} + static int setup_dbus(pa_bluetooth_discovery *y) { DBusError err; diff --git a/src/modules/bluetooth/bluetooth-util.h b/src/modules/bluetooth/bluetooth-util.h index 4c909ab..e471e0d 100644 --- a/src/modules/bluetooth/bluetooth-util.h +++ b/src/modules/bluetooth/bluetooth-util.h @@ -79,6 +79,7 @@ typedef enum pa_bluetooth_hook { PA_BLUETOOTH_HOOK_TRANSPORT_STATE_CHANGED, /* Call data: pa_bluetooth_transport */ PA_BLUETOOTH_HOOK_TRANSPORT_NREC_CHANGED, /* Call data: pa_bluetooth_transport */ PA_BLUETOOTH_HOOK_TRANSPORT_MICROPHONE_GAIN_CHANGED, /* Call data: pa_bluetooth_transport */ + PA_BLUETOOTH_HOOK_TRANSPORT_SPEAKER_GAIN_CHANGED, /* Call data: pa_bluetooth_transport */ PA_BLUETOOTH_HOOK_MAX } pa_bluetooth_hook_t; @@ -100,6 +101,7 @@ struct pa_bluetooth_transport { pa_bluetooth_transport_state_t state; pa_bool_t nrec; uint16_t microphone_gain; /* Used for HSP/HFP */ + uint16_t speaker_gain; /* Used for HSP/HFP */ }; /* This enum is shared among Audio, Headset, AudioSink, and AudioSource, although not all values are acceptable in all profiles */ @@ -150,6 +152,7 @@ int pa_bluetooth_transport_acquire(pa_bluetooth_transport *t, const char *access void pa_bluetooth_transport_release(pa_bluetooth_transport *t, const char *accesstype); void pa_bluetooth_transport_set_microphone_gain(pa_bluetooth_transport *t, uint16_t value); +void pa_bluetooth_transport_set_speaker_gain(pa_bluetooth_transport *t, uint16_t value); pa_hook* pa_bluetooth_discovery_hook(pa_bluetooth_discovery *y, pa_bluetooth_hook_t hook); -- 1.7.11.7