Revision
16724
Author
gmaruzz
Date
2010-02-22 16:13:59 -0600 (Mon, 22 Feb 2010)

Log Message

skypiax: no more tcp ports in config, timing tweakings

Modified Paths

Diff

Modified: freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c (16723 => 16724)


--- freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c	2010-02-22 19:46:34 UTC (rev 16723)
+++ freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c	2010-02-22 22:13:59 UTC (rev 16724)
@@ -167,6 +167,7 @@
 	private_t SKYPIAX_INTERFACES[SKYPIAX_MAX_INTERFACES];
 	switch_mutex_t *mutex;
 	private_t *sk_console;
+	int start_port;
 } globals;
 
 switch_endpoint_interface_t *skypiax_endpoint_interface;
@@ -1448,6 +1449,7 @@
 		}
 	}
 
+	globals.start_port=32769;
 	if ((interfaces = switch_xml_child(cfg, "per_interface_settings"))) {
 		int i = 0;
 
@@ -1716,6 +1718,8 @@
 					switch_sleep(10000);
 					skypiax_signaling_write(&globals.SKYPIAX_INTERFACES[interface_id], "SET WINDOWSTATE HIDDEN");
 					switch_sleep(10000);
+					skypiax_signaling_write(&globals.SKYPIAX_INTERFACES[interface_id], "SET USERSTATUS ONLINE");
+					switch_sleep(10000);
 				} else {
 					ERRORA
 						("The Skype client to which we are connected FAILED to gave us CURRENTUSERHANDLE=%s, interface_id=%d FAILED to start. No Skype client logged in as '%s' has been found. Please (re)launch a Skype client logged in as '%s'. Skypiax exiting now\n",
@@ -2831,6 +2835,14 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
+int next_port(void){
+	switch_mutex_lock(globals.mutex);
+	globals.start_port++;
+	if(globals.start_port == 65000)
+		globals.start_port=32769;
+	switch_mutex_unlock(globals.mutex);
+	return (globals.start_port - 1);
+}
 
 
 /* For Emacs:

Modified: freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax.h (16723 => 16724)


--- freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax.h	2010-02-22 19:46:34 UTC (rev 16723)
+++ freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax.h	2010-02-22 22:13:59 UTC (rev 16724)
@@ -339,3 +339,4 @@
 int skypiax_socket_create_and_bind(private_t * tech_pvt, unsigned short *which_port);
 #endif //WIN32
 int incoming_chatmessage(private_t * tech_pvt, int which);
+int next_port(void);

Modified: freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax_protocol.c (16723 => 16724)


--- freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax_protocol.c	2010-02-22 19:46:34 UTC (rev 16723)
+++ freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax_protocol.c	2010-02-22 22:13:59 UTC (rev 16724)
@@ -55,6 +55,7 @@
 	if (*which_port != 0)
 		start_port = *which_port;
 
+	start_port=next_port();
 	my_addr.sin_port = htons(start_port);
 	//fcntl(s, F_SETFL, O_NONBLOCK);
 	//tech_pvt->tcp_cli_port = start_port;
@@ -501,8 +502,11 @@
 					DEBUGA_SKYPE("Skype FAILED on skype_call %s. Let's wait for the FAILED message.\n", SKYPIAX_P_LOG, id);
 				}
 				if (!strcasecmp(prop, "DURATION")) { /* each second, we sync ithe timers */
+					if(!((atoi(value) % 5))){
 					switch_core_timer_sync(&tech_pvt->timer_read);
 					switch_core_timer_sync(&tech_pvt->timer_write);
+					DEBUGA_SKYPE("Synching on skype_call: %s.\n", SKYPIAX_P_LOG, id);
+					}
 				}
 				if (!strcasecmp(prop, "DURATION") && (!strcasecmp(value, "1"))) {
 					if (strcasecmp(id, tech_pvt->skype_call_id)) {
@@ -1134,10 +1138,12 @@
 #endif //0
 
 
+#if 0
 if(tech_pvt->begin_to_write==0){
 skypiax_sleep(1000);
 continue;
 }
+#endif//0
 					 if (tech_pvt->timer_write.timer_interface && tech_pvt->timer_write.timer_interface->timer_next) {
 		switch_core_timer_next(&tech_pvt->timer_write);
 }
@@ -1364,6 +1370,7 @@
 
 				if (!(running && tech_pvt->running))
 					break;
+				skypiax_sleep(2000);
 				while (tech_pvt->interface_state != SKYPIAX_STATE_DOWN
 						&& (tech_pvt->skype_callflow == CALLFLOW_STATUS_INPROGRESS
 							|| tech_pvt->skype_callflow == CALLFLOW_STATUS_EARLYMEDIA
@@ -1382,10 +1389,6 @@
 					to.tv_usec = 60000;	//60 msec
 					to.tv_sec = 0;
 
-					if(tech_pvt->begin_to_read==0){
-						skypiax_sleep(1000);
-						continue;
-					}
 					rt = select(fdselect + 1, &fs, NULL, NULL, &to);
 					if (rt > 0) {
 
@@ -1394,6 +1397,12 @@
 						} else {
 							continue;
 						}
+#if 1
+					if(tech_pvt->begin_to_read==0){
+							DEBUGA_SKYPE("len=%d, expected 640\n", SKYPIAX_P_LOG, len);
+						continue;
+					}
+#endif //0
 
 						if (len == -1) {
 							DEBUGA_SKYPE("len=%d, error: %s\n", SKYPIAX_P_LOG, len,  strerror(errno));
@@ -1404,13 +1413,14 @@
 							switch_buffer_write(tech_pvt->read_buffer, srv_in, len);
 							switch_mutex_unlock(tech_pvt->mutex_audio_srv);
 						} else if (len == 0) {
-							DEBUGA_SKYPE("CLOSING, len=%d, expected 640\n", SKYPIAX_P_LOG, len);
+							DEBUGA_SKYPE("CLOSED, len=%d, expected 640\n", SKYPIAX_P_LOG, len);
 							break;
 						} else {
 							DEBUGA_SKYPE("len=%d, expected 640\n", SKYPIAX_P_LOG, len);
 						}
 
 					} else if(rt==0){
+						DEBUGA_SKYPE("SRV rt=%d\n", SKYPIAX_P_LOG, rt);
 						continue;
 					} else {
 						DEBUGA_SKYPE("SRV rt=%d\n", SKYPIAX_P_LOG, rt);
@@ -1534,11 +1544,22 @@
 					fdselect = fd;
 					FD_SET(fdselect, &fs);
 
+						if (tech_pvt->timer_write.timer_interface && tech_pvt->timer_write.timer_interface->timer_next && tech_pvt->interface_state != SKYPIAX_STATE_HANGUP_REQUESTED) {
+							switch_core_timer_next(&tech_pvt->timer_write);
+						}
+#if 1
 
 					if(tech_pvt->begin_to_write==0){
-						skypiax_sleep(1000);
-						continue;
+							memset(cli_out, 255, sizeof(cli_out));
+							bytes_to_write = 320;
+							len = send(fd, (char *)cli_out, bytes_to_write, 0);
+							if (len == -1) {
+								DEBUGA_SKYPE("len=%d, error: %s\n", SKYPIAX_P_LOG, len,  strerror(errno));
+								break;
+							}
+							continue;
 					}
+#endif//0
 
 					//rt = select(fdselect + 1, NULL, &fs, NULL, &to);
 					//if(rt==-1)
@@ -1548,9 +1569,9 @@
 					if (rt > 0) {
 
 							//DEBUGA_SKYPE("before!\n", SKYPIAX_P_LOG);
-						if (tech_pvt->timer_write.timer_interface && tech_pvt->timer_write.timer_interface->timer_next && tech_pvt->interface_state != SKYPIAX_STATE_HANGUP_REQUESTED) {
-							switch_core_timer_next(&tech_pvt->timer_write);
-						}
+						//if (tech_pvt->timer_write.timer_interface && tech_pvt->timer_write.timer_interface->timer_next && tech_pvt->interface_state != SKYPIAX_STATE_HANGUP_REQUESTED) {
+							//switch_core_timer_next(&tech_pvt->timer_write);
+						//}
 							//DEBUGA_SKYPE("after!\n", SKYPIAX_P_LOG);
 						bytes_to_write=0;
 						waitin=0;
@@ -1581,6 +1602,7 @@
 							}
 						}
 					} else if(rt==0){
+						DEBUGA_SKYPE("CLI rt=%d\n", SKYPIAX_P_LOG, rt);
 						continue;
 					} else {
 						DEBUGA_SKYPE("CLI rt=%d\n", SKYPIAX_P_LOG, rt);