[Freeswitch-branches] [commit] r11694 - freeswitch/branches/gmaruzz/mod_skypiax

FreeSWITCH SVN gmaruzz at freeswitch.org
Sun Feb 8 09:10:44 PST 2009


Author: gmaruzz
Date: Sun Feb  8 11:10:44 2009
New Revision: 11694

Log:
skypiax: cleaning skypiax_protocol.c

Modified:
   freeswitch/branches/gmaruzz/mod_skypiax/skypiax_protocol.c

Modified: freeswitch/branches/gmaruzz/mod_skypiax/skypiax_protocol.c
==============================================================================
--- freeswitch/branches/gmaruzz/mod_skypiax/skypiax_protocol.c	(original)
+++ freeswitch/branches/gmaruzz/mod_skypiax/skypiax_protocol.c	Sun Feb  8 11:10:44 2009
@@ -7,8 +7,8 @@
 extern char *skypiax_console_active;
 #else /* FREESWITCH */
 #define skypiax_sleep switch_sleep
-//#define skypiax_file_write switch_file_write
-#define skypiax_file_read switch_file_read
+//#define skypiax_pipe_write switch_file_write
+//#define skypiax_pipe_read switch_file_read
 extern switch_memory_pool_t *skypiax_module_pool;
 extern switch_endpoint_interface_t *skypiax_endpoint_interface;
 #endif /* ASTERISK */
@@ -23,8 +23,31 @@
 #endif /* WIN32 */
 /*************************************/
 
+
+#if defined(WIN32) && !defined(__CYGWIN__)
+int skypiax_pipe_read(switch_file_t * pipe, short *buf, int howmany)
+{
+  switch_size_t quantity;
+
+  quantity = howmany;
+
+  switch_file_read(pipe, buf, &quantity);
+
+  howmany = quantity;
+
+  return howmany;
+}
+#else /* WIN32 */
+int skypiax_pipe_read(int pipe, short *buf, int howmany)
+{
+  howmany = read(pipe, buf, howmany);
+  return howmany;
+}
+#endif /* WIN32 */
+
+
 #if defined(WIN32) && !defined(__CYGWIN__)
-int skypiax_file_write(switch_file_t * pipe, short *buf, int howmany)
+int skypiax_pipe_write(switch_file_t * pipe, short *buf, int howmany)
 {
   switch_size_t quantity;
 
@@ -37,12 +60,14 @@
   return howmany;
 }
 #else /* WIN32 */
-int skypiax_file_write(int pipe, short *buf, int howmany)
+int skypiax_pipe_write(int pipe, short *buf, int howmany)
 {
   howmany = write(pipe, buf, howmany);
   return howmany;
 }
 #endif /* WIN32 */
+
+
 #if defined(WIN32) && !defined(__CYGWIN__)
 int skypiax_close_socket(unsigned int fd)
 {
@@ -153,7 +178,7 @@
               a++;
             }
           } else if (SAMPLERATE_SKYPIAX == 16000) {
-            /* we're NOT downsampling from 16khz to 8khz, srv_out will contain ALL samples from srv_in */
+            /* we're NOT downsampling, srv_out will contain ALL samples from srv_in */
             for (i = 0; i < len / sizeof(short); i++) {
               srv_out[i] = srv_in[i];
             }
@@ -177,7 +202,7 @@
             }
             /* send the complete frame through the pipe to our code waiting for incoming audio */
             howmany =
-              skypiax_file_write(tech_pvt->audiopipe[1], totalbuf,
+              skypiax_pipe_write(tech_pvt->audiopipe[1], totalbuf,
                                  SAMPLES_PER_FRAME * sizeof(short));
             if (howmany != SAMPLES_PER_FRAME * sizeof(short)) {
               ERRORA("howmany is %d, but was expected to be %d\n", SKYPIAX_P_LOG, howmany,
@@ -204,17 +229,18 @@
 
     }
 
+    /* let's send some frame in the pipes, so both tcp_cli and tcp_srv will have an occasion to die */
     kill_cli_size = SAMPLES_PER_FRAME * sizeof(short);
-    len = skypiax_file_write(tech_pvt->audiopipe[1], kill_cli_buff, kill_cli_size);
+    len = skypiax_pipe_write(tech_pvt->audiopipe[1], kill_cli_buff, kill_cli_size);
     kill_cli_size = SAMPLES_PER_FRAME * sizeof(short);
-    len = skypiax_file_write(tech_pvt->audioskypepipe[1], kill_cli_buff, kill_cli_size);
+    len = skypiax_pipe_write(tech_pvt->audioskypepipe[1], kill_cli_buff, kill_cli_size);
     tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
     kill_cli_size = SAMPLES_PER_FRAME * sizeof(short);
-    len = skypiax_file_write(tech_pvt->audiopipe[1], kill_cli_buff, kill_cli_size);
+    len = skypiax_pipe_write(tech_pvt->audiopipe[1], kill_cli_buff, kill_cli_size);
     kill_cli_size = SAMPLES_PER_FRAME * sizeof(short);
-    len = skypiax_file_write(tech_pvt->audioskypepipe[1], kill_cli_buff, kill_cli_size);
+    len = skypiax_pipe_write(tech_pvt->audioskypepipe[1], kill_cli_buff, kill_cli_size);
 
-    DEBUGA_SKYPE("Skype client GONE\n", SKYPIAX_P_LOG);
+    DEBUGA_SKYPE("Skype incoming audio GONE\n", SKYPIAX_P_LOG);
     skypiax_close_socket(fd);
     if (exit)
       break;
@@ -227,6 +253,8 @@
   }
   return NULL;
 }
