re-implement sla barge using eavesdrop backend

This commit is contained in:
Anthony Minessale
2012-05-07 13:44:10 -05:00
parent cc1c47b6fe
commit a511ff3026
13 changed files with 378 additions and 80 deletions

View File

@@ -498,21 +498,12 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
continue;
}
if (bp->ready && switch_test_flag(bp, SMBF_READ_STREAM)) {
switch_mutex_lock(bp->read_mutex);
switch_buffer_write(bp->raw_read_buffer, read_frame->data, read_frame->datalen);
if (bp->callback) {
ok = bp->callback(bp, bp->user_data, SWITCH_ABC_TYPE_READ);
}
switch_mutex_unlock(bp->read_mutex);
}
if (ok && switch_test_flag(bp, SMBF_READ_REPLACE)) {
do_bugs = 0;
if (bp->callback) {
bp->read_replace_frame_in = read_frame;
bp->read_replace_frame_out = read_frame;
bp->read_demux_frame = NULL;
if ((ok = bp->callback(bp, bp->user_data, SWITCH_ABC_TYPE_READ_REPLACE)) == SWITCH_TRUE) {
read_frame = bp->read_replace_frame_out;
}
@@ -532,6 +523,55 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
}
}
if (session->bugs) {
switch_media_bug_t *bp;
switch_bool_t ok = SWITCH_TRUE;
int prune = 0;
switch_thread_rwlock_rdlock(session->bug_rwlock);
for (bp = session->bugs; bp; bp = bp->next) {
if (switch_channel_test_flag(session->channel, CF_PAUSE_BUGS) && !switch_core_media_bug_test_flag(bp, SMBF_NO_PAUSE)) {
continue;
}
if (!switch_channel_test_flag(session->channel, CF_ANSWERED) && switch_core_media_bug_test_flag(bp, SMBF_ANSWER_REQ)) {
continue;
}
if (switch_test_flag(bp, SMBF_PRUNE)) {
prune++;
continue;
}
if (ok && bp->ready && switch_test_flag(bp, SMBF_READ_STREAM)) {
switch_mutex_lock(bp->read_mutex);
if (bp->read_demux_frame) {
uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE];
int bytes = read_frame->datalen / 2;
memcpy(data, read_frame->data, read_frame->datalen);
switch_unmerge_sln((int16_t *)data, bytes, bp->read_demux_frame->data, bytes);
switch_buffer_write(bp->raw_read_buffer, data, read_frame->datalen);
} else {
switch_buffer_write(bp->raw_read_buffer, read_frame->data, read_frame->datalen);
}
if (bp->callback) {
ok = bp->callback(bp, bp->user_data, SWITCH_ABC_TYPE_READ);
}
switch_mutex_unlock(bp->read_mutex);
}
if ((bp->stop_time && bp->stop_time <= switch_epoch_time_now(NULL)) || ok == SWITCH_FALSE) {
switch_set_flag(bp, SMBF_PRUNE);
prune++;
}
}
switch_thread_rwlock_unlock(session->bug_rwlock);
if (prune) {
switch_core_media_bug_prune(session);
}
}
if (do_bugs) {
goto done;
}