]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
adding code to invoke freetdm dtmf removal api
authorKapil Gupta <kgupta@sangoma.com>
Fri, 7 Sep 2012 14:14:58 +0000 (10:14 -0400)
committerKapil Gupta <kgupta@sangoma.com>
Fri, 7 Sep 2012 14:14:58 +0000 (10:14 -0400)
src/mod/endpoints/mod_media_gateway/media_gateway.c
src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c
src/mod/endpoints/mod_media_gateway/mod_media_gateway.h

index ee96bc319d528b8b09ef8937823862787be3b184..4272e414af3750fe28f25d72351bad61f8e3d90a 100644 (file)
@@ -208,6 +208,51 @@ done:
     return status;
 }
 
+switch_status_t megaco_tdm_term_dtmf_removal(mg_termination_t *term, int enable)
+{
+       char buf[128];
+       switch_event_t *event = NULL;
+       mg_termination_t* tdm_term = NULL;
+
+       if(NULL == term) return SWITCH_STATUS_FALSE;
+
+       if(MG_TERM_RTP == term->type){
+               if(NULL == term->context) {
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Null Context from rtp term, not able to get tdm term \n");   
+                       return SWITCH_STATUS_FALSE;
+               }
+               tdm_term = megaco_context_get_peer_term(term->context, term);
+       }else{
+               tdm_term = term;
+       }
+
+       if(NULL == tdm_term) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Null TDM term \n");   
+               return SWITCH_STATUS_FALSE;
+       }
+
+       memset(&buf[0],0,sizeof(buf));
+
+       if (switch_event_create(&event, SWITCH_EVENT_TRAP) != SWITCH_STATUS_SUCCESS) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failed to create NOTIFY event\n");
+               return SWITCH_STATUS_FALSE;
+       }
+
+       switch_event_add_header(event, SWITCH_STACK_BOTTOM, "span-name", "%s",  tdm_term->u.tdm.span_name);
+       switch_event_add_header(event, SWITCH_STACK_BOTTOM, "chan-number", "%d", tdm_term->u.tdm.channel);
+       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "condition", "mg-tdm-dtmfremoval");
+
+       sprintf(buf,"%s",(1 == enable)?"enable":"disable");
+
+       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Sending DTMF Removal Event[%s] for MG Term[%s], TDM span[%s] channel[%d]\n",
+                                        buf,tdm_term->name, tdm_term->u.tdm.span_name, tdm_term->u.tdm.channel);
+
+       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "command", buf);
+
+       switch_event_fire(&event);
+    return SWITCH_STATUS_SUCCESS;
+}
+
 switch_status_t megaco_prepare_tdm_termination(mg_termination_t *term)
 {
        switch_event_t *event = NULL;
@@ -403,6 +448,23 @@ void megaco_termination_destroy(mg_termination_t *term)
     }
 }
 
+mg_termination_t* megaco_context_get_peer_term(mg_context_t *ctx, mg_termination_t *term)
+{
+
+    switch_assert(ctx != NULL);
+    switch_assert(term != NULL);
+
+    if (ctx->terminations[0] && (term == ctx->terminations[0])) {
+        return ctx->terminations[1];
+    }
+
+    if (ctx->terminations[1] && (term == ctx->terminations[1])) {
+        return ctx->terminations[0];
+    }
+
+    return NULL;
+}
+
 switch_status_t megaco_context_is_term_present(mg_context_t *ctx, mg_termination_t *term)
 {
 
index f2673ac0c2891c5337eaf83baa9c55aaa7321544..cc393d8ff8fa59121c9dc20948ad015f1c8e6800 100644 (file)
@@ -741,6 +741,17 @@ switch_status_t handle_mg_add_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *i
         goto error;
     }
 
+       if(is_rtp){
+               mg_termination_t* tdm_term = NULL;
+               /* disable dtmf removal */
+               tdm_term = megaco_context_get_peer_term(mg_ctxt, term);
+               if(term->u.rtp.rfc2833_pt){
+                       megaco_tdm_term_dtmf_removal(tdm_term,0x01);
+               }else{
+                       megaco_tdm_term_dtmf_removal(tdm_term,0x00);
+               }
+       }
+
     
     mg_print_t38_attributes(term);
 
index b30c7d41b16ab8e0a494e2301c5145060d56b2b1..95d738d559f677607515cdf588b77422db5ef5d0 100644 (file)
@@ -321,6 +321,7 @@ static inline megaco_codec_t megaco_codec_parse(const char *codec) {
 }
 
 
+switch_status_t megaco_tdm_term_dtmf_removal(mg_termination_t *term, int enable);
 megaco_profile_t *megaco_profile_locate(const char *name);
 mg_termination_t *megaco_term_locate_by_span_chan_id(const char *span_name, const char *chan_number);
 mg_peer_profile_t *megaco_peer_profile_locate(const char *name);
@@ -363,6 +364,7 @@ switch_status_t megaco_context_is_term_present(mg_context_t *ctx, mg_termination
 
 switch_status_t megaco_prepare_tdm_termination(mg_termination_t *term);
 switch_status_t megaco_check_tdm_termination(mg_termination_t *term);
+mg_termination_t* megaco_context_get_peer_term(mg_context_t *ctx, mg_termination_t *term);