diff --git a/src/include/switch_rtp.h b/src/include/switch_rtp.h index 67e0f324d3..92b5386fd8 100644 --- a/src/include/switch_rtp.h +++ b/src/include/switch_rtp.h @@ -75,7 +75,7 @@ SWITCH_DECLARE(switch_port_t) switch_rtp_set_end_port(switch_port_t port); \return the new port to use */ SWITCH_DECLARE(switch_port_t) switch_rtp_request_port(const char *ip); - +SWITCH_DECLARE(void) switch_rtp_release_port(const char *ip, switch_port_t port); /*! \brief create a new RTP session handle \param new_rtp_session a poiter to aim at the new session diff --git a/src/mod/endpoints/mod_dingaling/mod_dingaling.c b/src/mod/endpoints/mod_dingaling/mod_dingaling.c index 3bd376793f..97b79561f4 100644 --- a/src/mod/endpoints/mod_dingaling/mod_dingaling.c +++ b/src/mod/endpoints/mod_dingaling/mod_dingaling.c @@ -687,6 +687,11 @@ static void terminate_session(switch_core_session_t **session, int line, switch_ tech_pvt = switch_core_session_get_private(*session); + + if (tech_pvt->profile->ip && tech_pvt->local_port) { + switch_rtp_release_port(tech_pvt->profile->ip, tech_pvt->local_port); + } + if (!switch_core_session_running(*session) && (!tech_pvt || !switch_test_flag(tech_pvt, TFLAG_READY))) { switch_core_session_destroy(session); return; @@ -1209,6 +1214,10 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) tech_pvt = switch_core_session_get_private(session); switch_assert(tech_pvt != NULL); + if (tech_pvt->profile->ip && tech_pvt->local_port) { + switch_rtp_release_port(tech_pvt->profile->ip, tech_pvt->local_port); + } + switch_clear_flag_locked(tech_pvt, TFLAG_IO); switch_clear_flag_locked(tech_pvt, TFLAG_VOICE); switch_set_flag_locked(tech_pvt, TFLAG_BYE); diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 3f281bcaf0..b209ea226a 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -201,7 +201,10 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session) tech_pvt = (private_object_t *) switch_core_session_get_private(session); switch_assert(tech_pvt != NULL); - + + if (tech_pvt->profile->rtpip && tech_pvt->local_sdp_audio_port) { + switch_rtp_release_port(tech_pvt->profile->rtpip, tech_pvt->local_sdp_audio_port); + } if (switch_test_flag(tech_pvt, TFLAG_SIP_HOLD)) { const char *buuid; diff --git a/src/switch_rtp.c b/src/switch_rtp.c index 170f88142e..5fd76cc45d 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -316,16 +316,16 @@ SWITCH_DECLARE(switch_port_t) switch_rtp_set_end_port(switch_port_t port) return END_PORT; } -static void release_port(const char *host, switch_port_t port) +SWITCH_DECLARE(void) switch_rtp_release_port(const char *ip, switch_port_t port) { switch_core_port_allocator_t *alloc = NULL; - if (!host) { + if (!ip) { return; } switch_mutex_lock(port_lock); - if ((alloc = switch_core_hash_find(alloc_hash, host))) { + if ((alloc = switch_core_hash_find(alloc_hash, ip))) { switch_core_port_allocator_free_port(alloc, port); } switch_mutex_unlock(port_lock); @@ -634,7 +634,7 @@ SWITCH_DECLARE(switch_rtp_t *) switch_rtp_new(const char *rx_host, rtp_session->rx_host = switch_core_strdup(rtp_session->pool, rx_host); rtp_session->rx_port = rx_port; } else { - release_port(rx_host, rx_port); + switch_rtp_release_port(rx_host, rx_port); } return rtp_session; @@ -731,7 +731,7 @@ SWITCH_DECLARE(void) switch_rtp_destroy(switch_rtp_t **rtp_session) switch_core_timer_destroy(&(*rtp_session)->timer); } - release_port((*rtp_session)->rx_host, (*rtp_session)->rx_port); + switch_rtp_release_port((*rtp_session)->rx_host, (*rtp_session)->rx_port); switch_mutex_unlock((*rtp_session)->flag_mutex); return;