Revision
14673
Author
gmaruzz
Date
2009-08-29 03:12:44 -0500 (Sat, 29 Aug 2009)

Log Message

celliax: dtmf detection

Modified Paths

Diff

Modified: freeswitch/branches/gmaruzz/mod_celliax/celliax.h (14672 => 14673)


--- freeswitch/branches/gmaruzz/mod_celliax/celliax.h	2009-08-29 03:08:08 UTC (rev 14672)
+++ freeswitch/branches/gmaruzz/mod_celliax/celliax.h	2009-08-29 08:12:44 UTC (rev 14673)
@@ -56,6 +56,8 @@
 #include <termios.h>
 #include <sys/ioctl.h>
 #include <iconv.h>
+#include <libteletone.h>
+
 #ifdef CELLIAX_ALSA
 #define ALSA_PCM_NEW_HW_PARAMS_API
 #define ALSA_PCM_NEW_SW_PARAMS_API
@@ -429,6 +431,9 @@
   time_t audio_play_reset_timestamp;
   int audio_play_reset_period;
 
+switch_timer_t timer;
+    teletone_dtmf_detect_state_t dtmf_detect;
+  switch_time_t old_dtmf_timestamp;
 
 };
 

Modified: freeswitch/branches/gmaruzz/mod_celliax/celliax_protocol.c (14672 => 14673)


--- freeswitch/branches/gmaruzz/mod_celliax/celliax_protocol.c	2009-08-29 03:08:08 UTC (rev 14672)
+++ freeswitch/branches/gmaruzz/mod_celliax/celliax_protocol.c	2009-08-29 08:12:44 UTC (rev 14673)
@@ -4784,9 +4784,9 @@
       time(&tech_pvt->audio_play_reset_timestamp);
     }
   }
-  res = 0;
-  if (res > 0)
-    res = 0;
+  //res = 0;
+  //if (res > 0)
+    //res = 0;
   return res;
 }
 

Modified: freeswitch/branches/gmaruzz/mod_celliax/mod_celliax.c (14672 => 14673)


--- freeswitch/branches/gmaruzz/mod_celliax/mod_celliax.c	2009-08-29 03:08:08 UTC (rev 14672)
+++ freeswitch/branches/gmaruzz/mod_celliax/mod_celliax.c	2009-08-29 08:12:44 UTC (rev 14673)
@@ -252,6 +252,28 @@
 		ERRORA("celliax_codec FAILED\n", SKYPIAX_P_LOG);
 		return SWITCH_STATUS_FALSE;
 	}
+
+int res;
+				  res = alsa_init(tech_pvt);
+				  if (res == -1) {
+					  ERRORA("Failed initializing sound device\n", SKYPIAX_P_LOG);
+					  /* we failed, free the PVT */
+					  //if (tmp)
+						  //free(tmp);
+					  //return NULL;
+				  }
+
+
+
+        //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) != SWITCH_STATUS_SUCCESS) {
+		ERRORA("setup timer failed\n", SKYPIAX_P_LOG);
+		return SWITCH_STATUS_FALSE;
+	}
+
+
 switch_clear_flag(tech_pvt, TFLAG_HANGUP);	
 	DEBUGA_SKYPE("celliax_codec SUCCESS\n", SKYPIAX_P_LOG);
 	return SWITCH_STATUS_SUCCESS;
@@ -456,6 +478,11 @@
 		if (switch_core_codec_ready(&tech_pvt->write_codec)) {
 			switch_core_codec_destroy(&tech_pvt->write_codec);
 		}
+
+			switch_core_timer_destroy(&tech_pvt->timer);
+
+alsa_shutdown(tech_pvt);
+
 		*tech_pvt->session_uuid_str = '\0';
 		tech_pvt->interface_state = SKYPIAX_STATE_IDLE;
 		if (tech_pvt->skype_callflow == CALLFLOW_STATUS_FINISHED) {
@@ -659,21 +686,52 @@
 			tech_pvt->read_frame.datalen = samples * 2;
 			tech_pvt->read_frame.samples = samples;
 
-			//switch_core_timer_check(&globals.timer, SWITCH_TRUE);
-			//globals.read_frame.timestamp = globals.timer.samplecount;
+			switch_core_timer_check(&tech_pvt->timer, SWITCH_TRUE);
+			tech_pvt->read_frame.timestamp = tech_pvt->timer.samplecount;
 			*frame = &tech_pvt->read_frame;
 
 			//status = SWITCH_STATUS_SUCCESS;
+			switch_set_flag(tech_pvt, TFLAG_VOICE);
 		}
-		switch_set_flag(tech_pvt, TFLAG_VOICE);
 
+if(samples != 160)
+		ERRORA("samples=%d\n", SKYPIAX_P_LOG, samples);
 
+		//WARNINGA("samples=%d\n", SKYPIAX_P_LOG, samples);
+
 //usleep(17000);
 //usleep(17000);
 
 
 
+        char digit_str[256];
 
+
+            memset(digit_str, 0, sizeof(digit_str));
+                teletone_dtmf_detect(&tech_pvt->dtmf_detect, tech_pvt->read_frame.data, tech_pvt->read_frame.samples);
+                teletone_dtmf_get(&tech_pvt->dtmf_detect, digit_str, sizeof(digit_str));
+
+                if (digit_str[0]) {
+                        NOTICA("DTMF DETECTED: [%s]\n", SKYPIAX_P_LOG, digit_str);
+                switch_time_t new_dtmf_timestamp = switch_time_now();
+                if((new_dtmf_timestamp - tech_pvt->old_dtmf_timestamp) > 350000) { //FIXME: make it configurable
+                        char *p = digit_str;
+                            switch_channel_t *channel = switch_core_session_get_channel(session);
+
+                        while(p && *p) {
+                            switch_dtmf_t dtmf;
+                            dtmf.digit = *p;
+                            dtmf.duration = SWITCH_DEFAULT_DTMF_DURATION;
+                            switch_channel_queue_dtmf(channel, &dtmf);
+                            p++;
+                        }
+                        NOTICA("DTMF DETECTED: [%s] new_dtmf_timestamp: %u, delta_t: %u\n", SKYPIAX_P_LOG, digit_str, (unsigned int)new_dtmf_timestamp, (unsigned int)(new_dtmf_timestamp - tech_pvt->old_dtmf_timestamp));
+                    tech_pvt->old_dtmf_timestamp = new_dtmf_timestamp;
+                    }
+            }
+
+
+
 #ifdef NOTDEF
 
 	if (!celliax_audio_read(tech_pvt)) {
@@ -761,7 +819,7 @@
 		//ERRORA("PLAY \n", SKYPIAX_P_LOG);
 	            //snd_pcm_writei(tech_pvt->alsap, (short *) frame->data, (int) (frame->datalen / 2));
 
- alsa_write(tech_pvt, frame->data, (int) (frame->datalen));
+ sent = alsa_write(tech_pvt, frame->data, (int) (frame->datalen));
 
 #ifdef NOTDEF //FIXME
 #ifdef WIN32
@@ -770,10 +828,11 @@
 	sent = write(tech_pvt->audioskypepipe[1], frame->data, sent);
 #endif /* WIN32 */
 #endif //NOTDEF
-	if (sent != frame->datalen && sent != -1) {
-		DEBUGA_SKYPE("CLI PIPE write %d\n", SKYPIAX_P_LOG, sent);
+	if (sent && sent != frame->datalen/2 && sent != -1) {
+		DEBUGA_SKYPE("sent %d\n", SKYPIAX_P_LOG, sent);
 	}
 
+		//NOTICA("sent=%d\n", SKYPIAX_P_LOG, sent);
 	return SWITCH_STATUS_SUCCESS;
 }
 
@@ -1462,6 +1521,7 @@
 
 				switch_sleep(100000);
 
+#ifdef NOTDEF 
 				  res = alsa_init(&globals.SKYPIAX_INTERFACES[interface_id]);
 				  if (res == -1) {
 					  ERRORA("Failed initializing sound device\n", SKYPIAX_P_LOG);
@@ -1471,7 +1531,6 @@
 					  //return NULL;
 				  }
 
-#ifdef NOTDEF 
 				switch_threadattr_create(&celliax_signaling_thread_attr, celliax_module_pool);
 				switch_threadattr_stacksize_set(celliax_signaling_thread_attr, SWITCH_THREAD_STACKSIZE);
 				switch_thread_create(&globals.SKYPIAX_INTERFACES[interface_id].celliax_signaling_thread, celliax_signaling_thread_attr, celliax_signaling_thread_func, &globals.SKYPIAX_INTERFACES[interface_id], celliax_module_pool);