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

Side by Side Diff: webrtc/modules/remote_bitrate_estimator/overuse_estimator.cc

Issue 2296253002: Enable BWE logging to command line when rtc_enable_bwe_test_logging is set to true (Closed)
Patch Set: adding macro declaration Created 4 years, 3 months 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 unified diff | Download patch
OLDNEW
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
11 #include "webrtc/modules/remote_bitrate_estimator/overuse_estimator.h" 11 #include "webrtc/modules/remote_bitrate_estimator/overuse_estimator.h"
12 12
13 #include <assert.h> 13 #include <assert.h>
14 #include <math.h> 14 #include <math.h>
15 #include <stdlib.h> 15 #include <stdlib.h>
16 #include <string.h> 16 #include <string.h>
17 17
18 #include <algorithm> 18 #include <algorithm>
19 19
20 #include "webrtc/base/logging.h" 20 #include "webrtc/base/logging.h"
21 #include "webrtc/modules/remote_bitrate_estimator/include/bwe_defines.h" 21 #include "webrtc/modules/remote_bitrate_estimator/include/bwe_defines.h"
22 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h"
22 23
23 namespace webrtc { 24 namespace webrtc {
24 25
25 enum { kMinFramePeriodHistoryLength = 60 }; 26 enum { kMinFramePeriodHistoryLength = 60 };
26 enum { kDeltaCounterMax = 1000 }; 27 enum { kDeltaCounterMax = 1000 };
27 28
28 OveruseEstimator::OveruseEstimator(const OverUseDetectorOptions& options) 29 OveruseEstimator::OveruseEstimator(const OverUseDetectorOptions& options)
29 : options_(options), 30 : options_(options),
30 num_of_deltas_(0), 31 num_of_deltas_(0),
31 slope_(options_.initial_slope), 32 slope_(options_.initial_slope),
32 offset_(options_.initial_offset), 33 offset_(options_.initial_offset),
33 prev_offset_(options_.initial_offset), 34 prev_offset_(options_.initial_offset),
34 E_(), 35 E_(),
35 process_noise_(), 36 process_noise_(),
36 avg_noise_(options_.initial_avg_noise), 37 avg_noise_(options_.initial_avg_noise),
37 var_noise_(options_.initial_var_noise), 38 var_noise_(options_.initial_var_noise),
38 ts_delta_hist_() { 39 ts_delta_hist_() {
39 memcpy(E_, options_.initial_e, sizeof(E_)); 40 memcpy(E_, options_.initial_e, sizeof(E_));
40 memcpy(process_noise_, options_.initial_process_noise, 41 memcpy(process_noise_, options_.initial_process_noise,
41 sizeof(process_noise_)); 42 sizeof(process_noise_));
42 } 43 }
43 44
44 OveruseEstimator::~OveruseEstimator() { 45 OveruseEstimator::~OveruseEstimator() {
45 ts_delta_hist_.clear(); 46 ts_delta_hist_.clear();
46 } 47 }
47 48
48 void OveruseEstimator::Update(int64_t t_delta, 49 void OveruseEstimator::Update(int64_t t_delta,
49 double ts_delta, 50 double ts_delta,
50 int size_delta, 51 int size_delta,
51 BandwidthUsage current_hypothesis) { 52 BandwidthUsage current_hypothesis,
53 int64_t now_ms) {
52 const double min_frame_period = UpdateMinFramePeriod(ts_delta); 54 const double min_frame_period = UpdateMinFramePeriod(ts_delta);
53 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);
54 double fs_delta = size_delta; 57 double fs_delta = size_delta;
55 58
56 ++num_of_deltas_; 59 ++num_of_deltas_;
57 if (num_of_deltas_ > kDeltaCounterMax) { 60 if (num_of_deltas_ > kDeltaCounterMax) {
58 num_of_deltas_ = kDeltaCounterMax; 61 num_of_deltas_ = kDeltaCounterMax;
59 } 62 }
60 63
61 // Update the Kalman filter. 64 // Update the Kalman filter.
62 E_[0][0] += process_noise_[0]; 65 E_[0][0] += process_noise_[0];
63 E_[1][1] += process_noise_[1]; 66 E_[1][1] += process_noise_[1];
64 67
65 if ((current_hypothesis == kBwOverusing && offset_ < prev_offset_) || 68 if ((current_hypothesis == kBwOverusing && offset_ < prev_offset_) ||
66 (current_hypothesis == kBwUnderusing && offset_ > prev_offset_)) { 69 (current_hypothesis == kBwUnderusing && offset_ > prev_offset_)) {
67 E_[1][1] += 10 * process_noise_[1]; 70 E_[1][1] += 10 * process_noise_[1];
68 } 71 }
69 72
70 const double h[2] = {fs_delta, 1.0}; 73 const double h[2] = {fs_delta, 1.0};
71 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],
72 E_[1][0]*h[0] + E_[1][1]*h[1]}; 75 E_[1][0]*h[0] + E_[1][1]*h[1]};
73 76
77 BWE_TEST_LOGGING_PLOT(1, "d[ms]", now_ms, slope_ * h[0] - offset_);
78
74 const double residual = t_ts_delta - slope_*h[0] - offset_; 79 const double residual = t_ts_delta - slope_*h[0] - offset_;
75 80
76 const bool in_stable_state = (current_hypothesis == kBwNormal); 81 const bool in_stable_state = (current_hypothesis == kBwNormal);
77 const double max_residual = 3.0 * sqrt(var_noise_); 82 const double max_residual = 3.0 * sqrt(var_noise_);
78 // 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
79 // frames doesn't fit the Gaussian model well. 84 // frames doesn't fit the Gaussian model well.
80 if (fabs(residual) < max_residual) { 85 if (fabs(residual) < max_residual) {
81 UpdateNoiseEstimate(residual, min_frame_period, in_stable_state); 86 UpdateNoiseEstimate(residual, min_frame_period, in_stable_state);
82 } else { 87 } else {
83 UpdateNoiseEstimate(residual < 0 ? -max_residual : max_residual, 88 UpdateNoiseEstimate(residual < 0 ? -max_residual : max_residual,
(...skipping 21 matching lines...) Expand all
105 E_[0][0] * E_[1][1] - E_[0][1] * E_[1][0] >= 0 && E_[0][0] >= 0; 110 E_[0][0] * E_[1][1] - E_[0][1] * E_[1][0] >= 0 && E_[0][0] >= 0;
106 assert(positive_semi_definite); 111 assert(positive_semi_definite);
107 if (!positive_semi_definite) { 112 if (!positive_semi_definite) {
108 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 "
109 "semi-definite."; 114 "semi-definite.";
110 } 115 }
111 116
112 slope_ = slope_ + K[0] * residual; 117 slope_ = slope_ + K[0] * residual;
113 prev_offset_ = offset_; 118 prev_offset_ = offset_;
114 offset_ = offset_ + K[1] * residual; 119 offset_ = offset_ + K[1] * residual;
120
121 BWE_TEST_LOGGING_PLOT(1, "kc", now_ms, K[0]);
122 BWE_TEST_LOGGING_PLOT(1, "km", now_ms, K[1]);
123 BWE_TEST_LOGGING_PLOT(1, "slope[1/bps]", now_ms, slope_);
124 BWE_TEST_LOGGING_PLOT(1, "var_noise", now_ms, var_noise_);
115 } 125 }
116 126
117 double OveruseEstimator::UpdateMinFramePeriod(double ts_delta) { 127 double OveruseEstimator::UpdateMinFramePeriod(double ts_delta) {
118 double min_frame_period = ts_delta; 128 double min_frame_period = ts_delta;
119 if (ts_delta_hist_.size() >= kMinFramePeriodHistoryLength) { 129 if (ts_delta_hist_.size() >= kMinFramePeriodHistoryLength) {
120 ts_delta_hist_.pop_front(); 130 ts_delta_hist_.pop_front();
121 } 131 }
122 std::list<double>::iterator it = ts_delta_hist_.begin(); 132 std::list<double>::iterator it = ts_delta_hist_.begin();
123 for (; it != ts_delta_hist_.end(); it++) { 133 for (; it != ts_delta_hist_.end(); it++) {
124 min_frame_period = std::min(*it, min_frame_period); 134 min_frame_period = std::min(*it, min_frame_period);
(...skipping 20 matching lines...) Expand all
145 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);
146 avg_noise_ = beta * avg_noise_ 156 avg_noise_ = beta * avg_noise_
147 + (1 - beta) * residual; 157 + (1 - beta) * residual;
148 var_noise_ = beta * var_noise_ 158 var_noise_ = beta * var_noise_
149 + (1 - beta) * (avg_noise_ - residual) * (avg_noise_ - residual); 159 + (1 - beta) * (avg_noise_ - residual) * (avg_noise_ - residual);
150 if (var_noise_ < 1) { 160 if (var_noise_ < 1) {
151 var_noise_ = 1; 161 var_noise_ = 1;
152 } 162 }
153 } 163 }
154 } // namespace webrtc 164 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698