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

FreeSWITCH SVN gmaruzz at freeswitch.org
Tue Dec 16 05:56:17 PST 2008


Author: gmaruzz
Date: Tue Dec 16 08:56:16 2008
New Revision: 10791

Log:
skypiax: beginning native samplerate on linux

Modified:
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c
   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	Tue Dec 16 08:56:16 2008
@@ -107,7 +107,7 @@
     p->tech_pvt = tech_pvt;
 
   }
-  if (skypiax_codec(tech_pvt, 8000, 20) != SWITCH_STATUS_SUCCESS) {
+  if (skypiax_codec(tech_pvt, 16000, 20) != SWITCH_STATUS_SUCCESS) {
     switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "skypiax_docec FAILED\n");
   } else {
     switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "skypiax_codec SUCCESS\n");
@@ -390,9 +390,10 @@
   }
 #endif
 
-  sent = frame->datalen;
+  sent = frame->datalen/sizeof(short);
+  //ERRORA("CLI to be sent %d\n", SKYPIAX_P_LOG, sent);
   switch_file_write(p->audioskypepipe[1], (short *) frame->data, &sent);
-  //ERRORA("sent %d\n", SKYPIAX_P_LOG, sent);
+  //ERRORA("CLI sent %d\n", SKYPIAX_P_LOG, sent);
 
   return SWITCH_STATUS_SUCCESS;
 

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	Tue Dec 16 08:56:16 2008
@@ -37,13 +37,13 @@
 /**********************************************************/
 /**********************************************************/
 /**********************************************************/
