# Timestamp smoothing

To prevent RTP timestamp interruptions when switching from one source to another during a call, a timestamp smoothing (TS) algorithm is implemented in the server RTP audio and video endpoints. Examples of changing sources include:

- Switching from a bridging configuration to a playback configuration.

- Performing consecutive playbacks from different files as part of the same call.

The transmitting RTP endpoint uses a real-time clock to correlate the time difference between consecutive arriving packets and the difference in their timestamps. Only one input channel can be enabled at one time. A threshold parameter called TS Threshold (TST) determines if there is an interruption between sequential packets.

If | (TimeStamp1 – TimeStamp2) – (PktArrivalTime1 – PktArrivalTime2) | > TST, for packets arriving into the transmitting RTP endpoint, the endpoint generates a timestamp for Packet 2. This timestamp is based on the difference between the arrival times on packets 1 and 2, and not on the difference in timestamps between input TimeStamp1 and TimeStamp2.

For example, if the endpoint is transmitting single frames of AMR packets, then normally, if the threshold is not exceeded, TimeStamp2 = TimeStamp1+20ms. However, if the threshold is exceeded, the timestamp smoothing algorithm sets TimeStamp2 = TimeStamp1 + (PktArrivalTime2 - PktArrivalTime1).

Pass-through channels and IVR/Fusion channels supply packets with timestamps that are correlated to their measured arrival times because they are throttled within a single real-time system on the CG board. If these two paths are the only source of the packets, the threshold can be set to a small time value, for example 30 ms. the packets arriving through the pass-through channels, however, are subject to network jitter. The jitter can cause the timestamp smoothing algorithm to be invoked if the threshold is set too low. It is better to avoid this and, as such, the timestamp smoothing threshold parameter is application-configurable for both audio and video RTP endpoints. Each endpoint can be properly tuned to network conditions so it does not confuse the packets arriving late and the packets arriving from a new source (through a new channel).

Set the threshold parameter TST with mspSendCommand using a command identifier of MSP_CMD_RTPFDX_SET_TS_SMOOTHING_THRESH. The resolution of the threshold value is given in ms, and the value must lie in the 100 ms to 2000 ms range. The default threshold value is 100 ms. The following code fragment illustrates how to set the threshold:

msp_ENDPOINT_RTPFDX_SET_TS_THRESH thresh_cmd;
DWORD command;
thresh_cmd.value = H2NMS_DWORD(150); //150 ms, Endian adjusted
command = mspBuildCommand(MSP_ENDPOINT_RTPFDX_AUDIO,
MSP_CMD_RTPFDX_SET_TS_SMOOTHING_THRESH);
ret = mspSendCommand(EP_handle, command, (void*) thresh_cmd,
sizeof(msp_ENDPOINT_RTPFDX_SET_TS_THRESH));