OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 latest->send_time_ms + now_ms - latest->arrival_time_ms; | 117 latest->send_time_ms + now_ms - latest->arrival_time_ms; |
118 } | 118 } |
119 | 119 |
120 // Sends a tuple containing latest values of <d_hat_n, d_tilde_n, x_n, x'_n, | 120 // Sends a tuple containing latest values of <d_hat_n, d_tilde_n, x_n, x'_n, |
121 // R_r> and additional information. | 121 // R_r> and additional information. |
122 return new NadaFeedback(flow_id_, now_ms * 1000, exp_smoothed_delay_ms_, | 122 return new NadaFeedback(flow_id_, now_ms * 1000, exp_smoothed_delay_ms_, |
123 est_queuing_delay_signal_ms_, congestion_signal_ms, | 123 est_queuing_delay_signal_ms_, congestion_signal_ms, |
124 derivative, RecentKbps(), corrected_send_time_ms); | 124 derivative, RecentKbps(), corrected_send_time_ms); |
125 } | 125 } |
126 | 126 |
| 127 // If size is even, the median is the average of the two middlemost numbers. |
127 int64_t NadaBweReceiver::MedianFilter(int64_t* last_delays_ms, int size) { | 128 int64_t NadaBweReceiver::MedianFilter(int64_t* last_delays_ms, int size) { |
128 // Typically, size = 5. | |
129 std::vector<int64_t> array_copy(last_delays_ms, last_delays_ms + size); | 129 std::vector<int64_t> array_copy(last_delays_ms, last_delays_ms + size); |
130 std::nth_element(array_copy.begin(), array_copy.begin() + size / 2, | 130 std::nth_element(array_copy.begin(), array_copy.begin() + size / 2, |
131 array_copy.end()); | 131 array_copy.end()); |
132 return array_copy.at(size / 2); | 132 if (size % 2 == 1) { |
| 133 // Typically, size = 5. For odd size values, right and left are equal. |
| 134 return array_copy.at(size / 2); |
| 135 } |
| 136 int64_t right = array_copy.at(size / 2); |
| 137 std::nth_element(array_copy.begin(), array_copy.begin() + (size - 1) / 2, |
| 138 array_copy.end()); |
| 139 int64_t left = array_copy.at((size - 1) / 2); |
| 140 return (left + right + 1) / 2; |
133 } | 141 } |
134 | 142 |
135 int64_t NadaBweReceiver::ExponentialSmoothingFilter(int64_t new_value, | 143 int64_t NadaBweReceiver::ExponentialSmoothingFilter(int64_t new_value, |
136 int64_t last_smoothed_value, | 144 int64_t last_smoothed_value, |
137 float alpha) { | 145 float alpha) { |
138 if (last_smoothed_value < 0) { | 146 if (last_smoothed_value < 0) { |
139 return new_value; // Handling initial case. | 147 return new_value; // Handling initial case. |
140 } | 148 } |
141 return static_cast<int64_t>(alpha * new_value + | 149 return static_cast<int64_t>(alpha * new_value + |
142 (1.0f - alpha) * last_smoothed_value + 0.5f); | 150 (1.0f - alpha) * last_smoothed_value + 0.5f); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 (kTheta - (bitrate_kbps_ - kMinBitrateKbps) * x_hat)) / | 278 (kTheta - (bitrate_kbps_ - kMinBitrateKbps) * x_hat)) / |
271 (kTauOMs * kTauOMs) + | 279 (kTauOMs * kTauOMs) + |
272 0.5f); | 280 0.5f); |
273 | 281 |
274 bitrate_kbps_ = bitrate_kbps_ + smoothing_factor * original_increase; | 282 bitrate_kbps_ = bitrate_kbps_ + smoothing_factor * original_increase; |
275 } | 283 } |
276 | 284 |
277 } // namespace bwe | 285 } // namespace bwe |
278 } // namespace testing | 286 } // namespace testing |
279 } // namespace webrtc | 287 } // namespace webrtc |
OLD | NEW |