Revision
16633
Author
gmaruzz
Date
2010-02-13 10:54:24 -0600 (Sat, 13 Feb 2010)

Log Message

skypiax: restored a previous wrong commit

Modified Paths

Diff

Modified: freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c (16632 => 16633)


--- freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c	2010-02-13 11:10:30 UTC (rev 16632)
+++ freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c	2010-02-13 16:54:24 UTC (rev 16633)
@@ -36,12 +36,7 @@
 
 #include "skypiax.h"
 #define MDL_CHAT_PROTO "skype"
-#define TIMERS_ON
-#ifdef TIMERS_ON
 #define TIMER_WRITE
-#else
-#undef TIMER_WRITE
-#endif
 
 #ifdef WIN32
 /***************/
@@ -263,7 +258,6 @@
 		return SWITCH_STATUS_FALSE;
 	}
 
-#ifdef TIMERS_ON
 	if (switch_core_timer_init(&tech_pvt->timer_read, "soft", 20, tech_pvt->read_codec.implementation->samples_per_packet, skypiax_module_pool) !=
 		SWITCH_STATUS_SUCCESS) {
 		ERRORA("setup timer failed\n", SKYPIAX_P_LOG);
@@ -271,7 +265,6 @@
 	}
 
 	switch_core_timer_sync(&tech_pvt->timer_read);
-#endif// TIMERS_ON
 
 #ifdef TIMER_WRITE
 	if (switch_core_timer_init(&tech_pvt->timer_write, "soft", 20, tech_pvt->write_codec.implementation->samples_per_packet, skypiax_module_pool) !=
@@ -489,9 +482,7 @@
 			switch_core_codec_destroy(&tech_pvt->write_codec);
 		}
 
-#ifdef TIMERS_ON
 		switch_core_timer_destroy(&tech_pvt->timer_read);
-#endif// TIMERS_ON
 #ifdef TIMER_WRITE
 
 		switch_core_timer_destroy(&tech_pvt->timer_write);
@@ -684,7 +675,6 @@
 	switch_channel_t *channel = NULL;
 	private_t *tech_pvt = NULL;
 	switch_byte_t *data;
-//unsigned int len;
 
 	channel = switch_core_session_get_channel(session);
 	switch_assert(channel != NULL);
@@ -703,15 +693,8 @@
 
 	//switch_core_timer_next(&tech_pvt->timer_read);
 
-						if (tech_pvt->skype_callflow != CALLFLOW_STATUS_REMOTEHOLD) {
-							tech_pvt->read_frame.datalen = recv(tech_pvt->readfd, (char *) tech_pvt->read_frame.data, 320, 0);	//seems that Skype only sends 320 bytes at time
-						} else {
-							tech_pvt->read_frame.datalen = 0;
-						}
+	if (!skypiax_audio_read(tech_pvt)) {
 
-	//if (!skypiax_audio_read(tech_pvt)) {
-	if (!tech_pvt->read_frame.datalen) {
-
 		ERRORA("skypiax_audio_read ERROR\n", SKYPIAX_P_LOG);
 
 	} else {
@@ -736,9 +719,7 @@
 				DEBUGA_SKYPE("CHANNEL READ CONTINUE\n", SKYPIAX_P_LOG);
 				continue;
 			}
-#ifdef TIMERS_ON
 			switch_core_timer_check(&tech_pvt->timer_read, SWITCH_TRUE);
-#endif// TIMERS_ON
 			*frame = &tech_pvt->read_frame;
 #if SWITCH_BYTE_ORDER == __BIG_ENDIAN
 			if (switch_test_flag(tech_pvt, TFLAG_LINEAR)) {
@@ -771,7 +752,7 @@
 {
 	switch_channel_t *channel = NULL;
 	private_t *tech_pvt = NULL;
-	unsigned int sent=0;
+	unsigned int sent;
 
 	channel = switch_core_session_get_channel(session);
 	switch_assert(channel != NULL);
@@ -790,50 +771,25 @@
 	}
 #endif
 
-#if 0
 	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 == 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);
 #endif // TIMER_WRITE
 
-	//while (tech_pvt->flag_audio_cli == 1) {
-		//switch_sleep(1000);		//10 millisec
-						//WARNINGA("write now is 1\n", SKYPIAX_P_LOG);
-	//}
-	switch_mutex_lock(tech_pvt->flag_audio_cli_mutex);
 		memcpy(tech_pvt->audiobuf_cli, frame->data, frame->datalen);
 		tech_pvt->flag_audio_cli = 1;
-	switch_mutex_unlock(tech_pvt->flag_audio_cli_mutex);
-	//}
+	}
 	//NOTICA("write \n", SKYPIAX_P_LOG);
