neels has uploaded this change for review.

View Change

mgcp-client: MGCP response: pass fmtp to caller

When receiving MGCP responses, so far libosmo-mgcp-client completely
ignored a=fmtp: parameters (like 'octet-align'). Add fmtp parsing to
pass the fmtp string to the caller as-is.

Since the responses so far never included the octet_aligned flags, do
not bother to parse fmtp to populate the legacy items. New callers
should use the fmtp string.

Change-Id: If8ca5c3880cad9e41b80e9d1c821439b0d7b7e23
---
M src/libosmo-mgcp-client/mgcp_client.c
1 file changed, 57 insertions(+), 2 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/05/34905/1
diff --git a/src/libosmo-mgcp-client/mgcp_client.c b/src/libosmo-mgcp-client/mgcp_client.c
index 1bbae95..6af75fd 100644
--- a/src/libosmo-mgcp-client/mgcp_client.c
+++ b/src/libosmo-mgcp-client/mgcp_client.c
@@ -377,11 +377,12 @@
{
unsigned int pt;
unsigned int i;
- char codec_resp[64];
+ char codec_resp[256];
int rc;

#define A_PTIME "a=ptime:"
#define A_RTPMAP "a=rtpmap:"
+#define A_FMTP "a=fmtp:"

if (osmo_str_startswith(line, A_PTIME)) {
if (sscanf(line, A_PTIME "%u", &r->ptime) != 1) {
@@ -390,7 +391,7 @@
return -EINVAL;
}
} else if (osmo_str_startswith(line, A_RTPMAP)) {
- if (sscanf(line, A_RTPMAP "%d %63s", &pt, codec_resp) != 2) {
+ if (sscanf(line, A_RTPMAP "%d %255s", &pt, codec_resp) != 2) {
LOGP(DLMGCP, LOGL_ERROR,
"Failed to parse SDP parameter, invalid rtpmap: %s\n", osmo_quote_str(line, -1));
return -EINVAL;
@@ -429,7 +430,44 @@
.codec = rc,
};
r->ptmap_len++;
+
+ } else if (osmo_str_startswith(line, A_FMTP)) {
+ if (sscanf(line, A_FMTP "%d %255s", &pt, codec_resp) != 2) {
+ LOGP(DLMGCP, LOGL_ERROR,
+ "Failed to parse SDP parameter, invalid fmtp: %s\n", osmo_quote_str(line, -1));
+ return -EINVAL;
+ }
+
+ /* Earlier, a line like "m=audio 16002 RTP/AVP 98 112 3" established the desired order of payloads, now
+ * enrich it with actual codec information provided by "a=rtpmap:..." entries.
+ * For each, find the entry with the right pt number and add the info there. */
+
+ for (i = 0; i < r->ptmap_len; i++) {
+ if (r->ptmap[i].pt != pt)
+ continue;
+ OSMO_STRLCPY_ARRAY(r->ptmap[r->ptmap_len].fmtp, codec_resp);
+ return 0;
+ }
+
+ /* No entry was found. This is an error in the MGCP protocol, but let's just add another entry
+ * anyway, to not make it look like it was never there. */
+ LOGP(DLMGCP, LOGL_ERROR,
+ "error in MGCP message: 'a=fmtp:%u' has no matching entry in 'm=audio ... %u'\n",
+ pt, pt);
+ if (r->ptmap_len <= ARRAY_SIZE(r->ptmap)) {
+ LOGP(DLMGCP, LOGL_ERROR,
+ "cannot parse all codecs: can only store up to %zu rtpmap entries.\n",
+ ARRAY_SIZE(r->ptmap));
+ return -ENOSPC;
+ }
+ r->ptmap[r->ptmap_len] = (struct ptmap){
+ .pt = pt,
+ .codec = -1,
+ };
+ OSMO_STRLCPY_ARRAY(r->ptmap[r->ptmap_len].fmtp, codec_resp);
+ r->ptmap_len++;
}
+
return 0;
}


To view, visit change 34905. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-Change-Id: If8ca5c3880cad9e41b80e9d1c821439b0d7b7e23
Gerrit-Change-Number: 34905
Gerrit-PatchSet: 1
Gerrit-Owner: neels <nhofmeyr@sysmocom.de>
Gerrit-MessageType: newchange