skypiax: added FS timers, allow for better Virtual Machine (xen, ec2) conference behavior, to be polished

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16521 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Giovanni Maruzzelli 2010-01-27 13:30:07 +00:00
parent 677246547b
commit 7323745f0a
3 changed files with 323 additions and 266 deletions

View File

@ -36,6 +36,7 @@
#include "skypiax.h"
#define MDL_CHAT_PROTO "skype"
#define TIMER_WRITE
#ifdef WIN32
/***************/
@ -193,7 +194,8 @@ static switch_status_t channel_on_soft_execute(switch_core_session_t *session);
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, switch_call_cause_t *cancel_cause);
switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags,
switch_call_cause_t *cancel_cause);
static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id);
static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id);
static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig);
@ -255,7 +257,26 @@ switch_status_t skypiax_tech_init(private_t * tech_pvt, switch_core_session_t *s
ERRORA("skypiax_codec FAILED\n", SKYPIAX_P_LOG);
return SWITCH_STATUS_FALSE;
}
DEBUGA_SKYPE("skypiax_codec SUCCESS\n", SKYPIAX_P_LOG);
if (switch_core_timer_init(&tech_pvt->timer_read, "soft", 20, tech_pvt->read_codec.implementation->samples_per_packet, skypiax_module_pool) !=
SWITCH_STATUS_SUCCESS) {
ERRORA("setup timer failed\n", SKYPIAX_P_LOG);
return SWITCH_STATUS_FALSE;
}
switch_core_timer_sync(&tech_pvt->timer_read);
#ifdef TIMER_WRITE
if (switch_core_timer_init(&tech_pvt->timer_write, "soft", 20, tech_pvt->write_codec.implementation->samples_per_packet, skypiax_module_pool) !=
SWITCH_STATUS_SUCCESS) {
ERRORA("setup timer failed\n", SKYPIAX_P_LOG);
return SWITCH_STATUS_FALSE;
}
switch_core_timer_sync(&tech_pvt->timer_write);
#endif// TIMER_WRITE
DEBUGA_SKYPE("skypiax_tech_init SUCCESS\n", SKYPIAX_P_LOG);
return SWITCH_STATUS_SUCCESS;
}
@ -460,6 +481,14 @@ static switch_status_t channel_on_destroy(switch_core_session_t *session)
if (switch_core_codec_ready(&tech_pvt->write_codec)) {
switch_core_codec_destroy(&tech_pvt->write_codec);
}
switch_core_timer_destroy(&tech_pvt->timer_read);
#ifdef TIMER_WRITE
switch_core_timer_destroy(&tech_pvt->timer_write);
#endif// TIMER_WRITE
*tech_pvt->session_uuid_str = '\0';
tech_pvt->interface_state = SKYPIAX_STATE_IDLE;
if (tech_pvt->skype_callflow == CALLFLOW_STATUS_FINISHED) {
@ -662,6 +691,8 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
tech_pvt->read_frame.flags = SFF_NONE;
*frame = NULL;
switch_core_timer_next(&tech_pvt->timer_read);
if (!skypiax_audio_read(tech_pvt)) {
ERRORA("skypiax_audio_read ERROR\n", SKYPIAX_P_LOG);
@ -745,18 +776,17 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc
#else /* WIN32 */
//sent = write(tech_pvt->audiopipe_cli[1], frame->data, sent);
#endif /* WIN32 */
//FIXME while(tech_pvt->flag_audio_cli == 1){
//FIXME switch_sleep(100); //1 millisec
//NOTICA("write now is 1\n", SKYPIAX_P_LOG);
//FIXME }
//WARNINGA("write is now 0\n", SKYPIAX_P_LOG);
//memcpy(tech_pvt->audiobuf_cli, frame->data, frame->datalen);
if (tech_pvt->flag_audio_cli == 1) {
switch_sleep(1000); //1 millisec
}
if (tech_pvt->flag_audio_cli == 0) {
#ifdef TIMER_WRITE
switch_core_timer_next(&tech_pvt->timer_write);
#endif// TIMER_WRITE
memcpy(tech_pvt->audiobuf_cli, frame->data, frame->datalen);
tech_pvt->flag_audio_cli = 1;
}
@ -801,6 +831,11 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s
case SWITCH_MESSAGE_INDICATE_ANSWER:
{
DEBUGA_SKYPE("MSG_ID=%d, TO BE ANSWERED!\n", SKYPIAX_P_LOG, msg->message_id);
switch_core_timer_sync(&tech_pvt->timer_read);
#ifdef TIMER_WRITE
switch_core_timer_sync(&tech_pvt->timer_write);
#endif// TIMER_WRITE
channel_answer_channel(session);
}
break;
@ -808,16 +843,20 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s
DEBUGA_SKYPE("%s CHANNEL got SWITCH_MESSAGE_INDICATE_AUDIO_SYNC\n", SKYPIAX_P_LOG, switch_channel_get_name(channel));
//for (i=0; i<50; i++) {
//skypiax_audio_read(tech_pvt);
//WARNINGA("read samples\n", SKYPIAX_P_LOG);
//}
//switch_core_timer_sync(&tech_pvt->timer_read);
//switch_core_timer_sync(&tech_pvt->timer_write);
switch_core_timer_sync(&tech_pvt->timer_read);
#ifdef TIMER_WRITE
switch_core_timer_sync(&tech_pvt->timer_write);
#endif// TIMER_WRITE
break;
default:
{
switch_core_timer_sync(&tech_pvt->timer_read);
#ifdef TIMER_WRITE
switch_core_timer_sync(&tech_pvt->timer_write);
#endif// TIMER_WRITE
DEBUGA_SKYPE("MSG_ID=%d\n", SKYPIAX_P_LOG, msg->message_id);
}
break;
@ -869,7 +908,8 @@ switch_io_routines_t skypiax_io_routines = {
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, switch_call_cause_t *cancel_cause)
switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags,
switch_call_cause_t *cancel_cause)
{
private_t *tech_pvt = NULL;
if ((*new_session = switch_core_session_request(skypiax_endpoint_interface, SWITCH_CALL_DIRECTION_OUTBOUND, pool)) != 0) {
@ -1261,7 +1301,7 @@ static switch_status_t load_config(int reload_type)
} else {
DEBUGA_SKYPE("Initialized XInitThreads!\n", SKYPIAX_P_LOG);
}
switch_sleep(100);
switch_sleep(1000);
#endif /* WIN32 */
if (interface_id && interface_id < SKYPIAX_MAX_INTERFACES) {
@ -1424,7 +1464,8 @@ static switch_status_t load_config(int reload_type)
DEBUGA_SKYPE("i=%d globals.SKYPIAX_INTERFACES[%d].dialplan=%s\n", SKYPIAX_P_LOG, i, i, globals.SKYPIAX_INTERFACES[i].dialplan);
DEBUGA_SKYPE("i=%d globals.SKYPIAX_INTERFACES[%d].destination=%s\n", SKYPIAX_P_LOG, i, i, globals.SKYPIAX_INTERFACES[i].destination);
DEBUGA_SKYPE("i=%d globals.SKYPIAX_INTERFACES[%d].context=%s\n", SKYPIAX_P_LOG, i, i, globals.SKYPIAX_INTERFACES[i].context);
DEBUGA_SKYPE("i=%d globals.SKYPIAX_INTERFACES[%d].report_incoming_chatmessages=%d\n", SKYPIAX_P_LOG, i, i, globals.SKYPIAX_INTERFACES[i].report_incoming_chatmessages);
DEBUGA_SKYPE("i=%d globals.SKYPIAX_INTERFACES[%d].report_incoming_chatmessages=%d\n", SKYPIAX_P_LOG, i, i,
globals.SKYPIAX_INTERFACES[i].report_incoming_chatmessages);
}
}
}
@ -1434,7 +1475,8 @@ static switch_status_t load_config(int reload_type)
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t chat_send(const char *proto, const char *from, const char *to, const char *subject, const char *body, const char *type, const char *hint)
static switch_status_t chat_send(const char *proto, const char *from, const char *to, const char *subject, const char *body, const char *type,
const char *hint)
{
//char *user, *host, *f_user = NULL, *ffrom = NULL, *f_host = NULL, *f_resource = NULL;
char *user = NULL, *host, *f_user = NULL, *f_host = NULL, *f_resource = NULL;
@ -1445,7 +1487,8 @@ static switch_status_t chat_send(const char *proto, const char *from, const char
switch_assert(proto != NULL);
DEBUGA_SKYPE("chat_send(proto=%s, from=%s, to=%s, subject=%s, body=%s, type=%s, hint=%s)\n", SKYPIAX_P_LOG, proto, from, to, subject, body, type, hint?hint:"NULL");
DEBUGA_SKYPE("chat_send(proto=%s, from=%s, to=%s, subject=%s, body=%s, type=%s, hint=%s)\n", SKYPIAX_P_LOG, proto, from, to, subject, body, type,
hint ? hint : "NULL");
if (!to || !strlen(to)) {
ERRORA("Missing To: header.\n", SKYPIAX_P_LOG);
@ -1470,10 +1513,10 @@ static switch_status_t chat_send(const char *proto, const char *from, const char
if ((host = strchr(user, '@'))) {
*host++ = '\0';
}
//if (!strcmp(proto, MDL_CHAT_PROTO)) {
DEBUGA_SKYPE("chat_send(proto=%s, from=%s, to=%s, subject=%s, body=%s, type=%s, hint=%s)\n", SKYPIAX_P_LOG, proto, from, to, subject, body, type, hint?hint:"NULL");
DEBUGA_SKYPE("chat_send(proto=%s, from=%s, to=%s, subject=%s, body=%s, type=%s, hint=%s)\n", SKYPIAX_P_LOG, proto, from, to, subject, body, type,
hint ? hint : "NULL");
if (hint && strlen(hint)) {
//in hint we receive the interface name to use
for (i = 0; !found && i < SKYPIAX_MAX_INTERFACES; i++) {
@ -1498,13 +1541,14 @@ static switch_status_t chat_send(const char *proto, const char *from, const char
}
}
if (!found) {
ERRORA("ERROR: A Skypiax interface with name='%s' or one with skypeuser='%s' was not found\n", SKYPIAX_P_LOG, hint?hint:"NULL", from?from:"NULL");
ERRORA("ERROR: A Skypiax interface with name='%s' or one with skypeuser='%s' was not found\n", SKYPIAX_P_LOG, hint ? hint : "NULL",
from ? from : "NULL");
goto end;
} else {
snprintf(skype_msg, sizeof(skype_msg), "CHAT CREATE %s", to);
skypiax_signaling_write(tech_pvt, skype_msg);
switch_sleep(100);
switch_sleep(1000);
}
//} else {
//FIXME don't know how to do here, let's hope this is correct
@ -2424,9 +2468,11 @@ SWITCH_STANDARD_API(skypiax_chat_function)
//chat_send(p*roto, const char *from, const char *to, const char *subject, const char *body, const char *type, const char *hint);
//chat_send(MDL_CHAT_PROTO, tech_pvt->skype_user, argv[1], "SIMPLE MESSAGE", switch_str_nil((char *) &cmd[strlen(argv[0]) + 1 + strlen(argv[1]) + 1]), NULL, hint);
NOTICA("chat_send(proto=%s, from=%s, to=%s, subject=%s, body=%s, type=NULL, hint=%s)\n", SKYPIAX_P_LOG, MDL_CHAT_PROTO, tech_pvt->skype_user, argv[1], "SIMPLE MESSAGE", switch_str_nil((char *) &cmd[strlen(argv[0]) + 1 + strlen(argv[1]) + 1]), tech_pvt->name);
NOTICA("chat_send(proto=%s, from=%s, to=%s, subject=%s, body=%s, type=NULL, hint=%s)\n", SKYPIAX_P_LOG, MDL_CHAT_PROTO, tech_pvt->skype_user,
argv[1], "SIMPLE MESSAGE", switch_str_nil((char *) &cmd[strlen(argv[0]) + 1 + strlen(argv[1]) + 1]), tech_pvt->name);
chat_send(MDL_CHAT_PROTO, tech_pvt->skype_user, argv[1], "SIMPLE MESSAGE", switch_str_nil((char *) &cmd[strlen(argv[0]) + 1 + strlen(argv[1]) + 1]), NULL, tech_pvt->name);
chat_send(MDL_CHAT_PROTO, tech_pvt->skype_user, argv[1], "SIMPLE MESSAGE",
switch_str_nil((char *) &cmd[strlen(argv[0]) + 1 + strlen(argv[1]) + 1]), NULL, tech_pvt->name);
//NOTICA("TEXT is: %s\n", SKYPIAX_P_LOG, (char *) &cmd[strlen(argv[0]) + 1 + strlen(argv[1]) + 1] );
//snprintf(skype_msg, sizeof(skype_msg), "CHAT CREATE %s", argv[1]);
@ -2445,7 +2491,8 @@ SWITCH_STANDARD_API(skypiax_chat_function)
while (!found) {
for (i = 0; i < MAX_CHATS; i++) {
if (!strcmp(tech_pvt->chats[i].dialog_partner, argv[1])) {
snprintf(skype_msg, sizeof(skype_msg), "CHATMESSAGE %s %s", tech_pvt->chats[i].chatname, (char *) &cmd[strlen(argv[0]) + 1 + strlen(argv[1]) + 1]);
snprintf(skype_msg, sizeof(skype_msg), "CHATMESSAGE %s %s", tech_pvt->chats[i].chatname,
(char *) &cmd[strlen(argv[0]) + 1 + strlen(argv[1]) + 1]);
skypiax_signaling_write(tech_pvt, skype_msg);
found = 1;
break;

View File

@ -277,6 +277,8 @@ struct private_object {
chatmessage_t chatmessages[MAX_CHATMESSAGES];
chat_t chats[MAX_CHATS];
uint32_t report_incoming_chatmessages;
switch_timer_t timer_read;
switch_timer_t timer_write;
};
typedef struct private_object private_t;

View File

@ -308,7 +308,8 @@ int skypiax_signaling_read(private_t * tech_pvt)
DEBUGA_SKYPE("why we do not have a chats slot free? we have more than %d chats in parallel?\n", SKYPIAX_P_LOG, MAX_CHATS);
}
DEBUGA_SKYPE("CHAT %s is in position %d in the chats array, chatname=%s, dialog_partner=%s\n", SKYPIAX_P_LOG, id, i, tech_pvt->chats[i].chatname, tech_pvt->chats[i].dialog_partner);
DEBUGA_SKYPE("CHAT %s is in position %d in the chats array, chatname=%s, dialog_partner=%s\n", SKYPIAX_P_LOG, id, i,
tech_pvt->chats[i].chatname, tech_pvt->chats[i].dialog_partner);
}
}
@ -344,18 +345,20 @@ int skypiax_signaling_read(private_t * tech_pvt)
}
}
if (!found) {
DEBUGA_SKYPE("why we do not have a chatmessages slot free? we have more than %d chatmessages in parallel?\n", SKYPIAX_P_LOG, MAX_CHATMESSAGES);
DEBUGA_SKYPE("why we do not have a chatmessages slot free? we have more than %d chatmessages in parallel?\n", SKYPIAX_P_LOG,
MAX_CHATMESSAGES);
} else {
DEBUGA_SKYPE("CHATMESSAGE %s is in position %d in the chatmessages array, type=%s, id=%s\n", SKYPIAX_P_LOG, id, i, tech_pvt->chatmessages[i].type, tech_pvt->chatmessages[i].id);
DEBUGA_SKYPE("CHATMESSAGE %s is in position %d in the chatmessages array, type=%s, id=%s\n", SKYPIAX_P_LOG, id, i,
tech_pvt->chatmessages[i].type, tech_pvt->chatmessages[i].id);
sprintf(msg_to_skype, "GET CHATMESSAGE %s CHATNAME", id);
skypiax_signaling_write(tech_pvt, msg_to_skype);
skypiax_sleep(100);
skypiax_sleep(1000);
sprintf(msg_to_skype, "GET CHATMESSAGE %s FROM_HANDLE", id);
skypiax_signaling_write(tech_pvt, msg_to_skype);
skypiax_sleep(100);
skypiax_sleep(1000);
sprintf(msg_to_skype, "GET CHATMESSAGE %s FROM_DISPNAME", id);
skypiax_signaling_write(tech_pvt, msg_to_skype);
skypiax_sleep(100);
skypiax_sleep(1000);
sprintf(msg_to_skype, "GET CHATMESSAGE %s BODY", id);
skypiax_signaling_write(tech_pvt, msg_to_skype);
}
@ -418,7 +421,10 @@ int skypiax_signaling_read(private_t * tech_pvt)
if (!found) {
DEBUGA_SKYPE("why chatmessage %s was not found in the chatmessages array??\n", SKYPIAX_P_LOG, id);
} else {
DEBUGA_SKYPE("CHATMESSAGE %s is in position %d in the chatmessages array, type=%s, id=%s, chatname=%s, from_handle=%s, from_dispname=%s, body=%s\n", SKYPIAX_P_LOG, id, i, tech_pvt->chatmessages[i].type, tech_pvt->chatmessages[i].id, tech_pvt->chatmessages[i].chatname, tech_pvt->chatmessages[i].from_handle, tech_pvt->chatmessages[i].from_dispname, tech_pvt->chatmessages[i].body);
DEBUGA_SKYPE
("CHATMESSAGE %s is in position %d in the chatmessages array, type=%s, id=%s, chatname=%s, from_handle=%s, from_dispname=%s, body=%s\n",
SKYPIAX_P_LOG, id, i, tech_pvt->chatmessages[i].type, tech_pvt->chatmessages[i].id, tech_pvt->chatmessages[i].chatname,
tech_pvt->chatmessages[i].from_handle, tech_pvt->chatmessages[i].from_dispname, tech_pvt->chatmessages[i].body);
if (strcmp(tech_pvt->chatmessages[i].from_handle, tech_pvt->skype_user)) { //if the message was not sent by myself
incoming_chatmessage(tech_pvt, i);
}
@ -1800,7 +1806,7 @@ void *skypiax_do_skypeapi_thread_func(void *obj)
case ClientMessage:
if (an_event.xclient.format != 8) {
skypiax_sleep(100); //0.1 msec
skypiax_sleep(1000); //0.1 msec
break;
}
@ -1818,7 +1824,9 @@ void *skypiax_do_skypeapi_thread_func(void *obj)
unsigned int howmany;
howmany = strlen(b) + 1;
howmany = write(SkypiaxHandles->fdesc[1], b, howmany);
WARNINGA("A begin atom while the previous message is not closed???? value of previous message (between vertical bars) is=|||%s|||, will be lost\n", SKYPIAX_P_LOG, buffer);
WARNINGA
("A begin atom while the previous message is not closed???? value of previous message (between vertical bars) is=|||%s|||, will be lost\n",
SKYPIAX_P_LOG, buffer);
memset(buffer, '\0', 17000);
}
if (continue_is_broken) {
@ -1831,7 +1839,8 @@ void *skypiax_do_skypeapi_thread_func(void *obj)
if (!strlen(buffer)) {
DEBUGA_SKYPE
("Got a 'continue' XAtom without a previous 'begin'. It's value (between vertical bars) is=|||%s|||, let's store it and hope next 'begin' will be the good one\n", SKYPIAX_P_LOG, buf);
("Got a 'continue' XAtom without a previous 'begin'. It's value (between vertical bars) is=|||%s|||, let's store it and hope next 'begin' will be the good one\n",
SKYPIAX_P_LOG, buf);
strcat(continuebuffer, buf);
continue_is_broken = 1;
if (!strncmp(buf, "ognised identity", 15)) {
@ -1840,16 +1849,15 @@ void *skypiax_do_skypeapi_thread_func(void *obj)
SKYPIAX_P_LOG, buf);
skypiax_sleep(1000000); //1 sec
}
skypiax_sleep(100); //0.1 msec
skypiax_sleep(1000); //0.1 msec
break;
}
}
if (continue_is_broken) {
XFlush(disp);
skypiax_sleep(100); //0.1 msec
skypiax_sleep(1000); //0.1 msec
continue;
}
//DEBUGA_SKYPE ("i=%d, buffer=|||%s|||\n", SKYPIAX_P_LOG, i, buffer);
strcat(buffer, buf);
//DEBUGA_SKYPE ("i=%d, buffer=|||%s|||\n", SKYPIAX_P_LOG, i, buffer);
@ -1869,10 +1877,10 @@ void *skypiax_do_skypeapi_thread_func(void *obj)
there_were_continues = 0;
}
skypiax_sleep(100); //0.1 msec
skypiax_sleep(1000); //0.1 msec
break;
default:
skypiax_sleep(100); //0.1 msec
skypiax_sleep(1000); //0.1 msec
break;
}
}