OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | |
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 #ifndef WEBRTC_P2P_BASE_PACKETLOSSESTIMATOR_H_ | |
12 #define WEBRTC_P2P_BASE_PACKETLOSSESTIMATOR_H_ | |
13 | |
14 #include <stdint.h> | |
15 #include <string> | |
16 #include <unordered_map> | |
17 | |
18 namespace cricket { | |
19 | |
20 // Estimates the response rate for a series of messages expecting responses. | |
21 // Messages and their corresponding responses are identified by a string id. | |
22 // Responses are considered lost if they are not received within | |
23 // |consider_lost_after| ms. If a responses is received after | |
Taylor Brandstetter
2017/03/07 18:16:32
"response", singular
Zach Stein
2017/03/08 06:21:15
Done.
| |
24 // |consider_lost_after| ms, it is still considered to be a response. | |
Taylor Brandstetter
2017/03/07 18:16:32
Maybe "counted as" instead of "considered to be"?
Zach Stein
2017/03/08 06:21:15
Done.
| |
25 // Messages sent more than |forget_after| ms ago are not considered | |
26 // anymore. The response rate is initially assumed to be 1.0. If the current | |
Taylor Brandstetter
2017/03/07 18:16:32
Paragraph break before "If"?
Zach Stein
2017/03/08 06:21:14
Done.
| |
27 // time is 7, |forget_after| is 6, and |consider_lost_after| is 2, the response | |
Taylor Brandstetter
2017/03/07 18:16:32
Since "forget_after" now means "forget both sent r
Zach Stein
2017/03/08 06:21:15
I don't really like the name forget after, but I w
Taylor Brandstetter
2017/03/08 17:48:20
I guess "window size" is still ambiguous since the
| |
28 // rate considers messages sent between times 1 and 5, so the window looks like | |
29 // this: | |
30 // | |
31 // Time: 0 1 2 3 4 5 6 7 | |
32 // Wind: <-------> | | |
Taylor Brandstetter
2017/03/07 18:16:32
I'm not sure this is accurate; if a request is sen
Zach Stein
2017/03/08 06:21:15
It will be. I was trying to show the window where
Taylor Brandstetter
2017/03/08 17:48:20
That diagram looks good (or, even just the sentenc
| |
33 class PacketLossEstimator { | |
34 public: | |
35 explicit PacketLossEstimator(int64_t consider_lost_after, | |
36 int64_t forget_after); | |
37 | |
38 // Registers that a message with the given |id| was sent at |sent_time|. | |
39 void ExpectResponse(std::string id, int64_t sent_time); | |
40 | |
41 // Registers a response with the given |id| was received at |received_time|. | |
42 void ReceivedResponse(std::string id, int64_t received_time); | |
43 | |
44 // Calculates the current response rate based on the expected and received | |
45 // messages. Messages sent more than |forget_after| ms ago will be erased. | |
46 // This method is called periodically by ExpectResponse and ReceivedResponse | |
47 // to bound memory usage. | |
48 void UpdateResponseRate(int64_t now); | |
49 | |
50 // Gets the current response rate as updated by UpdateResponseRate. | |
51 double get_response_rate() const { return response_rate_; } | |
52 | |
53 private: | |
54 struct PacketInfo { | |
55 int64_t sent_time; | |
56 bool response_received; | |
57 }; | |
58 | |
59 void UpdateResponseRateIfStale(int64_t now); | |
60 | |
61 bool ConsiderLost(const PacketInfo&, int64_t now) const; | |
62 bool Forget(const PacketInfo&, int64_t now) const; | |
63 | |
64 int64_t consider_lost_after_; // In milliseconds. | |
Taylor Brandstetter
2017/03/07 18:16:32
I forgot if I suggested this, but if these variabl
Zach Stein
2017/03/08 06:21:15
Done.
| |
65 int64_t forget_after_; // In milliseconds. | |
66 | |
67 int64_t last_update_time_ = 0; | |
68 | |
69 std::unordered_map<std::string, PacketInfo> tracked_packets_; | |
70 | |
71 double response_rate_ = 1.0; | |
72 }; | |
73 | |
74 } // namespace cricket | |
75 | |
76 #endif // WEBRTC_P2P_BASE_PACKETLOSSESTIMATOR_H_ | |
OLD | NEW |