From e2f34d588c710db809da6bcfc9a85f3f09468201 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Tue, 6 Nov 2012 13:16:26 +0100 Subject: nat: Inject a a=fmtp:%d to force the right AMR code This assumes that AMR is used and/or the mode-set is ignored for other codecs by the remote end. --- openbsc/src/osmo-bsc_nat/bsc_mgcp_utils.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'openbsc/src/osmo-bsc_nat') diff --git a/openbsc/src/osmo-bsc_nat/bsc_mgcp_utils.c b/openbsc/src/osmo-bsc_nat/bsc_mgcp_utils.c index 668ddd653..d78dc91bc 100644 --- a/openbsc/src/osmo-bsc_nat/bsc_mgcp_utils.c +++ b/openbsc/src/osmo-bsc_nat/bsc_mgcp_utils.c @@ -563,12 +563,18 @@ struct msgb *bsc_mgcp_rewrite(char *input, int length, int endpoint, const char static const char *ip_str = "c=IN IP4 "; static const char *aud_str = "m=audio "; + static const char *fmt_str = "a=fmtp: "; char buf[128]; char *running, *token; struct msgb *output; - if (length > 4096 - 128) { + /* keep state to add the a=fmtp line */ + int found_fmtp = 0; + int payload = -1; + int cr = 1; + + if (length > 4096 - 256) { LOGP(DMGCP, LOGL_ERROR, "Input is too long.\n"); return NULL; } @@ -584,7 +590,7 @@ struct msgb *bsc_mgcp_rewrite(char *input, int length, int endpoint, const char output->l3h = output->l2h; for (token = strsep(&running, "\n"); running; token = strsep(&running, "\n")) { int len = strlen(token); - int cr = len > 0 && token[len - 1] == '\r'; + cr = len > 0 && token[len - 1] == '\r'; if (strncmp(crcx_str, token, (sizeof crcx_str) - 1) == 0) { patch_mgcp(output, "CRCX", token, endpoint, len, cr); @@ -607,7 +613,6 @@ struct msgb *bsc_mgcp_rewrite(char *input, int length, int endpoint, const char output->l3h[0] = '\n'; } } else if (strncmp(aud_str, token, (sizeof aud_str) - 1) == 0) { - int payload; if (sscanf(token, "m=audio %*d RTP/AVP %d", &payload) != 1) { LOGP(DMGCP, LOGL_ERROR, "Could not parsed audio line.\n"); msgb_free(output); @@ -620,13 +625,29 @@ struct msgb *bsc_mgcp_rewrite(char *input, int length, int endpoint, const char output->l3h = msgb_put(output, strlen(buf)); memcpy(output->l3h, buf, strlen(buf)); + } else if (strncmp(fmt_str, token, (sizeof fmt_str) - 1) == 0) { + found_fmtp = 1; + goto copy; } else { +copy: output->l3h = msgb_put(output, len + 1); memcpy(output->l3h, token, len); output->l3h[len] = '\n'; } } + /* + * the above code made sure that we have 128 bytes lefts. So we can + * safely append another line. + */ + if (!found_fmtp && payload != -1) { + snprintf(buf, sizeof(buf) - 1, "a=fmtp:%d mode-set=2%s", + payload, cr ? "\r\n" : "\n"); + buf[sizeof(buf) - 1] = '\0'; + output->l3h = msgb_put(output, strlen(buf)); + memcpy(output->l3h, buf, strlen(buf)); + } + return output; } -- cgit v1.2.3