]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
skypiax: Synching audio
authorGiovanni Maruzzelli <gmaruzz@gmail.com>
Mon, 1 Mar 2010 13:25:04 +0000 (13:25 +0000)
committerGiovanni Maruzzelli <gmaruzz@gmail.com>
Mon, 1 Mar 2010 13:25:04 +0000 (13:25 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16851 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/endpoints/mod_skypiax/mod_skypiax.c
src/mod/endpoints/mod_skypiax/skypiax_protocol.c

index 61b6f413c24e5a6751b5b67e26a098194b29f725..05a1adbc17c82c9d59486775f57d17b0f1b40611 100644 (file)
@@ -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:
index 57d4fa3e60dfcd11eae32cf2067df30daec36149..893ec2cefa37600fc6a26778045d504478d03458 100644 (file)
@@ -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"))) {