Improvements to network control types.
This CL prepares for adding the BBR network controller and unit tests for GoogCC network controller. The changes include: * Adding pad_rate helper method on PacerConfig. * Adding ostream operators for controller feedback structs. * Adding increment operator to Timestamp class. * Adding kEpoch to Timestamp class to represent 0. * Rounding when multiplying with double. Bug: webrtc:8415 Change-Id: I58289f37a6f9f2eee0a88bb06fb24dc295942862 Reviewed-on: https://webrtc-review.googlesource.com/61503 Commit-Queue: Sebastian Jansson <srte@webrtc.org> Reviewed-by: Björn Terelius <terelius@webrtc.org> Cr-Commit-Position: refs/heads/master@{#22458}
This commit is contained in:
parent
dfe6bcdcd2
commit
aca5a7df73
@ -155,6 +155,7 @@ if (rtc_include_tests) {
|
||||
"../../remote_bitrate_estimator",
|
||||
"../../rtp_rtcp:rtp_rtcp_format",
|
||||
"../network_control",
|
||||
"../network_control:network_control_test",
|
||||
"//testing/gmock",
|
||||
]
|
||||
if (!build_with_chromium && is_clang) {
|
||||
|
||||
@ -11,6 +11,7 @@
|
||||
|
||||
#include "modules/congestion_controller/goog_cc/probe_controller.h"
|
||||
#include "modules/congestion_controller/network_control/include/network_types.h"
|
||||
#include "modules/congestion_controller/network_control/test/network_ostream_operators.h"
|
||||
#include "rtc_base/logging.h"
|
||||
#include "system_wrappers/include/clock.h"
|
||||
#include "test/gmock.h"
|
||||
|
||||
@ -26,12 +26,21 @@ rtc_static_library("network_control") {
|
||||
}
|
||||
|
||||
if (rtc_include_tests) {
|
||||
rtc_source_set("network_control_test") {
|
||||
testonly = true
|
||||
sources = [
|
||||
"test/network_ostream_operators.cc",
|
||||
"test/network_ostream_operators.h",
|
||||
]
|
||||
deps = [
|
||||
":network_control",
|
||||
]
|
||||
}
|
||||
rtc_source_set("network_control_unittests") {
|
||||
testonly = true
|
||||
sources = [
|
||||
"network_units_unittest.cc",
|
||||
]
|
||||
|
||||
deps = [
|
||||
":network_control",
|
||||
"../../../test:test_support",
|
||||
|
||||
@ -11,7 +11,6 @@
|
||||
#ifndef MODULES_CONGESTION_CONTROLLER_NETWORK_CONTROL_INCLUDE_NETWORK_TYPES_H_
|
||||
#define MODULES_CONGESTION_CONTROLLER_NETWORK_CONTROL_INCLUDE_NETWORK_TYPES_H_
|
||||
#include <stdint.h>
|
||||
#include <ostream>
|
||||
#include <vector>
|
||||
#include "modules/congestion_controller/network_control/include/network_units.h"
|
||||
#include "modules/include/module_common_types.h"
|
||||
@ -144,6 +143,7 @@ struct PacerConfig {
|
||||
// Pacer should send at least pad_window data over time_window duration.
|
||||
DataSize pad_window;
|
||||
DataRate data_rate() const { return data_window / time_window; }
|
||||
DataRate pad_rate() const { return pad_window / time_window; }
|
||||
};
|
||||
|
||||
struct ProbeClusterConfig {
|
||||
@ -164,10 +164,6 @@ struct TargetTransferRate {
|
||||
struct ProcessInterval {
|
||||
Timestamp at_time;
|
||||
};
|
||||
|
||||
::std::ostream& operator<<(::std::ostream& os,
|
||||
const ProbeClusterConfig& config);
|
||||
::std::ostream& operator<<(::std::ostream& os, const PacerConfig& config);
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // MODULES_CONGESTION_CONTROLLER_NETWORK_CONTROL_INCLUDE_NETWORK_TYPES_H_
|
||||
|
||||
@ -76,9 +76,15 @@ class TimeDelta {
|
||||
TimeDelta operator-(const TimeDelta& other) const {
|
||||
return TimeDelta::us(us() - other.us());
|
||||
}
|
||||
TimeDelta operator*(double scalar) const {
|
||||
return TimeDelta::us(us() * scalar);
|
||||
TimeDelta& operator-=(const TimeDelta& other) {
|
||||
microseconds_ -= other.us();
|
||||
return *this;
|
||||
}
|
||||
TimeDelta& operator+=(const TimeDelta& other) {
|
||||
microseconds_ += other.us();
|
||||
return *this;
|
||||
}
|
||||
TimeDelta operator*(double scalar) const;
|
||||
TimeDelta operator*(int64_t scalar) const {
|
||||
return TimeDelta::us(us() * scalar);
|
||||
}
|
||||
@ -121,16 +127,22 @@ inline TimeDelta operator*(const int32_t& scalar, const TimeDelta& delta) {
|
||||
// Timestamp represents the time that has passed since some unspecified epoch.
|
||||
// The epoch is assumed to be before any represented timestamps, this means that
|
||||
// negative values are not valid. The most notable feature is that the
|
||||
// difference of of two Timestamps results in a TimeDelta.
|
||||
// difference of two Timestamps results in a TimeDelta.
|
||||
class Timestamp {
|
||||
public:
|
||||
static const Timestamp kPlusInfinity;
|
||||
static const Timestamp kNotInitialized;
|
||||
Timestamp() : Timestamp(kNotInitialized) {}
|
||||
static Timestamp Infinity() { return kPlusInfinity; }
|
||||
static Timestamp s(int64_t seconds) { return Timestamp(seconds * 1000000); }
|
||||
static Timestamp ms(int64_t millis) { return Timestamp(millis * 1000); }
|
||||
static Timestamp us(int64_t micros) { return Timestamp(micros); }
|
||||
static Timestamp seconds(int64_t seconds) { return Timestamp::s(seconds); }
|
||||
static Timestamp s(int64_t seconds) {
|
||||
return Timestamp::us(seconds * 1000000);
|
||||
}
|
||||
static Timestamp ms(int64_t millis) { return Timestamp::us(millis * 1000); }
|
||||
static Timestamp us(int64_t micros) {
|
||||
RTC_DCHECK_GE(micros, 0);
|
||||
return Timestamp(micros);
|
||||
}
|
||||
int64_t s() const { return units_internal::DivideAndRound(us(), 1000000); }
|
||||
int64_t ms() const { return units_internal::DivideAndRound(us(), 1000); }
|
||||
int64_t us() const {
|
||||
@ -153,6 +165,14 @@ class Timestamp {
|
||||
Timestamp operator+(const TimeDelta& delta) const {
|
||||
return Timestamp::us(us() + delta.us());
|
||||
}
|
||||
Timestamp& operator-=(const TimeDelta& other) {
|
||||
microseconds_ -= other.us();
|
||||
return *this;
|
||||
}
|
||||
Timestamp& operator+=(const TimeDelta& other) {
|
||||
microseconds_ += other.us();
|
||||
return *this;
|
||||
}
|
||||
bool operator==(const Timestamp& other) const {
|
||||
return microseconds_ == other.microseconds_;
|
||||
}
|
||||
@ -181,8 +201,14 @@ class DataSize {
|
||||
DataSize() : DataSize(kNotInitialized) {}
|
||||
static DataSize Zero() { return kZero; }
|
||||
static DataSize Infinity() { return kPlusInfinity; }
|
||||
static DataSize bytes(int64_t bytes) { return DataSize(bytes); }
|
||||
static DataSize bits(int64_t bits) { return DataSize(bits / 8); }
|
||||
static DataSize bytes(int64_t bytes) {
|
||||
RTC_DCHECK_GE(bytes, 0);
|
||||
return DataSize(bytes);
|
||||
}
|
||||
static DataSize bits(int64_t bits) {
|
||||
RTC_DCHECK_GE(bits, 0);
|
||||
return DataSize(bits / 8);
|
||||
}
|
||||
int64_t bytes() const {
|
||||
RTC_DCHECK(IsFinite());
|
||||
return bytes_;
|
||||
@ -204,9 +230,7 @@ class DataSize {
|
||||
DataSize operator+(const DataSize& other) const {
|
||||
return DataSize::bytes(bytes() + other.bytes());
|
||||
}
|
||||
DataSize operator*(double scalar) const {
|
||||
return DataSize::bytes(bytes() * scalar);
|
||||
}
|
||||
DataSize operator*(double scalar) const;
|
||||
DataSize operator*(int64_t scalar) const {
|
||||
return DataSize::bytes(bytes() * scalar);
|
||||
}
|
||||
@ -268,9 +292,11 @@ class DataRate {
|
||||
static DataRate Zero() { return kZero; }
|
||||
static DataRate Infinity() { return kPlusInfinity; }
|
||||
static DataRate bytes_per_second(int64_t bytes_per_sec) {
|
||||
RTC_DCHECK_GE(bytes_per_sec, 0);
|
||||
return DataRate(bytes_per_sec * 8);
|
||||
}
|
||||
static DataRate bits_per_second(int64_t bits_per_sec) {
|
||||
RTC_DCHECK_GE(bits_per_sec, 0);
|
||||
return DataRate(bits_per_sec);
|
||||
}
|
||||
static DataRate bps(int64_t bits_per_sec) {
|
||||
@ -297,9 +323,7 @@ class DataRate {
|
||||
return bits_per_sec_ != kNotInitialized.bits_per_sec_;
|
||||
}
|
||||
bool IsFinite() const { return IsInitialized() && !IsInfinite(); }
|
||||
DataRate operator*(double scalar) const {
|
||||
return DataRate::bytes_per_second(bytes_per_second() * scalar);
|
||||
}
|
||||
DataRate operator*(double scalar) const;
|
||||
DataRate operator*(int64_t scalar) const {
|
||||
return DataRate::bytes_per_second(bytes_per_second() * scalar);
|
||||
}
|
||||
|
||||
@ -51,13 +51,4 @@ std::vector<PacketResult> TransportPacketsFeedback::PacketsWithFeedback()
|
||||
return packet_feedbacks;
|
||||
}
|
||||
|
||||
::std::ostream& operator<<(::std::ostream& os,
|
||||
const ProbeClusterConfig& config) {
|
||||
return os << "ProbeClusterConfig(...)";
|
||||
}
|
||||
|
||||
::std::ostream& operator<<(::std::ostream& os, const PacerConfig& config) {
|
||||
return os << "PacerConfig(...)";
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
*/
|
||||
|
||||
#include "modules/congestion_controller/network_control/include/network_units.h"
|
||||
#include <cmath>
|
||||
|
||||
namespace webrtc {
|
||||
namespace {
|
||||
@ -34,6 +35,18 @@ const DataSize DataSize::kZero = DataSize(0);
|
||||
const DataSize DataSize::kPlusInfinity = DataSize(kPlusInfinityVal);
|
||||
const DataSize DataSize::kNotInitialized = DataSize(kNotInitializedVal);
|
||||
|
||||
TimeDelta TimeDelta::operator*(double scalar) const {
|
||||
return TimeDelta::us(std::round(us() * scalar));
|
||||
}
|
||||
|
||||
DataSize DataSize::operator*(double scalar) const {
|
||||
return DataSize::bytes(std::round(bytes() * scalar));
|
||||
}
|
||||
|
||||
DataRate DataRate::operator*(double scalar) const {
|
||||
return DataRate::bytes_per_second(std::round(bytes_per_second() * scalar));
|
||||
}
|
||||
|
||||
DataRate operator/(const DataSize& size, const TimeDelta& duration) {
|
||||
RTC_DCHECK(size.bytes() < std::numeric_limits<int64_t>::max() / 1000000)
|
||||
<< "size is too large, size: " << size.bytes() << " is not less than "
|
||||
@ -98,4 +111,5 @@ DataSize operator*(const TimeDelta& duration, const DataRate& rate) {
|
||||
return os << value.ms() << " ms";
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2018 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.
|
||||
*/
|
||||
|
||||
#include "modules/congestion_controller/network_control/test/network_ostream_operators.h"
|
||||
|
||||
namespace webrtc {
|
||||
::std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982)
|
||||
::std::ostream& os, // no-presubmit-check TODO(webrtc:8982)
|
||||
const CongestionWindow& window) {
|
||||
return os << "CongestionWindow(...)";
|
||||
}
|
||||
::std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982)
|
||||
::std::ostream& os, // no-presubmit-check TODO(webrtc:8982)
|
||||
const ProbeClusterConfig& config) {
|
||||
return os << "ProbeClusterConfig(...)";
|
||||
}
|
||||
::std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982)
|
||||
::std::ostream& os, // no-presubmit-check TODO(webrtc:8982)
|
||||
const PacerConfig& config) {
|
||||
return os << "PacerConfig(...)";
|
||||
}
|
||||
::std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982)
|
||||
::std::ostream& os, // no-presubmit-check TODO(webrtc:8982)
|
||||
const TargetTransferRate& target_rate) {
|
||||
return os << "TargetTransferRate(...)";
|
||||
}
|
||||
} // namespace webrtc
|
||||
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2018 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 MODULES_CONGESTION_CONTROLLER_NETWORK_CONTROL_TEST_NETWORK_OSTREAM_OPERATORS_H_
|
||||
#define MODULES_CONGESTION_CONTROLLER_NETWORK_CONTROL_TEST_NETWORK_OSTREAM_OPERATORS_H_
|
||||
// Overloading ostream << operator is required for gtest printing.
|
||||
#include <ostream> // no-presubmit-check TODO(webrtc:8982)
|
||||
#include "modules/congestion_controller/network_control/include/network_types.h"
|
||||
|
||||
namespace webrtc {
|
||||
::std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982)
|
||||
::std::ostream& os, // no-presubmit-check TODO(webrtc:8982)
|
||||
const CongestionWindow& window);
|
||||
::std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982)
|
||||
::std::ostream& os, // no-presubmit-check TODO(webrtc:8982)
|
||||
const ProbeClusterConfig& config);
|
||||
::std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982)
|
||||
::std::ostream& os, // no-presubmit-check TODO(webrtc:8982)
|
||||
const PacerConfig& config);
|
||||
::std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982)
|
||||
::std::ostream& os, // no-presubmit-check TODO(webrtc:8982)
|
||||
const TargetTransferRate& target_rate);
|
||||
} // namespace webrtc
|
||||
#endif // MODULES_CONGESTION_CONTROLLER_NETWORK_CONTROL_TEST_NETWORK_OSTREAM_OPERATORS_H_
|
||||
Loading…
x
Reference in New Issue
Block a user