All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH 2/2] Add call volume support for hfpmodem
  2009-11-11 13:32 [PATCH 2/2] Add call volume support for hfpmodem Zhenhua Zhang
@ 2009-11-11  5:52 ` Denis Kenzior
  2009-11-11  6:31   ` Zhang, Zhenhua
  0 siblings, 1 reply; 4+ messages in thread
From: Denis Kenzior @ 2009-11-11  5:52 UTC (permalink / raw)
  To: ofono

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

Hi Zhenhua,

> The call volume driver listens the speaker volume and microphone
> gain from the AG. It also allow to synchronze the speaker and
> microphone volume changes with the AG through AT+VGS and AT+VGM.
> +struct cv_data {
> +	GAtChat *chat;
> +	unsigned char cind_pos[HFP_INDICATOR_LAST];

Useless, remove

> +	int cind_val[HFP_INDICATOR_LAST];

Useless, remove

> +	unsigned char sp_volume;
> +	unsigned char mic_volume;
> +};

<snip>

> +static void hfp_call_volume_initialized(gpointer user_data)
> +{
> +	struct ofono_call_volume *cv = user_data;
> +	struct cv_data *vd = ofono_call_volume_get_data(cv);
> +
> +	DBG("");
> +
> +	g_at_chat_register(vd->chat, "+VGS:", vgs_notify, FALSE, cv, NULL);
> +	g_at_chat_register(vd->chat, "+VGM:", vgm_notify, FALSE, cv, NULL);
> +
> +	ofono_call_volume_register(cv);
> +
> +	ofono_call_volume_set_microphone_volume(cv, vd->mic_volume);
> +	ofono_call_volume_set_speaker_volume(cv, vd->sp_volume);

Section 4.28.2 of HFP Spec.  Don't we need to perform volume level 
synchronization here?

> +}
> +
> +static int hfp_call_volume_probe(struct ofono_call_volume *cv,
> +					unsigned int vendor, void *data)
> +{

<snip>

> +	memcpy(vd->cind_pos, d->cind_pos, HFP_INDICATOR_LAST);
> +	memcpy(vd->cind_val, d->cind_val, HFP_INDICATOR_LAST);

Useless

> +
> +	ofono_call_volume_set_data(cv, vd);
> +
> +	hfp_call_volume_initialized(cv);
> +
> +	return 0;
> +}
> +
> +static void hfp_call_volume_remove(struct ofono_call_volume *cv)
> +{
> +	struct cv_data *vd = ofono_call_volume_get_data(cv);

Make sure to ofono_call_volume_set_data(cv, NULL) here.

> +
> +	g_free(vd);
> +}
> +

