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

FreeSWITCH SVN gmaruzz at freeswitch.org
Mon Nov 10 01:56:40 PST 2008


Author: gmaruzz
Date: Mon Nov 10 04:56:40 2008
New Revision: 10311

Log:
skypiax: added audio thread, but cannot activate incoming call. Need to move things from skypiax_config to tech_pvt

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	Mon Nov 10 04:56:40 2008
@@ -270,6 +270,7 @@
     DEBUGA_SKYPE("ACCEPTED\n", SKYPIAX_P_LOG);
     while (1) {
       len = recv(fd, in, sizeof(short) * GG, 0);
+    DEBUGA_SKYPE("recv %d\n", SKYPIAX_P_LOG, len);
       if (len > 0) {
         a = 0;
         for (i = 0; i < len / sizeof(short); i++) {
@@ -312,9 +313,10 @@
   }
   return NULL;
 }
-void *skypiax_do_tcp_cli_thread(void *data)
+static void *SWITCH_THREAD_FUNC skypiax_do_tcp_cli_thread(switch_thread_t *thread, void *obj)
+//void *skypiax_do_tcp_cli_thread(void *data)
 {
-  struct skypiax_config *p = data;
+  struct skypiax_config *p = obj;
   int s, fd, len;
   short in[NN / 2];
   short out[NN];
@@ -355,11 +357,12 @@
 
   sin_size = sizeof(remote_addr);
   while ((fd = accept(s, (struct sockaddr *) &remote_addr, &sin_size)) > 0) {
-    DEBUGA_SKYPE("ACCEPTED\n", SKYPIAX_P_LOG);
+    ERRORA("ACCEPTED\n", SKYPIAX_P_LOG);
     //while (1 && p->owner && p->owner->_state == AST_STATE_UP)  FIXME FIXME FIXME
     while (1) {
 
       got = read(p->audioskypepipe[0], in, (NN / 2) * sizeof(short));
+    ERRORA("got %d\n", SKYPIAX_P_LOG, got);
 
       if (got > 0) {
         a = 0;
@@ -377,7 +380,7 @@
           break;
         }
       } else {
-        usleep(100);
+        usleep(1000);
       }
 
     }
@@ -498,31 +501,21 @@
   }
   return &f;
 }
-int skypiax_skypeaudio_write(struct skypiax_config *p, struct ast_frame *f)
-{
-  int sent;
-
-  if (option_debug > 100) {
-    DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG);
-  }
-  sent = write(p->audioskypepipe[1], (short *) f->data, f->datalen);
-
-  if (option_debug > 100) {
-    DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
-  }
-  return 0;
-}
 #endif //NOTDEF
 
 #endif /* SKYPE_AUDIO */
 static void tech_init(private_t *tech_pvt, switch_core_session_t *session)
 {
+	struct skypiax_config *p = NULL;
+
+    DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG);
 	tech_pvt->read_frame.data = tech_pvt->databuf;
 	tech_pvt->read_frame.buflen = sizeof(tech_pvt->databuf);
 	switch_mutex_init(&tech_pvt->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
 	switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
 	switch_core_session_set_private(session, tech_pvt);
 	tech_pvt->session = session;
+    DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
 }
 
 /* 
@@ -734,6 +727,7 @@
 	switch_channel_t *channel = NULL;
 	private_t *tech_pvt = NULL;
 	//switch_frame_t *pframe;
+	//FIXME int sent;
 
 	channel = switch_core_session_get_channel(session);
 	assert(channel != NULL);
@@ -750,6 +744,9 @@
 	}
 #endif
 
+	//FIXME sent = write(p->audioskypepipe[1], (short *) frame->data, frame->datalen);
+    //FIXME ERRORA("sent %d\n", SKYPIAX_P_LOG, sent);
+
 
 	return SWITCH_STATUS_SUCCESS;
 
@@ -1581,6 +1578,19 @@
               if (1) {
                 char msg_to_skype[1024];
                 if (!p->tcp_cli_thread) {
+if(1)
+{
+    switch_thread_t *thread;
+    switch_threadattr_t *thd_attr = NULL;
+
+    switch_threadattr_create(&thd_attr, module_pool);
+    switch_threadattr_detach_set(thd_attr, 1);
+    switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
+    switch_thread_create(&thread, thd_attr, skypiax_do_tcp_cli_thread, p, module_pool);
+                    DEBUGA_SKYPE("started tcp_cli_thread thread.\n", SKYPIAX_P_LOG);
+}
+
+
 #ifdef NOTDEF
                   if (ast_pthread_create
                       (&p->tcp_cli_thread, NULL, skypiax_do_tcp_cli_thread, p) < 0) {
@@ -1605,6 +1615,72 @@
               }
 
               p->skype_callflow = AST_STATE_UP;
+
+			  /**************************/
+
+			  //FIXME switch_core_session_t **new_session;
+
+			  //FIXME *new_session=switch_loadable_module_create_interface(skypiax_endpoint_interface, pool);
+
+#ifdef NOTDEF
+				if (1) {
+					switch_core_session_t *session;
+
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "New Inbound Channel!\n");
+
+					if ((session = switch_core_session_request(iax_endpoint_interface, NULL)) != 0) {
+						switch_core_session_add_stream(session, NULL);
+						if ((tech_pvt = (private_t *) switch_core_session_alloc(session, sizeof(private_t))) != 0) {
+							channel = switch_core_session_get_channel(session);
+							tech_init(tech_pvt, session);
+						} else {
+							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n");
+							switch_core_session_destroy(&session);
+							break;
+						}
+
+						if ((tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
+																				  iaxevent->ies.username,
+																				  globals.dialplan,
+																				  iaxevent->ies.calling_name,
+																				  iaxevent->ies.calling_number,
+																				  iax_get_peer_ip(iaxevent->session),
+																				  iaxevent->ies.calling_ani,
+																				  NULL,
+																				  NULL,
+																				  modname,
+																				  iaxevent->ies.called_context, iaxevent->ies.called_number)) != 0) {
+							char name[128];
+							switch_snprintf(name, sizeof(name), "IAX/%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);
+						}
+
+						if (iax_set_codec(tech_pvt, iaxevent->session,
+										  &iaxevent->ies.format, &iaxevent->ies.capability, &iaxevent->ies.samprate, IAX_SET) != SWITCH_STATUS_SUCCESS) {
+							iax_reject(iaxevent->session, "Codec Error!");
+							switch_core_session_destroy(&session);
+						} else {
+							tech_pvt->iax_session = iaxevent->session;
+							tech_pvt->session = session;
+							iax_accept(tech_pvt->iax_session, tech_pvt->codec);
+							iax_ring_announce(tech_pvt->iax_session);
+							switch_channel_set_state(channel, CS_INIT);
+							if (switch_core_session_thread_launch(session) != SWITCH_STATUS_SUCCESS) {
+								switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error spawning thread\n");
+								switch_core_session_destroy(&session);
+							}
+						}
+					}
+				}
+#endif //NOTDEF
+			  /**************************/
+
+
+
+
+
+
             } else {
               WARNINGA("skype_call: %s, STATUS: %s is not recognized\n", SKYPIAX_P_LOG,
                        id, value);



More information about the Freeswitch-svn mailing list