From 9350fb96265961fd87c1bcecdb4e0123cf77234f Mon Sep 17 00:00:00 2001 From: Giovanni Maruzzelli Date: Tue, 7 Dec 2010 00:19:49 -0600 Subject: [PATCH] skypopen: added a second timer on read from Skype client (timer_read_srv), so not to depend anymore from select on that socket --- src/mod/endpoints/mod_skypopen/mod_skypopen.c | 20 +++++++++++++++++++ src/mod/endpoints/mod_skypopen/skypopen.h | 5 +++-- .../mod_skypopen/skypopen_protocol.c | 10 ++++++++-- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/mod/endpoints/mod_skypopen/mod_skypopen.c b/src/mod/endpoints/mod_skypopen/mod_skypopen.c index 1263e5f81a..65c1b120fd 100644 --- a/src/mod/endpoints/mod_skypopen/mod_skypopen.c +++ b/src/mod/endpoints/mod_skypopen/mod_skypopen.c @@ -526,6 +526,10 @@ static switch_status_t channel_on_destroy(switch_core_session_t *session) switch_core_timer_destroy(&tech_pvt->timer_read); } + if (tech_pvt->timer_read_srv.timer_interface && tech_pvt->timer_read_srv.timer_interface->timer_next) { + switch_core_timer_destroy(&tech_pvt->timer_read_srv); + } + if (tech_pvt->timer_write.timer_interface && tech_pvt->timer_write.timer_interface->timer_next) { switch_core_timer_destroy(&tech_pvt->timer_write); } @@ -1121,6 +1125,9 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s if (tech_pvt->timer_read.timer_interface && tech_pvt->timer_read.timer_interface->timer_next) { switch_core_timer_sync(&tech_pvt->timer_read); } + if (tech_pvt->timer_read_srv.timer_interface && tech_pvt->timer_read_srv.timer_interface->timer_next) { + switch_core_timer_sync(&tech_pvt->timer_read_srv); + } switch_mutex_unlock(tech_pvt->mutex_audio_srv); } @@ -1146,6 +1153,9 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s if (tech_pvt->timer_read.timer_interface && tech_pvt->timer_read.timer_interface->timer_next) { switch_core_timer_sync(&tech_pvt->timer_read); } + if (tech_pvt->timer_read_srv.timer_interface && tech_pvt->timer_read_srv.timer_interface->timer_next) { + switch_core_timer_sync(&tech_pvt->timer_read_srv); + } switch_mutex_unlock(tech_pvt->mutex_audio_srv); } @@ -1168,6 +1178,9 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s if (tech_pvt->timer_read.timer_interface && tech_pvt->timer_read.timer_interface->timer_next) { switch_core_timer_sync(&tech_pvt->timer_read); } + if (tech_pvt->timer_read_srv.timer_interface && tech_pvt->timer_read_srv.timer_interface->timer_next) { + switch_core_timer_sync(&tech_pvt->timer_read_srv); + } switch_mutex_unlock(tech_pvt->mutex_audio_srv); } @@ -2168,6 +2181,13 @@ int start_audio_threads(private_t *tech_pvt) switch_core_timer_sync(&tech_pvt->timer_read); + if (switch_core_timer_init(&tech_pvt->timer_read_srv, "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_srv); + 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; diff --git a/src/mod/endpoints/mod_skypopen/skypopen.h b/src/mod/endpoints/mod_skypopen/skypopen.h index 4ff2b012c6..2f1c8e48e9 100644 --- a/src/mod/endpoints/mod_skypopen/skypopen.h +++ b/src/mod/endpoints/mod_skypopen/skypopen.h @@ -76,8 +76,8 @@ #define SAMPLERATE_SKYPOPEN 16000 #define MS_SKYPOPEN 20 -#define SAMPLES_PER_FRAME SAMPLERATE_SKYPOPEN/(1000/MS_SKYPOPEN) -#define BYTES_PER_FRAME SAMPLES_PER_FRAME * sizeof(short) +#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 @@ -341,6 +341,7 @@ struct private_object { chat_t chats[MAX_CHATS]; uint32_t report_incoming_chatmessages; switch_timer_t timer_read; + switch_timer_t timer_read_srv; switch_timer_t timer_write; int begin_to_write; int begin_to_read; diff --git a/src/mod/endpoints/mod_skypopen/skypopen_protocol.c b/src/mod/endpoints/mod_skypopen/skypopen_protocol.c index ef06bfac1e..391a23caaf 100644 --- a/src/mod/endpoints/mod_skypopen/skypopen_protocol.c +++ b/src/mod/endpoints/mod_skypopen/skypopen_protocol.c @@ -547,6 +547,9 @@ int skypopen_signaling_read(private_t *tech_pvt) if (tech_pvt->timer_read.timer_interface && tech_pvt->timer_read.timer_interface->timer_next) { switch_core_timer_sync(&tech_pvt->timer_read); } + if (tech_pvt->timer_read_srv.timer_interface && tech_pvt->timer_read_srv.timer_interface->timer_next) { + switch_core_timer_sync(&tech_pvt->timer_read_srv); + } switch_mutex_unlock(tech_pvt->mutex_audio_srv); } @@ -878,7 +881,7 @@ void *skypopen_do_tcp_srv_thread_func(void *obj) || tech_pvt->skype_callflow == CALLFLOW_STATUS_REMOTEHOLD || tech_pvt->skype_callflow == SKYPOPEN_STATE_UP)) { unsigned int fdselect; - int rt; + int rt=1; fd_set fs; struct timeval to; int nospace; @@ -891,7 +894,10 @@ void *skypopen_do_tcp_srv_thread_func(void *obj) to.tv_usec = MS_SKYPOPEN * 1000 * 3; to.tv_sec = 0; - rt = select(fdselect + 1, &fs, NULL, NULL, &to); + if (tech_pvt->timer_read_srv.timer_interface && tech_pvt->timer_read_srv.timer_interface->timer_next) { + switch_core_timer_next(&tech_pvt->timer_read_srv); + } + //rt = select(fdselect + 1, &fs, NULL, NULL, &to); if (rt > 0) { if (tech_pvt->skype_callflow != CALLFLOW_STATUS_REMOTEHOLD) { -- 2.47.2