diff --git a/configure.in b/configure.in index 83cb414..8bd1e01 100644 diff --git a/libs/freetdm/mod_freetdm/tdm.c b/libs/freetdm/mod_freetdm/tdm.c index 1b401d3..7fcdf03 100644 --- a/libs/freetdm/mod_freetdm/tdm.c +++ b/libs/freetdm/mod_freetdm/tdm.c @@ -40,6 +40,7 @@ void ctdm_init(switch_loadable_module_interface_t *module_interface); #define kCHAN_ID "chan" #define kSPAN_NAME "span_name" #define kPREBUFFER_LEN "prebuffer_len" +#define kDISABLE_ECHOCANCEL "disable_ec" static struct { switch_memory_pool_t *pool; @@ -485,7 +486,8 @@ static switch_status_t channel_on_destroy(switch_core_session_t *session) switch_core_codec_destroy(&tech_pvt->write_codec); } - ftdm_channel_close(&tech_pvt->ftdm_channel); + ftdm_channel_command(tech_pvt->ftdm_channel, FTDM_COMMAND_ENABLE_ECHOCANCEL, NULL); + ftdm_channel_close(&tech_pvt->ftdm_channel); } return SWITCH_STATUS_SUCCESS; @@ -651,7 +653,9 @@ static switch_status_t channel_receive_event(switch_core_session_t *session, swi } } } - + if (!zstr(command) && !strcasecmp(command, kDISABLE_ECHOCANCEL)) { + ftdm_channel_command(tech_pvt->ftdm_channel, FTDM_COMMAND_DISABLE_ECHOCANCEL, NULL); + } return SWITCH_STATUS_SUCCESS; } diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway.c b/src/mod/endpoints/mod_media_gateway/media_gateway.c index f1abe47..03e8ffe 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway.c @@ -368,10 +368,10 @@ void megaco_termination_destroy(mg_termination_t *term) switch_channel_t *channel; if ((session = switch_core_session_locate(term->uuid))) { - channel = switch_core_session_get_channel(session); - switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); - switch_core_session_rwunlock(session); - term->uuid = NULL; + channel = switch_core_session_get_channel(session); + switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); + switch_core_session_rwunlock(session); + term->uuid = NULL; } if (term->type == MG_TERM_RTP && term->u.rtp.local_port != 0) { @@ -761,6 +761,33 @@ void mg_term_set_pre_buffer_size(mg_termination_t *term, int newval) switch_event_destroy(&event); } +void mg_term_echocancel_disable(mg_termination_t *term) +{ + switch_event_t *event = NULL, *event2 = NULL; + switch_core_session_t *session, *session2; + + if (!zstr(term->uuid) && (session = switch_core_session_locate(term->uuid))) { + switch_event_create(&event, SWITCH_EVENT_CLONE); + + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "command", kDISABLE_ECHOCANCEL); + + /* Propagate event to bridged session if there is one */ + if (switch_core_session_get_partner(session, &session2) == SWITCH_STATUS_SUCCESS) { + switch_event_dup(&event2, event); + switch_core_session_receive_event(session2, &event2); + switch_core_session_rwunlock(session2); + } + + switch_core_session_receive_event(session, &event); + switch_core_session_rwunlock(session); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Sent DISABLE_ECHOCANCEL event to [%s]\n", + term->uuid); + } + + switch_event_destroy(&event); +} + /* For Emacs: * Local Variables: * mode:c diff --git a/src/mod/endpoints/mod_media_gateway/mod_media_gateway.c b/src/mod/endpoints/mod_media_gateway/mod_media_gateway.c index a905a44..581bdc4 100644 --- a/src/mod/endpoints/mod_media_gateway/mod_media_gateway.c +++ b/src/mod/endpoints/mod_media_gateway/mod_media_gateway.c @@ -39,9 +39,11 @@ SWITCH_STANDARD_APP(mg_notify_function) if (!strcmp(data, "cng")) { mg_send_t38_cng_notify(term->profile, term->name); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Sent CNG notify\n"); + mg_term_echocancel_disable(term); } else if (!strcmp(data, "ced")) { - mg_send_t38_ans_notify(term->profile, term->name); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Sent CED notify\n"); + mg_send_t38_ans_notify(term->profile, term->name); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Sent CED notify\n"); + mg_term_echocancel_disable(term); } } diff --git a/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h b/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h index 15f1cf7..9d8bdc9 100644 --- a/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h +++ b/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h @@ -88,6 +88,7 @@ typedef struct mg_context_s mg_context_t; #define kCHAN_ID "chan" #define kSPAN_NAME "span_name" #define kPREBUFFER_LEN "prebuffer_len" +#define kDISABLE_ECHOCANCEL "disable_ec" typedef struct mg_termination_s mg_termination_t; @@ -269,6 +270,8 @@ switch_status_t megaco_profile_destroy(megaco_profile_t **profile); uint32_t mg_rtp_request_id(megaco_profile_t *profile); void mg_rtp_release_id(megaco_profile_t *profile, uint32_t id); void mg_term_set_pre_buffer_size(mg_termination_t *term, int newval); +void mg_term_echocancel_disable(mg_termination_t *term); + mg_context_t *megaco_get_context(megaco_profile_t *profile, uint32_t context_id); mg_context_t *megaco_choose_context(megaco_profile_t *profile);