Author: anthm Date: Fri Feb 2 16:01:13 2007 New Revision: 4109 Modified: freeswitch/trunk/src/switch_core.c freeswitch/trunk/src/switch_ivr.c Log: bug in the bugs Modified: freeswitch/trunk/src/switch_core.c ============================================================================== --- freeswitch/trunk/src/switch_core.c (original) +++ freeswitch/trunk/src/switch_core.c Fri Feb 2 16:01:13 2007 @@ -67,6 +67,7 @@ switch_core_session_t *session; void *user_data; uint32_t flags; + uint8_t ready; struct switch_media_bug *next; }; @@ -313,6 +314,7 @@ bug->user_data = user_data; bug->session = session; 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)); bytes = session->read_codec->implementation->bytes_per_frame; @@ -374,6 +376,9 @@ if (session->bugs) { switch_thread_rwlock_wrlock(session->bug_rwlock); for (bp = session->bugs; bp; bp = bp->next) { + if (!bp->ready) { + continue; + } if (bp == *bug) { if (last) { last->next = bp->next; @@ -389,6 +394,7 @@ if (bp) { if (bp->callback) { bp->callback(bp, bp->user_data, SWITCH_ABC_TYPE_CLOSE); + bp->ready = 0; } switch_core_media_bug_destroy(bp); *bug = NULL; @@ -2012,7 +2018,7 @@ switch_media_bug_t *bp; switch_thread_rwlock_rdlock(session->bug_rwlock); 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_buffer_write(bp->raw_read_buffer, read_frame->data, read_frame->datalen); if (bp->callback) { @@ -2249,6 +2255,9 @@ switch_media_bug_t *bp; switch_thread_rwlock_rdlock(session->bug_rwlock); for (bp = session->bugs; bp; bp = bp->next) { + if (!bp->ready) { + continue; + } if (switch_test_flag(bp, SMBF_WRITE_STREAM)) { switch_mutex_lock(bp->write_mutex); switch_buffer_write(bp->raw_write_buffer, write_frame->data, write_frame->datalen); Modified: freeswitch/trunk/src/switch_ivr.c ============================================================================== --- freeswitch/trunk/src/switch_ivr.c (original) +++ freeswitch/trunk/src/switch_ivr.c Fri Feb 2 16:01:13 2007 @@ -551,7 +551,10 @@ case SWITCH_ABC_TYPE_INIT: break; case SWITCH_ABC_TYPE_CLOSE: - switch_core_file_close(fh); + if (fh) { + switch_core_file_close(fh); + } + break; case SWITCH_ABC_TYPE_READ: if (fh) { switch_size_t len; @@ -767,11 +770,13 @@ } break; - case SWITCH_ABC_TYPE_CLOSE: + case SWITCH_ABC_TYPE_CLOSE: { switch_core_asr_close(sth->ah, &flags); switch_mutex_lock(sth->mutex); switch_thread_cond_signal(sth->cond); switch_mutex_unlock(sth->mutex); + } + break; case SWITCH_ABC_TYPE_READ: if (sth->ah) { if (switch_core_media_bug_read(bug, &frame) == SWITCH_STATUS_SUCCESS) {