Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(305)

Unified Diff: remoting/base/leaky_bucket.cc

Issue 2381153002: Pace outgoing frames in frame scheduler to match target bitrate. (Closed)
Patch Set: . Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/base/leaky_bucket.h ('k') | remoting/protocol/webrtc_frame_scheduler_simple.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/base/leaky_bucket.cc
diff --git a/remoting/base/leaky_bucket.cc b/remoting/base/leaky_bucket.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9426692d42369d138dd830f95e2bdf9b21ef9372
--- /dev/null
+++ b/remoting/base/leaky_bucket.cc
@@ -0,0 +1,48 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "remoting/base/leaky_bucket.h"
+
+#include "base/logging.h"
+
+namespace remoting {
+
+LeakyBucket::LeakyBucket(int depth, int rate)
+ : depth_(depth),
+ rate_(rate),
+ current_level_(0),
+ level_updated_time_(base::TimeTicks::Now()) {}
+
+LeakyBucket::~LeakyBucket() {}
+
+bool LeakyBucket::RefillOrSpill(int drops, base::TimeTicks now) {
+ UpdateLevel(now);
+
+ int new_level = current_level_ + drops;
+ if (depth_ >= 0 && new_level > depth_)
+ return false;
+ current_level_ = new_level;
+ return true;
+}
+
+base::TimeTicks LeakyBucket::GetEmptyTime() {
+ return level_updated_time_ +
+ base::TimeDelta::FromMicroseconds(
+ base::TimeTicks::kMicrosecondsPerSecond * current_level_ / rate_);
+}
+
+void LeakyBucket::UpdateRate(int new_rate, base::TimeTicks now) {
+ UpdateLevel(now);
+ rate_ = new_rate;
+}
+
+void LeakyBucket::UpdateLevel(base::TimeTicks now) {
+ current_level_ -= rate_ * (now - level_updated_time_).InMicroseconds() /
+ base::TimeTicks::kMicrosecondsPerSecond;
+ if (current_level_ < 0)
+ current_level_ = 0;
+ level_updated_time_ = now;
+}
+
+} // namespace remoting
« no previous file with comments | « remoting/base/leaky_bucket.h ('k') | remoting/protocol/webrtc_frame_scheduler_simple.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698