[Freeswitch-svn] [commit] r3189 - in freeswitch/trunk/src: . include mod/applications/mod_conference

Freeswitch SVN anthm at freeswitch.org
Tue Oct 24 21:00:26 EDT 2006


Author: anthm
Date: Tue Oct 24 21:00:26 2006
New Revision: 3189

Modified:
   freeswitch/trunk/src/include/switch_resample.h
   freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c
   freeswitch/trunk/src/switch_ivr.c
   freeswitch/trunk/src/switch_resample.c

Log:
add some sanity code to originate and conference

Modified: freeswitch/trunk/src/include/switch_resample.h
==============================================================================
--- freeswitch/trunk/src/include/switch_resample.h	(original)
+++ freeswitch/trunk/src/include/switch_resample.h	Tue Oct 24 21:00:26 2006
@@ -38,6 +38,7 @@
 	way comes along some day. =D
 	
 */
+#define switch_normalize_volume(x) if(x > 4) x = 4; if (x < -4) x = -4;
 
 #ifndef SWITCH_RESAMPLE_H
 #define SWITCH_RESAMPLE_H
@@ -154,6 +155,13 @@
  */
 SWITCH_DECLARE(void) switch_swap_linear(int16_t *buf, int len);
 
+/*!
+  \brief Change the volume of a signed linear audio frame
+  \param data the audio data
+  \param samples the number of 2 byte samples
+  \param vol the volume factor -4 -> 4
+ */
+SWITCH_DECLARE(void) switch_change_sln_volume(int16_t *data, uint32_t samples, int32_t vol);
 ///\}
 
 SWITCH_END_EXTERN_C

Modified: freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c	Tue Oct 24 21:00:26 2006
@@ -31,7 +31,7 @@
  *
  */
 #include <switch.h>
-#define normalize_volume(x) if(x > 4) x = 4; if (x < -4) x = -4;
+
 static const char modname[] = "mod_conference";
 static const char global_app_name[] = "conference";
 static char *global_cf_name = "conference.conf";
@@ -229,7 +229,6 @@
 static switch_status_t conference_member_say(conference_obj_t *conference, conference_member_t *member, char *text, uint32_t leadin);
 static uint32_t conference_member_stop_file(conference_member_t *member, file_stop_t stop);
 static conference_obj_t *conference_new(char *name, switch_xml_t profile, switch_memory_pool_t *pool);
-static void switch_change_sln_volume(int16_t *data, uint32_t samples, int32_t vol);
 static switch_status_t chat_send(char *proto, char *from, char *to, char *subject, char *body, char *hint);
 static void launch_conference_record_thread(conference_obj_t *conference, char *path);
 
@@ -250,28 +249,6 @@
 	return id;
 }
 
-static void switch_change_sln_volume(int16_t *data, uint32_t samples, int32_t vol)
-{
-	int16_t *p = data;
-	uint32_t x = 0;
-	int32_t v = vol * 10;
-	double mult = (((double)abs(v)) / 100) * 2;
-	int32_t b;
-
-	if (v > 0) {
-		mult += (.2 * abs(v));
-		mult = 4;
-	} else {
-		mult -= 1;
-	}
-
-	for (x = 0; x < samples; x++) {
-		b = (int32_t)((double)p[x] * mult);
-		switch_normalize_to_16bit(b);
-		p[x] = (int16_t) b;
-	}
-}
-
 /* if other_member has a relationship with member, produce it */
 static conference_relationship_t *member_get_relationship(conference_member_t *member, conference_member_t *other_member)
 {
@@ -920,7 +897,7 @@
 				case '3':
 					switch_mutex_lock(member->flag_mutex);
 					member->volume_out_level++;
-					normalize_volume(member->volume_out_level);
+					switch_normalize_volume(member->volume_out_level);
 					switch_mutex_unlock(member->flag_mutex);
 					snprintf(msg, sizeof(msg), "Volume level %d", member->volume_out_level);
 					conference_member_say(member->conference, member, msg, 0);
@@ -935,7 +912,7 @@
 				case '1':
 					switch_mutex_lock(member->flag_mutex);
 					member->volume_out_level--;
-					normalize_volume(member->volume_out_level);
+					switch_normalize_volume(member->volume_out_level);
 					switch_mutex_unlock(member->flag_mutex);
 					snprintf(msg, sizeof(msg), "Volume level %d", member->volume_out_level);
 					conference_member_say(member->conference, member, msg, 0);
@@ -943,7 +920,7 @@
 				case '6':
 					switch_mutex_lock(member->flag_mutex);
 					member->volume_in_level++;
-					normalize_volume(member->volume_in_level);
+					switch_normalize_volume(member->volume_in_level);
 					switch_mutex_unlock(member->flag_mutex);
 					snprintf(msg, sizeof(msg), "Gain level %d", member->volume_in_level);
 					conference_member_say(member->conference, member, msg, 0);
@@ -958,7 +935,7 @@
 				case '4':
 					switch_mutex_lock(member->flag_mutex);
 					member->volume_in_level--;
-					normalize_volume(member->volume_in_level);
+					switch_normalize_volume(member->volume_in_level);
 					switch_mutex_unlock(member->flag_mutex);
 					snprintf(msg, sizeof(msg), "Gain level %d", member->volume_in_level);
 					conference_member_say(member->conference, member, msg, 0);
@@ -1756,7 +1733,7 @@
 		if (data) {
 			switch_mutex_lock(member->flag_mutex);
 			member->volume_in_level = atoi((char *)data);
-			normalize_volume(member->volume_in_level);
+			switch_normalize_volume(member->volume_in_level);
 			switch_mutex_unlock(member->flag_mutex);
 		}
 
@@ -1792,7 +1769,7 @@
 		if (data) {
 			switch_mutex_lock(member->flag_mutex);
 			member->volume_out_level = atoi((char *)data);
-			normalize_volume(member->volume_out_level);
+			switch_normalize_volume(member->volume_out_level);
 			switch_mutex_unlock(member->flag_mutex);
 		}
 
@@ -2458,6 +2435,17 @@
 	char appdata[512];
 	switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING;
 
+
+	if (switch_thread_rwlock_tryrdlock(conference->rwlock) != SWITCH_STATUS_SUCCESS) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Read Lock Fail\n");
+		return SWITCH_STATUS_FALSE;
+	}
+
+	if (session) {
+		caller_channel = switch_core_session_get_channel(session);
+	
+	}
+
 	if (switch_ivr_originate(session,
 							 &peer_session,
 							 &cause,
@@ -2469,8 +2457,7 @@
 							 NULL) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot create outgoing channel, cause: %s\n",
 				  switch_channel_cause2str(cause));
-		if (session) {
-			caller_channel = switch_core_session_get_channel(session);
+		if (caller_channel) {
 			switch_channel_hangup(caller_channel, cause);
 		}
 		goto done;
@@ -2480,6 +2467,15 @@
 	peer_channel = switch_core_session_get_channel(peer_session);
 	assert(peer_channel != NULL);
 
+	if (!switch_test_flag(conference, CFLAG_RUNNING)) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Conference is gone now, nevermind..\n");
+		if (caller_channel) {
+			switch_channel_hangup(caller_channel, SWITCH_CAUSE_NO_ROUTE_DESTINATION);
+		}
+		switch_channel_hangup(peer_channel, SWITCH_CAUSE_NO_ROUTE_DESTINATION);
+		goto done;
+	}
+
 	if (caller_channel && switch_channel_test_flag(peer_channel, CF_ANSWERED)) {
 		switch_channel_answer(caller_channel);
 	}
@@ -2509,6 +2505,7 @@
 	}
 
 done:
+	switch_thread_rwlock_unlock(conference->rwlock);
 	return status;
 }
 

Modified: freeswitch/trunk/src/switch_ivr.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr.c	(original)
+++ freeswitch/trunk/src/switch_ivr.c	Tue Oct 24 21:00:26 2006
@@ -1999,6 +1999,10 @@
 		
 		}
 
+		if (!switch_channel_ready(caller_channel)) {
+			idx = -2;
+		}
+
 		if (session && !switch_channel_test_flag(caller_channel, CF_NOMEDIA)) {
 			switch_core_session_reset(session);
 		}
@@ -2062,10 +2066,21 @@
 					break;
 				}
 			}
+
 			if (caller_channel) {
+				if (idx == -2) {
+					*cause = switch_channel_get_cause(caller_channel);
+				} 
 				switch_channel_set_variable(caller_channel, "originate_disposition", switch_channel_cause2str(*cause));
+				
 			}
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Originate Resulted in Error Cause: %d [%s]\n", *cause, switch_channel_cause2str(*cause));
+			if (idx == -2) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Originate Cancelled by originator termination Cause: %d [%s]\n",
+								  *cause, switch_channel_cause2str(*cause));
+			} else {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Originate Resulted in Error Cause: %d [%s]\n",
+								  *cause, switch_channel_cause2str(*cause));
+			}
 		}
 
 		if (!pass && write_codec.implementation) {

Modified: freeswitch/trunk/src/switch_resample.c
==============================================================================
--- freeswitch/trunk/src/switch_resample.c	(original)
+++ freeswitch/trunk/src/switch_resample.c	Tue Oct 24 21:00:26 2006
@@ -182,3 +182,37 @@
 		buf[i] = ((buf[i] >> 8) & 0x00ff) | ((buf[i] << 8) & 0xff00);
 	}
 }
+
+SWITCH_DECLARE(void) switch_change_sln_volume(int16_t *data, uint32_t samples, int32_t vol)
+{
+    double newrate = 0;
+    int div = 0;
+
+	switch_normalize_volume(vol);
+
+	if (vol > 0) {
+		vol++;
+	} else if (vol < 0) {
+		vol--;
+	}
+
+	newrate = vol * 1.3;
+
+	if (vol < 0) {
+		newrate *= -1;
+		div++;
+	}
+
+	if (newrate) {
+		int32_t tmp;
+		int x;
+		int16_t *fp = data;
+
+		for (x = 0; x < samples; x++) {
+			tmp = (double) div ? fp[x] / newrate : fp[x] * newrate;
+			switch_normalize_to_16bit(tmp);
+			fp[x] = tmp;
+		}
+	}
+}
+



More information about the Freeswitch-svn mailing list