summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/webrtc/system_wrappers/include
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/libwebrtc/webrtc/system_wrappers/include')
-rw-r--r--third_party/libwebrtc/webrtc/system_wrappers/include/aligned_array.h78
-rw-r--r--third_party/libwebrtc/webrtc/system_wrappers/include/aligned_malloc.h57
-rw-r--r--third_party/libwebrtc/webrtc/system_wrappers/include/asm_defines.h66
-rw-r--r--third_party/libwebrtc/webrtc/system_wrappers/include/atomic32.h59
-rw-r--r--third_party/libwebrtc/webrtc/system_wrappers/include/clock.h88
-rw-r--r--third_party/libwebrtc/webrtc/system_wrappers/include/cpu_features_wrapper.h48
-rw-r--r--third_party/libwebrtc/webrtc/system_wrappers/include/cpu_info.h28
-rw-r--r--third_party/libwebrtc/webrtc/system_wrappers/include/event_wrapper.h69
-rw-r--r--third_party/libwebrtc/webrtc/system_wrappers/include/field_trial.h75
-rw-r--r--third_party/libwebrtc/webrtc/system_wrappers/include/field_trial_default.h28
-rw-r--r--third_party/libwebrtc/webrtc/system_wrappers/include/file_wrapper.h88
-rw-r--r--third_party/libwebrtc/webrtc/system_wrappers/include/metrics.h272
-rw-r--r--third_party/libwebrtc/webrtc/system_wrappers/include/metrics_default.h61
-rw-r--r--third_party/libwebrtc/webrtc/system_wrappers/include/ntp_time.h58
-rw-r--r--third_party/libwebrtc/webrtc/system_wrappers/include/rtp_to_ntp_estimator.h90
-rw-r--r--third_party/libwebrtc/webrtc/system_wrappers/include/rw_lock_wrapper.h64
-rw-r--r--third_party/libwebrtc/webrtc/system_wrappers/include/sleep.h24
-rw-r--r--third_party/libwebrtc/webrtc/system_wrappers/include/timestamp_extrapolator.h54
18 files changed, 1307 insertions, 0 deletions
diff --git a/third_party/libwebrtc/webrtc/system_wrappers/include/aligned_array.h b/third_party/libwebrtc/webrtc/system_wrappers/include/aligned_array.h
new file mode 100644
index 0000000000..793c785820
--- /dev/null
+++ b/third_party/libwebrtc/webrtc/system_wrappers/include/aligned_array.h
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_ALIGNED_ARRAY_
+#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_ALIGNED_ARRAY_
+
+#include "rtc_base/checks.h"
+#include "system_wrappers/include/aligned_malloc.h"
+
+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 {
+ public:
+ AlignedArray(size_t rows, size_t cols, size_t alignment)
+ : rows_(rows), cols_(cols) {
+ RTC_CHECK_GT(alignment, 0);
+ 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));
+ }
+ }
+
+ ~AlignedArray() {
+ for (size_t i = 0; i < rows_; ++i) {
+ AlignedFree(head_row_[i]);
+ }
+ AlignedFree(head_row_);
+ }
+
+ T* const* Array() { return head_row_; }
+
+ const T* const* Array() const { return head_row_; }
+
+ T* Row(size_t row) {
+ RTC_CHECK_LE(row, rows_);
+ return head_row_[row];
+ }
+
+ const T* Row(size_t row) const {
+ RTC_CHECK_LE(row, rows_);
+ return head_row_[row];
+ }
+
+ T& At(size_t row, size_t col) {
+ RTC_CHECK_LE(col, cols_);
+ return Row(row)[col];
+ }
+
+ const T& At(size_t row, size_t col) const {
+ RTC_CHECK_LE(col, cols_);
+ return Row(row)[col];
+ }
+
+ size_t rows() const { return rows_; }
+
+ size_t cols() const { return cols_; }
+
+ private:
+ size_t rows_;
+ size_t cols_;
+ T** head_row_;
+};
+
+} // namespace webrtc
+
+#endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_ALIGNED_ARRAY_
diff --git a/third_party/libwebrtc/webrtc/system_wrappers/include/aligned_malloc.h b/third_party/libwebrtc/webrtc/system_wrappers/include/aligned_malloc.h
new file mode 100644
index 0000000000..33b23d2aec
--- /dev/null
+++ b/third_party/libwebrtc/webrtc/system_wrappers/include/aligned_malloc.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef SYSTEM_WRAPPERS_INCLUDE_ALIGNED_MALLOC_H_
+#define SYSTEM_WRAPPERS_INCLUDE_ALIGNED_MALLOC_H_
+
+// The functions declared here
+// 1) Allocates block of aligned memory.
+// 2) Re-calculates a pointer such that it is aligned to a higher or equal
+// address.
+// Note: alignment must be a power of two. The alignment is in bytes.
+
+#include <stddef.h>
+
+namespace webrtc {
+
+// Returns a pointer to the first boundry of |alignment| bytes following the
+// address of |ptr|.
+// Note that there is no guarantee that the memory in question is available.
+// |ptr| has no requirements other than it can't be NULL.
+void* GetRightAlign(const void* ptr, size_t alignment);
+
+// Allocates memory of |size| bytes aligned on an |alignment| boundry.
+// The return value is a pointer to the memory. Note that the memory must
+// be de-allocated using AlignedFree.
+void* AlignedMalloc(size_t size, size_t alignment);
+// De-allocates memory created using the AlignedMalloc() API.
+void AlignedFree(void* mem_block);
+
+// Templated versions to facilitate usage of aligned malloc without casting
+// 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));
+}
+template <typename T>
+T* AlignedMalloc(size_t size, size_t alignment) {
+ return reinterpret_cast<T*>(AlignedMalloc(size, 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); }
+};
+
+} // namespace webrtc
+
+#endif // SYSTEM_WRAPPERS_INCLUDE_ALIGNED_MALLOC_H_
diff --git a/third_party/libwebrtc/webrtc/system_wrappers/include/asm_defines.h b/third_party/libwebrtc/webrtc/system_wrappers/include/asm_defines.h
new file mode 100644
index 0000000000..7f4c80ef2c
--- /dev/null
+++ b/third_party/libwebrtc/webrtc/system_wrappers/include/asm_defines.h
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef SYSTEM_WRAPPERS_INCLUDE_ASM_DEFINES_H_
+#define SYSTEM_WRAPPERS_INCLUDE_ASM_DEFINES_H_
+
+#if defined(__linux__) && defined(__ELF__)
+.section .note.GNU-stack,"",%progbits
+#endif
+
+// Define the macros used in ARM assembly code, so that for Mac or iOS builds
+// we add leading underscores for the function names.
+#ifdef __APPLE__
+.macro GLOBAL_FUNCTION name
+.global _\name
+.private_extern _\name
+.endm
+.macro DEFINE_FUNCTION name
+_\name:
+.endm
+.macro CALL_FUNCTION name
+bl _\name
+.endm
+.macro GLOBAL_LABEL name
+.global _\name
+.private_extern _\name
+.endm
+#else
+.macro GLOBAL_FUNCTION name
+.global \name
+.hidden \name
+.endm
+.macro DEFINE_FUNCTION name
+#if defined(__linux__) && defined(__ELF__)
+.type \name,%function
+#endif
+\name:
+.endm
+.macro CALL_FUNCTION name
+bl \name
+.endm
+.macro GLOBAL_LABEL name
+.global \name
+.hidden \name
+.endm
+#endif
+
+// With Apple's clang compiler, for instructions ldrb, strh, etc.,
+// the condition code is after the width specifier. Here we define
+// only the ones that are actually used in the assembly files.
+#if (defined __llvm__) && (defined __APPLE__)
+.macro streqh reg1, reg2, num
+strheq \reg1, \reg2, \num
+.endm
+#endif
+
+.text
+
+#endif // SYSTEM_WRAPPERS_INCLUDE_ASM_DEFINES_H_
diff --git a/third_party/libwebrtc/webrtc/system_wrappers/include/atomic32.h b/third_party/libwebrtc/webrtc/system_wrappers/include/atomic32.h
new file mode 100644
index 0000000000..74a540ed89
--- /dev/null
+++ b/third_party/libwebrtc/webrtc/system_wrappers/include/atomic32.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+// Atomic, system independent 32-bit integer. Unless you know what you're
+// doing, use locks instead! :-)
+//
+// Note: assumes 32-bit (or higher) system
+#ifndef SYSTEM_WRAPPERS_INCLUDE_ATOMIC32_H_
+#define SYSTEM_WRAPPERS_INCLUDE_ATOMIC32_H_
+
+#include <atomic>
+
+#include <stddef.h>
+
+#include "common_types.h" // NOLINT(build/include)
+#include "rtc_base/constructormagic.h"
+
+namespace webrtc {
+
+// DEPRECATED: Please use std::atomic<int32_t> instead.
+// TODO(yuweih): Replace Atomic32 uses with std::atomic<int32_t> and remove this
+// class. (bugs.webrtc.org/8428)
+// 32 bit atomic variable. Note that this class relies on the compiler to
+// align the 32 bit value correctly (on a 32 bit boundary), so as long as you're
+// not doing things like reinterpret_cast over some custom allocated memory
+// without being careful with alignment, you should be fine.
+class Atomic32 {
+ public:
+ Atomic32(int32_t initial_value = 0);
+ ~Atomic32();
+
+ // Prefix operator!
+ int32_t operator++();
+ int32_t operator--();
+
+ int32_t operator+=(int32_t value);
+ int32_t operator-=(int32_t value);
+
+ // Sets the value atomically to new_value if the value equals compare value.
+ // The function returns true if the exchange happened.
+ bool CompareExchange(int32_t new_value, int32_t compare_value);
+ int32_t Value() const;
+
+ private:
+ RTC_DISALLOW_COPY_AND_ASSIGN(Atomic32);
+
+ std::atomic<int32_t> value_;
+};
+
+} // namespace webrtc
+
+#endif // SYSTEM_WRAPPERS_INCLUDE_ATOMIC32_H_
diff --git a/third_party/libwebrtc/webrtc/system_wrappers/include/clock.h b/third_party/libwebrtc/webrtc/system_wrappers/include/clock.h
new file mode 100644
index 0000000000..aec5ca5be9
--- /dev/null
+++ b/third_party/libwebrtc/webrtc/system_wrappers/include/clock.h
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2013 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_CLOCK_H_
+#define SYSTEM_WRAPPERS_INCLUDE_CLOCK_H_
+
+#include <memory>
+
+#include "system_wrappers/include/ntp_time.h"
+#include "system_wrappers/include/rw_lock_wrapper.h"
+#include "typedefs.h" // NOLINT(build/include)
+
+namespace webrtc {
+
+// January 1970, in NTP seconds.
+const uint32_t kNtpJan1970 = 2208988800UL;
+
+// Magic NTP fractional unit.
+const double kMagicNtpFractionalUnit = 4.294967296E+9;
+
+// A clock interface that allows reading of absolute and relative timestamps.
+class Clock {
+ public:
+ virtual ~Clock() {}
+
+ // Return a timestamp in milliseconds relative to some arbitrary source; the
+ // source is fixed for this clock.
+ virtual int64_t TimeInMilliseconds() const = 0;
+
+ // Return a timestamp in microseconds relative to some arbitrary source; the
+ // source is fixed for this clock.
+ virtual int64_t TimeInMicroseconds() const = 0;
+
+ // Retrieve an NTP absolute timestamp.
+ virtual NtpTime CurrentNtpTime() const = 0;
+
+ // Retrieve an NTP absolute timestamp in milliseconds.
+ virtual int64_t CurrentNtpInMilliseconds() const = 0;
+
+ // Converts an NTP timestamp to a millisecond timestamp.
+ static int64_t NtpToMs(uint32_t seconds, uint32_t fractions) {
+ return NtpTime(seconds, fractions).ToMs();
+ }
+
+ // Returns an instance of the real-time system clock implementation.
+ static Clock* GetRealTimeClock();
+};
+
+class SimulatedClock : public Clock {
+ public:
+ explicit SimulatedClock(int64_t initial_time_us);
+
+ ~SimulatedClock() override;
+
+ // Return a timestamp in milliseconds relative to some arbitrary source; the
+ // source is fixed for this clock.
+ int64_t TimeInMilliseconds() const override;
+
+ // Return a timestamp in microseconds relative to some arbitrary source; the
+ // source is fixed for this clock.
+ int64_t TimeInMicroseconds() const override;
+
+ // Retrieve an NTP absolute timestamp.
+ NtpTime CurrentNtpTime() const override;
+
+ // Converts an NTP timestamp to a millisecond timestamp.
+ int64_t CurrentNtpInMilliseconds() const override;
+
+ // Advance the simulated clock with a given number of milliseconds or
+ // microseconds.
+ void AdvanceTimeMilliseconds(int64_t milliseconds);
+ void AdvanceTimeMicroseconds(int64_t microseconds);
+
+ private:
+ int64_t time_us_;
+ std::unique_ptr<RWLockWrapper> lock_;
+};
+
+}; // namespace webrtc
+
+#endif // SYSTEM_WRAPPERS_INCLUDE_CLOCK_H_
diff --git a/third_party/libwebrtc/webrtc/system_wrappers/include/cpu_features_wrapper.h b/third_party/libwebrtc/webrtc/system_wrappers/include/cpu_features_wrapper.h
new file mode 100644
index 0000000000..07ee912cb2
--- /dev/null
+++ b/third_party/libwebrtc/webrtc/system_wrappers/include/cpu_features_wrapper.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef SYSTEM_WRAPPERS_INCLUDE_CPU_FEATURES_WRAPPER_H_
+#define SYSTEM_WRAPPERS_INCLUDE_CPU_FEATURES_WRAPPER_H_
+
+#if defined(__cplusplus) || defined(c_plusplus)
+extern "C" {
+#endif
+
+#include "typedefs.h" // NOLINT(build/include)
+
+// List of features in x86.
+typedef enum { kSSE2, kSSE3 } CPUFeature;
+
+// List of features in ARM.
+enum {
+ kCPUFeatureARMv7 = (1 << 0),
+ kCPUFeatureVFPv3 = (1 << 1),
+ kCPUFeatureNEON = (1 << 2),
+ kCPUFeatureLDREXSTREX = (1 << 3)
+};
+
+typedef int (*WebRtc_CPUInfo)(CPUFeature feature);
+
+// Returns true if the CPU supports the feature.
+extern WebRtc_CPUInfo WebRtc_GetCPUInfo;
+
+// No CPU feature is available => straight C path.
+extern WebRtc_CPUInfo WebRtc_GetCPUInfoNoASM;
+
+// Return the features in an ARM device.
+// It detects the features in the hardware platform, and returns supported
+// values in the above enum definition as a bitmask.
+extern uint64_t WebRtc_GetCPUFeaturesARM(void);
+
+#if defined(__cplusplus) || defined(c_plusplus)
+} // extern "C"
+#endif
+
+#endif // SYSTEM_WRAPPERS_INCLUDE_CPU_FEATURES_WRAPPER_H_
diff --git a/third_party/libwebrtc/webrtc/system_wrappers/include/cpu_info.h b/third_party/libwebrtc/webrtc/system_wrappers/include/cpu_info.h
new file mode 100644
index 0000000000..dbd5d606aa
--- /dev/null
+++ b/third_party/libwebrtc/webrtc/system_wrappers/include/cpu_info.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef SYSTEM_WRAPPERS_INCLUDE_CPU_INFO_H_
+#define SYSTEM_WRAPPERS_INCLUDE_CPU_INFO_H_
+
+#include "typedefs.h" // NOLINT(build/include)
+
+namespace webrtc {
+
+class CpuInfo {
+ public:
+ static uint32_t DetectNumberOfCores();
+
+ private:
+ CpuInfo() {}
+};
+
+} // namespace webrtc
+
+#endif // SYSTEM_WRAPPERS_INCLUDE_CPU_INFO_H_
diff --git a/third_party/libwebrtc/webrtc/system_wrappers/include/event_wrapper.h b/third_party/libwebrtc/webrtc/system_wrappers/include/event_wrapper.h
new file mode 100644
index 0000000000..0c29138203
--- /dev/null
+++ b/third_party/libwebrtc/webrtc/system_wrappers/include/event_wrapper.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef SYSTEM_WRAPPERS_INCLUDE_EVENT_WRAPPER_H_
+#define SYSTEM_WRAPPERS_INCLUDE_EVENT_WRAPPER_H_
+
+namespace webrtc {
+enum EventTypeWrapper {
+ kEventSignaled = 1,
+ kEventError = 2,
+ kEventTimeout = 3
+};
+
+#define WEBRTC_EVENT_INFINITE 0xffffffff
+
+class EventTimerWrapper;
+
+class EventWrapper {
+ public:
+ // Factory method. Constructor disabled.
+ static EventWrapper* Create();
+
+ virtual ~EventWrapper() {}
+
+ // Releases threads who are calling Wait() and has started waiting. Please
+ // note that a thread calling Wait() will not start waiting immediately.
+ // assumptions to the contrary is a very common source of issues in
+ // multithreaded programming.
+ // Set is sticky in the sense that it will release at least one thread
+ // either immediately or some time in the future.
+ virtual bool Set() = 0;
+
+ // Puts the calling thread into a wait state. The thread may be released
+ // by a Set() call depending on if other threads are waiting and if so on
+ // timing. The thread that was released will reset the event before leaving
+ // preventing more threads from being released. If multiple threads
+ // are waiting for the same Set(), only one (random) thread is guaranteed to
+ // be released. It is possible that multiple (random) threads are released
+ // Depending on timing.
+ //
+ // |max_time| is the maximum time to wait in milliseconds or
+ // WEBRTC_EVENT_INFINITE to wait infinitely.
+ virtual EventTypeWrapper Wait(unsigned long max_time) = 0;
+};
+
+class EventTimerWrapper : public EventWrapper {
+ public:
+ static EventTimerWrapper* Create();
+
+ // Starts a timer that will call a non-sticky version of Set() either once
+ // or periodically. If the timer is periodic it ensures that there is no
+ // drift over time relative to the system clock.
+ //
+ // |time| is in milliseconds.
+ virtual bool StartTimer(bool periodic, unsigned long time) = 0;
+
+ virtual bool StopTimer() = 0;
+};
+
+} // namespace webrtc
+
+#endif // SYSTEM_WRAPPERS_INCLUDE_EVENT_WRAPPER_H_
diff --git a/third_party/libwebrtc/webrtc/system_wrappers/include/field_trial.h b/third_party/libwebrtc/webrtc/system_wrappers/include/field_trial.h
new file mode 100644
index 0000000000..399dcbc0a6
--- /dev/null
+++ b/third_party/libwebrtc/webrtc/system_wrappers/include/field_trial.h
@@ -0,0 +1,75 @@
+//
+// Copyright (c) 2014 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_FIELD_TRIAL_H_
+#define SYSTEM_WRAPPERS_INCLUDE_FIELD_TRIAL_H_
+
+#include <string>
+
+// Field trials allow webrtc clients (such as Chrome) to turn on feature code
+// in binaries out in the field and gather information with that.
+//
+// WebRTC clients MUST provide an implementation of:
+//
+// std::string webrtc::field_trial::FindFullName(const std::string& trial).
+//
+// Or link with a default one provided in:
+//
+// system_wrappers/system_wrappers.gyp:field_trial_default
+//
+//
+// They are designed to wire up directly to chrome field trials and to speed up
+// developers by reducing the need to wire APIs to control whether a feature is
+// on/off. E.g. to experiment with a new method that could lead to a different
+// trade-off between CPU/bandwidth:
+//
+// 1 - Develop the feature with default behaviour off:
+//
+// if (FieldTrial::FindFullName("WebRTCExperimenMethod2") == "Enabled")
+// method2();
+// else
+// method1();
+//
+// 2 - Once the changes are rolled to chrome, the new code path can be
+// controlled as normal chrome field trials.
+//
+// 3 - Evaluate the new feature and clean the code paths.
+//
+// Notes:
+// - NOT every feature is a candidate to be controlled by this mechanism as
+// it may require negotation between involved parties (e.g. SDP).
+//
+// TODO(andresp): since chrome --force-fieldtrials does not marks the trial
+// as active it does not gets propaged to renderer process. For now one
+// needs to push a config with start_active:true or run a local finch
+// server.
+//
+// TODO(andresp): find out how to get bots to run tests with trials enabled.
+
+namespace webrtc {
+namespace field_trial {
+
+// Returns the group name chosen for the named trial, or the empty string
+// if the trial does not exists.
+//
+// Note: To keep things tidy append all the trial names with WebRTC.
+std::string FindFullName(const std::string& name);
+
+// Convenience method, returns true iff FindFullName(name) return a string that
+// starts with "Enabled".
+// TODO(tommi): Make sure all implementations support this.
+inline bool IsEnabled(const char* name) {
+ return FindFullName(name).find("Enabled") == 0;
+}
+
+} // namespace field_trial
+} // namespace webrtc
+
+#endif // SYSTEM_WRAPPERS_INCLUDE_FIELD_TRIAL_H_
diff --git a/third_party/libwebrtc/webrtc/system_wrappers/include/field_trial_default.h b/third_party/libwebrtc/webrtc/system_wrappers/include/field_trial_default.h
new file mode 100644
index 0000000000..1774c2d416
--- /dev/null
+++ b/third_party/libwebrtc/webrtc/system_wrappers/include/field_trial_default.h
@@ -0,0 +1,28 @@
+//
+// 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_FIELD_TRIAL_DEFAULT_H_
+#define SYSTEM_WRAPPERS_INCLUDE_FIELD_TRIAL_DEFAULT_H_
+
+namespace webrtc {
+namespace field_trial {
+
+// Optionally initialize field trial from a string.
+// This method can be called at most once before any other call into webrtc.
+// E.g. before the peer connection factory is constructed.
+// Note: trials_string must never be destroyed.
+void InitFieldTrialsFromString(const char* trials_string);
+
+const char* GetFieldTrialString();
+
+} // namespace field_trial
+} // namespace webrtc
+
+#endif // SYSTEM_WRAPPERS_INCLUDE_FIELD_TRIAL_DEFAULT_H_
diff --git a/third_party/libwebrtc/webrtc/system_wrappers/include/file_wrapper.h b/third_party/libwebrtc/webrtc/system_wrappers/include/file_wrapper.h
new file mode 100644
index 0000000000..143da13ac4
--- /dev/null
+++ b/third_party/libwebrtc/webrtc/system_wrappers/include/file_wrapper.h
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef SYSTEM_WRAPPERS_INCLUDE_FILE_WRAPPER_H_
+#define SYSTEM_WRAPPERS_INCLUDE_FILE_WRAPPER_H_
+
+#include <stddef.h>
+#include <stdio.h>
+
+#include "common_types.h" // NOLINT(build/include)
+#include "rtc_base/criticalsection.h"
+#include "typedefs.h" // NOLINT(build/include)
+
+// Implementation of an InStream and OutStream that can read (exclusive) or
+// write from/to a file.
+
+namespace webrtc {
+
+// TODO(tommi): Remove the base classes, rename to rtc::File and move to base.
+class FileWrapper : public InStream, public OutStream {
+ public:
+ static const size_t kMaxFileNameSize = 1024;
+
+ // Factory methods.
+ // TODO(tommi): Remove Create().
+ static FileWrapper* Create();
+ static FileWrapper Open(const char* file_name_utf8, bool read_only);
+
+ FileWrapper(FILE* file, size_t max_size);
+ ~FileWrapper() override;
+
+ // Support for move semantics.
+ FileWrapper(FileWrapper&& other);
+ FileWrapper& operator=(FileWrapper&& other);
+
+ // Returns true if a file has been opened.
+ bool is_open() const { return file_ != nullptr; }
+
+ // Opens a file in read or write mode, decided by the read_only parameter.
+ bool OpenFile(const char* file_name_utf8, bool read_only);
+
+ // Initializes the wrapper from an existing handle. The wrapper
+ // takes ownership of |handle| and closes it in CloseFile().
+ bool OpenFromFileHandle(FILE* handle);
+
+ void CloseFile();
+
+ // Limits the file size to |bytes|. Writing will fail after the cap
+ // is hit. Pass zero to use an unlimited size.
+ // TODO(tommi): Could we move this out into a separate class?
+ void SetMaxFileSize(size_t bytes);
+
+ // Flush any pending writes. Note: Flushing when closing, is not required.
+ int Flush();
+
+ // Rewinds the file to the start.
+ int Rewind() override;
+ int Read(void* buf, size_t length) override;
+ bool Write(const void* buf, size_t length) override;
+
+ private:
+ FileWrapper();
+
+ void CloseFileImpl();
+ int FlushImpl();
+
+ // TODO(tommi): Remove the lock.
+ rtc::CriticalSection lock_;
+
+ FILE* file_ = nullptr;
+ size_t position_ = 0;
+ size_t max_size_in_bytes_ = 0;
+
+ // Copying is not supported.
+ FileWrapper(const FileWrapper&) = delete;
+ FileWrapper& operator=(const FileWrapper&) = delete;
+};
+
+} // namespace webrtc
+
+#endif // SYSTEM_WRAPPERS_INCLUDE_FILE_WRAPPER_H_
diff --git a/third_party/libwebrtc/webrtc/system_wrappers/include/metrics.h b/third_party/libwebrtc/webrtc/system_wrappers/include/metrics.h
new file mode 100644
index 0000000000..13f2483b32
--- /dev/null
+++ b/third_party/libwebrtc/webrtc/system_wrappers/include/metrics.h
@@ -0,0 +1,272 @@
+//
+// Copyright (c) 2014 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_METRICS_H_
+#define SYSTEM_WRAPPERS_INCLUDE_METRICS_H_
+
+#include <string>
+
+#include "common_types.h" // NOLINT(build/include)
+#include "rtc_base/atomicops.h"
+#include "rtc_base/checks.h"
+
+// Macros for allowing WebRTC clients (e.g. Chrome) to gather and aggregate
+// statistics.
+//
+// Histogram for counters.
+// RTC_HISTOGRAM_COUNTS(name, sample, min, max, bucket_count);
+//
+// Histogram for enumerators.
+// The boundary should be above the max enumerator sample.
+// RTC_HISTOGRAM_ENUMERATION(name, sample, boundary);
+//
+//
+// The macros use the methods HistogramFactoryGetCounts,
+// HistogramFactoryGetEnumeration and HistogramAdd.
+//
+// Therefore, WebRTC clients must either:
+//
+// - provide implementations of
+// Histogram* webrtc::metrics::HistogramFactoryGetCounts(
+// const std::string& name, int sample, int min, int max,
+// int bucket_count);
+// Histogram* webrtc::metrics::HistogramFactoryGetEnumeration(
+// const std::string& name, int sample, int boundary);
+// void webrtc::metrics::HistogramAdd(
+// Histogram* histogram_pointer, const std::string& name, int sample);
+//
+// - or link with the default implementations (i.e.
+// system_wrappers:metrics_default).
+//
+//
+// Example usage:
+//
+// RTC_HISTOGRAM_COUNTS("WebRTC.Video.NacksSent", nacks_sent, 1, 100000, 100);
+//
+// enum Types {
+// kTypeX,
+// kTypeY,
+// kBoundary,
+// };
+//
+// RTC_HISTOGRAM_ENUMERATION("WebRTC.Types", kTypeX, kBoundary);
+//
+// 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).
+#define RTC_HISTOGRAM_COUNTS_100(name, sample) \
+ RTC_HISTOGRAM_COUNTS(name, sample, 1, 100, 50)
+
+#define RTC_HISTOGRAM_COUNTS_200(name, sample) \
+ RTC_HISTOGRAM_COUNTS(name, sample, 1, 200, 50)
+
+#define RTC_HISTOGRAM_COUNTS_500(name, sample) \
+ RTC_HISTOGRAM_COUNTS(name, sample, 1, 500, 50)
+
+#define RTC_HISTOGRAM_COUNTS_1000(name, sample) \
+ RTC_HISTOGRAM_COUNTS(name, sample, 1, 1000, 50)
+
+#define RTC_HISTOGRAM_COUNTS_10000(name, sample) \
+ RTC_HISTOGRAM_COUNTS(name, sample, 1, 10000, 50)
+
+#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_LINEAR(name, sample, min, max, bucket_count) \
+ RTC_HISTOGRAM_COMMON_BLOCK(name, sample, \
+ webrtc::metrics::HistogramFactoryGetCountsLinear( \
+ name, min, max, bucket_count))
+
+// Slow metrics: pointer to metric is acquired at each call and is not cached.
+//
+#define RTC_HISTOGRAM_COUNTS_SPARSE_100(name, sample) \
+ RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 100, 50)
+
+#define RTC_HISTOGRAM_COUNTS_SPARSE_200(name, sample) \
+ RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 200, 50)
+
+#define RTC_HISTOGRAM_COUNTS_SPARSE_500(name, sample) \
+ RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 500, 50)
+
+#define RTC_HISTOGRAM_COUNTS_SPARSE_1000(name, sample) \
+ RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 1000, 50)
+
+#define RTC_HISTOGRAM_COUNTS_SPARSE_10000(name, sample) \
+ RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 10000, 50)
+
+#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))
+
+// Histogram for percentage (evenly spaced buckets).
+#define RTC_HISTOGRAM_PERCENTAGE_SPARSE(name, sample) \
+ RTC_HISTOGRAM_ENUMERATION_SPARSE(name, sample, 101)
+
+// Histogram for booleans.
+#define RTC_HISTOGRAM_BOOLEAN_SPARSE(name, sample) \
+ RTC_HISTOGRAM_ENUMERATION_SPARSE(name, sample, 2)
+
+// Histogram for enumerators (evenly spaced buckets).
+// |boundary| should be above the max enumerator sample.
+#define RTC_HISTOGRAM_ENUMERATION_SPARSE(name, sample, boundary) \
+ RTC_HISTOGRAM_COMMON_BLOCK_SLOW( \
+ name, sample, \
+ webrtc::metrics::HistogramFactoryGetEnumeration(name, boundary))
+
+// Histogram for percentage (evenly spaced buckets).
+#define RTC_HISTOGRAM_PERCENTAGE(name, sample) \
+ RTC_HISTOGRAM_ENUMERATION(name, sample, 101)
+
+// Histogram for booleans.
+#define RTC_HISTOGRAM_BOOLEAN(name, sample) \
+ RTC_HISTOGRAM_ENUMERATION(name, sample, 2)
+
+// 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, \
+ webrtc::metrics::HistogramFactoryGetEnumeration(name, boundary))
+
+// The name of the histogram should not vary.
+// TODO(asapersson): Consider changing string to const char*.
+#define RTC_HISTOGRAM_COMMON_BLOCK(constant_name, sample, \
+ factory_get_invocation) \
+ do { \
+ static webrtc::metrics::Histogram* atomic_histogram_pointer = nullptr; \
+ webrtc::metrics::Histogram* histogram_pointer = \
+ rtc::AtomicOps::AcquireLoadPtr(&atomic_histogram_pointer); \
+ if (!histogram_pointer) { \
+ histogram_pointer = factory_get_invocation; \
+ webrtc::metrics::Histogram* prev_pointer = \
+ rtc::AtomicOps::CompareAndSwapPtr( \
+ &atomic_histogram_pointer, \
+ static_cast<webrtc::metrics::Histogram*>(nullptr), \
+ histogram_pointer); \
+ RTC_DCHECK(prev_pointer == nullptr || \
+ prev_pointer == histogram_pointer); \
+ } \
+ if (histogram_pointer) { \
+ webrtc::metrics::HistogramAdd(histogram_pointer, sample); \
+ } \
+ } while (0)
+
+// Deprecated.
+// The histogram is constructed/found for each call.
+// May be used for histograms with infrequent updates.`
+#define RTC_HISTOGRAM_COMMON_BLOCK_SLOW(name, sample, factory_get_invocation) \
+ do { \
+ webrtc::metrics::Histogram* histogram_pointer = factory_get_invocation; \
+ if (histogram_pointer) { \
+ webrtc::metrics::HistogramAdd(histogram_pointer, sample); \
+ } \
+ } while (0)
+
+// Helper macros.
+// Macros for calling a histogram with varying name (e.g. when using a metric
+// in different modes such as real-time vs screenshare). Fast, because pointer
+// 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))
+
+#define RTC_HISTOGRAMS_COUNTS_200(index, name, sample) \
+ 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))
+
+#define RTC_HISTOGRAMS_COUNTS_1000(index, name, sample) \
+ 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))
+
+#define RTC_HISTOGRAMS_COUNTS_100000(index, name, sample) \
+ 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))
+
+#define RTC_HISTOGRAMS_PERCENTAGE(index, name, sample) \
+ RTC_HISTOGRAMS_COMMON(index, name, sample, \
+ RTC_HISTOGRAM_PERCENTAGE(name, sample))
+
+#define RTC_HISTOGRAMS_COMMON(index, name, sample, macro_invocation) \
+ do { \
+ switch (index) { \
+ case 0: \
+ macro_invocation; \
+ break; \
+ case 1: \
+ macro_invocation; \
+ break; \
+ case 2: \
+ macro_invocation; \
+ break; \
+ default: \
+ RTC_NOTREACHED(); \
+ } \
+ } while (0)
+
+namespace webrtc {
+namespace metrics {
+
+// Time that should have elapsed for stats that are gathered once per call.
+enum { kMinRunTimeInSeconds = 10 };
+
+class Histogram;
+
+// Functions for getting pointer to histogram (constructs or finds the named
+// histogram).
+
+// Get histogram for counters.
+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,
+ int min,
+ int max,
+ int bucket_count);
+
+// Get histogram for enumerators.
+// |boundary| should be above the max enumerator sample.
+Histogram* HistogramFactoryGetEnumeration(const std::string& name,
+ int boundary);
+
+// Function for adding a |sample| to a histogram.
+void HistogramAdd(Histogram* histogram_pointer, int sample);
+
+} // namespace metrics
+} // namespace webrtc
+
+#endif // SYSTEM_WRAPPERS_INCLUDE_METRICS_H_
diff --git a/third_party/libwebrtc/webrtc/system_wrappers/include/metrics_default.h b/third_party/libwebrtc/webrtc/system_wrappers/include/metrics_default.h
new file mode 100644
index 0000000000..5ce3582204
--- /dev/null
+++ b/third_party/libwebrtc/webrtc/system_wrappers/include/metrics_default.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2016 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_METRICS_DEFAULT_H_
+#define SYSTEM_WRAPPERS_INCLUDE_METRICS_DEFAULT_H_
+
+#include <map>
+#include <memory>
+#include <string>
+
+namespace webrtc {
+namespace metrics {
+
+// This class does not actually exist. It is casted to an implementation defined
+// pointer inside the functions.
+class Histogram;
+
+struct SampleInfo {
+ SampleInfo(const std::string& name, int min, int max, size_t bucket_count);
+ ~SampleInfo();
+
+ const std::string name;
+ const int min;
+ const int max;
+ const size_t bucket_count;
+ std::map<int, int> samples; // <value, # of events>
+};
+
+// Enables collection of samples.
+// This method should be called before any other call into webrtc.
+void Enable();
+
+// Gets histograms and clears all samples.
+void GetAndReset(
+ std::map<std::string, std::unique_ptr<SampleInfo>>* histograms);
+
+// Functions below are mainly for testing.
+
+// Clears all samples.
+void Reset();
+
+// Returns the number of times the |sample| has been added to the histogram.
+int NumEvents(const std::string& name, int sample);
+
+// Returns the total number of added samples to the histogram.
+int NumSamples(const std::string& name);
+
+// Returns the minimum sample value (or -1 if the histogram has no samples).
+int MinSample(const std::string& name);
+
+} // namespace metrics
+} // namespace webrtc
+
+#endif // SYSTEM_WRAPPERS_INCLUDE_METRICS_DEFAULT_H_
diff --git a/third_party/libwebrtc/webrtc/system_wrappers/include/ntp_time.h b/third_party/libwebrtc/webrtc/system_wrappers/include/ntp_time.h
new file mode 100644
index 0000000000..e963ecf39c
--- /dev/null
+++ b/third_party/libwebrtc/webrtc/system_wrappers/include/ntp_time.h
@@ -0,0 +1,58 @@
+/*
+ * 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_
+
+#include <stdint.h>
+
+namespace webrtc {
+
+class NtpTime {
+ public:
+ static constexpr uint64_t kFractionsPerSecond = 0x100000000;
+ NtpTime() : value_(0) {}
+ explicit NtpTime(uint64_t value) : value_(value) {}
+ NtpTime(uint32_t seconds, uint32_t fractions)
+ : value_(seconds * kFractionsPerSecond + fractions) {}
+
+ NtpTime(const NtpTime&) = default;
+ NtpTime& operator=(const NtpTime&) = default;
+ explicit operator uint64_t() const { return value_; }
+
+ void Set(uint32_t seconds, uint32_t fractions) {
+ value_ = seconds * kFractionsPerSecond + fractions;
+ }
+ void Reset() { value_ = 0; }
+
+ int64_t ToMs() const {
+ static constexpr double kNtpFracPerMs = 4.294967296E6; // 2^32 / 1000.
+ const double frac_ms = static_cast<double>(fractions()) / kNtpFracPerMs;
+ return 1000 * static_cast<int64_t>(seconds()) +
+ static_cast<int64_t>(frac_ms + 0.5);
+ }
+ // NTP standard (RFC1305, section 3.1) explicitly state value 0 is invalid.
+ bool Valid() const { return value_ != 0; }
+
+ uint32_t seconds() const { return value_ / kFractionsPerSecond; }
+ uint32_t fractions() const { return value_ % kFractionsPerSecond; }
+
+ private:
+ uint64_t value_;
+};
+
+inline bool operator==(const NtpTime& n1, const NtpTime& n2) {
+ return static_cast<uint64_t>(n1) == static_cast<uint64_t>(n2);
+}
+inline bool operator!=(const NtpTime& n1, const NtpTime& n2) {
+ return !(n1 == n2);
+}
+
+} // namespace webrtc
+#endif // SYSTEM_WRAPPERS_INCLUDE_NTP_TIME_H_
diff --git a/third_party/libwebrtc/webrtc/system_wrappers/include/rtp_to_ntp_estimator.h b/third_party/libwebrtc/webrtc/system_wrappers/include/rtp_to_ntp_estimator.h
new file mode 100644
index 0000000000..7c0757c546
--- /dev/null
+++ b/third_party/libwebrtc/webrtc/system_wrappers/include/rtp_to_ntp_estimator.h
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef SYSTEM_WRAPPERS_INCLUDE_RTP_TO_NTP_ESTIMATOR_H_
+#define SYSTEM_WRAPPERS_INCLUDE_RTP_TO_NTP_ESTIMATOR_H_
+
+#include <list>
+
+#include "api/optional.h"
+#include "modules/include/module_common_types_public.h"
+#include "rtc_base/numerics/moving_median_filter.h"
+#include "system_wrappers/include/ntp_time.h"
+#include "typedefs.h" // NOLINT(build/include)
+
+namespace webrtc {
+// Class for converting an RTP timestamp to the NTP domain in milliseconds.
+// The class needs to be trained with (at least 2) RTP/NTP timestamp pairs from
+// RTCP sender reports before the convertion can be done.
+class RtpToNtpEstimator {
+ public:
+ RtpToNtpEstimator();
+ ~RtpToNtpEstimator();
+
+ // RTP and NTP timestamp pair from a RTCP SR report.
+ struct RtcpMeasurement {
+ RtcpMeasurement(uint32_t ntp_secs,
+ uint32_t ntp_frac,
+ int64_t unwrapped_timestamp);
+ bool IsEqual(const RtcpMeasurement& other) const;
+
+ NtpTime ntp_time;
+ int64_t unwrapped_rtp_timestamp;
+ };
+
+ // Estimated parameters from RTP and NTP timestamp pairs in |measurements_|.
+ struct Parameters {
+ // Implicit conversion from int because MovingMedianFilter returns 0
+ // internally if no samples are present. However, it should never happen as
+ // we don't ask smoothing_filter_ to return anything if there were no
+ // samples.
+ Parameters(const int& value) { // NOLINT
+ RTC_NOTREACHED();
+ }
+ Parameters() : frequency_khz(0.0), offset_ms(0.0) {}
+
+ double frequency_khz;
+ double offset_ms;
+
+ // Needed to make it work inside MovingMedianFilter
+ bool operator<(const Parameters& other) const;
+ bool operator==(const Parameters& other) const;
+ bool operator<=(const Parameters& other) const;
+ bool operator!=(const Parameters& other) const;
+ };
+
+ // Updates measurements with RTP/NTP timestamp pair from a RTCP sender report.
+ // |new_rtcp_sr| is set to true if a new report is added.
+ bool UpdateMeasurements(uint32_t ntp_secs,
+ uint32_t ntp_frac,
+ uint32_t rtp_timestamp,
+ bool* new_rtcp_sr);
+
+ // Converts an RTP timestamp to the NTP domain in milliseconds.
+ // Returns true on success, false otherwise.
+ bool Estimate(int64_t rtp_timestamp, int64_t* rtp_timestamp_ms) const;
+
+ // Returns estimated rtp to ntp linear transform parameters.
+ const rtc::Optional<Parameters> params() const;
+
+ static const int kMaxInvalidSamples = 3;
+
+ private:
+ void UpdateParameters();
+
+ int consecutive_invalid_samples_;
+ std::list<RtcpMeasurement> measurements_;
+ MovingMedianFilter<Parameters> smoothing_filter_;
+ bool params_calculated_;
+ mutable TimestampUnwrapper unwrapper_;
+};
+} // namespace webrtc
+
+#endif // SYSTEM_WRAPPERS_INCLUDE_RTP_TO_NTP_ESTIMATOR_H_
diff --git a/third_party/libwebrtc/webrtc/system_wrappers/include/rw_lock_wrapper.h b/third_party/libwebrtc/webrtc/system_wrappers/include/rw_lock_wrapper.h
new file mode 100644
index 0000000000..a22b6ab9b9
--- /dev/null
+++ b/third_party/libwebrtc/webrtc/system_wrappers/include/rw_lock_wrapper.h
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef SYSTEM_WRAPPERS_INCLUDE_RW_LOCK_WRAPPER_H_
+#define SYSTEM_WRAPPERS_INCLUDE_RW_LOCK_WRAPPER_H_
+
+#include "rtc_base/thread_annotations.h"
+
+// Note, Windows pre-Vista version of RW locks are not supported natively. For
+// these OSs regular critical sections have been used to approximate RW lock
+// functionality and will therefore have worse performance.
+
+namespace webrtc {
+
+class RTC_LOCKABLE RWLockWrapper {
+ public:
+ static RWLockWrapper* CreateRWLock();
+ virtual ~RWLockWrapper() {}
+
+ virtual void AcquireLockExclusive() RTC_EXCLUSIVE_LOCK_FUNCTION() = 0;
+ virtual void ReleaseLockExclusive() RTC_UNLOCK_FUNCTION() = 0;
+
+ virtual void AcquireLockShared() RTC_SHARED_LOCK_FUNCTION() = 0;
+ virtual void ReleaseLockShared() RTC_UNLOCK_FUNCTION() = 0;
+};
+
+// RAII extensions of the RW lock. Prevents Acquire/Release missmatches and
+// provides more compact locking syntax.
+class RTC_SCOPED_LOCKABLE ReadLockScoped {
+ public:
+ ReadLockScoped(RWLockWrapper& rw_lock) RTC_SHARED_LOCK_FUNCTION(rw_lock)
+ : rw_lock_(rw_lock) {
+ rw_lock_.AcquireLockShared();
+ }
+
+ ~ReadLockScoped() RTC_UNLOCK_FUNCTION() { rw_lock_.ReleaseLockShared(); }
+
+ private:
+ RWLockWrapper& rw_lock_;
+};
+
+class RTC_SCOPED_LOCKABLE WriteLockScoped {
+ public:
+ WriteLockScoped(RWLockWrapper& rw_lock) RTC_EXCLUSIVE_LOCK_FUNCTION(rw_lock)
+ : rw_lock_(rw_lock) {
+ rw_lock_.AcquireLockExclusive();
+ }
+
+ ~WriteLockScoped() RTC_UNLOCK_FUNCTION() { rw_lock_.ReleaseLockExclusive(); }
+
+ private:
+ RWLockWrapper& rw_lock_;
+};
+
+} // namespace webrtc
+
+#endif // SYSTEM_WRAPPERS_INCLUDE_RW_LOCK_WRAPPER_H_
diff --git a/third_party/libwebrtc/webrtc/system_wrappers/include/sleep.h b/third_party/libwebrtc/webrtc/system_wrappers/include/sleep.h
new file mode 100644
index 0000000000..3bf8df219f
--- /dev/null
+++ b/third_party/libwebrtc/webrtc/system_wrappers/include/sleep.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+// An OS-independent sleep function.
+
+#ifndef SYSTEM_WRAPPERS_INCLUDE_SLEEP_H_
+#define SYSTEM_WRAPPERS_INCLUDE_SLEEP_H_
+
+namespace webrtc {
+
+// This function sleeps for the specified number of milliseconds.
+// It may return early if the thread is woken by some other event,
+// such as the delivery of a signal on Unix.
+void SleepMs(int msecs);
+
+} // namespace webrtc
+
+#endif // SYSTEM_WRAPPERS_INCLUDE_SLEEP_H_
diff --git a/third_party/libwebrtc/webrtc/system_wrappers/include/timestamp_extrapolator.h b/third_party/libwebrtc/webrtc/system_wrappers/include/timestamp_extrapolator.h
new file mode 100644
index 0000000000..9418100373
--- /dev/null
+++ b/third_party/libwebrtc/webrtc/system_wrappers/include/timestamp_extrapolator.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef SYSTEM_WRAPPERS_INCLUDE_TIMESTAMP_EXTRAPOLATOR_H_
+#define SYSTEM_WRAPPERS_INCLUDE_TIMESTAMP_EXTRAPOLATOR_H_
+
+#include "system_wrappers/include/rw_lock_wrapper.h"
+#include "typedefs.h" // NOLINT(build/include)
+
+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);
+
+ 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;
+};
+
+} // namespace webrtc
+
+#endif // SYSTEM_WRAPPERS_INCLUDE_TIMESTAMP_EXTRAPOLATOR_H_