-#endif //0
 
-#ifdef TIMER_WRITE
-/* NONBLOCKING ? */
-		switch_core_timer_next(&tech_pvt->timer_write);
-		//switch_core_timer_check(&tech_pvt->timer_write, SWITCH_TRUE);
-#endif // TIMER_WRITE
-	/* send the 16khz frame to the Skype client waiting for incoming audio to be sent to the remote party */
-								if (tech_pvt->skype_callflow != CALLFLOW_STATUS_REMOTEHOLD) {
-									sent = send(tech_pvt->writefd, (char *) frame->data, frame->datalen, 0);
-									if (sent == -1) {
-										ERRORA("EXIT? sent=%d\n", SKYPIAX_P_LOG, sent);
-									} else if (sent != frame->datalen) {
-										ERRORA("sent=%d\n", SKYPIAX_P_LOG, sent);
-									}
-								}
-
-
-#ifdef TIMER_WRITE
-/* BLOCKING ? */
-		//switch_core_timer_check(&tech_pvt->timer_write, SWITCH_TRUE);
-#endif // TIMER_WRITE
 	if (sent != frame->datalen && sent != -1) {
 		DEBUGA_SKYPE("CLI PIPE write %d\n", SKYPIAX_P_LOG, sent);
 	}
@@ -874,9 +830,7 @@
 		{
 			DEBUGA_SKYPE("MSG_ID=%d, TO BE ANSWERED!\n", SKYPIAX_P_LOG, msg->message_id);
 
-#ifdef TIMERS_ON
 			switch_core_timer_sync(&tech_pvt->timer_read);
-#endif// TIMERS_ON
 #ifdef TIMER_WRITE
 			switch_core_timer_sync(&tech_pvt->timer_write);
 #endif // TIMER_WRITE
@@ -887,9 +841,7 @@
 
 		DEBUGA_SKYPE("%s CHANNEL got SWITCH_MESSAGE_INDICATE_AUDIO_SYNC\n", SKYPIAX_P_LOG, switch_channel_get_name(channel));
 
-#ifdef TIMERS_ON
 		switch_core_timer_sync(&tech_pvt->timer_read);
-#endif// TIMERS_ON
 #ifdef TIMER_WRITE
 		switch_core_timer_sync(&tech_pvt->timer_write);
 #endif // TIMER_WRITE
@@ -897,9 +849,7 @@
 	default:
 		{
 
-#ifdef TIMERS_ON
 			switch_core_timer_sync(&tech_pvt->timer_read);
-#endif// TIMERS_ON
 #ifdef TIMER_WRITE
 
 			switch_core_timer_sync(&tech_pvt->timer_write);
@@ -1444,8 +1394,6 @@
 
 				skypiax_audio_init(&globals.SKYPIAX_INTERFACES[interface_id]);
 
-	switch_mutex_init(&globals.SKYPIAX_INTERFACES[interface_id].flag_audio_srv_mutex, SWITCH_MUTEX_NESTED, skypiax_module_pool);
-	switch_mutex_init(&globals.SKYPIAX_INTERFACES[interface_id].flag_audio_cli_mutex, 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",
 					 SKYPIAX_P_LOG, interface_id);

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


--- freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax.h	2010-02-13 11:10:30 UTC (rev 16632)
+++ freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax.h	2010-02-13 16:54:24 UTC (rev 16633)
@@ -29,7 +29,6 @@
  * Further Contributors:
  *
  *
- *
  * mod_skypiax.c -- Skype compatible Endpoint Module
  *
  */
@@ -192,8 +191,6 @@
 	switch_caller_profile_t *caller_profile;
 	switch_mutex_t *mutex;
 	switch_mutex_t *flag_mutex;
-	switch_mutex_t *flag_audio_cli_mutex;
-	switch_mutex_t *flag_audio_srv_mutex;
 
 	char interface_id[80];
 	char name[80];
@@ -281,8 +278,6 @@
 	uint32_t report_incoming_chatmessages;
 	switch_timer_t timer_read;
 	switch_timer_t timer_write;
-unsigned int writefd;
-unsigned int readfd;
 };
 
 typedef struct private_object private_t;

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


--- freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax_protocol.c	2010-02-13 11:10:30 UTC (rev 16632)
+++ freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax_protocol.c	2010-02-13 16:54:24 UTC (rev 16633)
@@ -55,9 +55,8 @@
 		start_port = *which_port;
 
 	my_addr.sin_port = htons(start_port);
-/* NONBLOCKING ? */
 	//fcntl(s, F_SETFL, O_NONBLOCK);
-
+	//tech_pvt->tcp_cli_port = start_port;
 	*which_port = start_port;
 	while (bind(s, (struct sockaddr *) &my_addr, sizeof(struct sockaddr)) < 0) {
 		DEBUGA_SKYPE("*which_port=%d, tech_pvt->tcp_cli_port=%d, tech_pvt->tcp_srv_port=%d\n", SKYPIAX_P_LOG, *which_port, tech_pvt->tcp_cli_port,
@@ -119,7 +118,6 @@
 	size = sizeof(int);
 	setsockopt(s, SOL_SOCKET, SO_SNDBUF, (char *) &sockbufsize, size);
 
-
 	sockbufsize = 0;
 	size = sizeof(int);
 	getsockopt(s, SOL_SOCKET, SO_SNDBUF, (char *) &sockbufsize, &size);
@@ -724,22 +722,22 @@
 	private_t *tech_pvt = obj;
 	int s;
 	unsigned int len;
-	//unsigned int i;
-	//unsigned int a;
+	unsigned int i;
+	unsigned int a;
 #if defined(WIN32) && !defined(__CYGWIN__)
 	int sin_size;
 #else /* WIN32 */
 	unsigned int sin_size;
 #endif /* WIN32 */
 	unsigned int fd;
-	//short srv_in[SAMPLES_PER_FRAME];
-	//short srv_out[SAMPLES_PER_FRAME / 2];
+	short srv_in[SAMPLES_PER_FRAME];
+	short srv_out[SAMPLES_PER_FRAME / 2];
 	//struct sockaddr_in my_addr;
 	struct sockaddr_in remote_addr;
 	//int exit = 0;
 	unsigned int kill_cli_size;
 	short kill_cli_buff[SAMPLES_PER_FRAME];
-	//short totalbuf[SAMPLES_PER_FRAME];
+	short totalbuf[SAMPLES_PER_FRAME];
 	int sockbufsize = 0;
 	unsigned int size = sizeof(int);
 
@@ -799,13 +797,6 @@
 						   || tech_pvt->skype_callflow == CALLFLOW_STATUS_EARLYMEDIA
 						   || tech_pvt->skype_callflow == CALLFLOW_STATUS_REMOTEHOLD || tech_pvt->skype_callflow == SKYPIAX_STATE_UP)) {
 
-					tech_pvt->readfd = fd;
-						//WARNINGA("read HERE\n", SKYPIAX_P_LOG);
-						skypiax_sleep(100000);
-
-
-#ifdef NOLOOP
-
 					unsigned int fdselect;
 					int rt;
 					fd_set fs;
@@ -875,16 +866,13 @@
 
 
 								howmany = SAMPLES_PER_FRAME * sizeof(short);
-								//while (tech_pvt->flag_audio_srv == 1) {
-									//switch_sleep(1000);	//10 millisec
-						//WARNINGA("read now is 1\n", SKYPIAX_P_LOG);
-								//}
-								//if (tech_pvt->flag_audio_srv == 0) {
-	//switch_mutex_lock(tech_pvt->flag_audio_srv_mutex);
+								if (tech_pvt->flag_audio_srv == 1) {
+									switch_sleep(1000);	//1 millisec
+								}
+								if (tech_pvt->flag_audio_srv == 0) {
 									memcpy(tech_pvt->audiobuf_srv, totalbuf, SAMPLES_PER_FRAME * sizeof(short));
 									tech_pvt->flag_audio_srv = 1;
-	//switch_mutex_unlock(tech_pvt->flag_audio_srv_mutex);
-								//}
+								}
 								//NOTICA("read \n", SKYPIAX_P_LOG);
 								if (howmany != SAMPLES_PER_FRAME * sizeof(short)) {
 									ERRORA("howmany is %d, but was expected to be %d\n", SKYPIAX_P_LOG,
@@ -906,7 +894,6 @@
 						skypiax_sleep(10000);
 					}
 
-#endif// NOLOOP
 				}
 
 				/* let's send some frame in the pipes, so both tcp_cli and tcp_srv will have an occasion to die */
@@ -931,7 +918,6 @@
 				skypiax_sleep(2000);
 				DEBUGA_SKYPE("Skype incoming audio GONE\n", SKYPIAX_P_LOG);
 				skypiax_close_socket(fd);
-				break;
 			}
 		}
 	}
