sdp_msg.c: parse send/recv mode
Related: SYS#5066 Change-Id: I529c0bfad1cab376e26173ed48db2767c7dfaa64
This commit is contained in:
parent
6e29b91ae2
commit
e679fa146e
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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"
|
||||
,
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue