adding MG_FAX_NOTIFIED flag to notify only one fax event(ced or cng) per call to mgc

This commit is contained in:
Kapil Gupta 2012-09-06 17:14:42 -04:00
parent e3de0a5c70
commit fbfdfc1591
4 changed files with 85 additions and 64 deletions

View File

@ -172,54 +172,30 @@ switch_status_t megaco_activate_termination(mg_termination_t *term)
term->uuid = NULL;
}
if (zstr(term->uuid)) {
switch_channel_t *channel;
if (switch_ivr_originate(NULL, &session, &cause, dialstring, 0, NULL, NULL, NULL, NULL, var_event, 0, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to instanciate termination [%s]: %s\n", term->name, switch_channel_cause2str(cause));
status = SWITCH_STATUS_FALSE;
goto done;
}
if (zstr(term->uuid)) {
switch_channel_t *channel;
if (switch_ivr_originate(NULL, &session, &cause, dialstring, 0, NULL, NULL, NULL, NULL, var_event, 0, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to instanciate termination [%s]: %s\n", term->name, switch_channel_cause2str(cause));
status = SWITCH_STATUS_FALSE;
goto done;
}
term->uuid = switch_core_strdup(term->pool, switch_core_session_get_uuid(session));
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Termination [%s] successfully instanciated as [%s] [%s]\n", term->name, dialstring, switch_core_session_get_uuid(session));
channel = switch_core_session_get_channel(session);
switch_channel_set_private(channel, PVT_MG_TERM, term);
term->uuid = switch_core_strdup(term->pool, switch_core_session_get_uuid(session));
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Termination [%s] successfully instanciated as [%s] [%s]\n", term->name, dialstring, switch_core_session_get_uuid(session));
channel = switch_core_session_get_channel(session);
switch_channel_set_private(channel, PVT_MG_TERM, term);
if (term->type == MG_TERM_RTP && term->u.rtp.t38_options) {
switch_channel_set_private(channel, "t38_options", term->u.rtp.t38_options);
}
if (term->type == MG_TERM_RTP && term->u.rtp.t38_options) {
switch_channel_set_private(channel, "t38_options", term->u.rtp.t38_options);
}
switch_core_event_hook_add_recv_dtmf(session, mg_on_dtmf);
switch_core_event_hook_add_recv_dtmf(session, mg_on_dtmf);
if (term->type == MG_TERM_TDM){
switch_core_session_execute_application_async(session, "spandsp_start_fax_detect", "mg_notify ced 120 ced");
switch_core_session_execute_application_async(session, "spandsp_start_fax_detect", "mg_notify cng 120 cng");
}
if ((term->type == MG_TERM_TDM) && (term->profile)){
switch(term->profile->fax_detect_evt_type){
case MG_FAX_DETECT_EVENT_TYPE_CED:
{
switch_core_session_execute_application_async(session, "spandsp_start_fax_detect", "mg_notify ced 120 ced");
break;
}
case MG_FAX_DETECT_EVENT_TYPE_CNG:
{
switch_core_session_execute_application_async(session, "spandsp_start_fax_detect", "mg_notify cng 120 cng");
break;
}
case MG_FAX_DETECT_EVENT_TYPE_CNG_CED:
{
switch_core_session_execute_application_async(session, "spandsp_start_fax_detect", "mg_notify cng 120 cng");
switch_core_session_execute_application_async(session, "spandsp_start_fax_detect", "mg_notify ced 120 ced");
break;
}
case MG_FAX_DETECT_EVENT_TYPE_DISABLE:
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "FAX detection Disable\n");
break;
}
default:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid FAX detection Event[%d]\n",term->profile->fax_detect_evt_type);
break;
}
}
}
}
switch_set_flag(term, MGT_ACTIVE);
@ -419,6 +395,7 @@ void megaco_termination_destroy(mg_termination_t *term)
switch_clear_flag(term, MGT_ALLOCATED);
switch_clear_flag(term, MGT_ACTIVE);
switch_clear_flag(term, MG_FAX_NOTIFIED);
if (term->type == MG_TERM_RTP) {
switch_core_hash_delete_wrlock(term->profile->terminations, term->name, term->profile->terminations_rwlock);
@ -757,8 +734,9 @@ switch_status_t mgco_init_ins_service_change(SuId suId)
for (hi = switch_hash_first(NULL, profile->terminations); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, &key, &keylen, &val);
term = (mg_termination_t *) val;
if(!term) continue;
megaco_check_tdm_termination(term);
if(!term) continue;
if(MG_TERM_RTP == term->type) continue;
megaco_check_tdm_termination(term);
}
return SWITCH_STATUS_SUCCESS;

