From d66929995ff62e92c6cb5177d059e85b902fd388 Mon Sep 17 00:00:00 2001 From: "henrik.lundin@webrtc.org" Date: Thu, 20 Mar 2014 12:04:09 +0000 Subject: [PATCH] Prevent playout delay wrap-around in VoiceEngine In the case where a network glitch causes a packet to arrive so late that the jitter buffer has gone into expand mode, the playout timestamp could have been increased to a value that is larger than the RTP timestamp of the late packet when it finally arrives. This causes the difference to be negative, and would make the value wrap (unsigned). With this fix, the difference is set to zero when the playout timestamp is ahead of the incoming RTP timestamp. Further down in the method, a zero-value will lead to the averaging filter not being updated. BUG=3080 R=henrika@webrtc.org, tina.legrand@webrtc.org Review URL: https://webrtc-codereview.appspot.com/10199004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@5735 4adac7df-926f-26a2-2b94-8c16560cd09d --- webrtc/voice_engine/channel.cc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/webrtc/voice_engine/channel.cc b/webrtc/voice_engine/channel.cc index e14ee78d4c..ea80570a7a 100644 --- a/webrtc/voice_engine/channel.cc +++ b/webrtc/voice_engine/channel.cc @@ -13,6 +13,7 @@ #include "webrtc/common.h" #include "webrtc/modules/audio_device/include/audio_device.h" #include "webrtc/modules/audio_processing/include/audio_processing.h" +#include "webrtc/modules/interface/module_common_types.h" #include "webrtc/modules/rtp_rtcp/interface/receive_statistics.h" #include "webrtc/modules/rtp_rtcp/interface/rtp_payload_registry.h" #include "webrtc/modules/rtp_rtcp/interface/rtp_receiver.h" @@ -4886,16 +4887,20 @@ void Channel::UpdatePacketDelay(uint32_t rtp_timestamp, // every incoming packet. uint32_t timestamp_diff_ms = (rtp_timestamp - jitter_buffer_playout_timestamp_) / (rtp_receive_frequency / 1000); + if (!IsNewerTimestamp(rtp_timestamp, jitter_buffer_playout_timestamp_) || + timestamp_diff_ms > (2 * kVoiceEngineMaxMinPlayoutDelayMs)) { + // If |jitter_buffer_playout_timestamp_| is newer than the incoming RTP + // timestamp, the resulting difference is negative, but is set to zero. + // This can happen when a network glitch causes a packet to arrive late, + // and during long comfort noise periods with clock drift. + timestamp_diff_ms = 0; + } uint16_t packet_delay_ms = (rtp_timestamp - _previousTimestamp) / (rtp_receive_frequency / 1000); _previousTimestamp = rtp_timestamp; - if (timestamp_diff_ms > (2 * kVoiceEngineMaxMinPlayoutDelayMs)) { - timestamp_diff_ms = 0; - } - if (timestamp_diff_ms == 0) return; if (packet_delay_ms >= 10 && packet_delay_ms <= 60) {