diff --git a/src/include/switch_types.h b/src/include/switch_types.h index c4c2ed7190..b766d1db40 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -1249,6 +1249,7 @@ typedef enum { CF_TRACKABLE, CF_NO_CDR, CF_EARLY_OK, + CF_MEDIA_TRANS, /* WARNING: DO NOT ADD ANY FLAGS BELOW THIS LINE */ /* IF YOU ADD NEW ONES CHECK IF THEY SHOULD PERSIST OR ZERO THEM IN switch_core_session.c switch_core_session_request_xml() */ CF_FLAG_MAX diff --git a/src/switch_ivr.c b/src/switch_ivr.c index b6c1127b31..b8fd0923e3 100644 --- a/src/switch_ivr.c +++ b/src/switch_ivr.c @@ -1476,6 +1476,13 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_media(const char *uuid, switch_media_ if ((session = switch_core_session_locate(uuid))) { channel = switch_core_session_get_channel(session); + + if (switch_channel_test_flag(channel, CF_MEDIA_TRANS)) { + switch_core_session_rwunlock(session); + return SWITCH_STATUS_INUSE; + } + + switch_channel_set_flag(channel, CF_MEDIA_TRANS); if ((flags & SMF_REBRIDGE) && !switch_channel_test_flag(channel, CF_BRIDGE_ORIGINATOR)) { swap = 1; @@ -1527,6 +1534,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_media(const char *uuid, switch_media_ } } + switch_channel_clear_flag(channel, CF_MEDIA_TRANS); switch_core_session_rwunlock(session); if (other_channel) { @@ -1559,6 +1567,13 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_nomedia(const char *uuid, switch_medi status = SWITCH_STATUS_SUCCESS; channel = switch_core_session_get_channel(session); + if (switch_channel_test_flag(channel, CF_MEDIA_TRANS)) { + switch_core_session_rwunlock(session); + return SWITCH_STATUS_INUSE; + } + + switch_channel_set_flag(channel, CF_MEDIA_TRANS); + if ((flags & SMF_REBRIDGE) && !switch_channel_test_flag(channel, CF_BRIDGE_ORIGINATOR)) { swap = 1; } @@ -1617,9 +1632,12 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_nomedia(const char *uuid, switch_medi switch_core_session_rwunlock(other_session); } } - switch_core_session_rwunlock(session); + + switch_channel_clear_flag(channel, CF_MEDIA_TRANS); } + + return status; }