prevent race while changing codecs mid call
This commit is contained in:
parent
3501087b4d
commit
7aa72b67df
|
@ -2673,6 +2673,7 @@ switch_status_t sofia_glue_tech_set_codec(private_object_t *tech_pvt, int force)
|
||||||
switch_core_session_lock_codec_write(tech_pvt->session);
|
switch_core_session_lock_codec_write(tech_pvt->session);
|
||||||
switch_core_session_lock_codec_read(tech_pvt->session);
|
switch_core_session_lock_codec_read(tech_pvt->session);
|
||||||
resetting = 1;
|
resetting = 1;
|
||||||
|
switch_yield(tech_pvt->read_impl.microseconds_per_packet);
|
||||||
switch_core_codec_destroy(&tech_pvt->read_codec);
|
switch_core_codec_destroy(&tech_pvt->read_codec);
|
||||||
switch_core_codec_destroy(&tech_pvt->write_codec);
|
switch_core_codec_destroy(&tech_pvt->write_codec);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -110,6 +110,15 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
|
||||||
|
|
||||||
switch_assert(session != NULL);
|
switch_assert(session != NULL);
|
||||||
|
|
||||||
|
|
||||||
|
if (switch_mutex_trylock(session->codec_read_mutex) == SWITCH_STATUS_SUCCESS) {
|
||||||
|
switch_mutex_unlock(session->codec_read_mutex);
|
||||||
|
} else {
|
||||||
|
switch_cond_next();
|
||||||
|
*frame = &runtime.dummy_cng_frame;
|
||||||
|
return SWITCH_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
if (!(session->read_codec && session->read_codec->implementation && switch_core_codec_ready(session->read_codec))) {
|
if (!(session->read_codec && session->read_codec->implementation && switch_core_codec_ready(session->read_codec))) {
|
||||||
if (switch_channel_test_flag(session->channel, CF_PROXY_MODE) || switch_channel_get_state(session->channel) == CS_HIBERNATE) {
|
if (switch_channel_test_flag(session->channel, CF_PROXY_MODE) || switch_channel_get_state(session->channel) == CS_HIBERNATE) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "%s reading on a session with no media!\n",
|
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "%s reading on a session with no media!\n",
|
||||||
|
@ -641,12 +650,19 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
|
||||||
return SWITCH_STATUS_FALSE;
|
return SWITCH_STATUS_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (switch_mutex_trylock(session->codec_write_mutex) == SWITCH_STATUS_SUCCESS) {
|
||||||
|
switch_mutex_unlock(session->codec_write_mutex);
|
||||||
|
} else {
|
||||||
|
return SWITCH_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
if (switch_test_flag(frame, SFF_CNG)) {
|
if (switch_test_flag(frame, SFF_CNG)) {
|
||||||
if (switch_channel_test_flag(session->channel, CF_ACCEPT_CNG)) {
|
if (switch_channel_test_flag(session->channel, CF_ACCEPT_CNG)) {
|
||||||
pass_cng = 1;
|
pass_cng = 1;
|
||||||
}
|
} else {
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!(session->write_codec && switch_core_codec_ready(session->write_codec)) && !pass_cng) {
|
if (!(session->write_codec && switch_core_codec_ready(session->write_codec)) && !pass_cng) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "%s has no write codec.\n", switch_channel_get_name(session->channel));
|
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "%s has no write codec.\n", switch_channel_get_name(session->channel));
|
||||||
|
|
Loading…
Reference in New Issue