[asterisk-addons-commits] mnicholson: branch mnicholson/chan-mobile-refactor r785 - /team/mnicholson/ch...

SVN commits to the Asterisk addons project asterisk-addons-commits at lists.digium.com
Thu Feb 19 16:20:02 CST 2009


Author: mnicholson
Date: Thu Feb 19 16:20:02 2009
New Revision: 785

URL: http://svn.digium.com/svn-view/asterisk-addons?view=rev&rev=785
Log:
Attempt to fix headset audio.

Modified:
    team/mnicholson/chan-mobile-refactor/channels/chan_mobile.c

Modified: team/mnicholson/chan-mobile-refactor/channels/chan_mobile.c
URL: http://svn.digium.com/svn-view/asterisk-addons/team/mnicholson/chan-mobile-refactor/channels/chan_mobile.c?view=diff&rev=785&r1=784&r2=785
==============================================================================
--- team/mnicholson/chan-mobile-refactor/channels/chan_mobile.c (original)
+++ team/mnicholson/chan-mobile-refactor/channels/chan_mobile.c Thu Feb 19 16:20:02 2009
@@ -2761,8 +2761,14 @@
 
 	struct mbl_pvt *pvt = (struct mbl_pvt *)data;
 	char buf[256];
-	int t;
+	int t, zero = 0;
 	at_message_t at_msg;
+	struct io_context *io = NULL;
+
+	if (!(io = io_context_create())) {
+		ast_log(LOG_ERROR, "Unable to create I/O context for headset audio connections\n");
+		goto e_cleanup;
+	}
 
 	pvt->state = MBL_STATE_PREIDLE;
 
@@ -2773,7 +2779,7 @@
 		else
 			t = 1000;
 		
-		if (rfcomm_wait(pvt->rfcomm_socket, &t)) {
+		if (!ast_io_wait(io, t) && rfcomm_wait(pvt->rfcomm_socket, &zero)) {
 			if ((at_msg = at_read_full(pvt->rfcomm_socket, buf, sizeof(buf))) < 0) {
 				if (strerror_r(errno, buf, sizeof(buf)))
 					ast_debug(1, "[%s] error reading from device\n", pvt->id); 
@@ -2822,6 +2828,12 @@
 			} else if (pvt->state == MBL_STATE_RING) {
 				pvt->sco_socket = sco_connect(pvt->adapter->addr, pvt->addr);
 				if (pvt->sco_socket > -1) {
+					if (!ast_io_add(io, pvt->sco_socket, sco_read, AST_IO_IN, pvt)) {
+						ast_log(LOG_ERROR, "error monitoring new audio connection for device %s\n", pvt->id);
+						ast_queue_control(pvt->owner, AST_CONTROL_HANGUP);
+						close(pvt->sco_socket);
+						break;
+					}
 					ast_setstate(pvt->owner, AST_STATE_RINGING);
 					ast_queue_control(pvt->owner, AST_CONTROL_RINGING);
 					pvt->state = MBL_STATE_RING2;
@@ -2838,11 +2850,14 @@
 
 	}
 
-	if (pvt->rfcomm_socket > -1)
-		close(pvt->rfcomm_socket);
-	if (pvt->sco_socket > -1)
-		close(pvt->sco_socket);
+e_cleanup:
+	if (io)
+		io_context_destroy(io);
+
+	close(pvt->rfcomm_socket);
+	close(pvt->sco_socket);
 	pvt->sco_socket = -1;
+
 	pvt->connected = 0;
 
 	manager_event(EVENT_FLAG_SYSTEM, "MobileStatus", "Status: Disconnect\r\nDevice: %s\r\n", pvt->id);




More information about the asterisk-addons-commits mailing list