bug in the bugs

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4109 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2007-02-02 21:01:13 +00:00
parent 82db5e0112
commit 6f9be6bf5a
2 changed files with 17 additions and 3 deletions

View File

@ -67,6 +67,7 @@ struct switch_media_bug {
switch_core_session_t *session; switch_core_session_t *session;
void *user_data; void *user_data;
uint32_t flags; uint32_t flags;
uint8_t ready;
struct switch_media_bug *next; struct switch_media_bug *next;
}; };
@ -313,6 +314,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_add(switch_core_session_t
bug->user_data = user_data; bug->user_data = user_data;
bug->session = session; bug->session = session;
bug->flags = flags; bug->flags = flags;
bug->ready = 1;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Attaching BUG to %s\n", switch_channel_get_name(session->channel)); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Attaching BUG to %s\n", switch_channel_get_name(session->channel));
bytes = session->read_codec->implementation->bytes_per_frame; bytes = session->read_codec->implementation->bytes_per_frame;
@ -374,6 +376,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove(switch_core_session
if (session->bugs) { if (session->bugs) {
switch_thread_rwlock_wrlock(session->bug_rwlock); switch_thread_rwlock_wrlock(session->bug_rwlock);
for (bp = session->bugs; bp; bp = bp->next) { for (bp = session->bugs; bp; bp = bp->next) {
if (!bp->ready) {
continue;
}
if (bp == *bug) { if (bp == *bug) {
if (last) { if (last) {
last->next = bp->next; last->next = bp->next;
@ -389,6 +394,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove(switch_core_session
if (bp) { if (bp) {
if (bp->callback) { if (bp->callback) {
bp->callback(bp, bp->user_data, SWITCH_ABC_TYPE_CLOSE); bp->callback(bp, bp->user_data, SWITCH_ABC_TYPE_CLOSE);
bp->ready = 0;
} }
switch_core_media_bug_destroy(bp); switch_core_media_bug_destroy(bp);
*bug = NULL; *bug = NULL;
@ -2012,7 +2018,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
switch_media_bug_t *bp; switch_media_bug_t *bp;
switch_thread_rwlock_rdlock(session->bug_rwlock); switch_thread_rwlock_rdlock(session->bug_rwlock);
for (bp = session->bugs; bp; bp = bp->next) { for (bp = session->bugs; bp; bp = bp->next) {
if (switch_test_flag(bp, SMBF_READ_STREAM)) { if (bp->ready && switch_test_flag(bp, SMBF_READ_STREAM)) {
switch_mutex_lock(bp->read_mutex); switch_mutex_lock(bp->read_mutex);
switch_buffer_write(bp->raw_read_buffer, read_frame->data, read_frame->datalen); switch_buffer_write(bp->raw_read_buffer, read_frame->data, read_frame->datalen);
if (bp->callback) { if (bp->callback) {
@ -2249,6 +2255,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
switch_media_bug_t *bp; switch_media_bug_t *bp;
switch_thread_rwlock_rdlock(session->bug_rwlock); switch_thread_rwlock_rdlock(session->bug_rwlock);
for (bp = session->bugs; bp; bp = bp->next) { for (bp = session->bugs; bp; bp = bp->next) {
if (!bp->ready) {
continue;
}
if (switch_test_flag(bp, SMBF_WRITE_STREAM)) { if (switch_test_flag(bp, SMBF_WRITE_STREAM)) {
switch_mutex_lock(bp->write_mutex); switch_mutex_lock(bp->write_mutex);
switch_buffer_write(bp->raw_write_buffer, write_frame->data, write_frame->datalen); switch_buffer_write(bp->raw_write_buffer, write_frame->data, write_frame->datalen);

View File

@ -551,7 +551,10 @@ static void record_callback(switch_media_bug_t *bug, void *user_data, switch_abc
case SWITCH_ABC_TYPE_INIT: case SWITCH_ABC_TYPE_INIT:
break; break;
case SWITCH_ABC_TYPE_CLOSE: case SWITCH_ABC_TYPE_CLOSE:
switch_core_file_close(fh); if (fh) {
switch_core_file_close(fh);
}
break;
case SWITCH_ABC_TYPE_READ: case SWITCH_ABC_TYPE_READ:
if (fh) { if (fh) {
switch_size_t len; switch_size_t len;
@ -767,11 +770,13 @@ static void speech_callback(switch_media_bug_t *bug, void *user_data, switch_abc
} }
break; break;
case SWITCH_ABC_TYPE_CLOSE: case SWITCH_ABC_TYPE_CLOSE: {
switch_core_asr_close(sth->ah, &flags); switch_core_asr_close(sth->ah, &flags);
switch_mutex_lock(sth->mutex); switch_mutex_lock(sth->mutex);
switch_thread_cond_signal(sth->cond); switch_thread_cond_signal(sth->cond);
switch_mutex_unlock(sth->mutex); switch_mutex_unlock(sth->mutex);
}
break;
case SWITCH_ABC_TYPE_READ: case SWITCH_ABC_TYPE_READ:
if (sth->ah) { if (sth->ah) {
if (switch_core_media_bug_read(bug, &frame) == SWITCH_STATUS_SUCCESS) { if (switch_core_media_bug_read(bug, &frame) == SWITCH_STATUS_SUCCESS) {