Chromium Code Reviews| 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 12 matching lines...) Expand all Loading... | |
| 23 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h" | 23 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h" |
| 24 #include "webrtc/modules/rtp_rtcp/interface/receive_statistics.h" | 24 #include "webrtc/modules/rtp_rtcp/interface/receive_statistics.h" |
| 25 | 25 |
| 26 namespace webrtc { | 26 namespace webrtc { |
| 27 namespace testing { | 27 namespace testing { |
| 28 namespace bwe { | 28 namespace bwe { |
| 29 | 29 |
| 30 const int NadaBweReceiver::kMedian; | 30 const int NadaBweReceiver::kMedian; |
| 31 const int NadaBweSender::kMinRefRateKbps; | 31 const int NadaBweSender::kMinRefRateKbps; |
| 32 const int NadaBweSender::kMaxRefRateKbps; | 32 const int NadaBweSender::kMaxRefRateKbps; |
| 33 const int64_t NadaBweReceiver::kReceivingRateTimeWindowMs; | |
| 34 | 33 |
| 35 NadaBweReceiver::NadaBweReceiver(int flow_id) | 34 NadaBweReceiver::NadaBweReceiver(int flow_id) |
| 36 : BweReceiver(flow_id), | 35 : BweReceiver(flow_id, kReceivingRateTimeWindowMs), |
| 37 clock_(0), | 36 clock_(0), |
| 38 last_feedback_ms_(0), | 37 last_feedback_ms_(0), |
| 39 recv_stats_(ReceiveStatistics::Create(&clock_)), | 38 recv_stats_(ReceiveStatistics::Create(&clock_)), |
| 40 baseline_delay_ms_(0), | 39 baseline_delay_ms_(10000), // Initialized as an upper bound. |
| 41 delay_signal_ms_(0), | 40 delay_signal_ms_(0), |
| 42 last_congestion_signal_ms_(0), | 41 last_congestion_signal_ms_(0), |
| 43 last_delays_index_(0), | 42 last_delays_index_(0), |
| 44 exp_smoothed_delay_ms_(-1), | 43 exp_smoothed_delay_ms_(-1), |
| 45 est_queuing_delay_signal_ms_(0) { | 44 est_queuing_delay_signal_ms_(0) { |
| 46 } | 45 } |
| 47 | 46 |
| 48 NadaBweReceiver::~NadaBweReceiver() { | 47 NadaBweReceiver::~NadaBweReceiver() { |
| 49 } | 48 } |
| 50 | 49 |
| 51 void NadaBweReceiver::ReceivePacket(int64_t arrival_time_ms, | 50 void NadaBweReceiver::ReceivePacket(int64_t arrival_time_ms, |
| 52 const MediaPacket& media_packet) { | 51 const MediaPacket& media_packet) { |
| 53 const float kAlpha = 0.1f; // Used for exponential smoothing. | 52 const float kAlpha = 0.1f; // Used for exponential smoothing. |
| 54 const int64_t kDelayLowThresholdMs = 50; // Referred as d_th. | 53 const int64_t kDelayLowThresholdMs = 50; // Referred as d_th. |
| 55 const int64_t kDelayMaxThresholdMs = 400; // Referred as d_max. | 54 const int64_t kDelayMaxThresholdMs = 400; // Referred as d_max. |
| 56 | 55 |
| 57 clock_.AdvanceTimeMilliseconds(arrival_time_ms - clock_.TimeInMilliseconds()); | 56 clock_.AdvanceTimeMilliseconds(arrival_time_ms - clock_.TimeInMilliseconds()); |
| 58 recv_stats_->IncomingPacket(media_packet.header(), | 57 recv_stats_->IncomingPacket(media_packet.header(), |
| 59 media_packet.payload_size(), false); | 58 media_packet.payload_size(), false); |
| 60 int64_t delay_ms = arrival_time_ms - | 59 int64_t delay_ms = arrival_time_ms - |
| 61 media_packet.creation_time_us() / 1000; // Refered as x_n. | 60 media_packet.creation_time_us() / 1000; // Refered as x_n. |
| 61 | |
| 62 // The min should be updated within the first 10 minutes. | 62 // The min should be updated within the first 10 minutes. |
| 63 if (clock_.TimeInMilliseconds() < 10 * 60 * 1000) { | 63 if (clock_.TimeInMilliseconds() < 10 * 60 * 1000) { |
| 64 baseline_delay_ms_ = std::min(baseline_delay_ms_, delay_ms); | 64 baseline_delay_ms_ = std::min(baseline_delay_ms_, delay_ms); |
| 65 } | 65 } |
| 66 | |
| 66 delay_signal_ms_ = delay_ms - baseline_delay_ms_; // Refered as d_n. | 67 delay_signal_ms_ = delay_ms - baseline_delay_ms_; // Refered as d_n. |
| 67 last_delays_ms_[(last_delays_index_++) % kMedian] = delay_signal_ms_; | 68 last_delays_ms_[(last_delays_index_++) % kMedian] = delay_signal_ms_; |
| 68 int size = std::min(last_delays_index_, kMedian); | 69 int size = std::min(last_delays_index_, kMedian); |
| 70 | |
| 69 int64_t median_filtered_delay_ms_ = MedianFilter(last_delays_ms_, size); | 71 int64_t median_filtered_delay_ms_ = MedianFilter(last_delays_ms_, size); |
| 70 exp_smoothed_delay_ms_ = ExponentialSmoothingFilter( | 72 exp_smoothed_delay_ms_ = ExponentialSmoothingFilter( |
| 71 median_filtered_delay_ms_, exp_smoothed_delay_ms_, kAlpha); | 73 median_filtered_delay_ms_, exp_smoothed_delay_ms_, kAlpha); |
| 72 | 74 |
| 73 if (exp_smoothed_delay_ms_ < kDelayLowThresholdMs) { | 75 if (exp_smoothed_delay_ms_ < kDelayLowThresholdMs) { |
| 74 est_queuing_delay_signal_ms_ = exp_smoothed_delay_ms_; | 76 est_queuing_delay_signal_ms_ = exp_smoothed_delay_ms_; |
| 75 } else if (exp_smoothed_delay_ms_ < kDelayMaxThresholdMs) { | 77 } else if (exp_smoothed_delay_ms_ < kDelayMaxThresholdMs) { |
| 76 est_queuing_delay_signal_ms_ = static_cast<int64_t>( | 78 est_queuing_delay_signal_ms_ = static_cast<int64_t>( |
| 77 pow((static_cast<double>(kDelayMaxThresholdMs - | 79 pow((static_cast<double>(kDelayMaxThresholdMs - |
| 78 exp_smoothed_delay_ms_)) / | 80 exp_smoothed_delay_ms_)) / |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 108 } | 110 } |
| 109 last_feedback_ms_ = now_ms; | 111 last_feedback_ms_ = now_ms; |
| 110 last_congestion_signal_ms_ = congestion_signal_ms; | 112 last_congestion_signal_ms_ = congestion_signal_ms; |
| 111 | 113 |
| 112 PacketIdentifierNode* latest = *(received_packets_.begin()); | 114 PacketIdentifierNode* latest = *(received_packets_.begin()); |
| 113 int64_t corrected_send_time_ms = | 115 int64_t corrected_send_time_ms = |
| 114 latest->send_time_ms + now_ms - latest->arrival_time_ms; | 116 latest->send_time_ms + now_ms - latest->arrival_time_ms; |
| 115 | 117 |
| 116 // Sends a tuple containing latest values of <d_hat_n, d_tilde_n, x_n, x'_n, | 118 // Sends a tuple containing latest values of <d_hat_n, d_tilde_n, x_n, x'_n, |
| 117 // R_r> and additional information. | 119 // R_r> and additional information. |
| 118 return new NadaFeedback(flow_id_, now_ms, exp_smoothed_delay_ms_, | 120 return new NadaFeedback(flow_id_, now_ms * 1000, exp_smoothed_delay_ms_, |
| 119 est_queuing_delay_signal_ms_, congestion_signal_ms, | 121 est_queuing_delay_signal_ms_, congestion_signal_ms, |
| 120 derivative, RecentReceivingRate(), | 122 derivative, RecentKbps(), corrected_send_time_ms); |
| 121 corrected_send_time_ms); | |
| 122 } | |
| 123 | |
| 124 // For a given time window, compute the receiving speed rate in kbps. | |
| 125 // As described below, three cases are considered depending on the number of | |
| 126 // packets received. | |
| 127 size_t NadaBweReceiver::RecentReceivingRate() { | |
| 128 // If the receiver didn't receive any packet, return 0. | |
| 129 if (received_packets_.empty()) { | |
| 130 return 0.0f; | |
| 131 } | |
| 132 size_t total_size = 0; | |
| 133 int number_packets = 0; | |
| 134 | |
| 135 PacketNodeIt node_it = received_packets_.begin(); | |
| 136 | |
| 137 int64_t last_time_ms = (*node_it)->arrival_time_ms; | |
| 138 int64_t start_time_ms = last_time_ms; | |
| 139 PacketNodeIt end = received_packets_.end(); | |
| 140 | |
| 141 // Stops after including the first packet out of the timeWindow. | |
| 142 // Ameliorates results when there are wide gaps between packets. | |
| 143 // E.g. Large packets : p1(0ms), p2(3000ms). | |
| 144 while (node_it != end) { | |
| 145 total_size += (*node_it)->payload_size; | |
| 146 last_time_ms = (*node_it)->arrival_time_ms; | |
| 147 ++number_packets; | |
| 148 if ((*node_it)->arrival_time_ms < | |
| 149 start_time_ms - kReceivingRateTimeWindowMs) { | |
| 150 break; | |
| 151 } | |
| 152 ++node_it; | |
| 153 } | |
| 154 | |
| 155 int64_t corrected_time_ms; | |
| 156 // If the receiver received a single packet, return its size*8/timeWindow. | |
| 157 if (number_packets == 1) { | |
| 158 corrected_time_ms = kReceivingRateTimeWindowMs; | |
| 159 } | |
| 160 // If the receiver received multiple packets, use as time interval the gap | |
| 161 // between first and last packet falling in the timeWindow corrected by the | |
| 162 // factor number_packets/(number_packets-1). | |
| 163 // E.g: Let timeWindow = 500ms, payload_size = 500 bytes, number_packets = 2, | |
| 164 // packets received at t1(0ms) and t2(499 or 501ms). This prevent the function | |
| 165 // from returning ~2*8, sending instead a more likely ~1*8 kbps. | |
| 166 else { | |
| 167 corrected_time_ms = (number_packets * (start_time_ms - last_time_ms)) / | |
| 168 (number_packets - 1); | |
| 169 } | |
| 170 | |
| 171 // Converting from bytes/ms to kbits/s. | |
| 172 return static_cast<size_t>(8 * total_size / corrected_time_ms); | |
| 173 } | 123 } |
| 174 | 124 |
| 175 int64_t NadaBweReceiver::MedianFilter(int64_t* last_delays_ms, int size) { | 125 int64_t NadaBweReceiver::MedianFilter(int64_t* last_delays_ms, int size) { |
| 176 // Typically, size = 5. | 126 // Typically, size = 5. |
| 177 std::vector<int64_t> array_copy(last_delays_ms, last_delays_ms + size); | 127 std::vector<int64_t> array_copy(last_delays_ms, last_delays_ms + size); |
| 178 std::nth_element(array_copy.begin(), array_copy.begin() + size / 2, | 128 std::nth_element(array_copy.begin(), array_copy.begin() + size / 2, |
| 179 array_copy.end()); | 129 array_copy.end()); |
| 180 return array_copy.at(size / 2); | 130 return array_copy.at(size / 2); |
| 181 } | 131 } |
| 182 | 132 |
| 183 int64_t NadaBweReceiver::ExponentialSmoothingFilter(int64_t new_value, | 133 int64_t NadaBweReceiver::ExponentialSmoothingFilter(int64_t new_value, |
| 184 int64_t last_smoothed_value, | 134 int64_t last_smoothed_value, |
| 185 float alpha) { | 135 float alpha) { |
| 186 if (last_smoothed_value < 0) { | 136 if (last_smoothed_value < 0) { |
| 187 return new_value; // Handling initial case. | 137 return new_value; // Handling initial case. |
| 188 } | 138 } |
| 189 return static_cast<int64_t>(alpha * new_value + | 139 return static_cast<int64_t>(alpha * new_value + |
| 190 (1.0f - alpha) * last_smoothed_value + 0.5f); | 140 (1.0f - alpha) * last_smoothed_value + 0.5f); |
| 191 } | 141 } |
| 192 | 142 |
| 193 // Implementation according to Cisco's proposal by default. | 143 // Implementation according to Cisco's proposal by default. |
| 194 NadaBweSender::NadaBweSender(int kbps, BitrateObserver* observer, Clock* clock) | 144 NadaBweSender::NadaBweSender(int kbps, BitrateObserver* observer, Clock* clock) |
| 195 : clock_(clock), | 145 : clock_(clock), |
| 196 observer_(observer), | 146 observer_(observer), |
| 197 bitrate_kbps_(kbps), | |
| 198 original_operating_mode_(true) { | 147 original_operating_mode_(true) { |
| 148 bitrate_kbps_ = kMinRefRateKbps; // Referred as "Reference Rate" = R_n. | |
| 199 } | 149 } |
| 200 | 150 |
| 201 NadaBweSender::NadaBweSender(BitrateObserver* observer, Clock* clock) | 151 NadaBweSender::NadaBweSender(BitrateObserver* observer, Clock* clock) |
| 202 : clock_(clock), | 152 : clock_(clock), |
| 203 observer_(observer), | 153 observer_(observer), |
| 204 bitrate_kbps_(kMinRefRateKbps), | |
| 205 original_operating_mode_(true) { | 154 original_operating_mode_(true) { |
| 155 bitrate_kbps_ = kMinRefRateKbps; // Referred as "Reference Rate" = R_n. | |
|
stefan-webrtc
2015/07/07 12:46:37
Why don't we set this in the initializer list any
magalhaesc
2015/07/08 18:12:31
Now it is a member of the upper class BweSender. I
| |
| 206 } | 156 } |
| 207 | 157 |
| 208 NadaBweSender::~NadaBweSender() { | 158 NadaBweSender::~NadaBweSender() { |
| 209 } | 159 } |
| 210 | 160 |
| 211 int NadaBweSender::GetFeedbackIntervalMs() const { | 161 int NadaBweSender::GetFeedbackIntervalMs() const { |
| 212 return 100; | 162 return 100; |
| 213 } | 163 } |
| 214 | 164 |
| 215 void NadaBweSender::GiveFeedback(const FeedbackPacket& feedback) { | 165 void NadaBweSender::GiveFeedback(const FeedbackPacket& feedback) { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 (kTheta - (bitrate_kbps_ - kMinRefRateKbps) * x_hat)) / | 268 (kTheta - (bitrate_kbps_ - kMinRefRateKbps) * x_hat)) / |
| 319 (kTauOMs * kTauOMs) + | 269 (kTauOMs * kTauOMs) + |
| 320 0.5f); | 270 0.5f); |
| 321 | 271 |
| 322 bitrate_kbps_ = bitrate_kbps_ + smoothing_factor * original_increase; | 272 bitrate_kbps_ = bitrate_kbps_ + smoothing_factor * original_increase; |
| 323 } | 273 } |
| 324 | 274 |
| 325 } // namespace bwe | 275 } // namespace bwe |
| 326 } // namespace testing | 276 } // namespace testing |
| 327 } // namespace webrtc | 277 } // namespace webrtc |
| OLD | NEW |