git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7623 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2008-02-15 19:08:45 +00:00
parent a7997d674a
commit dd1c14cfa8

View File

@ -855,6 +855,7 @@ static void *SWITCH_THREAD_FUNC conference_thread_run(switch_thread_t * thread,
switch_set_flag(conference, CFLAG_DESTRUCT); switch_set_flag(conference, CFLAG_DESTRUCT);
break; break;
} }
switch_mutex_lock(conference->mutex); switch_mutex_lock(conference->mutex);
has_file_data = ready = total = 0; has_file_data = ready = total = 0;
@ -919,11 +920,13 @@ static void *SWITCH_THREAD_FUNC conference_thread_run(switch_thread_t * thread,
} else if (!conference->async_fnode->done) { } else if (!conference->async_fnode->done) {
file_sample_len = samples; file_sample_len = samples;
switch_core_file_read(&conference->async_fnode->fh, async_file_frame, &file_sample_len); switch_core_file_read(&conference->async_fnode->fh, async_file_frame, &file_sample_len);
if (file_sample_len <= 0) { if (file_sample_len <= 0) {
conference->async_fnode->done++; conference->async_fnode->done++;
} else { } else {
if (has_file_data) { if (has_file_data) {
switch_size_t x; switch_size_t x;
for (x = 0; x < file_sample_len; x++) { for (x = 0; x < file_sample_len; x++) {
int32_t z; int32_t z;
int16_t *bptr, *muxed; int16_t *bptr, *muxed;
@ -945,6 +948,7 @@ static void *SWITCH_THREAD_FUNC conference_thread_run(switch_thread_t * thread,
if (ready || has_file_data) { if (ready || has_file_data) {
//int nt = 0; //int nt = 0;
/* Build a muxed frame for every member that contains the mixed audio of everyone else */ /* Build a muxed frame for every member that contains the mixed audio of everyone else */
for (omember = conference->members; omember; omember = omember->next) { for (omember = conference->members; omember; omember = omember->next) {
if (has_file_data && file_sample_len) { if (has_file_data && file_sample_len) {
uint32_t sample_bytes = file_sample_len * 2; uint32_t sample_bytes = file_sample_len * 2;
@ -1020,7 +1024,6 @@ static void *SWITCH_THREAD_FUNC conference_thread_run(switch_thread_t * thread,
#endif #endif
} }
} }
/* Go back and write each member his dedicated copy of the audio frame that does not contain his own audio. */ /* Go back and write each member his dedicated copy of the audio frame that does not contain his own audio. */
for (imember = conference->members; imember; imember = imember->next) { for (imember = conference->members; imember; imember = imember->next) {
if (switch_test_flag(imember, MFLAG_RUNNING)) { if (switch_test_flag(imember, MFLAG_RUNNING)) {
@ -1648,12 +1651,14 @@ static void conference_loop_output(conference_member_t * member)
uint32_t samples = switch_bytes_per_frame(member->conference->rate, interval); uint32_t samples = switch_bytes_per_frame(member->conference->rate, interval);
uint32_t csamples = samples; uint32_t csamples = samples;
uint32_t tsamples = member->orig_read_codec->implementation->samples_per_frame; uint32_t tsamples = member->orig_read_codec->implementation->samples_per_frame;
uint32_t flush_len = member->read_codec.implementation->bytes_per_frame * 4; uint32_t flush_len = 0;
uint32_t low_count = 0, bytes = samples * 2; uint32_t low_count = 0, bytes = samples * 2;
call_list_t *call_list = NULL, *cp = NULL; call_list_t *call_list = NULL, *cp = NULL;
switch_assert(member->conference != NULL); switch_assert(member->conference != NULL);
flush_len = switch_bytes_per_frame(member->conference->rate, member->conference->interval) * 2;
if (switch_core_timer_init(&timer, member->conference->timer_name, interval, tsamples, NULL) != SWITCH_STATUS_SUCCESS) { if (switch_core_timer_init(&timer, member->conference->timer_name, interval, tsamples, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer Setup Failed. Conference Cannot Start\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer Setup Failed. Conference Cannot Start\n");
return; return;
@ -1846,7 +1851,7 @@ static void conference_loop_output(conference_member_t * member)
} }
} }
} }
} else { /* send the conferecne frame to the call leg */ } else {
switch_buffer_t *use_buffer = NULL; switch_buffer_t *use_buffer = NULL;
uint32_t mux_used = (uint32_t) switch_buffer_inuse(member->mux_buffer); uint32_t mux_used = (uint32_t) switch_buffer_inuse(member->mux_buffer);
@ -1856,26 +1861,17 @@ static void conference_loop_output(conference_member_t * member)
/* partial frame sitting around this long is useless and builds delay */ /* partial frame sitting around this long is useless and builds delay */
switch_set_flag_locked(member, MFLAG_FLUSH_BUFFER); switch_set_flag_locked(member, MFLAG_FLUSH_BUFFER);
} }
mux_used = 0;
} else if (mux_used > flush_len) { } else if (mux_used > flush_len) {
/* getting behind, clear the buffer */ /* getting behind, clear the buffer */
switch_set_flag_locked(member, MFLAG_FLUSH_BUFFER); switch_set_flag_locked(member, MFLAG_FLUSH_BUFFER);
} }
} }
if (switch_test_flag(member, MFLAG_FLUSH_BUFFER)) {
if (mux_used) {
switch_mutex_lock(member->audio_out_mutex);
switch_buffer_zero(member->mux_buffer);
switch_mutex_unlock(member->audio_out_mutex);
mux_used = 0;
}
switch_clear_flag_locked(member, MFLAG_FLUSH_BUFFER);
}
use_timer = 1; use_timer = 1;
if (mux_used) { if (mux_used >= bytes) {
/* Flush the output buffer and write all the data (presumably muxed) back to the channel */ /* Flush the output buffer and write all the data (presumably muxed) back to the channel */
switch_mutex_lock(member->audio_out_mutex); switch_mutex_lock(member->audio_out_mutex);
write_frame.data = data; write_frame.data = data;
@ -1895,8 +1891,6 @@ static void conference_loop_output(conference_member_t * member)
} }
switch_mutex_unlock(member->audio_out_mutex); switch_mutex_unlock(member->audio_out_mutex);
} else { } else {
if (switch_test_flag(member, MFLAG_WASTE_BANDWIDTH)) { if (switch_test_flag(member, MFLAG_WASTE_BANDWIDTH)) {
if (member->conference->comfort_noise_level) { if (member->conference->comfort_noise_level) {
@ -1912,10 +1906,21 @@ static void conference_loop_output(conference_member_t * member)
} }
} }
if (switch_test_flag(member, MFLAG_FLUSH_BUFFER)) {
if (switch_buffer_inuse(member->mux_buffer)) {
switch_mutex_lock(member->audio_out_mutex);
switch_buffer_zero(member->mux_buffer);
switch_mutex_unlock(member->audio_out_mutex);
}
switch_clear_flag_locked(member, MFLAG_FLUSH_BUFFER);
}
switch_mutex_unlock(member->flag_mutex); switch_mutex_unlock(member->flag_mutex);
if (use_timer) { if (use_timer) {
switch_core_timer_next(&timer); switch_core_timer_next(&timer);
} else {
switch_yield(1000);
} }
} /* Rinse ... Repeat */ } /* Rinse ... Repeat */
@ -4247,6 +4252,7 @@ SWITCH_STANDARD_APP(conference_function)
NULL, NULL,
read_codec->implementation->actual_samples_per_second, read_codec->implementation->actual_samples_per_second,
read_codec->implementation->microseconds_per_frame / 1000, read_codec->implementation->microseconds_per_frame / 1000,
//conference->interval,
1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, member.pool) == SWITCH_STATUS_SUCCESS) { 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, member.pool) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
"Raw Codec Activation Success L16@%uhz 1 channel %dms\n", "Raw Codec Activation Success L16@%uhz 1 channel %dms\n",
@ -4260,7 +4266,7 @@ SWITCH_STANDARD_APP(conference_function)
goto done; goto done;
} }
member.frame_size = switch_bytes_per_frame(conference->rate, conference->interval) * 4; member.frame_size = SWITCH_RECOMMENDED_BUFFER_SIZE;
member.frame = switch_core_alloc(member.pool, member.frame_size); member.frame = switch_core_alloc(member.pool, member.frame_size);
member.mux_frame = switch_core_alloc(member.pool, member.frame_size); member.mux_frame = switch_core_alloc(member.pool, member.frame_size);