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

FreeSWITCH SVN anthm at freeswitch.org
Tue Feb 3 15:38:06 PST 2009


Author: anthm
Date: Tue Feb  3 17:38:06 2009
New Revision: 11626

Log:
refactor conference record function to fix some bugs

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	Tue Feb  3 17:38:06 2009
@@ -2129,7 +2129,7 @@
 /* Sub-Routine called by a record entity inside a conference */
 static void *SWITCH_THREAD_FUNC conference_record_thread_run(switch_thread_t *thread, void *obj)
 {
-	uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE];
+	int16_t *data_buf;
 	switch_file_handle_t fh = { 0 };
 	conference_member_t smember = { 0 }, *member;
 	conference_record_t *rec = (conference_record_t *) obj;
@@ -2139,6 +2139,11 @@
 	char *vval;
 	switch_timer_t timer = { 0 };
 	uint32_t rlen;
+	switch_size_t data_buf_len;
+
+	data_buf_len = samples * sizeof(int16_t);
+
+	switch_zmalloc(data_buf, data_buf_len);
 
 	if (switch_thread_rwlock_tryrdlock(conference->rwlock) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Read Lock Fail\n");
@@ -2212,9 +2217,9 @@
 	switch_core_file_set_string(&fh, SWITCH_AUDIO_COL_STR_ARTIST, "FreeSWITCH mod_conference Software Conference Module");
 
 	while (switch_test_flag(member, MFLAG_RUNNING) && switch_test_flag(conference, CFLAG_RUNNING) && conference->count) {
-		switch_size_t len;
+		switch_size_t len = 0;
 		mux_used = (uint32_t) switch_buffer_inuse(member->mux_buffer);
-
+		
 		if (switch_test_flag(member, MFLAG_FLUSH_BUFFER)) {
 			if (mux_used) {
 				switch_mutex_lock(member->audio_out_mutex);
@@ -2225,26 +2230,26 @@
 			switch_clear_flag_locked(member, MFLAG_FLUSH_BUFFER);
 		}
 
-		if (mux_used) {
-			/* Flush the output buffer and write all the data (presumably muxed) to the file */
-			switch_mutex_lock(member->audio_out_mutex);
-			low_count = 0;
+		if (switch_test_flag((&fh), SWITCH_FILE_PAUSE)) {
+			switch_set_flag_locked(member, MFLAG_FLUSH_BUFFER);
+		} else {
+			if (mux_used) {
+				/* Flush the output buffer and write all the data (presumably muxed) to the file */
+				switch_mutex_lock(member->audio_out_mutex);
+				low_count = 0;
 
-			if ((rlen = (uint32_t) switch_buffer_read(member->mux_buffer, data, sizeof(data)))) {
-				if (!switch_test_flag((&fh), SWITCH_FILE_PAUSE)) {
+				if ((rlen = (uint32_t) switch_buffer_read(member->mux_buffer, data_buf, data_buf_len))) {
 					len = (switch_size_t) rlen / sizeof(int16_t);
 				}
-			}
-			switch_mutex_unlock(member->audio_out_mutex);
-		} else {
-			if (!switch_test_flag((&fh), SWITCH_FILE_PAUSE)) {
+				switch_mutex_unlock(member->audio_out_mutex);
+			} 
+			
+			if (len < (switch_size_t) samples) {
+				memset(data_buf + (len * sizeof(int16_t)), 255, ((switch_size_t)samples - len) * sizeof(int16_t));
 				len = (switch_size_t) samples;
-				memset(data, 0, len);
 			}
-		}
-
-		if (!switch_test_flag((&fh), SWITCH_FILE_PAUSE)) {
-			if (switch_core_file_write(&fh, data, &len) != SWITCH_STATUS_SUCCESS) {
+			
+			if (!len || switch_core_file_write(&fh, data_buf, &len) != SWITCH_STATUS_SUCCESS) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write Failed\n");
 				switch_clear_flag_locked(member, MFLAG_RUNNING);
 			}
@@ -2255,6 +2260,7 @@
 
   end:
 
+	switch_safe_free(data_buf);
 	switch_core_timer_destroy(&timer);
 	conference_del_member(conference, member);
 	switch_buffer_destroy(&member->audio_buffer);



More information about the Freeswitch-svn mailing list