From 7b7a0636932e99d194bd520662309ef06c083db9 Mon Sep 17 00:00:00 2001 From: Giovanni Date: Tue, 6 Apr 2010 17:48:18 +0200 Subject: [PATCH 1/3] skypopen: better X11 interaction with a select on XEvents, no more setsockopt by default (tcp buffer size and TCP_NODELAY), setsockopt in config file --- src/mod/endpoints/mod_skypopen/alsa/dummy.c | 6 +-- src/mod/endpoints/mod_skypopen/mod_skypopen.c | 22 ++++++++++ src/mod/endpoints/mod_skypopen/skypopen.h | 1 + .../mod_skypopen/skypopen_protocol.c | 44 ++++++++++++++++--- 4 files changed, 64 insertions(+), 9 deletions(-) diff --git a/src/mod/endpoints/mod_skypopen/alsa/dummy.c b/src/mod/endpoints/mod_skypopen/alsa/dummy.c index 21db5b3885..6b8c86f245 100644 --- a/src/mod/endpoints/mod_skypopen/alsa/dummy.c +++ b/src/mod/endpoints/mod_skypopen/alsa/dummy.c @@ -236,7 +236,7 @@ static void snd_card_dummy_pcm_timer_function(unsigned long data) giovatimer.expires = 1 + jiffies; add_timer(&giovatimer); - spin_lock_bh(&giovalock); + //spin_lock_bh(&giovalock); for (i = 0; i < giovaindex + 1; i++) { if (i > MAX_PCM_SUBSTREAMS || giovaindex > MAX_PCM_SUBSTREAMS) { @@ -262,7 +262,7 @@ static void snd_card_dummy_pcm_timer_function(unsigned long data) //spin_unlock_bh(&dpcm->lock); } } - spin_unlock_bh(&giovalock); + //spin_unlock_bh(&giovalock); for (i = 0; i < giovaindex + 1; i++) { if (i > MAX_PCM_SUBSTREAMS || giovaindex > MAX_PCM_SUBSTREAMS) { @@ -774,7 +774,7 @@ static int __init alsa_card_dummy_init(void) giovatimer.function = snd_card_dummy_pcm_timer_function; giovatimer.expires = 1 + jiffies; add_timer(&giovatimer); - printk("snd-dummy skypopen driver version: 5, %s:%d working on a machine with %dHZ kernel\n", __FILE__, __LINE__, HZ); + printk("snd-dummy skypopen driver version: 6, %s:%d working on a machine with %dHZ kernel\n", __FILE__, __LINE__, HZ); spin_unlock_bh(&giovalock); } diff --git a/src/mod/endpoints/mod_skypopen/mod_skypopen.c b/src/mod/endpoints/mod_skypopen/mod_skypopen.c index eff59c2c36..97d0ce6778 100644 --- a/src/mod/endpoints/mod_skypopen/mod_skypopen.c +++ b/src/mod/endpoints/mod_skypopen/mod_skypopen.c @@ -151,6 +151,7 @@ static struct { char *report_incoming_chatmessages; char *silent_mode; char *write_silence_when_idle; + char *setsockopt; int calls; int real_interfaces; int next_interface; @@ -171,6 +172,7 @@ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_skype_user, globals.skype_user); SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_report_incoming_chatmessages, globals.report_incoming_chatmessages); SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_silent_mode, globals.silent_mode); SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_write_silence_when_idle, globals.write_silence_when_idle); +SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_setsockopt, globals.setsockopt); static switch_status_t interface_exists(char *the_interface); static switch_status_t remove_interface(char *the_interface); @@ -1241,6 +1243,9 @@ static switch_status_t load_config(int reload_type) } else if (!strcmp(var, "write_silence_when_idle")) { set_global_write_silence_when_idle(val); DEBUGA_SKYPE("globals.write_silence_when_idle=%s\n", SKYPOPEN_P_LOG, globals.write_silence_when_idle); + } else if (!strcmp(var, "setsockopt")) { + set_global_setsockopt(val); + DEBUGA_SKYPE("globals.setsockopt=%s\n", SKYPOPEN_P_LOG, globals.setsockopt); } } @@ -1261,6 +1266,7 @@ static switch_status_t load_config(int reload_type) char *report_incoming_chatmessages = "true"; char *silent_mode = "false"; char *write_silence_when_idle = "true"; + char *setsockopt = "false"; uint32_t interface_id = 0; if(globals.context) @@ -1277,6 +1283,8 @@ static switch_status_t load_config(int reload_type) silent_mode=globals.silent_mode; if(globals.write_silence_when_idle) write_silence_when_idle=globals.write_silence_when_idle; + if(globals.setsockopt) + setsockopt=globals.setsockopt; tech_pvt = NULL; @@ -1298,6 +1306,8 @@ static switch_status_t load_config(int reload_type) silent_mode = val; } else if (!strcasecmp(var, "write_silence_when_idle")) { write_silence_when_idle = val; + } else if (!strcasecmp(var, "setsockopt")) { + setsockopt = val; } else if (!strcasecmp(var, "X11-display") || !strcasecmp(var, "X11_display")) { X11_display = val; } @@ -1397,6 +1407,13 @@ static switch_status_t load_config(int reload_type) } + if (!strcmp(setsockopt, "true") || !strcmp(setsockopt, "1")) { + globals.SKYPOPEN_INTERFACES[interface_id].setsockopt = 1; + } else { + globals.SKYPOPEN_INTERFACES[interface_id].setsockopt = 0; //redundant, just in case + + } + DEBUGA_SKYPE("interface_id=%d globals.SKYPOPEN_INTERFACES[interface_id].name=%s\n", SKYPOPEN_P_LOG, interface_id, globals.SKYPOPEN_INTERFACES[interface_id].name); DEBUGA_SKYPE @@ -1423,6 +1440,9 @@ static switch_status_t load_config(int reload_type) DEBUGA_SKYPE ("interface_id=%d globals.SKYPOPEN_INTERFACES[interface_id].write_silence_when_idle=%d\n", SKYPOPEN_P_LOG, interface_id, globals.SKYPOPEN_INTERFACES[interface_id].write_silence_when_idle); + DEBUGA_SKYPE + ("interface_id=%d globals.SKYPOPEN_INTERFACES[interface_id].setsockopt=%d\n", + SKYPOPEN_P_LOG, interface_id, globals.SKYPOPEN_INTERFACES[interface_id].setsockopt); WARNINGA("STARTING interface_id=%d\n", SKYPOPEN_P_LOG, interface_id); @@ -1532,6 +1552,7 @@ static switch_status_t load_config(int reload_type) globals.SKYPOPEN_INTERFACES[i].report_incoming_chatmessages); DEBUGA_SKYPE("i=%d globals.SKYPOPEN_INTERFACES[%d].silent_mode=%d\n", SKYPOPEN_P_LOG, i, i, globals.SKYPOPEN_INTERFACES[i].silent_mode); DEBUGA_SKYPE("i=%d globals.SKYPOPEN_INTERFACES[%d].write_silence_when_idle=%d\n", SKYPOPEN_P_LOG, i, i, globals.SKYPOPEN_INTERFACES[i].write_silence_when_idle); + DEBUGA_SKYPE("i=%d globals.SKYPOPEN_INTERFACES[%d].setsockopt=%d\n", SKYPOPEN_P_LOG, i, i, globals.SKYPOPEN_INTERFACES[i].setsockopt); } } } @@ -1775,6 +1796,7 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_skypopen_shutdown) switch_safe_free(globals.report_incoming_chatmessages); switch_safe_free(globals.silent_mode); switch_safe_free(globals.write_silence_when_idle); + switch_safe_free(globals.setsockopt); return SWITCH_STATUS_SUCCESS; } diff --git a/src/mod/endpoints/mod_skypopen/skypopen.h b/src/mod/endpoints/mod_skypopen/skypopen.h index d1d0c5dd00..b978623fd5 100644 --- a/src/mod/endpoints/mod_skypopen/skypopen.h +++ b/src/mod/endpoints/mod_skypopen/skypopen.h @@ -287,6 +287,7 @@ struct private_object { switch_buffer_t *read_buffer; int silent_mode; int write_silence_when_idle; + int setsockopt; }; diff --git a/src/mod/endpoints/mod_skypopen/skypopen_protocol.c b/src/mod/endpoints/mod_skypopen/skypopen_protocol.c index 2241197e27..77568c6e5c 100644 --- a/src/mod/endpoints/mod_skypopen/skypopen_protocol.c +++ b/src/mod/endpoints/mod_skypopen/skypopen_protocol.c @@ -103,7 +103,9 @@ int skypopen_socket_create_and_bind(private_t * tech_pvt, unsigned short *which_ sockbufsize = SAMPLES_PER_FRAME * 8; #endif //WIN32 size = sizeof(int); - setsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *) &sockbufsize, size); + if(tech_pvt->setsockopt){ + setsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *) &sockbufsize, size); + } sockbufsize = 0; size = sizeof(int); @@ -120,7 +122,9 @@ int skypopen_socket_create_and_bind(private_t * tech_pvt, unsigned short *which_ sockbufsize = SAMPLES_PER_FRAME * 8; #endif //WIN32 size = sizeof(int); - setsockopt(s, SOL_SOCKET, SO_SNDBUF, (char *) &sockbufsize, size); + if(tech_pvt->setsockopt){ + setsockopt(s, SOL_SOCKET, SO_SNDBUF, (char *) &sockbufsize, size); + } sockbufsize = 0; size = sizeof(int); @@ -131,7 +135,9 @@ int skypopen_socket_create_and_bind(private_t * tech_pvt, unsigned short *which_ getsockopt(s, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, &size); DEBUGA_SKYPE("TCP_NODELAY is %d\n", SKYPOPEN_P_LOG, flag); flag = 1; - setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, size); + if(tech_pvt->setsockopt){ + setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, size); + } flag = 0; getsockopt(s, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, &size); DEBUGA_SKYPE("TCP_NODELAY is %d\n", SKYPOPEN_P_LOG, flag); @@ -1563,6 +1569,7 @@ void *skypopen_do_skypeapi_thread_func(void *obj) Window root = -1; Window win = -1; int xfd; + fd_set xfds; if (!strlen(tech_pvt->X11_display)) strcpy(tech_pvt->X11_display, getenv("DISPLAY")); @@ -1623,6 +1630,7 @@ void *skypopen_do_skypeapi_thread_func(void *obj) int i; int continue_is_broken = 0; int there_were_continues = 0; + struct timeval tv; Atom atom_begin = XInternAtom(disp, "SKYPECONTROLAPI_MESSAGE_BEGIN", False); Atom atom_continue = XInternAtom(disp, "SKYPECONTROLAPI_MESSAGE", False); @@ -1631,6 +1639,22 @@ void *skypopen_do_skypeapi_thread_func(void *obj) b = buffer; while (running && tech_pvt->running) { + + + FD_ZERO(&xfds); + FD_SET(xfd, &xfds); + + tv.tv_usec = 100000; + tv.tv_sec = 0; + + + +if (select(xfd+1, &xfds, 0, 0, &tv)){ + +while(XPending(disp)){ + + + XNextEvent(disp, &an_event); if (!(running && tech_pvt->running)) break; @@ -1664,7 +1688,7 @@ void *skypopen_do_skypeapi_thread_func(void *obj) } if (an_event.xclient.message_type == atom_continue) { if (!strlen(buffer)) { - DEBUGA_SKYPE + WARNINGA ("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", SKYPOPEN_P_LOG, buf); strcat(continuebuffer, buf); @@ -1703,8 +1727,16 @@ void *skypopen_do_skypeapi_thread_func(void *obj) default: skypopen_sleep(1000); //0.1 msec break; - } - } + } //switch event.type + } //while XPending + +} // if select +} //while running + + + + + } } else { ERRORA("Skype is not running, maybe crashed. Please run/restart Skype and relaunch Skypopen\n", SKYPOPEN_P_LOG); From ea8f69fd7721a31c29ce3703352616a451106fce Mon Sep 17 00:00:00 2001 From: Giovanni Date: Tue, 6 Apr 2010 17:52:40 +0200 Subject: [PATCH 2/3] skypopen: reversed previous commit of alsa/dummy.c (I like to have it in a separate commit) --- src/mod/endpoints/mod_skypopen/alsa/dummy.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mod/endpoints/mod_skypopen/alsa/dummy.c b/src/mod/endpoints/mod_skypopen/alsa/dummy.c index 6b8c86f245..5d16436c34 100644 --- a/src/mod/endpoints/mod_skypopen/alsa/dummy.c +++ b/src/mod/endpoints/mod_skypopen/alsa/dummy.c @@ -236,7 +236,7 @@ static void snd_card_dummy_pcm_timer_function(unsigned long data) giovatimer.expires = 1 + jiffies; add_timer(&giovatimer); - //spin_lock_bh(&giovalock); + spin_lock_bh(&giovalock); for (i = 0; i < giovaindex + 1; i++) { if (i > MAX_PCM_SUBSTREAMS || giovaindex > MAX_PCM_SUBSTREAMS) { @@ -262,7 +262,7 @@ static void snd_card_dummy_pcm_timer_function(unsigned long data) //spin_unlock_bh(&dpcm->lock); } } - //spin_unlock_bh(&giovalock); + spin_unlock_bh(&giovalock); for (i = 0; i < giovaindex + 1; i++) { if (i > MAX_PCM_SUBSTREAMS || giovaindex > MAX_PCM_SUBSTREAMS) { From ce882fb6f129c6acea5476a23ab94ffca37ca65e Mon Sep 17 00:00:00 2001 From: Giovanni Date: Tue, 6 Apr 2010 17:54:32 +0200 Subject: [PATCH 3/3] skypopen: alsa/dummy.c, the snd-summy custom alsa driver, now do not spin_lock_bh() on timer loop --- src/mod/endpoints/mod_skypopen/alsa/dummy.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mod/endpoints/mod_skypopen/alsa/dummy.c b/src/mod/endpoints/mod_skypopen/alsa/dummy.c index 5d16436c34..6b8c86f245 100644 --- a/src/mod/endpoints/mod_skypopen/alsa/dummy.c +++ b/src/mod/endpoints/mod_skypopen/alsa/dummy.c @@ -236,7 +236,7 @@ static void snd_card_dummy_pcm_timer_function(unsigned long data) giovatimer.expires = 1 + jiffies; add_timer(&giovatimer); - spin_lock_bh(&giovalock); + //spin_lock_bh(&giovalock); for (i = 0; i < giovaindex + 1; i++) { if (i > MAX_PCM_SUBSTREAMS || giovaindex > MAX_PCM_SUBSTREAMS) { @@ -262,7 +262,7 @@ static void snd_card_dummy_pcm_timer_function(unsigned long data) //spin_unlock_bh(&dpcm->lock); } } - spin_unlock_bh(&giovalock); + //spin_unlock_bh(&giovalock); for (i = 0; i < giovaindex + 1; i++) { if (i > MAX_PCM_SUBSTREAMS || giovaindex > MAX_PCM_SUBSTREAMS) {