summaryrefslogtreecommitdiff
path: root/pjmedia
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2006-06-01 11:37:30 +0000
committerBenny Prijono <bennylp@teluu.com>2006-06-01 11:37:30 +0000
commit0a523ff1658aad0f96d7c325f3ae4327f1020d9e (patch)
tree553eb783e6d967e48af337c75bf95256c377591d /pjmedia
parent4d82c2e0f6790422e6e319ad80983e1e002fca85 (diff)
Added options in pjmedia UDP transport to disable source address checking
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@483 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjmedia')
-rw-r--r--pjmedia/include/pjmedia/transport_udp.h45
-rw-r--r--pjmedia/src/pjmedia/transport_udp.c57
2 files changed, 80 insertions, 22 deletions
diff --git a/pjmedia/include/pjmedia/transport_udp.h b/pjmedia/include/pjmedia/transport_udp.h
index a84da98c..e0b25ed6 100644
--- a/pjmedia/include/pjmedia/transport_udp.h
+++ b/pjmedia/include/pjmedia/transport_udp.h
@@ -29,25 +29,64 @@
/**
- * Create UDP stream transport.
+ * Options that can be specified when creating UDP transport.
+ */
+enum pjmedia_transport_udp_options
+{
+ /**
+ * Normally the UDP transport will continuously check the source address
+ * of incoming packets to see if it is different than the configured
+ * remote address, and switch the remote address to the source address
+ * of the packet if they are different after several packets are
+ * received.
+ * Specifying this option will disable this feature.
+ */
+ PJMEDIA_UDP_NO_SRC_ADDR_CHECKING = 1,
+};
+
+
+/**
+ * Create an RTP and RTCP sockets and bind RTP the socket to the specified
+ * port to create media transport.
+ *
+ * @param endpt The media endpoint instance.
+ * @param name Optional name to be assigned to the transport.
+ * @param port UDP port number for the RTP socket. The RTCP port number
+ * will be set to one above RTP port.
+ * @param options Options, bitmask of #pjmedia_transport_udp_options.
+ * @param p_tp Pointer to receive the transport instance.
+ *
+ * @return PJ_SUCCESS on success.
*/
PJ_DECL(pj_status_t) pjmedia_transport_udp_create(pjmedia_endpt *endpt,
const char *name,
int port,
+ unsigned options,
pjmedia_transport **p_tp);
/**
- * Create UDP stream transport from existing socket info.
+ * Create UDP stream transport from existing sockets. Use this function when
+ * the sockets have previously been created.
+ *
+ * @param endpt The media endpoint instance.
+ * @param name Optional name to be assigned to the transport.
+ * @param si Media socket info containing the RTP and RTCP sockets.
+ * @param options Options, bitmask of #pjmedia_transport_udp_options.
+ * @param p_tp Pointer to receive the transport instance.
+ *
+ * @return PJ_SUCCESS on success.
*/
PJ_DECL(pj_status_t) pjmedia_transport_udp_attach(pjmedia_endpt *endpt,
const char *name,
const pjmedia_sock_info *si,
+ unsigned options,
pjmedia_transport **p_tp);
/**
- * Close UDP transport.
+ * Close UDP transport. Application can also use the "destroy" member of
+ * media transport interface to close the UDP transport.
*/
PJ_DECL(pj_status_t) pjmedia_transport_udp_close(pjmedia_transport *tp);
diff --git a/pjmedia/src/pjmedia/transport_udp.c b/pjmedia/src/pjmedia/transport_udp.c
index 5ee8968a..6af2b124 100644
--- a/pjmedia/src/pjmedia/transport_udp.c
+++ b/pjmedia/src/pjmedia/transport_udp.c
@@ -36,7 +36,7 @@ struct transport_udp
pjmedia_transport base; /**< Base transport. */
pj_pool_t *pool; /**< Memory pool */
-
+ unsigned options; /**< Transport options. */
pjmedia_stream *stream; /**< Stream user (may be NULL) */
pj_sockaddr_in rem_rtp_addr; /**< Remote RTP address */
pj_sockaddr_in rem_rtcp_addr; /**< Remote RTCP address */
@@ -108,6 +108,7 @@ static pjmedia_transport_op transport_udp_op =
PJ_DEF(pj_status_t) pjmedia_transport_udp_create( pjmedia_endpt *endpt,
const char *name,
int port,
+ unsigned options,
pjmedia_transport **p_tp)
{
pjmedia_sock_info si;
@@ -152,7 +153,7 @@ PJ_DEF(pj_status_t) pjmedia_transport_udp_create( pjmedia_endpt *endpt,
/* Create UDP transport by attaching socket info */
- return pjmedia_transport_udp_attach( endpt, name, &si, p_tp);
+ return pjmedia_transport_udp_attach( endpt, name, &si, options, p_tp);
on_error:
@@ -170,6 +171,7 @@ on_error:
PJ_DEF(pj_status_t) pjmedia_transport_udp_attach( pjmedia_endpt *endpt,
const char *name,
const pjmedia_sock_info *si,
+ unsigned options,
pjmedia_transport **p_tp)
{
struct transport_udp *tp;
@@ -198,6 +200,7 @@ PJ_DEF(pj_status_t) pjmedia_transport_udp_attach( pjmedia_endpt *endpt,
tp = pj_pool_zalloc(pool, sizeof(struct transport_udp));
tp->pool = pool;
+ tp->options = options;
pj_ansi_strcpy(tp->base.name, name);
tp->base.op = &transport_udp_op;
@@ -319,24 +322,40 @@ static void on_rx_rtp( pj_ioqueue_key_t *key,
(*cb)(stream, udp->rtp_pkt, bytes_read);
/* See if source address of RTP packet is different than the
- * configured address.
+ * configured address, and switch RTP remote address to
+ * source packet address after several consecutive packets
+ * have been received.
*/
- if ((udp->rem_rtp_addr.sin_addr.s_addr !=
- udp->rtp_src_addr.sin_addr.s_addr) ||
- (udp->rem_rtp_addr.sin_port !=
- udp->rtp_src_addr.sin_port))
- {
- udp->rtp_src_cnt++;
-
- if (udp->rtp_src_cnt >= PJMEDIA_RTP_NAT_PROBATION_CNT) {
-
- udp->rem_rtp_addr = udp->rtp_src_addr;
- udp->rtp_src_cnt = 0;
-
- PJ_LOG(4,(udp->base.name,
- "Remote RTP address switched to %s:%d",
- pj_inet_ntoa(udp->rtp_src_addr.sin_addr),
- pj_ntohs(udp->rtp_src_addr.sin_port)));
+ if ((udp->options & PJMEDIA_UDP_NO_SRC_ADDR_CHECKING)==0) {
+ if ((udp->rem_rtp_addr.sin_addr.s_addr !=
+ udp->rtp_src_addr.sin_addr.s_addr) ||
+ (udp->rem_rtp_addr.sin_port !=
+ udp->rtp_src_addr.sin_port))
+ {
+ udp->rtp_src_cnt++;
+
+ if (udp->rtp_src_cnt >= PJMEDIA_RTP_NAT_PROBATION_CNT) {
+
+ pj_uint16_t port;
+
+ /* Set remote RTP address to source address */
+ udp->rem_rtp_addr = udp->rtp_src_addr;
+
+ /* Also update remote RTCP address */
+ pj_memcpy(&udp->rem_rtcp_addr, &udp->rem_rtp_addr,
+ sizeof(pj_sockaddr_in));
+ port = (pj_uint16_t)
+ (pj_ntohs(udp->rem_rtp_addr.sin_port)+1);
+ udp->rem_rtcp_addr.sin_port = pj_htons(port);
+
+ /* Reset counter */
+ udp->rtp_src_cnt = 0;
+
+ PJ_LOG(4,(udp->base.name,
+ "Remote RTP address switched to %s:%d",
+ pj_inet_ntoa(udp->rtp_src_addr.sin_addr),
+ pj_ntohs(udp->rtp_src_addr.sin_port)));
+ }
}
}