add spandsp cng-tone detect

This commit is contained in:
Mathieu Rene 2012-08-09 17:10:27 -04:00
parent 83e0d9c3bd
commit 8aa901c422
3 changed files with 27 additions and 75 deletions

View File

@ -84,7 +84,7 @@ megaco_profile_t* megaco_get_profile_by_suId(SuId suId)
static switch_status_t mg_on_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf, switch_dtmf_direction_t direction) static switch_status_t mg_on_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf, switch_dtmf_direction_t direction)
{ {
switch_channel_t *channel = switch_core_session_get_channel(session); switch_channel_t *channel = switch_core_session_get_channel(session);
mg_termination_t *term = switch_channel_get_private(channel, "_mg_term_"); mg_termination_t *term = switch_channel_get_private(channel, PVT_MG_TERM);
//char digit[2] = { dtmf->digit }; //char digit[2] = { dtmf->digit };
if (!term) { if (!term) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find termination structure for session [%s]\n", switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find termination structure for session [%s]\n",
@ -168,8 +168,10 @@ switch_status_t megaco_activate_termination(mg_termination_t *term)
term->uuid = switch_core_strdup(term->pool, switch_core_session_get_uuid(session)); 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)); 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); channel = switch_core_session_get_channel(session);
switch_channel_set_private(channel, "_mg_term_", term); switch_channel_set_private(channel, PVT_MG_TERM, term);
switch_core_event_hook_add_recv_dtmf(session, mg_on_dtmf); switch_core_event_hook_add_recv_dtmf(session, mg_on_dtmf);
switch_core_session_execute_application_async(session, "spandsp_start_fax_detect", "mg_notify cng 120 cng");
} }
switch_set_flag(term, MGT_ACTIVE); switch_set_flag(term, MGT_ACTIVE);

View File

