aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeels Hofmeyr <nhofmeyr@sysmocom.de>2022-07-19 12:16:02 +0200
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2022-08-09 02:28:32 +0200
commitfa52bef9c3cdd11146158a7ac5ba3139556831d6 (patch)
tree33a0382d26a186a09fcc5d0f29a2a27658a2326c
parenta7a500717e0e31364e1c99608bac7c4360187093 (diff)
sdp_msg.c: parse send/recv mode
-rw-r--r--include/osmocom/msc/sdp_msg.h9
-rw-r--r--src/libmsc/sdp_msg.c31
-rw-r--r--tests/sdp_msg/sdp_msg_test.c2
-rw-r--r--tests/sdp_msg/sdp_msg_test.ok2
4 files changed, 35 insertions, 9 deletions
diff --git a/include/osmocom/msc/sdp_msg.h b/include/osmocom/msc/sdp_msg.h
index cf1e56055..1b905b7ef 100644
--- a/include/osmocom/msc/sdp_msg.h
+++ b/include/osmocom/msc/sdp_msg.h
@@ -9,6 +9,14 @@ static inline const char *sdp_msg_payload_type_name(unsigned int payload_type)
{ 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_audio_codecs {
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 a76ae5e5f..dd5551769 100644
--- a/src/libmsc/sdp_msg.c
+++ b/src/libmsc/sdp_msg.c
@@ -227,6 +227,14 @@ int sdp_audio_codecs_remove(struct sdp_audio_codecs *ac, const struct sdp_audio_
return 0;
}
+static const char *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)
{
@@ -262,6 +270,9 @@ int sdp_msg_to_sdp_str_buf(char *dst, size_t dst_size, const struct sdp_msg *sdp
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;
}
@@ -287,9 +298,6 @@ int sdp_parse_attrib(struct sdp_msg *sdp, const char *src)
#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" */
@@ -346,19 +354,24 @@ int sdp_parse_attrib(struct sdp_msg *sdp, const char *src)
/* 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 ee48e808f..a1ffac0f6 100644
--- a/tests/sdp_msg/sdp_msg_test.c
+++ b/tests/sdp_msg/sdp_msg_test.c
@@ -61,6 +61,7 @@ struct sdp_test_data sdp_tests[] = {
"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 @@ struct sdp_test_data sdp_tests[] = {
"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 5f84ddd57..51a236b51 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=fmtp:100 192-193\r\n
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:8 PCMA/8000\r\n
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