-#define SAMPLES_PER_FRAME 160
+#define SAMPLES_PER_FRAME 320
 
 static void *SWITCH_THREAD_FUNC skypiax_do_tcp_srv_thread(switch_thread_t * thread,
                                                           void *obj)
 {
   struct skypiax_interface *p = obj;
-  short srv_out[SAMPLES_PER_FRAME / 2];
+  //short srv_out[SAMPLES_PER_FRAME / 2];
   int s;
 #ifdef WIN32
   unsigned int len;
@@ -53,10 +53,10 @@
   int sin_size;
   unsigned int fd;
 #else
-  int len;
-  int i;
-  int a;
-  short srv_in[SAMPLES_PER_FRAME];
+  int len = 0;
+  //int i;
+  //int a;
+  short srv_in[SAMPLES_PER_FRAME * 2];
   unsigned int sin_size;
   int fd;
 #endif /* WIN32 */
@@ -65,6 +65,8 @@
   int exit = 0;
   unsigned int kill_cli_size;
   short kill_cli_buff[320];
+  int i;
+  int a;
 
   if (option_debug > 10) {
     WARNINGA("ENTERING FUNC\n", SKYPIAX_P_LOG);
@@ -118,16 +120,61 @@
       fdselect = fd;
       FD_ZERO(&fs);
       FD_SET(fdselect, &fs);
-      to.tv_usec = 10000;
+      to.tv_usec = 100000;
       to.tv_sec = 0;
       rt = select(fdselect + 1, &fs, NULL, NULL, &to);
-	  //usleep(1000);
+	  //switch_sleep(10000);
 	  //rt=1;
       if (rt > 0) {
 
-        len = recv(fd, srv_in, sizeof(short) * SAMPLES_PER_FRAME, 0);
+        len = recv(fd, srv_in, SAMPLES_PER_FRAME * sizeof(short), 0);
         //DEBUGA_SKYPE("recv %d\n", SKYPIAX_P_LOG, len);
         if (len > 0) {
+			if(len == SAMPLES_PER_FRAME * sizeof(short)) {
+            unsigned int howmany;
+
+            howmany = len / sizeof(short);
+            switch_file_write(p->audiopipe[1], srv_in, &howmany);
+			if(howmany == 320){
+            NOTICA("SRV=====> req=%d recv=%d to sent=%d sent=%d\n", SKYPIAX_P_LOG, SAMPLES_PER_FRAME * sizeof(short), len, len / sizeof(short), howmany);
+			} else {
+            ERRORA("SRV=====> req=%d recv=%d to sent=%d sent=%d\n", SKYPIAX_P_LOG, SAMPLES_PER_FRAME * sizeof(short), len, len / sizeof(short), howmany);
+			switch_sleep(1000);
+			}
+			} else {
+
+          if (!p->audiobuf_is_loaded) {
+            for (i = 0; i < (len / sizeof(short)); i++) {
+              p->audiobuf[i] = srv_in[i];
+            }
+            p->audiobuf_is_loaded = 1;
+          } else {
+            unsigned int howmany;
+            short totalbuf[SAMPLES_PER_FRAME];
+
+            howmany = len / 2 ;
+            for (i = 0; i < howmany; i++)
+              totalbuf[i] = p->audiobuf[i];
+
+            howmany = len / 2 ;
+            for (a = 0; a < howmany; a++) {
+              totalbuf[i] = srv_in[a];
+              i++;
+            }
+
+            howmany = SAMPLES_PER_FRAME;
+
+            switch_file_write(p->audiopipe[1], totalbuf, &howmany);
+            p->audiobuf_is_loaded = 0;
+            DEBUGA_SKYPE("SRV=====> req=%d recv=%d to sent=%d sent=%d\n", SKYPIAX_P_LOG, sizeof(short)*SAMPLES_PER_FRAME, len, SAMPLES_PER_FRAME, howmany);
+          }
+
+
+
+
+			}
+
+#if 0
           a = 0;
           for (i = 0; i < len / sizeof(short); i++) {
             srv_out[a] = srv_in[i];
@@ -161,6 +208,7 @@
             //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);
           }
 
+#endif
         } else if (len == 0) {
           DEBUGA_SKYPE("Skype client GONE\n", SKYPIAX_P_LOG);
           break;
@@ -223,9 +271,9 @@
   unsigned int fd;
 #else
   int len;
-  int i;
-  int a;
-  short cli_in[SAMPLES_PER_FRAME / 2];
+  //int i;
+  //int a;
+  //short cli_in[SAMPLES_PER_FRAME / 2];
   short cli_out[SAMPLES_PER_FRAME];
   unsigned int sin_size;
   int fd;
@@ -288,9 +336,17 @@
       to.tv_usec = 10000;
       to.tv_sec = 0;
       //rt = select(fdselect + 1, &fs, NULL, NULL, &to);
-	  switch_sleep(5000);
+	  switch_sleep(1000);
       rt = 1;
       if (rt > 0) {
+        //got = (SAMPLES_PER_FRAME / 2) * sizeof(short);
+        got = SAMPLES_PER_FRAME;
+        switch_file_read(p->audioskypepipe[0], cli_out, &got);
+        if (got > 0) {
+          len = send(fd, cli_out, got * sizeof(short), 0);
+            NOTICA("CLI=====> req=%d recv=%d to sent=%d sent=%d\n", SKYPIAX_P_LOG, SAMPLES_PER_FRAME, got, got*sizeof(short), len);
+		}
+#if 0
 
         got = (SAMPLES_PER_FRAME / 2) * sizeof(short);
         switch_file_read(p->audioskypepipe[0], cli_in, &got);
@@ -314,6 +370,7 @@
           switch_sleep(1000);
           //ERRORA("Audio skype pipe give us: %u\n", SKYPIAX_P_LOG, got);
         }
+#endif
       }
 
     }
@@ -352,7 +409,7 @@
 
   rv =
     switch_file_pipe_create(&p->audioskypepipe[0], &p->audioskypepipe[1], skypiax_module_pool);
-  rv = switch_file_pipe_timeout_set(p->audioskypepipe[0], 100);
+  rv = switch_file_pipe_timeout_set(p->audioskypepipe[0], 100000);
   if (option_debug > 10) {
     DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
   }
@@ -372,22 +429,24 @@
 
   memset(buf, '\0', sizeof(buf));
 
+  //switch_sleep(10000);
   rt = 1;
   if (rt > 0) {
 
-    samples = SAMPLES_PER_FRAME * sizeof(short);
+    samples = SAMPLES_PER_FRAME;
 
     switch_file_read(p->audiopipe[0], tech_pvt->read_frame.data, &samples);
 
     //if ((samples = read(p->audiopipe[0], buf, SAMPLES_PER_FRAME * sizeof(short))) != 320) 
-    if (samples != SAMPLES_PER_FRAME * sizeof(short)) {
-      if (samples)
-        DEBUGA_SKYPE("read=====> NOT GOOD samples=%d expected=%d\n", SKYPIAX_P_LOG,
-                     samples, SAMPLES_PER_FRAME * sizeof(short));
+    if (samples != SAMPLES_PER_FRAME) {
+      if (samples){
+        DEBUGA_SKYPE("SRV=====> NOT GOOD samples=%d expected=%d\n", SKYPIAX_P_LOG, samples, SAMPLES_PER_FRAME);
+      //tech_pvt->read_frame.datalen = 0;
       //do nothing
+	  }
     } else {
-      tech_pvt->read_frame.datalen = samples;
-      //DEBUGA_SKYPE("read=====> GOOD samples=%d\n", SKYPIAX_P_LOG, samples);
+      tech_pvt->read_frame.datalen = samples * sizeof(short);
+      NOTICA("SRV=====> GOOD samples=%d\n", SKYPIAX_P_LOG, samples);
       /* A real frame */
     }
   } else {



More information about the Freeswitch-branches mailing list