mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-13 13:50:40 +01:00
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:
parent
b93baffb0a
commit
79eb1d98eb
25 changed files with 322 additions and 372 deletions
|
@ -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<typename T> class AlignedArray {
|
||||
template <typename T>
|
||||
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<T**>(AlignedMalloc(rows_ * sizeof(*head_row_),
|
||||
alignment));
|
||||
head_row_ =
|
||||
static_cast<T**>(AlignedMalloc(rows_ * sizeof(*head_row_), alignment));
|
||||
for (size_t i = 0; i < rows_; ++i) {
|
||||
head_row_[i] = static_cast<T*>(AlignedMalloc(cols_ * sizeof(**head_row_),
|
||||
alignment));
|
||||
head_row_[i] = static_cast<T*>(
|
||||
AlignedMalloc(cols_ * sizeof(**head_row_), alignment));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,13 +39,9 @@ template<typename T> 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<typename T> 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_;
|
||||
|
|
|
@ -38,8 +38,8 @@ void AlignedFree(void* mem_block);
|
|||
// to and from void*.
|
||||
template <typename T>
|
||||
T* GetRightAlign(const T* ptr, size_t alignment) {
|
||||
return reinterpret_cast<T*>(GetRightAlign(reinterpret_cast<const void*>(ptr),
|
||||
alignment));
|
||||
return reinterpret_cast<T*>(
|
||||
GetRightAlign(reinterpret_cast<const void*>(ptr), alignment));
|
||||
}
|
||||
template <typename T>
|
||||
T* AlignedMalloc(size_t size, size_t alignment) {
|
||||
|
@ -49,9 +49,7 @@ T* AlignedMalloc(size_t size, size_t alignment) {
|
|||
// Deleter for use with unique_ptr. E.g., use as
|
||||
// std::unique_ptr<Foo, AlignedFreeDeleter> foo;
|
||||
struct AlignedFreeDeleter {
|
||||
inline void operator()(void* ptr) const {
|
||||
AlignedFree(ptr);
|
||||
}
|
||||
inline void operator()(void* ptr) const { AlignedFree(ptr); }
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
|
|
@ -18,10 +18,7 @@ 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 {
|
||||
|
|
|
@ -62,7 +62,6 @@ class EventTimerWrapper : public EventWrapper {
|
|||
virtual bool StartTimer(bool periodic, unsigned long time) = 0;
|
||||
|
||||
virtual bool StopTimer() = 0;
|
||||
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
|
|
@ -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).
|
||||
|
@ -85,7 +84,8 @@
|
|||
|
||||
#define RTC_HISTOGRAM_COUNTS(name, sample, min, max, bucket_count) \
|
||||
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) \
|
||||
RTC_HISTOGRAM_COMMON_BLOCK(name, sample, \
|
||||
|
@ -114,7 +114,8 @@
|
|||
|
||||
#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))
|
||||
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.
|
||||
|
@ -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);
|
||||
|
|
|
@ -14,11 +14,9 @@
|
|||
#include "system_wrappers/include/rw_lock_wrapper.h"
|
||||
#include "typedefs.h" // NOLINT(build/include)
|
||||
|
||||
namespace webrtc
|
||||
{
|
||||
namespace webrtc {
|
||||
|
||||
class TimestampExtrapolator
|
||||
{
|
||||
class TimestampExtrapolator {
|
||||
public:
|
||||
explicit TimestampExtrapolator(int64_t start_ms);
|
||||
~TimestampExtrapolator();
|
||||
|
|
|
@ -43,8 +43,8 @@ TEST(AlignedMalloc, GetRightAlign) {
|
|||
EXPECT_TRUE(scoped.get() != NULL);
|
||||
const uintptr_t aligned_address = reinterpret_cast<uintptr_t>(scoped.get());
|
||||
const uintptr_t misaligned_address = aligned_address - left_misalignment;
|
||||
const char* misaligned_ptr = reinterpret_cast<const char*>(
|
||||
misaligned_address);
|
||||
const char* misaligned_ptr =
|
||||
reinterpret_cast<const char*>(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
|
||||
|
||||
|
|
|
@ -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 <MMSystem.h>
|
||||
|
||||
#elif ((defined WEBRTC_LINUX) || (defined WEBRTC_MAC))
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
|
||||
#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 {
|
||||
|
@ -62,7 +63,8 @@ class RealTimeClock : public Clock {
|
|||
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;
|
||||
|
@ -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_);
|
||||
|
|
|
@ -33,14 +33,15 @@ static inline void __cpuid(int cpu_info[4], int 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"(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])
|
||||
__asm__ volatile("cpuid\n"
|
||||
: "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]),
|
||||
"=d"(cpu_info[3])
|
||||
: "a"(info_type));
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
#include "system_wrappers/include/cpu_info.h"
|
||||
|
||||
#if defined(WEBRTC_WIN)
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#ifndef EXCLUDE_D3D9
|
||||
#include <d3d9.h>
|
||||
#endif
|
||||
|
@ -51,7 +51,7 @@ static int DetectNumberOfCores() {
|
|||
|
||||
return number_of_cores;
|
||||
}
|
||||
}
|
||||
} // namespace internal
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
|
|
|
@ -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<int>(max_time);
|
||||
int to_wait = max_time == WEBRTC_EVENT_INFINITE
|
||||
? rtc::Event::kForever
|
||||
: static_cast<int>(max_time);
|
||||
return event_.Wait(to_wait) ? kEventSignaled : kEventTimeout;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,10 +22,7 @@
|
|||
|
||||
namespace webrtc {
|
||||
|
||||
enum State {
|
||||
kUp = 1,
|
||||
kDown = 2
|
||||
};
|
||||
enum State { kUp = 1, kDown = 2 };
|
||||
|
||||
class EventTimerPosix : public EventTimerWrapper {
|
||||
public:
|
||||
|
|
|
@ -24,8 +24,7 @@ EventTimerWin::EventTimerWin()
|
|||
FALSE, // manual reset
|
||||
FALSE, // initial state
|
||||
NULL)), // name of event
|
||||
timerID_(NULL) {
|
||||
}
|
||||
timerID_(NULL) {}
|
||||
|
||||
EventTimerWin::~EventTimerWin() {
|
||||
StopTimer();
|
||||
|
|
|
@ -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 <string>
|
||||
|
||||
|
@ -30,14 +30,13 @@ 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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -12,8 +12,7 @@
|
|||
|
||||
namespace webrtc {
|
||||
|
||||
RWLockPosix::RWLockPosix() : lock_() {
|
||||
}
|
||||
RWLockPosix::RWLockPosix() : lock_() {}
|
||||
|
||||
RWLockPosix::~RWLockPosix() {
|
||||
pthread_rwlock_destroy(&lock_);
|
||||
|
|
|
@ -74,12 +74,10 @@ bool RWLockWin::LoadModule() {
|
|||
initialize_srw_lock =
|
||||
(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");
|
||||
release_srw_lock_shared =
|
||||
|
|
|
@ -34,13 +34,11 @@ TimestampExtrapolator::TimestampExtrapolator(int64_t start_ms)
|
|||
Reset(start_ms);
|
||||
}
|
||||
|
||||
TimestampExtrapolator::~TimestampExtrapolator()
|
||||
{
|
||||
TimestampExtrapolator::~TimestampExtrapolator() {
|
||||
delete _rwLock;
|
||||
}
|
||||
|
||||
void TimestampExtrapolator::Reset(int64_t start_ms)
|
||||
{
|
||||
void TimestampExtrapolator::Reset(int64_t start_ms) {
|
||||
WriteLockScoped wl(*_rwLock);
|
||||
_startMs = start_ms;
|
||||
_prevMs = _startMs;
|
||||
|
@ -59,21 +57,15 @@ void TimestampExtrapolator::Reset(int64_t start_ms)
|
|||
_detectorAccumulatorNeg = 0;
|
||||
}
|
||||
|
||||
void
|
||||
TimestampExtrapolator::Update(int64_t tMs, uint32_t ts90khz)
|
||||
{
|
||||
|
||||
void TimestampExtrapolator::Update(int64_t tMs, uint32_t ts90khz) {
|
||||
_rwLock->AcquireLockExclusive();
|
||||
if (tMs - _prevMs > 10e3)
|
||||
{
|
||||
if (tMs - _prevMs > 10e3) {
|
||||
// Ten seconds without a complete frame.
|
||||
// Reset the extrapolator
|
||||
_rwLock->ReleaseLockExclusive();
|
||||
Reset(tMs);
|
||||
_rwLock->AcquireLockExclusive();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
_prevMs = tMs;
|
||||
}
|
||||
|
||||
|
@ -82,11 +74,11 @@ TimestampExtrapolator::Update(int64_t tMs, uint32_t ts90khz)
|
|||
|
||||
CheckForWrapArounds(ts90khz);
|
||||
|
||||
int64_t unwrapped_ts90khz = static_cast<int64_t>(ts90khz) +
|
||||
int64_t unwrapped_ts90khz =
|
||||
static_cast<int64_t>(ts90khz) +
|
||||
_wrapArounds * ((static_cast<int64_t>(1) << 32) - 1);
|
||||
|
||||
if (_firstAfterReset)
|
||||
{
|
||||
if (_firstAfterReset) {
|
||||
// Make an initial guess of the offset,
|
||||
// should be almost correct since tMs - _startMs
|
||||
// should about zero at this time.
|
||||
|
@ -95,12 +87,10 @@ TimestampExtrapolator::Update(int64_t tMs, uint32_t ts90khz)
|
|||
_firstAfterReset = false;
|
||||
}
|
||||
|
||||
double residual =
|
||||
(static_cast<double>(unwrapped_ts90khz) - _firstTimestamp) -
|
||||
double residual = (static_cast<double>(unwrapped_ts90khz) - _firstTimestamp) -
|
||||
static_cast<double>(tMs) * _w[0] - _w[1];
|
||||
if (DelayChangeDetection(residual) &&
|
||||
_packetCount >= _startUpFilterDelayInPackets)
|
||||
{
|
||||
_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.
|
||||
|
@ -108,8 +98,7 @@ TimestampExtrapolator::Update(int64_t tMs, uint32_t ts90khz)
|
|||
}
|
||||
|
||||
if (_prevUnwrappedTimestamp >= 0 &&
|
||||
unwrapped_ts90khz < _prevUnwrappedTimestamp)
|
||||
{
|
||||
unwrapped_ts90khz < _prevUnwrappedTimestamp) {
|
||||
// Drop reordered frames.
|
||||
_rwLock->ReleaseLockExclusive();
|
||||
return;
|
||||
|
@ -128,103 +117,87 @@ TimestampExtrapolator::Update(int64_t tMs, uint32_t ts90khz)
|
|||
_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]));
|
||||
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)
|
||||
{
|
||||
if (_packetCount < _startUpFilterDelayInPackets) {
|
||||
_packetCount++;
|
||||
}
|
||||
_rwLock->ReleaseLockExclusive();
|
||||
}
|
||||
|
||||
int64_t
|
||||
TimestampExtrapolator::ExtrapolateLocalTime(uint32_t timestamp90khz)
|
||||
{
|
||||
int64_t TimestampExtrapolator::ExtrapolateLocalTime(uint32_t timestamp90khz) {
|
||||
ReadLockScoped rl(*_rwLock);
|
||||
int64_t localTimeMs = 0;
|
||||
CheckForWrapArounds(timestamp90khz);
|
||||
double unwrapped_ts90khz = static_cast<double>(timestamp90khz) +
|
||||
double unwrapped_ts90khz =
|
||||
static_cast<double>(timestamp90khz) +
|
||||
_wrapArounds * ((static_cast<int64_t>(1) << 32) - 1);
|
||||
if (_packetCount == 0)
|
||||
{
|
||||
if (_packetCount == 0) {
|
||||
localTimeMs = -1;
|
||||
}
|
||||
else if (_packetCount < _startUpFilterDelayInPackets)
|
||||
{
|
||||
localTimeMs = _prevMs + static_cast<int64_t>(
|
||||
} 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)
|
||||
{
|
||||
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 {
|
||||
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
|
||||
TimestampExtrapolator::CheckForWrapArounds(uint32_t ts90khz)
|
||||
{
|
||||
if (_prevWrapTimestamp == -1)
|
||||
{
|
||||
// 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<int32_t>(ts90khz - _prevWrapTimestamp) > 0)
|
||||
{
|
||||
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)
|
||||
{
|
||||
// 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)
|
||||
{
|
||||
bool TimestampExtrapolator::DelayChangeDetection(double error) {
|
||||
// CUSUM detection of sudden delay changes
|
||||
error = (error > 0) ? std::min(error, _accMaxError) :
|
||||
std::max(error, -_accMaxError);
|
||||
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)
|
||||
{
|
||||
if (_detectorAccumulatorPos > _alarmThreshold ||
|
||||
_detectorAccumulatorNeg < -_alarmThreshold) {
|
||||
// Alarm
|
||||
_detectorAccumulatorPos = _detectorAccumulatorNeg = 0;
|
||||
return true;
|
||||
|
@ -232,4 +205,4 @@ TimestampExtrapolator::DelayChangeDetection(double error)
|
|||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace webrtc
|
||||
|
|
Loading…
Reference in a new issue