refactor conference record function to fix some bugs

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@11626 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2009-02-03 23:38:06 +00:00
parent d7a5a04aa5
commit 8daae0bb4e

View File

@ -2129,7 +2129,7 @@ static void conference_loop_output(conference_member_t *member)
/* 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 @@ static void *SWITCH_THREAD_FUNC conference_record_thread_run(switch_thread_t *th
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 @@ static void *SWITCH_THREAD_FUNC conference_record_thread_run(switch_thread_t *th
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 @@ static void *SWITCH_THREAD_FUNC conference_record_thread_run(switch_thread_t *th
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 @@ static void *SWITCH_THREAD_FUNC conference_record_thread_run(switch_thread_t *th
end:
switch_safe_free(data_buf);
switch_core_timer_destroy(&timer);
conference_del_member(conference, member);
switch_buffer_destroy(&member->audio_buffer);