Regards,
-Denis

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH 2/2] Add call volume support for hfpmodem
  2009-11-11  5:52 ` Denis Kenzior
@ 2009-11-11  6:31   ` Zhang, Zhenhua
  2009-11-11  6:41     ` Denis Kenzior
  0 siblings, 1 reply; 4+ messages in thread
From: Zhang, Zhenhua @ 2009-11-11  6:31 UTC (permalink / raw)
  To: ofono

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

Hi Denis,

Denis Kenzior wrote:
> Hi Zhenhua,
> 
>> +static void hfp_call_volume_initialized(gpointer user_data) {
>> +	struct ofono_call_volume *cv = user_data;
>> +	struct cv_data *vd = ofono_call_volume_get_data(cv); +
>> +	DBG("");
>> +
>> +	g_at_chat_register(vd->chat, "+VGS:", vgs_notify, FALSE, cv, NULL);
>> +	g_at_chat_register(vd->chat, "+VGM:", vgm_notify, FALSE, cv,
>> NULL); + +	ofono_call_volume_register(cv);
>> +
>> +	ofono_call_volume_set_microphone_volume(cv, vd->mic_volume);
>> +	ofono_call_volume_set_speaker_volume(cv, vd->sp_volume);
> 
> Section 4.28.2 of HFP Spec.  Don't we need to perform volume level
> synchronization here? 

Good catch. I add the sync code in attached.
 
>> +}
>> +
>> +static int hfp_call_volume_probe(struct ofono_call_volume *cv,
>> +					unsigned int vendor,
> void *data) {
> 
> <snip>
> 
>> +	memcpy(vd->cind_pos, d->cind_pos, HFP_INDICATOR_LAST);
>> +	memcpy(vd->cind_val, d->cind_val, HFP_INDICATOR_LAST);
> 
> Useless

Fixed by remove cind_pos, cind_val from struct cv_data.

>> +
>> +	ofono_call_volume_set_data(cv, vd);
>> +
>> +	hfp_call_volume_initialized(cv);
>> +
>> +	return 0;
>> +}
>> +
>> +static void hfp_call_volume_remove(struct ofono_call_volume *cv) {
>> +	struct cv_data *vd = ofono_call_volume_get_data(cv);
> 
> Make sure to ofono_call_volume_set_data(cv, NULL) here.

I don't see ofono_call_volume_set_data(cv, NULL) or ofono_voicecall_set_data(vc, NULL)
from atmodem either. Anyway, I add the code in hfp_call_volume_remove.

>> +
>> +	g_free(vd);
>> +}
>> +
> 
> Regards,
> -Denis
> _______________________________________________
> ofono mailing list
> ofono(a)ofono.org
> http://lists.ofono.org/listinfo/ofono



Regards,
Zhenhua


[-- Attachment #2: 0002-Add-call-volume-support-for-hfpmodem.patch --]
[-- Type: application/octet-stream, Size: 8937 bytes --]

From ee6bfec6a68356158f731893aca306b57e887aed Mon Sep 17 00:00:00 2001
From: Zhenhua Zhang <zhenhua.zhang@intel.com>
Date: Mon, 9 Nov 2009 01:15:59 +0800
Subject: [PATCH 2/2] Add call volume support for hfpmodem

The call volume driver listens the speaker volume and microphone
gain from the AG. It also allow to synchronze the speaker and
microphone volume changes with the AG through AT+VGS and AT+VGM.

Update: 4.28.2 sync speaker and mic volume on startup.
---
 Makefile.am                    |    3 +-
 drivers/hfpmodem/call-volume.c |  241 ++++++++++++++++++++++++++++++++++++++++
 drivers/hfpmodem/hfpmodem.c    |    2 +
 drivers/hfpmodem/hfpmodem.h    |    3 +
 plugins/hfp.c                  |    2 +
 5 files changed, 250 insertions(+), 1 deletions(-)
 create mode 100644 drivers/hfpmodem/call-volume.c

diff --git a/Makefile.am b/Makefile.am
index c3e06b4..ae9feb9 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -127,7 +127,8 @@ builtin_sources += drivers/atmodem/atutil.h \
 			drivers/hfpmodem/hfpmodem.h \
 			drivers/hfpmodem/hfpmodem.c \
 			drivers/hfpmodem/voicecall.c \
-			drivers/hfpmodem/network-registration.c
+			drivers/hfpmodem/network-registration.c \
+			drivers/hfpmodem/call-volume.c
 
 builtin_modules += mbmmodem
 builtin_sources += drivers/atmodem/atutil.h \
diff --git a/drivers/hfpmodem/call-volume.c b/drivers/hfpmodem/call-volume.c
new file mode 100644
index 0000000..a7ceb32
--- /dev/null
+++ b/drivers/hfpmodem/call-volume.c
@@ -0,0 +1,241 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2008-2009  Intel Corporation. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#define _GNU_SOURCE
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include <glib.h>
+
+#include <ofono/log.h>
+#include <ofono/modem.h>
+#include <ofono/call-volume.h>
+
+#include "gatchat.h"
+#include "gatresult.h"
+
+#include "hfpmodem.h"
+
+#define HFP_CALL_VOLUME_MAX 15
+
+static const char *vgs_prefix[] = { "+VGS:", NULL };
+static const char *vgm_prefix[] = { "+VGM:", NULL };
+
+struct cv_data {
+	GAtChat *chat;
+	unsigned char sp_volume;
+	unsigned char mic_volume;
+};
+
+static void cv_generic_set_cb(gboolean ok, GAtResult *result,
+					gpointer user_data)
+{
+	struct cb_data *cbd = user_data;
+	ofono_call_volume_cb_t cb = cbd->cb;
+	struct ofono_error error;
+
+	dump_response("generic_set_cb", ok, result);
+	decode_at_error(&error, g_at_result_final_response(result));
+
+	cb(&error, cbd->data);
+}
+
+static void hfp_speaker_volume(struct ofono_call_volume *cv,
+					unsigned char percent,
+					ofono_call_volume_cb_t cb,
+					void *data)
+{
+	struct cv_data *vd = ofono_call_volume_get_data(data);
+	struct cb_data *cbd = cb_data_new(cb, data);
+	char buf[64];
+
+	if (!cbd)
+		goto error;
+
+	vd->sp_volume = percent;
+
+	snprintf(buf, sizeof(buf), "AT+VGS=%d",
+				(int)(percent*HFP_CALL_VOLUME_MAX/100));
+
+	if (g_at_chat_send(vd->chat, buf, vgs_prefix,
+				cv_generic_set_cb, cbd, g_free) > 0)
+		return;
+
+error:
+	if (cbd)
+		g_free(cbd);
+
+	CALLBACK_WITH_FAILURE(cb, data);
+}
+
+static void hfp_microphone_volume(struct ofono_call_volume *cv,
+					unsigned char percent,
+					ofono_call_volume_cb_t cb,
+					void *data)
+{
+	struct cv_data *vd = ofono_call_volume_get_data(data);
+	struct cb_data *cbd = cb_data_new(cb, data);
+	char buf[64];
+
+	if (!cbd)
+		goto error;
+
+	vd->mic_volume = percent;
+
+	snprintf(buf, sizeof(buf), "AT+VGM=%d",
+				(int)(percent*HFP_CALL_VOLUME_MAX/100));
+
+	if (g_at_chat_send(vd->chat, buf, vgm_prefix,
+				cv_generic_set_cb, cbd, g_free) > 0)
+		return;
+
+error:
+	if (cbd)
+		g_free(cbd);
+
+	CALLBACK_WITH_FAILURE(cb, data);
+}
+
+static void vgs_notify(GAtResult *result, gpointer user_data)
+{
+	struct ofono_call_volume *cv = user_data;
+	struct cv_data *vd = ofono_call_volume_get_data(cv);
+	GAtResultIter iter;
+	gint value;
+
+	g_at_result_iter_init(&iter, result);
+
+	if (!g_at_result_iter_next(&iter, "+VGS:"))
+		return;
+
+	if (!g_at_result_iter_next_number(&iter, &value))
+		return;
+
+	vd->sp_volume = (unsigned char)(value*100/HFP_CALL_VOLUME_MAX);
+	ofono_call_volume_set_speaker_volume(cv, vd->sp_volume);
+}
+
+static void vgm_notify(GAtResult *result, gpointer user_data)
+{
+	struct ofono_call_volume *cv = user_data;
+	struct cv_data *vd = ofono_call_volume_get_data(cv);
+	GAtResultIter iter;
+	gint value;
+
+	g_at_result_iter_init(&iter, result);
+
+	if (!g_at_result_iter_next(&iter, "+VGM:"))
+		return;
+
+	if (!g_at_result_iter_next_number(&iter, &value))
+		return;
+
+	vd->mic_volume = (unsigned char)(value*100/HFP_CALL_VOLUME_MAX);
+	ofono_call_volume_set_microphone_volume(cv, vd->mic_volume);
+}
+
+static void sync_speaker_volume_cb(const struct ofono_error *error,
+					void *user_data)
+{
+	struct ofono_call_volume *cv = user_data;
+	struct cv_data *vd = ofono_call_volume_get_data(cv);
+
+	ofono_call_volume_set_speaker_volume(cv, vd->sp_volume);
+}
+
+static void sync_microphone_volume_cb(const struct ofono_error *error,
+					void *user_data)
+{
+	struct ofono_call_volume *cv = user_data;
+	struct cv_data *vd = ofono_call_volume_get_data(cv);
+
+	ofono_call_volume_set_microphone_volume(cv, vd->mic_volume);
+}
+
+static void hfp_call_volume_initialized(gpointer user_data)
+{
+	struct ofono_call_volume *cv = user_data;
+	struct cv_data *vd = ofono_call_volume_get_data(cv);
+
+	DBG("");
+
+	g_at_chat_register(vd->chat, "+VGS:", vgs_notify, FALSE, cv, NULL);
+	g_at_chat_register(vd->chat, "+VGM:", vgm_notify, FALSE, cv, NULL);
+
+	ofono_call_volume_register(cv);
+
+	/* set sp and mic volume at 50 percents by default */
+	hfp_speaker_volume(cv, 50, sync_speaker_volume_cb, cv);
+	hfp_microphone_volume(cv, 50, sync_microphone_volume_cb, cv);
+}
+
+static int hfp_call_volume_probe(struct ofono_call_volume *cv,
+					unsigned int vendor, void *data)
+{
+	struct hfp_data *d = data;
+	struct cv_data *vd;
+
+	DBG("");
+	vd = g_new0(struct cv_data, 1);
+	vd->chat = d->chat;
+
+	ofono_call_volume_set_data(cv, vd);
+
+	hfp_call_volume_initialized(cv);
+
+	return 0;
+}
+
+static void hfp_call_volume_remove(struct ofono_call_volume *cv)
+{
+	struct cv_data *vd = ofono_call_volume_get_data(cv);
+
+	ofono_call_volume_set_data(cv, NULL);
+
+	g_free(vd);
+}
+
+static struct ofono_call_volume_driver driver = {
+	.name			= "hfpmodem",
+	.probe			= hfp_call_volume_probe,
+	.remove			= hfp_call_volume_remove,
+	.speaker_volume		= hfp_speaker_volume,
+	.microphone_volume 	= hfp_microphone_volume,
+	.mute			= NULL,
+};
+
+void hfp_call_volume_init()
+{
+	ofono_call_volume_driver_register(&driver);
+}
+
+void hfp_call_volume_exit()
+{
+	ofono_call_volume_driver_unregister(&driver);
+}
+
diff --git a/drivers/hfpmodem/hfpmodem.c b/drivers/hfpmodem/hfpmodem.c
index 58ae03d..f3c7a91 100644
--- a/drivers/hfpmodem/hfpmodem.c
+++ b/drivers/hfpmodem/hfpmodem.c
@@ -43,6 +43,7 @@ static int hfpmodem_init(void)
 {
 	hfp_voicecall_init();
 	hfp_netreg_init();
+	hfp_call_volume_init();
 
 	return 0;
 }
@@ -51,6 +52,7 @@ static void hfpmodem_exit(void)
 {
 	hfp_voicecall_exit();
 	hfp_netreg_exit();
+	hfp_call_volume_exit();
 }
 
 OFONO_PLUGIN_DEFINE(hfpmodem, "Hands-Free Profile Driver", VERSION,
diff --git a/drivers/hfpmodem/hfpmodem.h b/drivers/hfpmodem/hfpmodem.h
index 02f5a4b..c0e4c7e 100644
--- a/drivers/hfpmodem/hfpmodem.h
+++ b/drivers/hfpmodem/hfpmodem.h
@@ -64,6 +64,9 @@ struct hfp_data {
 extern void hfp_netreg_init();
 extern void hfp_netreg_exit();
 
+extern void hfp_call_volume_init();
+extern void hfp_call_volume_exit();
+
 extern void hfp_voicecall_init();
 extern void hfp_voicecall_exit();
 
diff --git a/plugins/hfp.c b/plugins/hfp.c
index d696e47..fc29ad9 100644
--- a/plugins/hfp.c
+++ b/plugins/hfp.c
@@ -48,6 +48,7 @@
 #include <ofono/ssn.h>
 #include <ofono/ussd.h>
 #include <ofono/voicecall.h>
+#include <ofono/call-volume.h>
 
 #include <drivers/hfpmodem/hfpmodem.h>
 
@@ -313,6 +314,7 @@ static void hfp_pre_sim(struct ofono_modem *modem)
 
 	ofono_voicecall_create(modem, 0, "hfpmodem", data);
 	ofono_netreg_create(modem, 0, "hfpmodem", data);
+	ofono_call_volume_create(modem, 0, "hfpmodem", data);
 }
 
 static void hfp_post_sim(struct ofono_modem *modem)
-- 
1.6.2.5


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] Add call volume support for hfpmodem
  2009-11-11  6:31   ` Zhang, Zhenhua
