[Freeswitch-branches] [commit] r11578 - freeswitch/branches/gmaruzz/mod_skypiax/asterisk

FreeSWITCH SVN gmaruzz at freeswitch.org
Sat Jan 31 08:07:53 PST 2009


Author: gmaruzz
Date: Sat Jan 31 10:07:53 2009
New Revision: 11578

Log:
skypiax: has answered first call on asterisk, DTMF incoming works (eg. IVR), outbound audio works, incoming audio not yet

Modified:
   freeswitch/branches/gmaruzz/mod_skypiax/asterisk/chan_skypiax.c
   freeswitch/branches/gmaruzz/mod_skypiax/asterisk/skypiax.h
   freeswitch/branches/gmaruzz/mod_skypiax/asterisk/skypiax_protocol.c

Modified: freeswitch/branches/gmaruzz/mod_skypiax/asterisk/chan_skypiax.c
==============================================================================
--- freeswitch/branches/gmaruzz/mod_skypiax/asterisk/chan_skypiax.c	(original)
+++ freeswitch/branches/gmaruzz/mod_skypiax/asterisk/chan_skypiax.c	Sat Jan 31 10:07:53 2009
@@ -107,7 +107,7 @@
 /*! \brief Default skypiax_pvt structure values, 
  * used by skypiax_mkif to initialize the interfaces */
 struct skypiax_pvt skypiax_default = {
-  .interface_state = AST_STATE_DOWN,
+  .interface_state = SKYPIAX_STATE_DOWN,
   .skype_callflow = 0,
   .context = "default",
   .language = "en",
@@ -341,7 +341,7 @@
           DEBUGA_PBX("Requesting: %s, name: %s, format: %d\n", SKYPIAX_P_LOG, type, name,
                      format);
           /* create a new channel owning this interface */
-          tmp = skypiax_new(p, AST_STATE_DOWN, p->context);
+          tmp = skypiax_new(p, SKYPIAX_STATE_DOWN, p->context);
           if (!tmp) {
             /* the channel was not created, probable memory allocation error */
             *cause = AST_CAUSE_SWITCH_CONGESTION;
@@ -398,16 +398,16 @@
   if (option_debug > 10) {
     DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG);
   }
-  if (p->skype && p->interface_state != AST_STATE_DOWN) {
+  if (p->skype && p->interface_state != SKYPIAX_STATE_DOWN) {
     char msg_to_skype[1024];
-    p->interface_state = AST_STATE_HANGUP_REQUESTED;
+    p->interface_state = SKYPIAX_STATE_HANGUP_REQUESTED;
     DEBUGA_SKYPE("hanging up skype call: %s\n", SKYPIAX_P_LOG, p->skype_call_id);
     //sprintf(msg_to_skype, "SET CALL %s STATUS FINISHED", p->skype_call_id);
     sprintf(msg_to_skype, "ALTER CALL %s HANGUP", p->skype_call_id);
     skypiax_skype_write(p, msg_to_skype);
   }
 
-  while (p->interface_state != AST_STATE_DOWN) {
+  while (p->interface_state != SKYPIAX_STATE_DOWN) {
     usleep(10000);
   }
   DEBUGA_SKYPE("Now is really DOWN\n", SKYPIAX_P_LOG);
@@ -434,7 +434,7 @@
   }
   p->controldev_thread = AST_PTHREADT_NULL;
 
-  p->interface_state = AST_STATE_DOWN;
+  p->interface_state = SKYPIAX_STATE_DOWN;
   p->skype_callflow = CALLFLOW_CALL_IDLE;
 
   DEBUGA_PBX("I'll send AST_CONTROL_HANGUP\n", SKYPIAX_P_LOG);
@@ -454,7 +454,7 @@
   /* our channel has no more this skypiax pvt interface to manage */
   c->tech_pvt = NULL;
   /* set the channel state to DOWN, eg. available, not in active use */
-  if (ast_setstate(c, AST_STATE_DOWN)) {
+  if (ast_setstate(c, SKYPIAX_STATE_DOWN)) {
     ERRORA("ast_setstate failed, BAD\n", SKYPIAX_P_LOG);
     if (option_debug > 10) {
       DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
@@ -490,11 +490,11 @@
     DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG);
   }
   /* whle ringing, we just wait, the skype thread will answer */
-  while (p->interface_state == AST_STATE_RING) {
+  while (p->interface_state == SKYPIAX_STATE_RING) {
     usleep(10000);              //10msec
   }
-  if (p->interface_state != AST_STATE_UP) {
-    ERRORA("call answering failed\n", SKYPIAX_P_LOG);
+  if (p->interface_state != SKYPIAX_STATE_UP) {
+    ERRORA("call answering failed, we want it to be into interface_state=%d, got %d\n", SKYPIAX_P_LOG, SKYPIAX_STATE_UP, p->interface_state);
     res = -1;
   } else {
     if (option_debug)
@@ -603,7 +603,7 @@
   f.delivery.tv_usec = 0;
 
 /* if the call is not active (ie: answered), do not send audio frames, they would pile up in a lag queue */
-  if (p->owner && p->owner->_state != AST_STATE_UP) {
+  if (p->owner && p->owner->_state != SKYPIAX_STATE_UP) {
     if (option_debug > 100) {
       DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
     }
@@ -652,8 +652,8 @@
   if (option_debug > 10) {
     DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG);
   }
-  if ((c->_state != AST_STATE_DOWN)
-      && (c->_state != AST_STATE_RESERVED)) {
+  if ((c->_state != SKYPIAX_STATE_DOWN)
+      && (c->_state != SKYPIAX_STATE_RESERVED)) {
     ERRORA("skypiax_call called on %s, neither down nor reserved\n", SKYPIAX_P_LOG,
            c->name);
     if (option_debug > 10) {
@@ -697,7 +697,7 @@
     DEBUGA_PBX("skypiax_call dialed idest: %s, timeout: %d, dstr: %s!\n", SKYPIAX_P_LOG,
                idest, timeout, dstr);
 
-  ast_setstate(p->owner, AST_STATE_DIALING);
+  ast_setstate(p->owner, SKYPIAX_STATE_DIALING);
   if (option_debug > 10) {
     DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
   }
@@ -732,7 +732,7 @@
   if (option_debug > 100) {
     DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG);
   }
-  if (p->owner && p->owner->_state != AST_STATE_UP) {
+  if (p->owner && p->owner->_state != SKYPIAX_STATE_UP) {
     if (option_debug > 100) {
       DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
     }
@@ -862,7 +862,7 @@
       return NULL;
     }
     /* if the requested state is different from DOWN, let the pbx manage this interface (now part of the newly created channel) */
-    if (state != AST_STATE_DOWN) {
+    if (state != SKYPIAX_STATE_DOWN) {
       DEBUGA_PBX("Try to start PBX on %s, state=%d\n", SKYPIAX_P_LOG, tmp->name, state);
       if (ast_pbx_start(tmp)) {
         ERRORA("Unable to start PBX on %s\n", SKYPIAX_P_LOG, tmp->name);
@@ -1422,7 +1422,7 @@
     free(tmp);
     return NULL;
   }
-  res = pipe(tmp->AsteriskHandlesAst.fdesc);
+  res = pipe(tmp->SkypiaxHandles.fdesc);
   if (res) {
     ast_log(LOG_ERROR, "Unable to create skype pipe\n");
     if (option_debug > 10) {
@@ -1431,9 +1431,10 @@
     free(tmp);
     return NULL;
   }
-  fcntl(tmp->AsteriskHandlesAst.fdesc[0], F_SETFL, O_NONBLOCK);
-  fcntl(tmp->AsteriskHandlesAst.fdesc[1], F_SETFL, O_NONBLOCK);
+  fcntl(tmp->SkypiaxHandles.fdesc[0], F_SETFL, O_NONBLOCK);
+  fcntl(tmp->SkypiaxHandles.fdesc[1], F_SETFL, O_NONBLOCK);
   tmp->skype_thread = AST_PTHREADT_NULL;
+
   if (tmp->skype) {
     if (option_debug > 1)
       ast_log(LOG_DEBUG, "TO BE started skype_thread=%lu STOP=%lu NULL=%lu\n",
@@ -1441,7 +1442,7 @@
               (unsigned long) AST_PTHREADT_NULL);
 #ifdef __CYGWIN__
     if (ast_pthread_create
-        (&tmp->skype_thread, NULL, do_skypeapi_thread, &tmp->AsteriskHandlesAst) < 0) {
+        (&tmp->skype_thread, NULL, do_skypeapi_thread, &tmp->SkypiaxHandles) < 0) {
       ast_log(LOG_ERROR, "Unable to start skype_main thread.\n");
       if (option_debug > 10) {
         DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_TMP_LOG);
@@ -1452,7 +1453,7 @@
 #else /* __CYGWIN__ */
 #ifdef WANT_SKYPE_X11
     if (option_debug > 1)
-      ast_log(LOG_DEBUG, "AsteriskHandlesfd: %d\n", tmp->AsteriskHandlesAst.fdesc[1]);
+      ast_log(LOG_DEBUG, "AsteriskHandlesfd: %d\n", tmp->SkypiaxHandles.fdesc[1]);
     if (ast_pthread_create(&tmp->skype_thread, NULL, do_skypeapi_thread, tmp) < 0) {
       ast_log(LOG_ERROR, "Unable to start skype_main thread.\n");
       if (option_debug > 10) {
@@ -1478,6 +1479,57 @@
               (unsigned long) AST_PTHREADT_NULL);
   }
 
+
+#if 0
+  if (tmp->skype) {
+#if 0
+    if (option_debug > 1)
+      ast_log(LOG_DEBUG, "TO BE started skype_thread=%lu STOP=%lu NULL=%lu\n",
+              (unsigned long) tmp->skype_thread, (unsigned long) AST_PTHREADT_STOP,
+              (unsigned long) AST_PTHREADT_NULL);
+#endif
+#ifdef __CYGWIN__
+    if (ast_pthread_create
+        (&tmp->skype_thread, NULL, do_skypeapi_thread, &tmp->SkypiaxHandles) < 0) {
+      ast_log(LOG_ERROR, "Unable to start skype_main thread.\n");
+      if (option_debug > 10) {
+        DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_TMP_LOG);
+      }
+      free(tmp);
+      return NULL;
+    }
+#else /* __CYGWIN__ */
+#ifdef WANT_SKYPE_X11
+    if (ast_pthread_create(&tmp->signaling_thread, NULL, do_signaling_thread_fnc, tmp) < 0) {
+      ast_log(LOG_ERROR, "Unable to start skype_main thread.\n");
+      if (option_debug > 10) {
+        DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_TMP_LOG);
+      }
+      free(tmp);
+      return NULL;
+    }
+#endif /* WANT_SKYPE_X11 */
+#endif /* __CYGWIN__ */
+    usleep(100000); //0.1 sec
+    if( tmp->skype_thread == AST_PTHREADT_NULL){
+      ast_log(LOG_ERROR, "Unable to start skype_main thread.\n");
+      if (option_debug > 10) {
+        DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_TMP_LOG);
+      }
+      free(tmp);
+      return NULL;
+    }
+    if (option_debug > 1)
+      ast_log(LOG_DEBUG, "STARTED signaling_thread=%lu STOP=%lu NULL=%lu\n",
+              (unsigned long) tmp->signaling_thread, (unsigned long) AST_PTHREADT_STOP,
+              (unsigned long) AST_PTHREADT_NULL);
+  }
+
+#endif
+
+
+
+
   /* return the newly created skypiax_pvt */
   if (option_debug > 10) {
     DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_TMP_LOG);
@@ -1577,14 +1629,14 @@
         /* This interface needs to be watched, as it lacks an owner */
 
         if (p->skype) {
-          if (FD_ISSET(p->AsteriskHandlesAst.fdesc[0], &rfds))
-            ERRORA("Descriptor %d (AsteriskHandlesAst.fdesc[0]) appears twice ?\n",
-                   SKYPIAX_P_LOG, p->AsteriskHandlesAst.fdesc[0]);
-
-          if (p->AsteriskHandlesAst.fdesc[0] > 0) {
-            FD_SET(p->AsteriskHandlesAst.fdesc[0], &rfds);
-            if (p->AsteriskHandlesAst.fdesc[0] > max)
-              max = p->AsteriskHandlesAst.fdesc[0];
+          if (FD_ISSET(p->SkypiaxHandles.fdesc[0], &rfds))
+            ERRORA("Descriptor %d (SkypiaxHandles.fdesc[0]) appears twice ?\n",
+                   SKYPIAX_P_LOG, p->SkypiaxHandles.fdesc[0]);
+
+          if (p->SkypiaxHandles.fdesc[0] > 0) {
+            FD_SET(p->SkypiaxHandles.fdesc[0], &rfds);
+            if (p->SkypiaxHandles.fdesc[0] > max)
+              max = p->SkypiaxHandles.fdesc[0];
 
           }
         }
@@ -1639,12 +1691,12 @@
     for (; p; p = p->next) {
 
       if (p->skype) {
-        if (FD_ISSET(p->AsteriskHandlesAst.fdesc[0], &rfds)) {
+        if (FD_ISSET(p->SkypiaxHandles.fdesc[0], &rfds)) {
           res = skypiax_skype_read(p);
           if (res == CALLFLOW_INCOMING_CALLID || res == CALLFLOW_INCOMING_RING) {
             //ast_log(LOG_NOTICE, "CALLFLOW_INCOMING_RING SKYPE\n");
             DEBUGA_SKYPE("CALLFLOW_INCOMING_RING\n", SKYPIAX_P_LOG);
-            skypiax_new(p, AST_STATE_RING, p->context /* p->context */ );
+            skypiax_new(p, SKYPIAX_STATE_RING, p->context /* p->context */ );
           }
         }
       }
@@ -2051,7 +2103,33 @@
 	return 0;
 
 }
-int start_audio_threads(private_t *tech_pvt) {
+int start_audio_threads(private_t *p) {
+                if (!p->tcp_srv_thread) {
+                  if (ast_pthread_create
+                      (&p->tcp_srv_thread, NULL, skypiax_do_tcp_srv_thread, p) < 0) {
+                    ERRORA("Unable to start tcp_srv_thread thread.\n", SKYPIAX_P_LOG);
+                    if (option_debug > 100) {
+                      DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
+                    }
+                    return -1;
+                  } else {
+                    DEBUGA_SKYPE("started tcp_srv_thread thread.\n", SKYPIAX_P_LOG);
+                  }
+                }
+                if (!p->tcp_cli_thread) {
+                  if (ast_pthread_create
+                      (&p->tcp_cli_thread, NULL, skypiax_do_tcp_cli_thread, p) < 0) {
+                    ERRORA("Unable to start tcp_cli_thread thread.\n", SKYPIAX_P_LOG);
+                    if (option_debug > 100) {
+                      DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
+                    }
+                    return -1;
+                  } else {
+                    DEBUGA_SKYPE("started tcp_cli_thread thread.\n", SKYPIAX_P_LOG);
+                  }
+                }
+
+
 #ifdef NOTDEF
                   switch_threadattr_t *thd_attr = NULL;
 
@@ -2077,7 +2155,8 @@
 	return 0;
 }
 
-int new_inbound_channel(private_t *tech_pvt) {
+int new_inbound_channel(private_t *p) {
+
 #ifdef NOTDEF
                   switch_core_session_t *session = NULL;
                   switch_channel_t *channel = NULL;
@@ -2113,12 +2192,12 @@
                   }
                   switch_channel_mark_answered(channel);
 
-        DEBUGA_SKYPE("Here\n", SKYPIAX_P_LOG);
 
 #endif
+        NOTICA("Here\n", SKYPIAX_P_LOG);
 	return 0;
 }
-int outbound_channel_answered(private_t *tech_pvt) {
+int outbound_channel_answered(private_t *p) {
 #ifdef NOTDEF
                   switch_core_session_t *session = NULL;
                   switch_channel_t *channel = NULL;
@@ -2142,12 +2221,20 @@
                   }
 
                   switch_core_session_rwunlock(session);
-                  DEBUGA_SKYPE("HERE!\n", SKYPIAX_P_LOG);
 
 #endif
+                  NOTICA("HERE!\n", SKYPIAX_P_LOG);
 
 	return 0;
 }
+void * skypiax_do_tcp_srv_thread(void *obj)
+{
+	return skypiax_do_tcp_srv_thread_func(obj);
+}
+void * skypiax_do_tcp_cli_thread(void *obj)
+{
+	return skypiax_do_tcp_cli_thread_func(obj);
+}
 
 /************************************************/
 #ifdef ASTERISK_VERSION_1_4

Modified: freeswitch/branches/gmaruzz/mod_skypiax/asterisk/skypiax.h
==============================================================================
--- freeswitch/branches/gmaruzz/mod_skypiax/asterisk/skypiax.h	(original)
+++ freeswitch/branches/gmaruzz/mod_skypiax/asterisk/skypiax.h	Sat Jan 31 10:07:53 2009
@@ -297,6 +297,7 @@
   char skype_password[256];
   char destination[256];
   char session_uuid_str[512 + 1];
+  pthread_t signaling_thread;
 };
 
 typedef struct skypiax_pvt private_t;
@@ -401,12 +402,13 @@
 int new_inbound_channel(private_t *tech_pvt);
 int outbound_channel_answered(private_t *tech_pvt);
 int skypiax_skype_senddigit(struct skypiax_pvt *p, char digit);
-#define		SKYPIAX_STATE_DOWN		1
-#define		SKYPIAX_STATE_RING		2
-#define		SKYPIAX_STATE_DIALING	3
-#define		SKYPIAX_STATE_BUSY		4
-#define		SKYPIAX_STATE_UP		5
-#define		SKYPIAX_STATE_RINGING	6
-#define		SKYPIAX_STATE_PRERING	7
+#define		SKYPIAX_STATE_DOWN		AST_STATE_DOWN
+#define		SKYPIAX_STATE_RING		AST_STATE_RING
+#define		SKYPIAX_STATE_DIALING	AST_STATE_DIALING
+#define		SKYPIAX_STATE_BUSY		AST_STATE_BUSY
+#define		SKYPIAX_STATE_UP		AST_STATE_UP
+#define		SKYPIAX_STATE_RINGING	AST_STATE_RINGING
+#define		SKYPIAX_STATE_PRERING	AST_STATE_PRERING
+#define		SKYPIAX_STATE_RESERVED	AST_STATE_RESERVED
 #define 	SKYPIAX_STATE_HANGUP_REQUESTED   200
 #endif /* _SKYPIAX_H_ */

Modified: freeswitch/branches/gmaruzz/mod_skypiax/asterisk/skypiax_protocol.c
==============================================================================
--- freeswitch/branches/gmaruzz/mod_skypiax/asterisk/skypiax_protocol.c	(original)
+++ freeswitch/branches/gmaruzz/mod_skypiax/asterisk/skypiax_protocol.c	Sat Jan 31 10:07:53 2009
@@ -126,8 +126,8 @@
 
         if ((SAMPLERATE_SKYPIAX - 8000) == 0) {
 
-          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]);
+          //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]);
           if (len > 0) {
             a = 0;
             for (i = 0; i < len / sizeof(short); i++) {
@@ -933,6 +933,15 @@
 
   DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG);
 
+  if(!strlen(tech_pvt->X11_display))
+  	strcpy(tech_pvt->X11_display, getenv("DISPLAY"));
+
+  if(!tech_pvt->tcp_srv_port)
+  	tech_pvt->tcp_srv_port = 10160;
+
+  if(!tech_pvt->tcp_cli_port)
+  	tech_pvt->tcp_cli_port = 10161;
+
   if (pipe(tech_pvt->SkypiaxHandles.fdesc)) {
     fcntl(tech_pvt->SkypiaxHandles.fdesc[0], F_SETFL, O_NONBLOCK);
     fcntl(tech_pvt->SkypiaxHandles.fdesc[1], F_SETFL, O_NONBLOCK);
@@ -1019,6 +1028,7 @@
           howmany = strlen(b) + 1;
 
           howmany = write(SkypiaxHandles->fdesc[1], b, howmany);
+      //DEBUGA_PBX("HERE: %s\n", SKYPIAX_P_LOG, b);
           memset(buffer, '\0', 17000);
         }
 



More information about the Freeswitch-branches mailing list