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

FreeSWITCH SVN gmaruzz at freeswitch.org
Thu Nov 13 08:08:29 PST 2008


Author: gmaruzz
Date: Thu Nov 13 11:08:28 2008
New Revision: 10371

Log:
skypiax: at the moment it's an hack made of ad hoc band aids. But it can accept incoming calls and originate outbound calls, audio is going back and forth, and so are DTMFs. It works just for one call. Crashes on exit. Now I got a vague idea of how an endpoint is working on FS. During the next days, a fairly thorough rewrite.

Modified:
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.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	Thu Nov 13 11:08:28 2008
@@ -220,6 +220,7 @@
 static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig);
 
 int option_debug = 100;
+switch_core_session_t *global_session = NULL;
 
 static switch_status_t skypiax_codec(private_t *tech_pvt, int sample_rate, int codec_ms)
 {
@@ -687,12 +688,11 @@
 {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "skypiax_docec FAILED\n");
 } else {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "skypiax_docec SUCCESS\n");
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "skypiax_codec SUCCESS\n");
 }
 
     DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
 }
-
 /* 
    State methods they get called when the state changes to the specific state 
    returning SWITCH_STATUS_SUCCESS tells the core to execute the standard state method next
@@ -1018,7 +1018,7 @@
 
 	return SWITCH_STATUS_SUCCESS;
 }
-
+#ifdef NOTDEF //FIXME: moved below
 /* Make sure when you have 2 sessions in the same scope that you pass the appropriate one to the routines
    that allocate memory or you will have 1 channel with memory allocated from another channel's pool!
 */
@@ -1033,6 +1033,7 @@
 
 		switch_core_session_add_stream(*new_session, NULL);
 		if ((tech_pvt = (private_t *) switch_core_session_alloc(*new_session, sizeof(private_t))) != 0) {
+			tech_pvt->p = SKYPIAX_CONFIGS[2]; //FIXME
 			channel = switch_core_session_get_channel(*new_session);
 			tech_init(tech_pvt, *new_session, NULL);
 		} else {
@@ -1044,7 +1045,7 @@
 		if (outbound_profile) {
 			char name[128];
 
-			snprintf(name, sizeof(name), "SKYPIAX/%s", outbound_profile->destination_number);
+			snprintf(name, sizeof(name), "skypiax/%s", outbound_profile->destination_number);
 			switch_channel_set_name(channel, name);
 
 			caller_profile = switch_caller_profile_clone(*new_session, outbound_profile);
@@ -1057,6 +1058,7 @@
 		}
 
 
+		skypiax_skype_call(tech_pvt->p, outbound_profile->destination_number, 30);
 
 		switch_channel_set_flag(channel, CF_OUTBOUND);
 		switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
@@ -1067,6 +1069,7 @@
 	return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
 
 }
+#endif // NOTDEF //FIXME: moved below
 
 static switch_status_t channel_receive_event(switch_core_session_t *session, switch_event_t *event)
 {
@@ -1727,6 +1730,7 @@
               DEBUGA_SKYPE("We missed skype_call %s\n", SKYPIAX_P_LOG, id);
 
             } else if (!strcasecmp(value, "FINISHED")) {
+				global_session = NULL; //FIXME
               p->skype_callflow = CALLFLOW_STATUS_FINISHED;
               if (option_debug)
                 DEBUGA_SKYPE("skype_call %s now is DOWN\n", SKYPIAX_P_LOG, id);
@@ -1873,7 +1877,7 @@
 			  //FIXME *new_session=switch_loadable_module_create_interface(skypiax_endpoint_interface, pool);
 
 #ifndef NOTDEF
-				if (1) {
+				if (!global_session) { //FIXME FIXME FIXME 
 					switch_core_session_t *session = NULL;
 					private_t *tech_pvt = NULL;
 					switch_channel_t *channel = NULL;
@@ -1897,9 +1901,9 @@
 
 #if 1
 						if ((tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
-																				  "SKYPIAX",
+																				  "skypiax",
 																				  "XML",
-																				  "calling_name",
+																				  "gmaruzz_from_skype",
 																				  "calling_number",
 																				  NULL,
 																				  "calling_ani",
@@ -1909,7 +1913,7 @@
 																				  "default", 
 																				  "5000")) != 0) {
 							char name[128];
-							switch_snprintf(name, sizeof(name), "Skypiax/%s-%04x", tech_pvt->caller_profile->destination_number, rand() & 0xffff);
+							switch_snprintf(name, sizeof(name), "skypiax/%s-%04x", tech_pvt->caller_profile->destination_number, rand() & 0xffff);
 							switch_channel_set_name(channel, name);
 							switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
 						}
@@ -1942,6 +1946,33 @@
 						}
 #endif //0
 					}
