diff --git a/system_wrappers/include/aligned_array.h b/system_wrappers/include/aligned_array.h index 88b5269902..793c785820 100644 --- a/system_wrappers/include/aligned_array.h +++ b/system_wrappers/include/aligned_array.h @@ -18,17 +18,17 @@ namespace webrtc { // Wrapper class for aligned arrays. Every row (and the first dimension) are // aligned to the given byte alignment. -template class AlignedArray { +template +class AlignedArray { public: AlignedArray(size_t rows, size_t cols, size_t alignment) - : rows_(rows), - cols_(cols) { + : rows_(rows), cols_(cols) { RTC_CHECK_GT(alignment, 0); - head_row_ = static_cast(AlignedMalloc(rows_ * sizeof(*head_row_), - alignment)); + head_row_ = + static_cast(AlignedMalloc(rows_ * sizeof(*head_row_), alignment)); for (size_t i = 0; i < rows_; ++i) { - head_row_[i] = static_cast(AlignedMalloc(cols_ * sizeof(**head_row_), - alignment)); + head_row_[i] = static_cast( + AlignedMalloc(cols_ * sizeof(**head_row_), alignment)); } } @@ -39,13 +39,9 @@ template class AlignedArray { AlignedFree(head_row_); } - T* const* Array() { - return head_row_; - } + T* const* Array() { return head_row_; } - const T* const* Array() const { - return head_row_; - } + const T* const* Array() const { return head_row_; } T* Row(size_t row) { RTC_CHECK_LE(row, rows_); @@ -67,13 +63,9 @@ template class AlignedArray { return Row(row)[col]; } - size_t rows() const { - return rows_; - } + size_t rows() const { return rows_; } - size_t cols() const { - return cols_; - } + size_t cols() const { return cols_; } private: size_t rows_; diff --git a/system_wrappers/include/aligned_malloc.h b/system_wrappers/include/aligned_malloc.h index ac049b0ea7..33b23d2aec 100644 --- a/system_wrappers/include/aligned_malloc.h +++ b/system_wrappers/include/aligned_malloc.h @@ -36,12 +36,12 @@ void AlignedFree(void* mem_block); // Templated versions to facilitate usage of aligned malloc without casting // to and from void*. -template +template T* GetRightAlign(const T* ptr, size_t alignment) { - return reinterpret_cast(GetRightAlign(reinterpret_cast(ptr), - alignment)); + return reinterpret_cast( + GetRightAlign(reinterpret_cast(ptr), alignment)); } -template +template T* AlignedMalloc(size_t size, size_t alignment) { return reinterpret_cast(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 // std::unique_ptr foo; struct AlignedFreeDeleter { - inline void operator()(void* ptr) const { - AlignedFree(ptr); - } + inline void operator()(void* ptr) const { AlignedFree(ptr); } }; } // namespace webrtc -#endif // SYSTEM_WRAPPERS_INCLUDE_ALIGNED_MALLOC_H_ +#endif // SYSTEM_WRAPPERS_INCLUDE_ALIGNED_MALLOC_H_ diff --git a/system_wrappers/include/cpu_features_wrapper.h b/system_wrappers/include/cpu_features_wrapper.h index 7187077b51..07ee912cb2 100644 --- a/system_wrappers/include/cpu_features_wrapper.h +++ b/system_wrappers/include/cpu_features_wrapper.h @@ -18,17 +18,14 @@ extern "C" { #include "typedefs.h" // NOLINT(build/include) // List of features in x86. -typedef enum { - kSSE2, - kSSE3 -} CPUFeature; +typedef enum { kSSE2, kSSE3 } CPUFeature; // List of features in ARM. enum { - kCPUFeatureARMv7 = (1 << 0), - kCPUFeatureVFPv3 = (1 << 1), - kCPUFeatureNEON = (1 << 2), - kCPUFeatureLDREXSTREX = (1 << 3) + kCPUFeatureARMv7 = (1 << 0), + kCPUFeatureVFPv3 = (1 << 1), + kCPUFeatureNEON = (1 << 2), + kCPUFeatureLDREXSTREX = (1 << 3) }; typedef int (*WebRtc_CPUInfo)(CPUFeature feature); @@ -48,4 +45,4 @@ extern uint64_t WebRtc_GetCPUFeaturesARM(void); } // extern "C" #endif -#endif // SYSTEM_WRAPPERS_INCLUDE_CPU_FEATURES_WRAPPER_H_ +#endif // SYSTEM_WRAPPERS_INCLUDE_CPU_FEATURES_WRAPPER_H_ diff --git a/system_wrappers/include/cpu_info.h b/system_wrappers/include/cpu_info.h index c4cf2da8d3..dbd5d606aa 100644 --- a/system_wrappers/include/cpu_info.h +++ b/system_wrappers/include/cpu_info.h @@ -25,4 +25,4 @@ class CpuInfo { } // namespace webrtc -#endif // SYSTEM_WRAPPERS_INCLUDE_CPU_INFO_H_ +#endif // SYSTEM_WRAPPERS_INCLUDE_CPU_INFO_H_ diff --git a/system_wrappers/include/event_wrapper.h b/system_wrappers/include/event_wrapper.h index b8dab2c341..0c29138203 100644 --- a/system_wrappers/include/event_wrapper.h +++ b/system_wrappers/include/event_wrapper.h @@ -62,7 +62,6 @@ class EventTimerWrapper : public EventWrapper { virtual bool StartTimer(bool periodic, unsigned long time) = 0; virtual bool StopTimer() = 0; - }; } // namespace webrtc diff --git a/system_wrappers/include/metrics.h b/system_wrappers/include/metrics.h index 6a6878ad9b..13f2483b32 100644 --- a/system_wrappers/include/metrics.h +++ b/system_wrappers/include/metrics.h @@ -61,7 +61,6 @@ // NOTE: It is recommended to do the Chromium review for modifications to // histograms.xml before new metrics are committed to WebRTC. - // Macros for adding samples to a named histogram. // Histogram for counters (exponentially spaced buckets). @@ -83,9 +82,10 @@ #define RTC_HISTOGRAM_COUNTS_100000(name, sample) \ RTC_HISTOGRAM_COUNTS(name, sample, 1, 100000, 50) -#define RTC_HISTOGRAM_COUNTS(name, sample, min, max, bucket_count) \ - RTC_HISTOGRAM_COMMON_BLOCK(name, sample, \ - webrtc::metrics::HistogramFactoryGetCounts(name, min, max, bucket_count)) +#define RTC_HISTOGRAM_COUNTS(name, sample, min, max, bucket_count) \ + RTC_HISTOGRAM_COMMON_BLOCK(name, sample, \ + webrtc::metrics::HistogramFactoryGetCounts( \ + name, min, max, bucket_count)) #define RTC_HISTOGRAM_COUNTS_LINEAR(name, sample, min, max, bucket_count) \ RTC_HISTOGRAM_COMMON_BLOCK(name, sample, \ @@ -112,9 +112,10 @@ #define RTC_HISTOGRAM_COUNTS_SPARSE_100000(name, sample) \ RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 100000, 50) -#define RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, min, max, bucket_count) \ - RTC_HISTOGRAM_COMMON_BLOCK_SLOW(name, sample, \ - webrtc::metrics::HistogramFactoryGetCounts(name, min, max, bucket_count)) +#define RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, min, max, bucket_count) \ + RTC_HISTOGRAM_COMMON_BLOCK_SLOW(name, sample, \ + webrtc::metrics::HistogramFactoryGetCounts( \ + name, min, max, bucket_count)) // Histogram for percentage (evenly spaced buckets). #define RTC_HISTOGRAM_PERCENTAGE_SPARSE(name, sample) \ @@ -142,7 +143,8 @@ // Histogram for enumerators (evenly spaced buckets). // |boundary| should be above the max enumerator sample. #define RTC_HISTOGRAM_ENUMERATION(name, sample, boundary) \ - RTC_HISTOGRAM_COMMON_BLOCK(name, sample, \ + RTC_HISTOGRAM_COMMON_BLOCK( \ + name, sample, \ webrtc::metrics::HistogramFactoryGetEnumeration(name, boundary)) // The name of the histogram should not vary. @@ -185,36 +187,36 @@ // is cached. |index| should be different for different names. Allowed |index| // values are 0, 1, and 2. #define RTC_HISTOGRAMS_COUNTS_100(index, name, sample) \ - RTC_HISTOGRAMS_COMMON(index, name, sample, \ - RTC_HISTOGRAM_COUNTS(name, sample, 1, 100, 50)) + RTC_HISTOGRAMS_COMMON(index, name, sample, \ + RTC_HISTOGRAM_COUNTS(name, sample, 1, 100, 50)) #define RTC_HISTOGRAMS_COUNTS_200(index, name, sample) \ - RTC_HISTOGRAMS_COMMON(index, name, sample, \ - RTC_HISTOGRAM_COUNTS(name, sample, 1, 200, 50)) + RTC_HISTOGRAMS_COMMON(index, name, sample, \ + RTC_HISTOGRAM_COUNTS(name, sample, 1, 200, 50)) #define RTC_HISTOGRAMS_COUNTS_500(index, name, sample) \ - RTC_HISTOGRAMS_COMMON(index, name, sample, \ - RTC_HISTOGRAM_COUNTS(name, sample, 1, 500, 50)) + RTC_HISTOGRAMS_COMMON(index, name, sample, \ + RTC_HISTOGRAM_COUNTS(name, sample, 1, 500, 50)) #define RTC_HISTOGRAMS_COUNTS_1000(index, name, sample) \ - RTC_HISTOGRAMS_COMMON(index, name, sample, \ - RTC_HISTOGRAM_COUNTS(name, sample, 1, 1000, 50)) + RTC_HISTOGRAMS_COMMON(index, name, sample, \ + RTC_HISTOGRAM_COUNTS(name, sample, 1, 1000, 50)) #define RTC_HISTOGRAMS_COUNTS_10000(index, name, sample) \ - RTC_HISTOGRAMS_COMMON(index, name, sample, \ - RTC_HISTOGRAM_COUNTS(name, sample, 1, 10000, 50)) + RTC_HISTOGRAMS_COMMON(index, name, sample, \ + RTC_HISTOGRAM_COUNTS(name, sample, 1, 10000, 50)) #define RTC_HISTOGRAMS_COUNTS_100000(index, name, sample) \ - RTC_HISTOGRAMS_COMMON(index, name, sample, \ - RTC_HISTOGRAM_COUNTS(name, sample, 1, 100000, 50)) + RTC_HISTOGRAMS_COMMON(index, name, sample, \ + RTC_HISTOGRAM_COUNTS(name, sample, 1, 100000, 50)) #define RTC_HISTOGRAMS_ENUMERATION(index, name, sample, boundary) \ - RTC_HISTOGRAMS_COMMON(index, name, sample, \ - RTC_HISTOGRAM_ENUMERATION(name, sample, boundary)) + RTC_HISTOGRAMS_COMMON(index, name, sample, \ + RTC_HISTOGRAM_ENUMERATION(name, sample, boundary)) #define RTC_HISTOGRAMS_PERCENTAGE(index, name, sample) \ - RTC_HISTOGRAMS_COMMON(index, name, sample, \ - RTC_HISTOGRAM_PERCENTAGE(name, sample)) + RTC_HISTOGRAMS_COMMON(index, name, sample, \ + RTC_HISTOGRAM_PERCENTAGE(name, sample)) #define RTC_HISTOGRAMS_COMMON(index, name, sample, macro_invocation) \ do { \ @@ -245,8 +247,10 @@ class Histogram; // histogram). // Get histogram for counters. -Histogram* HistogramFactoryGetCounts( - const std::string& name, int min, int max, int bucket_count); +Histogram* HistogramFactoryGetCounts(const std::string& name, + int min, + int max, + int bucket_count); // Get histogram for counters with linear bucket spacing. Histogram* HistogramFactoryGetCountsLinear(const std::string& name, @@ -256,8 +260,8 @@ Histogram* HistogramFactoryGetCountsLinear(const std::string& name, // Get histogram for enumerators. // |boundary| should be above the max enumerator sample. -Histogram* HistogramFactoryGetEnumeration( - const std::string& name, int boundary); +Histogram* HistogramFactoryGetEnumeration(const std::string& name, + int boundary); // Function for adding a |sample| to a histogram. void HistogramAdd(Histogram* histogram_pointer, int sample); diff --git a/system_wrappers/include/ntp_time.h b/system_wrappers/include/ntp_time.h index 43ef161a69..e963ecf39c 100644 --- a/system_wrappers/include/ntp_time.h +++ b/system_wrappers/include/ntp_time.h @@ -1,12 +1,12 @@ /* -* Copyright (c) 2015 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. -*/ + * Copyright (c) 2015 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 SYSTEM_WRAPPERS_INCLUDE_NTP_TIME_H_ #define SYSTEM_WRAPPERS_INCLUDE_NTP_TIME_H_ diff --git a/system_wrappers/include/timestamp_extrapolator.h b/system_wrappers/include/timestamp_extrapolator.h index 907b56f325..9418100373 100644 --- a/system_wrappers/include/timestamp_extrapolator.h +++ b/system_wrappers/include/timestamp_extrapolator.h @@ -14,43 +14,41 @@ #include "system_wrappers/include/rw_lock_wrapper.h" #include "typedefs.h" // NOLINT(build/include) -namespace webrtc -{ +namespace webrtc { -class TimestampExtrapolator -{ -public: - explicit TimestampExtrapolator(int64_t start_ms); - ~TimestampExtrapolator(); - void Update(int64_t tMs, uint32_t ts90khz); - int64_t ExtrapolateLocalTime(uint32_t timestamp90khz); - void Reset(int64_t start_ms); +class TimestampExtrapolator { + public: + explicit TimestampExtrapolator(int64_t start_ms); + ~TimestampExtrapolator(); + 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 _pP[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; + private: + void CheckForWrapArounds(uint32_t ts90khz); + bool DelayChangeDetection(double error); + RWLockWrapper* _rwLock; + double _w[2]; + double _pP[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 _pP11; + double _detectorAccumulatorPos; + double _detectorAccumulatorNeg; + const double _alarmThreshold; + const double _accDrift; + const double _accMaxError; + const double _pP11; }; } // namespace webrtc -#endif // SYSTEM_WRAPPERS_INCLUDE_TIMESTAMP_EXTRAPOLATOR_H_ +#endif // SYSTEM_WRAPPERS_INCLUDE_TIMESTAMP_EXTRAPOLATOR_H_ diff --git a/system_wrappers/source/aligned_malloc_unittest.cc b/system_wrappers/source/aligned_malloc_unittest.cc index 2ae61e154c..7afbf6d1bb 100644 --- a/system_wrappers/source/aligned_malloc_unittest.cc +++ b/system_wrappers/source/aligned_malloc_unittest.cc @@ -30,7 +30,7 @@ bool CorrectUsage(size_t size, size_t alignment) { if (scoped.get() == NULL) { return false; } - const uintptr_t scoped_address = reinterpret_cast (scoped.get()); + const uintptr_t scoped_address = reinterpret_cast(scoped.get()); return 0u == scoped_address % alignment; } @@ -41,10 +41,10 @@ TEST(AlignedMalloc, GetRightAlign) { std::unique_ptr scoped( static_cast(AlignedMalloc(size, alignment))); EXPECT_TRUE(scoped.get() != NULL); - const uintptr_t aligned_address = reinterpret_cast (scoped.get()); + const uintptr_t aligned_address = reinterpret_cast(scoped.get()); const uintptr_t misaligned_address = aligned_address - left_misalignment; - const char* misaligned_ptr = reinterpret_cast( - misaligned_address); + const char* misaligned_ptr = + reinterpret_cast(misaligned_address); const char* realigned_ptr = GetRightAlign(misaligned_ptr, alignment); EXPECT_EQ(scoped.get(), realigned_ptr); } @@ -80,4 +80,3 @@ TEST(AlignedMalloc, AlignTo128Bytes) { } } // namespace webrtc - diff --git a/system_wrappers/source/clock.cc b/system_wrappers/source/clock.cc index 184b35ee75..fc863552de 100644 --- a/system_wrappers/source/clock.cc +++ b/system_wrappers/source/clock.cc @@ -11,12 +11,17 @@ #include "system_wrappers/include/clock.h" #if defined(_WIN32) + // Windows needs to be included before mmsystem.h #include "rtc_base/win32.h" + #include + #elif ((defined WEBRTC_LINUX) || (defined WEBRTC_MAC)) + #include #include + #endif #include "rtc_base/criticalsection.h" @@ -28,15 +33,11 @@ namespace webrtc { class RealTimeClock : public Clock { // Return a timestamp in milliseconds relative to some arbitrary source; the // source is fixed for this clock. - int64_t TimeInMilliseconds() const override { - return rtc::TimeMillis(); - } + int64_t TimeInMilliseconds() const override { return rtc::TimeMillis(); } // Return a timestamp in microseconds relative to some arbitrary source; the // source is fixed for this clock. - int64_t TimeInMicroseconds() const override { - return rtc::TimeMicros(); - } + int64_t TimeInMicroseconds() const override { return rtc::TimeMicros(); } // Retrieve an NTP absolute timestamp. NtpTime CurrentNtpTime() const override { @@ -56,13 +57,14 @@ class RealTimeClock : public Clock { double microseconds_in_seconds; Adjust(tv, &seconds, µseconds_in_seconds); return 1000 * static_cast(seconds) + - static_cast(1000.0 * microseconds_in_seconds + 0.5); + static_cast(1000.0 * microseconds_in_seconds + 0.5); } protected: 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) { *adjusted_s = tv.tv_sec + kNtpJan1970; *adjusted_us_in_s = tv.tv_usec / 1e6; @@ -107,8 +109,8 @@ class WindowsRealTimeClock : public RealTimeClock { // speed stepping. GetTime(&StartTime); - Time = (((uint64_t) StartTime.dwHighDateTime) << 32) + - (uint64_t) StartTime.dwLowDateTime; + Time = (((uint64_t)StartTime.dwHighDateTime) << 32) + + (uint64_t)StartTime.dwLowDateTime; // Convert the hecto-nano second time to tv format. Time -= FILETIME_1970; @@ -226,11 +228,9 @@ Clock* Clock::GetRealTimeClock() { } 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 { ReadLockScoped synchronize(*lock_); diff --git a/system_wrappers/source/cpu_features.cc b/system_wrappers/source/cpu_features.cc index 1c7e45eda6..7417f53d59 100644 --- a/system_wrappers/source/cpu_features.cc +++ b/system_wrappers/source/cpu_features.cc @@ -30,18 +30,19 @@ int GetCPUInfoNoASM(CPUFeature feature) { #if defined(__pic__) && defined(__i386__) static inline void __cpuid(int cpu_info[4], int info_type) { __asm__ volatile( - "mov %%ebx, %%edi\n" - "cpuid\n" - "xchg %%edi, %%ebx\n" - : "=a"(cpu_info[0]), "=D"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3]) - : "a"(info_type)); + "mov %%ebx, %%edi\n" + "cpuid\n" + "xchg %%edi, %%ebx\n" + : "=a"(cpu_info[0]), "=D"(cpu_info[1]), "=c"(cpu_info[2]), + "=d"(cpu_info[3]) + : "a"(info_type)); } #else static inline void __cpuid(int cpu_info[4], int info_type) { - __asm__ volatile( - "cpuid\n" - : "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3]) - : "a"(info_type)); + __asm__ volatile("cpuid\n" + : "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]), + "=d"(cpu_info[3]) + : "a"(info_type)); } #endif #endif // _MSC_VER diff --git a/system_wrappers/source/cpu_info.cc b/system_wrappers/source/cpu_info.cc index b96369d7cd..fa70ced410 100644 --- a/system_wrappers/source/cpu_info.cc +++ b/system_wrappers/source/cpu_info.cc @@ -11,8 +11,8 @@ #include "system_wrappers/include/cpu_info.h" #if defined(WEBRTC_WIN) -#include #include +#include #ifndef EXCLUDE_D3D9 #include #endif @@ -51,7 +51,7 @@ static int DetectNumberOfCores() { return number_of_cores; } -} +} // namespace internal namespace webrtc { diff --git a/system_wrappers/source/event.cc b/system_wrappers/source/event.cc index 1bbd01ffac..aac69f6e02 100644 --- a/system_wrappers/source/event.cc +++ b/system_wrappers/source/event.cc @@ -37,8 +37,9 @@ class EventWrapperImpl : public EventWrapper { } EventTypeWrapper Wait(unsigned long max_time) override { - int to_wait = max_time == WEBRTC_EVENT_INFINITE ? - rtc::Event::kForever : static_cast(max_time); + int to_wait = max_time == WEBRTC_EVENT_INFINITE + ? rtc::Event::kForever + : static_cast(max_time); return event_.Wait(to_wait) ? kEventSignaled : kEventTimeout; } diff --git a/system_wrappers/source/event_timer_posix.cc b/system_wrappers/source/event_timer_posix.cc index bc663ad2c3..2a6a580c64 100644 --- a/system_wrappers/source/event_timer_posix.cc +++ b/system_wrappers/source/event_timer_posix.cc @@ -160,7 +160,7 @@ bool EventTimerPosix::StartTimer(bool periodic, unsigned long time_ms) { // Timer already started. pthread_mutex_unlock(&mutex_); return false; - } else { + } else { // New one shot timer. time_ms_ = time_ms; created_at_.tv_sec = 0; diff --git a/system_wrappers/source/event_timer_posix.h b/system_wrappers/source/event_timer_posix.h index 4de7422950..72d6753e53 100644 --- a/system_wrappers/source/event_timer_posix.h +++ b/system_wrappers/source/event_timer_posix.h @@ -22,10 +22,7 @@ namespace webrtc { -enum State { - kUp = 1, - kDown = 2 -}; +enum State { kUp = 1, kDown = 2 }; class EventTimerPosix : public EventTimerWrapper { public: @@ -47,16 +44,16 @@ class EventTimerPosix : public EventTimerWrapper { virtual rtc::PlatformThread* CreateThread(); - pthread_cond_t cond_; + pthread_cond_t cond_; pthread_mutex_t mutex_; bool event_set_; // TODO(pbos): Remove unique_ptr and use PlatformThread directly. std::unique_ptr timer_thread_; std::unique_ptr timer_event_; - timespec created_at_; + timespec created_at_; - bool periodic_; + bool periodic_; unsigned long time_ms_; unsigned long count_; bool is_stopping_; diff --git a/system_wrappers/source/event_timer_win.cc b/system_wrappers/source/event_timer_win.cc index 19ed3fa6e9..b6a93feb82 100644 --- a/system_wrappers/source/event_timer_win.cc +++ b/system_wrappers/source/event_timer_win.cc @@ -24,8 +24,7 @@ EventTimerWin::EventTimerWin() FALSE, // manual reset FALSE, // initial state NULL)), // name of event - timerID_(NULL) { -} + timerID_(NULL) {} EventTimerWin::~EventTimerWin() { StopTimer(); diff --git a/system_wrappers/source/event_timer_win.h b/system_wrappers/source/event_timer_win.h index 827390c92f..5631a3fbc4 100644 --- a/system_wrappers/source/event_timer_win.h +++ b/system_wrappers/source/event_timer_win.h @@ -31,7 +31,7 @@ class EventTimerWin : public EventTimerWrapper { virtual bool StopTimer(); private: - HANDLE event_; + HANDLE event_; uint32_t timerID_; }; diff --git a/system_wrappers/source/field_trial_default.cc b/system_wrappers/source/field_trial_default.cc index 94e56b5bc4..e8d8917874 100644 --- a/system_wrappers/source/field_trial_default.cc +++ b/system_wrappers/source/field_trial_default.cc @@ -7,8 +7,8 @@ // 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.h" #include @@ -17,7 +17,7 @@ namespace webrtc { namespace field_trial { -static const char *trials_init_string = NULL; +static const char* trials_init_string = NULL; std::string FindFullName(const std::string& name) { if (trials_init_string == NULL) @@ -30,21 +30,20 @@ std::string FindFullName(const std::string& name) { static const char kPersistentStringSeparator = '/'; size_t next_item = 0; while (next_item < trials_string.length()) { - // Find next name/value pair in field trial configuration string. - size_t field_name_end = trials_string.find( - kPersistentStringSeparator, next_item); + size_t field_name_end = + trials_string.find(kPersistentStringSeparator, next_item); if (field_name_end == trials_string.npos || field_name_end == next_item) break; - size_t field_value_end = trials_string.find( - kPersistentStringSeparator, field_name_end + 1); + size_t field_value_end = + trials_string.find(kPersistentStringSeparator, field_name_end + 1); if (field_value_end == trials_string.npos || field_value_end == field_name_end + 1) break; 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, - field_value_end - field_name_end - 1); + field_value_end - field_name_end - 1); next_item = field_value_end + 1; if (name == field_name) diff --git a/system_wrappers/source/metrics_default_unittest.cc b/system_wrappers/source/metrics_default_unittest.cc index dfac863a98..fa253a9bfe 100644 --- a/system_wrappers/source/metrics_default_unittest.cc +++ b/system_wrappers/source/metrics_default_unittest.cc @@ -8,8 +8,8 @@ * 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.h" #include "test/gtest.h" namespace webrtc { @@ -54,9 +54,7 @@ class MetricsDefaultTest : public ::testing::Test { MetricsDefaultTest() {} protected: - virtual void SetUp() { - metrics::Reset(); - } + virtual void SetUp() { metrics::Reset(); } }; TEST_F(MetricsDefaultTest, Reset) { diff --git a/system_wrappers/source/metrics_unittest.cc b/system_wrappers/source/metrics_unittest.cc index fe909e821c..53d43cd2b1 100644 --- a/system_wrappers/source/metrics_unittest.cc +++ b/system_wrappers/source/metrics_unittest.cc @@ -29,9 +29,7 @@ class MetricsTest : public ::testing::Test { MetricsTest() {} protected: - virtual void SetUp() { - metrics::Reset(); - } + virtual void SetUp() { metrics::Reset(); } }; TEST_F(MetricsTest, InitiallyNoSamples) { diff --git a/system_wrappers/source/ntp_time_unittest.cc b/system_wrappers/source/ntp_time_unittest.cc index 3fb174316c..7be464d02d 100644 --- a/system_wrappers/source/ntp_time_unittest.cc +++ b/system_wrappers/source/ntp_time_unittest.cc @@ -8,8 +8,8 @@ * 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/clock.h" #include "test/gtest.h" namespace webrtc { diff --git a/system_wrappers/source/rtp_to_ntp_estimator_unittest.cc b/system_wrappers/source/rtp_to_ntp_estimator_unittest.cc index 4084620bfc..6bf12f40e8 100644 --- a/system_wrappers/source/rtp_to_ntp_estimator_unittest.cc +++ b/system_wrappers/source/rtp_to_ntp_estimator_unittest.cc @@ -86,8 +86,8 @@ TEST(WrapAroundTests, RtpWrapped) { estimator.UpdateMeasurements(ntp_sec, ntp_frac, timestamp, &new_sr)); int64_t timestamp_ms = -1; - EXPECT_TRUE(estimator.Estimate(0xFFFFFFFF - 2 * kTimestampTicksPerMs, - ×tamp_ms)); + EXPECT_TRUE( + estimator.Estimate(0xFFFFFFFF - 2 * kTimestampTicksPerMs, ×tamp_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_ms); diff --git a/system_wrappers/source/rw_lock_posix.cc b/system_wrappers/source/rw_lock_posix.cc index f1b743b723..412873c770 100644 --- a/system_wrappers/source/rw_lock_posix.cc +++ b/system_wrappers/source/rw_lock_posix.cc @@ -12,8 +12,7 @@ namespace webrtc { -RWLockPosix::RWLockPosix() : lock_() { -} +RWLockPosix::RWLockPosix() : lock_() {} RWLockPosix::~RWLockPosix() { pthread_rwlock_destroy(&lock_); diff --git a/system_wrappers/source/rw_lock_win.cc b/system_wrappers/source/rw_lock_win.cc index 1debe7d97a..e81e9d7354 100644 --- a/system_wrappers/source/rw_lock_win.cc +++ b/system_wrappers/source/rw_lock_win.cc @@ -18,18 +18,18 @@ static bool native_rw_locks_supported = false; static bool module_load_attempted = false; static HMODULE library = NULL; -typedef void (WINAPI* InitializeSRWLock)(PSRWLOCK); +typedef void(WINAPI* InitializeSRWLock)(PSRWLOCK); -typedef void (WINAPI* AcquireSRWLockExclusive)(PSRWLOCK); -typedef void (WINAPI* ReleaseSRWLockExclusive)(PSRWLOCK); +typedef void(WINAPI* AcquireSRWLockExclusive)(PSRWLOCK); +typedef void(WINAPI* ReleaseSRWLockExclusive)(PSRWLOCK); -typedef void (WINAPI* AcquireSRWLockShared)(PSRWLOCK); -typedef void (WINAPI* ReleaseSRWLockShared)(PSRWLOCK); +typedef void(WINAPI* AcquireSRWLockShared)(PSRWLOCK); +typedef void(WINAPI* ReleaseSRWLockShared)(PSRWLOCK); -InitializeSRWLock initialize_srw_lock; +InitializeSRWLock initialize_srw_lock; AcquireSRWLockExclusive acquire_srw_lock_exclusive; -AcquireSRWLockShared acquire_srw_lock_shared; -ReleaseSRWLockShared release_srw_lock_shared; +AcquireSRWLockShared acquire_srw_lock_shared; +ReleaseSRWLockShared release_srw_lock_shared; ReleaseSRWLockExclusive release_srw_lock_exclusive; RWLockWin::RWLockWin() { @@ -72,18 +72,16 @@ bool RWLockWin::LoadModule() { LOG(LS_VERBOSE) << "Loaded Kernel.dll"; initialize_srw_lock = - (InitializeSRWLock)GetProcAddress(library, "InitializeSRWLock"); + (InitializeSRWLock)GetProcAddress(library, "InitializeSRWLock"); - acquire_srw_lock_exclusive = - (AcquireSRWLockExclusive)GetProcAddress(library, - "AcquireSRWLockExclusive"); - release_srw_lock_exclusive = - (ReleaseSRWLockExclusive)GetProcAddress(library, - "ReleaseSRWLockExclusive"); + acquire_srw_lock_exclusive = (AcquireSRWLockExclusive)GetProcAddress( + library, "AcquireSRWLockExclusive"); + release_srw_lock_exclusive = (ReleaseSRWLockExclusive)GetProcAddress( + library, "ReleaseSRWLockExclusive"); acquire_srw_lock_shared = - (AcquireSRWLockShared)GetProcAddress(library, "AcquireSRWLockShared"); + (AcquireSRWLockShared)GetProcAddress(library, "AcquireSRWLockShared"); release_srw_lock_shared = - (ReleaseSRWLockShared)GetProcAddress(library, "ReleaseSRWLockShared"); + (ReleaseSRWLockShared)GetProcAddress(library, "ReleaseSRWLockShared"); if (initialize_srw_lock && acquire_srw_lock_exclusive && release_srw_lock_exclusive && acquire_srw_lock_shared && diff --git a/system_wrappers/source/timestamp_extrapolator.cc b/system_wrappers/source/timestamp_extrapolator.cc index 98f6a7bd34..b8c6ba0934 100644 --- a/system_wrappers/source/timestamp_extrapolator.cc +++ b/system_wrappers/source/timestamp_extrapolator.cc @@ -31,205 +31,178 @@ TimestampExtrapolator::TimestampExtrapolator(int64_t start_ms) _accDrift(6600), // in timestamp ticks, i.e. 15 ms _accMaxError(7000), _pP11(1e10) { - Reset(start_ms); + Reset(start_ms); } -TimestampExtrapolator::~TimestampExtrapolator() -{ - delete _rwLock; +TimestampExtrapolator::~TimestampExtrapolator() { + delete _rwLock; } -void TimestampExtrapolator::Reset(int64_t start_ms) -{ - WriteLockScoped wl(*_rwLock); - _startMs = start_ms; - _prevMs = _startMs; - _firstTimestamp = 0; - _w[0] = 90.0; - _w[1] = 0; - _pP[0][0] = 1; - _pP[1][1] = _pP11; - _pP[0][1] = _pP[1][0] = 0; - _firstAfterReset = true; - _prevUnwrappedTimestamp = -1; - _prevWrapTimestamp = -1; - _wrapArounds = 0; - _packetCount = 0; - _detectorAccumulatorPos = 0; - _detectorAccumulatorNeg = 0; +void TimestampExtrapolator::Reset(int64_t start_ms) { + WriteLockScoped wl(*_rwLock); + _startMs = start_ms; + _prevMs = _startMs; + _firstTimestamp = 0; + _w[0] = 90.0; + _w[1] = 0; + _pP[0][0] = 1; + _pP[1][1] = _pP11; + _pP[0][1] = _pP[1][0] = 0; + _firstAfterReset = true; + _prevUnwrappedTimestamp = -1; + _prevWrapTimestamp = -1; + _wrapArounds = 0; + _packetCount = 0; + _detectorAccumulatorPos = 0; + _detectorAccumulatorNeg = 0; } -void -TimestampExtrapolator::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(ts90khz) + - _wrapArounds * ((static_cast(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(unwrapped_ts90khz) - _firstTimestamp) - - static_cast(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++; - } +void TimestampExtrapolator::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(ts90khz) + + _wrapArounds * ((static_cast(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(unwrapped_ts90khz) - _firstTimestamp) - + static_cast(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 -TimestampExtrapolator::ExtrapolateLocalTime(uint32_t timestamp90khz) -{ - ReadLockScoped rl(*_rwLock); - int64_t localTimeMs = 0; - CheckForWrapArounds(timestamp90khz); - double unwrapped_ts90khz = static_cast(timestamp90khz) + - _wrapArounds * ((static_cast(1) << 32) - 1); - if (_packetCount == 0) - { - localTimeMs = -1; - } - else if (_packetCount < _startUpFilterDelayInPackets) - { - localTimeMs = _prevMs + static_cast( +int64_t TimestampExtrapolator::ExtrapolateLocalTime(uint32_t timestamp90khz) { + ReadLockScoped rl(*_rwLock); + int64_t localTimeMs = 0; + CheckForWrapArounds(timestamp90khz); + double unwrapped_ts90khz = + static_cast(timestamp90khz) + + _wrapArounds * ((static_cast(1) << 32) - 1); + if (_packetCount == 0) { + localTimeMs = -1; + } else if (_packetCount < _startUpFilterDelayInPackets) { + localTimeMs = + _prevMs + + static_cast( static_cast(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(_firstTimestamp); + localTimeMs = static_cast(static_cast(_startMs) + + (timestampDiff - _w[1]) / _w[0] + 0.5); } - else - { - if (_w[0] < 1e-3) - { - localTimeMs = _startMs; - } - else - { - double timestampDiff = unwrapped_ts90khz - - static_cast(_firstTimestamp); - localTimeMs = static_cast( - static_cast(_startMs) + (timestampDiff - _w[1]) / - _w[0] + 0.5); - } - } - return localTimeMs; + } + 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 -TimestampExtrapolator::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(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(_prevWrapTimestamp - ts90khz) > 0) - { - // Backward wrap around - _wrapArounds--; - } +// Investigates if the timestamp clock has overflowed since the last timestamp +// and keeps track of the number of wrap arounds since reset. +void TimestampExtrapolator::CheckForWrapArounds(uint32_t ts90khz) { + if (_prevWrapTimestamp == -1) { _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; + } + 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(ts90khz - _prevWrapTimestamp) > 0) { + // Forward wrap around + _wrapArounds++; } - 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(_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