laforge has submitted this change. ( 
https://gerrit.osmocom.org/c/osmo-msc/+/30110 )

Change subject: sdp_msg.c: parse send/recv mode
......................................................................

sdp_msg.c: parse send/recv mode

Related: SYS#5066
Change-Id: I529c0bfad1cab376e26173ed48db2767c7dfaa64
---
M include/osmocom/msc/sdp_msg.h
M src/libmsc/sdp_msg.c
M tests/sdp_msg/sdp_msg_test.c
M tests/sdp_msg/sdp_msg_test.ok
4 files changed, 35 insertions(+), 9 deletions(-)

Approvals:
  neels: Looks good to me, approved
  pespin: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/include/osmocom/msc/sdp_msg.h b/include/osmocom/msc/sdp_msg.h
index cf1e560..1b905b7 100644
--- a/include/osmocom/msc/sdp_msg.h
+++ b/include/osmocom/msc/sdp_msg.h
@@ -9,6 +9,14 @@
 { return get_value_string(sdp_msg_payload_type_names, payload_type); }
 int sdp_subtype_name_to_payload_type(const char *subtype_name);

+enum sdp_mode_e {
+       SDP_MODE_UNSET = 0,
+       SDP_MODE_SENDONLY = 1,
+       SDP_MODE_RECVONLY = 2,
+       SDP_MODE_SENDRECV = 3,
+       SDP_MODE_INACTIVE = 4,
+};
+
 struct sdp_audio_codec {
        /* Payload type number, like 3 for GSM-FR. */
        unsigned int payload_type;
@@ -26,6 +34,7 @@
 struct sdp_msg {
        struct osmo_sockaddr_str rtp;
        unsigned int ptime;
+       enum sdp_mode_e mode;
        struct sdp_audio_codecs audio_codecs;
 };

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;
diff --git a/tests/sdp_msg/sdp_msg_test.c b/tests/sdp_msg/sdp_msg_test.c
index ee48e80..a1ffac0 100644
--- a/tests/sdp_msg/sdp_msg_test.c
+++ b/tests/sdp_msg/sdp_msg_test.c
@@ -61,6 +61,7 @@
                "a=rtpmap:101 telephone-event/8000\r\n"
                "a=fmtp:101 0-15\r\n"
                "a=ptime:20\r\n"
+               "a=sendrecv\r\n"
                ,
        },
        {
@@ -116,6 +117,7 @@
                "a=rtpmap:101 telephone-event/8000\r\n"
                "a=fmtp:101 0-15\r\n"
                "a=ptime:20\r\n"
+               "a=sendrecv\r\n"
                ,
        },
 };
diff --git a/tests/sdp_msg/sdp_msg_test.ok b/tests/sdp_msg/sdp_msg_test.ok
index 5f84ddd..51a236b 100644
--- a/tests/sdp_msg/sdp_msg_test.ok
+++ b/tests/sdp_msg/sdp_msg_test.ok
@@ -42,6 +42,7 @@
 sdp_msg_to_sdp_str_buf: a=rtpmap:101 telephone-event/8000\r\n
 sdp_msg_to_sdp_str_buf: a=fmtp:101 0-15\r\n
 sdp_msg_to_sdp_str_buf: a=ptime:20\r\n
+sdp_msg_to_sdp_str_buf: a=sendrecv\r\n
 [0] ok

 [1]
@@ -95,6 +96,7 @@
 sdp_msg_to_sdp_str_buf: a=rtpmap:101 telephone-event/8000\r\n
 sdp_msg_to_sdp_str_buf: a=fmtp:101 0-15\r\n
 sdp_msg_to_sdp_str_buf: a=ptime:20\r\n
+sdp_msg_to_sdp_str_buf: a=sendrecv\r\n
 [2] ok



--
To view, visit https://gerrit.osmocom.org/c/osmo-msc/+/30110
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-msc
Gerrit-Branch: master
Gerrit-Change-Id: I529c0bfad1cab376e26173ed48db2767c7dfaa64
Gerrit-Change-Number: 30110
Gerrit-PatchSet: 3
Gerrit-Owner: neels <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <[email protected]>
Gerrit-Reviewer: laforge <[email protected]>
Gerrit-Reviewer: neels <[email protected]>
Gerrit-Reviewer: pespin <[email protected]>
Gerrit-MessageType: merged

Reply via email to