Commit 0d3a78d4 authored by Pekka Pessi's avatar Pekka Pessi

Handle mode attributes (inactive, sendonly, recvonly, sendrecv).

darcs-hash:20050928153158-65a35-a93153096decd3fb160ffda3ca31a64bf96721b5.gz
parent 1d7bd086
......@@ -475,7 +475,11 @@ enum sdp_parse_flags_e {
/** Don't require c= for each media line */
sdp_f_c_missing = 128,
/** Parse SDP config files */
sdp_f_config = 256
sdp_f_config = 256,
/** Do not generate or parse SDP mode */
sdp_f_mode_manual = 512,
/** Include sendrecv mode, too. */
sdp_f_mode_always = 1024
};
/** SDP parser handle. */
......
......@@ -57,11 +57,15 @@ struct sdp_parser_s {
} pr_output;
char *pr_message;
su_home_t *pr_orig_home;
sdp_mode_t pr_session_mode;
unsigned pr_ok : 1;
unsigned pr_strict : 1;
unsigned pr_anynet : 1;
unsigned pr_mode_0000 : 1;
unsigned pr_mode_manual : 1;
unsigned pr_insane : 1;
unsigned pr_c_missing : 1;
unsigned pr_config : 1;
......@@ -138,6 +142,9 @@ sdp_parse(su_home_t *home, char const msg[], int msgsize, int flags)
p->pr_c_missing = (flags & sdp_f_c_missing) != 0;
if (flags & sdp_f_config)
p->pr_c_missing = 1, p->pr_config = 1;
p->pr_mode_manual = (flags & sdp_f_mode_manual) != 0;
p->pr_session_mode = sdp_sendrecv;
parse_message(p);
return p;
......@@ -457,7 +464,6 @@ int sdp_connection_is_inaddr_any(sdp_connection_t const *c)
static void post_session(sdp_parser_t *p, sdp_session_t *sdp)
{
sdp_media_t *m;
sdp_mode_t mode;
sdp_connection_t const *c;
if (!p->pr_ok)
......@@ -466,7 +472,6 @@ static void post_session(sdp_parser_t *p, sdp_session_t *sdp)
/* Set session back-pointer */
for (m = sdp->sdp_media; m; m = m->m_next) {
m->m_session = sdp;
m->m_mode = sdp_sendrecv;
}
if (p->pr_config) {
......@@ -475,8 +480,6 @@ static void post_session(sdp_parser_t *p, sdp_session_t *sdp)
return;
}
mode = sdp_attribute_mode(sdp->sdp_attributes, sdp_sendrecv);
/* Go through all media and set mode */
for (m = sdp->sdp_media; m; m = m->m_next) {
if (m->m_port == 0) {
......@@ -485,8 +488,6 @@ static void post_session(sdp_parser_t *p, sdp_session_t *sdp)
continue;
}
m->m_mode = sdp_attribute_mode(m->m_attributes, mode);
c = sdp_media_connections(m);
if (p->pr_mode_0000 && c) {
......@@ -1179,14 +1180,25 @@ static void parse_session_attr(sdp_parser_t *p, char *r, sdp_attribute_t **resul
if (strcasecmp(name, "charset") == 0) {
p->pr_session->sdp_charset = value;
return;
}
else {
PARSE_ALLOC(p, sdp_attribute_t, a);
*result = a;
a->a_name = name;
a->a_value = value;
}
if (p->pr_mode_manual)
;
else if (strcasecmp(name, "inactive") == 0)
p->pr_session_mode = sdp_inactive;
else if (strcasecmp(name, "sendonly") == 0)
p->pr_session_mode = sdp_sendonly;
else if (strcasecmp(name, "recvonly") == 0)
p->pr_session_mode = sdp_recvonly;
else if (strcasecmp(name, "sendrecv") == 0)
p->pr_session_mode = sdp_sendrecv;
PARSE_ALLOC(p, sdp_attribute_t, a);
*result = a;
a->a_name = name;
a->a_value = value;
}
/* -------------------------------------------------------------------------
......@@ -1463,6 +1475,25 @@ static void parse_media_attr(sdp_parser_t *p, char *r, sdp_media_t *m,
else
PARSE_CHECK_REST(p, r, "a");
if (p->pr_mode_manual)
;
else if (strcasecmp(name, "inactive") == 0) {
m->m_mode = sdp_inactive;
return;
}
else if (strcasecmp(name, "sendonly") == 0) {
m->m_mode = sdp_sendonly;
return;
}
else if (strcasecmp(name, "recvonly") == 0) {
m->m_mode = sdp_recvonly;
return;
}
else if (strcasecmp(name, "sendrecv") == 0) {
m->m_mode = sdp_sendrecv;
return;
}
if (rtp && strcasecmp(name, "rtpmap") == 0) {
if ((n = parse_rtpmap(p, r, m)) == 0 || n < -1)
return;
......@@ -1626,6 +1657,7 @@ static void parse_descs(sdp_parser_t *p,
parse_media(p, rest, medias);
m = *medias;
if (m) {
m->m_mode = p->pr_session_mode;
medias = &m->m_next;
connections = &m->m_connections;
bandwidths = &m->m_bandwidths;
......
......@@ -65,9 +65,11 @@ struct sdp_printer_s {
/* various flags */
int pr_ok : 1;
int pr_strict : 1;
int pr_owns_buffer : 1;
int pr_may_realloc : 1;
int pr_all_rtpmaps : 1;
unsigned pr_owns_buffer:1;
unsigned pr_may_realloc:1;
unsigned pr_all_rtpmaps:1;
unsigned pr_mode_manual:1;
unsigned pr_mode_always:1;
};
static struct sdp_printer_s printer_memory_error = {
......@@ -105,6 +107,8 @@ static void print_session(sdp_printer_t *p, sdp_session_t const *session);
* @li @c sdp_f_prefix - The buffer provided by caller already contains valid
* data. The function sdp_print() will concatenate its result to the buffer.
*
* @li @c sdp_f_mode - Add mode attributes.
*
* @return
* The function sdp_print() always returns a handle to an sdp_printer_t
* object.
......@@ -135,6 +139,8 @@ sdp_printer_t *sdp_print(su_home_t *home,
}
p->pr_strict = (flags & sdp_f_strict) != 0;
p->pr_all_rtpmaps = (flags & sdp_f_all_rtpmaps) != 0;
p->pr_mode_manual = (flags & sdp_f_mode_manual) != 0;
p->pr_mode_always = (flags & sdp_f_mode_always) != 0;
print_session(p, session);
......@@ -518,6 +524,23 @@ static void print_attributes(sdp_printer_t *p, sdp_attribute_t const *a)
}
}
static void
print_attributes_without_mode(sdp_printer_t *p, sdp_attribute_t const *a)
{
for (;a; a = a->a_next) {
char const *name = a->a_name;
char const *value = a->a_value;
if (strcasecmp(name, "inactive") == 0 ||
strcasecmp(name, "sendonly") == 0 ||
strcasecmp(name, "recvonly") == 0 ||
strcasecmp(name, "sendrecv") == 0)
continue;
sdp_printf(p, "a=%s%s%s" CRLF, name, value ? ":" : "", value ? value : "");
}
}
static void print_charset(sdp_printer_t *p, sdp_text_t *charset)
{
sdp_printf(p, "a=charset%s%s" CRLF, charset ? ":" : "", charset ? charset : "");
......@@ -530,6 +553,11 @@ static void print_media(sdp_printer_t *p,
char const *media, *proto;
sdp_rtpmap_t *rm;
sdp_mode_t session_mode = sdp_sendrecv;
if (!p->pr_mode_manual)
session_mode = sdp_attribute_mode(sdp->sdp_attributes, sdp_sendrecv);
for (;m ; m = m->m_next) {
switch (m->m_type) {
case sdp_media_audio: media = "audio"; break;
......@@ -596,9 +624,30 @@ static void print_media(sdp_printer_t *p,
rm->rm_pt, rm->rm_fmtp);
}
if (m->m_attributes)
if (!p->pr_mode_manual && !m->m_rejected &&
(m->m_mode != session_mode || p->pr_mode_always)) {
switch (m->m_mode) {
case sdp_inactive:
sdp_printf(p, "a=inactive" CRLF);
break;
case sdp_sendonly:
sdp_printf(p, "a=sendonly" CRLF);
break;
case sdp_recvonly:
sdp_printf(p, "a=recvonly" CRLF);
break;
case sdp_sendrecv:
sdp_printf(p, "a=sendrecv" CRLF);
break;
default:
break;
}
}
if (p->pr_mode_manual)
print_attributes(p, m->m_attributes);
else
print_attributes_without_mode(p, m->m_attributes);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment