Revision: ea56f76e4df6
Author: Ivelin Ivanov <[email protected]>
Date: Fri Jan 4 21:04:10 2013
Log: - bug fix. current jitter buffer duration is calculated in RTP
timestamp
units, but it was compared to jitterBufferSize, which is in
milliseconds. Now both are compared in timestamp units. The choice is to
convert jitterBufferSize to ts units in order to better preserve
accuracy. Typically 8 ts units = 1 ms (clock rate 8KHz). Sometimes 16 ts
units = 1 ms (clock rate 16KHz).
http://code.google.com/p/mediaserver/source/detail?r=ea56f76e4df6
Modified:
/io/rtp/src/main/java/org/mobicents/media/server/impl/rtp/JitterBuffer.java
=======================================
---
/io/rtp/src/main/java/org/mobicents/media/server/impl/rtp/JitterBuffer.java
Fri Jan 4 20:48:06 2013
+++
/io/rtp/src/main/java/org/mobicents/media/server/impl/rtp/JitterBuffer.java
Fri Jan 4 21:04:10 2013
@@ -1,6 +1,5 @@
/*
- * JBoss, Home of Professional Open Source
- * Copyright 2011, Red Hat, Inc. and individual contributors
+ * Copyright 2012, Telestax, Inc. and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
@@ -53,9 +52,17 @@
* introduced can lead to conversational difficulty.
*
* @author oifa yulian
+ * @author Ivelin Ivanov
+ *
*/
public class JitterBuffer implements Serializable {
- //The underlying buffer size
+
+ /**
+ * serialVersionID is required for serializable classes
+ */
+ private static final long serialVersionUID = -179700214594330050L;
+
+ //The underlying buffer size
private static final int QUEUE_SIZE = 10;
//the underlying buffer
private ArrayList<Frame> queue = new ArrayList(QUEUE_SIZE);
@@ -65,9 +72,13 @@
//first received sequence number
private long isn = -1;
- //allowed jitter
+ //allowed jitter buffer size
private long jitterBufferSize;
+ // jitter buffer size in the current timestamp units
+ private long jitterBufferSizeInTimestampUnits;
+
+
//packet arrival dead line measured on RTP clock.
//initial value equals to infinity
private long arrivalDeadLine = 0;
@@ -220,7 +231,7 @@
//Since the RTP packet Payload Type (format) changed, it is
possible that the sampling rate/clock rate is different for the new format
// update current clock rate we use to convert timestamp units to
absolute time and vice versa
- rtpClock.setClockRate(this.format.getClockRate());
+ updateCurrentClockRate(this.format.getClockRate());
}
//if this is first packet then synchronize clock
@@ -316,7 +327,7 @@
//check if this buffer already full
if (!ready) {
- ready = !useBuffer || (duration >= jitterBufferSize && queue.size()
1);
+ ready = !useBuffer || (duration >= jitterBufferSizeInTimestampUnits
&& queue.size() > 1);
if (ready) {
if (listener != null) {
listener.onFill();
@@ -326,7 +337,13 @@
}
}
- /**
+
+ private void updateCurrentClockRate(int newClockRate) {
+ rtpClock.setClockRate(newClockRate);
+ jitterBufferSizeInTimestampUnits =
rtpClock.convertToRtpTime(jitterBufferSize);
+ }
+
+ /**
* Polls packet from buffer's head.
*
* @param timestamp the media time measured by reader