[Freeswitch-svn] [commit] r3253 - freeswitch/branches/knhor/wip/mod_conference

Freeswitch SVN knhor at freeswitch.org
Wed Nov 1 22:20:38 EST 2006


Author: knhor
Date: Wed Nov  1 22:20:37 2006
New Revision: 3253

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

Log:
break caller dtmf control into functions

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	Wed Nov  1 22:20:37 2006
@@ -779,6 +779,166 @@
 	return NULL;
 }
 
+static void conference_loop_fn_mute_toggle(conference_member_t *member)
+{
+	char msg[512];
+
+	if (switch_test_flag(member, MFLAG_CAN_SPEAK)) {
+		switch_clear_flag_locked(member, MFLAG_CAN_SPEAK | MFLAG_CAN_HEAR);
+		if (member->conference->muted_sound) {
+			conference_member_play_file(member, member->conference->muted_sound, 0);
+		} else {
+			snprintf(msg, sizeof(msg), "Muted");
+			conference_member_say(member->conference, member, msg, 0);
+		}
+	} else {
+		switch_set_flag_locked(member, MFLAG_CAN_SPEAK);
+		if (member->conference->unmuted_sound) {
+			conference_member_play_file(member, member->conference->unmuted_sound, 0);
+		} else {
+			snprintf(msg, sizeof(msg), "Un-Muted");
+			conference_member_say(member->conference, member, msg, 0);
+		}
+	}
+}
+
+static void conference_loop_fn_deafmute_toggle(conference_member_t *member)
+{
+	char msg[512];
+
+	if (switch_test_flag(member, MFLAG_CAN_SPEAK)) {
+		switch_clear_flag_locked(member, MFLAG_CAN_SPEAK|MFLAG_CAN_HEAR);
+		if (member->conference->muted_sound) {
+			conference_member_play_file(member, member->conference->muted_sound, 0);
+		} else {
+			snprintf(msg, sizeof(msg), "Muted");
+			conference_member_say(member->conference, member, msg, 0);
+		}
+	} else {
+		switch_set_flag_locked(member, MFLAG_CAN_SPEAK|MFLAG_CAN_HEAR);
+		if (member->conference->unmuted_sound) {
+			conference_member_play_file(member, member->conference->unmuted_sound, 0);
+		} else {
+			snprintf(msg, sizeof(msg), "UN-Muted");
+			conference_member_say(member->conference, member, msg, 0);
+		}
+	}
+}
+
+static void conference_loop_fn_energy_up(conference_member_t *member)
+{
+	char msg[512];
+
+	switch_mutex_lock(member->flag_mutex);
+	member->energy_level += 100;
+	if (member->energy_level > 1200) {
+		member->energy_level = 1200;
+	}
+	switch_mutex_unlock(member->flag_mutex);
+	snprintf(msg, sizeof(msg), "Energy level %d", member->energy_level);
+	conference_member_say(member->conference, member, msg, 0);
+}
+
+static void conference_loop_fn_energy_equ_conference(conference_member_t *member)
+{
+	char msg[512];
+
+	switch_mutex_lock(member->flag_mutex);
+	member->energy_level = member->conference->energy_level;
+	switch_mutex_unlock(member->flag_mutex);
+	snprintf(msg, sizeof(msg), "Energy level %d", member->energy_level);
+	conference_member_say(member->conference, member, msg, 0);
+}
+					
+static void conference_loop_fn_energy_dn(conference_member_t *member)
+{
+	char msg[512];
+
+	switch_mutex_lock(member->flag_mutex);
+	member->energy_level -= 100;
+	if (member->energy_level < 0) {
+		member->energy_level = 0;
+	}
+	switch_mutex_unlock(member->flag_mutex);
+	snprintf(msg, sizeof(msg), "Energy level %d", member->energy_level);
+	conference_member_say(member->conference, member, msg, 0);
+}
+
+static void conference_loop_fn_volume_talk_up(conference_member_t *member)
+{
+	char msg[512];
+
+	switch_mutex_lock(member->flag_mutex);
+	member->volume_out_level++;
+	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);
+}
+
+static void conference_loop_fn_volume_talk_zero(conference_member_t *member)
+{
+	char msg[512];
+
+	switch_mutex_lock(member->flag_mutex);
+	member->volume_out_level = 0;
+	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);
+}
+
+static void conference_loop_fn_volume_talk_dn(conference_member_t *member)
+{
+	char msg[512];
+
+	switch_mutex_lock(member->flag_mutex);
+	member->volume_out_level--;
+	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);
+}
+
+static void conference_loop_fn_volume_listen_up(conference_member_t *member)
+{
+	char msg[512];
+
+	switch_mutex_lock(member->flag_mutex);
+	member->volume_in_level++;
+	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);
+}
+
+static void conference_loop_fn_volume_listen_zero(conference_member_t *member)
+{
+	char msg[512];
+
+	switch_mutex_lock(member->flag_mutex);
+	member->volume_in_level = 0;
+	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);
+}
+
+static void conference_loop_fn_volume_listen_dn(conference_member_t *member)
+{
+	char msg[512];
+
+	switch_mutex_lock(member->flag_mutex);
+	member->volume_in_level--;
+	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);
+}
+
+static void conference_loop_fn_hangup(conference_member_t *member)
+{
+	switch_clear_flag_locked(member, MFLAG_RUNNING);
+}
+
 /* Sub-Routine called by a channel inside a conference */
 static void conference_loop(conference_member_t *member)
 {
@@ -824,7 +984,6 @@
 		switch_size_t file_data_len = samples * 2;
 		switch_size_t file_sample_len = samples;
 		char *digit;
-		char msg[512];
 		switch_event_t *event;
 
 		if (switch_core_session_dequeue_event(member->session, &event) == SWITCH_STATUS_SUCCESS) {
@@ -860,118 +1019,40 @@
 			for (digit = dtmf; *digit; digit++) {
 				switch(*digit) {
 				case '0':
-					if (switch_test_flag(member, MFLAG_CAN_SPEAK)) {
-						switch_clear_flag_locked(member, MFLAG_CAN_SPEAK | MFLAG_CAN_HEAR);
-						if (member->conference->muted_sound) {
-							conference_member_play_file(member, member->conference->muted_sound, 0);
-						} else {
-							snprintf(msg, sizeof(msg), "Muted");
-							conference_member_say(member->conference, member, msg, 0);
-						}
-					} else {
-						switch_set_flag_locked(member, MFLAG_CAN_SPEAK);
-						if (member->conference->unmuted_sound) {
-							conference_member_play_file(member, member->conference->unmuted_sound, 0);
-						} else {
-							snprintf(msg, sizeof(msg), "Un-Muted");
-							conference_member_say(member->conference, member, msg, 0);
-						}
-					}
+					conference_loop_fn_mute_toggle(member);
 					break;
 				case '*':
-					if (switch_test_flag(member, MFLAG_CAN_SPEAK)) {
-						switch_clear_flag_locked(member, MFLAG_CAN_SPEAK|MFLAG_CAN_HEAR);
-						if (member->conference->muted_sound) {
-							conference_member_play_file(member, member->conference->muted_sound, 0);
-						} else {
-							snprintf(msg, sizeof(msg), "Muted");
-							conference_member_say(member->conference, member, msg, 0);
-						}
-					} else {
-						switch_set_flag_locked(member, MFLAG_CAN_SPEAK|MFLAG_CAN_HEAR);
-						if (member->conference->unmuted_sound) {
-							conference_member_play_file(member, member->conference->unmuted_sound, 0);
-						} else {
-							snprintf(msg, sizeof(msg), "UN-Muted");
-							conference_member_say(member->conference, member, msg, 0);
-						}
-					}
+					conference_loop_fn_deafmute_toggle(member);
 					break;
 				case '9':
-					switch_mutex_lock(member->flag_mutex);
-					member->energy_level += 100;
-					if (member->energy_level > 1200) {
-						member->energy_level = 1200;
-					}
-					switch_mutex_unlock(member->flag_mutex);
-					snprintf(msg, sizeof(msg), "Energy level %d", member->energy_level);
-					conference_member_say(member->conference, member, msg, 0);
+					conference_loop_fn_energy_up(member);
 					break;
 				case '8':
-					switch_mutex_lock(member->flag_mutex);
-					member->energy_level = member->conference->energy_level;
-					switch_mutex_unlock(member->flag_mutex);
-					snprintf(msg, sizeof(msg), "Energy level %d", member->energy_level);
-					conference_member_say(member->conference, member, msg, 0);
+					conference_loop_fn_energy_equ_conference(member);
 					break;
 				case '7':
-					switch_mutex_lock(member->flag_mutex);
-					member->energy_level -= 100;
-					if (member->energy_level < 0) {
-						member->energy_level = 0;
-					}
-					switch_mutex_unlock(member->flag_mutex);
-					snprintf(msg, sizeof(msg), "Energy level %d", member->energy_level);
-					conference_member_say(member->conference, member, msg, 0);
+					conference_loop_fn_energy_dn(member);
 					break;
 				case '3':
-					switch_mutex_lock(member->flag_mutex);
-					member->volume_out_level++;
-					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);
+					conference_loop_fn_volume_talk_up(member);
 					break;
 				case '2':
-					switch_mutex_lock(member->flag_mutex);
-					member->volume_out_level = 0;
-					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);
+					conference_loop_fn_volume_talk_zero(member);
 					break;
 				case '1':
-					switch_mutex_lock(member->flag_mutex);
-					member->volume_out_level--;
-					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);
+					conference_loop_fn_volume_talk_dn(member);
 					break;
 				case '6':
-					switch_mutex_lock(member->flag_mutex);
-					member->volume_in_level++;
-					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);
+					conference_loop_fn_volume_listen_up(member);
 					break;
 				case '5':
-					switch_mutex_lock(member->flag_mutex);
-					member->volume_in_level = 0;
-					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);
+					conference_loop_fn_volume_listen_zero(member);
 					break;
 				case '4':
-					switch_mutex_lock(member->flag_mutex);
-					member->volume_in_level--;
-					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);
+					conference_loop_fn_volume_listen_dn(member);
 					break;
 				case '#':
-					switch_clear_flag_locked(member, MFLAG_RUNNING);
+					conference_loop_fn_hangup(member);
 					break;
 				default:
 					break;



More information about the Freeswitch-svn mailing list