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 14 #include "webrtc/modules/remote_bitrate_estimator/include/bwe_defines.h" 15 16 namespace webrtc { 17 18 class RemoteRateControl { 19 public: 20 explicit RemoteRateControl(uint32_t min_bitrate_bps); 21 ~RemoteRateControl() {} 22 23 void Reset(); 24 25 // Returns true if there is a valid estimate of the incoming bitrate, false 26 // otherwise. 27 bool ValidEstimate() const; 28 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 57 uint32_t min_configured_bit_rate_; 58 uint32_t max_configured_bit_rate_; 59 uint32_t current_bit_rate_; 60 uint32_t max_hold_rate_; 61 float avg_max_bit_rate_; 62 float var_max_bit_rate_; 63 RateControlState rate_control_state_; 64 RateControlState came_from_state_; 65 RateControlRegion rate_control_region_; 66 int64_t last_bit_rate_change_; 67 RateControlInput current_input_; 68 bool updated_; 69 int64_t time_first_incoming_estimate_; 70 bool initialized_bit_rate_; 71 float avg_change_period_; 72 int64_t last_change_ms_; 73 float beta_; 74 unsigned int rtt_; 75 }; 76 } // namespace webrtc 77 78 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_REMOTE_RATE_CONTROL_H_ 79