{
switch_io_event_hook_read_frame_t *ptr;
switch_status_t status = SWITCH_STATUS_FALSE;
- int need_codec, perfect, bug_locked = 0, global_prune = 0, do_bugs = 0, do_resample = 0, is_cng = 0, tap_only = 0;
+ int need_codec, perfect, do_bugs = 0, do_resample = 0, is_cng = 0, tap_only = 0;
switch_codec_implementation_t codec_impl;
unsigned int flag = 0;
int i;
if (status == SWITCH_STATUS_INUSE) {
*frame = &runtime.dummy_cng_frame;
switch_yield(20000);
- switch_goto_status(SWITCH_STATUS_SUCCESS, bail_out);
+ return SWITCH_STATUS_SUCCESS;
}
if (!SWITCH_READ_ACCEPTABLE(status) || !session->read_codec || !switch_core_codec_ready(session->read_codec)) {
*frame = NULL;
- switch_goto_status(SWITCH_STATUS_FALSE, bail_out);
+ return SWITCH_STATUS_FALSE;
}
switch_mutex_lock(session->codec_read_mutex);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "%s has no read codec.\n", switch_channel_get_name(session->channel));
switch_channel_hangup(session->channel, SWITCH_CAUSE_INCOMPATIBLE_DESTINATION);
*frame = &runtime.dummy_cng_frame;
- switch_goto_status(SWITCH_STATUS_FALSE, bail_out);
+ return SWITCH_STATUS_FALSE;
}
switch_mutex_lock(session->read_codec->mutex);
goto done;
}
- if (!bug_locked) {
- switch_thread_rwlock_rdlock(session->bug_rwlock);
- if (session->bugs) {
- bug_locked = 1;
- } else {
- switch_thread_rwlock_unlock(session->bug_rwlock);
- }
- }
-
if (session->bugs && !((*frame)->flags & SFF_CNG) && !((*frame)->flags & SFF_NOT_AUDIO)) {
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) {
- global_prune++;
+ switch_core_media_bug_prune(session);
}
}
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) {
- global_prune++;
+ switch_core_media_bug_prune(session);
}
} 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) &&
} else {
switch_codec_t *codec = use_codec;
+ switch_thread_rwlock_rdlock(session->bug_rwlock);
+
if (!switch_core_codec_ready(codec)) {
codec = read_frame->codec;
}
+ if (!switch_core_codec_ready(codec)) {
+ switch_thread_rwlock_unlock(session->bug_rwlock);
+ goto done;
+ }
+
codec->cur_frame = read_frame;
session->read_codec->cur_frame = read_frame;
status = switch_core_codec_decode(codec,
session->raw_read_frame.data, &session->raw_read_frame.datalen, &session->raw_read_frame.rate,
&read_frame->flags);
+ if (status == SWITCH_STATUS_NOT_INITALIZED) {
+ switch_thread_rwlock_unlock(session->bug_rwlock);
+ goto done;
+ }
+
session->raw_read_frame.samples = session->raw_read_frame.datalen / 2;
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) {
- global_prune++;
+ switch_core_media_bug_prune(session);
}
}
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) {
- global_prune++;
+ switch_core_media_bug_prune(session);
}
}
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) {
- global_prune++;
+ switch_core_media_bug_prune(session);
}
}
}
switch_channel_set_callstate(session->channel, CCS_ACTIVE);
}
- bail_out:
-
- if (bug_locked) {
- switch_thread_rwlock_unlock(session->bug_rwlock);
- }
-
- if (global_prune) {
- switch_core_media_bug_prune(session);
- }
return status;
}