@@ -948,15 +934,13 @@
 	int s;
 	//struct sockaddr_in my_addr;
 	struct sockaddr_in remote_addr;
-#ifdef NOVARS
 	unsigned int got;
 	unsigned int len;
 	unsigned int i;
 	unsigned int a;
+	unsigned int fd;
 	short cli_out[SAMPLES_PER_FRAME * 2];
 	short cli_in[SAMPLES_PER_FRAME];
-#endif// NOVARS
-	unsigned int fd;
 #ifdef WIN32
 	int sin_size;
 #else
@@ -1025,19 +1009,10 @@
 
 				if (!(running && tech_pvt->running))
 					break;
-
-
-
-
 				while (tech_pvt->interface_state != SKYPIAX_STATE_DOWN
 					   && (tech_pvt->skype_callflow == CALLFLOW_STATUS_INPROGRESS
 						   || tech_pvt->skype_callflow == CALLFLOW_STATUS_EARLYMEDIA
 						   || tech_pvt->skype_callflow == CALLFLOW_STATUS_REMOTEHOLD || tech_pvt->skype_callflow == SKYPIAX_STATE_UP)) {
-					tech_pvt->writefd = fd;
-						//NOTICA("write HERE\n", SKYPIAX_P_LOG);
-						skypiax_sleep(100000);
-#if 0
-#ifdef NOVARS
 					unsigned int fdselect;
 					int rt;
 					fd_set fs;
@@ -1064,46 +1039,32 @@
 					fdselect = fd;
 					FD_SET(fdselect, &fs);
 
-#endif// NOVARS
-#if 0
-					rt = select(fdselect + 1, NULL, &fs, NULL, NULL);
+					//FIXME rt = select(fdselect + 1, NULL, &fs, NULL, &to);
 					while (tech_pvt->flag_audio_cli == 0) {
 #ifdef WIN32
 						skypiax_sleep(100);	//0.1 millisec
 #else
-						skypiax_sleep(1000);	//10 millisec
+						skypiax_sleep(1000);	//1 millisec
 #endif //WIN32
-						NOTICA("write now is 0\n", SKYPIAX_P_LOG);
+						//WARNINGA("write now is 0\n", SKYPIAX_P_LOG);
 					}
 					//ERRORA("write is now 1\n", SKYPIAX_P_LOG);
 
 					rt = 1;
-#endif //0
-					//rt = select(fdselect + 1, NULL, &fs, NULL, NULL);
 
-#ifdef NOLOOP
 					if (rt > 0) {
 						int counter;
-#if 0
-					while (tech_pvt->flag_audio_cli == 0) {
-#ifdef WIN32
-						skypiax_sleep(100);	//0.1 millisec
-#else
-						skypiax_sleep(10000);	//10 millisec
-#endif //WIN32
-						WARNINGA("write now is 0\n", SKYPIAX_P_LOG);
-					}
-#endif //0
-	
+
 						/* until we drained the pipe to empty */
+						//for (counter = 0; counter < 10; counter++) {
 						for (counter = 0; counter < 1; counter++) {
 							/* read from the pipe the audio frame we are supposed to send out */
 							//got = skypiax_pipe_read(tech_pvt->audiopipe_cli[0], cli_in, SAMPLES_PER_FRAME * sizeof(short));
 
 
 							got = SAMPLES_PER_FRAME * sizeof(short);
-	switch_mutex_lock(tech_pvt->flag_audio_cli_mutex);
 							memcpy(cli_in, tech_pvt->audiobuf_cli, SAMPLES_PER_FRAME * sizeof(short));
+							tech_pvt->flag_audio_cli = 0;
 
 
 
@@ -1139,7 +1100,6 @@
 								/* send the 16khz frame to the Skype client waiting for incoming audio to be sent to the remote party */
 								if (tech_pvt->skype_callflow != CALLFLOW_STATUS_REMOTEHOLD) {
 									len = send(fd, (char *) cli_out, got, 0);
-							tech_pvt->flag_audio_cli = 0;
 									//skypiax_sleep(5000);  //5 msec
 
 									if (len == -1) {
@@ -1151,7 +1111,6 @@
 									}
 								}
 
-	switch_mutex_unlock(tech_pvt->flag_audio_cli_mutex);
 							} else {
 
 								WARNINGA("got is %d, but was expected to be %d\n", SKYPIAX_P_LOG, got, (int) (SAMPLES_PER_FRAME * sizeof(short)));
@@ -1174,12 +1133,9 @@
 						skypiax_sleep(1000);
 					}
 
-#endif// NOLOOP
-#endif// 0
 				}
 				DEBUGA_SKYPE("Skype outbound audio GONE\n", SKYPIAX_P_LOG);
 				skypiax_close_socket(fd);
-				break;
 			}
 		}
 	}
