From 8caba1836c17cc518280ffedfbdde9802862e2f2 Mon Sep 17 00:00:00 2001 From: Christian Spielberger Date: Fri, 25 Mar 2022 10:49:19 +0100 Subject: [PATCH] sdp: a utility function for decoding SDP direction --- include/re_sdp.h | 2 ++ src/sdp/util.c | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/re_sdp.h b/include/re_sdp.h index bad4bfa90..8ad3ab774 100644 --- a/include/re_sdp.h +++ b/include/re_sdp.h @@ -175,6 +175,8 @@ extern const char sdp_proto_rtpsavp[]; /* utility functions */ +enum sdp_dir sdp_dir_decode(const struct pl *pl); + /** RTP Header Extensions, as defined in RFC 5285 */ struct sdp_extmap { struct pl name; diff --git a/src/sdp/util.c b/src/sdp/util.c index 754f5b888..6e5c3feae 100644 --- a/src/sdp/util.c +++ b/src/sdp/util.c @@ -11,6 +11,31 @@ #include +/** + * Decode an SDP direction + * + * @param pl SDP direction as string + * + * @return sdp_dir SDP direction, SDP_SENDRECV as fallback + */ +enum sdp_dir sdp_dir_decode(const struct pl *pl) +{ + if (!pl_strcmp(pl, "off")) { + return SDP_INACTIVE; + } + else if (!pl_strcmp(pl, "inactive")) { + return SDP_INACTIVE; + } + else if (!pl_strcmp(pl, "sendonly")) { + return SDP_SENDONLY; + } + else if (!pl_strcmp(pl, "recvonly")) { + return SDP_RECVONLY; + } + + return SDP_SENDRECV; +} + /** * Decode RTP Header Extension SDP attribute value *