diff --git a/webrtc/modules/video_coding/main/source/timestamp_extrapolator.cc b/webrtc/modules/video_coding/main/source/timestamp_extrapolator.cc index 2243c86ad..bde2f0a80 100644 --- a/webrtc/modules/video_coding/main/source/timestamp_extrapolator.cc +++ b/webrtc/modules/video_coding/main/source/timestamp_extrapolator.cc @@ -8,15 +8,14 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "webrtc/modules/video_coding/main/source/internal_defines.h" #include "webrtc/modules/video_coding/main/source/timestamp_extrapolator.h" -#include "webrtc/system_wrappers/interface/clock.h" + +#include namespace webrtc { -VCMTimestampExtrapolator::VCMTimestampExtrapolator(Clock* clock) +VCMTimestampExtrapolator::VCMTimestampExtrapolator(int64_t start_ms) : _rwLock(RWLockWrapper::CreateRWLock()), - _clock(clock), _startMs(0), _firstTimestamp(0), _wrapArounds(0), @@ -32,7 +31,7 @@ VCMTimestampExtrapolator::VCMTimestampExtrapolator(Clock* clock) _accDrift(6600), // in timestamp ticks, i.e. 15 ms _accMaxError(7000), _P11(1e10) { - Reset(); + Reset(start_ms); } VCMTimestampExtrapolator::~VCMTimestampExtrapolator() @@ -41,10 +40,10 @@ VCMTimestampExtrapolator::~VCMTimestampExtrapolator() } void -VCMTimestampExtrapolator::Reset() +VCMTimestampExtrapolator::Reset(int64_t start_ms) { WriteLockScoped wl(*_rwLock); - _startMs = _clock->TimeInMilliseconds(); + _startMs = start_ms; _prevMs = _startMs; _firstTimestamp = 0; _w[0] = 90.0; @@ -71,7 +70,7 @@ VCMTimestampExtrapolator::Update(int64_t tMs, uint32_t ts90khz) // Ten seconds without a complete frame. // Reset the extrapolator _rwLock->ReleaseLockExclusive(); - Reset(); + Reset(tMs); _rwLock->AcquireLockExclusive(); } else @@ -214,9 +213,12 @@ bool VCMTimestampExtrapolator::DelayChangeDetection(double error) { // CUSUM detection of sudden delay changes - error = (error > 0) ? VCM_MIN(error, _accMaxError) : VCM_MAX(error, -_accMaxError); - _detectorAccumulatorPos = VCM_MAX(_detectorAccumulatorPos + error - _accDrift, (double)0); - _detectorAccumulatorNeg = VCM_MIN(_detectorAccumulatorNeg + error + _accDrift, (double)0); + 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 diff --git a/webrtc/modules/video_coding/main/source/timestamp_extrapolator.h b/webrtc/modules/video_coding/main/source/timestamp_extrapolator.h index f3cf74f7b..151e4ded7 100644 --- a/webrtc/modules/video_coding/main/source/timestamp_extrapolator.h +++ b/webrtc/modules/video_coding/main/source/timestamp_extrapolator.h @@ -17,22 +17,19 @@ namespace webrtc { -class Clock; - class VCMTimestampExtrapolator { public: - explicit VCMTimestampExtrapolator(Clock* clock); + explicit VCMTimestampExtrapolator(int64_t start_ms); ~VCMTimestampExtrapolator(); void Update(int64_t tMs, uint32_t ts90khz); int64_t ExtrapolateLocalTime(uint32_t timestamp90khz); - void Reset(); + void Reset(int64_t start_ms); private: void CheckForWrapArounds(uint32_t ts90khz); bool DelayChangeDetection(double error); RWLockWrapper* _rwLock; - Clock* _clock; double _w[2]; double _P[2][2]; int64_t _startMs; diff --git a/webrtc/modules/video_coding/main/source/timing.cc b/webrtc/modules/video_coding/main/source/timing.cc index e5b563507..dd8218783 100644 --- a/webrtc/modules/video_coding/main/source/timing.cc +++ b/webrtc/modules/video_coding/main/source/timing.cc @@ -35,7 +35,8 @@ VCMTiming::VCMTiming(Clock* clock, prev_frame_timestamp_(0) { if (master_timing == NULL) { master_ = true; - ts_extrapolator_ = new VCMTimestampExtrapolator(clock_); + ts_extrapolator_ = + new VCMTimestampExtrapolator(clock_->TimeInMilliseconds()); } else { ts_extrapolator_ = master_timing->ts_extrapolator_; } @@ -50,7 +51,7 @@ VCMTiming::~VCMTiming() { void VCMTiming::Reset() { CriticalSectionScoped cs(crit_sect_); - ts_extrapolator_->Reset(); + ts_extrapolator_->Reset(clock_->TimeInMilliseconds()); codec_timer_.Reset(); render_delay_ms_ = kDefaultRenderDelayMs; min_playout_delay_ms_ = 0; diff --git a/webrtc/video_engine/vie_receiver.cc b/webrtc/video_engine/vie_receiver.cc index 34cade1fa..2775ac9f9 100644 --- a/webrtc/video_engine/vie_receiver.cc +++ b/webrtc/video_engine/vie_receiver.cc @@ -48,7 +48,8 @@ ViEReceiver::ViEReceiver(const int32_t channel_id, vcm_(module_vcm), remote_bitrate_estimator_(remote_bitrate_estimator), clock_(Clock::GetRealTimeClock()), - ts_extrapolator_(new VCMTimestampExtrapolator(clock_)), + ts_extrapolator_( + new VCMTimestampExtrapolator(clock_->TimeInMilliseconds())), rtp_dump_(NULL), receiving_(false), restored_packet_in_use_(false),