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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "remoting/base/leaky_bucket.h"
6
7 #include "base/logging.h"
8
9 namespace remoting {
10
11 LeakyBucket::LeakyBucket(int depth, int rate)
12 : depth_(depth),
13 rate_(rate),
14 level_(0),
15 last_update_(base::TimeTicks::Now()) {
16 DCHECK_GE(depth_, 0);
17 }
18
19 LeakyBucket::~LeakyBucket() {}
20
21 bool LeakyBucket::RefillOrSpill(int size, base::TimeTicks now) {
22 UpdateLevel(now);
23
24 int new_level = level_ + size;
25 if (depth_ > 0 && new_level > depth_)
26 return false;
27 level_ = new_level;
28 return true;
29 }
30
31 base::TimeTicks LeakyBucket::GetEmptyTime() {
32 return last_update_ + base::TimeDelta::FromSecondsD(level_ / rate_);
33 }
34
35 void LeakyBucket::UpdateRate(int new_rate, base::TimeTicks now) {
36 UpdateLevel(now);
37 rate_ = new_rate;
38 }
39
40 void LeakyBucket::UpdateLevel(base::TimeTicks now) {
41 level_ -= rate_ * (now - last_update_).InMicroseconds() /
42 base::TimeTicks::kMicrosecondsPerSecond;
43 if (level_ < 0)
44 level_ = 0;
45 last_update_ = now;
46 }
47
48 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698