Open Source Telephony
 help / color / mirror / Atom feed
From: =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis <frederic.danis@linux.intel.com>
To: ofono@ofono.org
Subject: [RFC v2 10/12] emulator: Add AT+VGM support
Date: Mon, 26 Mar 2012 11:25:27 +0200	[thread overview]
Message-ID: <1332753929-9711-11-git-send-email-frederic.danis@linux.intel.com> (raw)
In-Reply-To: <1332753929-9711-1-git-send-email-frederic.danis@linux.intel.com>

[-- Attachment #1: Type: text/plain, Size: 3785 bytes --]

---
 src/emulator.c |   81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 81 insertions(+), 0 deletions(-)

diff --git a/src/emulator.c b/src/emulator.c
index 08f63ee..8c5a89a 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -55,6 +55,8 @@ struct ofono_emulator {
 	int pns_id;
 	char *audio_transport;
 	guint audio_watch;
+	int mic_gain;
+	int mic_pending;
 };
 
 struct indicator {
@@ -948,6 +950,48 @@ fail:
 	};
 }
 
+static void vgm_cb(GAtServer *server, GAtServerRequestType type,
+			GAtResult *result, gpointer user_data)
+{
+	struct ofono_emulator *em = user_data;
+	GAtResultIter iter;
+	int val;
+
+	if (em->slc == FALSE)
+		goto fail;
+
+	switch (type) {
+	case G_AT_SERVER_REQUEST_TYPE_SET:
+		if (em->audio_transport == NULL)
+			goto fail;
+
+		g_at_result_iter_init(&iter, result);
+		g_at_result_iter_next(&iter, "");
+
+		if (!g_at_result_iter_next_number(&iter, &val))
+			goto fail;
+
+		if (val < 0 || val > 15)
+			goto fail;
+
+		/* check this is last parameter */
+		if (g_at_result_iter_skip_next(&iter))
+			goto fail;
+
+		if (em->mic_pending != -1)
+			ofono_error("Receiving AT+VGM while processing one");
+
+		em->mic_pending = val;
+		audio_transport_set_property(server, em->audio_transport,
+				"MicrophoneGain", DBUS_TYPE_UINT16, &val);
+		break;
+
+	default:
+fail:
+		g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
+	};
+}
+
 static void emulator_add_indicator(struct ofono_emulator *em, const char* name,
 					int min, int max, int dflt,
 					gboolean mandatory)
@@ -1051,6 +1095,7 @@ void ofono_emulator_register(struct ofono_emulator *em, int fd)
 		g_at_server_register(em->server, "+CMEE", cmee_cb, em, NULL);
 		g_at_server_register(em->server, "+BIA", bia_cb, em, NULL);
 		g_at_server_register(em->server, "+NREC", nrec_cb, em, NULL);
+		g_at_server_register(em->server, "+VGM", vgm_cb, em, NULL);
 	}
 
 	__ofono_atom_register(em->atom, emulator_unregister);
@@ -1115,6 +1160,7 @@ struct ofono_emulator *ofono_emulator_create(struct ofono_modem *modem,
 	em->l_features |= HFP_AG_FEATURE_EXTENDED_RES_CODE;
 	em->events_mode = 3;	/* default mode is forwarding events */
 	em->cmee_mode = 0;	/* CME ERROR disabled by default */
+	em->mic_pending = -1;
 
 	em->atom = __ofono_modem_add_atom_offline(modem, atom_t,
 							emulator_remove, em);
@@ -1162,6 +1208,41 @@ static gboolean audio_property_changed(DBusConnection *connection,
 
 		sprintf(buf, "+BSIR: %d", value);
 		g_at_server_send_unsolicited(em->server, buf);
+	} else if (g_str_equal(property, "MicrophoneGain") == TRUE) {
+		DBusMessageIter variant;
+		int value;
+
+		if (!(em->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 +VGM only if :
+		 *   - the value has changed
+		 *   - and this is not a side effect of AT+VGM
+		 * But, if we receive a value change while waiting for another
+		 * pending change, we may have to send +VGM for other changes
+		 * (multiple AT+VGM received) to keep mic gain in sync
+		 */
+		if (em->mic_pending != value && em->mic_gain != value) {
+			sprintf(buf, "+VGM: %d", value);
+			g_at_server_send_unsolicited(em->server, buf);
+			em->mic_pending = -1;
+		} else if (em->mic_pending == value)
+			em->mic_pending = -1;
+		em->mic_gain = value;
 	}
 
 	return TRUE;
-- 
1.7.1


  parent reply	other threads:[~2012-03-26  9:25 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-26  9:25 [RFC v2 00/12] org.bluez.Telephony interface integration =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-03-26  9:25 ` [RFC v2 01/12] bluetooth: Add org.bluez.Telephony helpers =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-03-26  9:25 ` [RFC v2 02/12] hfp_hf: Update to org.bluez.Telephony interface =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-03-26  9:25 ` [RFC v2 03/12] hfp_ag: " =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-03-26  9:25 ` [RFC v2 04/12] bluetooth: Add org.bluez.MediaTransport interface =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-03-26  9:25 ` [RFC v2 05/12] include: Add audio transport set API =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-03-26  9:25 ` [RFC v2 06/12] emulator: Add audio transport set =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-03-26  9:25 ` [RFC v2 07/12] hfp_ag: Add media transport support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-03-26  9:25 ` [RFC v2 08/12] emulator: Add AT+NREC support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-03-26  9:25 ` [RFC v2 09/12] emulator: Add +BSIR support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-03-26  9:25 ` =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis [this message]
2012-03-26  9:25 ` [RFC v2 11/12] emulator: Add AT+VGS support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-03-26  9:25 ` [RFC v2 12/12] hfp_ag: Update supported features =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1332753929-9711-11-git-send-email-frederic.danis@linux.intel.com \
    --to=frederic.danis@linux.intel.com \
    --cc=ofono@ofono.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox