Skip to contentSkip to conversation

error in headset capture, patch included

Bluez-devel New Pavel Semerad 3 participants 5 messages Jan 9, 2008 – Jan 10, 2008 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

Helo,

I have found error in function bluetooth_hsp_read. frame_size is correctly set only when data->count is zero. When data->count is nonzero, frame_size is 0 and condition
'if ((data->count + size * frame_size) <= data->link_mtu)' is always true and frames_to_write is set incorrectly (1000 instead max 24 in my case). This results in capture not working for headset, cycling in endless loop.

Following patch sets frame_size before check to data->count and 'arecord -D bluetooth -f S16_LE' now works.

Pavel Semerad

--- ./audio/pcm_bluetooth.c.capture 2007-12-08 20:04:40.000000000
+0100
+++ ./audio/pcm_bluetooth.c 2008-01-09 01:12:02.000000000 +0100
@ -786,11 +786,11 @@ static snd_pcm_sframes_t bluetooth_hsp_r

        DBG("areas->step=%u areas->first=%u offset=%lu size=%lu
io->nonblock=%u",
                        areas->step, areas->first, offset, size,

io->nonblock);

+ frame_size = areas->step / 8;
+

        if (data->count > 0)
                goto proceed;

- frame_size = areas->step / 8;
-

        nrecv = recv(data->stream.fd, data->buffer, data->link_mtu,
                        MSG_WAITALL | (io->nonblock ? MSG_DONTWAIT :

0));

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#1 lore raw

Hi Pavel,

Quoted 10 lines · Pavel Semerad

I have found error in function bluetooth_hsp_read. frame_size is correctly set only when data->count is zero. When data->count is nonzero, frame_size is 0 and condition
'if ((data->count + size * frame_size) <= data->link_mtu)' is always true and frames_to_write is set incorrectly (1000 instead max 24 in my case). This results in capture not working for headset, cycling in endless loop.

Following patch sets frame_size before check to data->count and 'arecord -D bluetooth -f S16_LE' now works.

Nice catch! Thanks! Commited to CVS now.

Johan

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#2 lore raw

PATCH 1/1 HFP - Rejecting a call

In reply to Pavel Semerad

Hi Johan,

Here is a patch which handles the "Call Rejection" use case. Let me know if anything needs to be changed.

Alok.

Index: audio/headset.c
===================================================================
RCS file: /cvsroot/bluez/utils/audio/headset.c,v
retrieving revision 1.155

headset.c +6 -4
diff -u -5 -p -r1.155 headset.c
@@ -250,19 +250,21 @@ static int terminate_call(struct device 
 
 	dbus_connection_emit_signal(device->conn, device->path,
 			AUDIO_HEADSET_INTERFACE, "CallTerminated",
 			DBUS_TYPE_INVALID);
 
+	err = headset_send(hs, "\r\nOK\r\n");
+	if (err < 0)
+		return err;
+
 	if (hs->ring_timer) {
 		g_source_remove(hs->ring_timer);
 		hs->ring_timer = 0;
+		/*+CIEV: (callsetup = 0)*/
+		return headset_send(hs, "\r\n+CIEV:2, 0\r\n");
 	}
 
-	err = headset_send(hs, "\r\nOK\r\n");
-	if (err < 0)
-		return err;
-
 	/*+CIEV: (call = 0)*/
 	return headset_send(hs, "\r\n+CIEV:2, 0\r\n");
 }
 
 static int signal_gain_setting(struct device *device, const char *buf)

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace

_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#3 lore raw

PATCH 1/1 - default device as hfp

In reply to Pavel Semerad

Hi Johan,

Attaching a patch which fixes a HFP bug in headset.c

When a default device/stored device is registered, it cannot be used as a handsfree (i.e hs->hfp_active = false) because the following condition in rfcomm_connect_cb() fails.

if (server_is_enabled(HANDSFREE_SVCLASS_ID) && hs->hfp_handle != 0)

This is because, hs->hfp_handle is not populated for the default device.As a matter of fact, hs->hsp_handle is not populated either. verified this by printing the handles.

The 2 handles are ONLY populated through a call to headset_init() with its 2nd and 3rd arguments not being zero.

I have tested this patch with my setup.

Let me know if my logic is wrong or the patch needs to be changed.

Thanks,
Alok.

Index: audio/headset.c
===================================================================
RCS file: /cvsroot/bluez/utils/audio/headset.c,v
retrieving revision 1.156

headset.c +6 -0
diff -u -5 -p -r1.156 headset.c
@@ -752,10 +752,16 @@ static void get_record_reply(DBusPending
 		|| (uuid.type == SDP_UUID16 && uuid.value.uuid16 != id)) {
 		error("Service classes did not contain the expected UUID");
 		goto failed_not_supported;
 	}
 
