andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 1 | /* |
| 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.org | d5d709e | 2013-05-27 12:41:33 +0000 | [diff] [blame] | 14 | #include "webrtc/modules/remote_bitrate_estimator/include/bwe_defines.h" |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 15 | |
| 16 | namespace webrtc { |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 17 | |
solenberg@webrtc.org | 5f09bcc | 2013-04-30 08:33:46 +0000 | [diff] [blame] | 18 | class RemoteRateControl { |
| 19 | public: |
henrik.lundin@webrtc.org | c49a3fa | 2013-12-13 08:42:42 +0000 | [diff] [blame] | 20 | explicit RemoteRateControl(uint32_t min_bitrate_bps); |
solenberg@webrtc.org | 5f09bcc | 2013-04-30 08:33:46 +0000 | [diff] [blame] | 21 | ~RemoteRateControl() {} |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 22 | |
solenberg@webrtc.org | 5f09bcc | 2013-04-30 08:33:46 +0000 | [diff] [blame] | 23 | void Reset(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 24 | |
solenberg@webrtc.org | 5f09bcc | 2013-04-30 08:33:46 +0000 | [diff] [blame] | 25 | // Returns true if there is a valid estimate of the incoming bitrate, false |
| 26 | // otherwise. |
| 27 | bool ValidEstimate() const; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 28 | |
solenberg@webrtc.org | 5f09bcc | 2013-04-30 08:33:46 +0000 | [diff] [blame] | 29 | // 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.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 77 | }; |
pbos@webrtc.org | 3b89e10 | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 78 | } // namespace webrtc |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 79 | |
| 80 | #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_REMOTE_RATE_CONTROL_H_ |