skypiax: avoid memory leaks and overhead by reusing the same audiothreads spawned with first call (they no more exit at call end)

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@14594 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Giovanni Maruzzelli 2009-08-22 06:14:38 +00:00
parent 2ff0b7dcdf
commit ed49550460
2 changed files with 46 additions and 20 deletions

View File

@ -570,10 +570,17 @@ static switch_status_t channel_kill_channel(switch_core_session_t *session, int
switch_clear_flag(tech_pvt, TFLAG_VOICE);
switch_set_flag(tech_pvt, TFLAG_HANGUP);
if (tech_pvt->skype_callflow == CALLFLOW_STATUS_REMOTEHOLD) {
ERRORA("%s CHANNEL got SWITCH_SIG_KILL\n", SKYPIAX_P_LOG, switch_channel_get_name(channel));
ERRORA("FYI %s CHANNEL in CALLFLOW_STATUS_REMOTEHOLD got SWITCH_SIG_KILL\n", SKYPIAX_P_LOG, switch_channel_get_name(channel));
channel_on_hangup(session);
}
if (switch_channel_get_state(channel) == CS_NEW) {
ERRORA("FYI %s CHANNEL in CS_NEW state got SWITCH_SIG_KILL\n", SKYPIAX_P_LOG, switch_channel_get_name(channel));
channel_on_hangup(session);
}
if ( switch_channel_get_state(channel) != CS_NEW && switch_channel_get_state(channel) < CS_EXECUTE) {
ERRORA("FYI %s CHANNEL in %d state got SWITCH_SIG_KILL\n", SKYPIAX_P_LOG, switch_channel_get_name(channel), switch_channel_get_state(channel));
channel_on_hangup(session);
}
//switch_mutex_unlock(tech_pvt->flag_mutex);
break;
case SWITCH_SIG_BREAK:
@ -1281,6 +1288,7 @@ static switch_status_t load_config(int reload_type)
WARNINGA("STARTING interface_id=%d\n", SKYPIAX_P_LOG, interface_id);
switch_threadattr_create(&skypiax_api_thread_attr, skypiax_module_pool);
switch_threadattr_detach_set(skypiax_api_thread_attr, 1);
switch_threadattr_stacksize_set(skypiax_api_thread_attr, SWITCH_THREAD_STACKSIZE);
switch_thread_create(&globals.SKYPIAX_INTERFACES[interface_id].skypiax_api_thread,
skypiax_api_thread_attr, skypiax_do_skypeapi_thread, &globals.SKYPIAX_INTERFACES[interface_id], skypiax_module_pool);
@ -1288,6 +1296,7 @@ static switch_status_t load_config(int reload_type)
switch_sleep(100000);
switch_threadattr_create(&skypiax_signaling_thread_attr, skypiax_module_pool);
switch_threadattr_detach_set(skypiax_signaling_thread_attr, 1);
switch_threadattr_stacksize_set(skypiax_signaling_thread_attr, SWITCH_THREAD_STACKSIZE);
switch_thread_create(&globals.SKYPIAX_INTERFACES[interface_id].
skypiax_signaling_thread, skypiax_signaling_thread_attr,
@ -1793,7 +1802,7 @@ SWITCH_STANDARD_API(sk_function)
if (strlen(globals.SKYPIAX_INTERFACES[i].name)) {
stream->write_function(stream,
"%c %d\t[%s]\t%3ld/%ld\t%6ld/%ld\t%s\t%s\t%s\n",
"%c %d\t[%s]\t%3u/%u\t%6u/%u\t%s\t%s\t%s\n",
next_flag_char,
i, globals.SKYPIAX_INTERFACES[i].name,
globals.SKYPIAX_INTERFACES[i].ib_failed_calls,
@ -1808,7 +1817,7 @@ SWITCH_STANDARD_API(sk_function)
}
stream->write_function(stream, "\nTotal Interfaces: %d IB Calls(Failed/Total): %ld/%ld OB Calls(Failed/Total): %ld/%ld\n",
globals.real_interfaces - 1, ib_failed, ib, ob_failed, ob);
globals.real_interfaces > 0 ? globals.real_interfaces - 1 : 0, ib_failed, ib, ob_failed, ob);
} else if (!strcasecmp(argv[0], "console")) {
int i;

View File

@ -322,9 +322,12 @@ int skypiax_signaling_read(private_t * tech_pvt)
tech_pvt->skype_callflow = CALLFLOW_STATUS_EARLYMEDIA;
tech_pvt->interface_state = SKYPIAX_STATE_DIALING;
DEBUGA_SKYPE("Our remote party in skype_call %s is EARLYMEDIA\n", SKYPIAX_P_LOG, id);
if (start_audio_threads(tech_pvt)) {
ERRORA("start_audio_threads FAILED\n", SKYPIAX_P_LOG);
return CALLFLOW_INCOMING_HANGUP;
if(tech_pvt->tcp_cli_thread == NULL){
DEBUGA_SKYPE("START start_audio_threads\n", SKYPIAX_P_LOG);
if (start_audio_threads(tech_pvt)) {
ERRORA("start_audio_threads FAILED\n", SKYPIAX_P_LOG);
return CALLFLOW_INCOMING_HANGUP;
}
}
skypiax_sleep(1000);
sprintf(msg_to_skype, "ALTER CALL %s SET_INPUT PORT=\"%d\"", id, tech_pvt->tcp_cli_port);
@ -405,15 +408,18 @@ int skypiax_signaling_read(private_t * tech_pvt)
if (!strlen(tech_pvt->session_uuid_str) || !strlen(tech_pvt->skype_call_id)
|| !strcasecmp(tech_pvt->skype_call_id, id)) {
skypiax_strncpy(tech_pvt->skype_call_id, id, sizeof(tech_pvt->skype_call_id) - 1);
tech_pvt->skype_callflow = CALLFLOW_STATUS_INPROGRESS;
DEBUGA_SKYPE("skype_call: %s is now active\n", SKYPIAX_P_LOG, id);
if (tech_pvt->skype_callflow != CALLFLOW_STATUS_EARLYMEDIA) {
tech_pvt->skype_callflow = CALLFLOW_STATUS_INPROGRESS;
tech_pvt->interface_state = SKYPIAX_STATE_UP;
if (start_audio_threads(tech_pvt)) {
ERRORA("start_audio_threads FAILED\n", SKYPIAX_P_LOG);
return CALLFLOW_INCOMING_HANGUP;
if(tech_pvt->tcp_cli_thread == NULL){
DEBUGA_SKYPE("START start_audio_threads\n", SKYPIAX_P_LOG);
if (start_audio_threads(tech_pvt)) {
ERRORA("start_audio_threads FAILED\n", SKYPIAX_P_LOG);
return CALLFLOW_INCOMING_HANGUP;
}
}
skypiax_sleep(1000); //FIXME
sprintf(msg_to_skype, "ALTER CALL %s SET_INPUT PORT=\"%d\"", id, tech_pvt->tcp_cli_port);
@ -422,6 +428,7 @@ int skypiax_signaling_read(private_t * tech_pvt)
sprintf(msg_to_skype, "#output ALTER CALL %s SET_OUTPUT PORT=\"%d\"", id, tech_pvt->tcp_srv_port);
skypiax_signaling_write(tech_pvt, msg_to_skype);
}
tech_pvt->skype_callflow = CALLFLOW_STATUS_INPROGRESS;
if (!strlen(tech_pvt->session_uuid_str)) {
DEBUGA_SKYPE("New Inbound Channel!\n\n\n\n", SKYPIAX_P_LOG);
new_inbound_channel(tech_pvt);
@ -550,7 +557,7 @@ void *skypiax_do_tcp_srv_thread_func(void *obj)
/****************************/
while ((fd = accept(s, (struct sockaddr *) &remote_addr, &sin_size)) > 0) {
while (s > 0 && (fd = accept(s, (struct sockaddr *) &remote_addr, &sin_size)) > 0) {
DEBUGA_SKYPE("ACCEPTED here I send you %d\n", SKYPIAX_P_LOG, tech_pvt->tcp_srv_port);
if (!(running && tech_pvt->running))
break;
@ -655,15 +662,13 @@ void *skypiax_do_tcp_srv_thread_func(void *obj)
DEBUGA_SKYPE("Skype incoming audio GONE\n", SKYPIAX_P_LOG);
skypiax_close_socket(fd);
//if (exit)
break;
}
}
}
DEBUGA_SKYPE("incoming audio server (I am it) EXITING\n", SKYPIAX_P_LOG);
skypiax_close_socket(s);
tech_pvt->tcp_srv_thread = NULL;
s=-1;
return NULL;
}
@ -725,7 +730,7 @@ void *skypiax_do_tcp_cli_thread_func(void *obj)
/****************************/
while ((fd = accept(s, (struct sockaddr *) &remote_addr, &sin_size)) > 0) {
while (s > 0 && (fd = accept(s, (struct sockaddr *) &remote_addr, &sin_size)) > 0) {
DEBUGA_SKYPE("ACCEPTED here you send me %d\n", SKYPIAX_P_LOG, tech_pvt->tcp_cli_port);
#ifndef WIN32
fcntl(tech_pvt->audioskypepipe[0], F_SETFL, O_NONBLOCK);
@ -836,14 +841,13 @@ void *skypiax_do_tcp_cli_thread_func(void *obj)
}
DEBUGA_SKYPE("Skype outbound audio GONE\n", SKYPIAX_P_LOG);
skypiax_close_socket(fd);
break;
}
}
}
DEBUGA_SKYPE("outbound audio server (I am it) EXITING\n", SKYPIAX_P_LOG);
skypiax_close_socket(s);
tech_pvt->tcp_cli_thread = NULL;
s=-1;
return NULL;
}
@ -949,8 +953,12 @@ int skypiax_pipe_read(int pipe, short *buf, int howmany)
int skypiax_pipe_write(int pipe, short *buf, int howmany)
{
howmany = write(pipe, buf, howmany);
return howmany;
if(buf){
howmany = write(pipe, buf, howmany);
return howmany;
} else {
return 0;
}
}
int skypiax_close_socket(unsigned int fd)
@ -1452,6 +1460,8 @@ void *skypiax_do_skypeapi_thread_func(void *obj)
if (!skypiax_send_message(SkypiaxHandles, buf)) {
ERRORA("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch Skypiax again\n", SKYPIAX_P_LOG);
running = 0;
if(disp)
XCloseDisplay(disp);
return NULL;
}
@ -1459,6 +1469,8 @@ void *skypiax_do_skypeapi_thread_func(void *obj)
if (!skypiax_send_message(SkypiaxHandles, buf)) {
ERRORA("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch Skypiax again\n", SKYPIAX_P_LOG);
running = 0;
if(disp)
XCloseDisplay(disp);
return NULL;
}
@ -1472,6 +1484,7 @@ void *skypiax_do_skypeapi_thread_func(void *obj)
Atom atom_begin = XInternAtom(disp, "SKYPECONTROLAPI_MESSAGE_BEGIN", False);
Atom atom_continue = XInternAtom(disp, "SKYPECONTROLAPI_MESSAGE", False);
memset(buffer, '\0', 17000);
b = buffer;
while (1) {
@ -1539,9 +1552,13 @@ void *skypiax_do_skypeapi_thread_func(void *obj)
} else {
ERRORA("Skype is not running, maybe crashed. Please run/restart Skype and relaunch Skypiax\n", SKYPIAX_P_LOG);
running = 0;
if(disp)
XCloseDisplay(disp);
return NULL;
}
//running = 0;
if(disp)
XCloseDisplay(disp);
return NULL;
}