@ -26,6 +26,22 @@ SWITCH_STANDARD_API(megaco_function)
return mg_process_cli_cmd(cmd, stream); return mg_process_cli_cmd(cmd, stream);
} }
SWITCH_STANDARD_APP(mg_notify_function)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
mg_termination_t *term = switch_channel_get_private(channel, PVT_MG_TERM);
if (!term) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "mg_notify called on a non-supported channel.\n");
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");
}
}
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)
{ {
switch_hash_index_t *hi; switch_hash_index_t *hi;
@ -92,6 +108,7 @@ static void mg_event_handler(switch_event_t *event)
SWITCH_MODULE_LOAD_FUNCTION(mod_media_gateway_load) SWITCH_MODULE_LOAD_FUNCTION(mod_media_gateway_load)
{ {
switch_api_interface_t *api_interface; switch_api_interface_t *api_interface;
switch_application_interface_t *app_interface;
memset(&megaco_globals, 0, sizeof(megaco_globals)); memset(&megaco_globals, 0, sizeof(megaco_globals));
megaco_globals.pool = pool; megaco_globals.pool = pool;
@ -105,6 +122,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_media_gateway_load)
switch_thread_rwlock_create(&megaco_globals.peer_profile_rwlock, pool); switch_thread_rwlock_create(&megaco_globals.peer_profile_rwlock, pool);
SWITCH_ADD_API(api_interface, "mg", "media_gateway", megaco_function, MEGACO_FUNCTION_SYNTAX); SWITCH_ADD_API(api_interface, "mg", "media_gateway", megaco_function, MEGACO_FUNCTION_SYNTAX);
SWITCH_ADD_APP(app_interface, "mg_notify", "<type>", "sends a notify to the mgc", mg_notify_function, "", 0);
switch_console_set_complete("add mg profile ::mg::list_profiles start"); switch_console_set_complete("add mg profile ::mg::list_profiles start");
switch_console_set_complete("add mg profile ::mg::list_profiles stop"); switch_console_set_complete("add mg profile ::mg::list_profiles stop");
@ -247,76 +265,6 @@ void handle_sng_log(uint8_t level, char *fmt, ...)
} }
/*****************************************************************************************************************************/ /*****************************************************************************************************************************/
#if 0
static switch_status_t mgco_parse_local_sdp(mg_termination_t *term, CmSdpInfoSet *sdp)
{
int i;
CmSdpInfoSet *local_sdp;
/* Parse the local SDP while copying the important bits over to our local structure,
* while taking care of editing choose request and replacing them by real values */
if (!term->u.rtp.local_sdp) {
local_sdp = term->u.rtp.local_sdp = switch_core_alloc(term->context->pool, sizeof *term->u.rtp.local_sdp);
}
if (sdp->numComp.pres == NOTPRSNT) {
return SWITCH_STATUS_FALSE;
}
for (i = 0; i < sdp->numComp.val; i++) {
CmSdpInfo *s = sdp->info[i];
int mediaId;
local_sdp->info[i] = switch_core_alloc(term->context->pool, sizeof *(local_sdp->info[i]));
*(local_sdp->info[i]) = *(sdp->info[i]);
if (s->conn.addrType.pres && s->conn.addrType.val == CM_SDP_ADDR_TYPE_IPV4 &&
s->conn.netType.type.val == CM_SDP_NET_TYPE_IN &&
s->conn.u.ip4.addrType.val == CM_SDP_IPV4_IP_UNI) {
if (s->conn.u.ip4.addrType.pres) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Local address: %d.%d.%d.%d\n",
s->conn.u.ip4.u.uniIp.b[0].val,
s->conn.u.ip4.u.uniIp.b[1].val,
s->conn.u.ip4.u.uniIp.b[2].val,
s->conn.u.ip4.u.uniIp.b[3].val);
/* TODO: Double-check bind address for this profile */
}
if (s->attrSet.numComp.pres) {
for (mediaId = 0; mediaId < s->attrSet.numComp.val; mediaId++) {
CmSdpAttr *a = s->attrSet.attr[mediaId];
local_sdp->info[i]->attrSet.attr[mediaId] = switch_core_alloc(term->context->pool, sizeof(CmSdpAttr));
*(local_sdp->info[i]->attrSet.attr[mediaId]) = *a;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Media %p\n", (void*)a);
}
}
if (s->mediaDescSet.numComp.pres) {
for (mediaId = 0; mediaId < s->mediaDescSet.numComp.val; mediaId++) {
CmSdpMediaDesc *desc = s->mediaDescSet.mediaDesc[mediaId];
local_sdp->info[i]->mediaDescSet.mediaDesc[mediaId] = switch_core_alloc(term->context->pool, sizeof(CmSdpMediaDesc));
*(local_sdp->info[i]->mediaDescSet.mediaDesc[mediaId]) = *desc;
if (desc->field.mediaType.val == CM_SDP_MEDIA_AUDIO &&
desc->field.id.type.val == CM_SDP_VCID_PORT &&
desc->field.id.u.port.type.val == CM_SDP_PORT_INT &&
desc->field.id.u.port.u.portInt.port.type.val == CM_SDP_SPEC) {
int port = desc->field.id.u.port.u.portInt.port.val.val;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Port: %d\n", port);
}
}
}
}
}
return SWITCH_STATUS_SUCCESS;
}
#endif
/* KAPIL- NOTE : We are using Command mode operation of MEGACO stack, so we will always get command indication instead of transaction */ /* KAPIL- NOTE : We are using Command mode operation of MEGACO stack, so we will always get command indication instead of transaction */
/* Below API is not useful ... just leaving as it is...*/ /* Below API is not useful ... just leaving as it is...*/

View File

@ -22,6 +22,8 @@
#define MEGACO_LOGGING_CLI_SYNTAX "logging [enable|disable]" #define MEGACO_LOGGING_CLI_SYNTAX "logging [enable|disable]"
#define MEGACO_FUNCTION_SYNTAX "profile [name] [start | stop] [status] [xmlstatus] [peerxmlstatus]" #define MEGACO_FUNCTION_SYNTAX "profile [name] [start | stop] [status] [xmlstatus] [peerxmlstatus]"
#define PVT_MG_TERM "_mg_term_"
struct megaco_globals { struct megaco_globals {
switch_memory_pool_t *pool; switch_memory_pool_t *pool;
switch_hash_t *profile_hash; switch_hash_t *profile_hash;