+
+
 void *skypiax_do_tcp_cli_thread_func(void *obj)
 {
   private_t *tech_pvt = obj;
@@ -317,11 +345,7 @@
       if (rt > 0) {
         if ((SAMPLERATE_SKYPIAX - 8000) == 0) {
           got = SAMPLES_PER_FRAME * sizeof(short);
-#if defined(WIN32) && !defined(__CYGWIN__)
-          skypiax_file_read(tech_pvt->audioskypepipe[0], cli_in, &got);
-#else /* WIN32 */
-          got = read(tech_pvt->audioskypepipe[0], cli_in, got);
-#endif /* WIN32 */
+          got = skypiax_pipe_read(tech_pvt->audioskypepipe[0], cli_in, got);
 
           if (got > 0) {
             a = 0;
@@ -347,11 +371,7 @@
           }
         } else if (SAMPLERATE_SKYPIAX == 16000) {
           got = SAMPLES_PER_FRAME * sizeof(short);
-#if defined(WIN32) && !defined(__CYGWIN__)
-          skypiax_file_read(tech_pvt->audioskypepipe[0], cli_in, &got);
-#else /* WIN32 */
-          got = read(tech_pvt->audioskypepipe[0], cli_in, got);
-#endif /* WIN32 */
+          got = skypiax_pipe_read(tech_pvt->audioskypepipe[0], cli_in, got);
 
           if (got > 0) {
             if (got != SAMPLES_PER_FRAME * sizeof(short))
@@ -450,11 +470,7 @@
 #endif /* WIN32 */
   if (rt > 0) {
     samples = SAMPLES_PER_FRAME * sizeof(short);
-#if defined(WIN32) && !defined(__CYGWIN__)
-    skypiax_file_read(tech_pvt->audiopipe[0], tech_pvt->read_frame.data, &samples);
-#else /* WIN32 */
-    samples = read(tech_pvt->audiopipe[0], tech_pvt->read_frame.data, samples);
-#endif /* WIN32 */
+    samples = skypiax_pipe_read(tech_pvt->audiopipe[0], tech_pvt->read_frame.data, samples);
 
     //ERRORA("tech_pvt->audiopipe[0] = %d\n", SKYPIAX_P_LOG, tech_pvt->audiopipe[0]);
     //ERRORA("tech_pvt->audiopipe[1] = %d\n", SKYPIAX_P_LOG, tech_pvt->audiopipe[1]);
@@ -554,7 +570,7 @@
       howmany = strlen(msg_from_skype) + 1;
 //#if defined(WIN32) && !defined(__CYGWIN__) 
       howmany =
-        skypiax_file_write(tech_pvt->SkypiaxHandles.fdesc[1], (short *) msg_from_skype,
+        skypiax_pipe_write(tech_pvt->SkypiaxHandles.fdesc[1], (short *) msg_from_skype,
                            howmany);
       //NOTICA("From Skype API: %s\n", SKYPIAX_P_LOG, msg_from_skype);
 //#else
@@ -1115,12 +1131,7 @@
   if (rt > 0) {
     if (tech_pvt->SkypiaxHandles.fdesc[0]) {
       howmany = sizeof(read_from_pipe);
-#if defined(WIN32) && !defined(__CYGWIN__)
-      skypiax_file_read(tech_pvt->SkypiaxHandles.fdesc[0], read_from_pipe, &howmany);
-#else /* WIN32 */
-      howmany =
-        read(tech_pvt->SkypiaxHandles.fdesc[0], read_from_pipe, sizeof(read_from_pipe));
-#endif /* WIN32 */
+      howmany = skypiax_pipe_read(tech_pvt->SkypiaxHandles.fdesc[0], (short *)read_from_pipe, howmany);
 
       a = 0;
       for (i = 0; i < howmany; i++) {



More information about the Freeswitch-branches mailing list