[Freeswitch-svn] [commit] r11661 - freeswitch/trunk/src/mod/applications/mod_conference

FreeSWITCH SVN anthm at freeswitch.org
Thu Feb 5 14:43:47 PST 2009


Author: anthm
Date: Thu Feb  5 16:43:46 2009
New Revision: 11661

Log:
MODAPP-209

Modified:
   freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.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	Thu Feb  5 16:43:46 2009
@@ -288,6 +288,7 @@
 	uint32_t flags;
 	uint32_t score;
 	switch_mutex_t *flag_mutex;
+	switch_mutex_t *control_mutex;
 	switch_mutex_t *audio_in_mutex;
 	switch_mutex_t *audio_out_mutex;
 	switch_codec_t *orig_read_codec;
@@ -448,8 +449,8 @@
 	if (member == NULL || other_member == NULL || member->relationships == NULL)
 		return NULL;
 
-	switch_mutex_lock(member->flag_mutex);
-	switch_mutex_lock(other_member->flag_mutex);
+	switch_mutex_lock(member->control_mutex);
+	switch_mutex_lock(other_member->control_mutex);
 
 	for (rel = member->relationships; rel; rel = rel->next) {
 		if (rel->id == other_member->id) {
@@ -462,8 +463,8 @@
 		}
 	}
 
-	switch_mutex_unlock(other_member->flag_mutex);
-	switch_mutex_unlock(member->flag_mutex);
+	switch_mutex_unlock(other_member->control_mutex);
+	switch_mutex_unlock(member->control_mutex);
 
 	return rel ? rel : global;
 }
@@ -527,10 +528,10 @@
 
 	rel->id = id;
 
-	switch_mutex_lock(member->flag_mutex);
+	switch_mutex_lock(member->control_mutex);
 	rel->next = member->relationships;
 	member->relationships = rel;
-	switch_mutex_unlock(member->flag_mutex);
+	switch_mutex_unlock(member->control_mutex);
 
 	return rel;
 }
@@ -544,7 +545,7 @@
 	if (member == NULL || id == 0)
 		return status;
 
