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 |
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 | 22 |
stefan-webrtc
2016/09/13 08:19:44
Remove this empty line.
| |
23 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h" | |
24 | |
23 namespace webrtc { | 25 namespace webrtc { |
24 | 26 |
25 enum { kMinFramePeriodHistoryLength = 60 }; | 27 enum { kMinFramePeriodHistoryLength = 60 }; |
26 enum { kDeltaCounterMax = 1000 }; | 28 enum { kDeltaCounterMax = 1000 }; |
27 | 29 |
28 OveruseEstimator::OveruseEstimator(const OverUseDetectorOptions& options) | 30 OveruseEstimator::OveruseEstimator(const OverUseDetectorOptions& options) |
29 : options_(options), | 31 : options_(options), |
30 num_of_deltas_(0), | 32 num_of_deltas_(0), |
31 slope_(options_.initial_slope), | 33 slope_(options_.initial_slope), |
32 offset_(options_.initial_offset), | 34 offset_(options_.initial_offset), |
33 prev_offset_(options_.initial_offset), | 35 prev_offset_(options_.initial_offset), |
34 E_(), | 36 E_(), |
35 process_noise_(), | 37 process_noise_(), |
36 avg_noise_(options_.initial_avg_noise), | 38 avg_noise_(options_.initial_avg_noise), |
37 var_noise_(options_.initial_var_noise), | 39 var_noise_(options_.initial_var_noise), |
38 ts_delta_hist_() { | 40 ts_delta_hist_() { |
39 memcpy(E_, options_.initial_e, sizeof(E_)); | 41 memcpy(E_, options_.initial_e, sizeof(E_)); |
40 memcpy(process_noise_, options_.initial_process_noise, | 42 memcpy(process_noise_, options_.initial_process_noise, |
41 sizeof(process_noise_)); | 43 sizeof(process_noise_)); |
42 } | 44 } |
43 | 45 |
44 OveruseEstimator::~OveruseEstimator() { | 46 OveruseEstimator::~OveruseEstimator() { |
45 ts_delta_hist_.clear(); | 47 ts_delta_hist_.clear(); |
46 } | 48 } |
47 | 49 |
48 void OveruseEstimator::Update(int64_t t_delta, | 50 void OveruseEstimator::Update(int64_t t_delta, |
49 double ts_delta, | 51 double ts_delta, |
50 int size_delta, | 52 int size_delta, |
51 BandwidthUsage current_hypothesis) { | 53 BandwidthUsage current_hypothesis, |
54 int64_t now_ms) { | |
52 const double min_frame_period = UpdateMinFramePeriod(ts_delta); | 55 const double min_frame_period = UpdateMinFramePeriod(ts_delta); |
53 const double t_ts_delta = t_delta - ts_delta; | 56 const double t_ts_delta = t_delta - ts_delta; |
57 BWE_TEST_LOGGING_PLOT(1, "dm[ms]", now_ms, t_ts_delta); | |
54 double fs_delta = size_delta; | 58 double fs_delta = size_delta; |
55 | 59 |
56 ++num_of_deltas_; | 60 ++num_of_deltas_; |
57 if (num_of_deltas_ > kDeltaCounterMax) { | 61 if (num_of_deltas_ > kDeltaCounterMax) { |
58 num_of_deltas_ = kDeltaCounterMax; | 62 num_of_deltas_ = kDeltaCounterMax; |
59 } | 63 } |
60 | 64 |
61 // Update the Kalman filter. | 65 // Update the Kalman filter. |
62 E_[0][0] += process_noise_[0]; | 66 E_[0][0] += process_noise_[0]; |
63 E_[1][1] += process_noise_[1]; | 67 E_[1][1] += process_noise_[1]; |
64 | 68 |
65 if ((current_hypothesis == kBwOverusing && offset_ < prev_offset_) || | 69 if ((current_hypothesis == kBwOverusing && offset_ < prev_offset_) || |
66 (current_hypothesis == kBwUnderusing && offset_ > prev_offset_)) { | 70 (current_hypothesis == kBwUnderusing && offset_ > prev_offset_)) { |
67 E_[1][1] += 10 * process_noise_[1]; | 71 E_[1][1] += 10 * process_noise_[1]; |
68 } | 72 } |
69 | 73 |
70 const double h[2] = {fs_delta, 1.0}; | 74 const double h[2] = {fs_delta, 1.0}; |
71 const double Eh[2] = {E_[0][0]*h[0] + E_[0][1]*h[1], | 75 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]}; | 76 E_[1][0]*h[0] + E_[1][1]*h[1]}; |
73 | 77 |
78 BWE_TEST_LOGGING_PLOT(1, "d[ms]", now_ms, slope_ * h[0] - offset_); | |
79 | |
74 const double residual = t_ts_delta - slope_*h[0] - offset_; | 80 const double residual = t_ts_delta - slope_*h[0] - offset_; |
75 | 81 |
76 const bool in_stable_state = (current_hypothesis == kBwNormal); | 82 const bool in_stable_state = (current_hypothesis == kBwNormal); |
77 const double max_residual = 3.0 * sqrt(var_noise_); | 83 const double max_residual = 3.0 * sqrt(var_noise_); |
78 // We try to filter out very late frames. For instance periodic key | 84 // We try to filter out very late frames. For instance periodic key |
79 // frames doesn't fit the Gaussian model well. | 85 // frames doesn't fit the Gaussian model well. |
80 if (fabs(residual) < max_residual) { | 86 if (fabs(residual) < max_residual) { |
81 UpdateNoiseEstimate(residual, min_frame_period, in_stable_state); | 87 UpdateNoiseEstimate(residual, min_frame_period, in_stable_state); |
82 } else { | 88 } else { |
83 UpdateNoiseEstimate(residual < 0 ? -max_residual : max_residual, | 89 UpdateNoiseEstimate(residual < 0 ? -max_residual : max_residual, |
(...skipping 21 matching lines...) Expand all Loading... | |
105 E_[0][0] * E_[1][1] - E_[0][1] * E_[1][0] >= 0 && E_[0][0] >= 0; | 111 E_[0][0] * E_[1][1] - E_[0][1] * E_[1][0] >= 0 && E_[0][0] >= 0; |
106 assert(positive_semi_definite); | 112 assert(positive_semi_definite); |
107 if (!positive_semi_definite) { | 113 if (!positive_semi_definite) { |
108 LOG(LS_ERROR) << "The over-use estimator's covariance matrix is no longer " | 114 LOG(LS_ERROR) << "The over-use estimator's covariance matrix is no longer " |
109 "semi-definite."; | 115 "semi-definite."; |
110 } | 116 } |
111 | 117 |
112 slope_ = slope_ + K[0] * residual; | 118 slope_ = slope_ + K[0] * residual; |
113 prev_offset_ = offset_; | 119 prev_offset_ = offset_; |
114 offset_ = offset_ + K[1] * residual; | 120 offset_ = offset_ + K[1] * residual; |
121 | |
122 BWE_TEST_LOGGING_PLOT(1, "kc", now_ms, K[0]); | |
123 BWE_TEST_LOGGING_PLOT(1, "km", now_ms, K[1]); | |
124 BWE_TEST_LOGGING_PLOT(1, "slope[1/bps]", now_ms, slope_); | |
125 BWE_TEST_LOGGING_PLOT(1, "var_noise", now_ms, var_noise_); | |
115 } | 126 } |
116 | 127 |
117 double OveruseEstimator::UpdateMinFramePeriod(double ts_delta) { | 128 double OveruseEstimator::UpdateMinFramePeriod(double ts_delta) { |
118 double min_frame_period = ts_delta; | 129 double min_frame_period = ts_delta; |
119 if (ts_delta_hist_.size() >= kMinFramePeriodHistoryLength) { | 130 if (ts_delta_hist_.size() >= kMinFramePeriodHistoryLength) { |
120 ts_delta_hist_.pop_front(); | 131 ts_delta_hist_.pop_front(); |
121 } | 132 } |
122 std::list<double>::iterator it = ts_delta_hist_.begin(); | 133 std::list<double>::iterator it = ts_delta_hist_.begin(); |
123 for (; it != ts_delta_hist_.end(); it++) { | 134 for (; it != ts_delta_hist_.end(); it++) { |
124 min_frame_period = std::min(*it, min_frame_period); | 135 min_frame_period = std::min(*it, min_frame_period); |
(...skipping 20 matching lines...) Expand all Loading... | |
145 const double beta = pow(1 - alpha, ts_delta * 30.0 / 1000.0); | 156 const double beta = pow(1 - alpha, ts_delta * 30.0 / 1000.0); |
146 avg_noise_ = beta * avg_noise_ | 157 avg_noise_ = beta * avg_noise_ |
147 + (1 - beta) * residual; | 158 + (1 - beta) * residual; |
148 var_noise_ = beta * var_noise_ | 159 var_noise_ = beta * var_noise_ |
149 + (1 - beta) * (avg_noise_ - residual) * (avg_noise_ - residual); | 160 + (1 - beta) * (avg_noise_ - residual) * (avg_noise_ - residual); |
150 if (var_noise_ < 1) { | 161 if (var_noise_ < 1) { |
151 var_noise_ = 1; | 162 var_noise_ = 1; |
152 } | 163 } |
153 } | 164 } |
154 } // namespace webrtc | 165 } // namespace webrtc |
OLD | NEW |