summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2006-04-07 15:01:51 +0000
committerBenny Prijono <bennylp@teluu.com>2006-04-07 15:01:51 +0000
commit280346e3dfb43813596d4b61a83ca224a3b98ebb (patch)
treed52d17a8bf0dec44e4599127b147ded59c840527
parentbaf5bf601d9dff3e6c7b27cfa5e111531400a20b (diff)
Randomize RTCP send interval to reduce collision risk
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@394 74dad513-b988-da41-8d7b-12977e46ad98
-rw-r--r--pjmedia/include/pjmedia/config.h43
-rw-r--r--pjmedia/src/pjmedia/rtcp.c6
-rw-r--r--pjmedia/src/pjmedia/stream.c30
-rw-r--r--pjsip-apps/src/samples/siprtp.c7
4 files changed, 68 insertions, 18 deletions
diff --git a/pjmedia/include/pjmedia/config.h b/pjmedia/include/pjmedia/config.h
index a0c8bcf2..918ab3ea 100644
--- a/pjmedia/include/pjmedia/config.h
+++ b/pjmedia/include/pjmedia/config.h
@@ -75,5 +75,48 @@
#endif
+/**
+ * Maximum frame duration (in msec) to be supported.
+ */
+#ifndef PJMEDIA_MAX_FRAME_DURATION_MS
+# define PJMEDIA_MAX_FRAME_DURATION_MS 200
+#endif
+
+
+/**
+ * Max packet size to support.
+ */
+#ifndef PJMEDIA_MAX_MTU
+# define PJMEDIA_MAX_MTU 1500
+#endif
+
+
+/**
+ * DTMF/telephone-event duration, in timestamp.
+ */
+#ifndef PJMEDIA_DTMF_DURATION
+# define PJMEDIA_DTMF_DURATION 1600 /* in timestamp */
+#endif
+
+
+/**
+ * Number of packets received from different source IP address from the
+ * remote address required to make the stream switch transmission
+ * to the source address.
+ */
+#ifndef PJMEDIA_RTP_NAT_PROBATION_CNT
+# define PJMEDIA_RTP_NAT_PROBATION_CNT 10
+#endif
+
+
+/**
+ * Interval to send RTCP packets, in msec
+ */
+#ifndef PJMEDIA_RTCP_INTERVAL
+# define PJMEDIA_RTCP_INTERVAL 5000 /* msec*/
+#endif
+
+
#endif /* __PJMEDIA_CONFIG_H__ */
+
diff --git a/pjmedia/src/pjmedia/rtcp.c b/pjmedia/src/pjmedia/rtcp.c
index 8755af52..d016768e 100644
--- a/pjmedia/src/pjmedia/rtcp.c
+++ b/pjmedia/src/pjmedia/rtcp.c
@@ -339,9 +339,11 @@ PJ_DEF(void) pjmedia_rtcp_rx_rtcp( pjmedia_rtcp_session *sess,
} else {
PJ_LOG(3, (THIS_FILE, "Internal NTP clock skew detected: "
- "lsr=%p, now=%p, dlsr=%p (%d:%03dms)",
+ "lsr=%p, now=%p, dlsr=%p (%d:%03dms), "
+ "diff=%d",
lsr, now, dlsr, dlsr/65536,
- (dlsr%65536)*1000/65536));
+ (dlsr%65536)*1000/65536,
+ dlsr-(now-lsr)));
}
}
diff --git a/pjmedia/src/pjmedia/stream.c b/pjmedia/src/pjmedia/stream.c
index 378d3670..aea571b3 100644
--- a/pjmedia/src/pjmedia/stream.c
+++ b/pjmedia/src/pjmedia/stream.c
@@ -38,13 +38,6 @@
#define ERRLEVEL 1
#define TRACE_(expr) stream_perror expr
#define TRC_(expr) PJ_LOG(4,expr)
-#define PJMEDIA_MAX_FRAME_DURATION_MS 200
-#define PJMEDIA_MAX_BUFFER_SIZE_MS 2000
-#define PJMEDIA_MAX_MTU 1500
-#define PJMEDIA_DTMF_DURATION 1600 /* in timestamp */
-#define PJMEDIA_RTP_NAT_PROBATION_CNT 10
-#define PJMEDIA_RTCP_INTERVAL 5 /* seconds */
-
/**
* Media channel.
@@ -341,13 +334,17 @@ static pj_status_t put_frame( pjmedia_port *port,
/* Check if this is the time to transmit RTCP packet */
if (stream->rtcp_tx_time == 0) {
+ unsigned first_interval;
+
+ first_interval = PJMEDIA_RTCP_INTERVAL + (pj_rand() % 2000);
stream->rtcp_tx_time = pj_ntohl(channel->rtp.out_hdr.ts) +
- PJMEDIA_RTCP_INTERVAL *
- stream->port.info.sample_rate;
+ first_interval* stream->port.info.sample_rate /
+ 1000;
} else if (pj_ntohl(channel->rtp.out_hdr.ts) >= stream->rtcp_tx_time) {
pjmedia_rtcp_pkt *rtcp_pkt;
pj_ssize_t size;
+ unsigned interval;
int len;
pjmedia_rtcp_build_rtcp(&stream->rtcp, &rtcp_pkt, &len);
@@ -355,13 +352,20 @@ static pj_status_t put_frame( pjmedia_port *port,
status = pj_sock_sendto(stream->skinfo.rtcp_sock, rtcp_pkt, &size, 0,
&stream->rem_rtcp_addr,
sizeof(stream->rem_rtcp_addr));
+#if 0
if (status != PJ_SUCCESS) {
- ;
+ char errmsg[PJ_ERR_MSG_SIZE];
+
+ pj_strerror(status, errmsg, sizeof(errmsg));
+ PJ_LOG(4,(THIS_FILE, "Error sending RTCP: %s [%d]",
+ errmsg, status));
}
-
+#endif
+
+ interval = PJMEDIA_RTCP_INTERVAL + (pj_rand() % 500);
stream->rtcp_tx_time = pj_ntohl(channel->rtp.out_hdr.ts) +
- PJMEDIA_RTCP_INTERVAL *
- stream->port.info.sample_rate;
+ interval * stream->port.info.sample_rate /
+ 1000;
}
/* Do nothing if we have nothing to transmit */
diff --git a/pjsip-apps/src/samples/siprtp.c b/pjsip-apps/src/samples/siprtp.c
index d4d5387e..415a9323 100644
--- a/pjsip-apps/src/samples/siprtp.c
+++ b/pjsip-apps/src/samples/siprtp.c
@@ -990,7 +990,7 @@ static pj_status_t create_sdp( pj_pool_t *pool,
*/
static int media_thread(void *arg)
{
- enum { RTCP_INTERVAL = 5 };
+ enum { RTCP_INTERVAL = 5000, RTCP_RAND = 2000 };
struct media_stream *strm = arg;
char packet[1500];
unsigned msec_interval;
@@ -1003,7 +1003,7 @@ static int media_thread(void *arg)
next_rtp.u64 += (freq.u64 * msec_interval / 1000);
next_rtcp = next_rtp;
- next_rtcp.u64 += (freq.u64 * RTCP_INTERVAL);
+ next_rtcp.u64 += (freq.u64 * (RTCP_INTERVAL+(pj_rand()%RTCP_RAND)) / 1000);
while (!strm->thread_quit_flag) {
@@ -1165,7 +1165,8 @@ static int media_thread(void *arg)
}
/* Schedule next send */
- next_rtcp.u64 += (freq.u64 * RTCP_INTERVAL);
+ next_rtcp.u64 += (freq.u64 * (RTCP_INTERVAL+(pj_rand()%RTCP_RAND)) /
+ 1000);
}
}