From 6e54a5e9bca0eb8bbbf4f748519c0a33bc883619 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 27 Jul 2012 12:08:15 -0400 Subject: [PATCH] local descriptor codec negotiation done --- .../media_gateway_cmd_handler.c | 8 +++++- .../mod_media_gateway/media_gateway_utils.c | 26 ++++++++++++++----- .../mod_media_gateway/mod_media_gateway.h | 3 ++- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c b/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c index ca0d286ba2..8940d36e66 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c @@ -707,7 +707,13 @@ switch_status_t handle_mg_add_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *i /* only for RTP */ if(is_rtp){ - mg_build_sdp(&desc->u.media, inc_med_desc, mg_profile, term, &rsp.u.mgCmdRsp[0]->memCp); + if(SWITCH_STATUS_FALSE == mg_build_sdp(&desc->u.media, inc_med_desc, mg_profile, term, &rsp.u.mgCmdRsp[0]->memCp)) { + if(term->mg_error_code && (*term->mg_error_code == MGT_MGCP_RSP_CODE_INCONSISTENT_LCL_OPT)){ + mg_util_set_err_string(&errTxt, " Unsupported Codec "); + err_code = MGT_MGCP_RSP_CODE_INCONSISTENT_LCL_OPT; + goto error; + } + } } #if 0 if(is_rtp){ diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway_utils.c b/src/mod/endpoints/mod_media_gateway/media_gateway_utils.c index 39a69f3921..ae4ec24b04 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway_utils.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway_utils.c @@ -1699,17 +1699,18 @@ switch_status_t mg_rem_unsupported_codecs (megaco_profile_t* mg_profile, mg_term /* loop through coddec list and remove un-supported codec */ for(i = 0; i < fmtList->num.val; i++) { + foundCodec = 0x00; fmt = fmtList->fmts[i]; if((NOTPRSNT == fmt->type.pres) || (NOTPRSNT == fmt->val.pres)) continue; if(CM_SDP_SPEC != fmt->type.val) continue; /* TODO - need to see for other cases like CM_SDP_NIL/CM_SDP_CHOICE etc not sure as of now */ - switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "codec[%d] number \n", fmt->val.val); /* see if received codec is present in our codec supported list */ for (id = 0; codecs[id] && id < codec_count; id++) { int pt = codecs[id]->ianacode; + switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "Matching recv codec[%d] with supported codec[%d] \n", fmt->val.val, pt); //const char *name = codecs[id]->iananame; if(pt == fmt->val.val){ foundCodec = 0x01; @@ -1751,6 +1752,14 @@ switch_status_t mg_rem_unsupported_codecs (megaco_profile_t* mg_profile, mg_term } } + if(0 == fmtList->num.val) { + switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "No Supported codec found in offer, Rejecting request \n"); + term->mg_error_code = switch_core_alloc(term->pool, sizeof(term->mg_error_code)); + *term->mg_error_code = MGT_MGCP_RSP_CODE_INCONSISTENT_LCL_OPT; + + return SWITCH_STATUS_FALSE; + } + return SWITCH_STATUS_SUCCESS; } @@ -1799,6 +1808,12 @@ switch_status_t mg_build_sdp(MgMgcoMediaDesc* out, MgMgcoMediaDesc* inc, megaco_ for(i=0; inum.val; i++) { if(MGT_MEDIAPAR_LOCAL == out->parms[i]->type.val) { local = &out->parms[i]->u.local; + break; + } else if(MGT_MEDIAPAR_STRPAR == out->parms[i]->type.val){ + MgMgcoStreamDesc *stream = &out->parms[i]->u.stream; + if((NOTPRSNT != stream->sl.pres.pres) && (NOTPRSNT != stream->sl.local.pres.pres)){ + local = &stream->sl.local; + } } } } @@ -1823,12 +1838,9 @@ switch_status_t mg_build_sdp(MgMgcoMediaDesc* out, MgMgcoMediaDesc* inc, megaco_ MG_INIT_TOKEN_VALUE(&(psdp->info[psdp->numComp.val-1]->orig.type), CM_SDP_SPEC); MG_INIT_TOKEN_VALUE(&(psdp->info[psdp->numComp.val-1]->orig.orig.pres), 1); - MG_SET_TKNSTROSXL(psdp->info[psdp->numComp.val-1]->orig.orig.usrName, 1, "-", - NULL); - MG_SET_TKNSTROSXL(psdp->info[psdp->numComp.val-1]->orig.orig.sessId, 1, "0", - NULL); - MG_SET_TKNSTROSXL(psdp->info[psdp->numComp.val-1]->orig.orig.sessVer, 1, "0", - NULL); + MG_SET_TKNSTROSXL(psdp->info[psdp->numComp.val-1]->orig.orig.usrName, 1, "-", memCp); + MG_SET_TKNSTROSXL(psdp->info[psdp->numComp.val-1]->orig.orig.sessId, 1, "0", memCp); + MG_SET_TKNSTROSXL(psdp->info[psdp->numComp.val-1]->orig.orig.sessVer, 1, "0", memCp); MG_SET_VAL_PRES( (psdp->info[psdp->numComp.val-1]->orig.orig.sdpAddr.netType.type), CM_SDP_NET_TYPE_IN); MG_SET_VAL_PRES( (psdp->info[psdp->numComp.val-1]->orig.orig.sdpAddr.addrType), 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 fdecf761b9..5c50ed9cfe 100644 --- a/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h +++ b/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h @@ -112,8 +112,9 @@ struct mg_termination_s { MgMgcoReqEvtDesc *active_events; /* !< active megaco events */ mg_termination_t *next; /*!< List for physical terminations */ mg_context_t* mg_ctxt; + int *mg_error_code; /* MEGACO error code */ uint32_t flags; - const char *tech; /* Endpoint controlling the TDM interface - only FreeTDM tested so far */ + const char *tech; /* Endpoint controlling the TDM interface - only FreeTDM tested so far */ union { struct {