---
 plugins/bluetooth.c |   71 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 71 insertions(+), 0 deletions(-)

diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c
index 3560440..107c197 100644
--- a/plugins/bluetooth.c
+++ b/plugins/bluetooth.c
@@ -81,6 +81,8 @@ struct hfp_data {
        guint watch;
        int mic_gain;
        int mic_pending;
+       int sp_gain;
+       int sp_pending;
 };
 
 void bluetooth_create_path(const char *dev_addr, const char *adapter_addr,
@@ -301,6 +303,37 @@ fail:
        };
 }
 
+static void emulator_vgs_cb(struct ofono_emulator *em,
+               struct ofono_emulator_request *req, void *userdata)
+{
+       struct hfp_data *hfp = userdata;
+       struct ofono_error result;
+       int val;
+
+       switch (ofono_emulator_request_get_type(req)) {
+       case OFONO_EMULATOR_REQUEST_TYPE_SET:
+               if (!ofono_emulator_request_next_number(req, &val))
+                       goto fail;
+
+               if (val < 0 && val > 15)
+                       goto fail;
+
+               if (hfp->sp_pending != -1)
+                       ofono_error("Receiving AT+VGS while processing one");
+
+               hfp->sp_pending = val;
+               audio_transport_set_property(hfp, "SpeakerGain",
+                                                       DBUS_TYPE_UINT16, &val);
+               break;
+
+       default:
+fail:
+               result.error = 0;
+               result.type = OFONO_ERROR_TYPE_FAILURE;
+               ofono_emulator_send_final(em, &result);
+       };
+}
+
 static gboolean audio_property_changed(DBusConnection *connection,
                                        DBusMessage *message, void *user_data)
 {
@@ -371,6 +404,41 @@ static gboolean audio_property_changed(DBusConnection 
*connection,
                } else if (hfp->mic_pending == value)
                        hfp->mic_pending = -1;
                hfp->mic_gain = value;
+       } else if (g_str_equal(property, "SpeakerGain") == TRUE) {
+               DBusMessageIter variant;
+               int value;
+
+               if (!(hfp->r_features & HFP_HF_FEATURE_REMOTE_VOLUME_CONTROL))
+                       return TRUE;
+
+               if (!dbus_message_iter_next(&iter))
+                       return TRUE;
+
+               if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
+                       return TRUE;
+
+               dbus_message_iter_recurse(&iter, &variant);
+
+               if (dbus_message_iter_get_arg_type(&variant) !=
+                                                       DBUS_TYPE_UINT16)
+                       return TRUE;
+
+               dbus_message_iter_get_basic(&variant, &value);
+
+               /* Send unsolicited +VGS only if :
+                *   - the value has changed
+                *   - and this is not a side effect of AT+VGS
+                * But, if we receive a value change while waiting for another
+                * pending change, we may have to send +VGS for other changes
+                * (multiple AT+VGS received) to keep speaker gain in sync
+                */
+               if (hfp->sp_pending != value && hfp->sp_gain != value) {
+                       sprintf(buf, "+VGS: %d", value);
+                       ofono_emulator_send_unsolicited(hfp->em, buf);
+                       hfp->sp_pending = -1;
+               } else if (hfp->sp_pending == value)
+                       hfp->sp_pending = -1;
+               hfp->sp_gain = value;
        }
 
        return TRUE;
@@ -384,6 +452,7 @@ void bluetooth_free_audio_management(void *data)
 
        ofono_emulator_remove_handler(hfp->em, "+NREC");
        ofono_emulator_remove_handler(hfp->em, "+VGM");
+       ofono_emulator_remove_handler(hfp->em, "+VGS");
 
        g_dbus_remove_watch(connection, hfp->watch);
 
@@ -403,9 +472,11 @@ void *bluetooth_set_audio_management(void *em, const char 
*path,
        hfp->path = g_strdup(path);
        hfp->r_features = features;
        hfp->mic_pending = -1;
+       hfp->sp_pending = -1;
 
        ofono_emulator_add_handler(em, "+NREC", emulator_nrec_cb, hfp, NULL);
        ofono_emulator_add_handler(em, "+VGM", emulator_vgm_cb, hfp, NULL);
+       ofono_emulator_add_handler(em, "+VGS", emulator_vgs_cb, hfp, NULL);
 
        hfp->watch = g_dbus_add_signal_watch(connection, NULL, path,
                                                BLUEZ_TRANSPORT_INTERFACE,
-- 
1.7.1

_______________________________________________
ofono mailing list
[email protected]
http://lists.ofono.org/listinfo/ofono

Reply via email to