View File

@ -71,7 +71,8 @@ switch_status_t config_profile(megaco_profile_t *profile, switch_bool_t reload)
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,"rtp_ipaddr[%s], local ip[%s]\n", profile->rtp_ipaddr, profile->my_ipaddr);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,"fax_detect_evt_type[%s]\n", mg_fax_detect_evt_type2str(profile->fax_detect_evt_type));
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,"t38_fax_notify[%s]\n",
(MG_T38_FAX_NOTIFY_YES == profile->t38_fax_notify)?"ENABLE":"DISABLE");
if(SWITCH_STATUS_FALSE == (status = modify_mg_profile_mid(profile, &profile->mid))){
goto done;
@ -252,6 +253,7 @@ void mg_create_tdm_term(megaco_profile_t *profile, const char *tech, const char
term->u.tdm.channel = tdm_chan_num;
term->u.tdm.span_name = switch_core_strdup(pool, channel_prefix);
switch_set_flag(term, MG_OUT_OF_SERVICE);
switch_clear_flag(term, MG_FAX_NOTIFIED);
switch_core_hash_insert_wrlock(profile->terminations, term->name, term, profile->terminations_rwlock);
term->next = profile->physical_terminations;
@ -337,13 +339,19 @@ static switch_xml_config_item_t *get_instructions(megaco_profile_t *profile) {
{ "G.723.1", MEGACO_CODEC_G723_1},
{ "ILBC", MEGACO_CODEC_ILBC },
};
#endif
static switch_xml_config_enum_item_t opt_fax_detect_type_enum[] = {
{ "CED", MG_FAX_DETECT_EVENT_TYPE_CED},
{ "CNG", MG_FAX_DETECT_EVENT_TYPE_CNG},
{ "CED_CNG", MG_FAX_DETECT_EVENT_TYPE_CNG_CED},
{ "DISABLE", MG_FAX_DETECT_EVENT_TYPE_DISABLE},
};
#endif
static switch_xml_config_enum_item_t opt_t38_fax_notify[] = {
{ "ENABLE", MG_T38_FAX_NOTIFY_YES},
{ "DISABLE", MG_T38_FAX_NOTIFY_NO},
};
switch_xml_config_item_t instructions[] = {
@ -363,7 +371,8 @@ static switch_xml_config_item_t *get_instructions(megaco_profile_t *profile) {
SWITCH_CONFIG_ITEM("codec-prefs", SWITCH_CONFIG_STRING, 0, &profile->codec_prefs, "", &switch_config_string_strdup, "", "codec preferences, coma-separated"),
SWITCH_CONFIG_ITEM("license", SWITCH_CONFIG_STRING, 0, &profile->license, "/usr/local/nsg/conf/license.txt", &switch_config_string_strdup, "", "License file"),
SWITCH_CONFIG_ITEM("rtp-ip", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &profile->rtp_ipaddr, "" , &switch_config_string_strdup, "", "rtp ip"),
SWITCH_CONFIG_ITEM("fax-detect-event-type", SWITCH_CONFIG_ENUM, CONFIG_RELOADABLE, &profile->fax_detect_evt_type, MG_FAX_DETECT_EVENT_TYPE_CNG_CED , &opt_fax_detect_type_enum, "", "fax-detect-event-type"),
//SWITCH_CONFIG_ITEM("fax-detect-event-type", SWITCH_CONFIG_ENUM, CONFIG_RELOADABLE, &profile->fax_detect_evt_type, MG_FAX_DETECT_EVENT_TYPE_CNG_CED , &opt_fax_detect_type_enum, "", "fax-detect-event-type"),
SWITCH_CONFIG_ITEM("t38-fax-notify", SWITCH_CONFIG_ENUM, CONFIG_RELOADABLE, &profile->t38_fax_notify, MG_T38_FAX_NOTIFY_YES , &opt_t38_fax_notify, "", "t38_fax_notify"),
SWITCH_CONFIG_ITEM_END()
};

View File

@ -36,17 +36,42 @@ SWITCH_STANDARD_APP(mg_notify_function)
return;
}
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");
/* Disable echo cancellation */
mg_term_set_ec(term, 0);
} 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");
/* Disable echo cancellation */
mg_term_set_ec(term, 0);
}
if (!strcmp(data, "cng")) {
if((term->profile) &&
(term->profile->t38_fax_notify == MG_T38_FAX_NOTIFY_YES) &&
!switch_test_flag(term, MG_FAX_NOTIFIED)){
switch_set_flag(term, MG_FAX_NOTIFIED);
mg_send_t38_cng_notify(term->profile, term->name);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Sent CNG notify\n");
}else{
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Not reporting CNG tone "
"FAX Notify[%s] MG_FAX_NOTIFIED flag [%s]\n",
(MG_T38_FAX_NOTIFY_YES == term->profile->t38_fax_notify)?"ENABLE":"DISABLE",
(switch_test_flag(term, MG_FAX_NOTIFIED))?"TRUE":"FALSE");
}
/* Disable echo cancellation */
if(MG_TERM_TDM == term->type){
mg_term_set_ec(term, 0);
}
} else if (!strcmp(data, "ced")) {
if((term->profile) &&
(term->profile->t38_fax_notify == MG_T38_FAX_NOTIFY_YES) &&
!switch_test_flag(term, MG_FAX_NOTIFIED)){
switch_set_flag(term, MG_FAX_NOTIFIED);
mg_send_t38_ans_notify(term->profile, term->name);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Sent CED notify\n");
}else{
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Not reporting CED tone "
"FAX Notify[%s] MG_FAX_NOTIFIED flag [%s]\n",
(MG_T38_FAX_NOTIFY_YES == term->profile->t38_fax_notify)?"ENABLE":"DISABLE",
(switch_test_flag(term, MG_FAX_NOTIFIED))?"TRUE":"FALSE");
}
if(MG_TERM_TDM == term->type){
mg_term_set_ec(term, 0);
}
}
}
static switch_status_t console_complete_hashtable(switch_hash_t *hash, const char *line, const char *cursor, switch_console_callback_match_t **matches)

View File

@ -119,10 +119,19 @@ enum {
MGT_ACTIVE = (1 << 1),
MG_IN_SERVICE = (1 << 2),
MG_OUT_OF_SERVICE = (1 << 3),
MG_FAX_NOTIFIED = (1 << 4),
} mg_termination_flags;
typedef enum {
MG_T38_FAX_NOTIFY_NONE,
MG_T38_FAX_NOTIFY_YES,
MG_T38_FAX_NOTIFY_NO,
MG_T38_FAX_NOTIFY_INVALID,
} mg_t38_fax_notify_t;
typedef enum {
MGM_AUDIO = 0,
MGM_IMAGE,
@ -257,7 +266,7 @@ struct megaco_profile_s {
int inact_tmr; /* inactivity timer value */
int peer_active; /* inactivity timer value */
uint32_t inact_tmr_task_id; /* FS timer scheduler task-id */
mg_fax_detect_event_type_t fax_detect_evt_type;
mg_t38_fax_notify_t t38_fax_notify;
switch_thread_rwlock_t *contexts_rwlock;
uint32_t next_context_id;