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

Side by Side Diff: webrtc/p2p/base/packetlossestimator.cc

Issue 2722933002: Measure packet loss so we can use it to select ICE candidate pairs. (Closed)
Patch Set: test that UpdateResponseRate is called internally Created 3 years, 9 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
(Empty)
1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
Taylor Brandstetter 2017/03/07 18:16:31 nit: 2017
Zach Stein 2017/03/08 06:21:14 Done.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/p2p/base/packetlossestimator.h"
12
13 namespace cricket {
14
15 PacketLossEstimator::PacketLossEstimator(int64_t consider_lost_after,
16 int64_t forget_after)
17 : consider_lost_after_(consider_lost_after), forget_after_(forget_after) {}
Taylor Brandstetter 2017/03/07 18:16:32 Could add an "RTC_DCHECK_LT(consider_lost_after, f
Zach Stein 2017/03/08 06:21:14 Done.
18
19 void PacketLossEstimator::ExpectResponse(std::string id, int64_t sent_time) {
20 tracked_packets_[id] = PacketInfo{sent_time, false};
21
22 UpdateResponseRateIfStale(sent_time);
Taylor Brandstetter 2017/03/07 18:16:32 Is this called just to ensure the the map doesn't
Zach Stein 2017/03/08 06:21:14 Having ForgetOldRequests not update the response r
Taylor Brandstetter 2017/03/08 17:48:20 How to test that the map doesn't grow indefinitely
Zach Stein 2017/03/08 23:00:08 Done.
23 }
24
25 void PacketLossEstimator::ReceivedResponse(std::string id,
26 int64_t received_time) {
27 auto iter = tracked_packets_.find(id);
28 if (iter != tracked_packets_.end()) {
29 auto& packet_info = iter->second;
30 packet_info.response_received = true;
31 }
32
33 UpdateResponseRateIfStale(received_time);
34 }
35
36 void PacketLossEstimator::UpdateResponseRate(int64_t now) {
37 int responses_expected = 0;
38 int responses_received = 0;
39
40 for (auto iter = tracked_packets_.begin(); iter != tracked_packets_.end();) {
41 const auto& packet_info = iter->second;
42 if (Forget(packet_info, now)) {
43 iter = tracked_packets_.erase(iter);
44 continue;
45 }
46 if (packet_info.response_received) {
47 responses_expected += 1;
48 responses_received += 1;
49 } else if (ConsiderLost(packet_info, now)) {
50 responses_expected += 1;
51 }
52 ++iter;
53 }
54
55 if (responses_expected > 0) {
56 response_rate_ =
57 static_cast<double>(responses_received) / responses_expected;
58 } else {
59 response_rate_ = 1.0;
60 }
61
62 last_update_time_ = now;
63 }
64
65 void PacketLossEstimator::UpdateResponseRateIfStale(int64_t now) {
66 if (now - last_update_time_ > forget_after_) {
67 UpdateResponseRate(now);
68 }
69 }
70
71 bool PacketLossEstimator::ConsiderLost(const PacketInfo& packet_info,
72 int64_t now) const {
73 return packet_info.sent_time < now - consider_lost_after_;
74 }
75
76 bool PacketLossEstimator::Forget(const PacketInfo& packet_info,
77 int64_t now) const {
78 return now - packet_info.sent_time > forget_after_;
79 }
80
81 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698