Revision
16664
Author
gmaruzz
Date
2010-02-16 16:33:56 -0600 (Tue, 16 Feb 2010)

Log Message

skypiax: new write timing, perfect on linux, let's check on windoz. Long live Tony

Modified Paths

Diff

Modified: freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c (16663 => 16664)


--- freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c	2010-02-16 22:30:47 UTC (rev 16663)
+++ freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c	2010-02-16 22:33:56 UTC (rev 16664)
@@ -752,7 +752,7 @@
 	switch_channel_t *channel = NULL;
 	private_t *tech_pvt = NULL;
 	unsigned int sent;
-
+//cicopet
 	channel = switch_core_session_get_channel(session);
 	switch_assert(channel != NULL);
 
@@ -770,23 +770,27 @@
 	}
 #endif
 
+tech_pvt->begin_to_write=1;
 	sent = frame->datalen;
 #ifdef WIN32
 	//switch_file_write(tech_pvt->audiopipe_cli[1], frame->data, &sent);
 #else /* WIN32 */
 	//sent = write(tech_pvt->audiopipe_cli[1], frame->data, sent);
 #endif /* WIN32 */
-	if (tech_pvt->flag_audio_cli == 1) {
-		switch_sleep(1000);		//1 millisec
-	}
-	if (tech_pvt->flag_audio_cli == 0) {
+	//if (tech_pvt->flag_audio_cli == 1) {
+		//switch_sleep(1000);		//1 millisec
+	//}
+	//if (tech_pvt->flag_audio_cli == 0) {
 #ifdef TIMER_WRITE
-		switch_core_timer_next(&tech_pvt->timer_write);
+		//switch_core_timer_next(&tech_pvt->timer_write);
 #endif // TIMER_WRITE
 
+memset(tech_pvt->audiobuf_cli, 255, sizeof(tech_pvt->audiobuf_cli));
+							switch_mutex_lock(tech_pvt->mutex_audio_cli);
 		memcpy(tech_pvt->audiobuf_cli, frame->data, frame->datalen);
 		tech_pvt->flag_audio_cli = 1;
-	}
+							switch_mutex_unlock(tech_pvt->mutex_audio_cli);
+	//}
 	//NOTICA("write \n", SKYPIAX_P_LOG);
 
 	if (sent != frame->datalen && sent != -1) {
@@ -991,7 +995,7 @@
 			switch_mutex_unlock(globals.mutex);
 			return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
 		}
-		switch_channel_set_variable(channel, "send_silence_when_idle", "1500");
+		//switch_channel_set_variable(channel, "send_silence_when_idle", "1500");
 		switch_channel_set_variable(channel, "waste", "false");
 		if (skypiax_tech_init(tech_pvt, *new_session) != SWITCH_STATUS_SUCCESS) {
 			ERRORA("Doh! no tech_init?\n", SKYPIAX_P_LOG);
@@ -1399,6 +1403,7 @@
 
 				skypiax_audio_init(&globals.SKYPIAX_INTERFACES[interface_id]);
 				switch_mutex_init(&globals.SKYPIAX_INTERFACES[interface_id].mutex_audio_srv, SWITCH_MUTEX_NESTED, skypiax_module_pool);
+				switch_mutex_init(&globals.SKYPIAX_INTERFACES[interface_id].mutex_audio_cli, SWITCH_MUTEX_NESTED, skypiax_module_pool);
 
 				NOTICA
 					("WAITING roughly 10 seconds to find a running Skype client and connect to its SKYPE API for interface_id=%d\n",
@@ -1771,6 +1776,8 @@
 {
 	switch_threadattr_t *thd_attr = NULL;
 
+tech_pvt->begin_to_write=0;
+
 	switch_threadattr_create(&thd_attr, skypiax_module_pool);
 	switch_threadattr_detach_set(thd_attr, 1);
 	switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
@@ -1814,7 +1821,7 @@
 			switch_core_session_destroy(&session);
 			return 0;
 		}
-		switch_channel_set_variable(channel, "send_silence_when_idle", "1500");
+		//switch_channel_set_variable(channel, "send_silence_when_idle", "1500");
 		switch_channel_set_variable(channel, "waste", "false");
 		if (skypiax_tech_init(tech_pvt, session) != SWITCH_STATUS_SUCCESS) {
 			ERRORA("Doh! no tech_init?\n", SKYPIAX_P_LOG);

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


--- freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax.h	2010-02-16 22:30:47 UTC (rev 16663)
+++ freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax.h	2010-02-16 22:33:56 UTC (rev 16664)
@@ -278,6 +278,7 @@
 	uint32_t report_incoming_chatmessages;
 	switch_timer_t timer_read;
 	switch_timer_t timer_write;
+int begin_to_write;
 };
 
 typedef struct private_object private_t;

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


--- freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax_protocol.c	2010-02-16 22:30:47 UTC (rev 16663)
+++ freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax_protocol.c	2010-02-16 22:33:56 UTC (rev 16664)
@@ -1045,12 +1045,12 @@
 					int rt;
 					fd_set fs;
 					struct timeval to;
+#if 0
 					int waitin;
-#if 1
 					int big_waitin=40;
 					int lil_waitin=20;
+					int big_waited;
 #endif//0
-					int big_waited;
 
 					if (!(running && tech_pvt->running))
 						break;
@@ -1073,6 +1073,7 @@
 					fdselect = fd;
 					FD_SET(fdselect, &fs);
 
+#if 0
 					//rt = select(fdselect + 1, NULL, &fs, NULL, &to);
 					waitin=0;
 					big_waited=0;
@@ -1083,7 +1084,6 @@
 						skypiax_sleep(1000);	//1 millisec
 #endif //WIN32
 						waitin++;
-#if 1
 						if(big_waited == 1 && waitin==lil_waitin && tech_pvt->flag_audio_cli == 0){
 							memset(cli_out, 255, SAMPLES_PER_FRAME * sizeof(short));
 							send(fd, (char *) cli_out, SAMPLES_PER_FRAME * sizeof(short), 0);
@@ -1100,11 +1100,20 @@
 							big_waited=1;
 							continue;
 						}
-#endif //0
 					}
 					if(waitin > 21){
 						NOTICA("waitin is now %d\n", SKYPIAX_P_LOG, waitin);
 					}
+#endif //0
+
+
+if(tech_pvt->begin_to_write==0){
+skypiax_sleep(1000);
+continue;
+}
+					 if (tech_pvt->timer_write.timer_interface && tech_pvt->timer_write.timer_interface->timer_next) {
+		switch_core_timer_next(&tech_pvt->timer_write);
+}
 					rt = 1;
 
 					if (rt > 0) {
@@ -1115,8 +1124,13 @@
 
 
 						got = SAMPLES_PER_FRAME * sizeof(short);
+							switch_mutex_lock(tech_pvt->mutex_audio_cli);
+//if(tech_pvt->flag_audio_cli == 0){
+//memset(tech_pvt->audiobuf_cli, 255, sizeof(tech_pvt->audiobuf_cli));
+//} 
 						memcpy(cli_in, tech_pvt->audiobuf_cli, SAMPLES_PER_FRAME * sizeof(short));
 						tech_pvt->flag_audio_cli = 0;
+							switch_mutex_unlock(tech_pvt->mutex_audio_cli);