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

@ -190,35 +190,11 @@ switch_status_t megaco_activate_termination(mg_termination_t *term)
} }
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); 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_ALLOCATED);
switch_clear_flag(term, MGT_ACTIVE); switch_clear_flag(term, MGT_ACTIVE);
switch_clear_flag(term, MG_FAX_NOTIFIED);
if (term->type == MG_TERM_RTP) { if (term->type == MG_TERM_RTP) {
switch_core_hash_delete_wrlock(term->profile->terminations, term->name, term->profile->terminations_rwlock); switch_core_hash_delete_wrlock(term->profile->terminations, term->name, term->profile->terminations_rwlock);
@ -758,6 +735,7 @@ switch_status_t mgco_init_ins_service_change(SuId suId)
switch_hash_this(hi, &key, &keylen, &val); switch_hash_this(hi, &key, &keylen, &val);
term = (mg_termination_t *) val; term = (mg_termination_t *) val;
if(!term) continue; if(!term) continue;
if(MG_TERM_RTP == term->type) continue;
megaco_check_tdm_termination(term); megaco_check_tdm_termination(term);
} }

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,"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))){ if(SWITCH_STATUS_FALSE == (status = modify_mg_profile_mid(profile, &profile->mid))){
goto done; 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.channel = tdm_chan_num;
term->u.tdm.span_name = switch_core_strdup(pool, channel_prefix); term->u.tdm.span_name = switch_core_strdup(pool, channel_prefix);
switch_set_flag(term, MG_OUT_OF_SERVICE); 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); switch_core_hash_insert_wrlock(profile->terminations, term->name, term, profile->terminations_rwlock);
term->next = profile->physical_terminations; 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}, { "G.723.1", MEGACO_CODEC_G723_1},
{ "ILBC", MEGACO_CODEC_ILBC }, { "ILBC", MEGACO_CODEC_ILBC },
}; };
#endif
static switch_xml_config_enum_item_t opt_fax_detect_type_enum[] = { static switch_xml_config_enum_item_t opt_fax_detect_type_enum[] = {
{ "CED", MG_FAX_DETECT_EVENT_TYPE_CED}, { "CED", MG_FAX_DETECT_EVENT_TYPE_CED},
{ "CNG", MG_FAX_DETECT_EVENT_TYPE_CNG}, { "CNG", MG_FAX_DETECT_EVENT_TYPE_CNG},
{ "CED_CNG", MG_FAX_DETECT_EVENT_TYPE_CNG_CED}, { "CED_CNG", MG_FAX_DETECT_EVENT_TYPE_CNG_CED},
{ "DISABLE", MG_FAX_DETECT_EVENT_TYPE_DISABLE}, { "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[] = { 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("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("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("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() SWITCH_CONFIG_ITEM_END()
}; };

View File

@ -37,16 +37,41 @@ SWITCH_STANDARD_APP(mg_notify_function)
} }
if (!strcmp(data, "cng")) { 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); mg_send_t38_cng_notify(term->profile, term->name);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Sent CNG notify\n"); 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 */ /* Disable echo cancellation */
mg_term_set_ec(term, 0); if(MG_TERM_TDM == term->type){
} 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); 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) 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), MGT_ACTIVE = (1 << 1),
MG_IN_SERVICE = (1 << 2), MG_IN_SERVICE = (1 << 2),
MG_OUT_OF_SERVICE = (1 << 3), MG_OUT_OF_SERVICE = (1 << 3),
MG_FAX_NOTIFIED = (1 << 4),
} mg_termination_flags; } 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 { typedef enum {
MGM_AUDIO = 0, MGM_AUDIO = 0,
MGM_IMAGE, MGM_IMAGE,
@ -257,7 +266,7 @@ struct megaco_profile_s {
int inact_tmr; /* inactivity timer value */ int inact_tmr; /* inactivity timer value */
int peer_active; /* inactivity timer value */ int peer_active; /* inactivity timer value */
uint32_t inact_tmr_task_id; /* FS timer scheduler task-id */ 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; switch_thread_rwlock_t *contexts_rwlock;
uint32_t next_context_id; uint32_t next_context_id;