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

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
« no previous file with comments | « remoting/base/leaky_bucket.h ('k') | remoting/protocol/webrtc_frame_scheduler_simple.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 current_level_(0),
15 level_updated_time_(base::TimeTicks::Now()) {}
16
17 LeakyBucket::~LeakyBucket() {}
18
19 bool LeakyBucket::RefillOrSpill(int drops, base::TimeTicks now) {
20 UpdateLevel(now);
21
22 int new_level = current_level_ + drops;
23 if (depth_ >= 0 && new_level > depth_)
24 return false;
25 current_level_ = new_level;
26 return true;
27 }
28
29 base::TimeTicks LeakyBucket::GetEmptyTime() {
30 return level_updated_time_ +
31 base::TimeDelta::FromMicroseconds(
32 base::TimeTicks::kMicrosecondsPerSecond * current_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 current_level_ -= rate_ * (now - level_updated_time_).InMicroseconds() /
42 base::TimeTicks::kMicrosecondsPerSecond;
43 if (current_level_ < 0)
44 current_level_ = 0;
45 level_updated_time_ = now;
46 }
47
48 } // namespace remoting
OLDNEW
« 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