summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLiong Sauw Ming <ming@teluu.com>2011-04-28 04:01:40 +0000
committerLiong Sauw Ming <ming@teluu.com>2011-04-28 04:01:40 +0000
commit541e3c0640108690602f60912704e0619c94d111 (patch)
tree7e2078aa2ef6707cdec246cbfb5cf8902adf80e1
parentd3ae5a78389f8560b3f102feb2baf3978f914a89 (diff)
Fixed #1243: ICE bug: If RTCP is not in use, the agent MUST signal that using b=RS:0 and b=RR:0
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@3547 74dad513-b988-da41-8d7b-12977e46ad98
-rw-r--r--pjmedia/include/pjmedia/sdp.h46
-rw-r--r--pjmedia/src/pjmedia/sdp.c54
-rw-r--r--pjmedia/src/pjmedia/transport_ice.c16
3 files changed, 112 insertions, 4 deletions
diff --git a/pjmedia/include/pjmedia/sdp.h b/pjmedia/include/pjmedia/sdp.h
index 456a0476..4cc7398d 100644
--- a/pjmedia/include/pjmedia/sdp.h
+++ b/pjmedia/include/pjmedia/sdp.h
@@ -50,6 +50,14 @@ PJ_BEGIN_DECL
#endif
/**
+ * The PJMEDIA_MAX_SDP_BANDW macro defines maximum bandwidth information
+ * lines in a media line.
+ */
+#ifndef PJMEDIA_MAX_SDP_BANDW
+# define PJMEDIA_MAX_SDP_BANDW 4
+#endif
+
+/**
* The PJMEDIA_MAX_SDP_ATTR macro defines maximum SDP attributes in media and
* session descriptor.
*/
@@ -368,6 +376,34 @@ PJ_DECL(pjmedia_sdp_conn*) pjmedia_sdp_conn_clone(pj_pool_t *pool,
/* **************************************************************************
+ * SDP BANDWIDTH INFO
+ ****************************************************************************
+ */
+
+/**
+ * This structure describes SDP bandwidth info ("b=" line).
+ */
+typedef struct pjmedia_sdp_bandw
+{
+ pj_str_t modifier; /**< Bandwidth modifier. */
+ pj_uint32_t value; /**< Bandwidth value. */
+} pjmedia_sdp_bandw;
+
+
+/**
+ * Clone bandwidth info.
+ *
+ * @param pool Pool to allocate memory for the new bandwidth info.
+ * @param rhs The bandwidth into to clone.
+ *
+ * @return The new bandwidth info.
+ */
+PJ_DECL(pjmedia_sdp_bandw*)
+pjmedia_sdp_bandw_clone(pj_pool_t *pool, const pjmedia_sdp_bandw *rhs);
+
+
+
+/* **************************************************************************
* SDP MEDIA INFO/LINE
****************************************************************************
*/
@@ -387,12 +423,14 @@ struct pjmedia_sdp_media
unsigned port_count; /**< Port count, used only when >2 */
pj_str_t transport; /**< Transport ("RTP/AVP") */
unsigned fmt_count; /**< Number of formats. */
- pj_str_t fmt[PJMEDIA_MAX_SDP_FMT]; /**< Media formats. */
+ pj_str_t fmt[PJMEDIA_MAX_SDP_FMT]; /**< Media formats. */
} desc;
- pjmedia_sdp_conn *conn; /**< Optional connection info. */
- unsigned attr_count; /**< Number of attributes. */
- pjmedia_sdp_attr*attr[PJMEDIA_MAX_SDP_ATTR]; /**< Attributes. */
+ pjmedia_sdp_conn *conn; /**< Optional connection info. */
+ unsigned bandw_count; /**< Number of bandwidth info. */
+ pjmedia_sdp_bandw *bandw[PJMEDIA_MAX_SDP_BANDW]; /**< Bandwidth info. */
+ unsigned attr_count; /**< Number of attributes. */
+ pjmedia_sdp_attr *attr[PJMEDIA_MAX_SDP_ATTR]; /**< Attributes. */
};
diff --git a/pjmedia/src/pjmedia/sdp.c b/pjmedia/src/pjmedia/sdp.c
index 8e7c72c5..ee7d0656 100644
--- a/pjmedia/src/pjmedia/sdp.c
+++ b/pjmedia/src/pjmedia/sdp.c
@@ -544,6 +544,39 @@ PJ_DEF(pjmedia_sdp_conn*) pjmedia_sdp_conn_clone (pj_pool_t *pool,
return c;
}
+PJ_DEF(pjmedia_sdp_bandw*)
+pjmedia_sdp_bandw_clone (pj_pool_t *pool,
+ const pjmedia_sdp_bandw *rhs)
+{
+ pjmedia_sdp_bandw *b = PJ_POOL_ALLOC_T(pool, pjmedia_sdp_bandw);
+ if (!b) return NULL;
+
+ if (!pj_strdup (pool, &b->modifier, &rhs->modifier)) return NULL;
+ b->value = rhs->value;
+
+ return b;
+}
+
+static pj_ssize_t print_bandw(const pjmedia_sdp_bandw *bandw,
+ char *buf, pj_size_t len)
+{
+ char *p = buf;
+
+ if ((int)len < bandw->modifier.slen + 10 + 5)
+ return -1;
+
+ *p++ = 'b';
+ *p++ = '=';
+ pj_memcpy(p, bandw->modifier.ptr, bandw->modifier.slen);
+ p += bandw->modifier.slen;
+ *p++ = ':';
+ p += pj_utoa(bandw->value, p);
+
+ *p++ = '\r';
+ *p++ = '\n';
+ return p-buf;
+}
+
static pj_ssize_t print_attr(const pjmedia_sdp_attr *attr,
char *buf, pj_size_t len)
{
@@ -611,6 +644,15 @@ static int print_media_desc( pjmedia_sdp_media *m, char *buf, int len)
}
p += printed;
}
+
+ /* print optional bandwidth info. */
+ for (i=0; i<m->bandw_count; ++i) {
+ printed = print_bandw(m->bandw[i], p, end-p);
+ if (printed < 0) {
+ return -1;
+ }
+ p += printed;
+ }
/* print attributes. */
for (i=0; i<m->attr_count; ++i) {
@@ -647,6 +689,12 @@ PJ_DEF(pjmedia_sdp_media*) pjmedia_sdp_media_clone(
m->conn = NULL;
}
+ m->bandw_count = rhs->bandw_count;
+ for (i=0; i < rhs->bandw_count; ++i) {
+ m->bandw[i] = pjmedia_sdp_bandw_clone (pool, rhs->bandw[i]);
+ PJ_ASSERT_RETURN(m->bandw[i] != NULL, NULL);
+ }
+
m->attr_count = rhs->attr_count;
for (i=0; i < rhs->attr_count; ++i) {
m->attr[i] = pjmedia_sdp_attr_clone (pool, rhs->attr[i]);
@@ -1467,6 +1515,12 @@ PJ_DEF(pjmedia_sdp_media*) pjmedia_sdp_media_clone_deactivate(
PJ_ASSERT_RETURN(m->conn != NULL, NULL);
}
+ m->bandw_count = rhs->bandw_count;
+ for (i=0; i < rhs->bandw_count; ++i) {
+ m->bandw[i] = pjmedia_sdp_bandw_clone (pool, rhs->bandw[i]);
+ PJ_ASSERT_RETURN(m->bandw[i] != NULL, NULL);
+ }
+
/* And deactivate it */
pjmedia_sdp_media_deactivate(pool, m);
diff --git a/pjmedia/src/pjmedia/transport_ice.c b/pjmedia/src/pjmedia/transport_ice.c
index 9cf425a2..6105231d 100644
--- a/pjmedia/src/pjmedia/transport_ice.c
+++ b/pjmedia/src/pjmedia/transport_ice.c
@@ -174,6 +174,8 @@ static const pj_str_t STR_ICE_PWD = { "ice-pwd", 7 };
static const pj_str_t STR_IP4 = { "IP4", 3 };
static const pj_str_t STR_IP6 = { "IP6", 3 };
static const pj_str_t STR_RTCP = { "rtcp", 4 };
+static const pj_str_t STR_BANDW_RR = { "RR", 2 };
+static const pj_str_t STR_BANDW_RS = { "RS", 2 };
enum {
COMP_RTP = 1,
@@ -601,6 +603,20 @@ static pj_status_t encode_session_in_sdp(struct transport_ice *tp_ice,
attr = pjmedia_sdp_attr_find(m->attr_count, m->attr, &STR_RTCP, NULL);
if (attr)
pjmedia_sdp_attr_remove(&m->attr_count, m->attr, attr);
+ /* If RTCP is not in use, we MUST send b=RS:0 and b=RR:0. */
+ pj_assert(m->bandw_count + 2 <= PJ_ARRAY_SIZE(m->bandw));
+ if (m->bandw_count + 2 <= PJ_ARRAY_SIZE(m->bandw)) {
+ m->bandw[m->bandw_count] = PJ_POOL_ZALLOC_T(sdp_pool,
+ pjmedia_sdp_bandw);
+ pj_memcpy(&m->bandw[m->bandw_count]->modifier, &STR_BANDW_RS,
+ sizeof(pj_str_t));
+ m->bandw_count++;
+ m->bandw[m->bandw_count] = PJ_POOL_ZALLOC_T(sdp_pool,
+ pjmedia_sdp_bandw);
+ pj_memcpy(&m->bandw[m->bandw_count]->modifier, &STR_BANDW_RR,
+ sizeof(pj_str_t));
+ m->bandw_count++;
+ }
}