[Freeswitch-branches] [commit] r3258 - freeswitch/branches/knhor/wip/mod_conference

Freeswitch SVN knhor at freeswitch.org
Thu Nov 2 12:21:34 EST 2006


Author: knhor
Date: Thu Nov  2 12:21:33 2006
New Revision: 3258

Modified:
   freeswitch/branches/knhor/wip/mod_conference/mod_conference.c

Log:
merge revisions 3161-3256 from trunk

Modified: freeswitch/branches/knhor/wip/mod_conference/mod_conference.c
==============================================================================
--- freeswitch/branches/knhor/wip/mod_conference/mod_conference.c	(original)
+++ freeswitch/branches/knhor/wip/mod_conference/mod_conference.c	Thu Nov  2 12:21:33 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";
@@ -243,7 +243,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);
 
@@ -280,28 +279,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)
 {
@@ -894,7 +871,7 @@
 
 	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);
@@ -917,7 +894,7 @@
 
 	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);
@@ -929,7 +906,7 @@
 
 	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);
@@ -952,7 +929,7 @@
 
 	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);
@@ -1011,16 +988,22 @@
 		switch_event_t *event;
 
 		if (switch_core_session_dequeue_event(member->session, &event) == SWITCH_STATUS_SUCCESS) {
-			char *p;
 			char *from = switch_event_get_header(event, "from");
 			char *to = switch_event_get_header(event, "to");
 			char *proto = switch_event_get_header(event, "proto");
 			char *subject = switch_event_get_header(event, "subject");
+			char *hint = switch_event_get_header(event, "hint");
 			char *body = switch_event_get_body(event);
-			if ((p = strchr(to, '+'))) {
-				to = ++p;
+			char *p, *freeme = NULL;
+
+			if ((p = strchr(to, '+')) && 
+				strncmp(to, CONF_CHAT_PROTO, strlen(CONF_CHAT_PROTO))) {
+				freeme = switch_mprintf("%s+%s@%s", CONF_CHAT_PROTO, member->conference->name, member->conference->domain);
+				to = freeme;
 			}
-			chat_send(proto, from, to, subject, body, "");
+
+			chat_send(proto, from, to, subject, body, hint);
+			switch_safe_free(freeme);
 			switch_event_destroy(&event);
 		}
 
@@ -1882,7 +1865,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);
 		}
 
@@ -1919,7 +1902,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);
 		}
 
@@ -2543,6 +2526,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,
@@ -2554,8 +2548,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;
@@ -2565,6 +2558,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);
 	}
@@ -2594,6 +2596,7 @@
 	}
 
 done:
+	switch_thread_rwlock_unlock(conference->rwlock);
 	return status;
 }
 
@@ -3172,6 +3175,10 @@
 	conference_obj_t *conference = NULL;
 	switch_stream_handle_t stream = {0};
 
+	if ((p = strchr(to, '+'))) {
+		to = ++p;
+	}
+
 	if (!body) {
 		return SWITCH_STATUS_SUCCESS;
 	}
@@ -3180,6 +3187,7 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invaid Chat Interface [%s]!\n", proto);
 	}
 
+
 	if ((p = strchr(to, '@'))) {
 		switch_copy_string(name, to, ++p-to);
 	} else {
@@ -3187,7 +3195,7 @@
 	}
 
 	if (!(conference = (conference_obj_t *) switch_core_hash_find(globals.conference_hash, name))) {
-		ci->chat_send(CONF_CHAT_PROTO, to, from, "", "Sorry, We're Closed", "");
+		ci->chat_send(CONF_CHAT_PROTO, to, hint && strchr(hint, '/') ? hint : from, "", "Sorry, We're Closed", NULL);
 		return SWITCH_STATUS_FALSE;
 	}
 
@@ -3196,11 +3204,12 @@
 	if (strstr(body, "list")) {
 		conference_list_pretty(conference, &stream);
 	} else {
-		stream.write_function(&stream, "The only command we have is so far is 'list' Get coding or go press PayPal!!\n");
+		stream.write_function(&stream, "The only command we have so far is 'list'.\nGet coding or go press PayPal!!\n");
 	}
 
-	ci->chat_send(CONF_CHAT_PROTO, to, from, "", stream.data, "");
+	ci->chat_send(CONF_CHAT_PROTO, to, from, "", stream.data, NULL);
 	switch_safe_free(stream.data);
+
 
 
 	return SWITCH_STATUS_SUCCESS;



More information about the Freeswitch-branches mailing list