skypopen: a little bit of constant cleaning, and screening of A-D dtmfs (not accepted bu Skype client) - fix for FS-2891

This commit is contained in:
Giovanni Maruzzelli 2010-12-01 17:10:14 -06:00
parent 7dcddfa881
commit 04a092fab5
3 changed files with 34 additions and 26 deletions

View File

@ -261,7 +261,7 @@ switch_status_t skypopen_tech_init(private_t *tech_pvt, switch_core_session_t *s
ERRORA("skypopen_tech_init: no tech_pvt->session_uuid_str\n", SKYPOPEN_P_LOG);
return SWITCH_STATUS_FALSE;
}
if (skypopen_codec(tech_pvt, SAMPLERATE_SKYPOPEN, 20) != SWITCH_STATUS_SUCCESS) {
if (skypopen_codec(tech_pvt, SAMPLERATE_SKYPOPEN, MS_SKYPOPEN) != SWITCH_STATUS_SUCCESS) {
ERRORA("skypopen_tech_init: skypopen_codec FAILED\n", SKYPOPEN_P_LOG);
return SWITCH_STATUS_FALSE;
}
@ -822,23 +822,23 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
tech_pvt->read_frame.flags = SFF_NONE;
if (!switch_test_flag(tech_pvt, TFLAG_IO)) {
switch_sleep(20000);
switch_sleep(MS_SKYPOPEN * 1000);
return SWITCH_STATUS_FALSE;
}
if (!switch_channel_ready(channel)) {
ERRORA("channel not ready \n", SKYPOPEN_P_LOG);
switch_sleep(20000);
switch_sleep(MS_SKYPOPEN * 1000);
return SWITCH_STATUS_FALSE;
}
if (switch_test_flag(tech_pvt, TFLAG_PROGRESS)) {
//DEBUGA_SKYPE("CHANNEL READ FRAME in TFLAG_PROGRESS goto CNG\n", SKYPOPEN_P_LOG);
switch_sleep(20000);
switch_sleep(MS_SKYPOPEN * 1000);
goto cng;
}
if (!tech_pvt->read_buffer) {
int32_t max_len = 640 * 10;
int32_t max_len = BYTES_PER_FRAME * 10;
switch_buffer_create(skypopen_module_pool, &tech_pvt->read_buffer, max_len);
switch_assert(tech_pvt->read_buffer);
@ -861,7 +861,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
|| tech_pvt->skype_callflow == CALLFLOW_STATUS_REMOTEHOLD || tech_pvt->skype_callflow == SKYPOPEN_STATE_UP)) {
switch_mutex_lock(tech_pvt->mutex_audio_srv);
if (tech_pvt->read_buffer && switch_buffer_inuse(tech_pvt->read_buffer)) {
bytes_read = switch_buffer_read(tech_pvt->read_buffer, tech_pvt->read_frame.data, 640);
bytes_read = switch_buffer_read(tech_pvt->read_buffer, tech_pvt->read_frame.data, BYTES_PER_FRAME);
tech_pvt->read_frame.datalen = bytes_read;
}
switch_mutex_unlock(tech_pvt->mutex_audio_srv);
@ -873,13 +873,13 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
if (try < 5)
goto read;
DEBUGA_SKYPE("skypopen_audio_read Silence\n", SKYPOPEN_P_LOG);
memset(tech_pvt->read_frame.data, 255, SAMPLES_PER_FRAME * sizeof(short));
tech_pvt->read_frame.datalen = 640;
memset(tech_pvt->read_frame.data, 255, BYTES_PER_FRAME);
tech_pvt->read_frame.datalen = BYTES_PER_FRAME;
}
} else {
memset(tech_pvt->read_frame.data, 255, SAMPLES_PER_FRAME * sizeof(short));
tech_pvt->read_frame.datalen = 640;
memset(tech_pvt->read_frame.data, 255, BYTES_PER_FRAME);
tech_pvt->read_frame.datalen = BYTES_PER_FRAME;
}
switch_mutex_lock(tech_pvt->flag_mutex);
@ -1002,7 +1002,7 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc
}
#endif
if (!tech_pvt->write_buffer) {
int32_t max_len = 640 * 3;
int32_t max_len = BYTES_PER_FRAME * 3;
switch_buffer_create(skypopen_module_pool, &tech_pvt->write_buffer, max_len);
switch_assert(tech_pvt->write_buffer);
@ -1017,7 +1017,7 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc
switch_buffer_write(tech_pvt->write_buffer, frame->data, frame->datalen);
switch_mutex_unlock(tech_pvt->mutex_audio_cli);
if (no_space) {
switch_sleep(20000);
switch_sleep(MS_SKYPOPEN * 1000);
} else {
tech_pvt->begin_to_write = 1;
}
@ -2161,14 +2161,14 @@ int start_audio_threads(private_t *tech_pvt)
tech_pvt->begin_to_write = 0;
tech_pvt->begin_to_read = 0;
if (switch_core_timer_init(&tech_pvt->timer_read, "soft", 20, 320, skypopen_module_pool) != SWITCH_STATUS_SUCCESS) {
if (switch_core_timer_init(&tech_pvt->timer_read, "soft", MS_SKYPOPEN, SAMPLES_PER_FRAME, skypopen_module_pool) != SWITCH_STATUS_SUCCESS) {
ERRORA("setup timer failed\n", SKYPOPEN_P_LOG);
return SWITCH_STATUS_FALSE;
}
switch_core_timer_sync(&tech_pvt->timer_read);
if (switch_core_timer_init(&tech_pvt->timer_write, "soft", 20, 320, skypopen_module_pool) != SWITCH_STATUS_SUCCESS) {
if (switch_core_timer_init(&tech_pvt->timer_write, "soft", MS_SKYPOPEN, SAMPLES_PER_FRAME, skypopen_module_pool) != SWITCH_STATUS_SUCCESS) {
ERRORA("setup timer failed\n", SKYPOPEN_P_LOG);
return SWITCH_STATUS_FALSE;
}

View File

@ -75,7 +75,9 @@
#define MY_EVENT_INCOMING_RAW "skypopen::incoming_raw"
#define SAMPLERATE_SKYPOPEN 16000
#define SAMPLES_PER_FRAME SAMPLERATE_SKYPOPEN/50
#define MS_SKYPOPEN 20
#define SAMPLES_PER_FRAME SAMPLERATE_SKYPOPEN/(1000/MS_SKYPOPEN)
#define BYTES_PER_FRAME SAMPLES_PER_FRAME * sizeof(short)
#ifdef SKYPOPEN_C_VER
#ifdef MODSKYPOPEN_C_VER

View File

@ -846,7 +846,7 @@ void *skypopen_do_tcp_srv_thread_func(void *obj)
if (!(running && tech_pvt->running))
break;
FD_ZERO(&fsgio);
togio.tv_usec = 20000; //20msec
togio.tv_usec = MS_SKYPOPEN * 1000;
togio.tv_sec = 0;
fdselectgio = s;
FD_SET(fdselectgio, &fsgio);
@ -888,14 +888,14 @@ void *skypopen_do_tcp_srv_thread_func(void *obj)
fdselect = fd;
FD_ZERO(&fs);
FD_SET(fdselect, &fs);
to.tv_usec = 60000; //60 msec
to.tv_usec = MS_SKYPOPEN * 1000 * 3;
to.tv_sec = 0;
rt = select(fdselect + 1, &fs, NULL, NULL, &to);
if (rt > 0) {
if (tech_pvt->skype_callflow != CALLFLOW_STATUS_REMOTEHOLD) {
len = recv(fd, (char *) srv_in, 640, 0);
len = recv(fd, (char *) srv_in, BYTES_PER_FRAME, 0);
} else {
skypopen_sleep(10000);
continue;
@ -916,13 +916,15 @@ void *skypopen_do_tcp_srv_thread_func(void *obj)
if (tech_pvt->read_buffer) {
if (switch_buffer_freespace(tech_pvt->read_buffer) < len) {
switch_buffer_zero(tech_pvt->read_buffer);
switch_buffer_write(tech_pvt->read_buffer, srv_in, len);
nospace = 1;
} else {
switch_buffer_write(tech_pvt->read_buffer, srv_in, len);
}
switch_buffer_write(tech_pvt->read_buffer, srv_in, len);
}
switch_mutex_unlock(tech_pvt->mutex_audio_srv);
if (nospace) {
DEBUGA_SKYPE("NO SPACE READ: there was no space for: %d\n", SKYPOPEN_P_LOG, len);
WARNINGA("NO SPACE READ: there was no space for: %d\n", SKYPOPEN_P_LOG, len);
}
} else if (len == 0) {
DEBUGA_SKYPE("CLOSED\n", SKYPOPEN_P_LOG);
@ -1005,7 +1007,7 @@ void *skypopen_do_tcp_cli_thread_func(void *obj)
if (!(running && tech_pvt->running))
break;
FD_ZERO(&fsgio);
togio.tv_usec = 60000; //60msec
togio.tv_usec = MS_SKYPOPEN * 1000 * 3;
togio.tv_sec = 0;
fdselectgio = s;
FD_SET(fdselectgio, &fsgio);
@ -1048,7 +1050,7 @@ void *skypopen_do_tcp_cli_thread_func(void *obj)
if (tech_pvt->begin_to_write == 0) {
memset(cli_out, 255, sizeof(cli_out));
bytes_to_write = 640;
bytes_to_write = BYTES_PER_FRAME;
len = send(fd, (char *) cli_out, bytes_to_write, 0);
if (len == -1) {
DEBUGA_SKYPE("len=%d, error: %s\n", SKYPOPEN_P_LOG, len, strerror(errno));
@ -1065,14 +1067,14 @@ void *skypopen_do_tcp_cli_thread_func(void *obj)
}
switch_mutex_lock(tech_pvt->mutex_audio_cli);
if (tech_pvt->write_buffer && switch_buffer_inuse(tech_pvt->write_buffer)) {
bytes_to_write = switch_buffer_read(tech_pvt->write_buffer, cli_out, 640);
bytes_to_write = switch_buffer_read(tech_pvt->write_buffer, cli_out, BYTES_PER_FRAME);
}
switch_mutex_unlock(tech_pvt->mutex_audio_cli);
if (!bytes_to_write) {
if (tech_pvt->write_silence_when_idle) {
memset(cli_out, 255, sizeof(cli_out));
bytes_to_write = 640;
bytes_to_write = BYTES_PER_FRAME;
//DEBUGA_SKYPE("WRITE Silence!\n", SKYPOPEN_P_LOG);
} else {
continue;
@ -1118,8 +1120,12 @@ int skypopen_senddigit(private_t *tech_pvt, char digit)
char msg_to_skype[1024];
DEBUGA_SKYPE("DIGIT received: %c\n", SKYPOPEN_P_LOG, digit);
sprintf(msg_to_skype, "SET CALL %s DTMF %c", tech_pvt->skype_call_id, digit);
skypopen_signaling_write(tech_pvt, msg_to_skype);
if(digit != 'a' && digit != 'A' && digit != 'b' && digit != 'B' && digit != 'c' && digit != 'C' && digit != 'd' && digit != 'D'){
sprintf(msg_to_skype, "SET CALL %s DTMF %c", tech_pvt->skype_call_id, digit);
skypopen_signaling_write(tech_pvt, msg_to_skype);
} else {
WARNINGA("Received DTMF DIGIT \"%c\", but not relayed to Skype client because Skype client accepts only 0-9*#\n", SKYPOPEN_P_LOG, digit);
}
return 0;
}