Revision
16851
Author
gmaruzz
Date
2010-03-01 07:25:04 -0600 (Mon, 01 Mar 2010)

Log Message

skypiax: Synching audio

Modified Paths

Diff

Modified: freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c (16850 => 16851)


--- freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c	2010-03-01 11:06:47 UTC (rev 16850)
+++ freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c	2010-03-01 13:25:04 UTC (rev 16851)
@@ -847,22 +847,63 @@
 	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:

Modified: freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax_protocol.c (16850 => 16851)


--- freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax_protocol.c	2010-03-01 11:06:47 UTC (rev 16850)
+++ freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax_protocol.c	2010-03-01 13:25:04 UTC (rev 16851)
@@ -501,11 +501,22 @@
 				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"))) {