| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 ts_delta_hist_.clear(); | 46 ts_delta_hist_.clear(); |
| 47 } | 47 } |
| 48 | 48 |
| 49 void OveruseEstimator::Update(int64_t t_delta, | 49 void OveruseEstimator::Update(int64_t t_delta, |
| 50 double ts_delta, | 50 double ts_delta, |
| 51 int size_delta, | 51 int size_delta, |
| 52 BandwidthUsage current_hypothesis, | 52 BandwidthUsage current_hypothesis, |
| 53 int64_t now_ms) { | 53 int64_t now_ms) { |
| 54 const double min_frame_period = UpdateMinFramePeriod(ts_delta); | 54 const double min_frame_period = UpdateMinFramePeriod(ts_delta); |
| 55 const double t_ts_delta = t_delta - ts_delta; | 55 const double t_ts_delta = t_delta - ts_delta; |
| 56 BWE_TEST_LOGGING_PLOT(1, "dm[ms]", now_ms, t_ts_delta); | 56 BWE_TEST_LOGGING_PLOT(1, "dm_ms", now_ms, t_ts_delta); |
| 57 double fs_delta = size_delta; | 57 double fs_delta = size_delta; |
| 58 | 58 |
| 59 ++num_of_deltas_; | 59 ++num_of_deltas_; |
| 60 if (num_of_deltas_ > kDeltaCounterMax) { | 60 if (num_of_deltas_ > kDeltaCounterMax) { |
| 61 num_of_deltas_ = kDeltaCounterMax; | 61 num_of_deltas_ = kDeltaCounterMax; |
| 62 } | 62 } |
| 63 | 63 |
| 64 // Update the Kalman filter. | 64 // Update the Kalman filter. |
| 65 E_[0][0] += process_noise_[0]; | 65 E_[0][0] += process_noise_[0]; |
| 66 E_[1][1] += process_noise_[1]; | 66 E_[1][1] += process_noise_[1]; |
| 67 | 67 |
| 68 if ((current_hypothesis == kBwOverusing && offset_ < prev_offset_) || | 68 if ((current_hypothesis == kBwOverusing && offset_ < prev_offset_) || |
| 69 (current_hypothesis == kBwUnderusing && offset_ > prev_offset_)) { | 69 (current_hypothesis == kBwUnderusing && offset_ > prev_offset_)) { |
| 70 E_[1][1] += 10 * process_noise_[1]; | 70 E_[1][1] += 10 * process_noise_[1]; |
| 71 } | 71 } |
| 72 | 72 |
| 73 const double h[2] = {fs_delta, 1.0}; | 73 const double h[2] = {fs_delta, 1.0}; |
| 74 const double Eh[2] = {E_[0][0]*h[0] + E_[0][1]*h[1], | 74 const double Eh[2] = {E_[0][0]*h[0] + E_[0][1]*h[1], |
| 75 E_[1][0]*h[0] + E_[1][1]*h[1]}; | 75 E_[1][0]*h[0] + E_[1][1]*h[1]}; |
| 76 | 76 |
| 77 BWE_TEST_LOGGING_PLOT(1, "d[ms]", now_ms, slope_ * h[0] - offset_); | 77 BWE_TEST_LOGGING_PLOT(1, "d_ms", now_ms, slope_ * h[0] - offset_); |
| 78 | 78 |
| 79 const double residual = t_ts_delta - slope_*h[0] - offset_; | 79 const double residual = t_ts_delta - slope_*h[0] - offset_; |
| 80 | 80 |
| 81 const bool in_stable_state = (current_hypothesis == kBwNormal); | 81 const bool in_stable_state = (current_hypothesis == kBwNormal); |
| 82 const double max_residual = 3.0 * sqrt(var_noise_); | 82 const double max_residual = 3.0 * sqrt(var_noise_); |
| 83 // We try to filter out very late frames. For instance periodic key | 83 // We try to filter out very late frames. For instance periodic key |
| 84 // frames doesn't fit the Gaussian model well. | 84 // frames doesn't fit the Gaussian model well. |
| 85 if (fabs(residual) < max_residual) { | 85 if (fabs(residual) < max_residual) { |
| 86 UpdateNoiseEstimate(residual, min_frame_period, in_stable_state); | 86 UpdateNoiseEstimate(residual, min_frame_period, in_stable_state); |
| 87 } else { | 87 } else { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 113 LOG(LS_ERROR) << "The over-use estimator's covariance matrix is no longer " | 113 LOG(LS_ERROR) << "The over-use estimator's covariance matrix is no longer " |
| 114 "semi-definite."; | 114 "semi-definite."; |
| 115 } | 115 } |
| 116 | 116 |
| 117 slope_ = slope_ + K[0] * residual; | 117 slope_ = slope_ + K[0] * residual; |
| 118 prev_offset_ = offset_; | 118 prev_offset_ = offset_; |
| 119 offset_ = offset_ + K[1] * residual; | 119 offset_ = offset_ + K[1] * residual; |
| 120 | 120 |
| 121 BWE_TEST_LOGGING_PLOT(1, "kc", now_ms, K[0]); | 121 BWE_TEST_LOGGING_PLOT(1, "kc", now_ms, K[0]); |
| 122 BWE_TEST_LOGGING_PLOT(1, "km", now_ms, K[1]); | 122 BWE_TEST_LOGGING_PLOT(1, "km", now_ms, K[1]); |
| 123 BWE_TEST_LOGGING_PLOT(1, "slope[1/bps]", now_ms, slope_); | 123 BWE_TEST_LOGGING_PLOT(1, "slope_1/bps", now_ms, slope_); |
| 124 BWE_TEST_LOGGING_PLOT(1, "var_noise", now_ms, var_noise_); | 124 BWE_TEST_LOGGING_PLOT(1, "var_noise", now_ms, var_noise_); |
| 125 } | 125 } |
| 126 | 126 |
| 127 double OveruseEstimator::UpdateMinFramePeriod(double ts_delta) { | 127 double OveruseEstimator::UpdateMinFramePeriod(double ts_delta) { |
| 128 double min_frame_period = ts_delta; | 128 double min_frame_period = ts_delta; |
| 129 if (ts_delta_hist_.size() >= kMinFramePeriodHistoryLength) { | 129 if (ts_delta_hist_.size() >= kMinFramePeriodHistoryLength) { |
| 130 ts_delta_hist_.pop_front(); | 130 ts_delta_hist_.pop_front(); |
| 131 } | 131 } |
| 132 std::list<double>::iterator it = ts_delta_hist_.begin(); | 132 std::list<double>::iterator it = ts_delta_hist_.begin(); |
| 133 for (; it != ts_delta_hist_.end(); it++) { | 133 for (; it != ts_delta_hist_.end(); it++) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 155 const double beta = pow(1 - alpha, ts_delta * 30.0 / 1000.0); | 155 const double beta = pow(1 - alpha, ts_delta * 30.0 / 1000.0); |
| 156 avg_noise_ = beta * avg_noise_ | 156 avg_noise_ = beta * avg_noise_ |
| 157 + (1 - beta) * residual; | 157 + (1 - beta) * residual; |
| 158 var_noise_ = beta * var_noise_ | 158 var_noise_ = beta * var_noise_ |
| 159 + (1 - beta) * (avg_noise_ - residual) * (avg_noise_ - residual); | 159 + (1 - beta) * (avg_noise_ - residual) * (avg_noise_ - residual); |
| 160 if (var_noise_ < 1) { | 160 if (var_noise_ < 1) { |
| 161 var_noise_ = 1; | 161 var_noise_ = 1; |
| 162 } | 162 } |
| 163 } | 163 } |
| 164 } // namespace webrtc | 164 } // namespace webrtc |
| OLD | NEW |