skypopen: better X11 interaction with a select on XEvents, no more setsockopt by default (tcp buffer size and TCP_NODELAY), setsockopt in config file

This commit is contained in:
Giovanni 2010-04-06 17:48:18 +02:00
parent 0bdc156882
commit 7b7a063693
4 changed files with 64 additions and 9 deletions

View File

@ -236,7 +236,7 @@ static void snd_card_dummy_pcm_timer_function(unsigned long data)
giovatimer.expires = 1 + jiffies; giovatimer.expires = 1 + jiffies;
add_timer(&giovatimer); add_timer(&giovatimer);
spin_lock_bh(&giovalock); //spin_lock_bh(&giovalock);
for (i = 0; i < giovaindex + 1; i++) { for (i = 0; i < giovaindex + 1; i++) {
if (i > MAX_PCM_SUBSTREAMS || giovaindex > MAX_PCM_SUBSTREAMS) { 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(&dpcm->lock);
} }
} }
spin_unlock_bh(&giovalock); //spin_unlock_bh(&giovalock);
for (i = 0; i < giovaindex + 1; i++) { for (i = 0; i < giovaindex + 1; i++) {
if (i > MAX_PCM_SUBSTREAMS || giovaindex > MAX_PCM_SUBSTREAMS) { 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.function = snd_card_dummy_pcm_timer_function;
giovatimer.expires = 1 + jiffies; giovatimer.expires = 1 + jiffies;
add_timer(&giovatimer); 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); spin_unlock_bh(&giovalock);
} }

View File

@ -151,6 +151,7 @@ static struct {
char *report_incoming_chatmessages; char *report_incoming_chatmessages;
char *silent_mode; char *silent_mode;
char *write_silence_when_idle; char *write_silence_when_idle;
char *setsockopt;
int calls; int calls;
int real_interfaces; int real_interfaces;
int next_interface; 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_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_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_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 interface_exists(char *the_interface);
static switch_status_t remove_interface(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")) { } else if (!strcmp(var, "write_silence_when_idle")) {
set_global_write_silence_when_idle(val); set_global_write_silence_when_idle(val);
DEBUGA_SKYPE("globals.write_silence_when_idle=%s\n", SKYPOPEN_P_LOG, globals.write_silence_when_idle); 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 *report_incoming_chatmessages = "true";
char *silent_mode = "false"; char *silent_mode = "false";
char *write_silence_when_idle = "true"; char *write_silence_when_idle = "true";
char *setsockopt = "false";
uint32_t interface_id = 0; uint32_t interface_id = 0;
if(globals.context) if(globals.context)
@ -1277,6 +1283,8 @@ static switch_status_t load_config(int reload_type)
silent_mode=globals.silent_mode; silent_mode=globals.silent_mode;
if(globals.write_silence_when_idle) if(globals.write_silence_when_idle)
write_silence_when_idle=globals.write_silence_when_idle; write_silence_when_idle=globals.write_silence_when_idle;
if(globals.setsockopt)
setsockopt=globals.setsockopt;
tech_pvt = NULL; tech_pvt = NULL;
@ -1298,6 +1306,8 @@ static switch_status_t load_config(int reload_type)
silent_mode = val; silent_mode = val;
} else if (!strcasecmp(var, "write_silence_when_idle")) { } else if (!strcasecmp(var, "write_silence_when_idle")) {
write_silence_when_idle = val; write_silence_when_idle = val;
} else if (!strcasecmp(var, "setsockopt")) {
setsockopt = val;
} else if (!strcasecmp(var, "X11-display") || !strcasecmp(var, "X11_display")) { } else if (!strcasecmp(var, "X11-display") || !strcasecmp(var, "X11_display")) {
X11_display = val; 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", DEBUGA_SKYPE("interface_id=%d globals.SKYPOPEN_INTERFACES[interface_id].name=%s\n",
SKYPOPEN_P_LOG, interface_id, globals.SKYPOPEN_INTERFACES[interface_id].name); SKYPOPEN_P_LOG, interface_id, globals.SKYPOPEN_INTERFACES[interface_id].name);
DEBUGA_SKYPE DEBUGA_SKYPE
@ -1423,6 +1440,9 @@ static switch_status_t load_config(int reload_type)
DEBUGA_SKYPE DEBUGA_SKYPE
("interface_id=%d globals.SKYPOPEN_INTERFACES[interface_id].write_silence_when_idle=%d\n", ("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); 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); 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); 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].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].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.report_incoming_chatmessages);
switch_safe_free(globals.silent_mode); switch_safe_free(globals.silent_mode);
switch_safe_free(globals.write_silence_when_idle); switch_safe_free(globals.write_silence_when_idle);
switch_safe_free(globals.setsockopt);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }

View File

@ -287,6 +287,7 @@ struct private_object {
switch_buffer_t *read_buffer; switch_buffer_t *read_buffer;
int silent_mode; int silent_mode;
int write_silence_when_idle; int write_silence_when_idle;
int setsockopt;
}; };

