aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeels Hofmeyr <nhofmeyr@sysmocom.de>2024-02-22 05:27:55 +0100
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2024-02-25 04:00:27 +0100
commit48a1062ecbed013e92a529bb7cd69267db15d121 (patch)
tree03112856b9a65355f7f2c7424177ccc1bb9b968c
parente48ae2781345ab0b5a4e0cc4a2fd68232d0c8fd3 (diff)
mgcp-client: MGCP response: pass fmtp to callerneels/fmtp
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
-rw-r--r--src/libosmo-mgcp-client/mgcp_client.c46
1 files changed, 42 insertions, 4 deletions
diff --git a/src/libosmo-mgcp-client/mgcp_client.c b/src/libosmo-mgcp-client/mgcp_client.c
index b42ce0fa4..c507eaf2f 100644
--- a/src/libosmo-mgcp-client/mgcp_client.c
+++ b/src/libosmo-mgcp-client/mgcp_client.c
@@ -29,6 +29,7 @@
#include <osmocom/mgcp_client/mgcp_client.h>
#include <osmocom/mgcp_client/mgcp_client_internal.h>
+#include <osmocom/sdp/sdp_strings.h>
#include <osmocom/abis/e1_input.h>
@@ -388,11 +389,12 @@ static int mgcp_parse_audio_ptime_rtpmap(struct mgcp_response *r, const char *li
{
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_PTIME OSMO_SDP_A_PREFIX(OSMO_SDP_STR_PTIME)
+#define A_RTPMAP OSMO_SDP_A_PREFIX(OSMO_SDP_STR_RTPMAP)
+#define A_FMTP OSMO_SDP_A_PREFIX(OSMO_SDP_STR_FMTP)
if (osmo_str_startswith(line, A_PTIME)) {
if (sscanf(line, A_PTIME "%u", &r->ptime) != 1) {
@@ -401,7 +403,7 @@ static int mgcp_parse_audio_ptime_rtpmap(struct mgcp_response *r, const char *li
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;
@@ -440,6 +442,42 @@ static int mgcp_parse_audio_ptime_rtpmap(struct mgcp_response *r, const char *li
.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;