sdp_msg.c: parse send/recv mode
Related: SYS#5066
Change-Id: I529c0bfad1cab376e26173ed48db2767c7dfaa64
diff --git a/src/libmsc/sdp_msg.c b/src/libmsc/sdp_msg.c
index 0aa5763..97e871b 100644
--- a/src/libmsc/sdp_msg.c
+++ b/src/libmsc/sdp_msg.c
@@ -227,6 +227,14 @@
return 0;
}
+static const char * const sdp_mode_str[] = {
+ [SDP_MODE_UNSET] = "-",
+ [SDP_MODE_SENDONLY] = "sendonly",
+ [SDP_MODE_RECVONLY] = "recvonly",
+ [SDP_MODE_SENDRECV] = "sendrecv",
+ [SDP_MODE_INACTIVE] = "inactive",
+};
+
/* Convert struct sdp_msg to the actual SDP protocol representation */
int sdp_msg_to_sdp_str_buf(char *dst, size_t dst_size, const struct sdp_msg *sdp)
{
@@ -271,6 +279,9 @@
OSMO_STRBUF_PRINTF(sb, "a=ptime:%d\r\n", sdp->ptime > 0? sdp->ptime : 20);
+ if (sdp->mode != SDP_MODE_UNSET && sdp->mode < ARRAY_SIZE(sdp_mode_str))
+ OSMO_STRBUF_PRINTF(sb, "a=%s\r\n", sdp_mode_str[sdp->mode]);
+
return sb.chars_needed;
}
@@ -296,9 +307,6 @@
#define A_FMTP "fmtp:"
#define A_PTIME "ptime:"
#define A_RTCP "rtcp:"
-#define A_SENDRECV "sendrecv"
-#define A_SENDONLY "sendonly"
-#define A_RECVONLY "recvonly"
if (osmo_str_startswith(src, A_RTPMAP)) {
/* "a=rtpmap:3 GSM/8000" */
@@ -355,19 +363,24 @@
/* TODO? */
}
- else if (osmo_str_startswith(src, A_SENDRECV)) {
+ else if (osmo_str_startswith(src, sdp_mode_str[SDP_MODE_SENDRECV])) {
/* "a=sendrecv" */
- /* TODO? */
+ sdp->mode = SDP_MODE_SENDRECV;
}
- else if (osmo_str_startswith(src, A_SENDONLY)) {
+ else if (osmo_str_startswith(src, sdp_mode_str[SDP_MODE_SENDONLY])) {
/* "a=sendonly" */
- /* TODO? */
+ sdp->mode = SDP_MODE_SENDONLY;
}
- else if (osmo_str_startswith(src, A_RECVONLY)) {
+ else if (osmo_str_startswith(src, sdp_mode_str[SDP_MODE_RECVONLY])) {
/* "a=recvonly" */
- /* TODO? */
+ sdp->mode = SDP_MODE_RECVONLY;
+ }
+
+ else if (osmo_str_startswith(src, sdp_mode_str[SDP_MODE_INACTIVE])) {
+ /* "a=inactive" */
+ sdp->mode = SDP_MODE_INACTIVE;
}
return 0;