Run git cl format --full on the C++ files in system_wrappers/

Specifically, this CL was generated by the following shell commands:

  cd system_wrappers
  for f in $(find . -type f | grep -E '[.](h|cc)$'); do echo >> $f; done
  git cl format --full

Followed by a revert of the changes to asm_defines.h since that file
is assembly and not C++, and a manual edit to clock.cc to add some
blank lines in the #include list to prevent `git cl format` from
sorting <MMSystem.h> before "rtc_base/win32.h".

I needed to do this because otherwise `git cl format` introduces a lot
of unrelated formatting changes in other CLs that move these files
(since `git cl format` will try to re-format all lines of a moved
file).

BUG=none

Change-Id: I083e23a57ce2899add3e60bbd539f03343c7c219
Reviewed-on: https://webrtc-review.googlesource.com/21161
Reviewed-by: Henrik Andreassson <henrika@webrtc.org>
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20600}
This commit is contained in:
Karl Wiberg 2017-11-08 12:26:07 +01:00 committed by Commit Bot
parent b93baffb0a
commit 79eb1d98eb
25 changed files with 322 additions and 372 deletions

View file

@ -18,17 +18,17 @@ namespace webrtc {
// Wrapper class for aligned arrays. Every row (and the first dimension) are // Wrapper class for aligned arrays. Every row (and the first dimension) are
// aligned to the given byte alignment. // aligned to the given byte alignment.
template<typename T> class AlignedArray { template <typename T>
class AlignedArray {
public: public:
AlignedArray(size_t rows, size_t cols, size_t alignment) AlignedArray(size_t rows, size_t cols, size_t alignment)
: rows_(rows), : rows_(rows), cols_(cols) {
cols_(cols) {
RTC_CHECK_GT(alignment, 0); RTC_CHECK_GT(alignment, 0);
head_row_ = static_cast<T**>(AlignedMalloc(rows_ * sizeof(*head_row_), head_row_ =
alignment)); static_cast<T**>(AlignedMalloc(rows_ * sizeof(*head_row_), alignment));
for (size_t i = 0; i < rows_; ++i) { for (size_t i = 0; i < rows_; ++i) {
head_row_[i] = static_cast<T*>(AlignedMalloc(cols_ * sizeof(**head_row_), head_row_[i] = static_cast<T*>(
alignment)); AlignedMalloc(cols_ * sizeof(**head_row_), alignment));
} }
} }
@ -39,13 +39,9 @@ template<typename T> class AlignedArray {
AlignedFree(head_row_); AlignedFree(head_row_);
} }
T* const* Array() { T* const* Array() { return head_row_; }
return head_row_;
}
const T* const* Array() const { const T* const* Array() const { return head_row_; }
return head_row_;
}
T* Row(size_t row) { T* Row(size_t row) {
RTC_CHECK_LE(row, rows_); RTC_CHECK_LE(row, rows_);
@ -67,13 +63,9 @@ template<typename T> class AlignedArray {
return Row(row)[col]; return Row(row)[col];
} }
size_t rows() const { size_t rows() const { return rows_; }
return rows_;
}
size_t cols() const { size_t cols() const { return cols_; }
return cols_;
}
private: private:
size_t rows_; size_t rows_;

View file

@ -36,12 +36,12 @@ void AlignedFree(void* mem_block);
// Templated versions to facilitate usage of aligned malloc without casting // Templated versions to facilitate usage of aligned malloc without casting
// to and from void*. // to and from void*.
template<typename T> template <typename T>
T* GetRightAlign(const T* ptr, size_t alignment) { T* GetRightAlign(const T* ptr, size_t alignment) {
return reinterpret_cast<T*>(GetRightAlign(reinterpret_cast<const void*>(ptr), return reinterpret_cast<T*>(
alignment)); GetRightAlign(reinterpret_cast<const void*>(ptr), alignment));
} }
template<typename T> template <typename T>
T* AlignedMalloc(size_t size, size_t alignment) { T* AlignedMalloc(size_t size, size_t alignment) {
return reinterpret_cast<T*>(AlignedMalloc(size, alignment)); return reinterpret_cast<T*>(AlignedMalloc(size, alignment));
} }
@ -49,11 +49,9 @@ T* AlignedMalloc(size_t size, size_t alignment) {
// Deleter for use with unique_ptr. E.g., use as // Deleter for use with unique_ptr. E.g., use as
// std::unique_ptr<Foo, AlignedFreeDeleter> foo; // std::unique_ptr<Foo, AlignedFreeDeleter> foo;
struct AlignedFreeDeleter { struct AlignedFreeDeleter {
inline void operator()(void* ptr) const { inline void operator()(void* ptr) const { AlignedFree(ptr); }
AlignedFree(ptr);
}
}; };
} // namespace webrtc } // namespace webrtc
#endif // SYSTEM_WRAPPERS_INCLUDE_ALIGNED_MALLOC_H_ #endif // SYSTEM_WRAPPERS_INCLUDE_ALIGNED_MALLOC_H_

View file

@ -18,17 +18,14 @@ extern "C" {
#include "typedefs.h" // NOLINT(build/include) #include "typedefs.h" // NOLINT(build/include)
// List of features in x86. // List of features in x86.
typedef enum { typedef enum { kSSE2, kSSE3 } CPUFeature;
kSSE2,
kSSE3
} CPUFeature;
// List of features in ARM. // List of features in ARM.
enum { enum {
kCPUFeatureARMv7 = (1 << 0), kCPUFeatureARMv7 = (1 << 0),
kCPUFeatureVFPv3 = (1 << 1), kCPUFeatureVFPv3 = (1 << 1),
kCPUFeatureNEON = (1 << 2), kCPUFeatureNEON = (1 << 2),
kCPUFeatureLDREXSTREX = (1 << 3) kCPUFeatureLDREXSTREX = (1 << 3)
}; };
typedef int (*WebRtc_CPUInfo)(CPUFeature feature); typedef int (*WebRtc_CPUInfo)(CPUFeature feature);
@ -48,4 +45,4 @@ extern uint64_t WebRtc_GetCPUFeaturesARM(void);
} // extern "C" } // extern "C"
#endif #endif
#endif // SYSTEM_WRAPPERS_INCLUDE_CPU_FEATURES_WRAPPER_H_ #endif // SYSTEM_WRAPPERS_INCLUDE_CPU_FEATURES_WRAPPER_H_

View file

@ -25,4 +25,4 @@ class CpuInfo {
} // namespace webrtc } // namespace webrtc
#endif // SYSTEM_WRAPPERS_INCLUDE_CPU_INFO_H_ #endif // SYSTEM_WRAPPERS_INCLUDE_CPU_INFO_H_

View file

@ -62,7 +62,6 @@ class EventTimerWrapper : public EventWrapper {
virtual bool StartTimer(bool periodic, unsigned long time) = 0; virtual bool StartTimer(bool periodic, unsigned long time) = 0;
virtual bool StopTimer() = 0; virtual bool StopTimer() = 0;
}; };
} // namespace webrtc } // namespace webrtc

View file

@ -61,7 +61,6 @@
// NOTE: It is recommended to do the Chromium review for modifications to // NOTE: It is recommended to do the Chromium review for modifications to
// histograms.xml before new metrics are committed to WebRTC. // histograms.xml before new metrics are committed to WebRTC.
// Macros for adding samples to a named histogram. // Macros for adding samples to a named histogram.
// Histogram for counters (exponentially spaced buckets). // Histogram for counters (exponentially spaced buckets).
@ -83,9 +82,10 @@
#define RTC_HISTOGRAM_COUNTS_100000(name, sample) \ #define RTC_HISTOGRAM_COUNTS_100000(name, sample) \
RTC_HISTOGRAM_COUNTS(name, sample, 1, 100000, 50) RTC_HISTOGRAM_COUNTS(name, sample, 1, 100000, 50)
#define RTC_HISTOGRAM_COUNTS(name, sample, min, max, bucket_count) \ #define RTC_HISTOGRAM_COUNTS(name, sample, min, max, bucket_count) \
RTC_HISTOGRAM_COMMON_BLOCK(name, sample, \ RTC_HISTOGRAM_COMMON_BLOCK(name, sample, \
webrtc::metrics::HistogramFactoryGetCounts(name, min, max, bucket_count)) webrtc::metrics::HistogramFactoryGetCounts( \
name, min, max, bucket_count))
#define RTC_HISTOGRAM_COUNTS_LINEAR(name, sample, min, max, bucket_count) \ #define RTC_HISTOGRAM_COUNTS_LINEAR(name, sample, min, max, bucket_count) \
RTC_HISTOGRAM_COMMON_BLOCK(name, sample, \ RTC_HISTOGRAM_COMMON_BLOCK(name, sample, \
@ -112,9 +112,10 @@
#define RTC_HISTOGRAM_COUNTS_SPARSE_100000(name, sample) \ #define RTC_HISTOGRAM_COUNTS_SPARSE_100000(name, sample) \
RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 100000, 50) RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 100000, 50)
#define RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, min, max, bucket_count) \ #define RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, min, max, bucket_count) \
RTC_HISTOGRAM_COMMON_BLOCK_SLOW(name, sample, \ RTC_HISTOGRAM_COMMON_BLOCK_SLOW(name, sample, \
webrtc::metrics::HistogramFactoryGetCounts(name, min, max, bucket_count)) webrtc::metrics::HistogramFactoryGetCounts( \
name, min, max, bucket_count))
// Histogram for percentage (evenly spaced buckets). // Histogram for percentage (evenly spaced buckets).
#define RTC_HISTOGRAM_PERCENTAGE_SPARSE(name, sample) \ #define RTC_HISTOGRAM_PERCENTAGE_SPARSE(name, sample) \
@ -142,7 +143,8 @@
// Histogram for enumerators (evenly spaced buckets). // Histogram for enumerators (evenly spaced buckets).
// |boundary| should be above the max enumerator sample. // |boundary| should be above the max enumerator sample.
#define RTC_HISTOGRAM_ENUMERATION(name, sample, boundary) \ #define RTC_HISTOGRAM_ENUMERATION(name, sample, boundary) \
RTC_HISTOGRAM_COMMON_BLOCK(name, sample, \ RTC_HISTOGRAM_COMMON_BLOCK( \
name, sample, \
webrtc::metrics::HistogramFactoryGetEnumeration(name, boundary)) webrtc::metrics::HistogramFactoryGetEnumeration(name, boundary))
// The name of the histogram should not vary. // The name of the histogram should not vary.
@ -185,36 +187,36 @@
// is cached. |index| should be different for different names. Allowed |index| // is cached. |index| should be different for different names. Allowed |index|
// values are 0, 1, and 2. // values are 0, 1, and 2.
#define RTC_HISTOGRAMS_COUNTS_100(index, name, sample) \ #define RTC_HISTOGRAMS_COUNTS_100(index, name, sample) \
RTC_HISTOGRAMS_COMMON(index, name, sample, \ RTC_HISTOGRAMS_COMMON(index, name, sample, \
RTC_HISTOGRAM_COUNTS(name, sample, 1, 100, 50)) RTC_HISTOGRAM_COUNTS(name, sample, 1, 100, 50))
#define RTC_HISTOGRAMS_COUNTS_200(index, name, sample) \ #define RTC_HISTOGRAMS_COUNTS_200(index, name, sample) \
RTC_HISTOGRAMS_COMMON(index, name, sample, \ RTC_HISTOGRAMS_COMMON(index, name, sample, \
RTC_HISTOGRAM_COUNTS(name, sample, 1, 200, 50)) RTC_HISTOGRAM_COUNTS(name, sample, 1, 200, 50))
#define RTC_HISTOGRAMS_COUNTS_500(index, name, sample) \ #define RTC_HISTOGRAMS_COUNTS_500(index, name, sample) \
RTC_HISTOGRAMS_COMMON(index, name, sample, \ RTC_HISTOGRAMS_COMMON(index, name, sample, \
RTC_HISTOGRAM_COUNTS(name, sample, 1, 500, 50)) RTC_HISTOGRAM_COUNTS(name, sample, 1, 500, 50))
#define RTC_HISTOGRAMS_COUNTS_1000(index, name, sample) \ #define RTC_HISTOGRAMS_COUNTS_1000(index, name, sample) \
RTC_HISTOGRAMS_COMMON(index, name, sample, \ RTC_HISTOGRAMS_COMMON(index, name, sample, \
RTC_HISTOGRAM_COUNTS(name, sample, 1, 1000, 50)) RTC_HISTOGRAM_COUNTS(name, sample, 1, 1000, 50))
#define RTC_HISTOGRAMS_COUNTS_10000(index, name, sample) \ #define RTC_HISTOGRAMS_COUNTS_10000(index, name, sample) \
RTC_HISTOGRAMS_COMMON(index, name, sample, \ RTC_HISTOGRAMS_COMMON(index, name, sample, \
RTC_HISTOGRAM_COUNTS(name, sample, 1, 10000, 50)) RTC_HISTOGRAM_COUNTS(name, sample, 1, 10000, 50))
#define RTC_HISTOGRAMS_COUNTS_100000(index, name, sample) \ #define RTC_HISTOGRAMS_COUNTS_100000(index, name, sample) \
RTC_HISTOGRAMS_COMMON(index, name, sample, \ RTC_HISTOGRAMS_COMMON(index, name, sample, \
RTC_HISTOGRAM_COUNTS(name, sample, 1, 100000, 50)) RTC_HISTOGRAM_COUNTS(name, sample, 1, 100000, 50))
#define RTC_HISTOGRAMS_ENUMERATION(index, name, sample, boundary) \ #define RTC_HISTOGRAMS_ENUMERATION(index, name, sample, boundary) \
RTC_HISTOGRAMS_COMMON(index, name, sample, \ RTC_HISTOGRAMS_COMMON(index, name, sample, \
RTC_HISTOGRAM_ENUMERATION(name, sample, boundary)) RTC_HISTOGRAM_ENUMERATION(name, sample, boundary))
#define RTC_HISTOGRAMS_PERCENTAGE(index, name, sample) \ #define RTC_HISTOGRAMS_PERCENTAGE(index, name, sample) \
RTC_HISTOGRAMS_COMMON(index, name, sample, \ RTC_HISTOGRAMS_COMMON(index, name, sample, \
RTC_HISTOGRAM_PERCENTAGE(name, sample)) RTC_HISTOGRAM_PERCENTAGE(name, sample))
#define RTC_HISTOGRAMS_COMMON(index, name, sample, macro_invocation) \ #define RTC_HISTOGRAMS_COMMON(index, name, sample, macro_invocation) \
do { \ do { \
@ -245,8 +247,10 @@ class Histogram;
// histogram). // histogram).
// Get histogram for counters. // Get histogram for counters.
Histogram* HistogramFactoryGetCounts( Histogram* HistogramFactoryGetCounts(const std::string& name,
const std::string& name, int min, int max, int bucket_count); int min,
int max,
int bucket_count);
// Get histogram for counters with linear bucket spacing. // Get histogram for counters with linear bucket spacing.
Histogram* HistogramFactoryGetCountsLinear(const std::string& name, Histogram* HistogramFactoryGetCountsLinear(const std::string& name,
@ -256,8 +260,8 @@ Histogram* HistogramFactoryGetCountsLinear(const std::string& name,
// Get histogram for enumerators. // Get histogram for enumerators.
// |boundary| should be above the max enumerator sample. // |boundary| should be above the max enumerator sample.
Histogram* HistogramFactoryGetEnumeration( Histogram* HistogramFactoryGetEnumeration(const std::string& name,
const std::string& name, int boundary); int boundary);
// Function for adding a |sample| to a histogram. // Function for adding a |sample| to a histogram.
void HistogramAdd(Histogram* histogram_pointer, int sample); void HistogramAdd(Histogram* histogram_pointer, int sample);

View file

@ -1,12 +1,12 @@
/* /*
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
* *
* Use of this source code is governed by a BSD-style license * 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 * that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found * tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may * in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#ifndef SYSTEM_WRAPPERS_INCLUDE_NTP_TIME_H_ #ifndef SYSTEM_WRAPPERS_INCLUDE_NTP_TIME_H_
#define SYSTEM_WRAPPERS_INCLUDE_NTP_TIME_H_ #define SYSTEM_WRAPPERS_INCLUDE_NTP_TIME_H_

View file

@ -14,43 +14,41 @@
#include "system_wrappers/include/rw_lock_wrapper.h" #include "system_wrappers/include/rw_lock_wrapper.h"
#include "typedefs.h" // NOLINT(build/include) #include "typedefs.h" // NOLINT(build/include)
namespace webrtc namespace webrtc {
{
class TimestampExtrapolator class TimestampExtrapolator {
{ public:
public: explicit TimestampExtrapolator(int64_t start_ms);
explicit TimestampExtrapolator(int64_t start_ms); ~TimestampExtrapolator();
~TimestampExtrapolator(); void Update(int64_t tMs, uint32_t ts90khz);
void Update(int64_t tMs, uint32_t ts90khz); int64_t ExtrapolateLocalTime(uint32_t timestamp90khz);
int64_t ExtrapolateLocalTime(uint32_t timestamp90khz); void Reset(int64_t start_ms);
void Reset(int64_t start_ms);
private: private:
void CheckForWrapArounds(uint32_t ts90khz); void CheckForWrapArounds(uint32_t ts90khz);
bool DelayChangeDetection(double error); bool DelayChangeDetection(double error);
RWLockWrapper* _rwLock; RWLockWrapper* _rwLock;
double _w[2]; double _w[2];
double _pP[2][2]; double _pP[2][2];
int64_t _startMs; int64_t _startMs;
int64_t _prevMs; int64_t _prevMs;
uint32_t _firstTimestamp; uint32_t _firstTimestamp;
int32_t _wrapArounds; int32_t _wrapArounds;
int64_t _prevUnwrappedTimestamp; int64_t _prevUnwrappedTimestamp;
int64_t _prevWrapTimestamp; int64_t _prevWrapTimestamp;
const double _lambda; const double _lambda;
bool _firstAfterReset; bool _firstAfterReset;
uint32_t _packetCount; uint32_t _packetCount;
const uint32_t _startUpFilterDelayInPackets; const uint32_t _startUpFilterDelayInPackets;
double _detectorAccumulatorPos; double _detectorAccumulatorPos;
double _detectorAccumulatorNeg; double _detectorAccumulatorNeg;
const double _alarmThreshold; const double _alarmThreshold;
const double _accDrift; const double _accDrift;
const double _accMaxError; const double _accMaxError;
const double _pP11; const double _pP11;
}; };
} // namespace webrtc } // namespace webrtc
#endif // SYSTEM_WRAPPERS_INCLUDE_TIMESTAMP_EXTRAPOLATOR_H_ #endif // SYSTEM_WRAPPERS_INCLUDE_TIMESTAMP_EXTRAPOLATOR_H_

View file

@ -30,7 +30,7 @@ bool CorrectUsage(size_t size, size_t alignment) {
if (scoped.get() == NULL) { if (scoped.get() == NULL) {
return false; return false;
} }
const uintptr_t scoped_address = reinterpret_cast<uintptr_t> (scoped.get()); const uintptr_t scoped_address = reinterpret_cast<uintptr_t>(scoped.get());
return 0u == scoped_address % alignment; return 0u == scoped_address % alignment;
} }
@ -41,10 +41,10 @@ TEST(AlignedMalloc, GetRightAlign) {
std::unique_ptr<char, AlignedFreeDeleter> scoped( std::unique_ptr<char, AlignedFreeDeleter> scoped(
static_cast<char*>(AlignedMalloc(size, alignment))); static_cast<char*>(AlignedMalloc(size, alignment)));
EXPECT_TRUE(scoped.get() != NULL); EXPECT_TRUE(scoped.get() != NULL);
const uintptr_t aligned_address = reinterpret_cast<uintptr_t> (scoped.get()); const uintptr_t aligned_address = reinterpret_cast<uintptr_t>(scoped.get());
const uintptr_t misaligned_address = aligned_address - left_misalignment; const uintptr_t misaligned_address = aligned_address - left_misalignment;
const char* misaligned_ptr = reinterpret_cast<const char*>( const char* misaligned_ptr =
misaligned_address); reinterpret_cast<const char*>(misaligned_address);
const char* realigned_ptr = GetRightAlign(misaligned_ptr, alignment); const char* realigned_ptr = GetRightAlign(misaligned_ptr, alignment);
EXPECT_EQ(scoped.get(), realigned_ptr); EXPECT_EQ(scoped.get(), realigned_ptr);
} }
@ -80,4 +80,3 @@ TEST(AlignedMalloc, AlignTo128Bytes) {
} }
} // namespace webrtc } // namespace webrtc

View file

@ -11,12 +11,17 @@
#include "system_wrappers/include/clock.h" #include "system_wrappers/include/clock.h"
#if defined(_WIN32) #if defined(_WIN32)
// Windows needs to be included before mmsystem.h // Windows needs to be included before mmsystem.h
#include "rtc_base/win32.h" #include "rtc_base/win32.h"
#include <MMSystem.h> #include <MMSystem.h>
#elif ((defined WEBRTC_LINUX) || (defined WEBRTC_MAC)) #elif ((defined WEBRTC_LINUX) || (defined WEBRTC_MAC))
#include <sys/time.h> #include <sys/time.h>
#include <time.h> #include <time.h>
#endif #endif
#include "rtc_base/criticalsection.h" #include "rtc_base/criticalsection.h"
@ -28,15 +33,11 @@ namespace webrtc {
class RealTimeClock : public Clock { class RealTimeClock : public Clock {
// Return a timestamp in milliseconds relative to some arbitrary source; the // Return a timestamp in milliseconds relative to some arbitrary source; the
// source is fixed for this clock. // source is fixed for this clock.
int64_t TimeInMilliseconds() const override { int64_t TimeInMilliseconds() const override { return rtc::TimeMillis(); }
return rtc::TimeMillis();
}
// Return a timestamp in microseconds relative to some arbitrary source; the // Return a timestamp in microseconds relative to some arbitrary source; the
// source is fixed for this clock. // source is fixed for this clock.
int64_t TimeInMicroseconds() const override { int64_t TimeInMicroseconds() const override { return rtc::TimeMicros(); }
return rtc::TimeMicros();
}
// Retrieve an NTP absolute timestamp. // Retrieve an NTP absolute timestamp.
NtpTime CurrentNtpTime() const override { NtpTime CurrentNtpTime() const override {
@ -56,13 +57,14 @@ class RealTimeClock : public Clock {
double microseconds_in_seconds; double microseconds_in_seconds;
Adjust(tv, &seconds, &microseconds_in_seconds); Adjust(tv, &seconds, &microseconds_in_seconds);
return 1000 * static_cast<int64_t>(seconds) + return 1000 * static_cast<int64_t>(seconds) +
static_cast<int64_t>(1000.0 * microseconds_in_seconds + 0.5); static_cast<int64_t>(1000.0 * microseconds_in_seconds + 0.5);
} }
protected: protected:
virtual timeval CurrentTimeVal() const = 0; virtual timeval CurrentTimeVal() const = 0;
static void Adjust(const timeval& tv, uint32_t* adjusted_s, static void Adjust(const timeval& tv,
uint32_t* adjusted_s,
double* adjusted_us_in_s) { double* adjusted_us_in_s) {
*adjusted_s = tv.tv_sec + kNtpJan1970; *adjusted_s = tv.tv_sec + kNtpJan1970;
*adjusted_us_in_s = tv.tv_usec / 1e6; *adjusted_us_in_s = tv.tv_usec / 1e6;
@ -107,8 +109,8 @@ class WindowsRealTimeClock : public RealTimeClock {
// speed stepping. // speed stepping.
GetTime(&StartTime); GetTime(&StartTime);
Time = (((uint64_t) StartTime.dwHighDateTime) << 32) + Time = (((uint64_t)StartTime.dwHighDateTime) << 32) +
(uint64_t) StartTime.dwLowDateTime; (uint64_t)StartTime.dwLowDateTime;
// Convert the hecto-nano second time to tv format. // Convert the hecto-nano second time to tv format.
Time -= FILETIME_1970; Time -= FILETIME_1970;
@ -226,11 +228,9 @@ Clock* Clock::GetRealTimeClock() {
} }
SimulatedClock::SimulatedClock(int64_t initial_time_us) SimulatedClock::SimulatedClock(int64_t initial_time_us)
: time_us_(initial_time_us), lock_(RWLockWrapper::CreateRWLock()) { : time_us_(initial_time_us), lock_(RWLockWrapper::CreateRWLock()) {}
}
SimulatedClock::~SimulatedClock() { SimulatedClock::~SimulatedClock() {}
}
int64_t SimulatedClock::TimeInMilliseconds() const { int64_t SimulatedClock::TimeInMilliseconds() const {
ReadLockScoped synchronize(*lock_); ReadLockScoped synchronize(*lock_);

View file

@ -30,18 +30,19 @@ int GetCPUInfoNoASM(CPUFeature feature) {
#if defined(__pic__) && defined(__i386__) #if defined(__pic__) && defined(__i386__)
static inline void __cpuid(int cpu_info[4], int info_type) { static inline void __cpuid(int cpu_info[4], int info_type) {
__asm__ volatile( __asm__ volatile(
"mov %%ebx, %%edi\n" "mov %%ebx, %%edi\n"
"cpuid\n" "cpuid\n"
"xchg %%edi, %%ebx\n" "xchg %%edi, %%ebx\n"
: "=a"(cpu_info[0]), "=D"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3]) : "=a"(cpu_info[0]), "=D"(cpu_info[1]), "=c"(cpu_info[2]),
: "a"(info_type)); "=d"(cpu_info[3])
: "a"(info_type));
} }
#else #else
static inline void __cpuid(int cpu_info[4], int info_type) { static inline void __cpuid(int cpu_info[4], int info_type) {
__asm__ volatile( __asm__ volatile("cpuid\n"
"cpuid\n" : "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]),
: "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3]) "=d"(cpu_info[3])
: "a"(info_type)); : "a"(info_type));
} }
#endif #endif
#endif // _MSC_VER #endif // _MSC_VER

View file

@ -11,8 +11,8 @@
#include "system_wrappers/include/cpu_info.h" #include "system_wrappers/include/cpu_info.h"
#if defined(WEBRTC_WIN) #if defined(WEBRTC_WIN)
#include <winsock2.h>
#include <windows.h> #include <windows.h>
#include <winsock2.h>
#ifndef EXCLUDE_D3D9 #ifndef EXCLUDE_D3D9
#include <d3d9.h> #include <d3d9.h>
#endif #endif
@ -51,7 +51,7 @@ static int DetectNumberOfCores() {
return number_of_cores; return number_of_cores;
} }
} } // namespace internal
namespace webrtc { namespace webrtc {

View file

@ -37,8 +37,9 @@ class EventWrapperImpl : public EventWrapper {
} }
EventTypeWrapper Wait(unsigned long max_time) override { EventTypeWrapper Wait(unsigned long max_time) override {
int to_wait = max_time == WEBRTC_EVENT_INFINITE ? int to_wait = max_time == WEBRTC_EVENT_INFINITE
rtc::Event::kForever : static_cast<int>(max_time); ? rtc::Event::kForever
: static_cast<int>(max_time);
return event_.Wait(to_wait) ? kEventSignaled : kEventTimeout; return event_.Wait(to_wait) ? kEventSignaled : kEventTimeout;
} }

View file

@ -160,7 +160,7 @@ bool EventTimerPosix::StartTimer(bool periodic, unsigned long time_ms) {
// Timer already started. // Timer already started.
pthread_mutex_unlock(&mutex_); pthread_mutex_unlock(&mutex_);
return false; return false;
} else { } else {
// New one shot timer. // New one shot timer.
time_ms_ = time_ms; time_ms_ = time_ms;
created_at_.tv_sec = 0; created_at_.tv_sec = 0;

View file

@ -22,10 +22,7 @@
namespace webrtc { namespace webrtc {
enum State { enum State { kUp = 1, kDown = 2 };
kUp = 1,
kDown = 2
};
class EventTimerPosix : public EventTimerWrapper { class EventTimerPosix : public EventTimerWrapper {
public: public:
@ -47,16 +44,16 @@ class EventTimerPosix : public EventTimerWrapper {
virtual rtc::PlatformThread* CreateThread(); virtual rtc::PlatformThread* CreateThread();
pthread_cond_t cond_; pthread_cond_t cond_;
pthread_mutex_t mutex_; pthread_mutex_t mutex_;
bool event_set_; bool event_set_;
// TODO(pbos): Remove unique_ptr and use PlatformThread directly. // TODO(pbos): Remove unique_ptr and use PlatformThread directly.
std::unique_ptr<rtc::PlatformThread> timer_thread_; std::unique_ptr<rtc::PlatformThread> timer_thread_;
std::unique_ptr<EventTimerPosix> timer_event_; std::unique_ptr<EventTimerPosix> timer_event_;
timespec created_at_; timespec created_at_;
bool periodic_; bool periodic_;
unsigned long time_ms_; unsigned long time_ms_;
unsigned long count_; unsigned long count_;
bool is_stopping_; bool is_stopping_;

View file

@ -24,8 +24,7 @@ EventTimerWin::EventTimerWin()
FALSE, // manual reset FALSE, // manual reset
FALSE, // initial state FALSE, // initial state
NULL)), // name of event NULL)), // name of event
timerID_(NULL) { timerID_(NULL) {}
}
EventTimerWin::~EventTimerWin() { EventTimerWin::~EventTimerWin() {
StopTimer(); StopTimer();

View file

@ -31,7 +31,7 @@ class EventTimerWin : public EventTimerWrapper {
virtual bool StopTimer(); virtual bool StopTimer();
private: private:
HANDLE event_; HANDLE event_;
uint32_t timerID_; uint32_t timerID_;
}; };

View file

@ -7,8 +7,8 @@
// be found in the AUTHORS file in the root of the source tree. // be found in the AUTHORS file in the root of the source tree.
// //
#include "system_wrappers/include/field_trial.h"
#include "system_wrappers/include/field_trial_default.h" #include "system_wrappers/include/field_trial_default.h"
#include "system_wrappers/include/field_trial.h"
#include <string> #include <string>
@ -17,7 +17,7 @@
namespace webrtc { namespace webrtc {
namespace field_trial { namespace field_trial {
static const char *trials_init_string = NULL; static const char* trials_init_string = NULL;
std::string FindFullName(const std::string& name) { std::string FindFullName(const std::string& name) {
if (trials_init_string == NULL) if (trials_init_string == NULL)
@ -30,21 +30,20 @@ std::string FindFullName(const std::string& name) {
static const char kPersistentStringSeparator = '/'; static const char kPersistentStringSeparator = '/';
size_t next_item = 0; size_t next_item = 0;
while (next_item < trials_string.length()) { while (next_item < trials_string.length()) {
// Find next name/value pair in field trial configuration string. // Find next name/value pair in field trial configuration string.
size_t field_name_end = trials_string.find( size_t field_name_end =
kPersistentStringSeparator, next_item); trials_string.find(kPersistentStringSeparator, next_item);
if (field_name_end == trials_string.npos || field_name_end == next_item) if (field_name_end == trials_string.npos || field_name_end == next_item)
break; break;
size_t field_value_end = trials_string.find( size_t field_value_end =
kPersistentStringSeparator, field_name_end + 1); trials_string.find(kPersistentStringSeparator, field_name_end + 1);
if (field_value_end == trials_string.npos || if (field_value_end == trials_string.npos ||
field_value_end == field_name_end + 1) field_value_end == field_name_end + 1)
break; break;
std::string field_name(trials_string, next_item, std::string field_name(trials_string, next_item,
field_name_end - next_item); field_name_end - next_item);
std::string field_value(trials_string, field_name_end + 1, std::string field_value(trials_string, field_name_end + 1,
field_value_end - field_name_end - 1); field_value_end - field_name_end - 1);
next_item = field_value_end + 1; next_item = field_value_end + 1;
if (name == field_name) if (name == field_name)

View file

@ -8,8 +8,8 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#include "system_wrappers/include/metrics.h"
#include "system_wrappers/include/metrics_default.h" #include "system_wrappers/include/metrics_default.h"
#include "system_wrappers/include/metrics.h"
#include "test/gtest.h" #include "test/gtest.h"
namespace webrtc { namespace webrtc {
@ -54,9 +54,7 @@ class MetricsDefaultTest : public ::testing::Test {
MetricsDefaultTest() {} MetricsDefaultTest() {}
protected: protected:
virtual void SetUp() { virtual void SetUp() { metrics::Reset(); }
metrics::Reset();
}
}; };
TEST_F(MetricsDefaultTest, Reset) { TEST_F(MetricsDefaultTest, Reset) {

View file

@ -29,9 +29,7 @@ class MetricsTest : public ::testing::Test {
MetricsTest() {} MetricsTest() {}
protected: protected:
virtual void SetUp() { virtual void SetUp() { metrics::Reset(); }
metrics::Reset();
}
}; };
TEST_F(MetricsTest, InitiallyNoSamples) { TEST_F(MetricsTest, InitiallyNoSamples) {

View file

@ -8,8 +8,8 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#include "system_wrappers/include/clock.h"
#include "system_wrappers/include/ntp_time.h" #include "system_wrappers/include/ntp_time.h"
#include "system_wrappers/include/clock.h"
#include "test/gtest.h" #include "test/gtest.h"
namespace webrtc { namespace webrtc {

View file

@ -86,8 +86,8 @@ TEST(WrapAroundTests, RtpWrapped) {
estimator.UpdateMeasurements(ntp_sec, ntp_frac, timestamp, &new_sr)); estimator.UpdateMeasurements(ntp_sec, ntp_frac, timestamp, &new_sr));
int64_t timestamp_ms = -1; int64_t timestamp_ms = -1;
EXPECT_TRUE(estimator.Estimate(0xFFFFFFFF - 2 * kTimestampTicksPerMs, EXPECT_TRUE(
&timestamp_ms)); estimator.Estimate(0xFFFFFFFF - 2 * kTimestampTicksPerMs, &timestamp_ms));
// Since this RTP packet has the same timestamp as the RTCP packet constructed // Since this RTP packet has the same timestamp as the RTCP packet constructed
// at time 0 it should be mapped to 0 as well. // at time 0 it should be mapped to 0 as well.
EXPECT_EQ(0, timestamp_ms); EXPECT_EQ(0, timestamp_ms);

View file

@ -12,8 +12,7 @@
namespace webrtc { namespace webrtc {
RWLockPosix::RWLockPosix() : lock_() { RWLockPosix::RWLockPosix() : lock_() {}
}
RWLockPosix::~RWLockPosix() { RWLockPosix::~RWLockPosix() {
pthread_rwlock_destroy(&lock_); pthread_rwlock_destroy(&lock_);

View file

@ -18,18 +18,18 @@ static bool native_rw_locks_supported = false;
static bool module_load_attempted = false; static bool module_load_attempted = false;
static HMODULE library = NULL; static HMODULE library = NULL;
typedef void (WINAPI* InitializeSRWLock)(PSRWLOCK); typedef void(WINAPI* InitializeSRWLock)(PSRWLOCK);
typedef void (WINAPI* AcquireSRWLockExclusive)(PSRWLOCK); typedef void(WINAPI* AcquireSRWLockExclusive)(PSRWLOCK);
typedef void (WINAPI* ReleaseSRWLockExclusive)(PSRWLOCK); typedef void(WINAPI* ReleaseSRWLockExclusive)(PSRWLOCK);
typedef void (WINAPI* AcquireSRWLockShared)(PSRWLOCK); typedef void(WINAPI* AcquireSRWLockShared)(PSRWLOCK);
typedef void (WINAPI* ReleaseSRWLockShared)(PSRWLOCK); typedef void(WINAPI* ReleaseSRWLockShared)(PSRWLOCK);
InitializeSRWLock initialize_srw_lock; InitializeSRWLock initialize_srw_lock;
AcquireSRWLockExclusive acquire_srw_lock_exclusive; AcquireSRWLockExclusive acquire_srw_lock_exclusive;
AcquireSRWLockShared acquire_srw_lock_shared; AcquireSRWLockShared acquire_srw_lock_shared;
ReleaseSRWLockShared release_srw_lock_shared; ReleaseSRWLockShared release_srw_lock_shared;
ReleaseSRWLockExclusive release_srw_lock_exclusive; ReleaseSRWLockExclusive release_srw_lock_exclusive;
RWLockWin::RWLockWin() { RWLockWin::RWLockWin() {
@ -72,18 +72,16 @@ bool RWLockWin::LoadModule() {
LOG(LS_VERBOSE) << "Loaded Kernel.dll"; LOG(LS_VERBOSE) << "Loaded Kernel.dll";
initialize_srw_lock = initialize_srw_lock =
(InitializeSRWLock)GetProcAddress(library, "InitializeSRWLock"); (InitializeSRWLock)GetProcAddress(library, "InitializeSRWLock");
acquire_srw_lock_exclusive = acquire_srw_lock_exclusive = (AcquireSRWLockExclusive)GetProcAddress(
(AcquireSRWLockExclusive)GetProcAddress(library, library, "AcquireSRWLockExclusive");
"AcquireSRWLockExclusive"); release_srw_lock_exclusive = (ReleaseSRWLockExclusive)GetProcAddress(
release_srw_lock_exclusive = library, "ReleaseSRWLockExclusive");
(ReleaseSRWLockExclusive)GetProcAddress(library,
"ReleaseSRWLockExclusive");
acquire_srw_lock_shared = acquire_srw_lock_shared =
(AcquireSRWLockShared)GetProcAddress(library, "AcquireSRWLockShared"); (AcquireSRWLockShared)GetProcAddress(library, "AcquireSRWLockShared");
release_srw_lock_shared = release_srw_lock_shared =
(ReleaseSRWLockShared)GetProcAddress(library, "ReleaseSRWLockShared"); (ReleaseSRWLockShared)GetProcAddress(library, "ReleaseSRWLockShared");
if (initialize_srw_lock && acquire_srw_lock_exclusive && if (initialize_srw_lock && acquire_srw_lock_exclusive &&
release_srw_lock_exclusive && acquire_srw_lock_shared && release_srw_lock_exclusive && acquire_srw_lock_shared &&

View file

@ -31,205 +31,178 @@ TimestampExtrapolator::TimestampExtrapolator(int64_t start_ms)
_accDrift(6600), // in timestamp ticks, i.e. 15 ms _accDrift(6600), // in timestamp ticks, i.e. 15 ms
_accMaxError(7000), _accMaxError(7000),
_pP11(1e10) { _pP11(1e10) {
Reset(start_ms); Reset(start_ms);
} }
TimestampExtrapolator::~TimestampExtrapolator() TimestampExtrapolator::~TimestampExtrapolator() {
{ delete _rwLock;
delete _rwLock;
} }
void TimestampExtrapolator::Reset(int64_t start_ms) void TimestampExtrapolator::Reset(int64_t start_ms) {
{ WriteLockScoped wl(*_rwLock);
WriteLockScoped wl(*_rwLock); _startMs = start_ms;
_startMs = start_ms; _prevMs = _startMs;
_prevMs = _startMs; _firstTimestamp = 0;
_firstTimestamp = 0; _w[0] = 90.0;
_w[0] = 90.0; _w[1] = 0;
_w[1] = 0; _pP[0][0] = 1;
_pP[0][0] = 1; _pP[1][1] = _pP11;
_pP[1][1] = _pP11; _pP[0][1] = _pP[1][0] = 0;
_pP[0][1] = _pP[1][0] = 0; _firstAfterReset = true;
_firstAfterReset = true; _prevUnwrappedTimestamp = -1;
_prevUnwrappedTimestamp = -1; _prevWrapTimestamp = -1;
_prevWrapTimestamp = -1; _wrapArounds = 0;
_wrapArounds = 0; _packetCount = 0;
_packetCount = 0; _detectorAccumulatorPos = 0;
_detectorAccumulatorPos = 0; _detectorAccumulatorNeg = 0;
_detectorAccumulatorNeg = 0;
} }
void void TimestampExtrapolator::Update(int64_t tMs, uint32_t ts90khz) {
TimestampExtrapolator::Update(int64_t tMs, uint32_t ts90khz) _rwLock->AcquireLockExclusive();
{ if (tMs - _prevMs > 10e3) {
// Ten seconds without a complete frame.
_rwLock->AcquireLockExclusive(); // Reset the extrapolator
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 (_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.
_pP[1][1] = _pP11;
}
if (_prevUnwrappedTimestamp >= 0 &&
unwrapped_ts90khz < _prevUnwrappedTimestamp)
{
// Drop reordered frames.
_rwLock->ReleaseLockExclusive();
return;
}
//T = [t(k) 1]';
//that = T'*w;
//K = P*T/(lambda + T'*P*T);
double K[2];
K[0] = _pP[0][0] * tMs + _pP[0][1];
K[1] = _pP[1][0] * tMs + _pP[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 *
(_pP[0][0] - (K[0] * tMs * _pP[0][0] + K[0] * _pP[1][0]));
double p01 = 1 / _lambda *
(_pP[0][1] - (K[0] * tMs * _pP[0][1] + K[0] * _pP[1][1]));
_pP[1][0] = 1 / _lambda *
(_pP[1][0] - (K[1] * tMs * _pP[0][0] + K[1] * _pP[1][0]));
_pP[1][1] = 1 / _lambda *
(_pP[1][1] - (K[1] * tMs * _pP[0][1] + K[1] * _pP[1][1]));
_pP[0][0] = p00;
_pP[0][1] = p01;
_prevUnwrappedTimestamp = unwrapped_ts90khz;
if (_packetCount < _startUpFilterDelayInPackets)
{
_packetCount++;
}
_rwLock->ReleaseLockExclusive(); _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 (_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.
_pP[1][1] = _pP11;
}
if (_prevUnwrappedTimestamp >= 0 &&
unwrapped_ts90khz < _prevUnwrappedTimestamp) {
// Drop reordered frames.
_rwLock->ReleaseLockExclusive();
return;
}
// T = [t(k) 1]';
// that = T'*w;
// K = P*T/(lambda + T'*P*T);
double K[2];
K[0] = _pP[0][0] * tMs + _pP[0][1];
K[1] = _pP[1][0] * tMs + _pP[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 * (_pP[0][0] - (K[0] * tMs * _pP[0][0] + K[0] * _pP[1][0]));
double p01 =
1 / _lambda * (_pP[0][1] - (K[0] * tMs * _pP[0][1] + K[0] * _pP[1][1]));
_pP[1][0] =
1 / _lambda * (_pP[1][0] - (K[1] * tMs * _pP[0][0] + K[1] * _pP[1][0]));
_pP[1][1] =
1 / _lambda * (_pP[1][1] - (K[1] * tMs * _pP[0][1] + K[1] * _pP[1][1]));
_pP[0][0] = p00;
_pP[0][1] = p01;
_prevUnwrappedTimestamp = unwrapped_ts90khz;
if (_packetCount < _startUpFilterDelayInPackets) {
_packetCount++;
}
_rwLock->ReleaseLockExclusive();
} }
int64_t int64_t TimestampExtrapolator::ExtrapolateLocalTime(uint32_t timestamp90khz) {
TimestampExtrapolator::ExtrapolateLocalTime(uint32_t timestamp90khz) ReadLockScoped rl(*_rwLock);
{ int64_t localTimeMs = 0;
ReadLockScoped rl(*_rwLock); CheckForWrapArounds(timestamp90khz);
int64_t localTimeMs = 0; double unwrapped_ts90khz =
CheckForWrapArounds(timestamp90khz); static_cast<double>(timestamp90khz) +
double unwrapped_ts90khz = static_cast<double>(timestamp90khz) + _wrapArounds * ((static_cast<int64_t>(1) << 32) - 1);
_wrapArounds * ((static_cast<int64_t>(1) << 32) - 1); if (_packetCount == 0) {
if (_packetCount == 0) localTimeMs = -1;
{ } else if (_packetCount < _startUpFilterDelayInPackets) {
localTimeMs = -1; localTimeMs =
} _prevMs +
else if (_packetCount < _startUpFilterDelayInPackets) static_cast<int64_t>(
{
localTimeMs = _prevMs + static_cast<int64_t>(
static_cast<double>(unwrapped_ts90khz - _prevUnwrappedTimestamp) / static_cast<double>(unwrapped_ts90khz - _prevUnwrappedTimestamp) /
90.0 + 0.5); 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);
} }
else }
{ return localTimeMs;
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 // Investigates if the timestamp clock has overflowed since the last timestamp
// keeps track of the number of wrap arounds since reset. // and keeps track of the number of wrap arounds since reset.
void void TimestampExtrapolator::CheckForWrapArounds(uint32_t ts90khz) {
TimestampExtrapolator::CheckForWrapArounds(uint32_t ts90khz) if (_prevWrapTimestamp == -1) {
{
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; _prevWrapTimestamp = ts90khz;
} return;
}
bool if (ts90khz < _prevWrapTimestamp) {
TimestampExtrapolator::DelayChangeDetection(double error) // 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
// CUSUM detection of sudden delay changes // casted to a Word32, it should be positive.
error = (error > 0) ? std::min(error, _accMaxError) : if (static_cast<int32_t>(ts90khz - _prevWrapTimestamp) > 0) {
std::max(error, -_accMaxError); // Forward wrap around
_detectorAccumulatorPos = _wrapArounds++;
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; }
// 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 TimestampExtrapolator::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;
} }
} // namespace webrtc