From 265c79a5bf5e350fec99ca5e02f76f3cce0fc04d Mon Sep 17 00:00:00 2001 From: Giovanni Maruzzelli Date: Mon, 1 Mar 2010 13:25:04 +0000 Subject: [PATCH] skypiax: Synching audio git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16851 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/mod/endpoints/mod_skypiax/mod_skypiax.c | 55 ++++++++++++++++--- .../endpoints/mod_skypiax/skypiax_protocol.c | 19 +++++-- 2 files changed, 63 insertions(+), 11 deletions(-) diff --git a/src/mod/endpoints/mod_skypiax/mod_skypiax.c b/src/mod/endpoints/mod_skypiax/mod_skypiax.c index 61b6f413c2..05a1adbc17 100644 --- a/src/mod/endpoints/mod_skypiax/mod_skypiax.c +++ b/src/mod/endpoints/mod_skypiax/mod_skypiax.c @@ -847,22 +847,63 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s switch (msg->message_id) { 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); - switch_core_timer_sync(&tech_pvt->timer_write); + DEBUGA_SKYPE("%s CHANNEL got SWITCH_MESSAGE_INDICATE_ANSWER\n", SKYPIAX_P_LOG, switch_channel_get_name(channel)); + channel_answer_channel(session); + + if(tech_pvt->read_buffer){ + switch_mutex_lock(tech_pvt->mutex_audio_srv); + switch_buffer_zero(tech_pvt->read_buffer); + switch_core_timer_sync(&tech_pvt->timer_read); + switch_mutex_unlock(tech_pvt->mutex_audio_srv); + } + + if(tech_pvt->write_buffer){ + switch_mutex_lock(tech_pvt->mutex_audio_cli); + switch_buffer_zero(tech_pvt->write_buffer); + switch_core_timer_sync(&tech_pvt->timer_write); + switch_mutex_unlock(tech_pvt->mutex_audio_cli); + } + DEBUGA_SKYPE("Synching audio\n", SKYPIAX_P_LOG); + } break; case SWITCH_MESSAGE_INDICATE_AUDIO_SYNC: DEBUGA_SKYPE("%s CHANNEL got SWITCH_MESSAGE_INDICATE_AUDIO_SYNC\n", SKYPIAX_P_LOG, switch_channel_get_name(channel)); - switch_core_timer_sync(&tech_pvt->timer_read); - switch_core_timer_sync(&tech_pvt->timer_write); + + if(tech_pvt->read_buffer){ + switch_mutex_lock(tech_pvt->mutex_audio_srv); + switch_buffer_zero(tech_pvt->read_buffer); + switch_core_timer_sync(&tech_pvt->timer_read); + switch_mutex_unlock(tech_pvt->mutex_audio_srv); + } + + if(tech_pvt->write_buffer){ + switch_mutex_lock(tech_pvt->mutex_audio_cli); + switch_buffer_zero(tech_pvt->write_buffer); + switch_core_timer_sync(&tech_pvt->timer_write); + switch_mutex_unlock(tech_pvt->mutex_audio_cli); + } + DEBUGA_SKYPE("Synching audio\n", SKYPIAX_P_LOG); break; case SWITCH_MESSAGE_INDICATE_BRIDGE: DEBUGA_SKYPE("%s CHANNEL got SWITCH_MESSAGE_INDICATE_BRIDGE\n", SKYPIAX_P_LOG, switch_channel_get_name(channel)); - switch_core_timer_sync(&tech_pvt->timer_read); - switch_core_timer_sync(&tech_pvt->timer_write); + + if(tech_pvt->read_buffer){ + switch_mutex_lock(tech_pvt->mutex_audio_srv); + switch_buffer_zero(tech_pvt->read_buffer); + switch_core_timer_sync(&tech_pvt->timer_read); + switch_mutex_unlock(tech_pvt->mutex_audio_srv); + } + + if(tech_pvt->write_buffer){ + switch_mutex_lock(tech_pvt->mutex_audio_cli); + switch_buffer_zero(tech_pvt->write_buffer); + switch_core_timer_sync(&tech_pvt->timer_write); + switch_mutex_unlock(tech_pvt->mutex_audio_cli); + } + DEBUGA_SKYPE("Synching audio\n", SKYPIAX_P_LOG); break; default: diff --git a/src/mod/endpoints/mod_skypiax/skypiax_protocol.c b/src/mod/endpoints/mod_skypiax/skypiax_protocol.c index 57d4fa3e60..893ec2cefa 100644 --- a/src/mod/endpoints/mod_skypiax/skypiax_protocol.c +++ b/src/mod/endpoints/mod_skypiax/skypiax_protocol.c @@ -501,11 +501,22 @@ int skypiax_signaling_read(private_t * tech_pvt) if (!strcasecmp(prop, "FAILUREREASON")) { DEBUGA_SKYPE("Skype FAILED on skype_call %s. Let's wait for the FAILED message.\n", SKYPIAX_P_LOG, id); } - if (!strcasecmp(prop, "DURATION")) { /* each 20 seconds, we sync ithe timers */ + if (!strcasecmp(prop, "DURATION")) { /* each 20 seconds, we zero the buffers and sync the timers */ if (!((atoi(value) % 20))) { - switch_core_timer_sync(&tech_pvt->timer_read); - switch_core_timer_sync(&tech_pvt->timer_write); - DEBUGA_SKYPE("Synching on skype_call: %s.\n", SKYPIAX_P_LOG, id); + if(tech_pvt->read_buffer){ + switch_mutex_lock(tech_pvt->mutex_audio_srv); + switch_buffer_zero(tech_pvt->read_buffer); + switch_core_timer_sync(&tech_pvt->timer_read); + switch_mutex_unlock(tech_pvt->mutex_audio_srv); + } + + if(tech_pvt->write_buffer){ + switch_mutex_lock(tech_pvt->mutex_audio_cli); + switch_buffer_zero(tech_pvt->write_buffer); + switch_core_timer_sync(&tech_pvt->timer_write); + switch_mutex_unlock(tech_pvt->mutex_audio_cli); + } + DEBUGA_SKYPE("Synching audio on skype_call: %s.\n", SKYPIAX_P_LOG, id); } } if (!strcasecmp(prop, "DURATION") && (!strcasecmp(value, "1"))) {