-	switch_mutex_lock(member->flag_mutex);
+	switch_mutex_lock(member->control_mutex);
 	for (rel = member->relationships; rel; rel = rel->next) {
 		if (rel->id == id) {
 			/* we just forget about rel here cos it was allocated by the member's pool 
@@ -558,7 +559,7 @@
 		}
 		last = rel;
 	}
-	switch_mutex_unlock(member->flag_mutex);
+	switch_mutex_unlock(member->control_mutex);
 
 	return status;
 }
@@ -578,7 +579,7 @@
 	switch_mutex_lock(conference->mutex);
 	switch_mutex_lock(member->audio_in_mutex);
 	switch_mutex_lock(member->audio_out_mutex);
-	switch_mutex_lock(member->flag_mutex);
+	switch_mutex_lock(member->control_mutex);
 	switch_mutex_lock(conference->member_mutex);
 
 	switch_clear_flag(conference, CFLAG_DESTRUCT);
@@ -587,7 +588,7 @@
 	member->energy_level = conference->energy_level;
 	member->verbose_events = conference->verbose_events;
 	conference->members = member;
-	switch_set_flag(member, MFLAG_INTREE);
+	switch_set_flag_locked(member, MFLAG_INTREE);
 	switch_mutex_unlock(conference->member_mutex);
 
 	if (!switch_test_flag(member, MFLAG_NOCHANNEL)) {
@@ -658,7 +659,7 @@
 		}
 
 	}
-	switch_mutex_unlock(member->flag_mutex);
+	switch_mutex_unlock(member->control_mutex);
 	switch_mutex_unlock(member->audio_out_mutex);
 	switch_mutex_unlock(member->audio_in_mutex);
 
@@ -674,15 +675,24 @@
 	switch_status_t status = SWITCH_STATUS_FALSE;
 	conference_member_t *imember, *last = NULL;
 	switch_event_t *event;
+	conference_file_node_t *member_fnode;
+	switch_speech_handle_t *member_sh;
 
 	switch_assert(conference != NULL);
 	switch_assert(member != NULL);
 
+	switch_mutex_lock(member->control_mutex);
+	member_fnode = member->fnode;
+	member_sh = member->sh;
+	member->fnode = NULL;
+	member->sh = NULL;
+	switch_mutex_unlock(member->control_mutex);
+
 	switch_mutex_lock(conference->mutex);
 	switch_mutex_lock(conference->member_mutex);
 	switch_mutex_lock(member->audio_in_mutex);
 	switch_mutex_lock(member->audio_out_mutex);
-	switch_mutex_lock(member->flag_mutex);
+	switch_mutex_lock(member->control_mutex);
 	switch_clear_flag(member, MFLAG_INTREE);
 
 	for (imember = conference->members; imember; imember = imember->next) {
@@ -698,11 +708,11 @@
 	}
 
 	/* Close Unused Handles */
-	if (member->fnode) {
+	if (member_fnode) {
 		conference_file_node_t *fnode, *cur;
 		switch_memory_pool_t *pool;
 
-		fnode = member->fnode;
+		fnode = member_fnode;
 		while (fnode) {
 			cur = fnode;
 			fnode = fnode->next;
@@ -716,10 +726,9 @@
 		}
 	}
 
-	if (member->sh) {
+	if (member_sh) {
 		switch_speech_flag_t flags = SWITCH_SPEECH_FLAG_NONE;
 		switch_core_speech_close(&member->lsh, &flags);
-		member->sh = NULL;
 	}
 
 	if (switch_test_flag(member, MFLAG_ENDCONF)) {
@@ -775,7 +784,7 @@
 		}
 	}
 	switch_mutex_unlock(conference->member_mutex);
-	switch_mutex_unlock(member->flag_mutex);
+	switch_mutex_unlock(member->control_mutex);
 	switch_mutex_unlock(member->audio_out_mutex);
 	switch_mutex_unlock(member->audio_in_mutex);
 	switch_mutex_unlock(conference->mutex);
@@ -1298,7 +1307,7 @@
 	if (member == NULL)
 		return;
 
-	switch_mutex_lock(member->flag_mutex);
+	switch_mutex_lock(member->control_mutex);
 	member->energy_level += 200;
 	if (member->energy_level > 3000) {
 		member->energy_level = 3000;
@@ -1311,7 +1320,7 @@
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "New-Level", "%d", member->energy_level);
 		switch_event_fire(&event);
 	}
-	switch_mutex_unlock(member->flag_mutex);
+	switch_mutex_unlock(member->control_mutex);
 
 	switch_snprintf(msg, sizeof(msg), "Energy level %d", member->energy_level);
 	conference_member_say(member, msg, 0);
@@ -1325,7 +1334,7 @@
 	if (member == NULL)
 		return;
 
-	switch_mutex_lock(member->flag_mutex);
+	switch_mutex_lock(member->control_mutex);
 	member->energy_level = member->conference->energy_level;
 
 	if (test_eflag(member->conference, EFLAG_ENERGY_LEVEL) &&
@@ -1335,7 +1344,7 @@
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "New-Level", "%d", member->energy_level);
 		switch_event_fire(&event);
 	}
-	switch_mutex_unlock(member->flag_mutex);
+	switch_mutex_unlock(member->control_mutex);
 
 	switch_snprintf(msg, sizeof(msg), "Energy level %d", member->energy_level);
 	conference_member_say(member, msg, 0);
@@ -1349,7 +1358,7 @@
 	if (member == NULL)
 		return;
 
-	switch_mutex_lock(member->flag_mutex);
+	switch_mutex_lock(member->control_mutex);
 	member->energy_level -= 100;
 	if (member->energy_level < 0) {
 		member->energy_level = 0;
@@ -1362,7 +1371,7 @@
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "New-Level", "%d", member->energy_level);
 		switch_event_fire(&event);
 	}
-	switch_mutex_unlock(member->flag_mutex);
+	switch_mutex_unlock(member->control_mutex);
 
 	switch_snprintf(msg, sizeof(msg), "Energy level %d", member->energy_level);
 	conference_member_say(member, msg, 0);
