From 6f9be6bf5a31ed3b49a47f5262967fcaa801de94 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 2 Feb 2007 21:01:13 +0000 Subject: [PATCH] bug in the bugs git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4109 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/switch_core.c | 11 ++++++++++- src/switch_ivr.c | 9 +++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/switch_core.c b/src/switch_core.c index f57648086f..c5363cf1b9 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -67,6 +67,7 @@ struct switch_media_bug { switch_core_session_t *session; void *user_data; uint32_t flags; + uint8_t ready; 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->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 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove(switch_core_session 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 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove(switch_core_session 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_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi 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_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess 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); diff --git a/src/switch_ivr.c b/src/switch_ivr.c index 0e08a3bf51..8307e12d06 100644 --- a/src/switch_ivr.c +++ b/src/switch_ivr.c @@ -551,7 +551,10 @@ static void record_callback(switch_media_bug_t *bug, void *user_data, switch_abc 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 @@ static void speech_callback(switch_media_bug_t *bug, void *user_data, switch_abc } 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) {