{
switch_io_event_hook_read_frame_t *ptr;
switch_status_t status = SWITCH_STATUS_FALSE;
- int need_codec, perfect, do_bugs = 0, do_resample = 0, is_cng = 0, tap_only = 0;
+ int need_codec, perfect, bug_locked = 0, global_prune = 0, do_bugs = 0, do_resample = 0, is_cng = 0, tap_only = 0;
switch_codec_implementation_t codec_impl;
unsigned int flag = 0;
int i;
switch_mutex_lock(session->read_codec->mutex);
+ switch_thread_rwlock_rdlock(session->bug_rwlock);
+ if (session->bugs) {
+ bug_locked = 1;
+ } else {
+ switch_thread_rwlock_unlock(session->bug_rwlock);
+ }
+
top:
for(i = 0; i < 2; i++) {
switch_bool_t ok = SWITCH_TRUE;
int prune = 0;
- switch_thread_rwlock_rdlock(session->bug_rwlock);
-
for (bp = session->bugs; bp; bp = bp->next) {
ok = SWITCH_TRUE;
prune++;
}
}
- switch_thread_rwlock_unlock(session->bug_rwlock);
if (prune) {
- switch_core_media_bug_prune(session);
+ global_prune++;
}
}
int prune = 0;
if (session->bugs && switch_test_flag((*frame), SFF_CNG)) {
- switch_thread_rwlock_rdlock(session->bug_rwlock);
for (bp = session->bugs; bp; bp = bp->next) {
ok = SWITCH_TRUE;
prune++;
}
}
- switch_thread_rwlock_unlock(session->bug_rwlock);
if (prune) {
- switch_core_media_bug_prune(session);
+ global_prune++;
}
} else {
switch_codec_t *use_codec = read_frame->codec;
if (do_bugs) {
- switch_thread_rwlock_wrlock(session->bug_rwlock);
- if (!session->bugs) {
- switch_thread_rwlock_unlock(session->bug_rwlock);
- goto done;
- }
-
if (!switch_core_codec_ready(&session->bug_codec) && switch_core_codec_ready(read_frame->codec)) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Setting BUG Codec %s:%d\n",
read_frame->codec->implementation->iananame, read_frame->codec->implementation->ianacode);
if (switch_core_codec_ready(&session->bug_codec)) {
use_codec = &session->bug_codec;
}
- switch_thread_rwlock_unlock(session->bug_rwlock);
-
- switch_thread_rwlock_wrlock(session->bug_rwlock);
- if (!session->bugs) {
- do_bugs = 0;
- }
- switch_thread_rwlock_unlock(session->bug_rwlock);
- if (!do_bugs) goto done;
}
if (!switch_test_flag(read_frame->codec, SWITCH_CODEC_FLAG_HAS_PLC) &&
codec = read_frame->codec;
}
- switch_thread_rwlock_rdlock(session->bug_rwlock);
codec->cur_frame = read_frame;
session->read_codec->cur_frame = read_frame;
status = switch_core_codec_decode(codec,
session->raw_read_frame.channels = codec->implementation->number_of_channels;
codec->cur_frame = NULL;
session->read_codec->cur_frame = NULL;
- switch_thread_rwlock_unlock(session->bug_rwlock);
-
}
if (status == SWITCH_STATUS_SUCCESS && session->read_impl.number_of_channels == 1) {
switch_media_bug_t *bp;
switch_bool_t ok = SWITCH_TRUE;
int prune = 0;
- switch_thread_rwlock_rdlock(session->bug_rwlock);
for (bp = session->bugs; bp; bp = bp->next) {
ok = SWITCH_TRUE;
}
- switch_thread_rwlock_unlock(session->bug_rwlock);
+
if (prune) {
- switch_core_media_bug_prune(session);
+ global_prune++;
}
}
switch_media_bug_t *bp;
switch_bool_t ok = SWITCH_TRUE;
int prune = 0;
- switch_thread_rwlock_rdlock(session->bug_rwlock);
for (bp = session->bugs; bp; bp = bp->next) {
ok = SWITCH_TRUE;
prune++;
}
}
- switch_thread_rwlock_unlock(session->bug_rwlock);
+
if (prune) {
- switch_core_media_bug_prune(session);
+ global_prune++;
}
}
switch_media_bug_t *bp;
switch_bool_t ok = SWITCH_TRUE;
int prune = 0;
- switch_thread_rwlock_rdlock(session->bug_rwlock);
+
for (bp = session->bugs; bp; bp = bp->next) {
ok = SWITCH_TRUE;
prune++;
}
}
- switch_thread_rwlock_unlock(session->bug_rwlock);
+
if (prune) {
- switch_core_media_bug_prune(session);
+ global_prune++;
}
}
}
*frame = &runtime.dummy_cng_frame;
}
+ if (global_prune) {
+ switch_core_media_bug_prune(session);
+ }
+
+ if (bug_locked) {
+ switch_thread_rwlock_unlock(session->bug_rwlock);
+ }
+
switch_mutex_unlock(session->read_codec->mutex);
switch_mutex_unlock(session->codec_read_mutex);