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

Side by Side Diff: webrtc/modules/remote_bitrate_estimator/test/bwe.cc

Issue 1202253003: More Simulation Framework features (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Addressing trybot failures Created 5 years, 6 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) 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
11 #include "webrtc/modules/remote_bitrate_estimator/test/bwe.h" 11 #include "webrtc/modules/remote_bitrate_estimator/test/bwe.h"
12 12
13 #include <limits> 13 #include <limits>
14 14
15 #include "webrtc/base/common.h" 15 #include "webrtc/base/common.h"
16 #include "webrtc/modules/remote_bitrate_estimator/test/estimators/nada.h" 16 #include "webrtc/modules/remote_bitrate_estimator/test/estimators/nada.h"
17 #include "webrtc/modules/remote_bitrate_estimator/test/estimators/remb.h" 17 #include "webrtc/modules/remote_bitrate_estimator/test/estimators/remb.h"
18 #include "webrtc/modules/remote_bitrate_estimator/test/estimators/send_side.h" 18 #include "webrtc/modules/remote_bitrate_estimator/test/estimators/send_side.h"
19 #include "webrtc/modules/remote_bitrate_estimator/test/estimators/tcp.h" 19 #include "webrtc/modules/remote_bitrate_estimator/test/estimators/tcp.h"
20 20
21 namespace webrtc { 21 namespace webrtc {
22 namespace testing { 22 namespace testing {
23 namespace bwe { 23 namespace bwe {
24 24
25 // With the assumption that packet loss is lower than 97%, the max gap 25 // With the assumption that packet loss is lower than 97%, the max gap
26 // between elements in the set is lower than 0x8000, hence we have a 26 // between elements in the set is lower than 0x8000, hence we have a
27 // total order in the set. For (x,y,z) subset of the LinkedSet, 27 // total order in the set. For (x,y,z) subset of the LinkedSet,
28 // (x<=y and y<=z) ==> x<=z so the set can be sorted. 28 // (x<=y and y<=z) ==> x<=z so the set can be sorted.
29 const int kSetCapacity = 1000; 29 const int kSetCapacity = 1000;
magalhaesc 2015/06/25 11:09:16 2 options: -- Replace 1000 with 1000, then recalc
stefan-webrtc 2015/06/25 14:44:03 Right... I would personally prefer if we could hav
magalhaesc 2015/07/01 12:48:39 All right, I will keep it 1000. What do you think
30 30
31 BweReceiver::BweReceiver(int flow_id) 31 BweReceiver::BweReceiver(int flow_id)
32 : flow_id_(flow_id), received_packets_(kSetCapacity) { 32 : num_previous_total_packets_(0),
33 num_previous_lost_packets_(0),
34 flow_id_(flow_id),
35 received_packets_(kSetCapacity) {
36 }
37
38 void BweSender::Pause() {
39 running_ = false;
40 bitrate_kbps_ = 0;
41 }
42
43 void BweSender::Resume() {
44 running_ = true;
45 bitrate_kbps_ = kMinBitrateKbps;
33 } 46 }
34 47
35 class NullBweSender : public BweSender { 48 class NullBweSender : public BweSender {
36 public: 49 public:
37 NullBweSender() {} 50 NullBweSender() {}
38 virtual ~NullBweSender() {} 51 virtual ~NullBweSender() {}
39 52
40 int GetFeedbackIntervalMs() const override { return 1000; } 53 int GetFeedbackIntervalMs() const override { return 1000; }
41 void GiveFeedback(const FeedbackPacket& feedback) override {} 54 void GiveFeedback(const FeedbackPacket& feedback) override {}
42 void OnPacketsSent(const Packets& packets) override {} 55 void OnPacketsSent(const Packets& packets) override {}
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 return new NadaBweReceiver(flow_id); 103 return new NadaBweReceiver(flow_id);
91 case kTcpEstimator: 104 case kTcpEstimator:
92 return new TcpBweReceiver(flow_id); 105 return new TcpBweReceiver(flow_id);
93 case kNullEstimator: 106 case kNullEstimator:
94 return new BweReceiver(flow_id); 107 return new BweReceiver(flow_id);
95 } 108 }
96 assert(false); 109 assert(false);
97 return NULL; 110 return NULL;
98 } 111 }
99 112
100 float BweReceiver::GlobalPacketLossRatio() { 113 void BweReceiver::UpdateLossAccount() {
114 float set_loss_ratio = LinkedSetPacketLossRatio();
115 size_t set_received_packets = received_packets_.size();
116 size_t set_total_packets = set_received_packets / (1.0f - set_loss_ratio);
117 size_t set_lost_packets = set_total_packets - set_received_packets;
118
119 num_previous_total_packets_ += static_cast<uint32_t>(set_total_packets);
120 num_previous_lost_packets_ += static_cast<uint32_t>(set_lost_packets);
121 }
stefan-webrtc 2015/06/25 14:44:03 But if this method gets called whenever we remove
magalhaesc 2015/07/01 12:48:39 Yes, all should be fine for the global loss ratio
122
123 void BweReceiver::ClearSet() {
124 received_packets_.Clear();
125 }
126
127 float BweReceiver::GlobalReceiverPacketLossRatio() {
128 UpdateLossAccount();
129 return static_cast<float>(num_previous_lost_packets_) /
130 num_previous_total_packets_;
131 }
132
133 // This function considers at most kSetCapacity = 10000 packets.
134 // TODO(magalhaesc): Unwrap sequence number to handle more.
135 float BweReceiver::LinkedSetPacketLossRatio() {
101 if (received_packets_.empty()) { 136 if (received_packets_.empty()) {
102 return 0.0f; 137 return 0.0f;
103 } 138 }
104 // Possibly there are packets missing. 139 // Possibly there are packets missing.
105 const uint16_t kMaxGap = 1.5 * kSetCapacity; 140 const uint16_t kMaxGap = 1.5 * kSetCapacity;
106 uint16_t min = received_packets_.find_min(); 141 uint16_t min = received_packets_.find_min();
107 uint16_t max = received_packets_.find_max(); 142 uint16_t max = received_packets_.find_max();
108 143
109 int gap; 144 int gap;
110 if (max - min < kMaxGap) { 145 if (max - min < kMaxGap) {
111 gap = max - min + 1; 146 gap = max - min + 1;
112 } else { // There was an overflow. 147 } else { // There was an overflow.
113 max = received_packets_.upper_bound(kMaxGap); 148 max = received_packets_.upper_bound(kMaxGap);
114 min = received_packets_.lower_bound(0xFFFF - kMaxGap); 149 min = received_packets_.lower_bound(0xFFFF - kMaxGap);
115 gap = max + (0xFFFF - min) + 2; 150 gap = max + (0xFFFF - min) + 2;
116 } 151 }
117 return static_cast<float>(received_packets_.size()) / gap; 152 return static_cast<float>(gap - received_packets_.size()) / gap;
118 } 153 }
119 154
120 // Go through a fixed time window of most recent packets received and 155 // Go through a fixed time window of most recent packets received and
121 // counts packets missing to obtain the packet loss ratio. If an unordered 156 // counts packets missing to obtain the packet loss ratio. If an unordered
122 // packet falls out of the timewindow it will be counted as missing. 157 // packet falls out of the timewindow it will be counted as missing.
123 // E.g.: for a timewindow covering 5 packets of the following arrival sequence 158 // E.g.: for a timewindow covering 5 packets of the following arrival sequence
124 // {10 7 9 5 6} 8 3 2 4 1, the output will be 1/6 (#8 is considered as missing). 159 // {10 7 9 5 6} 8 3 2 4 1, the output will be 1/6 (#8 is considered as missing).
125 float BweReceiver::RecentPacketLossRatio() { 160 float BweReceiver::RecentPacketLossRatio() {
126 if (received_packets_.empty()) { 161 if (received_packets_.empty()) {
127 return 0.0f; 162 return 0.0f;
(...skipping 22 matching lines...) Expand all
150 ++node_it; 185 ++node_it;
151 ++number_packets_received; 186 ++number_packets_received;
152 } 187 }
153 // Interval width between oldest and newest sequence number. 188 // Interval width between oldest and newest sequence number.
154 // There was an overflow if newest_seq_nb < oldest_seq_nb. 189 // There was an overflow if newest_seq_nb < oldest_seq_nb.
155 int gap = static_cast<uint16_t>(newest_seq_nb - oldest_seq_nb + 1); 190 int gap = static_cast<uint16_t>(newest_seq_nb - oldest_seq_nb + 1);
156 191
157 return static_cast<float>(gap - number_packets_received) / gap; 192 return static_cast<float>(gap - number_packets_received) / gap;
158 } 193 }
159 194
195 // For a given time window, compute the receiving speed rate in kbps.
196 // As described below, three cases are considered depending on the number of
197 // packets received.
198 size_t BweReceiver::RecentReceivingRate() {
magalhaesc 2015/06/25 09:03:35 Since a RateCounter was added, RecentReceivingRate
199 // If the receiver didn't receive any packet, return 0.
200 if (received_packets_.empty()) {
201 return 0.0f;
202 }
203 size_t total_size = 0;
204 int number_packets = 0;
205
206 PacketNodeIt node_it = received_packets_.begin();
207
208 int64_t last_time_ms = (*node_it)->arrival_time_ms;
209 int64_t start_time_ms = last_time_ms;
210 PacketNodeIt end = received_packets_.end();
211
212 // Stops after including the first packet out of the timeWindow.
213 // Ameliorates results when there are wide gaps between packets.
214 // E.g. Large packets : p1(0ms), p2(3000ms).
215 while (node_it != end) {
216 total_size += (*node_it)->payload_size;
217 last_time_ms = (*node_it)->arrival_time_ms;
218 ++number_packets;
219 if ((*node_it)->arrival_time_ms <
220 start_time_ms - kReceivingRateTimeWindowMs) {
221 break;
222 }
223 ++node_it;
224 }
225
226 int64_t corrected_time_ms;
227 // If the receiver didn't receive enough packets to fill the time window:
228 if (start_time_ms - last_time_ms < kReceivingRateTimeWindowMs) {
229 corrected_time_ms = kReceivingRateTimeWindowMs;
230 }
231 // If the receiver received multiple packets, use as time interval the gap
232 // between first and last packet falling in the timeWindow corrected by the
233 // factor number_packets/(number_packets-1).
234 // E.g: Let timeWindow = 500ms, payload_size = 500 bytes, number_packets = 2,
235 // packets received at t1(0ms) and t2(499 or 501ms). This prevent the function
236 // from returning ~2*8, sending instead a more likely ~1*8 kbps.
237 else {
238 corrected_time_ms = (number_packets * (start_time_ms - last_time_ms)) /
239 (number_packets - 1);
240 }
241
242 // Converting from bytes/ms to kbits/s.
243 return static_cast<size_t>(8 * total_size / corrected_time_ms);
244 }
stefan-webrtc 2015/06/25 14:44:03 This method seems overly complicated to me. I woul
magalhaesc 2015/07/01 12:48:39 Right, this method will be removed.
245
160 void LinkedSet::Insert(uint16_t sequence_number, 246 void LinkedSet::Insert(uint16_t sequence_number,
161 int64_t send_time_ms, 247 int64_t send_time_ms,
162 int64_t arrival_time_ms, 248 int64_t arrival_time_ms,
163 size_t payload_size) { 249 size_t payload_size) {
164 std::map<uint16_t, PacketNodeIt>::iterator it = map_.find(sequence_number); 250 std::map<uint16_t, PacketNodeIt>::iterator it = map_.find(sequence_number);
165 if (it != map_.end()) { 251 if (it != map_.end()) {
166 PacketNodeIt node_it = it->second; 252 PacketNodeIt node_it = it->second;
167 PacketIdentifierNode* node = *node_it; 253 PacketIdentifierNode* node = *node_it;
168 node->arrival_time_ms = arrival_time_ms; 254 node->arrival_time_ms = arrival_time_ms;
169 if (node_it != list_.begin()) { 255 if (node_it != list_.begin()) {
(...skipping 14 matching lines...) Expand all
184 list_.pop_back(); 270 list_.pop_back();
185 } 271 }
186 void LinkedSet::UpdateHead(PacketIdentifierNode* new_head) { 272 void LinkedSet::UpdateHead(PacketIdentifierNode* new_head) {
187 list_.push_front(new_head); 273 list_.push_front(new_head);
188 map_[new_head->sequence_number] = list_.begin(); 274 map_[new_head->sequence_number] = list_.begin();
189 } 275 }
190 276
191 } // namespace bwe 277 } // namespace bwe
192 } // namespace testing 278 } // namespace testing
193 } // namespace webrtc 279 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698