@ 2009-11-11  6:41     ` Denis Kenzior
  0 siblings, 0 replies; 4+ messages in thread
From: Denis Kenzior @ 2009-11-11  6:41 UTC (permalink / raw)
  To: ofono

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

Hi Zhenhua,
> > Make sure to ofono_call_volume_set_data(cv, NULL) here.
>
> I don't see ofono_call_volume_set_data(cv, NULL) or
> ofono_voicecall_set_data(vc, NULL) from atmodem either. Anyway, I add the
> code in hfp_call_volume_remove.
>

Then that needs to be fixed.  Care to send a patch?

In general you should set_data to NULL before freeing it.

Regards,
-Denis


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/2] Add call volume support for hfpmodem
@ 2009-11-11 13:32 Zhenhua Zhang
  2009-11-11  5:52 ` Denis Kenzior
  0 siblings, 1 reply; 4+ messages in thread
From: Zhenhua Zhang @ 2009-11-11 13:32 UTC (permalink / raw)
  To: ofono

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

The call volume driver listens the speaker volume and microphone
gain from the AG. It also allow to synchronze the speaker and
microphone volume changes with the AG through AT+VGS and AT+VGM.
---
 Makefile.am                    |    3 +-
 drivers/hfpmodem/call-volume.c |  228
++++++++++++++++++++++++++++++++++++++++
 drivers/hfpmodem/hfpmodem.c    |    2 +
 drivers/hfpmodem/hfpmodem.h    |    3 +
 plugins/hfp.c                  |    2 +
 5 files changed, 237 insertions(+), 1 deletions(-)
 create mode 100644 drivers/hfpmodem/call-volume.c