@@ -1376,7 +1385,7 @@
 	if (member == NULL)
 		return;
 
-	switch_mutex_lock(member->flag_mutex);
+	switch_mutex_lock(member->control_mutex);
 	member->volume_out_level++;
 	switch_normalize_volume(member->volume_out_level);
 
@@ -1387,7 +1396,7 @@
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "New-Level", "%d", member->volume_out_level);
 		switch_event_fire(&event);
 	}
-	switch_mutex_unlock(member->flag_mutex);
+	switch_mutex_unlock(member->control_mutex);
 
 	switch_snprintf(msg, sizeof(msg), "Volume level %d", member->volume_out_level);
 	conference_member_say(member, msg, 0);
@@ -1401,7 +1410,7 @@
 	if (member == NULL)
 		return;
 
-	switch_mutex_lock(member->flag_mutex);
+	switch_mutex_lock(member->control_mutex);
 	member->volume_out_level = 0;
 
 	if (test_eflag(member->conference, EFLAG_VOLUME_LEVEL) &&
@@ -1411,7 +1420,7 @@
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "New-Level", "%d", member->volume_out_level);
 		switch_event_fire(&event);
 	}
-	switch_mutex_unlock(member->flag_mutex);
+	switch_mutex_unlock(member->control_mutex);
 
 	switch_snprintf(msg, sizeof(msg), "Volume level %d", member->volume_out_level);
 	conference_member_say(member, msg, 0);
@@ -1425,7 +1434,7 @@
 	if (member == NULL)
 		return;
 
-	switch_mutex_lock(member->flag_mutex);
+	switch_mutex_lock(member->control_mutex);
 	member->volume_out_level--;
 	switch_normalize_volume(member->volume_out_level);
 
@@ -1436,7 +1445,7 @@
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "New-Level", "%d", member->volume_out_level);
 		switch_event_fire(&event);
 	}
-	switch_mutex_unlock(member->flag_mutex);
+	switch_mutex_unlock(member->control_mutex);
 
 	switch_snprintf(msg, sizeof(msg), "Volume level %d", member->volume_out_level);
 	conference_member_say(member, msg, 0);
@@ -1450,7 +1459,7 @@
 	if (member == NULL)
 		return;
 
-	switch_mutex_lock(member->flag_mutex);
+	switch_mutex_lock(member->control_mutex);
 	member->volume_in_level++;
 	switch_normalize_volume(member->volume_in_level);
 
@@ -1461,7 +1470,7 @@
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "New-Level", "%d", member->volume_in_level);
 		switch_event_fire(&event);
 	}
-	switch_mutex_unlock(member->flag_mutex);
+	switch_mutex_unlock(member->control_mutex);
 
 	switch_snprintf(msg, sizeof(msg), "Gain level %d", member->volume_in_level);
 	conference_member_say(member, msg, 0);
@@ -1475,7 +1484,7 @@
 	if (member == NULL)
 		return;
 
-	switch_mutex_lock(member->flag_mutex);
+	switch_mutex_lock(member->control_mutex);
 	member->volume_in_level = 0;
 
 	if (test_eflag(member->conference, EFLAG_GAIN_LEVEL) &&
@@ -1485,7 +1494,7 @@
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "New-Level", "%d", member->volume_in_level);
 		switch_event_fire(&event);
 	}
-	switch_mutex_unlock(member->flag_mutex);
+	switch_mutex_unlock(member->control_mutex);
 
 	switch_snprintf(msg, sizeof(msg), "Gain level %d", member->volume_in_level);
 	conference_member_say(member, msg, 0);
@@ -1499,7 +1508,7 @@
 	if (member == NULL)
 		return;
 
-	switch_mutex_lock(member->flag_mutex);
+	switch_mutex_lock(member->control_mutex);
 	member->volume_in_level--;
 	switch_normalize_volume(member->volume_in_level);
 
@@ -1510,7 +1519,7 @@
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "New-Level", "%d", member->volume_in_level);
 		switch_event_fire(&event);
 	}
