Move timestamp_extrapolator and rtp_to_ntp to system wrapper so that it can be shared by both audio and video engine.

BUG=3111
TEST=try bots
R=mflodman@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/13459004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@6074 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/webrtc/modules/modules.gyp b/webrtc/modules/modules.gyp
index 444c665..d7e7cf8 100644
--- a/webrtc/modules/modules.gyp
+++ b/webrtc/modules/modules.gyp
@@ -180,7 +180,6 @@
             'remote_bitrate_estimator/remote_bitrate_estimator_unittest_helper.cc',
             'remote_bitrate_estimator/remote_bitrate_estimator_unittest_helper.h',
             'remote_bitrate_estimator/remote_bitrate_estimators_test.cc',
-            'remote_bitrate_estimator/rtp_to_ntp_unittest.cc',
             'remote_bitrate_estimator/test/bwe_test_baselinefile.cc',
             'remote_bitrate_estimator/test/bwe_test_baselinefile.h',
             'remote_bitrate_estimator/test/bwe_test_fileutils.cc',
diff --git a/webrtc/modules/remote_bitrate_estimator/include/rtp_to_ntp.h b/webrtc/modules/remote_bitrate_estimator/include/rtp_to_ntp.h
deleted file mode 100644
index 08a4d46..0000000
--- a/webrtc/modules/remote_bitrate_estimator/include/rtp_to_ntp.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
- *
- *  Use of this source code is governed by a BSD-style license
- *  that can be found in the LICENSE file in the root of the source
- *  tree. An additional intellectual property rights grant can be found
- *  in the file PATENTS.  All contributing project authors may
- *  be found in the AUTHORS file in the root of the source tree.
- */
-
-#ifndef WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_INCLUDE_RTP_TO_NTP_H_
-#define WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_INCLUDE_RTP_TO_NTP_H_
-
-#include <list>
-
-#include "webrtc/typedefs.h"
-
-namespace webrtc {
-
-namespace synchronization {
-
-struct RtcpMeasurement {
-  RtcpMeasurement();
-  RtcpMeasurement(uint32_t ntp_secs, uint32_t ntp_frac, uint32_t timestamp);
-  uint32_t ntp_secs;
-  uint32_t ntp_frac;
-  uint32_t rtp_timestamp;
-};
-
-typedef std::list<RtcpMeasurement> RtcpList;
-
-// Updates |rtcp_list| with timestamps from the latest RTCP SR.
-// |new_rtcp_sr| will be set to true if these are the timestamps which have
-// never be added to |rtcp_list|.
-bool UpdateRtcpList(uint32_t ntp_secs,
-                    uint32_t ntp_frac,
-                    uint32_t rtp_timestamp,
-                    RtcpList* rtcp_list,
-                    bool* new_rtcp_sr);
-
-// Converts an RTP timestamp to the NTP domain in milliseconds using two
-// (RTP timestamp, NTP timestamp) pairs.
-bool RtpToNtpMs(int64_t rtp_timestamp, const RtcpList& rtcp,
-                int64_t* timestamp_in_ms);
-
-// Returns 1 there has been a forward wrap around, 0 if there has been no wrap
-// around and -1 if there has been a backwards wrap around (i.e. reordering).
-int CheckForWrapArounds(uint32_t rtp_timestamp, uint32_t rtcp_rtp_timestamp);
-}  // namespace synchronization
-}  // namespace webrtc
-
-#endif  // WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_INCLUDE_RTP_TO_NTP_H_
diff --git a/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator.gypi b/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator.gypi
index 810da46..7292cae 100644
--- a/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator.gypi
+++ b/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator.gypi
@@ -21,10 +21,8 @@
       'sources': [
         'include/bwe_defines.h',
         'include/remote_bitrate_estimator.h',
-        'include/rtp_to_ntp.h',
         'rate_statistics.cc',
         'rate_statistics.h',
-        'rtp_to_ntp.cc',
       ], # source
     },
     {
diff --git a/webrtc/modules/remote_bitrate_estimator/rtp_to_ntp.cc b/webrtc/modules/remote_bitrate_estimator/rtp_to_ntp.cc
deleted file mode 100644
index 775cd0d..0000000
--- a/webrtc/modules/remote_bitrate_estimator/rtp_to_ntp.cc
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
- *
- *  Use of this source code is governed by a BSD-style license
- *  that can be found in the LICENSE file in the root of the source
- *  tree. An additional intellectual property rights grant can be found
- *  in the file PATENTS.  All contributing project authors may
- *  be found in the AUTHORS file in the root of the source tree.
- */
-
-#include "webrtc/modules/remote_bitrate_estimator/include/rtp_to_ntp.h"
-
-#include "webrtc/system_wrappers/interface/clock.h"
-
-#include <assert.h>
-
-namespace webrtc {
-
-namespace synchronization {
-
-RtcpMeasurement::RtcpMeasurement()
-    : ntp_secs(0), ntp_frac(0), rtp_timestamp(0) {}
-
-RtcpMeasurement::RtcpMeasurement(uint32_t ntp_secs, uint32_t ntp_frac,
-                                 uint32_t timestamp)
-    : ntp_secs(ntp_secs), ntp_frac(ntp_frac), rtp_timestamp(timestamp) {}
-
-// Calculates the RTP timestamp frequency from two pairs of NTP and RTP
-// timestamps.
-bool CalculateFrequency(
-    int64_t rtcp_ntp_ms1,
-    uint32_t rtp_timestamp1,
-    int64_t rtcp_ntp_ms2,
-    uint32_t rtp_timestamp2,
-    double* frequency_khz) {
-  if (rtcp_ntp_ms1 <= rtcp_ntp_ms2) {
-    return false;
-  }
-  *frequency_khz = static_cast<double>(rtp_timestamp1 - rtp_timestamp2) /
-      static_cast<double>(rtcp_ntp_ms1 - rtcp_ntp_ms2);
-  return true;
-}
-
-// Detects if there has been a wraparound between |old_timestamp| and
-// |new_timestamp|, and compensates by adding 2^32 if that is the case.
-bool CompensateForWrapAround(uint32_t new_timestamp,
-                             uint32_t old_timestamp,
-                             int64_t* compensated_timestamp) {
-  assert(compensated_timestamp);
-  int64_t wraps = synchronization::CheckForWrapArounds(new_timestamp,
-                                                       old_timestamp);
-  if (wraps < 0) {
-    // Reordering, don't use this packet.
-    return false;
-  }
-  *compensated_timestamp = new_timestamp + (wraps << 32);
-  return true;
-}
-
-bool UpdateRtcpList(uint32_t ntp_secs,
-                    uint32_t ntp_frac,
-                    uint32_t rtp_timestamp,
-                    RtcpList* rtcp_list,
-                    bool* new_rtcp_sr) {
-  *new_rtcp_sr = false;
-  if (ntp_secs == 0 && ntp_frac == 0) {
-    return false;
-  }
-
-  RtcpMeasurement measurement;
-  measurement.ntp_secs = ntp_secs;
-  measurement.ntp_frac = ntp_frac;
-  measurement.rtp_timestamp = rtp_timestamp;
-
-  for (RtcpList::iterator it = rtcp_list->begin();
-       it != rtcp_list->end(); ++it) {
-    if (measurement.ntp_secs == (*it).ntp_secs &&
-        measurement.ntp_frac == (*it).ntp_frac) {
-      // This RTCP has already been added to the list.
-      return true;
-    }
-  }
-
-  // We need two RTCP SR reports to map between RTP and NTP. More than two will
-  // not improve the mapping.
-  if (rtcp_list->size() == 2) {
-    rtcp_list->pop_back();
-  }
-  rtcp_list->push_front(measurement);
-  *new_rtcp_sr = true;
-  return true;
-}
-
-// Converts |rtp_timestamp| to the NTP time base using the NTP and RTP timestamp
-// pairs in |rtcp|. The converted timestamp is returned in
-// |rtp_timestamp_in_ms|. This function compensates for wrap arounds in RTP
-// timestamps and returns false if it can't do the conversion due to reordering.
-bool RtpToNtpMs(int64_t rtp_timestamp,
-                const synchronization::RtcpList& rtcp,
-                int64_t* rtp_timestamp_in_ms) {
-  assert(rtcp.size() == 2);
-  int64_t rtcp_ntp_ms_new = Clock::NtpToMs(rtcp.front().ntp_secs,
-                                           rtcp.front().ntp_frac);
-  int64_t rtcp_ntp_ms_old = Clock::NtpToMs(rtcp.back().ntp_secs,
-                                           rtcp.back().ntp_frac);
-  int64_t rtcp_timestamp_new = rtcp.front().rtp_timestamp;
-  int64_t rtcp_timestamp_old = rtcp.back().rtp_timestamp;
-  if (!CompensateForWrapAround(rtcp_timestamp_new,
-                               rtcp_timestamp_old,
-                               &rtcp_timestamp_new)) {
-    return false;
-  }
-  double freq_khz;
-  if (!CalculateFrequency(rtcp_ntp_ms_new,
-                          rtcp_timestamp_new,
-                          rtcp_ntp_ms_old,
-                          rtcp_timestamp_old,
-                          &freq_khz)) {
-    return false;
-  }
-  double offset = rtcp_timestamp_new - freq_khz * rtcp_ntp_ms_new;
-  int64_t rtp_timestamp_unwrapped;
-  if (!CompensateForWrapAround(rtp_timestamp, rtcp_timestamp_old,
-                               &rtp_timestamp_unwrapped)) {
-    return false;
-  }
-  double rtp_timestamp_ntp_ms = (static_cast<double>(rtp_timestamp_unwrapped) -
-      offset) / freq_khz + 0.5f;
-  if (rtp_timestamp_ntp_ms < 0) {
-    return false;
-  }
-  *rtp_timestamp_in_ms = rtp_timestamp_ntp_ms;
-  return true;
-}
-
-int CheckForWrapArounds(uint32_t new_timestamp, uint32_t old_timestamp) {
-  if (new_timestamp < old_timestamp) {
-    // This difference should be less than -2^31 if we have had a wrap around
-    // (e.g. |new_timestamp| = 1, |rtcp_rtp_timestamp| = 2^32 - 1). Since it is
-    // cast to a int32_t, it should be positive.
-    if (static_cast<int32_t>(new_timestamp - old_timestamp) > 0) {
-      // Forward wrap around.
-      return 1;
-    }
-  } else if (static_cast<int32_t>(old_timestamp - new_timestamp) > 0) {
-    // This difference should be less than -2^31 if we have had a backward wrap
-    // around. Since it is cast to a int32_t, it should be positive.
-    return -1;
-  }
-  return 0;
-}
-}  // namespace synchronization
-}  // namespace webrtc
diff --git a/webrtc/modules/remote_bitrate_estimator/rtp_to_ntp_unittest.cc b/webrtc/modules/remote_bitrate_estimator/rtp_to_ntp_unittest.cc
deleted file mode 100644
index aff314a..0000000
--- a/webrtc/modules/remote_bitrate_estimator/rtp_to_ntp_unittest.cc
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
- *
- *  Use of this source code is governed by a BSD-style license
- *  that can be found in the LICENSE file in the root of the source
- *  tree. An additional intellectual property rights grant can be found
- *  in the file PATENTS.  All contributing project authors may
- *  be found in the AUTHORS file in the root of the source tree.
- */
-
-#include "testing/gtest/include/gtest/gtest.h"
-#include "webrtc/modules/remote_bitrate_estimator/include/rtp_to_ntp.h"
-
-namespace webrtc {
-
-TEST(WrapAroundTests, NoWrap) {
-  EXPECT_EQ(0, synchronization::CheckForWrapArounds(0xFFFFFFFF, 0xFFFFFFFE));
-  EXPECT_EQ(0, synchronization::CheckForWrapArounds(1, 0));
-  EXPECT_EQ(0, synchronization::CheckForWrapArounds(0x00010000, 0x0000FFFF));
-}
-
-TEST(WrapAroundTests, ForwardWrap) {
-  EXPECT_EQ(1, synchronization::CheckForWrapArounds(0, 0xFFFFFFFF));
-  EXPECT_EQ(1, synchronization::CheckForWrapArounds(0, 0xFFFF0000));
-  EXPECT_EQ(1, synchronization::CheckForWrapArounds(0x0000FFFF, 0xFFFFFFFF));
-  EXPECT_EQ(1, synchronization::CheckForWrapArounds(0x0000FFFF, 0xFFFF0000));
-}
-
-TEST(WrapAroundTests, BackwardWrap) {
-  EXPECT_EQ(-1, synchronization::CheckForWrapArounds(0xFFFFFFFF, 0));
-  EXPECT_EQ(-1, synchronization::CheckForWrapArounds(0xFFFF0000, 0));
-  EXPECT_EQ(-1, synchronization::CheckForWrapArounds(0xFFFFFFFF, 0x0000FFFF));
-  EXPECT_EQ(-1, synchronization::CheckForWrapArounds(0xFFFF0000, 0x0000FFFF));
-}
-
-TEST(WrapAroundTests, OldRtcpWrapped) {
-  synchronization::RtcpList rtcp;
-  uint32_t ntp_sec = 0;
-  uint32_t ntp_frac = 0;
-  uint32_t timestamp = 0;
-  const uint32_t kOneMsInNtpFrac = 4294967;
-  const uint32_t kTimestampTicksPerMs = 90;
-  rtcp.push_front(synchronization::RtcpMeasurement(ntp_sec, ntp_frac,
-                                                   timestamp));
-  ntp_frac += kOneMsInNtpFrac;
-  timestamp -= kTimestampTicksPerMs;
-  rtcp.push_front(synchronization::RtcpMeasurement(ntp_sec, ntp_frac,
-                                                   timestamp));
-  ntp_frac += kOneMsInNtpFrac;
-  timestamp -= kTimestampTicksPerMs;
-  int64_t timestamp_in_ms = -1;
-  // This expected to fail since it's highly unlikely that the older RTCP
-  // has a much smaller RTP timestamp than the newer.
-  EXPECT_FALSE(synchronization::RtpToNtpMs(timestamp, rtcp, &timestamp_in_ms));
-}
-
-TEST(WrapAroundTests, NewRtcpWrapped) {
-  synchronization::RtcpList rtcp;
-  uint32_t ntp_sec = 0;
-  uint32_t ntp_frac = 0;
-  uint32_t timestamp = 0xFFFFFFFF;
-  const uint32_t kOneMsInNtpFrac = 4294967;
-  const uint32_t kTimestampTicksPerMs = 90;
-  rtcp.push_front(synchronization::RtcpMeasurement(ntp_sec, ntp_frac,
-                                                         timestamp));
-  ntp_frac += kOneMsInNtpFrac;
-  timestamp += kTimestampTicksPerMs;
-  rtcp.push_front(synchronization::RtcpMeasurement(ntp_sec, ntp_frac,
-                                                         timestamp));
-  int64_t timestamp_in_ms = -1;
-  EXPECT_TRUE(synchronization::RtpToNtpMs(rtcp.back().rtp_timestamp, rtcp,
-                                          &timestamp_in_ms));
-  // Since this RTP packet has the same timestamp as the RTCP packet constructed
-  // at time 0 it should be mapped to 0 as well.
-  EXPECT_EQ(0, timestamp_in_ms);
-}
-
-TEST(WrapAroundTests, RtpWrapped) {
-  const uint32_t kOneMsInNtpFrac = 4294967;
-  const uint32_t kTimestampTicksPerMs = 90;
-  synchronization::RtcpList rtcp;
-  uint32_t ntp_sec = 0;
-  uint32_t ntp_frac = 0;
-  uint32_t timestamp = 0xFFFFFFFF - 2 * kTimestampTicksPerMs;
-  rtcp.push_front(synchronization::RtcpMeasurement(ntp_sec, ntp_frac,
-                                                   timestamp));
-  ntp_frac += kOneMsInNtpFrac;
-  timestamp += kTimestampTicksPerMs;
-  rtcp.push_front(synchronization::RtcpMeasurement(ntp_sec, ntp_frac,
-                                                   timestamp));
-  ntp_frac += kOneMsInNtpFrac;
-  timestamp += kTimestampTicksPerMs;
-  int64_t timestamp_in_ms = -1;
-  EXPECT_TRUE(synchronization::RtpToNtpMs(timestamp, rtcp,
-                                          &timestamp_in_ms));
-  // Since this RTP packet has the same timestamp as the RTCP packet constructed
-  // at time 0 it should be mapped to 0 as well.
-  EXPECT_EQ(2, timestamp_in_ms);
-}
-
-TEST(WrapAroundTests, OldRtp_RtcpsWrapped) {
-  const uint32_t kOneMsInNtpFrac = 4294967;
-  const uint32_t kTimestampTicksPerMs = 90;
-  synchronization::RtcpList rtcp;
-  uint32_t ntp_sec = 0;
-  uint32_t ntp_frac = 0;
-  uint32_t timestamp = 0;
-  rtcp.push_front(synchronization::RtcpMeasurement(ntp_sec, ntp_frac,
-                                                   timestamp));
-  ntp_frac += kOneMsInNtpFrac;
-  timestamp += kTimestampTicksPerMs;
-  rtcp.push_front(synchronization::RtcpMeasurement(ntp_sec, ntp_frac,
-                                                   timestamp));
-  ntp_frac += kOneMsInNtpFrac;
-  timestamp -= 2*kTimestampTicksPerMs;
-  int64_t timestamp_in_ms = -1;
-  EXPECT_FALSE(synchronization::RtpToNtpMs(timestamp, rtcp,
-                                           &timestamp_in_ms));
-}
-
-TEST(WrapAroundTests, OldRtp_NewRtcpWrapped) {
-  const uint32_t kOneMsInNtpFrac = 4294967;
-  const uint32_t kTimestampTicksPerMs = 90;
-  synchronization::RtcpList rtcp;
-  uint32_t ntp_sec = 0;
-  uint32_t ntp_frac = 0;
-  uint32_t timestamp = 0xFFFFFFFF;
-  rtcp.push_front(synchronization::RtcpMeasurement(ntp_sec, ntp_frac,
-                                                   timestamp));
-  ntp_frac += kOneMsInNtpFrac;
-  timestamp += kTimestampTicksPerMs;
-  rtcp.push_front(synchronization::RtcpMeasurement(ntp_sec, ntp_frac,
-                                                   timestamp));
-  ntp_frac += kOneMsInNtpFrac;
-  timestamp -= kTimestampTicksPerMs;
-  int64_t timestamp_in_ms = -1;
-  EXPECT_TRUE(synchronization::RtpToNtpMs(timestamp, rtcp,
-                                          &timestamp_in_ms));
-  // Constructed at the same time as the first RTCP and should therefore be
-  // mapped to zero.
-  EXPECT_EQ(0, timestamp_in_ms);
-}
-
-TEST(WrapAroundTests, OldRtp_OldRtcpWrapped) {
-  const uint32_t kOneMsInNtpFrac = 4294967;
-  const uint32_t kTimestampTicksPerMs = 90;
-  synchronization::RtcpList rtcp;
-  uint32_t ntp_sec = 0;
-  uint32_t ntp_frac = 0;
-  uint32_t timestamp = 0;
-  rtcp.push_front(synchronization::RtcpMeasurement(ntp_sec, ntp_frac,
-                                                   timestamp));
-  ntp_frac += kOneMsInNtpFrac;
-  timestamp -= kTimestampTicksPerMs;
-  rtcp.push_front(synchronization::RtcpMeasurement(ntp_sec, ntp_frac,
-                                                   timestamp));
-  ntp_frac += kOneMsInNtpFrac;
-  timestamp += 2*kTimestampTicksPerMs;
-  int64_t timestamp_in_ms = -1;
-  EXPECT_FALSE(synchronization::RtpToNtpMs(timestamp, rtcp,
-                                           &timestamp_in_ms));
-}
-};  // namespace webrtc
diff --git a/webrtc/modules/video_coding/main/source/Android.mk b/webrtc/modules/video_coding/main/source/Android.mk
index 9ebdbed..a8cf2d0 100644
--- a/webrtc/modules/video_coding/main/source/Android.mk
+++ b/webrtc/modules/video_coding/main/source/Android.mk
@@ -37,7 +37,6 @@
     receiver.cc \
     rtt_filter.cc \
     session_info.cc \
-    timestamp_extrapolator.cc \
     timestamp_map.cc \
     timing.cc \
     video_coding_impl.cc
@@ -56,7 +55,7 @@
     $(LOCAL_PATH)/../../../../common_video/vplib/main/interface \
     $(LOCAL_PATH)/../../../../common_video/interface \
     $(LOCAL_PATH)/../../utility/include \
-    $(LOCAL_PATH)/../../../../system_wrappers/interface 
+    $(LOCAL_PATH)/../../../../system_wrappers/interface
 
 LOCAL_SHARED_LIBRARIES := \
     libcutils \
diff --git a/webrtc/modules/video_coding/main/source/timestamp_extrapolator.cc b/webrtc/modules/video_coding/main/source/timestamp_extrapolator.cc
deleted file mode 100644
index bde2f0a..0000000
--- a/webrtc/modules/video_coding/main/source/timestamp_extrapolator.cc
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
- *
- *  Use of this source code is governed by a BSD-style license
- *  that can be found in the LICENSE file in the root of the source
- *  tree. An additional intellectual property rights grant can be found
- *  in the file PATENTS.  All contributing project authors may
- *  be found in the AUTHORS file in the root of the source tree.
- */
-
-#include "webrtc/modules/video_coding/main/source/timestamp_extrapolator.h"
-
-#include <algorithm>
-
-namespace webrtc {
-
-VCMTimestampExtrapolator::VCMTimestampExtrapolator(int64_t start_ms)
-    : _rwLock(RWLockWrapper::CreateRWLock()),
-      _startMs(0),
-      _firstTimestamp(0),
-      _wrapArounds(0),
-      _prevUnwrappedTimestamp(-1),
-      _prevWrapTimestamp(-1),
-      _lambda(1),
-      _firstAfterReset(true),
-      _packetCount(0),
-      _startUpFilterDelayInPackets(2),
-      _detectorAccumulatorPos(0),
-      _detectorAccumulatorNeg(0),
-      _alarmThreshold(60e3),
-      _accDrift(6600),  // in timestamp ticks, i.e. 15 ms
-      _accMaxError(7000),
-      _P11(1e10) {
-    Reset(start_ms);
-}
-
-VCMTimestampExtrapolator::~VCMTimestampExtrapolator()
-{
-    delete _rwLock;
-}
-
-void
-VCMTimestampExtrapolator::Reset(int64_t start_ms)
-{
-    WriteLockScoped wl(*_rwLock);
-    _startMs = start_ms;
-    _prevMs = _startMs;
-    _firstTimestamp = 0;
-    _w[0] = 90.0;
-    _w[1] = 0;
-    _P[0][0] = 1;
-    _P[1][1] = _P11;
-    _P[0][1] = _P[1][0] = 0;
-    _firstAfterReset = true;
-    _prevUnwrappedTimestamp = -1;
-    _prevWrapTimestamp = -1;
-    _wrapArounds = 0;
-    _packetCount = 0;
-    _detectorAccumulatorPos = 0;
-    _detectorAccumulatorNeg = 0;
-}
-
-void
-VCMTimestampExtrapolator::Update(int64_t tMs, uint32_t ts90khz)
-{
-
-    _rwLock->AcquireLockExclusive();
-    if (tMs - _prevMs > 10e3)
-    {
-        // Ten seconds without a complete frame.
-        // Reset the extrapolator
-        _rwLock->ReleaseLockExclusive();
-        Reset(tMs);
-        _rwLock->AcquireLockExclusive();
-    }
-    else
-    {
-        _prevMs = tMs;
-    }
-
-    // Remove offset to prevent badly scaled matrices
-    tMs -= _startMs;
-
-    CheckForWrapArounds(ts90khz);
-
-    int64_t unwrapped_ts90khz = static_cast<int64_t>(ts90khz) +
-        _wrapArounds * ((static_cast<int64_t>(1) << 32) - 1);
-
-    if (_prevUnwrappedTimestamp >= 0 &&
-        unwrapped_ts90khz < _prevUnwrappedTimestamp)
-    {
-        // Drop reordered frames.
-        _rwLock->ReleaseLockExclusive();
-        return;
-    }
-
-    if (_firstAfterReset)
-    {
-        // Make an initial guess of the offset,
-        // should be almost correct since tMs - _startMs
-        // should about zero at this time.
-        _w[1] = -_w[0] * tMs;
-        _firstTimestamp = unwrapped_ts90khz;
-        _firstAfterReset = false;
-    }
-
-    double residual =
-        (static_cast<double>(unwrapped_ts90khz) - _firstTimestamp) -
-        static_cast<double>(tMs) * _w[0] - _w[1];
-    if (DelayChangeDetection(residual) &&
-        _packetCount >= _startUpFilterDelayInPackets)
-    {
-        // A sudden change of average network delay has been detected.
-        // Force the filter to adjust its offset parameter by changing
-        // the offset uncertainty. Don't do this during startup.
-        _P[1][1] = _P11;
-    }
-    //T = [t(k) 1]';
-    //that = T'*w;
-    //K = P*T/(lambda + T'*P*T);
-    double K[2];
-    K[0] = _P[0][0] * tMs + _P[0][1];
-    K[1] = _P[1][0] * tMs + _P[1][1];
-    double TPT = _lambda + tMs * K[0] + K[1];
-    K[0] /= TPT;
-    K[1] /= TPT;
-    //w = w + K*(ts(k) - that);
-    _w[0] = _w[0] + K[0] * residual;
-    _w[1] = _w[1] + K[1] * residual;
-    //P = 1/lambda*(P - K*T'*P);
-    double p00 = 1 / _lambda * (_P[0][0] - (K[0] * tMs * _P[0][0] + K[0] * _P[1][0]));
-    double p01 = 1 / _lambda * (_P[0][1] - (K[0] * tMs * _P[0][1] + K[0] * _P[1][1]));
-    _P[1][0] = 1 / _lambda * (_P[1][0] - (K[1] * tMs * _P[0][0] + K[1] * _P[1][0]));
-    _P[1][1] = 1 / _lambda * (_P[1][1] - (K[1] * tMs * _P[0][1] + K[1] * _P[1][1]));
-    _P[0][0] = p00;
-    _P[0][1] = p01;
-    _prevUnwrappedTimestamp = unwrapped_ts90khz;
-    if (_packetCount < _startUpFilterDelayInPackets)
-    {
-        _packetCount++;
-    }
-    _rwLock->ReleaseLockExclusive();
-}
-
-int64_t
-VCMTimestampExtrapolator::ExtrapolateLocalTime(uint32_t timestamp90khz)
-{
-    ReadLockScoped rl(*_rwLock);
-    int64_t localTimeMs = 0;
-    CheckForWrapArounds(timestamp90khz);
-    double unwrapped_ts90khz = static_cast<double>(timestamp90khz) +
-        _wrapArounds * ((static_cast<int64_t>(1) << 32) - 1);
-    if (_packetCount == 0)
-    {
-        localTimeMs = -1;
-    }
-    else if (_packetCount < _startUpFilterDelayInPackets)
-    {
-        localTimeMs = _prevMs + static_cast<int64_t>(
-            static_cast<double>(unwrapped_ts90khz - _prevUnwrappedTimestamp) /
-            90.0 + 0.5);
-    }
-    else
-    {
-        if (_w[0] < 1e-3)
-        {
-            localTimeMs = _startMs;
-        }
-        else
-        {
-            double timestampDiff = unwrapped_ts90khz -
-                static_cast<double>(_firstTimestamp);
-            localTimeMs = static_cast<int64_t>(
-                static_cast<double>(_startMs) + (timestampDiff - _w[1]) /
-                _w[0] + 0.5);
-        }
-    }
-    return localTimeMs;
-}
-
-// Investigates if the timestamp clock has overflowed since the last timestamp and
-// keeps track of the number of wrap arounds since reset.
-void
-VCMTimestampExtrapolator::CheckForWrapArounds(uint32_t ts90khz)
-{
-    if (_prevWrapTimestamp == -1)
-    {
-        _prevWrapTimestamp = ts90khz;
-        return;
-    }
-    if (ts90khz < _prevWrapTimestamp)
-    {
-        // This difference will probably be less than -2^31 if we have had a wrap around
-        // (e.g. timestamp = 1, _previousTimestamp = 2^32 - 1). Since it is casted to a Word32,
-        // it should be positive.
-        if (static_cast<int32_t>(ts90khz - _prevWrapTimestamp) > 0)
-        {
-            // Forward wrap around
-            _wrapArounds++;
-        }
-    }
-    // This difference will probably be less than -2^31 if we have had a backward wrap around.
-    // Since it is casted to a Word32, it should be positive.
-    else if (static_cast<int32_t>(_prevWrapTimestamp - ts90khz) > 0)
-    {
-        // Backward wrap around
-        _wrapArounds--;
-    }
-    _prevWrapTimestamp = ts90khz;
-}
-
-bool
-VCMTimestampExtrapolator::DelayChangeDetection(double error)
-{
-    // CUSUM detection of sudden delay changes
-    error = (error > 0) ? std::min(error, _accMaxError) :
-                          std::max(error, -_accMaxError);
-    _detectorAccumulatorPos =
-        std::max(_detectorAccumulatorPos + error - _accDrift, (double)0);
-    _detectorAccumulatorNeg =
-        std::min(_detectorAccumulatorNeg + error + _accDrift, (double)0);
-    if (_detectorAccumulatorPos > _alarmThreshold || _detectorAccumulatorNeg < -_alarmThreshold)
-    {
-        // Alarm
-        _detectorAccumulatorPos = _detectorAccumulatorNeg = 0;
-        return true;
-    }
-    return false;
-}
-
-}
diff --git a/webrtc/modules/video_coding/main/source/timestamp_extrapolator.h b/webrtc/modules/video_coding/main/source/timestamp_extrapolator.h
deleted file mode 100644
index 151e4de..0000000
--- a/webrtc/modules/video_coding/main/source/timestamp_extrapolator.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
- *
- *  Use of this source code is governed by a BSD-style license
- *  that can be found in the LICENSE file in the root of the source
- *  tree. An additional intellectual property rights grant can be found
- *  in the file PATENTS.  All contributing project authors may
- *  be found in the AUTHORS file in the root of the source tree.
- */
-
-#ifndef WEBRTC_MODULES_VIDEO_CODING_TIMESTAMP_EXTRAPOLATOR_H_
-#define WEBRTC_MODULES_VIDEO_CODING_TIMESTAMP_EXTRAPOLATOR_H_
-
-#include "webrtc/system_wrappers/interface/rw_lock_wrapper.h"
-#include "webrtc/typedefs.h"
-
-namespace webrtc
-{
-
-class VCMTimestampExtrapolator
-{
-public:
-    explicit VCMTimestampExtrapolator(int64_t start_ms);
-    ~VCMTimestampExtrapolator();
-    void Update(int64_t tMs, uint32_t ts90khz);
-    int64_t ExtrapolateLocalTime(uint32_t timestamp90khz);
-    void Reset(int64_t start_ms);
-
-private:
-    void CheckForWrapArounds(uint32_t ts90khz);
-    bool DelayChangeDetection(double error);
-    RWLockWrapper*        _rwLock;
-    double                _w[2];
-    double                _P[2][2];
-    int64_t         _startMs;
-    int64_t         _prevMs;
-    uint32_t        _firstTimestamp;
-    int32_t         _wrapArounds;
-    int64_t         _prevUnwrappedTimestamp;
-    int64_t         _prevWrapTimestamp;
-    const double          _lambda;
-    bool                  _firstAfterReset;
-    uint32_t        _packetCount;
-    const uint32_t  _startUpFilterDelayInPackets;
-
-    double              _detectorAccumulatorPos;
-    double              _detectorAccumulatorNeg;
-    const double        _alarmThreshold;
-    const double        _accDrift;
-    const double        _accMaxError;
-    const double        _P11;
-};
-
-}  // namespace webrtc
-
-#endif // WEBRTC_MODULES_VIDEO_CODING_TIMESTAMP_EXTRAPOLATOR_H_
diff --git a/webrtc/modules/video_coding/main/source/timing.cc b/webrtc/modules/video_coding/main/source/timing.cc
index dd82187..af0e35c 100644
--- a/webrtc/modules/video_coding/main/source/timing.cc
+++ b/webrtc/modules/video_coding/main/source/timing.cc
@@ -10,12 +10,10 @@
 
 #include "webrtc/modules/video_coding/main/source/timing.h"
 
-
 #include "webrtc/modules/video_coding/main/source/internal_defines.h"
 #include "webrtc/modules/video_coding/main/source/jitter_buffer_common.h"
-#include "webrtc/modules/video_coding/main/source/timestamp_extrapolator.h"
 #include "webrtc/system_wrappers/interface/clock.h"
-
+#include "webrtc/system_wrappers/interface/timestamp_extrapolator.h"
 
 
 namespace webrtc {
@@ -35,8 +33,7 @@
       prev_frame_timestamp_(0) {
   if (master_timing == NULL) {
     master_ = true;
-    ts_extrapolator_ =
-        new VCMTimestampExtrapolator(clock_->TimeInMilliseconds());
+    ts_extrapolator_ = new TimestampExtrapolator(clock_->TimeInMilliseconds());
   } else {
     ts_extrapolator_ = master_timing->ts_extrapolator_;
   }
diff --git a/webrtc/modules/video_coding/main/source/timing.h b/webrtc/modules/video_coding/main/source/timing.h
index fcb0402..1dca5e6 100644
--- a/webrtc/modules/video_coding/main/source/timing.h
+++ b/webrtc/modules/video_coding/main/source/timing.h
@@ -18,7 +18,7 @@
 namespace webrtc {
 
 class Clock;
-class VCMTimestampExtrapolator;
+class TimestampExtrapolator;
 
 class VCMTiming {
  public:
@@ -101,7 +101,7 @@
   CriticalSectionWrapper* crit_sect_;
   Clock* clock_;
   bool master_;
-  VCMTimestampExtrapolator* ts_extrapolator_;
+  TimestampExtrapolator* ts_extrapolator_;
   VCMCodecTimer codec_timer_;
   uint32_t render_delay_ms_;
   uint32_t min_playout_delay_ms_;
diff --git a/webrtc/modules/video_coding/main/source/video_coding.gypi b/webrtc/modules/video_coding/main/source/video_coding.gypi
index b4f6cb7..f19a585 100644
--- a/webrtc/modules/video_coding/main/source/video_coding.gypi
+++ b/webrtc/modules/video_coding/main/source/video_coding.gypi
@@ -48,7 +48,6 @@
         'receiver.h',
         'rtt_filter.h',
         'session_info.h',
-        'timestamp_extrapolator.h',
         'timestamp_map.h',
         'timing.h',
         'video_coding_impl.h',
@@ -72,7 +71,6 @@
         'receiver.cc',
         'rtt_filter.cc',
         'session_info.cc',
-        'timestamp_extrapolator.cc',
         'timestamp_map.cc',
         'timing.cc',
         'video_coding_impl.cc',