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

Unified Diff: remoting/base/leaky_bucket.h

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/BUILD.gn ('k') | remoting/base/leaky_bucket.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/base/leaky_bucket.h
diff --git a/remoting/base/leaky_bucket.h b/remoting/base/leaky_bucket.h
new file mode 100644
index 0000000000000000000000000000000000000000..ab5f762aacfbadc72e9fe918154a79c8b7968d8d
--- /dev/null
+++ b/remoting/base/leaky_bucket.h
@@ -0,0 +1,51 @@
+// 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.
+
+#ifndef REMOTING_BASE_LEAKY_BUCKET_H_
+#define REMOTING_BASE_LEAKY_BUCKET_H_
+
+#include "base/macros.h"
+#include "base/time/time.h"
+
+namespace remoting {
+
+class LeakyBucket {
+ public:
+ static const int kUnlimitedDepth = -1;
+
+ // |depth| specifies depth of the bucket in drops. kUnlimitedDepth indicate
+ // that bucket size is unlimited. |rate| is specified in drops per second.
+ LeakyBucket(int depth, int rate);
+ ~LeakyBucket();
+
+ // If the bucket can fit |drops| then adds them and returns true. Otherwise
+ // returns false.
+ bool RefillOrSpill(int drops, base::TimeTicks now);
+
+ // Updates rate.
+ void UpdateRate(int new_rate, base::TimeTicks now);
+
+ // Returns time when the bucket will be empty. The returned value may be in
+ // the past.
+ base::TimeTicks GetEmptyTime();
+
+ int rate() { return rate_; }
+
+ private:
+ void UpdateLevel(base::TimeTicks now);
+
+ int depth_;
+ int rate_;
+
+ // |current_level_| stores water level at |level_updated_time_|. Updated in
+ // UpdateLevel(), which is called from RefillOrSpill() and UpdateRate().
+ int current_level_;
+ base::TimeTicks level_updated_time_;
+
+ DISALLOW_COPY_AND_ASSIGN(LeakyBucket);
+};
+
+} // namespace remoting
+
+#endif // REMOTING_BASE_LEAKY_BUCKET_H_
« no previous file with comments | « remoting/base/BUILD.gn ('k') | remoting/base/leaky_bucket.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698