View File

@ -103,7 +103,9 @@ int skypopen_socket_create_and_bind(private_t * tech_pvt, unsigned short *which_
sockbufsize = SAMPLES_PER_FRAME * 8; sockbufsize = SAMPLES_PER_FRAME * 8;
#endif //WIN32 #endif //WIN32
size = sizeof(int); 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; sockbufsize = 0;
size = sizeof(int); 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; sockbufsize = SAMPLES_PER_FRAME * 8;
#endif //WIN32 #endif //WIN32
size = sizeof(int); 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; sockbufsize = 0;
size = sizeof(int); 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); getsockopt(s, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, &size);
DEBUGA_SKYPE("TCP_NODELAY is %d\n", SKYPOPEN_P_LOG, flag); DEBUGA_SKYPE("TCP_NODELAY is %d\n", SKYPOPEN_P_LOG, flag);
flag = 1; 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; flag = 0;
getsockopt(s, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, &size); getsockopt(s, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, &size);
DEBUGA_SKYPE("TCP_NODELAY is %d\n", SKYPOPEN_P_LOG, flag); 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 root = -1;
Window win = -1; Window win = -1;
int xfd; int xfd;
fd_set xfds;
if (!strlen(tech_pvt->X11_display)) if (!strlen(tech_pvt->X11_display))
strcpy(tech_pvt->X11_display, getenv("DISPLAY")); strcpy(tech_pvt->X11_display, getenv("DISPLAY"));
@ -1623,6 +1630,7 @@ void *skypopen_do_skypeapi_thread_func(void *obj)
int i; int i;
int continue_is_broken = 0; int continue_is_broken = 0;
int there_were_continues = 0; int there_were_continues = 0;
struct timeval tv;
Atom atom_begin = XInternAtom(disp, "SKYPECONTROLAPI_MESSAGE_BEGIN", False); Atom atom_begin = XInternAtom(disp, "SKYPECONTROLAPI_MESSAGE_BEGIN", False);
Atom atom_continue = XInternAtom(disp, "SKYPECONTROLAPI_MESSAGE", False); Atom atom_continue = XInternAtom(disp, "SKYPECONTROLAPI_MESSAGE", False);
@ -1631,6 +1639,22 @@ void *skypopen_do_skypeapi_thread_func(void *obj)
b = buffer; b = buffer;
while (running && tech_pvt->running) { 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); XNextEvent(disp, &an_event);
if (!(running && tech_pvt->running)) if (!(running && tech_pvt->running))
break; break;
@ -1664,7 +1688,7 @@ void *skypopen_do_skypeapi_thread_func(void *obj)
} }
if (an_event.xclient.message_type == atom_continue) { if (an_event.xclient.message_type == atom_continue) {
if (!strlen(buffer)) { 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", ("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); SKYPOPEN_P_LOG, buf);
strcat(continuebuffer, buf); strcat(continuebuffer, buf);
@ -1703,8 +1727,16 @@ void *skypopen_do_skypeapi_thread_func(void *obj)
default: default:
skypopen_sleep(1000); //0.1 msec skypopen_sleep(1000); //0.1 msec
break; break;
} } //switch event.type
} } //while XPending
} // if select
} //while running
} }
} else { } else {
ERRORA("Skype is not running, maybe crashed. Please run/restart Skype and relaunch Skypopen\n", SKYPOPEN_P_LOG); ERRORA("Skype is not running, maybe crashed. Please run/restart Skype and relaunch Skypopen\n", SKYPOPEN_P_LOG);