SWITCH_DECLARE(void) switch_core_session_lock_codec_read(_In_ switch_core_session_t *session);
SWITCH_DECLARE(void) switch_core_session_unlock_codec_read(_In_ switch_core_session_t *session);
+/*!
+ \brief Lock codec read mutex and codec write mutex using trylock in an infinite loop
+ \param session session to lock the codec in
+*/
+SWITCH_DECLARE(void) switch_core_codec_lock_full(switch_core_session_t *session);
+
+/*!
+ \brief Unlock codec read mutex and codec write mutex
+ \param session session to unlock the codec in
+*/
+SWITCH_DECLARE(void) switch_core_codec_unlock_full(switch_core_session_t *session);
SWITCH_DECLARE(switch_status_t) switch_core_session_get_read_impl(switch_core_session_t *session, switch_codec_implementation_t *impp);
SWITCH_DECLARE(switch_status_t) switch_core_session_get_real_read_impl(switch_core_session_t *session, switch_codec_implementation_t *impp);
if (msg->message_id == SWITCH_MESSAGE_INDICATE_SIGNAL_DATA) {
sofia_dispatch_event_t *de = (sofia_dispatch_event_t *) msg->pointer_arg;
+
+ switch_core_session_lock_codec_write(session);
switch_mutex_lock(tech_pvt->sofia_mutex);
if (switch_core_session_in_thread(session)) {
de->session = session;
sofia_process_dispatch_event(&de);
-
switch_mutex_unlock(tech_pvt->sofia_mutex);
+ switch_core_session_unlock_codec_write(session);
goto end;
}
/* ones that do not need to lock sofia mutex */
switch (msg->message_id) {
+ case SWITCH_MESSAGE_INDICATE_TRANSCODING_NECESSARY:
+ case SWITCH_MESSAGE_RESAMPLE_EVENT:
+ goto end;
case SWITCH_MESSAGE_INDICATE_KEEPALIVE:
{
if (msg->numeric_arg) {
}
/* ones that do need to lock sofia mutex */
+ switch_core_session_lock_codec_write(session);
switch_mutex_lock(tech_pvt->sofia_mutex);
if (switch_channel_down(channel) || sofia_test_flag(tech_pvt, TFLAG_BYE)) {
tech_pvt->proxy_refer_uuid = (char *)msg->string_array_arg[0];
} else if (!switch_channel_var_true(tech_pvt->channel, "sip_refer_continue_after_reply")) {
switch_mutex_unlock(tech_pvt->sofia_mutex);
+ switch_core_session_unlock_codec_write(session);
sofia_wait_for_reply(tech_pvt, 9999, 10);
+ switch_core_session_lock_codec_write(session);
switch_mutex_lock(tech_pvt->sofia_mutex);
if ((var = switch_channel_get_variable(tech_pvt->channel, "sip_refer_reply"))) {
/* Unlock the session signal to allow the ack to make it in */
// Maybe we should timeout?
switch_mutex_unlock(tech_pvt->sofia_mutex);
+ switch_core_session_unlock_codec_write(session);
while (switch_channel_ready(channel) && !sofia_test_flag(tech_pvt, TFLAG_3PCC_HAS_ACK)) {
switch_ivr_parse_all_events(session);
}
/* Regain lock on sofia */
+ switch_core_session_lock_codec_write(session);
switch_mutex_lock(tech_pvt->sofia_mutex);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "3PCC-PROXY, Done waiting for ACK\n");
//}
switch_mutex_unlock(tech_pvt->sofia_mutex);
+ switch_core_session_unlock_codec_write(session);
end:
switch_mutex_unlock(session->codec_read_mutex);
}
+SWITCH_DECLARE(void) switch_core_codec_lock_full(switch_core_session_t *session)
+{
+ do {
+ if (switch_mutex_trylock(session->codec_write_mutex) == SWITCH_STATUS_SUCCESS) {
+ if (switch_mutex_trylock(session->codec_read_mutex) == SWITCH_STATUS_SUCCESS) {
+ return;
+ }
+
+ switch_mutex_unlock(session->codec_write_mutex);
+ }
+
+ switch_cond_next();
+ } while (1);
+}
+
+SWITCH_DECLARE(void) switch_core_codec_unlock_full(switch_core_session_t *session)
+{
+ switch_mutex_unlock(session->codec_read_mutex);
+ switch_mutex_unlock(session->codec_write_mutex);
+}
+
SWITCH_DECLARE(void) switch_core_session_lock_codec_write(switch_core_session_t *session)
{
switch_mutex_lock(session->codec_write_mutex);
switch_assert(session);
- switch_core_session_lock_codec_write(session);
- switch_core_session_lock_codec_read(session);
+ switch_core_codec_lock_full(session);
switch_mutex_lock(session->codec_init_mutex);
switch_mutex_unlock(session->codec_init_mutex);
- switch_core_session_unlock_codec_read(session);
- switch_core_session_unlock_codec_write(session);
+ switch_core_codec_unlock_full(session);
return status;
}
{
switch_channel_t *channel = switch_core_session_get_channel(session);
+ switch_core_codec_lock_full(session);
+
if (reset_read_codec) {
switch_core_session_set_read_codec(session, NULL);
if (session->sdata && switch_core_codec_ready(&session->sdata->codec)) {
switch_clear_flag(session, SSF_WARN_TRANSCODE);
switch_ivr_deactivate_unicast(session);
switch_channel_clear_flag(channel, CF_BREAK);
+
+ switch_core_codec_unlock_full(session);
}