diff --git a/Makefile.am b/Makefile.am
index c3e06b4..ae9feb9 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -127,7 +127,8 @@ builtin_sources += drivers/atmodem/atutil.h \
 			drivers/hfpmodem/hfpmodem.h \
 			drivers/hfpmodem/hfpmodem.c \
 			drivers/hfpmodem/voicecall.c \
-			drivers/hfpmodem/network-registration.c
+			drivers/hfpmodem/network-registration.c \
+			drivers/hfpmodem/call-volume.c
 
 builtin_modules += mbmmodem
 builtin_sources += drivers/atmodem/atutil.h \
diff --git a/drivers/hfpmodem/call-volume.c
b/drivers/hfpmodem/call-volume.c
new file mode 100644
index 0000000..9859bf6
--- /dev/null
+++ b/drivers/hfpmodem/call-volume.c
@@ -0,0 +1,228 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2008-2009  Intel Corporation. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or
modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#define _GNU_SOURCE
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include <glib.h>
+
+#include <ofono/log.h>
+#include <ofono/modem.h>
+#include <ofono/call-volume.h>
+
+#include "gatchat.h"
+#include "gatresult.h"
+
+#include "hfpmodem.h"
+
+#define HFP_CALL_VOLUME_MAX 15
+
+static const char *vgs_prefix[] = { "+VGS:", NULL };
+static const char *vgm_prefix[] = { "+VGM:", NULL };
+
+struct cv_data {
+	GAtChat *chat;
+	unsigned char cind_pos[HFP_INDICATOR_LAST];
+	int cind_val[HFP_INDICATOR_LAST];
+	unsigned char sp_volume;
+	unsigned char mic_volume;
+};
+
+static void cv_generic_set_cb(gboolean ok, GAtResult *result,
+					gpointer user_data)
+{
+	struct cb_data *cbd = user_data;
+	ofono_call_volume_cb_t cb = cbd->cb;
+	struct ofono_error error;
+
+	dump_response("generic_set_cb", ok, result);
+	decode_at_error(&error, g_at_result_final_response(result));
+
+	cb(&error, cbd->data);
+}
+
+static void hfp_speaker_volume(struct ofono_call_volume *cv,
+					unsigned char percent,
+					ofono_call_volume_cb_t cb,
+					void *data)
+{
+	struct cv_data *vd = ofono_call_volume_get_data(data);
+	struct cb_data *cbd = cb_data_new(cb, data);
+	char buf[64];
+
+	if (!cbd)
+		goto error;
+
+	vd->sp_volume = percent;
+
+	snprintf(buf, sizeof(buf), "AT+VGS=%d",
+				(int)(percent*HFP_CALL_VOLUME_MAX/100));
+
+	if (g_at_chat_send(vd->chat, buf, vgs_prefix,
+				cv_generic_set_cb, cbd, g_free) > 0)
+		return;
+
+error:
+	if (cbd)
+		g_free(cbd);
+
+	CALLBACK_WITH_FAILURE(cb, data);
+}
+
+static void hfp_microphone_volume(struct ofono_call_volume *cv,
+					unsigned char percent,
+					ofono_call_volume_cb_t cb,
+					void *data)
+{
+	struct cv_data *vd = ofono_call_volume_get_data(data);
+	struct cb_data *cbd = cb_data_new(cb, data);
+	char buf[64];
+
+	if (!cbd)
+		goto error;
+
+	vd->mic_volume = percent;
+
+	snprintf(buf, sizeof(buf), "AT+VGM=%d",
+				(int)(percent*HFP_CALL_VOLUME_MAX/100));
+
+	if (g_at_chat_send(vd->chat, buf, vgm_prefix,
+				cv_generic_set_cb, cbd, g_free) > 0)
+		return;
+
+error:
+	if (cbd)
+		g_free(cbd);
+
+	CALLBACK_WITH_FAILURE(cb, data);
+}
+
+static void vgs_notify(GAtResult *result, gpointer user_data)
+{
+	struct ofono_call_volume *cv = user_data;
+	struct cv_data *vd = ofono_call_volume_get_data(cv);
+	GAtResultIter iter;
+	gint value;
+
+	g_at_result_iter_init(&iter, result);
+
+	if (!g_at_result_iter_next(&iter, "+VGS:"))
+		return;
+
+	if (!g_at_result_iter_next_number(&iter, &value))
+		return;
+
+	vd->sp_volume = (unsigned char)(value*100/HFP_CALL_VOLUME_MAX);
+	ofono_call_volume_set_speaker_volume(cv, vd->sp_volume);
+}
+
+static void vgm_notify(GAtResult *result, gpointer user_data)
+{
+	struct ofono_call_volume *cv = user_data;
+	struct cv_data *vd = ofono_call_volume_get_data(cv);
+	GAtResultIter iter;
+	gint value;
+
+	g_at_result_iter_init(&iter, result);
+
+	if (!g_at_result_iter_next(&iter, "+VGM:"))
+		return;
+
+	if (!g_at_result_iter_next_number(&iter, &value))
+		return;
+
+	vd->mic_volume = (unsigned char)(value*100/HFP_CALL_VOLUME_MAX);
+	ofono_call_volume_set_microphone_volume(cv, vd->mic_volume);
+}
+
+static void hfp_call_volume_initialized(gpointer user_data)
+{
+	struct ofono_call_volume *cv = user_data;
+	struct cv_data *vd = ofono_call_volume_get_data(cv);
+
+	DBG("");
+
+	g_at_chat_register(vd->chat, "+VGS:", vgs_notify, FALSE, cv, NULL);
+	g_at_chat_register(vd->chat, "+VGM:", vgm_notify, FALSE, cv, NULL);
+
+	ofono_call_volume_register(cv);
+
+	ofono_call_volume_set_microphone_volume(cv, vd->mic_volume);
+	ofono_call_volume_set_speaker_volume(cv, vd->sp_volume);
+}
+
+static int hfp_call_volume_probe(struct ofono_call_volume *cv,
+					unsigned int vendor, void *data)
+{
+	struct hfp_data *d = data;
+	struct cv_data *vd;
+
+	DBG("");
+	vd = g_new0(struct cv_data, 1);
+	vd->chat = d->chat;
+	/* set sp and mic volume at 50 percents by default */
+	vd->sp_volume = 50;
+	vd->mic_volume = 50;
+
+	memcpy(vd->cind_pos, d->cind_pos, HFP_INDICATOR_LAST);
+	memcpy(vd->cind_val, d->cind_val, HFP_INDICATOR_LAST);
+
+	ofono_call_volume_set_data(cv, vd);
+
+	hfp_call_volume_initialized(cv);
+
+	return 0;
+}
+
+static void hfp_call_volume_remove(struct ofono_call_volume *cv)
+{
+	struct cv_data *vd = ofono_call_volume_get_data(cv);
+
+	g_free(vd);
+}
+
+static struct ofono_call_volume_driver driver = {
+	.name			= "hfpmodem",
+	.probe			= hfp_call_volume_probe,
+	.remove			= hfp_call_volume_remove,
+	.speaker_volume		= hfp_speaker_volume,
+	.microphone_volume 	= hfp_microphone_volume,
+	.mute			= NULL,
+};
+
+void hfp_call_volume_init()
+{
+	ofono_call_volume_driver_register(&driver);
+}
+
+void hfp_call_volume_exit()
+{
+	ofono_call_volume_driver_unregister(&driver);
+}
+
diff --git a/drivers/hfpmodem/hfpmodem.c b/drivers/hfpmodem/hfpmodem.c
index 58ae03d..f3c7a91 100644
--- a/drivers/hfpmodem/hfpmodem.c
+++ b/drivers/hfpmodem/hfpmodem.c
@@ -43,6 +43,7 @@ static int hfpmodem_init(void)
 {
 	hfp_voicecall_init();
 	hfp_netreg_init();
+	hfp_call_volume_init();
 
 	return 0;
 }
