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
This commit is contained in:
henrik.lundin@webrtc.org
2014-03-20 12:04:09 +00:00
parent 800b8dbda6
commit d66929995f

View File

@ -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) {