Revision
14684
Author
gmaruzz
Date
2009-08-30 18:46:25 -0500 (Sun, 30 Aug 2009)

Log Message

celliax: use two audio timers, one for read and one for write

Modified Paths

Diff

Modified: freeswitch/branches/gmaruzz/mod_celliax/celliax.h (14683 => 14684)


--- freeswitch/branches/gmaruzz/mod_celliax/celliax.h	2009-08-30 19:44:25 UTC (rev 14683)
+++ freeswitch/branches/gmaruzz/mod_celliax/celliax.h	2009-08-30 23:46:25 UTC (rev 14684)
@@ -432,7 +432,8 @@
 	time_t audio_play_reset_timestamp;
 	int audio_play_reset_period;
 
-	switch_timer_t timer;
+	switch_timer_t timer_read;
+	switch_timer_t timer_write;
 	teletone_dtmf_detect_state_t dtmf_detect;
 	switch_time_t old_dtmf_timestamp;
 

Modified: freeswitch/branches/gmaruzz/mod_celliax/celliax_protocol.c (14683 => 14684)


--- freeswitch/branches/gmaruzz/mod_celliax/celliax_protocol.c	2009-08-30 19:44:25 UTC (rev 14683)
+++ freeswitch/branches/gmaruzz/mod_celliax/celliax_protocol.c	2009-08-30 23:46:25 UTC (rev 14684)
@@ -4686,17 +4686,20 @@
 
 	left = datalen;
 
+#if 0
 	struct timeval to;
 	fd_set rfds;
 	int result;
 
 
+
 	FD_ZERO(&rfds);
 	FD_SET(tech_pvt->celliax_sound_capt_fd, &rfds);
 
 	/* Wait for something to happen */
 	to.tv_sec = 0;
-	to.tv_usec = 500000;		/* we select with this timeout because under cygwin we avoid the signal usage, so there is no way to end the thread if it is stuck waiting for select */
+	//to.tv_usec = 500000;		/* we select with this timeout because under cygwin we avoid the signal usage, so there is no way to end the thread if it is stuck waiting for select */
+	to.tv_usec = 20000;		/* we select with this timeout because under cygwin we avoid the signal usage, so there is no way to end the thread if it is stuck waiting for select */
 	result = select(tech_pvt->celliax_sound_capt_fd + 1, &rfds, NULL, NULL, &to);
 
 
@@ -4717,10 +4720,11 @@
 	/* If there are no file descriptors changed, just continue  */
 
 	if (result == 0) {
-		usleep(10000);			//let's breath
-		ERRORA("select returned %d: %s\n", SKYPIAX_P_LOG, result, strerror(errno));
+		DEBUGA_SKYPE("select returned %d: no file descriptor ready to be read, read would return -EAGAIN\n", SKYPIAX_P_LOG, result);
+		usleep(500);			//let's breath
 	}
 
+#endif
 
 
 
@@ -4738,7 +4742,6 @@
 
 
 
-
 	state = snd_pcm_state(tech_pvt->alsac);
 	if (state != SND_PCM_STATE_RUNNING) {
 		DEBUGA_SKYPE("ALSA read state is not SND_PCM_STATE_RUNNING\n", SKYPIAX_P_LOG);
@@ -4765,8 +4768,8 @@
 	buf2 = __buf2 + ((AST_FRIENDLY_OFFSET / 2) * 2);
 
 	if (tech_pvt->alsa_capture_is_mono) {
-		//DEBUGA_SKYPE("buf=%p, buf+readpos=%p, datalen=%d, left=%d\n", SKYPIAX_P_LOG, (void *)buf, (void *)(buf + readpos), datalen, left);
 		r = snd_pcm_readi(tech_pvt->alsac, buf + readpos, left);
+		//DEBUGA_SKYPE("r=%d, buf=%p, buf+readpos=%p, datalen=%d, left=%d\n", SKYPIAX_P_LOG, r, (void *)buf, (void *)(buf + readpos), datalen, left);
 	} else {
 		r = snd_pcm_readi(tech_pvt->alsac, buf2 + (readpos * 2), left);
 

Modified: freeswitch/branches/gmaruzz/mod_celliax/mod_celliax.c (14683 => 14684)


--- freeswitch/branches/gmaruzz/mod_celliax/mod_celliax.c	2009-08-30 19:44:25 UTC (rev 14683)
+++ freeswitch/branches/gmaruzz/mod_celliax/mod_celliax.c	2009-08-30 23:46:25 UTC (rev 14684)
@@ -256,13 +256,23 @@
 	//teletone_dtmf_detect_init(&tech_pvt->dtmf_detect, tech_pvt->read_codec.implementation->actual_samples_per_second);
 	teletone_dtmf_detect_init(&tech_pvt->dtmf_detect, 8000);
 
-	if (switch_core_timer_init(&tech_pvt->timer, "soft", 20, tech_pvt->read_codec.implementation->samples_per_packet, celliax_module_pool) !=
+	if (switch_core_timer_init(&tech_pvt->timer_read, "soft", 20, tech_pvt->read_codec.implementation->samples_per_packet, celliax_module_pool) !=
 		SWITCH_STATUS_SUCCESS) {
 		ERRORA("setup timer failed\n", SKYPIAX_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, tech_pvt->write_codec.implementation->samples_per_packet, celliax_module_pool) !=
+		SWITCH_STATUS_SUCCESS) {
+		ERRORA("setup timer failed\n", SKYPIAX_P_LOG);
+		return SWITCH_STATUS_FALSE;
+	}
+
+                switch_core_timer_sync(&tech_pvt->timer_write);
+
+
 	switch_clear_flag(tech_pvt, TFLAG_HANGUP);
 	DEBUGA_SKYPE("celliax_codec SUCCESS\n", SKYPIAX_P_LOG);
 	return SWITCH_STATUS_SUCCESS;
@@ -468,7 +478,8 @@
 			switch_core_codec_destroy(&tech_pvt->write_codec);
 		}
 
-		switch_core_timer_destroy(&tech_pvt->timer);
+		switch_core_timer_destroy(&tech_pvt->timer_read);
+		switch_core_timer_destroy(&tech_pvt->timer_write);
 
 
 		*tech_pvt->session_uuid_str = '\0';
@@ -663,6 +674,7 @@
 	}
 
 
+		switch_core_timer_next(&tech_pvt->timer_read);
 
 	int samples;
 
@@ -671,18 +683,20 @@
 		tech_pvt->read_frame.datalen = samples * 2;
 		tech_pvt->read_frame.samples = samples;
 
-		switch_core_timer_check(&tech_pvt->timer, SWITCH_TRUE);
-		tech_pvt->read_frame.timestamp = tech_pvt->timer.samplecount;
+		//switch_core_timer_check(&tech_pvt->timer, SWITCH_TRUE);
+		tech_pvt->read_frame.timestamp = tech_pvt->timer_read.samplecount;
 		*frame = &tech_pvt->read_frame;
 
 		//status = SWITCH_STATUS_SUCCESS;
 		switch_set_flag(tech_pvt, TFLAG_VOICE);
 	}
 
-	if (samples != 160)
+	if (samples != 160){
 		ERRORA("samples=%d\n", SKYPIAX_P_LOG, samples);
+			goto cng;
+}
 
-	//WARNINGA("samples=%d\n", SKYPIAX_P_LOG, samples);
+//DEBUGA_SKYPE("samples=%d tech_pvt->read_frame.timestamp=%d\n", SKYPIAX_P_LOG, samples, tech_pvt->read_frame.timestamp);
 
 //usleep(17000);
 //usleep(17000);
@@ -796,12 +810,14 @@
 	}
 #endif
 
+		switch_core_timer_next(&tech_pvt->timer_write);
 	sent = frame->datalen;
 
 	//ERRORA("PLAY \n", SKYPIAX_P_LOG);
 	//snd_pcm_writei(tech_pvt->alsap, (short *) frame->data, (int) (frame->datalen / 2));
 
 	sent = alsa_write(tech_pvt, frame->data, (int) (frame->datalen));
+//DEBUGA_SKYPE("sent=%d \n", SKYPIAX_P_LOG, sent);
 
 #ifdef NOTDEF					//FIXME
 #ifdef WIN32