@@ -51,6 +52,7 @@ static void hfpmodem_exit(void)
 {
 	hfp_voicecall_exit();
 	hfp_netreg_exit();
+	hfp_call_volume_exit();
 }
 
 OFONO_PLUGIN_DEFINE(hfpmodem, "Hands-Free Profile Driver", VERSION,
diff --git a/drivers/hfpmodem/hfpmodem.h b/drivers/hfpmodem/hfpmodem.h
index 02f5a4b..c0e4c7e 100644
--- a/drivers/hfpmodem/hfpmodem.h
+++ b/drivers/hfpmodem/hfpmodem.h
@@ -64,6 +64,9 @@ struct hfp_data {
 extern void hfp_netreg_init();
 extern void hfp_netreg_exit();
 
+extern void hfp_call_volume_init();
+extern void hfp_call_volume_exit();
+
 extern void hfp_voicecall_init();
 extern void hfp_voicecall_exit();
 
diff --git a/plugins/hfp.c b/plugins/hfp.c
index d696e47..fc29ad9 100644
--- a/plugins/hfp.c
+++ b/plugins/hfp.c
@@ -48,6 +48,7 @@
 #include <ofono/ssn.h>
 #include <ofono/ussd.h>
 #include <ofono/voicecall.h>
+#include <ofono/call-volume.h>
 
 #include <drivers/hfpmodem/hfpmodem.h>
 
@@ -313,6 +314,7 @@ static void hfp_pre_sim(struct ofono_modem *modem)
 
 	ofono_voicecall_create(modem, 0, "hfpmodem", data);
 	ofono_netreg_create(modem, 0, "hfpmodem", data);
+	ofono_call_volume_create(modem, 0, "hfpmodem", data);
 }
 
 static void hfp_post_sim(struct ofono_modem *modem)
-- 
1.6.2.5




^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-11-11 13:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-11 13:32 [PATCH 2/2] Add call volume support for hfpmodem Zhenhua Zhang
2009-11-11  5:52 ` Denis Kenzior
2009-11-11  6:31   ` Zhang, Zhenhua
2009-11-11  6:41     ` Denis Kenzior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.