Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1651)

Unified Diff: webrtc/modules/remote_bitrate_estimator/overuse_estimator.cc

Issue 1481003002: Revert of Make overuse estimator one dimensional. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/remote_bitrate_estimator/overuse_estimator.cc
diff --git a/webrtc/modules/remote_bitrate_estimator/overuse_estimator.cc b/webrtc/modules/remote_bitrate_estimator/overuse_estimator.cc
index a9d3bfe609d2c69b05a8ae4f0e5393ae6a3404b0..4be7b7493b845945937765979797c250e53f229d 100644
--- a/webrtc/modules/remote_bitrate_estimator/overuse_estimator.cc
+++ b/webrtc/modules/remote_bitrate_estimator/overuse_estimator.cc
@@ -16,7 +16,6 @@
#include <stdlib.h>
#include <string.h>
-#include "webrtc/base/checks.h"
#include "webrtc/modules/remote_bitrate_estimator/include/bwe_defines.h"
#include "webrtc/system_wrappers/include/logging.h"
@@ -25,25 +24,33 @@
enum { kMinFramePeriodHistoryLength = 60 };
enum { kDeltaCounterMax = 1000 };
-OveruseEstimator::OveruseEstimator()
- : num_of_deltas_(0),
- offset_(0),
- prev_offset_(offset_),
- e_(0.1),
- process_noise_(1e-2),
- avg_noise_(0),
- var_noise_(50),
- send_delta_history_() {}
+OveruseEstimator::OveruseEstimator(const OverUseDetectorOptions& options)
+ : options_(options),
+ num_of_deltas_(0),
+ slope_(options_.initial_slope),
+ offset_(options_.initial_offset),
+ prev_offset_(options_.initial_offset),
+ E_(),
+ process_noise_(),
+ avg_noise_(options_.initial_avg_noise),
+ var_noise_(options_.initial_var_noise),
+ ts_delta_hist_() {
+ memcpy(E_, options_.initial_e, sizeof(E_));
+ memcpy(process_noise_, options_.initial_process_noise,
+ sizeof(process_noise_));
+}
OveruseEstimator::~OveruseEstimator() {
- send_delta_history_.clear();
+ ts_delta_hist_.clear();
}
-void OveruseEstimator::Update(double recv_delta_ms,
- double send_delta_ms,
+void OveruseEstimator::Update(int64_t t_delta,
+ double ts_delta,
+ int size_delta,
BandwidthUsage current_hypothesis) {
- const double min_frame_period = UpdateMinFramePeriod(send_delta_ms);
- const double delta_ms = recv_delta_ms - send_delta_ms;
+ const double min_frame_period = UpdateMinFramePeriod(ts_delta);
+ const double t_ts_delta = t_delta - ts_delta;
+ double fs_delta = size_delta;
++num_of_deltas_;
if (num_of_deltas_ > kDeltaCounterMax) {
@@ -51,14 +58,19 @@
}
// Update the Kalman filter.
- e_ += process_noise_;
+ E_[0][0] += process_noise_[0];
+ E_[1][1] += process_noise_[1];
if ((current_hypothesis == kBwOverusing && offset_ < prev_offset_) ||
(current_hypothesis == kBwUnderusing && offset_ > prev_offset_)) {
- e_ += 10 * process_noise_;
+ E_[1][1] += 10 * process_noise_[1];
}
- const double residual = delta_ms - offset_;
+ const double h[2] = {fs_delta, 1.0};
+ const double Eh[2] = {E_[0][0]*h[0] + E_[0][1]*h[1],
+ E_[1][0]*h[0] + E_[1][1]*h[1]};
+
+ const double residual = t_ts_delta - slope_*h[0] - offset_;
const bool in_stable_state = (current_hypothesis == kBwNormal);
const double max_residual = 3.0 * sqrt(var_noise_);
@@ -70,47 +82,66 @@
UpdateNoiseEstimate(residual < 0 ? -max_residual : max_residual,
min_frame_period, in_stable_state);
}
- const double k = e_ / (var_noise_ + e_);
+
+ const double denom = var_noise_ + h[0]*Eh[0] + h[1]*Eh[1];
+
+ const double K[2] = {Eh[0] / denom,
+ Eh[1] / denom};
+
+ const double IKh[2][2] = {{1.0 - K[0]*h[0], -K[0]*h[1]},
+ {-K[1]*h[0], 1.0 - K[1]*h[1]}};
+ const double e00 = E_[0][0];
+ const double e01 = E_[0][1];
// Update state.
- e_ = e_ * (1.0 - k);
+ E_[0][0] = e00 * IKh[0][0] + E_[1][0] * IKh[0][1];
+ E_[0][1] = e01 * IKh[0][0] + E_[1][1] * IKh[0][1];
+ E_[1][0] = e00 * IKh[1][0] + E_[1][0] * IKh[1][1];
+ E_[1][1] = e01 * IKh[1][0] + E_[1][1] * IKh[1][1];
- // The covariance matrix must be positive.
- RTC_DCHECK(e_ >= 0.0);
- if (e_ < 0)
- LOG(LS_ERROR) << "The over-use estimator's covariance is negative!";
+ // The covariance matrix must be positive semi-definite.
+ bool positive_semi_definite = E_[0][0] + E_[1][1] >= 0 &&
+ E_[0][0] * E_[1][1] - E_[0][1] * E_[1][0] >= 0 && E_[0][0] >= 0;
+ assert(positive_semi_definite);
+ if (!positive_semi_definite) {
+ LOG(LS_ERROR) << "The over-use estimator's covariance matrix is no longer "
+ "semi-definite.";
+ }
- offset_ = offset_ + k * residual;
+ slope_ = slope_ + K[0] * residual;
+ prev_offset_ = offset_;
+ offset_ = offset_ + K[1] * residual;
}
-double OveruseEstimator::UpdateMinFramePeriod(double send_delta_ms) {
- double min_frame_period = send_delta_ms;
- if (send_delta_history_.size() >= kMinFramePeriodHistoryLength) {
- send_delta_history_.pop_front();
+double OveruseEstimator::UpdateMinFramePeriod(double ts_delta) {
+ double min_frame_period = ts_delta;
+ if (ts_delta_hist_.size() >= kMinFramePeriodHistoryLength) {
+ ts_delta_hist_.pop_front();
}
- for (double delta_ms : send_delta_history_) {
- min_frame_period = std::min(delta_ms, min_frame_period);
+ std::list<double>::iterator it = ts_delta_hist_.begin();
+ for (; it != ts_delta_hist_.end(); it++) {
+ min_frame_period = std::min(*it, min_frame_period);
}
- send_delta_history_.push_back(send_delta_ms);
+ ts_delta_hist_.push_back(ts_delta);
return min_frame_period;
}
void OveruseEstimator::UpdateNoiseEstimate(double residual,
- double send_delta_ms,
+ double ts_delta,
bool stable_state) {
if (!stable_state) {
return;
}
// Faster filter during startup to faster adapt to the jitter level
// of the network. |alpha| is tuned for 30 frames per second, but is scaled
- // according to |send_delta_ms|.
+ // according to |ts_delta|.
double alpha = 0.01;
if (num_of_deltas_ > 10*30) {
alpha = 0.002;
}
// Only update the noise estimate if we're not over-using. |beta| is a
// function of alpha and the time delta since the previous update.
- const double beta = pow(1 - alpha, send_delta_ms * 30.0 / 1000.0);
+ const double beta = pow(1 - alpha, ts_delta * 30.0 / 1000.0);
avg_noise_ = beta * avg_noise_
+ (1 - beta) * residual;
var_noise_ = beta * var_noise_

Powered by Google App Engine
This is Rietveld 408576698