# How can I get the transit time for packets for a jitter buffer?

I'm trying to wrap my head around the concept of a real jitter buffer. I'm basing the only knowledge that I have around this article:

http://toncar.cz/Tutorials/VoIP/VoIP_Basics_Jitter.html

In the jitter estimator formula, the value D(i-1, i) is the difference of relative transit times for the two packets. The difference is computed as

D(i,j) = (Rj - Ri) - (Sj - Si) = (Rj - Sj) - (Ri - Si)

Si is the timestamp from the packet i and Ri is the time of arrival for packet i.

I've been trying to figure out in my head how it's possible to get the time it takes a packet to get from one system to the other even using TCP. If I'm not mistaken, won't the timestamps on the two devices be out of sync even if I were to send them as headers? Even if I were to sync timestamps before beginning pushing out the audio data, wouldn't that be received several milliseconds afterwards making syncing not possible?

So my question is, how can I actually calculate how long it takes for packets to arrive at their destination to calculate jitter?

Let's say the sender's clock is `t` milliseconds faster than the receiver's clock. `t` changes over time due to drift, but in the 20 milliseconds between packets, that drift is essentially negligible. That means we must add `t` to every receiver timestamp in order to synchronize it with the sender's timestamp. Correcting for the unsynchronized clocks, the formula becomes:
``````D(i,j) = ((Rj + t) - (Ri + t)) - (Sj - Si)
Notice anything? Because we are only interested in the difference between timestamps, the `t` cancels out! If we really want to calculate `t`, and subsequently the latency, we can do it using techniques I described here, but it's not necessary if we only care about jitter.
• `i` and `j` are two consecutive packets. `Rj` is the receiver's timestamp for the current packet and `Ri` is the receiver's timestamp on the previous packet. `D(i,j)` is the difference in transit time between the two packets. Jul 6 '15 at 14:55