OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 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 #ifndef WEBRTC_VOICE_ENGINE_TRANSPORT_FEEDBACK_PACKET_LOSS_TRACKER_H_ | 11 #ifndef WEBRTC_VOICE_ENGINE_TRANSPORT_FEEDBACK_PACKET_LOSS_TRACKER_H_ |
12 #define WEBRTC_VOICE_ENGINE_TRANSPORT_FEEDBACK_PACKET_LOSS_TRACKER_H_ | 12 #define WEBRTC_VOICE_ENGINE_TRANSPORT_FEEDBACK_PACKET_LOSS_TRACKER_H_ |
13 | 13 |
14 #include <map> | 14 #include <map> |
15 | 15 |
16 #include "webrtc/base/optional.h" | 16 #include "webrtc/base/optional.h" |
17 #include "webrtc/modules/include/module_common_types.h" | 17 #include "webrtc/modules/include/module_common_types.h" |
18 | 18 |
19 namespace webrtc { | 19 namespace webrtc { |
20 | 20 |
21 namespace rtcp { | 21 namespace rtcp { |
22 class TransportFeedback; | 22 class TransportFeedback; |
23 } | 23 } |
24 | 24 |
25 class TransportFeedbackPacketLossTracker final { | 25 class TransportFeedbackPacketLossTracker final { |
26 public: | 26 public: |
27 // Up to |max_window_size| latest packet statuses wil be used for calculating | 27 // Up to |max_window_size| latest packet statuses wil be used for calculating |
28 // the packet loss metrics. When less than |min_window_size| samples are | 28 // the packet loss metrics. When less than |min_window_size| samples are |
29 // available for making a reliable estimation, GetPacketLossRates() will | 29 // available for making a reliable estimation, neither PLR nor RPLR would |
30 // return false to indicate packet loss metrics are not ready. | 30 // be considered validly computable. |
31 // When |min_pairs_num_for_rplr| pairs or more are available, RPLR is reliably | |
32 // computable. This is independent of PLR being computable. | |
31 TransportFeedbackPacketLossTracker(size_t min_window_size, | 33 TransportFeedbackPacketLossTracker(size_t min_window_size, |
minyue-webrtc
2017/01/25 09:38:45
rename min_window_size to make it specific to plr,
elad.alon_webrtc.org
2017/01/25 12:47:55
Please see subsequent CL, which renames to min/max
minyue-webrtc
2017/01/25 20:00:59
You see I did not ask you to rename max_window_siz
| |
32 size_t max_window_size); | 34 size_t max_window_size, |
minyue-webrtc
2017/01/25 09:38:45
change the order of min_window_size (and rename it
elad.alon_webrtc.org
2017/01/25 12:47:55
Min-then-max looks fine to me. That's how I'm used
| |
35 size_t min_pairs_num_for_rplr); | |
minyue-webrtc
2017/01/25 09:38:45
rename to rplr_min_num_pairs_
elad.alon_webrtc.org
2017/01/25 12:47:55
Done.
| |
33 | 36 |
34 void OnReceivedTransportFeedback(const rtcp::TransportFeedback& feedback); | 37 void OnReceivedTransportFeedback(const rtcp::TransportFeedback& feedback); |
35 | 38 |
36 // Returns true if packet loss rate and packet loss episode duration are ready | 39 // Returns the packet loss rate, if the window has enough data to |
37 // and assigns respective values to |*packet_loss_rate| and | 40 // reliably compute it. |
38 // |*consecutive_packet_loss_rate|. Continuous packet loss rate is defined as | 41 rtc::Optional<float> GetPacketLossRate() const; |
39 // the probability of losing two adjacent packets. | 42 |
40 bool GetPacketLossRates(float* packet_loss_rate, | 43 // Returns the first-order-FEC recoverable packet loss rate, if the window |
41 float* consecutive_packet_loss_rate) const; | 44 // has enough data to reliably compute it. |
45 rtc::Optional<float> GetRecoverablePacketLossRate() const; | |
42 | 46 |
43 // Verifies that the internal states are correct. Only used for tests. | 47 // Verifies that the internal states are correct. Only used for tests. |
44 void Validate() const; | 48 void Validate() const; |
45 | 49 |
46 private: | 50 private: |
47 // PacketStatus is a map from sequence number to its reception status. The | 51 // PacketStatus is a map from sequence number to a boolean. The boolean is |
minyue-webrtc
2017/01/25 09:38:45
use the old comment.
elad.alon_webrtc.org
2017/01/25 12:47:55
Done. (Edited needlessly when doing some rebasing
minyue-webrtc
2017/01/25 20:00:59
Acknowledged.
| |
48 // status is true if the corresponding packet is received, and false if it is | 52 // true if it is received. |
49 // lost. Unknown statuses are not present in the map. | |
50 typedef std::map<uint16_t, bool> PacketStatus; | 53 typedef std::map<uint16_t, bool> PacketStatus; |
51 typedef PacketStatus::const_iterator PacketStatusIterator; | 54 typedef PacketStatus::const_iterator PacketStatusIterator; |
52 | 55 |
53 void Reset(); | 56 void Reset(); |
57 | |
54 // ReferenceSequenceNumber() provides a sequence number that defines the | 58 // ReferenceSequenceNumber() provides a sequence number that defines the |
55 // order of packet reception info stored in |packet_status_window_|. In | 59 // order of packet reception info stored in |packet_status_window_|. In |
56 // particular, given any sequence number |x|, | 60 // particular, given any sequence number |x|, |
57 // (2^16 + x - ref_seq_num_) % 2^16 defines its actual position in | 61 // (2^16 + x - ref_seq_num_) % 2^16 defines its actual position in |
58 // |packet_status_window_|. | 62 // |packet_status_window_|. |
59 uint16_t ReferenceSequenceNumber() const; | 63 uint16_t ReferenceSequenceNumber() const; |
60 bool IsOldSequenceNumber(uint16_t seq_num) const; | 64 bool IsOldSequenceNumber(uint16_t seq_num) const; |
61 void InsertPacketStatus(uint16_t seq_num, bool received); | 65 void InsertPacketStatus(uint16_t seq_num, bool received); |
62 void RemoveOldestPacketStatus(); | 66 void RemoveOldestPacketStatus(); |
63 void ApplyPacketStatus(PacketStatusIterator it); | 67 |
64 void UndoPacketStatus(PacketStatusIterator it); | 68 void UpdateMetrics(PacketStatusIterator it, bool apply /* false = undo */); |
minyue-webrtc
2017/01/25 09:38:45
I find it would be easier for me to understand
vo
elad.alon_webrtc.org
2017/01/25 12:47:55
1. I think it would be confusing for a reader to s
minyue-webrtc
2017/01/25 20:00:59
Sure, anyway, either way should not be a problem f
| |
69 void UpdatePlr(PacketStatusIterator it, bool apply /* false = undo */); | |
70 void UpdateRplr(PacketStatusIterator it, bool apply /* false = undo */); | |
71 | |
65 PacketStatusIterator PreviousPacketStatus(PacketStatusIterator it); | 72 PacketStatusIterator PreviousPacketStatus(PacketStatusIterator it); |
66 PacketStatusIterator NextPacketStatus(PacketStatusIterator it); | 73 PacketStatusIterator NextPacketStatus(PacketStatusIterator it); |
67 | 74 |
68 const size_t min_window_size_; | |
69 const size_t max_window_size_; | 75 const size_t max_window_size_; |
70 | 76 |
71 PacketStatus packet_status_window_; | 77 PacketStatus packet_status_window_; |
72 // |ref_packet_status_| points to the oldest item in |packet_status_window_|. | 78 // |ref_packet_status_| points to the oldest item in |packet_status_window_|. |
73 PacketStatusIterator ref_packet_status_; | 79 PacketStatusIterator ref_packet_status_; |
74 | 80 |
75 size_t num_received_packets_; | 81 struct PlrState { |
76 size_t num_lost_packets_; | 82 PlrState(size_t min_window_size) |
77 size_t num_consecutive_losses_; | 83 : min_window_size_(min_window_size) { |
78 size_t num_consecutive_old_reports_; | 84 Reset(); |
85 } | |
86 void Reset() { | |
87 num_received_packets_ = 0; | |
88 num_lost_packets_ = 0; | |
89 } | |
90 rtc::Optional<float> GetMetric() const; | |
91 const size_t min_window_size_; | |
minyue-webrtc
2017/01/25 09:38:45
rename min_window_size -> min_num_packets_
elad.alon_webrtc.org
2017/01/25 12:47:55
In this CL, it is still the window. In the subsequ
minyue-webrtc
2017/01/25 20:00:59
True, but doing it now will make it clearer, parti
| |
92 size_t num_received_packets_; | |
93 size_t num_lost_packets_; | |
94 } plr_state_; | |
95 | |
96 struct RplrState { | |
97 RplrState(size_t min_pairs) | |
98 : min_pairs_(min_pairs) { | |
99 Reset(); | |
100 } | |
101 void Reset() { | |
102 num_known_status_pairs_ = 0; | |
103 num_loss_followed_by_reception_pairs_ = 0; | |
104 } | |
105 rtc::Optional<float> GetMetric() const; | |
106 const size_t min_pairs_; | |
107 size_t num_known_status_pairs_; | |
108 size_t num_loss_followed_by_reception_pairs_; | |
minyue-webrtc
2017/01/25 09:38:45
let's consider making the var names more precise a
elad.alon_webrtc.org
2017/01/25 12:47:55
min_num_pair - OK
num_pairs - I prefer num_known_p
minyue-webrtc
2017/01/25 20:00:59
known is not a clearly defined word. In the next s
| |
109 } rplr_state_; | |
110 | |
111 size_t num_consecutive_old_reports_; // TODO(eladalon): Upcoming CL removes. | |
minyue-webrtc
2017/01/25 09:38:46
elad.alon
elad.alon_webrtc.org
2017/01/25 12:47:55
Done.
| |
79 }; | 112 }; |
80 | 113 |
81 } // namespace webrtc | 114 } // namespace webrtc |
82 | 115 |
83 #endif // WEBRTC_VOICE_ENGINE_TRANSPORT_FEEDBACK_PACKET_LOSS_TRACKER_H_ | 116 #endif // WEBRTC_VOICE_ENGINE_TRANSPORT_FEEDBACK_PACKET_LOSS_TRACKER_H_ |
OLD | NEW |