RtcpIntervalCalculator { public static long calculateInterval(boolean initial, boolean weSent, int senders, int members, double rtcpAvgSize, double rtcpBw, double rtcpBwFraction, double senderBwFraction, double receiverBwFraction) { double c; int n; if (senders <= (members * senderBwFraction)) { if (weSent) { c = rtcpAvgSize / (senderBwFraction * rtcpBw); n = senders; } else { c = rtcpAvgSize / (receiverBwFraction * rtcpBw); n = members - senders; } } else { c = rtcpAvgSize / rtcpBw; n = members; } double tMin = initial ? INITIAL_MIN_TIME : MIN_TIME; double td = Math.max(tMin, n * c); double min = td * 0.5; double max = td * 1.5; double t = min + (max - min) * RANDOM.nextDouble(); return (long) ((t / COMPENSATION) * 1000); }  static long calculateInterval(boolean initial, boolean weSent,
			int senders, int members, double rtcpAvgSize, double rtcpBw,
			double rtcpBwFraction, double senderBwFraction,
			double receiverBwFraction); static final double MIN_TIME; static final double INITIAL_MIN_TIME; }
@Test public void testInitialReceiverInterval() { boolean initial = true; boolean weSent = false; int members = 2; int senders = 1; for(int i = 0; i < 1000; i++) { long interval = RtcpIntervalCalculator.calculateInterval(initial, weSent, senders, members, RTCP_AVG_SIZE, RTCP_BW, RTCP_BW_FRACTION, RTCP_SENDER_BW_FRACTION, RTCP_RECEIVER_BW_FRACTION); double c = RTCP_AVG_SIZE / RTCP_BW; int n = members; double tMin = RtcpIntervalCalculator.INITIAL_MIN_TIME; double tD = Math.max(tMin, n * c); double compensation = Math.E - (3.0 / 2.0); long lowT = (long) (((tD * 0.5) / compensation) * 1000); long highT = (long) (((tD * 1.5) / compensation) * 1000); String msg = String.format(INTERVAL_RANGE, interval, lowT, highT); Assert.assertTrue(msg, interval >= lowT); Assert.assertTrue(msg, interval <= highT); } }
@Test public void testReceiverIntervalWithSenderMinority() { boolean initial = false; boolean weSent = false; int members = 4; int senders = 1; for(int i = 0; i < 1000; i++) { long interval = RtcpIntervalCalculator.calculateInterval(initial, weSent, senders, members, RTCP_AVG_SIZE, RTCP_BW, RTCP_BW_FRACTION, RTCP_SENDER_BW_FRACTION, RTCP_RECEIVER_BW_FRACTION); double c = RTCP_AVG_SIZE / (RTCP_BW * RTCP_RECEIVER_BW_FRACTION); int n = members - senders; double tMin = RtcpIntervalCalculator.MIN_TIME; double tD = Math.max(tMin, n * c); double compensation = Math.E - (3.0 / 2.0); long lowT = (long) (((tD * 0.5) / compensation) * 1000); long highT = (long) (((tD * 1.5) / compensation) * 1000); String msg = String.format(INTERVAL_RANGE, interval, lowT, highT); Assert.assertTrue(msg, interval >= lowT); Assert.assertTrue(msg, interval <= highT); } }
@Test public void testInitialSenderIntervalWithSenderMinority() { boolean initial = true; boolean weSent = true; int members = 12; int senders = 3; for(int i = 0; i < 1000; i++) { long interval = RtcpIntervalCalculator.calculateInterval(initial, weSent, senders, members, RTCP_AVG_SIZE, RTCP_BW, RTCP_BW_FRACTION, RTCP_SENDER_BW_FRACTION, RTCP_RECEIVER_BW_FRACTION); double c = RTCP_AVG_SIZE / (RTCP_BW * RTCP_SENDER_BW_FRACTION); int n = senders; double tMin = RtcpIntervalCalculator.INITIAL_MIN_TIME; double tD = Math.max(tMin, n * c); double compensation = Math.E - (3.0 / 2.0); long lowT = (long) (((tD * 0.5) / compensation) * 1000); long highT = (long) (((tD * 1.5) / compensation) * 1000); String msg = String.format(INTERVAL_RANGE, interval, lowT, highT); Assert.assertTrue(msg, interval >= lowT); Assert.assertTrue(msg, interval <= highT); } }
@Test public void testSenderIntervalWithSenderMinority() { boolean initial = false; boolean weSent = true; int members = 8; int senders = 2; for(int i = 0; i < 1000; i++) { long interval = RtcpIntervalCalculator.calculateInterval(initial, weSent, senders, members, RTCP_AVG_SIZE, RTCP_BW, RTCP_BW_FRACTION, RTCP_SENDER_BW_FRACTION, RTCP_RECEIVER_BW_FRACTION); double c = RTCP_AVG_SIZE / (RTCP_BW * RTCP_SENDER_BW_FRACTION); int n = senders; double tMin = RtcpIntervalCalculator.MIN_TIME; double tD = Math.max(tMin, n * c); double compensation = Math.E - (3.0 / 2.0); long lowT = (long) (((tD * 0.5) / compensation) * 1000); long highT = (long) (((tD * 1.5) / compensation) * 1000); String msg = String.format(INTERVAL_RANGE, interval, lowT, highT); Assert.assertTrue(msg, interval >= lowT); Assert.assertTrue(msg, interval <= highT); } }