[Freeswitch-branches] [commit] r10977 - freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax

FreeSWITCH SVN gmaruzz at freeswitch.org
Sun Dec 28 03:25:02 PST 2008


Author: gmaruzz
Date: Sun Dec 28 06:25:01 2008
New Revision: 10977

Log:
skypiax: using real pipes on linux

Modified:
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax.h
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c

Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c	Sun Dec 28 06:25:01 2008
@@ -393,9 +393,16 @@
 
   sent = frame->datalen;
   //DEBUGA_SKYPE("CLI PIPE to write %d\n", SKYPIAX_P_LOG, sent);
+#ifdef WIN32 
   switch_file_write(p->audioskypepipe[1], frame->data, &sent);
-  if(sent != frame->datalen)
+#else /* WIN32 */
+  sent = write(p->audioskypepipe[1], frame->data, sent);
+#endif /* WIN32 */
+  if(sent != frame->datalen){
 	ERRORA("CLI PIPE write %d\n", SKYPIAX_P_LOG, sent);
+  }else{
+	//NOTICA("CLI PIPE write %d\n", SKYPIAX_P_LOG, sent);
+  }
 
   return SWITCH_STATUS_SUCCESS;
 
@@ -958,7 +965,11 @@
   p = &globals.SKYPIAX_INTERFACES[interface_id];
 
 if(globals.SKYPIAX_INTERFACES[interface_id].skypiax_do_controldev_thread_thread){
+#ifdef WIN32
   switch_file_write(p->AsteriskHandlesAst.fdesc[1], "sciutati", &howmany);  // let's the controldev_thread die
+#else /* WIN32 */
+          write(p->AsteriskHandlesAst.fdesc[1], "sciutati", howmany);
+#endif /* WIN32 */
   }
 
 if(globals.SKYPIAX_INTERFACES[interface_id].skypiax_do_skype_thread_thread){

Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax.h
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax.h	(original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax.h	Sun Dec 28 06:25:01 2008
@@ -137,7 +137,7 @@
   Display *disp;
   Window win;
 int api_connected;
-  switch_file_t *fdesc[2];
+  int fdesc[2];
 };
 #else //WIN32
 
@@ -192,8 +192,13 @@
   int skype_callflow;           /*!< \brief 'callflow' of the skype interface (as opposed to phone interface) */
   int skype;                    /*!< \brief config flag, bool, Skype support on this interface (0 if false, -1 if true) */
   int control_to_send;
+#ifdef WIN32
   switch_file_t *audiopipe[2];
   switch_file_t *audioskypepipe[2];
+#else /* WIN32 */
+  int audiopipe[2];
+  int audioskypepipe[2];
+#endif /* WIN32 */
   switch_thread_t *tcp_srv_thread;
   switch_thread_t *tcp_cli_thread;
   switch_thread_t *skypiax_do_controldev_thread_thread;

Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c	Sun Dec 28 06:25:01 2008
@@ -1,4 +1,5 @@
 #include "skypiax.h"
+#include <netinet/tcp.h>
 
 extern switch_memory_pool_t *skypiax_module_pool;
 extern int option_debug;
@@ -53,6 +54,8 @@
   int exit = 0;
   unsigned int kill_cli_size;
   short kill_cli_buff[SAMPLES_PER_FRAME];
+  short totalbuf[SAMPLES_PER_FRAME];
+  //int one = 1;
 
   if (option_debug > 10) {
     WARNINGA("ENTERING FUNC\n", SKYPIAX_P_LOG);
@@ -70,6 +73,8 @@
     return NULL;
   }
 
+  //setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one));
+
   if (bind(s, (struct sockaddr *) &my_addr, sizeof(struct sockaddr)) < 0) {
     ERRORA("bind Error\n", SKYPIAX_P_LOG);
     if (option_debug > 10) {
@@ -78,7 +83,6 @@
     return NULL;
   }
   DEBUGA_SKYPE("started tcp_srv_thread thread.\n", SKYPIAX_P_LOG);
-    ERRORA("sizeof(short)=%d, sizeof(char)=%d\n", SKYPIAX_P_LOG, sizeof(short), sizeof(char));
 
   listen(s, 6);
 
@@ -107,7 +111,7 @@
       fdselect = fd;
       FD_ZERO(&fs);
       FD_SET(fdselect, &fs);
-      to.tv_usec = 50000;
+      to.tv_usec = 2000000; //20 msec
       to.tv_sec = 0;
 
       rt = select(fdselect + 1, &fs, NULL, NULL, &to);
@@ -138,7 +142,6 @@
 				      p->audiobuf_is_loaded = 1;
 			      } else {
 				      unsigned int howmany;
-				      short totalbuf[SAMPLES_PER_FRAME];
 
 				      howmany = len / 2 / 2;
 				      for (i = 0; i < howmany; i++)
@@ -152,7 +155,11 @@
 
 				      howmany = len;
 
+#ifdef WIN32 
 				      switch_file_write(p->audiopipe[1], totalbuf, &howmany);
+#else /* WIN32 */
+				      howmany = write(p->audiopipe[1], totalbuf, howmany);
+#endif /* WIN32 */
 				      p->audiobuf_is_loaded = 0;
 				      //DEBUGA_SKYPE("read=====> req=%d recv=%d to sent=%d sent=%d\n", SKYPIAX_P_LOG, sizeof(short)*SAMPLES_PER_FRAME, len, (len*sizeof(short))/2, howmany);
 			      }
@@ -177,7 +184,11 @@
 
 						WARNINGA("SRV recv %d\n", SKYPIAX_P_LOG, len);
 
+#ifdef WIN32 
 				      switch_file_write(p->audiopipe[1], srv_in, &howmany);
+#else /* WIN32 */
+				      howmany = write(p->audiopipe[1], srv_in, howmany);
+#endif /* WIN32 */
 				      p->audiobuf_is_loaded = 0;
 				      WARNINGA("SRV PIPE WRITE=====> req=%d recv=%d to sent=%d sent=%d\n", SKYPIAX_P_LOG, sizeof(short)*SAMPLES_PER_FRAME, len, len, howmany);
 			      }else if (len == SAMPLES_PER_FRAME * sizeof(short) / 2) {
@@ -192,7 +203,7 @@
 					      p->audiobuf_is_loaded = 1;
 				      } else {
 					      unsigned int howmany = SAMPLES_PER_FRAME * sizeof(short);
-					      short totalbuf[SAMPLES_PER_FRAME];
+					      //short totalbuf[SAMPLES_PER_FRAME];
 
 					      for (i = 0; i < (len / sizeof(short)); i++)
 						      totalbuf[i] = p->audiobuf[i];
@@ -201,7 +212,11 @@
 						      i++;
 					      }
 
+#ifdef WIN32 
 					      switch_file_write(p->audiopipe[1], totalbuf, &howmany);
+#else /* WIN32 */
+					      howmany = write(p->audiopipe[1], totalbuf, howmany);
+#endif /* WIN32 */
 					      p->audiobuf_is_loaded = 0;
 					      //NOTICA("SRV PIPE WRITE=====> req=%d recv=%d to sent=%d sent=%d\n", SKYPIAX_P_LOG, SAMPLES_PER_FRAME * sizeof(short), len, SAMPLES_PER_FRAME * sizeof(short), howmany);
 				      }
@@ -235,10 +250,13 @@
 	      }
       } else {
 
-		 ERRORA("SRV rt=%d\n", SKYPIAX_P_LOG, rt);
+		  if(rt)
+			ERRORA("SRV rt=%d\n", SKYPIAX_P_LOG, rt);
+		  switch_sleep(10000);
 	  }
     }
 
+#ifdef WIN32 
     kill_cli_size = SAMPLES_PER_FRAME * sizeof(short);
     switch_file_write(p->audiopipe[1], kill_cli_buff, &kill_cli_size);
     kill_cli_size = SAMPLES_PER_FRAME * sizeof(short);
@@ -248,6 +266,17 @@
     switch_file_write(p->audiopipe[1], kill_cli_buff, &kill_cli_size);
     kill_cli_size = SAMPLES_PER_FRAME * sizeof(short);
     switch_file_write(p->audioskypepipe[1], kill_cli_buff, &kill_cli_size);
+#else /* WIN32 */
+    kill_cli_size = SAMPLES_PER_FRAME * sizeof(short);
+    write(p->audiopipe[1], kill_cli_buff, kill_cli_size);
+    kill_cli_size = SAMPLES_PER_FRAME * sizeof(short);
+    write(p->audioskypepipe[1], kill_cli_buff, kill_cli_size);
+    p->interface_state = SKYPIAX_STATE_DOWN;
+    kill_cli_size = SAMPLES_PER_FRAME * sizeof(short);
+    write(p->audiopipe[1], kill_cli_buff, kill_cli_size);
+    kill_cli_size = SAMPLES_PER_FRAME * sizeof(short);
+    write(p->audioskypepipe[1], kill_cli_buff, kill_cli_size);
+#endif /* WIN32 */
 
     DEBUGA_SKYPE("Skype client GONE\n", SKYPIAX_P_LOG);
 
@@ -297,6 +326,7 @@
   short cli_out[SAMPLES_PER_FRAME * 2];
   short cli_in[SAMPLES_PER_FRAME];
 #endif /* WIN32 */
+  //int one = 1;
 
   if (option_debug > 10) {
     WARNINGA("ENTERING FUNC\n", SKYPIAX_P_LOG);
@@ -314,6 +344,8 @@
     return NULL;
   }
 
