# VoIP: Jitter Buffer for VoIP ## Study reference - [Jitter Buffer for Voice over IP](https://www.vocal.com/voip/jitter-buffer-for-voice-over-ip/) ## Topology ![](https://i.imgur.com/yaNEAri.png) - One of the key factors which has an impact on the overall voice quality in VoIP networks is the effectiveness of compensating for network jitter. - This is principally done by using a jitter buffer which should be realized such that it adapts to the packet transmission characteristic observed in a given transmission link. ## Jitter Buffer - 在 VoIP 環境, Jitter buffer 對語音品質有很大的影響, 其功用是儲存語音封包並緩和封包的抖動. - Jitter Buffer 是一塊 buffer 可以 queue住語音封包 Q: 為什麼要 queue住語音封包 A: 因為封包傳送的修先順序並不一定, 如果一來就撥出去, 這樣會無法即時順暢的撥出, 所以就會有個 queue 的存在.等到queue收集一些封包再先進先出的撥出, 中間如果有缺包, 就會先空著撥出前到達就插進去. ### Dynamic Jitter buffer - Jitter buffer size 越大會造成越大的delay, 聽起來越奇怪, 所以就提出了 dynamic jitter buffer - 偵測到有封包遺失的時候, 就把 jitter buffer 調大, 如果沒有掉封包的時候就把 buffer 調小, 這樣可以改善 delay很久或是沒聲音的狀況發生. 但是 ... jitter buffer size 調整的時候會有封包遺失的狀況, 也就會影響語音品質 Q: 有什麼情況下不能使用 Dynamic Jitter Buffer ? A: 傳送 FAX 的時候, 如果有發生封包遺失的話, 就很容易傳送失敗!! 或是說傳data(modem, FAX)的時候, 需要將 jitter buffer 固定大小!! ## RFC refer to jitter bffer parameters - The values reported in these fields SHOULD be the most recently obtained values at the time of reporting. 1. jitter buffer nominal delay (JB nominal): 16 bits This is the current nominal jitter buffer delay in milliseconds, which corresponds to the nominal jitter buffer delay for packets that arrive exactly on time. This parameter MUST be provided for both fixed and adaptive jitter buffer implementations. 2. jitter buffer maximum delay (JB maximum): 16 bits This is the current maximum jitter buffer delay in milliseconds which corresponds to the earliest arriving packet that would not be discarded. In simple queue implementations this may correspond to the nominal size. In adaptive jitter buffer implementations, this value may dynamically vary up to JB abs max (see below). This parameter MUST be provided for both fixed and adaptive jitter buffer implementations. 3. jitter buffer absolute maximum delay (JB abs max): 16 bits This is the absolute maximum delay in milliseconds that the adaptive jitter buffer can reach under worst case conditions. If this value exceeds 65535 milliseconds, then this field SHALL convey the value 65535. This parameter MUST be provided for adaptive jitter buffer implementations and its value MUST be set to JB maximum for fixed jitter buffer implementations. ### Souce code use jitter buffer parameter ~~~ c=1 int VoiceJitterBuffFixed = 0; int VoiceJitterBuffMin = 20; int VoiceJitterBuffMax = 100; int VoiceJitterBuffTarget = 20; int DataJitterBuffTarget = 100; // set to endpoint vrgEndptProvSet(lineId, EPPROV_VoiceJitterBuffFixed, &value, sizeof(int)); ~~~ #### project spec requirement: The jitter buffer must be 50-60 ms and adaptive. - 對於 VoiceJitterBuffTarget 跟 DataJitterBuffTarget 的解讀 1. DataJitterBuffTarget 是針對 data 也就是可能傳送 FAX, modem 使用的, 所以 jitter buffer 可以調大一點 2. VoiceJitterBuffTarget 則是針對 voice pkt, 所以 buffer 不能調太大, 不然delay會太久, 聽到的聲音就會覺得奇怪 3. 依照之前的設定方式: VoiceJitterBuffTarget 設定同 min: 50 DataJitterBuffTarget 設定同 max: 60 ### ASK BROADCOM question about voice jitter buffer - Q: confusion about voice jitter buffer mode setting A: The _VoiceJitter items are for voice mode and the _DataJitterBuffTarget is for VBD mode. 1. In voice mode, you have the choice of using fixed scheme or adaptive scheme by set _VoiceJitterBuffFixed to 1 or 0. When fixed scheme is used, the only item matter is _VoiceJitterBuffTarget. You should not set the target to 0 in this case. If you want to avoid JB underrun, the target should be set to the maximum of the known network jitter. Certainly this will cause more delay. In general, we do not recommend you to used fixed scheme in voice mode, unless you really don't like the adaptation in our adaptive scheme. 2. In VBD mode, the only configuration item available is _DataJitterBuffTarget, and fixed scheme is always used. Adaptive is not a choice. ###### tags: `VoIP` `Jitter`