@@ -1194,24 +1150,20 @@
 {
 	unsigned int samples;
 
-#if 0
 	while (tech_pvt->flag_audio_srv == 0) {
 #ifdef WIN32
 		skypiax_sleep(100);		//0.1 millisec
 #else
-		skypiax_sleep(1000);	//10 millisec
+		skypiax_sleep(1000);	//1 millisec
 #endif //WIN32
 
-		WARNINGA("read now is 0\n", SKYPIAX_P_LOG);
+		//WARNINGA("read now is 0\n", SKYPIAX_P_LOG);
 	}
-#endif //0
 	//ERRORA("read is now 1\n", SKYPIAX_P_LOG);
 	//samples = skypiax_pipe_read(tech_pvt->audiopipe_srv[0], tech_pvt->read_frame.data, SAMPLES_PER_FRAME * sizeof(short));
 	samples = SAMPLES_PER_FRAME * sizeof(short);
-	//switch_mutex_lock(tech_pvt->flag_audio_srv_mutex);
 	memcpy(tech_pvt->read_frame.data, tech_pvt->audiobuf_srv, SAMPLES_PER_FRAME * sizeof(short));
 	tech_pvt->flag_audio_srv = 0;
-	//switch_mutex_unlock(tech_pvt->flag_audio_srv_mutex);
 
 	if (samples != SAMPLES_PER_FRAME * sizeof(short)) {
 		if (samples)