+  //setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one));
+
   if (bind(s, (struct sockaddr *) &my_addr, sizeof(struct sockaddr)) < 0) {
     ERRORA("bind Error\n", SKYPIAX_P_LOG);
     if (option_debug > 10) {
@@ -349,21 +381,33 @@
 
       if (!running)
         break;
-      fdselect = fd;
+#ifdef WIN32
+      fdselect = fd; //cannot select on audioskypepipe, let's select on socket write
+#else /* WIN32 */
+      fdselect = p->audioskypepipe[0];
+#endif /* WIN32 */
       FD_ZERO(&fs);
       FD_SET(fdselect, &fs);
-      to.tv_usec = 50000; //50msec
+      to.tv_usec = 2000000; //20 msec
       to.tv_sec = 0;
 
-      rt = select(fdselect + 1, NULL, &fs, NULL, &to);
+#ifdef WIN32
+      rt = select(fdselect + 1, NULL, &fs, NULL, &to);//cannot select on audioskypepipe, let's select on socket write
+#else /* WIN32 */
+      rt = select(fdselect + 1, &fs, NULL, NULL, &to);
+#endif /* WIN32 */
 	  //switch_sleep(1000);//FIXME
-	  memset(cli_in, '\0', sizeof(cli_in));
-      //rt = 1;
+	  //memset(cli_in, '\0', sizeof(cli_in));
+      //rt = 0;
 	  if (rt > 0) {
 			  /*********************************************/
 		  if ((SAMPLERATE_SKYPIAX - 8000) == 0) {
 			  got = SAMPLES_PER_FRAME * sizeof(short);
+#ifdef WIN32 
 			  switch_file_read(p->audioskypepipe[0], cli_in, &got);
+#else /* WIN32 */
+			  got = read(p->audioskypepipe[0], cli_in, got);
+#endif /* WIN32 */
 
 			  if (got > 0) {
 				  //DEBUGA_SKYPE("CLI PIPE read %d\n", SKYPIAX_P_LOG, got);
@@ -396,7 +440,11 @@
 			  /*********************************************/
 		  else if (SAMPLERATE_SKYPIAX == 16000) {
 			  got = SAMPLES_PER_FRAME * sizeof(short);
+#ifdef WIN32 
 			  switch_file_read(p->audioskypepipe[0], cli_in, &got);
+#else /* WIN32 */
+			  got = read(p->audioskypepipe[0], cli_in, got);
+#endif /* WIN32 */
 
 			  if (got > 0) {
 				  if(got != SAMPLES_PER_FRAME * sizeof(short) )
@@ -422,7 +470,11 @@
 		  }
 		  /*********************************************/
 
-	  }
+	  } else {
+				  switch_sleep(1000);
+				  if(rt)
+					ERRORA("select give us: %u\n", SKYPIAX_P_LOG, rt);
+			  }
 
     }
     DEBUGA_SKYPE("Skype server GONE\n", SKYPIAX_P_LOG);
@@ -449,17 +501,26 @@
 int skypiax_skypeaudio_init(struct skypiax_interface *p)
 {
 
-  switch_status_t rv;
 
+#ifdef WIN32
+  switch_status_t rv;
   rv =
     switch_file_pipe_create(&p->audiopipe[0], &p->audiopipe[1], skypiax_module_pool);
+  rv =
+    switch_file_pipe_create(&p->audioskypepipe[0], &p->audioskypepipe[1], skypiax_module_pool);
+#else /* WIN32 */
+  pipe(p->audiopipe);
+  fcntl(p->audiopipe[0], F_SETFL, O_NONBLOCK);
+  fcntl(p->audiopipe[1], F_SETFL, O_NONBLOCK);
+  pipe(p->audioskypepipe);
+  fcntl(p->audioskypepipe[0], F_SETFL, O_NONBLOCK);
+  fcntl(p->audioskypepipe[1], F_SETFL, O_NONBLOCK);
+#endif /* WIN32 */
   //rv = switch_file_pipe_timeout_set(p->audiopipe[0], 100);
 
 /* the pipe is our audio fd for pbx to poll on */
-  p->skypiax_sound_capt_fd = p->audiopipe[0];
+  //p->skypiax_sound_capt_fd = p->audiopipe[0];
 
-  rv =
-    switch_file_pipe_create(&p->audioskypepipe[0], &p->audioskypepipe[1], skypiax_module_pool);
   //rv = switch_file_pipe_timeout_set(p->audioskypepipe[0], 20000);
   if (option_debug > 10) {
     DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
@@ -472,18 +533,40 @@
   struct skypiax_interface *p;
   unsigned int samples;
   int rt;
+#ifndef WIN32
+  int fdselect;
+  fd_set fs;
+  struct timeval to;
+#endif /* WIN32 */
+
 
   p = tech_pvt->p;
 
   //DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG);
 
-
+#ifdef WIN32
   rt = 1;
+#else /* WIN32 */
+
+  fdselect = p->audiopipe[0];
+  FD_ZERO(&fs);
+  FD_SET(fdselect, &fs);
+  to.tv_usec = 2000000; //20 msec
+  to.tv_sec = 0;
+  rt = select(fdselect + 1, &fs, NULL, NULL, &to);
+#endif /* WIN32 */
+
   if (rt > 0) {
 
     samples = SAMPLES_PER_FRAME * sizeof(short);
 
+#ifdef WIN32
     switch_file_read(p->audiopipe[0], tech_pvt->read_frame.data, &samples);
+#else /* WIN32 */
+
+	//samples = read(p->audiopipe[0], buf, SAMPLES_PER_FRAME * sizeof(short));
+    samples = read(p->audiopipe[0], tech_pvt->read_frame.data, samples);
+#endif /* WIN32 */
 
     if (samples != SAMPLES_PER_FRAME * sizeof(short)) {
       if (samples)
@@ -496,7 +579,8 @@
       /* A real frame */
     }
   } else {
-    DEBUGA_SKYPE("select returned %d\n", SKYPIAX_P_LOG, rt);
+	  if(rt)
+		DEBUGA_SKYPE("select returned %d\n", SKYPIAX_P_LOG, rt);
 
   }
 
@@ -943,7 +1027,10 @@
   p = obj;
   DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG);
 
-  switch_file_pipe_create(&p->AsteriskHandlesAst.fdesc[0], &p->AsteriskHandlesAst.fdesc[1], skypiax_module_pool);
+  //switch_file_pipe_create(&p->AsteriskHandlesAst.fdesc[0], &p->AsteriskHandlesAst.fdesc[1], skypiax_module_pool);
+  pipe(p->AsteriskHandlesAst.fdesc);
+  fcntl(p->AsteriskHandlesAst.fdesc[0], F_SETFL, O_NONBLOCK);
+  fcntl(p->AsteriskHandlesAst.fdesc[1], F_SETFL, O_NONBLOCK);
 
   //switch_file_pipe_timeout_set(p->AsteriskHandlesAst.fdesc[0], 100);
   AsteriskHandlesAst = &p->AsteriskHandlesAst;
@@ -1037,7 +1124,8 @@
 
           howmany = strlen(b) + 1;
 
-          switch_file_write(AsteriskHandlesAst->fdesc[1], b, &howmany);
+          //switch_file_write(AsteriskHandlesAst->fdesc[1], b, &howmany);
+          write(AsteriskHandlesAst->fdesc[1], b, howmany);
           //write(AsteriskHandlesAst->fdesc[1], "\0", 1);
           //FIXME DEBUGA_SKYPE("SKYPE pipewrite: |||%s|||len=%d serial=%ld\n\n\n", SKYPIAX_P_LOG, b, strlen(b) + 1, an_event.xclient.serial);
           //switch_sleep(1000);
@@ -1135,13 +1223,15 @@
   char messaggio_2[4096];
   char *buf, obj[512] = "", id[512] = "", prop[512] = "", value[512] = "", *where;
   char **stringp = NULL;
-  //int fd;
   int rt;
-  //fd_set fs;
-  //struct timeval to;
   int a;
   unsigned int howmany;
   unsigned int i;
+#ifndef WIN32
+  int fdselect;
+  fd_set fs;
+  struct timeval to;
+#endif /* WIN32 */
 
   if (option_debug > 100) {
     DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG);
@@ -1151,11 +1241,27 @@
   memset(messaggio, 0, 4096);
   memset(messaggio_2, 0, 4096);
 
+#ifdef WIN32
   rt = 1;
-  //if (rt > 0) {
+#else /* WIN32 */
+
+  fdselect = p->AsteriskHandlesAst.fdesc[0];
+  FD_ZERO(&fs);
+  FD_SET(fdselect, &fs);
+  to.tv_usec = 2000000; //500 msec
+  to.tv_sec = 0;
+  rt = select(fdselect + 1, &fs, NULL, NULL, &to);
+#endif /* WIN32 */
+
+  if (rt > 0) {
   if (p->AsteriskHandlesAst.fdesc[0]) {
     howmany = sizeof(read_from_pipe);
+#ifdef WIN32
     switch_file_read(p->AsteriskHandlesAst.fdesc[0], read_from_pipe, &howmany);
+#else /* WIN32 */
+    howmany =
+      read(p->AsteriskHandlesAst.fdesc[0], read_from_pipe, sizeof(read_from_pipe));
+#endif /* WIN32 */
 
     a = 0;
     for (i = 0; i < howmany; i++) {
@@ -1592,6 +1698,7 @@
     }                           //read_from_pipe
 
   }
+  }
 
   if (option_debug > 100) {
     DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);



More information about the Freeswitch-branches mailing list