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}
This commit is contained in:
Sebastian Jansson 2018-02-28 16:04:26 +01:00 committed by Commit Bot
parent d3f3816ad5
commit f9c5cf65f6
8 changed files with 77 additions and 55 deletions

View file

@ -46,7 +46,6 @@
namespace rtc {
class RateLimiter;
class Timing;
}

View file

@ -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 @@ RtpDataMediaChannel::RtpDataMediaChannel(const MediaConfig& config)
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 @@ bool RtpDataMediaChannel::SetMaxSendBandwidth(int bps) {
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;

View file

@ -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 @@ class RtpDataMediaChannel : public DataMediaChannel {
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

View file

@ -585,6 +585,8 @@ rtc_static_library("rtc_base_generic") {
"crc32.h",
"cryptstring.cc",
"cryptstring.h",
"data_rate_limiter.cc",
"data_rate_limiter.h",
"dscp.h",
"filerotatingstream.cc",
"filerotatingstream.h",
@ -630,7 +632,6 @@ rtc_static_library("rtc_base_generic") {
"physicalsocketserver.h",
"proxyinfo.cc",
"proxyinfo.h",
"ratelimiter.cc",
"ratelimiter.h",
"rtccertificate.cc",
"rtccertificate.h",
@ -1085,6 +1086,7 @@ if (rtc_include_tests) {
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 @@ if (rtc_include_tests) {
"optionsfile_unittest.cc",
"proxy_unittest.cc",
"ptr_util_unittest.cc",
"ratelimiter_unittest.cc",
"rollingaccumulator_unittest.cc",
"rtccertificate_unittest.cc",
"rtccertificategenerator_unittest.cc",

View file

@ -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_;

View file

@ -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_

View file

@ -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;

View file

@ -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_