[Freeswitch-svn] [commit] r10491 - freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax
FreeSWITCH SVN
gmaruzz at freeswitch.org
Fri Nov 21 07:44:47 PST 2008
Author: gmaruzz
Date: Fri Nov 21 10:44:46 2008
New Revision: 10491
Log:
skypiax: now it can be used for multiple consecutive calls, incoming and outbound. Time to begin a general rewriting.
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 Fri Nov 21 10:44:46 2008
@@ -194,8 +194,8 @@
int control_to_send;
int audiopipe[2];
int audioskypepipe[2];
- pthread_t tcp_srv_thread;
- pthread_t tcp_cli_thread;
+ switch_thread_t *tcp_srv_thread;
+ switch_thread_t *tcp_cli_thread;
short audiobuf[160];
int audiobuf_is_loaded;
@@ -436,7 +436,28 @@
sin_size = sizeof(remote_addr);
while ((fd = accept(s, (struct sockaddr *) &remote_addr, &sin_size)) > 0) {
DEBUGA_SKYPE("ACCEPTED\n", SKYPIAX_P_LOG);
- while (1) {
+ while (p->interface_state != SKYPIAX_STATE_DOWN && (p->skype_callflow == CALLFLOW_STATUS_INPROGRESS ||p->skype_callflow == SKYPIAX_STATE_UP)) {
+
+ int fdselect;
+ int rt;
+ fd_set fs;
+ struct timeval to;
+
+ exit=1;
+
+
+
+
+
+
+ fdselect = fd;
+ FD_ZERO(&fs);
+ FD_SET(fdselect, &fs);
+ to.tv_usec = 100;
+ to.tv_sec = 0;
+ rt = select(fdselect + 1, &fs, NULL, NULL, &to);
+ if (rt > 0) {
+
len = recv(fd, in, sizeof(short) * GG, 0);
//DEBUGA_SKYPE("recv %d\n", SKYPIAX_P_LOG, len);
if (len > 0) {
@@ -467,6 +488,7 @@
exit = 1;
break;
}
+ }
}
DEBUGA_SKYPE("Skype client GONE\n", SKYPIAX_P_LOG);
close(fd);
@@ -494,6 +516,7 @@
int a;
int i;
int got;
+ int exit=0;
if (option_debug > 10) {
DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG);
@@ -517,6 +540,7 @@
if (option_debug > 10) {
DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
}
+ close(s);
return NULL;
}
DEBUGA_SKYPE("started tcp_cli_thread thread.\n", SKYPIAX_P_LOG);
@@ -527,7 +551,27 @@
while ((fd = accept(s, (struct sockaddr *) &remote_addr, &sin_size)) > 0) {
ERRORA("ACCEPTED\n", SKYPIAX_P_LOG);
//while (1 && p->owner && p->owner->_state == SKYPIAX_STATE_UP) FIXME FIXME FIXME
- while (1) {
+ while (p->interface_state != SKYPIAX_STATE_DOWN && (p->skype_callflow == CALLFLOW_STATUS_INPROGRESS ||p->skype_callflow == SKYPIAX_STATE_UP)) {
+ int fdselect;
+ int rt;
+ fd_set fs;
+ struct timeval to;
+
+ exit=1;
+
+
+
+
+
+
+ fdselect = p->audioskypepipe[0];
+ FD_ZERO(&fs);
+ FD_SET(fdselect, &fs);
+ to.tv_usec = 100;
+ to.tv_sec = 0;
+ rt = select(fdselect + 1, &fs, NULL, NULL, &to);
+ if (rt > 0) {
+
got = read(p->audioskypepipe[0], in, (NN / 2) * sizeof(short));
//ERRORA("got %d\n", SKYPIAX_P_LOG, got);
@@ -550,10 +594,13 @@
} else {
usleep(1000);
}
+ }
}
DEBUGA_SKYPE("Skype server GONE\n", SKYPIAX_P_LOG);
close(fd);
+ if (exit)
+ break;
}
DEBUGA_SKYPE("client (I am it) GONE\n", SKYPIAX_P_LOG);
@@ -614,6 +661,10 @@
struct skypiax_interface *p;
short buf[640];
int samples;
+ int fd;
+ int rt;
+ fd_set fs;
+ struct timeval to;
p = tech_pvt->p;
@@ -622,6 +673,14 @@
memset(buf, '\0', sizeof(buf));
+ fd = p->audiopipe[0];
+ FD_ZERO(&fs);
+ FD_SET(fd, &fs);
+ to.tv_usec = 100000;
+ to.tv_sec = 0;
+ rt = select(fd + 1, &fs, NULL, NULL, &to);
+ if (rt > 0) {
+
//if ((samples = read(p->audiopipe[0], buf, SAMPLES_PER_FRAME * sizeof(short))) != 320)
if ((samples = read(p->audiopipe[0], tech_pvt->read_frame.data, SAMPLES_PER_FRAME * sizeof(short))) != 320) {
@@ -634,6 +693,11 @@
//DEBUGA_SKYPE("read=====> GOOD samples=%d\n", SKYPIAX_P_LOG, samples);
/* A real frame */
}
+ } else {
+ DEBUGA_SKYPE("select returned %d\n", SKYPIAX_P_LOG, rt);
+
+
+ }
//DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
@@ -794,12 +858,16 @@
switch (sig) {
case SWITCH_SIG_KILL:
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s CHANNEL got SWITCH_SIG_KILL\n", switch_channel_get_name(channel));
switch_clear_flag_locked(tech_pvt, TFLAG_IO);
switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
- switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
+ switch_set_flag_locked(tech_pvt, TFLAG_HANGUP);
+ //switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
+ //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "CHANNEL after TFLAG_HUP\n");
//switch_thread_cond_signal(tech_pvt->cond);
break;
case SWITCH_SIG_BREAK:
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s CHANNEL got SWITCH_SIG_BREAK\n", switch_channel_get_name(channel));
switch_set_flag_locked(tech_pvt, TFLAG_BREAK);
break;
default:
@@ -852,7 +920,8 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "skypiax_skypeaudio_read ERROR\n");
} else {
- //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "skypiax_skypeaudio_read SUCCESS\n");
+ switch_set_flag_locked(tech_pvt, TFLAG_VOICE);
+ //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "skypiax_skypeaudio_read SUCCESS\n");
}
@@ -888,8 +957,8 @@
}
#endif
+ //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "============>\n");
- switch_set_flag_locked(tech_pvt, TFLAG_VOICE); //FIXME
if (switch_test_flag(tech_pvt, TFLAG_IO) && switch_test_flag(tech_pvt, TFLAG_VOICE)) {
switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
@@ -904,9 +973,11 @@
}
#endif
return SWITCH_STATUS_SUCCESS;
- }
+ }
+
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CHANNEL READ no TFLAG_IO\n");
+ return SWITCH_STATUS_FALSE;
- switch_yield(1000);
}
@@ -1831,52 +1902,50 @@
+#if 0
if (!p->tcp_srv_thread) {
if(1)
{
- switch_thread_t *thread;
+#endif
+ //switch_thread_t *thread;
+ if(1){
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_srv_thread, p, module_pool);
+ switch_thread_create(&p->tcp_srv_thread, thd_attr, skypiax_do_tcp_srv_thread, p, module_pool);
DEBUGA_SKYPE("started tcp_srv_thread thread.\n", SKYPIAX_P_LOG);
+#if 0
}
}
+#endif
+#if 0
if (!p->tcp_cli_thread) {
if(1)
{
- switch_thread_t *thread;
- switch_threadattr_t *thd_attr = NULL;
+#endif
+ //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);
+ switch_thread_create(&p->tcp_cli_thread, thd_attr, skypiax_do_tcp_cli_thread, p, module_pool);
DEBUGA_SKYPE("started tcp_cli_thread thread.\n", SKYPIAX_P_LOG);
}
+#if 0
+ }
-#ifdef NOTDEF
- 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);
- }
-#endif //NOTDEF
}
+#endif
usleep(100000);
sprintf(msg_to_skype, "ALTER CALL %s SET_OUTPUT PORT=\"5556\"", id);
@@ -2134,14 +2203,30 @@
while (1) {
usleep(1000);
res = skypiax_skype_read(p);
-#if 0
+#if 1
+ //if (res == CALLFLOW_INCOMING_HANGUP && p->interface_state != SKYPIAX_STATE_DOWN)
if (res == CALLFLOW_INCOMING_HANGUP) {
+ switch_core_session_t *session = NULL;
+ private_t *tech_pvt;
+ switch_channel_t *channel;
+
+
+ p->interface_state=SKYPIAX_STATE_DOWN;
//if (option_debug)
DEBUGA_SKYPE("skype call ended\n", SKYPIAX_P_LOG);
- if (p->owner) {
- pthread_testcancel();
- ast_queue_control(p->owner, SKYPIAX_CONTROL_HANGUP);
- }
+
+ tech_pvt = p->tech_pvt;
+ session = tech_pvt->session;
+
+ channel = switch_core_session_get_channel(session);
+ DEBUGA_SKYPE("before channel_on_hangup\n", SKYPIAX_P_LOG);
+
+ //switch_channel_set_state(channel, CS_HANGUP);
+
+ switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
+ DEBUGA_SKYPE("after channel_on_hangup\n", SKYPIAX_P_LOG);
+
+ //DEBUGA_SKYPE("set state to CS_HANGUP\n", SKYPIAX_P_LOG);
}
#endif
}
@@ -2440,11 +2525,15 @@
switch_clear_flag_locked(tech_pvt, TFLAG_IO);
switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
- //switch_thread_cond_signal(tech_pvt->cond);
- WARNINGA("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);
+ //switch_set_flag_locked(tech_pvt, TFLAG_HANGUP);
+
+ if(strlen(p->skype_call_id)) {
+ //switch_thread_cond_signal(tech_pvt->cond);
+ WARNINGA("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);
+ }
if (tech_pvt->read_codec.implementation) {
switch_core_codec_destroy(&tech_pvt->read_codec);
More information about the Freeswitch-svn
mailing list