[Freeswitch-svn] [commit] r11692 - freeswitch/branches/gmaruzz/mod_skypiax

FreeSWITCH SVN gmaruzz at freeswitch.org
Sun Feb 8 08:05:32 PST 2009


Author: gmaruzz
Date: Sun Feb  8 10:05:32 2009
New Revision: 11692

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 10:05:32 2009
@@ -43,6 +43,26 @@
   return howmany;
 }
 #endif /* WIN32 */
+#if defined(WIN32) && !defined(__CYGWIN__)
+int skypiax_close_socket(unsigned int fd)
+{
+	int res;
+
+	res = closesocket(fd);
+
+  return res;
+}
+#else /* WIN32 */
+int skypiax_close_socket(unsigned int fd)
+{
+	int res;
+
+	res = close(fd);
+
+  return res;
+}
+#endif /* WIN32 */
+
 
 void *skypiax_do_tcp_srv_thread_func(void *obj)
 {
@@ -125,15 +145,23 @@
         if (len == 320) {
           unsigned int howmany;
 
-          if (SAMPLERATE_SKYPIAX == 8000) {
-            a = 0;
-	    /* we're downsampling from 16khz to 8khz, srv_out will contain each other sample from srv_in */
-            for (i = 0; i < len / sizeof(short); i++) {
-              srv_out[a] = srv_in[i];
-              i++;
-              a++;
-            }
-	    /* if not yet done, let's store half incoming frame */
+	  if (SAMPLERATE_SKYPIAX == 8000) {
+		  /* we're downsampling from 16khz to 8khz, srv_out will contain each other sample from srv_in */
+		  a = 0;
+		  for (i = 0; i < len / sizeof(short); i++) {
+			  srv_out[a] = srv_in[i];
+			  i++;
+			  a++;
+		  }
+	  } else if (SAMPLERATE_SKYPIAX == 16000) {
+		  /* we're NOT downsampling from 16khz to 8khz, srv_out will contain ALL samples from srv_in */
+		  for (i = 0; i < len / sizeof(short); i++) {
+			  srv_out[i] = srv_in[i];
+		  }
+	  } else {
+		  ERRORA("SAMPLERATE_SKYPIAX can only be 8000 or 16000\n", SKYPIAX_P_LOG);
+	  }
+	    /* if not yet done, let's store the half incoming frame */
             if (!tech_pvt->audiobuf_is_loaded) {
               for (i = 0; i < SAMPLES_PER_FRAME / 2; i++) {
                 tech_pvt->audiobuf[i] = srv_out[i];
@@ -157,36 +185,6 @@
               tech_pvt->audiobuf_is_loaded = 0;
             }
 
-          } else if (SAMPLERATE_SKYPIAX == 16000) {
-	    /* if not yet done, let's store half incoming frame */
-            if (!tech_pvt->audiobuf_is_loaded) {
-              for (i = 0; i < SAMPLES_PER_FRAME / 2; i++) {
-                tech_pvt->audiobuf[i] = srv_in[i];
-              }
-              tech_pvt->audiobuf_is_loaded = 1;
-            } else {
-	    /* we got a stored half frame, build a complete frame in totalbuf using the stored half frame and the current half frame */
-              for (i = 0; i < (SAMPLES_PER_FRAME / 2); i++){
-                totalbuf[i] = tech_pvt->audiobuf[i];
-	      }
-              for (a = 0; a < (SAMPLES_PER_FRAME / 2); a++) {
-                totalbuf[i] = srv_in[a];
-                i++;
-              }
-
-	      /* send the complete frame through the pipe to our code waiting for incoming audio */
-              howmany = skypiax_file_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, SAMPLES_PER_FRAME * sizeof(short));
-	      }
-	    /* done with the stored half frame */
-              tech_pvt->audiobuf_is_loaded = 0;
-            }
-
-          } else {
-            ERRORA("SAMPLERATE_SKYPIAX can only be 8000 or 16000\n", SKYPIAX_P_LOG);
-          }
-
         } else if (len == 0) {
           DEBUGA_SKYPE("Skype client GONE\n", SKYPIAX_P_LOG);
           skypiax_sleep(1000);
@@ -215,21 +213,13 @@
     len = skypiax_file_write(tech_pvt->audioskypepipe[1], kill_cli_buff, kill_cli_size);
 
     DEBUGA_SKYPE("Skype client GONE\n", SKYPIAX_P_LOG);
-#if defined(WIN32) && !defined(__CYGWIN__)
-    closesocket(fd);
-#else
-    close(fd);
-#endif
+    skypiax_close_socket(fd);
     if (exit)
       break;
   }
 
   DEBUGA_SKYPE("server (I am it) GONE\n", SKYPIAX_P_LOG);
-#if defined(WIN32) && !defined(__CYGWIN__)
-  closesocket(s);
-#else
-  close(s);
-#endif
+  skypiax_close_socket(s);
   if (option_debug > 100) {
     DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
   }
@@ -281,11 +271,7 @@
     if (option_debug > 100) {
       DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
     }
-#if defined(WIN32) && !defined(__CYGWIN__)
-    closesocket(s);
-#else
-    close(s);
-#endif
+    skypiax_close_socket(s);
     return NULL;
   }
   DEBUGA_SKYPE("started tcp_cli_thread thread.\n", SKYPIAX_P_LOG);
@@ -396,20 +382,12 @@
 
     }
     DEBUGA_SKYPE("Skype server GONE\n", SKYPIAX_P_LOG);
-#if defined(WIN32) && !defined(__CYGWIN__)
-    closesocket(s);
-#else
-    close(fd);
-#endif
+    skypiax_close_socket(s);
     break;
   }
 
   DEBUGA_SKYPE("client (I am it) GONE\n", SKYPIAX_P_LOG);
-#if defined(WIN32) && !defined(__CYGWIN__)
-  closesocket(s);
-#else
-  close(s);
-#endif
+  skypiax_close_socket(s);
   if (option_debug > 100) {
     DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
   }



More information about the Freeswitch-svn mailing list