switch_media_bug_t *bug, *bp;
switch_size_t bytes;
switch_event_t *event;
- int tap_only = 1, punt = 0;
+ int tap_only = 1, punt = 0, added = 0;
const char *p;
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Attaching BUG to %s\n", switch_channel_get_name(session->channel));
switch_thread_rwlock_wrlock(session->bug_rwlock);
- bug->next = session->bugs;
- session->bugs = bug;
+ if (!session->bugs) {
+ session->bugs = bug;
+ added = 1;
+ }
+
for(bp = session->bugs; bp; bp = bp->next) {
if (bp->ready && !switch_test_flag(bp, SMBF_TAP_NATIVE_READ) && !switch_test_flag(bp, SMBF_TAP_NATIVE_WRITE)) {
tap_only = 0;
}
+
+ if (!added && !bp->next) {
+ bp->next = bug;
+ break;
+ }
}
switch_thread_rwlock_unlock(session->bug_rwlock);