Index: webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.cc |
diff --git a/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.cc b/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.cc |
index f38ef783067eb478b27d40837c34ac36f1b2bc43..d391f03262ed270a2ea036417ff70cdb0b436a3d 100644 |
--- a/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.cc |
+++ b/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.cc |
@@ -44,16 +44,17 @@ struct RemoteBitrateEstimatorSingleStream::Detector { |
OveruseDetector detector; |
}; |
- RemoteBitrateEstimatorSingleStream::RemoteBitrateEstimatorSingleStream( |
- RemoteBitrateObserver* observer, |
- Clock* clock) |
- : clock_(clock), |
- incoming_bitrate_(kBitrateWindowMs, 8000), |
- remote_rate_(new AimdRateControl()), |
- observer_(observer), |
- crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), |
- last_process_time_(-1), |
- process_interval_ms_(kProcessIntervalMs) { |
+RemoteBitrateEstimatorSingleStream::RemoteBitrateEstimatorSingleStream( |
+ RemoteBitrateObserver* observer, |
+ Clock* clock) |
+ : clock_(clock), |
+ incoming_bitrate_(kBitrateWindowMs, 8000), |
+ last_valid_incoming_bitrate_(0), |
+ remote_rate_(new AimdRateControl()), |
+ observer_(observer), |
+ crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), |
+ last_process_time_(-1), |
+ process_interval_ms_(kProcessIntervalMs) { |
assert(observer_); |
LOG(LS_INFO) << "RemoteBitrateEstimatorSingleStream: Instantiating."; |
} |
@@ -90,7 +91,20 @@ void RemoteBitrateEstimatorSingleStream::IncomingPacket(int64_t arrival_time_ms, |
} |
Detector* estimator = it->second; |
estimator->last_packet_time_ms = now_ms; |
+ |
+ // Check if incoming bitrate estimate is valid, and if it needs to be reset. |
+ rtc::Optional<uint32_t> incoming_bitrate = incoming_bitrate_.Rate(now_ms); |
+ if (incoming_bitrate) { |
+ last_valid_incoming_bitrate_ = *incoming_bitrate; |
+ } else if (last_valid_incoming_bitrate_ > 0) { |
+ // Incoming bitrate had a previous valid value, but now not enough data |
+ // point are left within the current window. Reset incoming bitrate |
+ // estimator so that the window size will only contain new data points. |
+ incoming_bitrate_.Reset(); |
+ last_valid_incoming_bitrate_ = 0; |
+ } |
incoming_bitrate_.Update(payload_size, now_ms); |
+ |
const BandwidthUsage prior_state = estimator->detector.State(); |
uint32_t timestamp_delta = 0; |
int64_t time_delta = 0; |
@@ -106,9 +120,11 @@ void RemoteBitrateEstimatorSingleStream::IncomingPacket(int64_t arrival_time_ms, |
estimator->estimator.num_of_deltas(), now_ms); |
} |
if (estimator->detector.State() == kBwOverusing) { |
- uint32_t incoming_bitrate_bps = incoming_bitrate_.Rate(now_ms); |
- if (prior_state != kBwOverusing || |
- remote_rate_->TimeToReduceFurther(now_ms, incoming_bitrate_bps)) { |
+ rtc::Optional<uint32_t> incoming_bitrate_bps = |
+ incoming_bitrate_.Rate(now_ms); |
+ if (incoming_bitrate_bps && |
+ (prior_state != kBwOverusing || |
+ remote_rate_->TimeToReduceFurther(now_ms, *incoming_bitrate_bps))) { |
// The first overuse should immediately trigger a new estimate. |
// We also have to update the estimate immediately if we are overusing |
// and the target bitrate is too high compared to what we are receiving. |
@@ -167,6 +183,7 @@ void RemoteBitrateEstimatorSingleStream::UpdateEstimate(int64_t now_ms) { |
remote_rate_.reset(new AimdRateControl()); |
return; |
} |
+ |
double mean_noise_var = sum_var_noise / |
static_cast<double>(overuse_detectors_.size()); |
const RateControlInput input(bw_state, |