+				} else {
+					switch_core_session_t *session = NULL;
+					private_t *tech_pvt = NULL;
+					switch_channel_t *channel = NULL;
+
+              WARNINGA("skype_call: HERE\n", SKYPIAX_P_LOG);
+			  usleep(50000);
+					tech_pvt = p->tech_pvt;
+              WARNINGA("skype_call: HERE\n", SKYPIAX_P_LOG);
+			  usleep(50000);
+					//session = tech_pvt->session;
+					session = global_session;
+              WARNINGA("skype_call: HERE\n", SKYPIAX_P_LOG);
+			  usleep(5000000);
+							channel = switch_core_session_get_channel(session);
+
+              WARNINGA("skype_call: HERE\n", SKYPIAX_P_LOG);
+			  usleep(50000);
+
+
+			  switch_channel_mark_pre_answered(channel);
+
+							//switch_channel_set_state(channel, CS_EXECUTE);
+              WARNINGA("skype_call: HERE\n", SKYPIAX_P_LOG);
+			  usleep(50000);
+
+
 				}
 #endif //NOTDEF
 			  /**************************/
@@ -1972,6 +2003,100 @@
   return 0;
 }
 
+int skypiax_skype_call(struct skypiax_config *p, char *idest, int timeout, switch_core_session_t *session)
+{
+  char rdest[80];
+
+  if (option_debug > 10) {
+    DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG);
+  }
+usleep(5000);
+
+  //FIXME strncpy(rdest, idest, sizeof(rdest) - 1);
+  strncpy(rdest, "echo123", sizeof(rdest) - 1);
+  if (option_debug)
+    DEBUGA_SKYPE("Calling Skype, rdest is: %s\n", SKYPIAX_P_LOG, rdest);
+  //skypiax_skype_write(p, "GET AGC");
+  //usleep(10000);
+  skypiax_skype_write(p, "SET AGC OFF");
+  usleep(10000);
+  //skypiax_skype_write(p, "GET AGC");
+  //usleep(10000);
+  //skypiax_skype_write(p, "GET AEC");
+  //usleep(10000);
+  skypiax_skype_write(p, "SET AEC OFF");
+  usleep(10000);
+  //skypiax_skype_write(p, "GET AEC");
+  //usleep(300000);
+
+  char msg_to_skype[1024];
+  sprintf(msg_to_skype, "CALL %s", rdest);
+  if (skypiax_skype_write(p, msg_to_skype) < 0) {
+
+    ERRORA("failed to communicate with Skype client, now exit\n", SKYPIAX_P_LOG);
+    if (option_debug > 10) {
+      DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
+    }
+    return -1;
+  }
+  global_session = session;
+  //p->skype_call_ongoing = 1;
+
+  //if (p->owner) {
+  //ast_setstate(p->owner, AST_STATE_RINGING);
+  //}
+  //FIXME ast_queue_control(p->owner, AST_CONTROL_RINGING);
+  return 0;
+}
+
+static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event,
+													switch_caller_profile_t *outbound_profile,
+													switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags)
+{
+	if ((*new_session = switch_core_session_request(skypiax_endpoint_interface, pool)) != 0) {
+		private_t *tech_pvt;
+		switch_channel_t *channel;
+		switch_caller_profile_t *caller_profile;
+
+		switch_core_session_add_stream(*new_session, NULL);
+		if ((tech_pvt = (private_t *) switch_core_session_alloc(*new_session, sizeof(private_t))) != 0) {
+			tech_pvt->p = &SKYPIAX_CONFIGS[2]; //FIXME
+			channel = switch_core_session_get_channel(*new_session);
+			tech_init(tech_pvt, *new_session, NULL);
+		} else {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n");
+			switch_core_session_destroy(new_session);
+			return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
+		}
+
+		if (outbound_profile) {
+			char name[128];
+
+			snprintf(name, sizeof(name), "skypiax/%s", outbound_profile->destination_number);
+			switch_channel_set_name(channel, name);
+
+			caller_profile = switch_caller_profile_clone(*new_session, outbound_profile);
+			switch_channel_set_caller_profile(channel, caller_profile);
+			tech_pvt->caller_profile = caller_profile;
+		} else {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Doh! no caller profile\n");
+			switch_core_session_destroy(new_session);
+			return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
+		}
+
+
+		skypiax_skype_call(tech_pvt->p, outbound_profile->destination_number, 30, *new_session);
+
+		switch_channel_set_flag(channel, CF_OUTBOUND);
+		switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
+		switch_channel_set_state(channel, CS_INIT);
+		return SWITCH_CAUSE_SUCCESS;
+	}
+
+	return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
+
+}
+
 /*!
  * \brief This thread runs during a call, and monitor the interface serial port for signaling, like hangup, caller id, etc
  *



More information about the Freeswitch-svn mailing list