-	switch_mutex_unlock(member->flag_mutex);
+	switch_mutex_unlock(member->control_mutex);
 
 	switch_snprintf(msg, sizeof(msg), "Gain level %d", member->volume_in_level);
 	conference_member_say(member, msg, 0);
@@ -1893,7 +1902,7 @@
 			goto top;
 		}
 
-		switch_mutex_lock(member->flag_mutex);
+		switch_mutex_lock(member->control_mutex);
 
 		if (switch_core_session_dequeue_event(member->session, &event) == SWITCH_STATUS_SUCCESS) {
 			if (event->event_id == SWITCH_EVENT_MESSAGE) {
@@ -2086,7 +2095,7 @@
 			switch_clear_flag_locked(member, MFLAG_FLUSH_BUFFER);
 		}
 		
-		switch_mutex_unlock(member->flag_mutex);
+		switch_mutex_unlock(member->control_mutex);
 
 
 		if (switch_core_session_private_event_count(member->session)) {
@@ -2171,7 +2180,7 @@
 	member->mux_frame = switch_core_alloc(member->pool, member->frame_size);
 
 
-	switch_mutex_init(&member->flag_mutex, SWITCH_MUTEX_NESTED, rec->pool);
+	switch_mutex_init(&member->control_mutex, SWITCH_MUTEX_NESTED, rec->pool);
 	switch_mutex_init(&member->audio_in_mutex, SWITCH_MUTEX_NESTED, rec->pool);
 	switch_mutex_init(&member->audio_out_mutex, SWITCH_MUTEX_NESTED, rec->pool);
 
@@ -2330,7 +2339,7 @@
 	if (member == NULL)
 		return count;
 
-	switch_mutex_lock(member->flag_mutex);
+	switch_mutex_lock(member->control_mutex);
 
 	if (stop == FILE_STOP_ALL) {
 		for (nptr = member->fnode; nptr; nptr = nptr->next) {
@@ -2344,7 +2353,7 @@
 		}
 	}
 
-	switch_mutex_unlock(member->flag_mutex);
+	switch_mutex_unlock(member->control_mutex);
 
 	return count;
 }
@@ -2526,14 +2535,14 @@
 	fnode->pool = pool;
 	/* Queue the node */
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Queueing file '%s' for play\n", file);
-	switch_mutex_lock(member->flag_mutex);
+	switch_mutex_lock(member->control_mutex);
 	for (nptr = member->fnode; nptr && nptr->next; nptr = nptr->next);
 	if (nptr) {
 		nptr->next = fnode;
 	} else {
 		member->fnode = fnode;
 	}
-	switch_mutex_unlock(member->flag_mutex);
+	switch_mutex_unlock(member->control_mutex);
 	status = SWITCH_STATUS_SUCCESS;
 
   done:
@@ -2591,7 +2600,7 @@
 	}
 
 	/* Queue the node */
-	switch_mutex_lock(member->flag_mutex);
+	switch_mutex_lock(member->control_mutex);
 	for (nptr = member->fnode; nptr && nptr->next; nptr = nptr->next);
 
 	if (nptr) {
@@ -2617,7 +2626,7 @@
 	}
 
 	switch_core_speech_feed_tts(fnode->sh, text, &flags);
-	switch_mutex_unlock(member->flag_mutex);
+	switch_mutex_unlock(member->control_mutex);
 
 	status = SWITCH_STATUS_SUCCESS;
 
@@ -2918,11 +2927,11 @@
 	if (member == NULL)
 		return SWITCH_STATUS_GENERR;
 
-	switch_mutex_lock(member->flag_mutex);
+	switch_mutex_lock(member->control_mutex);
 	switch_clear_flag(member, MFLAG_RUNNING);
-	switch_set_flag(member, MFLAG_KICKED);
+	switch_set_flag_locked(member, MFLAG_KICKED);
 	switch_core_session_kill_channel(member->session, SWITCH_SIG_BREAK);
