Renamed rtc::RateLimiter to rtrc::DataRateLimiter.
This removes a confusing name collision between webrtc::RateLimiter
and rtc::RateLimiter where the header file names were separated only by
an underscore.
Bug: None
Change-Id: Ifcf0a4e62b2bf3bd9057714d7c536f7609ad1b79
Reviewed-on: https://webrtc-review.googlesource.com/58741
Commit-Queue: Sebastian Jansson <srte@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22237}diff --git a/media/base/mediachannel.h b/media/base/mediachannel.h
index d6205c2..a5831ff 100644
--- a/media/base/mediachannel.h
+++ b/media/base/mediachannel.h
@@ -46,7 +46,6 @@
namespace rtc {
-class RateLimiter;
class Timing;
}
diff --git a/media/base/rtpdataengine.cc b/media/base/rtpdataengine.cc
index 191645b..3aebe84 100644
--- a/media/base/rtpdataengine.cc
+++ b/media/base/rtpdataengine.cc
@@ -17,9 +17,9 @@
#include "media/base/rtputils.h"
#include "media/base/streamparams.h"
#include "rtc_base/copyonwritebuffer.h"
+#include "rtc_base/data_rate_limiter.h"
#include "rtc_base/helpers.h"
#include "rtc_base/logging.h"
-#include "rtc_base/ratelimiter.h"
#include "rtc_base/sanitizer.h"
#include "rtc_base/stringutils.h"
@@ -64,7 +64,7 @@
void RtpDataMediaChannel::Construct() {
sending_ = false;
receiving_ = false;
- send_limiter_.reset(new rtc::RateLimiter(kDataMaxBandwidth / 8, 1.0));
+ send_limiter_.reset(new rtc::DataRateLimiter(kDataMaxBandwidth / 8, 1.0));
}
@@ -248,7 +248,7 @@
if (bps <= 0) {
bps = kDataMaxBandwidth;
}
- send_limiter_.reset(new rtc::RateLimiter(bps / 8, 1.0));
+ send_limiter_.reset(new rtc::DataRateLimiter(bps / 8, 1.0));
RTC_LOG(LS_INFO) << "RtpDataMediaChannel::SetSendBandwidth to " << bps
<< "bps.";
return true;
diff --git a/media/base/rtpdataengine.h b/media/base/rtpdataengine.h
index 64e083b..52d4325 100644
--- a/media/base/rtpdataengine.h
+++ b/media/base/rtpdataengine.h
@@ -20,6 +20,10 @@
#include "media/base/mediaconstants.h"
#include "media/base/mediaengine.h"
+namespace rtc {
+class DataRateLimiter;
+}
+
namespace cricket {
struct DataCodec;
@@ -103,7 +107,7 @@
std::vector<StreamParams> send_streams_;
std::vector<StreamParams> recv_streams_;
std::map<uint32_t, RtpClock*> rtp_clock_by_send_ssrc_;
- std::unique_ptr<rtc::RateLimiter> send_limiter_;
+ std::unique_ptr<rtc::DataRateLimiter> send_limiter_;
};
} // namespace cricket
diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn
index df4969f..50c5c68 100644
--- a/rtc_base/BUILD.gn
+++ b/rtc_base/BUILD.gn
@@ -585,6 +585,8 @@
"crc32.h",
"cryptstring.cc",
"cryptstring.h",
+ "data_rate_limiter.cc",
+ "data_rate_limiter.h",
"dscp.h",
"filerotatingstream.cc",
"filerotatingstream.h",
@@ -630,7 +632,6 @@
"physicalsocketserver.h",
"proxyinfo.cc",
"proxyinfo.h",
- "ratelimiter.cc",
"ratelimiter.h",
"rtccertificate.cc",
"rtccertificate.h",
@@ -1085,6 +1086,7 @@
sources = [
"callback_unittest.cc",
"crc32_unittest.cc",
+ "data_rate_limiter_unittest.cc",
"helpers_unittest.cc",
"httpbase_unittest.cc",
"httpcommon_unittest.cc",
@@ -1098,7 +1100,6 @@
"optionsfile_unittest.cc",
"proxy_unittest.cc",
"ptr_util_unittest.cc",
- "ratelimiter_unittest.cc",
"rollingaccumulator_unittest.cc",
"rtccertificate_unittest.cc",
"rtccertificategenerator_unittest.cc",
diff --git a/rtc_base/ratelimiter.cc b/rtc_base/data_rate_limiter.cc
similarity index 82%
rename from rtc_base/ratelimiter.cc
rename to rtc_base/data_rate_limiter.cc
index 842538d..7288257 100644
--- a/rtc_base/ratelimiter.cc
+++ b/rtc_base/data_rate_limiter.cc
@@ -8,16 +8,16 @@
* be found in the AUTHORS file in the root of the source tree.
*/
-#include "rtc_base/ratelimiter.h"
+#include "rtc_base/data_rate_limiter.h"
namespace rtc {
-bool RateLimiter::CanUse(size_t desired, double time) {
+bool DataRateLimiter::CanUse(size_t desired, double time) {
return ((time > period_end_ && desired <= max_per_period_) ||
(used_in_period_ + desired) <= max_per_period_);
}
-void RateLimiter::Use(size_t used, double time) {
+void DataRateLimiter::Use(size_t used, double time) {
if (time > period_end_) {
period_start_ = time;
period_end_ = time + period_length_;
diff --git a/rtc_base/data_rate_limiter.h b/rtc_base/data_rate_limiter.h
new file mode 100644
index 0000000..d290816
--- /dev/null
+++ b/rtc_base/data_rate_limiter.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright 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 RTC_BASE_DATA_RATE_LIMITER_H_
+#define RTC_BASE_DATA_RATE_LIMITER_H_
+
+#include <stddef.h>
+
+namespace rtc {
+
+// Limits the rate of use to a certain maximum quantity per period of
+// time. Use, for example, for simple bandwidth throttling.
+//
+// It's implemented like a diet plan: You have so many calories per
+// day. If you hit the limit, you can't eat any more until the next
+// day.
+class DataRateLimiter {
+ public:
+ // For example, 100kb per second.
+ DataRateLimiter(size_t max, double period)
+ : max_per_period_(max),
+ period_length_(period),
+ used_in_period_(0),
+ period_start_(0.0),
+ period_end_(period) {}
+ virtual ~DataRateLimiter() {}
+
+ // Returns true if if the desired quantity is available in the
+ // current period (< (max - used)). Once the given time passes the
+ // end of the period, used is set to zero and more use is available.
+ bool CanUse(size_t desired, double time);
+ // Increment the quantity used this period. If past the end of a
+ // period, a new period is started.
+ void Use(size_t used, double time);
+
+ size_t used_in_period() const { return used_in_period_; }
+
+ size_t max_per_period() const { return max_per_period_; }
+
+ private:
+ size_t max_per_period_;
+ double period_length_;
+ size_t used_in_period_;
+ double period_start_;
+ double period_end_;
+};
+} // namespace rtc
+
+#endif // RTC_BASE_DATA_RATE_LIMITER_H_
diff --git a/rtc_base/ratelimiter_unittest.cc b/rtc_base/data_rate_limiter_unittest.cc
similarity index 94%
rename from rtc_base/ratelimiter_unittest.cc
rename to rtc_base/data_rate_limiter_unittest.cc
index f0931e4..8c410fe 100644
--- a/rtc_base/ratelimiter_unittest.cc
+++ b/rtc_base/data_rate_limiter_unittest.cc
@@ -8,14 +8,14 @@
* be found in the AUTHORS file in the root of the source tree.
*/
-#include "rtc_base/ratelimiter.h"
+#include "rtc_base/data_rate_limiter.h"
#include "rtc_base/gunit.h"
namespace rtc {
TEST(RateLimiterTest, TestCanUse) {
// Diet: Can eat 2,000 calories per day.
- RateLimiter limiter = RateLimiter(2000, 1.0);
+ DataRateLimiter limiter = DataRateLimiter(2000, 1.0);
double monday = 1.0;
double tuesday = 2.0;
diff --git a/rtc_base/ratelimiter.h b/rtc_base/ratelimiter.h
index 85706d3..8aa84aa 100644
--- a/rtc_base/ratelimiter.h
+++ b/rtc_base/ratelimiter.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 The WebRTC Project Authors. All rights reserved.
+ * Copyright 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
@@ -11,52 +11,14 @@
#ifndef RTC_BASE_RATELIMITER_H_
#define RTC_BASE_RATELIMITER_H_
-#include <stddef.h>
+#include "rtc_base/data_rate_limiter.h"
namespace rtc {
-
-// Limits the rate of use to a certain maximum quantity per period of
-// time. Use, for example, for simple bandwidth throttling.
-//
-// It's implemented like a diet plan: You have so many calories per
-// day. If you hit the limit, you can't eat any more until the next
-// day.
-class RateLimiter {
+// Deprecated, use DataRateLimiter instead
+class RateLimiter : public DataRateLimiter {
public:
- // For example, 100kb per second.
- RateLimiter(size_t max, double period)
- : max_per_period_(max),
- period_length_(period),
- used_in_period_(0),
- period_start_(0.0),
- period_end_(period) {
- }
- virtual ~RateLimiter() {}
-
- // Returns true if if the desired quantity is available in the
- // current period (< (max - used)). Once the given time passes the
- // end of the period, used is set to zero and more use is available.
- bool CanUse(size_t desired, double time);
- // Increment the quantity used this period. If past the end of a
- // period, a new period is started.
- void Use(size_t used, double time);
-
- size_t used_in_period() const {
- return used_in_period_;
- }
-
- size_t max_per_period() const {
- return max_per_period_;
- }
-
- private:
- size_t max_per_period_;
- double period_length_;
- size_t used_in_period_;
- double period_start_;
- double period_end_;
+ using DataRateLimiter::DataRateLimiter;
};
-
} // namespace rtc
#endif // RTC_BASE_RATELIMITER_H_