blob: b525834eca1b53e03722aae560a6c4d7815b3f0b [file] [log] [blame]
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +00001/*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_REMOTE_RATE_CONTROL_H_
12#define WEBRTC_MODULES_RTP_RTCP_SOURCE_REMOTE_RATE_CONTROL_H_
13
pbos@webrtc.orgd5d709e2013-05-27 12:41:33 +000014#include "webrtc/modules/remote_bitrate_estimator/include/bwe_defines.h"
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000015
16namespace webrtc {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000017
solenberg@webrtc.org5f09bcc2013-04-30 08:33:46 +000018class RemoteRateControl {
19 public:
henrik.lundin@webrtc.orgc49a3fa2013-12-13 08:42:42 +000020 explicit RemoteRateControl(uint32_t min_bitrate_bps);
solenberg@webrtc.org5f09bcc2013-04-30 08:33:46 +000021 ~RemoteRateControl() {}
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000022
solenberg@webrtc.org5f09bcc2013-04-30 08:33:46 +000023 void Reset();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000024
solenberg@webrtc.org5f09bcc2013-04-30 08:33:46 +000025 // Returns true if there is a valid estimate of the incoming bitrate, false
26 // otherwise.
27 bool ValidEstimate() const;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000028
solenberg@webrtc.org5f09bcc2013-04-30 08:33:46 +000029 // Returns true if the bitrate estimate hasn't been changed for more than
30 // an RTT, or if the incoming_bitrate is more than 5% above the current
31 // estimate. Should be used to decide if we should reduce the rate further
32 // when over-using.
33 bool TimeToReduceFurther(int64_t time_now,
34 unsigned int incoming_bitrate) const;
35
36 int32_t SetConfiguredBitRates(uint32_t min_bit_rate, uint32_t max_bit_rate);
37 uint32_t LatestEstimate() const;
38 uint32_t UpdateBandwidthEstimate(int64_t now_ms);
39 void SetRtt(unsigned int rtt);
40 RateControlRegion Update(const RateControlInput* input, int64_t now_ms);
41
42 private:
43 uint32_t ChangeBitRate(uint32_t current_bit_rate,
44 uint32_t incoming_bit_rate,
45 double delay_factor,
46 int64_t now_ms);
47 double RateIncreaseFactor(int64_t now_ms,
48 int64_t last_ms,
49 uint32_t reaction_time_ms,
50 double noise_var) const;
51 void UpdateChangePeriod(int64_t now_ms);
52 void UpdateMaxBitRateEstimate(float incoming_bit_rate_kbps);
53 void ChangeState(const RateControlInput& input, int64_t now_ms);
54 void ChangeState(RateControlState new_state);
55 void ChangeRegion(RateControlRegion region);
56 static void StateStr(RateControlState state, char* str);
57 static void StateStr(BandwidthUsage state, char* str);
58
59 uint32_t min_configured_bit_rate_;
60 uint32_t max_configured_bit_rate_;
61 uint32_t current_bit_rate_;
62 uint32_t max_hold_rate_;
63 float avg_max_bit_rate_;
64 float var_max_bit_rate_;
65 RateControlState rate_control_state_;
66 RateControlState came_from_state_;
67 RateControlRegion rate_control_region_;
68 int64_t last_bit_rate_change_;
69 RateControlInput current_input_;
70 bool updated_;
71 int64_t time_first_incoming_estimate_;
72 bool initialized_bit_rate_;
73 float avg_change_period_;
74 int64_t last_change_ms_;
75 float beta_;
76 unsigned int rtt_;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000077};
pbos@webrtc.org3b89e102013-07-03 15:12:26 +000078} // namespace webrtc
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000079
80#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_REMOTE_RATE_CONTROL_H_