-	switch_mutex_unlock(member->flag_mutex);
+	switch_mutex_unlock(member->control_mutex);
 	if (stream != NULL) {
 		stream->write_function(stream, "OK kicked %u\n", member->id);
 	}
@@ -2952,10 +2961,10 @@
 		return SWITCH_STATUS_GENERR;
 	}
 
-	switch_mutex_lock(member->flag_mutex);
+	switch_mutex_lock(member->control_mutex);
 	switch_core_session_kill_channel(member->session, SWITCH_SIG_BREAK);
 	switch_core_session_send_dtmf_string(member->session, (char *) data);
-	switch_mutex_unlock(member->flag_mutex);
+	switch_mutex_unlock(member->control_mutex);
 
 	if (stream != NULL) {
 		stream->write_function(stream, "OK sent %s to %u\n", (char *) data, member->id);
@@ -2980,9 +2989,9 @@
 		return SWITCH_STATUS_GENERR;
 
 	if (data) {
-		switch_mutex_lock(member->flag_mutex);
+		switch_mutex_lock(member->control_mutex);
 		member->energy_level = atoi((char *) data);
-		switch_mutex_unlock(member->flag_mutex);
+		switch_mutex_unlock(member->control_mutex);
 	}
 	if (stream != NULL) {
 		stream->write_function(stream, "Energy %u = %d\n", member->id, member->energy_level);
@@ -3006,10 +3015,10 @@
 		return SWITCH_STATUS_GENERR;
 
 	if (data) {
-		switch_mutex_lock(member->flag_mutex);
+		switch_mutex_lock(member->control_mutex);
 		member->volume_in_level = atoi((char *) data);
 		switch_normalize_volume(member->volume_in_level);
-		switch_mutex_unlock(member->flag_mutex);
+		switch_mutex_unlock(member->control_mutex);
 	}
 	if (stream != NULL) {
 		stream->write_function(stream, "Volume IN %u = %d\n", member->id, member->volume_in_level);
@@ -3033,10 +3042,10 @@
 		return SWITCH_STATUS_GENERR;
 
 	if (data) {
-		switch_mutex_lock(member->flag_mutex);
+		switch_mutex_lock(member->control_mutex);
 		member->volume_out_level = atoi((char *) data);
 		switch_normalize_volume(member->volume_out_level);
-		switch_mutex_unlock(member->flag_mutex);
+		switch_mutex_unlock(member->control_mutex);
 	}
 	if (stream != NULL) {
 		stream->write_function(stream, "Volume OUT %u = %d\n", member->id, member->volume_out_level);
@@ -3684,7 +3693,7 @@
 			}
 
 			/* move the member from the old conference to the new one */
-			switch_mutex_lock(member->flag_mutex);
+			switch_mutex_lock(member->control_mutex);
 			conference_del_member(conference, member);
 			conference_add_member(new_conference, member);
 
@@ -3693,12 +3702,12 @@
 					switch_clear_flag_locked(member, MFLAG_RUNNING);
 				} else {
 					switch_channel_set_flag(channel, CF_SERVICE);
-					switch_set_flag(member, MFLAG_RESTART);
+					switch_set_flag_locked(member, MFLAG_RESTART);
 				}
 			}
 
 			switch_mutex_unlock(new_conference->mutex);
-			switch_mutex_unlock(member->flag_mutex);
+			switch_mutex_unlock(member->control_mutex);
 
 			
 			stream->write_function(stream, "OK Member '%d' sent to conference %s.\n", member->id, argv[2]);
@@ -4820,6 +4829,7 @@
 	/* Prepare MUTEXS */
 	member.id = next_member_id();
 	switch_mutex_init(&member.flag_mutex, SWITCH_MUTEX_NESTED, member.pool);
+	switch_mutex_init(&member.control_mutex, SWITCH_MUTEX_NESTED, member.pool);
 	switch_mutex_init(&member.audio_in_mutex, SWITCH_MUTEX_NESTED, member.pool);
 	switch_mutex_init(&member.audio_out_mutex, SWITCH_MUTEX_NESTED, member.pool);
 



More information about the Freeswitch-svn mailing list