switch_core_session_t *session;
void *user_data;
uint32_t flags;
+ uint8_t ready;
struct switch_media_bug *next;
};
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;
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;
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;
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) {
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);
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;
}
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) {