All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH v3 1/6] include: Add ofono_handsfree_card_set_codec()
  2013-04-15 13:54 [PATCH v3 1/6] include: Add ofono_handsfree_card_set_codec() Vinicius Costa Gomes
@ 2013-04-15 12:22 ` Denis Kenzior
  2013-04-15 13:54 ` [PATCH v3 2/6] handsfree-audio: Implement ofono_handsfree_card_set_codec() Vinicius Costa Gomes
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Denis Kenzior @ 2013-04-15 12:22 UTC (permalink / raw)
  To: ofono

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

Hi Vinicius,

On 04/15/2013 08:54 AM, Vinicius Costa Gomes wrote:
> This will be used by the drivers that a given codec was negotiated
> for a card.
>
> It will return FALSE if the codec can't be used. For example, if the selected
> codec is mSBC and defer setup is not supported by the kernel.
> ---
>   include/handsfree-audio.h | 2 ++
>   1 file changed, 2 insertions(+)

All 6 patches in this series have been applied, thanks.

Regards,
-Denis


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

* [PATCH v3 1/6] include: Add ofono_handsfree_card_set_codec()
@ 2013-04-15 13:54 Vinicius Costa Gomes
  2013-04-15 12:22 ` Denis Kenzior
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Vinicius Costa Gomes @ 2013-04-15 13:54 UTC (permalink / raw)
  To: ofono

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

This will be used by the drivers that a given codec was negotiated
for a card.

It will return FALSE if the codec can't be used. For example, if the selected
codec is mSBC and defer setup is not supported by the kernel.
---
 include/handsfree-audio.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/handsfree-audio.h b/include/handsfree-audio.h
index 82d1312..53e8ab1 100644
--- a/include/handsfree-audio.h
+++ b/include/handsfree-audio.h
@@ -48,6 +48,8 @@ struct ofono_handsfree_card *ofono_handsfree_card_create(unsigned int vendor,
 							void *data);
 int ofono_handsfree_card_register(struct ofono_handsfree_card *card);
 void ofono_handsfree_card_remove(struct ofono_handsfree_card *card);
+ofono_bool_t ofono_handsfree_card_set_codec(struct ofono_handsfree_card *card,
+							unsigned char codec);
 
 ofono_bool_t ofono_handsfree_audio_has_wideband(void);
 
-- 
1.8.2


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

* [PATCH v3 2/6] handsfree-audio: Implement ofono_handsfree_card_set_codec()
  2013-04-15 13:54 [PATCH v3 1/6] include: Add ofono_handsfree_card_set_codec() Vinicius Costa Gomes
  2013-04-15 12:22 ` Denis Kenzior
@ 2013-04-15 13:54 ` Vinicius Costa Gomes
  2013-04-15 13:54 ` [PATCH v3 3/6] hfp_hf_bluez5: Watch for changes in the selected codec Vinicius Costa Gomes
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Vinicius Costa Gomes @ 2013-04-15 13:54 UTC (permalink / raw)
  To: ofono

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

---
 src/handsfree-audio.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index 50be691..8e8d460 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -49,6 +49,7 @@ struct ofono_handsfree_card {
 	char *local;
 	char *path;
 	DBusMessage *msg;
+	unsigned char selected_codec;
 	const struct ofono_handsfree_card_driver *driver;
 	void *driver_data;
 };