+	if ((uuid.value.uuid32 == HANDSFREE_SVCLASS_ID)
+		|| (uuid.value.uuid16 == HANDSFREE_SVCLASS_ID)) {
+		hs->hfp_handle = record->handle;
+	}else
+		hs->hsp_handle = record->handle;
+
 	if (!sdp_get_access_protos(record, &protos)) {
 		ch = sdp_get_proto_port(protos, RFCOMM_UUID);
 		sdp_list_foreach(protos, (sdp_list_func_t) sdp_list_free,
 					NULL);
 		sdp_list_free(protos, NULL);

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace

_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#4 lore raw

PATCH 1/1 - Setting the inband Ringtone

In reply to Pavel Semerad

Hi Johan,

Here is a patch to change the In-BandRingtone setting through a D-Bus method.

Let me know if the Method/Signal names are fine with you.

Ill send the patch for the audio-api.txt next.

Do you think we shud have a DBus method call to Identify the type of headset i.e HSP/HFP? A method like "IsHFP" which returns the value of hs->hfp_active will be useful. Otherwise there is no way to know (apart for reading /etc/bluetooth/audio.conf) what profile is active.

Let me know if anything in the patch needs to be changed. -Alok.

Index: audio/headset.c
===================================================================
RCS file: /cvsroot/bluez/utils/audio/headset.c,v
retrieving revision 1.156

headset.c +59 -0
diff -u -5 -p -r1.156 headset.c
@@ -1447,10 +1453,67 @@ static DBusHandlerResult hf_setup_call(D
 	send_message_and_unref(conn, reply);
 
 	return DBUS_HANDLER_RESULT_HANDLED;
 }
 
+static DBusHandlerResult hf_set_inband(DBusConnection *conn,
+						DBusMessage *msg,
+						void *data)
+{
+	struct device *device = data;
+	struct headset *hs = device->headset;
+	DBusMessage *reply;
+	DBusError derr;
+	gboolean *active;
+	int err;
+
+	if (!hs->hfp_active)
+		return error_not_supported(device->conn, msg);
+
+	if (hs->state < HEADSET_STATE_CONNECTED)
+		return error_not_connected(conn, msg);
+
+	dbus_error_init(&derr);
+	dbus_message_get_args(msg, &derr, DBUS_TYPE_BOOLEAN, &active,
+				DBUS_TYPE_INVALID);
+
+	if (dbus_error_is_set(&derr)) {
+		error_invalid_arguments(conn, msg, derr.message);
+		dbus_error_free(&derr);
+		return DBUS_HANDLER_RESULT_HANDLED;
+	}
+
+	reply = dbus_message_new_method_return(msg);
+	if (!reply)
+		return DBUS_HANDLER_RESULT_NEED_MEMORY;
+
+	if (active && !(ag_features & AG_FEATURE_INBAND_RINGTONE)) {
+		ag_features |= AG_FEATURE_INBAND_RINGTONE;
+		err = headset_send(hs, "\r\n+BSIR:1\r\n");
+	}
+
+	if (!active && (ag_features & AG_FEATURE_INBAND_RINGTONE)) {
+		ag_features &= ~AG_FEATURE_INBAND_RINGTONE;
+		err = headset_send(hs, "\r\n+BSIR:0\r\n");
+	}
+
+	if (err < 0) {
+		dbus_message_unref(reply);
+		return error_failed(conn, msg, "Unable to send to headset");
+	}
+
+	dbus_connection_emit_signal(conn, device->path,
+						AUDIO_HEADSET_INTERFACE,
+						"InBandSettingChanged",
+						DBUS_TYPE_BOOLEAN, &active,
+						DBUS_TYPE_INVALID);
+
+	send_message_and_unref(conn, reply);
+
+	return DBUS_HANDLER_RESULT_HANDLED;
+}
+
 static DBusMethodVTable headset_methods[] = {
 	{ "Connect",		hs_connect,		"",	""	},
 	{ "Disconnect",		hs_disconnect,		"",	""	},
 	{ "IsConnected",	hs_is_connected,	"",	"b"	},
 	{ "IndicateCall",	hs_ring,		"",	""	},
@@ -1461,10 +1524,11 @@ static DBusMethodVTable headset_methods[
 	{ "GetSpeakerGain",	hs_get_speaker_gain,	"",	"q"	},
 	{ "GetMicrophoneGain",	hs_get_mic_gain,	"",	"q"	},
 	{ "SetSpeakerGain",	hs_set_speaker_gain,	"q",	""	},
 	{ "SetMicrophoneGain",	hs_set_mic_gain,	"q",	""	},
 	{ "SetupCall",		hf_setup_call,		"s",	""	},
+	{ "SetInbandRingtone",	hf_set_inband,		"b",	""	},
 	{ NULL, NULL, NULL, NULL }
 };
 
 static DBusSignalVTable headset_signals[] = {
 	{ "Connected",			""	},
@@ -1473,10 +1537,11 @@ static DBusSignalVTable headset_signals[
 	{ "Stopped",			""	},
 	{ "Playing",			""	},
 	{ "SpeakerGainChanged",		"q"	},
 	{ "MicrophoneGainChanged",	"q"	},
 	{ "CallTerminated",		""	},
+	{ "InBandSettingChanged",	"b"	},
 	{ NULL, NULL }
 };
 
 static void headset_set_channel(struct headset *headset, sdp_record_t *record)
 {

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace

_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel