[Freeswitch-svn] [commit] r10346 - in freeswitch/trunk/src: . include

FreeSWITCH SVN anthm at freeswitch.org
Wed Nov 12 03:44:13 PST 2008


Author: anthm
Date: Wed Nov 12 06:44:13 2008
New Revision: 10346

Log:
possible fix for FSCORE-221

Modified:
   freeswitch/trunk/src/include/switch_core.h
   freeswitch/trunk/src/switch_core_media_bug.c
   freeswitch/trunk/src/switch_core_session.c
   freeswitch/trunk/src/switch_ivr_async.c

Modified: freeswitch/trunk/src/include/switch_core.h
==============================================================================
--- freeswitch/trunk/src/include/switch_core.h	(original)
+++ freeswitch/trunk/src/include/switch_core.h	Wed Nov 12 06:44:13 2008
@@ -212,6 +212,9 @@
 */
 SWITCH_DECLARE(switch_status_t) switch_core_media_bug_read(_In_ switch_media_bug_t *bug, _In_ switch_frame_t *frame);
 
+SWITCH_DECLARE(void) switch_core_media_bug_flush(_In_ switch_media_bug_t *bug);
+SWITCH_DECLARE(switch_status_t) switch_core_media_bug_flush_all(_In_ switch_core_session_t *session);
+
 ///\}
 
 ///\defgroup pa1 Port Allocation

Modified: freeswitch/trunk/src/switch_core_media_bug.c
==============================================================================
--- freeswitch/trunk/src/switch_core_media_bug.c	(original)
+++ freeswitch/trunk/src/switch_core_media_bug.c	Wed Nov 12 06:44:13 2008
@@ -76,6 +76,12 @@
 	return bug->user_data;
 }
 
+SWITCH_DECLARE(void) switch_core_media_bug_flush(switch_media_bug_t *bug)
+{
+	switch_buffer_zero(bug->raw_read_buffer);
+	switch_buffer_zero(bug->raw_write_buffer);
+}
+
 SWITCH_DECLARE(switch_status_t) switch_core_media_bug_read(switch_media_bug_t *bug, switch_frame_t *frame)
 {
 	uint32_t bytes = 0;
@@ -265,9 +271,27 @@
 }
 
 
+SWITCH_DECLARE(switch_status_t) switch_core_media_bug_flush_all(switch_core_session_t *session)
+{
+	switch_media_bug_t *bp;
+
+	if (session->bugs) {
+		switch_thread_rwlock_wrlock(session->bug_rwlock);
+		for (bp = session->bugs; bp; bp = bp->next) {
+			switch_core_media_bug_flush(bp);
+		}
+		switch_thread_rwlock_unlock(session->bug_rwlock);
+		return SWITCH_STATUS_SUCCESS;
+	}
+
+	return SWITCH_STATUS_FALSE;
+}
+
+
 SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove_all(switch_core_session_t *session)
 {
 	switch_media_bug_t *bp;
+	switch_status_t status = SWITCH_STATUS_FALSE;
 
 	if (session->bugs) {
 		switch_thread_rwlock_wrlock(session->bug_rwlock);
@@ -285,7 +309,7 @@
 		}
 		session->bugs = NULL;
 		switch_thread_rwlock_unlock(session->bug_rwlock);
-		return SWITCH_STATUS_SUCCESS;
+		status = SWITCH_STATUS_SUCCESS;
 	}
 
 	if (session->bug_codec.implementation) {
@@ -293,7 +317,7 @@
 		memset(&session->bug_codec, 0, sizeof(session->bug_codec));
 	}
 
-	return SWITCH_STATUS_FALSE;
+	return status;
 }
 
 SWITCH_DECLARE(switch_status_t) switch_core_media_bug_close(switch_media_bug_t **bug)

Modified: freeswitch/trunk/src/switch_core_session.c
==============================================================================
--- freeswitch/trunk/src/switch_core_session.c	(original)
+++ freeswitch/trunk/src/switch_core_session.c	Wed Nov 12 06:44:13 2008
@@ -742,6 +742,7 @@
 	switch_clear_flag(session, SSF_WARN_TRANSCODE);
 	switch_ivr_deactivate_unicast(session);
 	switch_channel_clear_flag(channel, CF_BREAK);
+	switch_core_media_bug_flush_all(session);
 }
 
 

Modified: freeswitch/trunk/src/switch_ivr_async.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr_async.c	(original)
+++ freeswitch/trunk/src/switch_ivr_async.c	Wed Nov 12 06:44:13 2008
@@ -913,22 +913,18 @@
 static switch_bool_t inband_dtmf_callback(switch_media_bug_t *bug, void *user_data, switch_abc_type_t type)
 {
 	switch_inband_dtmf_t *pvt = (switch_inband_dtmf_t *) user_data;
-	uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE];
-	switch_frame_t frame = { 0 };
+	switch_frame_t *frame = NULL;
 	char digit_str[80];
 	switch_channel_t *channel = switch_core_session_get_channel(pvt->session);
 
-	frame.data = data;
-	frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE;
-
 	switch (type) {
 	case SWITCH_ABC_TYPE_INIT:
 		break;
 	case SWITCH_ABC_TYPE_CLOSE:
 		break;
-	case SWITCH_ABC_TYPE_READ:
-		if (switch_core_media_bug_read(bug, &frame) == SWITCH_STATUS_SUCCESS) {
-			teletone_dtmf_detect(&pvt->dtmf_detect, frame.data, frame.samples);
+	case SWITCH_ABC_TYPE_READ_REPLACE:
+		if ((frame = switch_core_media_bug_get_read_replace_frame(bug))) {
+			teletone_dtmf_detect(&pvt->dtmf_detect, frame->data, frame->samples);
 			teletone_dtmf_get(&pvt->dtmf_detect, digit_str, sizeof(digit_str));
 			if (digit_str[0]) {
 				char *p = digit_str;
@@ -941,6 +937,7 @@
 				}
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "DTMF DETECTED: [%s]\n", digit_str);
 			}
+			switch_core_media_bug_set_read_replace_frame(bug, frame);
 		}
 		break;
 	case SWITCH_ABC_TYPE_WRITE:
@@ -984,7 +981,7 @@
 
 	switch_channel_pre_answer(channel);
 
-	if ((status = switch_core_media_bug_add(session, inband_dtmf_callback, pvt, 0, SMBF_READ_STREAM, &bug)) != SWITCH_STATUS_SUCCESS) {
+	if ((status = switch_core_media_bug_add(session, inband_dtmf_callback, pvt, 0, SMBF_READ_REPLACE, &bug)) != SWITCH_STATUS_SUCCESS) {
 		return status;
 	}
 



More information about the Freeswitch-svn mailing list