@@ -342,6 +343,8 @@ struct ofono_handsfree_card *ofono_handsfree_card_create(unsigned int vendor,
 
 	card = g_new0(struct ofono_handsfree_card, 1);
 
+	card->selected_codec = HFP_CODEC_CVSD;
+
 	card_list = g_slist_prepend(card_list, card);
 
 	for (l = drivers; l; l = l->next) {
@@ -535,6 +538,23 @@ void ofono_handsfree_card_remove(struct ofono_handsfree_card *card)
 	g_free(card);
 }
 
+ofono_bool_t ofono_handsfree_card_set_codec(struct ofono_handsfree_card *card,
+							unsigned char codec)
+{
+	if (codec == HFP_CODEC_CVSD)
+		goto done;
+
+	if (codec == HFP_CODEC_MSBC && has_wideband)
+		goto done;
+
+	return FALSE;
+
+done:
+	card->selected_codec = codec;
+
+	return TRUE;
+}
+
 ofono_bool_t ofono_handsfree_audio_has_wideband(void)
 {
 	return has_wideband;
-- 
1.8.2


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

* [PATCH v3 3/6] hfp_hf_bluez5: Watch for changes in the selected codec
  2013-04-15 13:54 [PATCH v3 1/6] include: Add ofono_handsfree_card_set_codec() Vinicius Costa Gomes
  2013-04-15 12:22 ` Denis Kenzior
  2013-04-15 13:54 ` [PATCH v3 2/6] handsfree-audio: Implement ofono_handsfree_card_set_codec() Vinicius Costa Gomes
@ 2013-04-15 13:54 ` Vinicius Costa Gomes
  2013-04-15 13:54 ` [PATCH v3 4/6] handsfree-audio: Send " Vinicius Costa Gomes
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Vinicius Costa Gomes @ 2013-04-15 13:54 UTC (permalink / raw)
  To: ofono

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

This patch adds a function to monitor when the AG sends a new codec
before establishing the SCO connection.
---
 plugins/hfp_hf_bluez5.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/plugins/hfp_hf_bluez5.c b/plugins/hfp_hf_bluez5.c
index c63b1a2..2c67a21 100644
--- a/plugins/hfp_hf_bluez5.c
+++ b/plugins/hfp_hf_bluez5.c
@@ -314,9 +314,49 @@ static struct ofono_modem_driver hfp_driver = {
 	.post_sim	= hfp_post_sim,
 };
 
+static void bcs_notify(GAtResult *result, gpointer user_data)
+{
+	struct hfp *hfp = user_data;
+	struct hfp_slc_info *info = &hfp->info;
+	GAtResultIter iter;
+	char str[32];
+	int value;
+
+	g_at_result_iter_init(&iter, result);
+
+	if (!g_at_result_iter_next(&iter, "+BCS:"))
+		return;
+
+	if (!g_at_result_iter_next_number(&iter, &value))
+		return;
+
+	if (ofono_handsfree_card_set_codec(hfp->card, value) == FALSE) {
+		/* Unsupported codec, re-send our codecs */
+		if (ofono_handsfree_audio_has_wideband())
+			sprintf(str, "AT+BAC=%d,%d", HFP_CODEC_CVSD,
+							HFP_CODEC_MSBC);
+		else
+			sprintf(str, "AT+BAC=%d", HFP_CODEC_CVSD);
+
+		goto done;
+	}
+
+	/* Confirm the codec */
+	sprintf(str, "AT+BCS=%d", value);
+
+done:
+	g_at_chat_send(info->chat, str, NULL, NULL, NULL, NULL);
+}
+
 static int hfp16_card_probe(struct ofono_handsfree_card *card,
 					unsigned int vendor, void *data)
 {
+	struct hfp *hfp = data;
+	struct hfp_slc_info *info = &hfp->info;
+
+	g_at_chat_register(info->chat, "+BCS:", bcs_notify, FALSE,
+								hfp, NULL);
+
 	return 0;
 }
 
-- 
1.8.2


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

* [PATCH v3 4/6] handsfree-audio: Send the selected codec
  2013-04-15 13:54 [PATCH v3 1/6] include: Add ofono_handsfree_card_set_codec() Vinicius Costa Gomes
                   ` (2 preceding siblings ...)
  2013-04-15 13:54 ` [PATCH v3 3/6] hfp_hf_bluez5: Watch for changes in the selected codec Vinicius Costa Gomes
@ 2013-04-15 13:54 ` Vinicius Costa Gomes
  2013-04-15 13:54 ` [PATCH v3 5/6] handsfree-audio: Keep track whether defer_setup is enabled Vinicius Costa Gomes
  2013-04-15 13:54 ` [PATCH v3 6/6] handsfree-audio: Toggle wideband support when the agent registers Vinicius Costa Gomes
  5 siblings, 0 replies; 7+ messages in thread
From: Vinicius Costa Gomes @ 2013-04-15 13:54 UTC (permalink / raw)
  To: ofono

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

From: Claudio Takahasi <claudio.takahasi@openbossa.org>

This patch removes the hard-coded CVSD codec, and adds the selected
codec in the NewConnection method call, notifying the agent the codec
previously selected for the audio connection.
---
 src/handsfree-audio.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index 8e8d460..7f5b33c 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -67,11 +67,10 @@ static guint sco_watch = 0;
 static GSList *drivers = 0;
 static ofono_bool_t has_wideband = FALSE;
 
-static void send_new_connection(const char *card, int fd)
+static void send_new_connection(const char *card, int fd, uint8_t codec)
 {
 	DBusMessage *msg;
 	DBusMessageIter iter;
-	uint8_t codec = HFP_CODEC_CVSD;
 
 	msg = dbus_message_new_method_call(agent->owner, agent->path,
 				HFP_AUDIO_AGENT_INTERFACE, "NewConnection");
@@ -150,7 +149,7 @@ static gboolean sco_accept(GIOChannel *io, GIOCondition cond,
 		return TRUE;
 	}
 
-	send_new_connection(card->path, nsk);
+	send_new_connection(card->path, nsk, card->selected_codec);
 	close(nsk);
 
 	return TRUE;
@@ -252,7 +251,7 @@ static gboolean sco_connect_cb(GIOChannel *io, GIOCondition cond,
 
 	sk = g_io_channel_unix_get_fd(io);
 
-	send_new_connection(card->path, sk);
+	send_new_connection(card->path, sk, card->selected_codec);
 
 	close(sk);
 
-- 
1.8.2


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

* [PATCH v3 5/6] handsfree-audio: Keep track whether defer_setup is enabled
  2013-04-15 13:54 [PATCH v3 1/6] include: Add ofono_handsfree_card_set_codec() Vinicius Costa Gomes
                   ` (3 preceding siblings ...)
  2013-04-15 13:54 ` [PATCH v3 4/6] handsfree-audio: Send " Vinicius Costa Gomes
@ 2013-04-15 13:54 ` Vinicius Costa Gomes
  2013-04-15 13:54 ` [PATCH v3 6/6] handsfree-audio: Toggle wideband support when the agent registers Vinicius Costa Gomes
  5 siblings, 0 replies; 7+ messages in thread
From: Vinicius Costa Gomes @ 2013-04-15 13:54 UTC (permalink / raw)
  To: ofono

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

'defer_setup' will be one of the inputs when enabling or disabling
support for wideband speech codecs, we will only enable wideband
speech support if the kernel supports deferred setup.

So, we have to have this information available, in this case it means
a global variable.
---
 src/handsfree-audio.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index 7f5b33c..fc3d15b 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -66,6 +66,7 @@ static GSList *card_list = 0;
 static guint sco_watch = 0;
 static GSList *drivers = 0;
 static ofono_bool_t has_wideband = FALSE;
+static int defer_setup = 1;
 
 static void send_new_connection(const char *card, int fd, uint8_t codec)
 {
@@ -159,7 +160,7 @@ static int sco_init(void)
 {
 	GIOChannel *sco_io;
 	struct sockaddr_sco saddr;
-	int sk, defer_setup = 1;
+	int sk;
 
 	sk = socket(PF_BLUETOOTH, SOCK_SEQPACKET | O_NONBLOCK | SOCK_CLOEXEC,
 								BTPROTO_SCO);
@@ -177,9 +178,11 @@ static int sco_init(void)
 	}
 
 	if (setsockopt(sk, SOL_BLUETOOTH, BT_DEFER_SETUP,
-				&defer_setup, sizeof(defer_setup)) < 0)
+				&defer_setup, sizeof(defer_setup)) < 0) {
+		defer_setup = 0;
 		ofono_warn("Can't enable deferred setup: %s (%d)",
 						strerror(errno), errno);
+	}
 
 	if (listen(sk, 5) < 0) {
 		close(sk);
-- 
1.8.2


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

* [PATCH v3 6/6] handsfree-audio: Toggle wideband support when the agent registers
  2013-04-15 13:54 [PATCH v3 1/6] include: Add ofono_handsfree_card_set_codec() Vinicius Costa Gomes
                   ` (4 preceding siblings ...)
  2013-04-15 13:54 ` [PATCH v3 5/6] handsfree-audio: Keep track whether defer_setup is enabled Vinicius Costa Gomes
@ 2013-04-15 13:54 ` Vinicius Costa Gomes
  5 siblings, 0 replies; 7+ messages in thread
From: Vinicius Costa Gomes @ 2013-04-15 13:54 UTC (permalink / raw)
  To: ofono

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

Each time an agent registers itself, we check if we support deferred
setup and if the agent has mSBC as a codec, if both checks are true,
we enable wideband speech support.
---
 src/handsfree-audio.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index fc3d15b..c24e787 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -646,7 +646,7 @@ static DBusMessage *am_agent_register(DBusConnection *conn,
 	unsigned char *codecs;
 	DBusMessageIter iter, array;
 	int length, i;
-	gboolean has_cvsd = FALSE;
+	gboolean has_cvsd = FALSE, has_msbc = FALSE;
 
 	if (agent)
 		return __ofono_error_in_use(msg);
@@ -668,10 +668,17 @@ static DBusMessage *am_agent_register(DBusConnection *conn,
 	for (i = 0; i < length; i++) {
 		if (codecs[i] == HFP_CODEC_CVSD)
 			has_cvsd = TRUE;
-		else if (codecs[i] != HFP_CODEC_MSBC)
+		else if (codecs[i] == HFP_CODEC_MSBC)
+			has_msbc = TRUE;
+		else
 			return __ofono_error_invalid_args(msg);
 	}
 
+	if (has_msbc && defer_setup == 1)
+		has_wideband = TRUE;
+	else
+		has_wideband = FALSE;
+
 	if (has_cvsd == FALSE) {
 		ofono_error("CVSD codec is mandatory");
 		return __ofono_error_invalid_args(msg);
-- 
1.8.2


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

end of thread, other threads:[~2013-04-15 13:54 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-15 13:54 [PATCH v3 1/6] include: Add ofono_handsfree_card_set_codec() Vinicius Costa Gomes
2013-04-15 12:22 ` Denis Kenzior
2013-04-15 13:54 ` [PATCH v3 2/6] handsfree-audio: Implement ofono_handsfree_card_set_codec() Vinicius Costa Gomes
2013-04-15 13:54 ` [PATCH v3 3/6] hfp_hf_bluez5: Watch for changes in the selected codec Vinicius Costa Gomes
2013-04-15 13:54 ` [PATCH v3 4/6] handsfree-audio: Send " Vinicius Costa Gomes
2013-04-15 13:54 ` [PATCH v3 5/6] handsfree-audio: Keep track whether defer_setup is enabled Vinicius Costa Gomes
2013-04-15 13:54 ` [PATCH v3 6/6] handsfree-audio: Toggle wideband support when the agent registers Vinicius Costa Gomes

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.