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

Side by Side Diff: webrtc/voice_engine/transport_feedback_packet_loss_tracker.h

Issue 2711473003: R/PLR calculation - time-based window (Closed)
Patch Set: More compiler nits. 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
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_acked_packets| latest packet statuses will be used for 27 // * We count up to |max_window_size_ms| from the sent
28 // calculating the packet loss metrics. 28 // time of the latest acked packet for the calculation of the metrics.
29 // * PLR (packet-loss-rate) is reliably computable once the statuses of 29 // * PLR (packet-loss-rate) is reliably computable once the statuses of
30 // |plr_min_num_acked_packets| packets are known. 30 // |plr_min_num_acked_packets| packets are known.
31 // * RPLR (recoverable-packet-loss-rate) is reliably computable once the 31 // * RPLR (recoverable-packet-loss-rate) is reliably computable once the
32 // statuses of |rplr_min_num_acked_pairs| pairs are known. 32 // statuses of |rplr_min_num_acked_pairs| pairs are known.
33 TransportFeedbackPacketLossTracker(size_t max_acked_packets, 33 TransportFeedbackPacketLossTracker(int64_t max_window_size_ms,
34 size_t plr_min_num_acked_packets, 34 size_t plr_min_num_acked_packets,
35 size_t rplr_min_num_acked_pairs); 35 size_t rplr_min_num_acked_pairs);
36 36
37 void OnPacketAdded(uint16_t seq_num); 37 void OnPacketAdded(uint16_t seq_num, int64_t send_time_ms);
38 38
39 void OnReceivedTransportFeedback(const rtcp::TransportFeedback& feedback); 39 void OnReceivedTransportFeedback(const rtcp::TransportFeedback& feedback);
40 40
41 // Returns the packet loss rate, if the window has enough packet statuses to 41 // Returns the packet loss rate, if the window has enough packet statuses to
42 // reliably compute it. Otherwise, returns empty. 42 // reliably compute it. Otherwise, returns empty.
43 rtc::Optional<float> GetPacketLossRate() const; 43 rtc::Optional<float> GetPacketLossRate() const;
44 44
45 // Returns the first-order-FEC recoverable packet loss rate, if the window has 45 // Returns the first-order-FEC recoverable packet loss rate, if the window has
46 // enough status pairs to reliably compute it. Otherwise, returns empty. 46 // enough status pairs to reliably compute it. Otherwise, returns empty.
47 rtc::Optional<float> GetRecoverablePacketLossRate() const; 47 rtc::Optional<float> GetRecoverablePacketLossRate() const;
48 48
49 // Verifies that the internal states are correct. Only used for tests. 49 // Verifies that the internal states are correct. Only used for tests.
50 void Validate() const; 50 void Validate() const;
51 51
52 private: 52 private:
53 // When a packet is sent, we memorize its association with the stream by 53 // When a packet is sent, we memorize its association with the stream by
54 // marking it as (sent-but-so-far-) unacked. If we ever receive a feedback 54 // marking it as (sent-but-so-far-) unacked. If we ever receive a feedback
55 // that reports it as received/lost, we update the state and 55 // that reports it as received/lost, we update the state and
56 // metrics accordingly. 56 // metrics accordingly.
57 57
58 enum class PacketStatus { Unacked = 0, Received = 1, Lost = 2 }; 58 enum class PacketStatus { Unacked = 0, Received = 1, Lost = 2 };
59 typedef std::map<uint16_t, PacketStatus> PacketStatusMap; 59 struct SentPacket {
60 typedef PacketStatusMap::const_iterator ConstPacketStatusIterator; 60 SentPacket(int64_t send_time_ms, PacketStatus status)
61 : send_time_ms(send_time_ms), status(status) {}
62 int64_t send_time_ms;
63 PacketStatus status;
64 };
65 typedef std::map<uint16_t, SentPacket> SentPacketStatusMap;
66 typedef SentPacketStatusMap::const_iterator ConstPacketStatusIterator;
61 67
62 void Reset(); 68 void Reset();
63 69
64 // ReferenceSequenceNumber() provides a sequence number that defines the 70 // ReferenceSequenceNumber() provides a sequence number that defines the
65 // order of packet reception info stored in |packet_status_window_|. In 71 // order of packet reception info stored in |packet_status_window_|. In
66 // particular, given any sequence number |x|, 72 // particular, given any sequence number |x|,
67 // (2^16 + x - ref_seq_num_) % 2^16 defines its actual position in 73 // (2^16 + x - ref_seq_num_) % 2^16 defines its actual position in
68 // |packet_status_window_|. 74 // |packet_status_window_|.
69 uint16_t ReferenceSequenceNumber() const; 75 uint16_t ReferenceSequenceNumber() const;
70 uint16_t NewestSequenceNumber() const; 76 uint16_t NewestSequenceNumber() const;
71 void RecordFeedback(PacketStatusMap::iterator it, bool received); 77 void UpdatePacketStatus(SentPacketStatusMap::iterator it,
78 PacketStatus new_status);
72 void RemoveOldestPacketStatus(); 79 void RemoveOldestPacketStatus();
73 80
74 void UpdateMetrics(ConstPacketStatusIterator it, 81 void UpdateMetrics(ConstPacketStatusIterator it,
75 bool apply /* false = undo */); 82 bool apply /* false = undo */);
76 void UpdatePlr(ConstPacketStatusIterator it, bool apply /* false = undo */); 83 void UpdatePlr(ConstPacketStatusIterator it, bool apply /* false = undo */);
77 void UpdateRplr(ConstPacketStatusIterator it, bool apply /* false = undo */); 84 void UpdateRplr(ConstPacketStatusIterator it, bool apply /* false = undo */);
78 85
79 ConstPacketStatusIterator PreviousPacketStatus( 86 ConstPacketStatusIterator PreviousPacketStatus(
80 ConstPacketStatusIterator it) const; 87 ConstPacketStatusIterator it) const;
81 ConstPacketStatusIterator NextPacketStatus( 88 ConstPacketStatusIterator NextPacketStatus(
82 ConstPacketStatusIterator it) const; 89 ConstPacketStatusIterator it) const;
83 90
84 const size_t max_acked_packets_; 91 const int64_t max_window_size_ms_;
85 size_t acked_packets_; 92 size_t acked_packets_;
86 93
87 PacketStatusMap packet_status_window_; 94 SentPacketStatusMap packet_status_window_;
88 // |ref_packet_status_| points to the oldest item in |packet_status_window_|. 95 // |ref_packet_status_| points to the oldest item in |packet_status_window_|.
89 ConstPacketStatusIterator ref_packet_status_; 96 ConstPacketStatusIterator ref_packet_status_;
90 97
91 // Packet-loss-rate calculation (lost / all-known-packets). 98 // Packet-loss-rate calculation (lost / all-known-packets).
92 struct PlrState { 99 struct PlrState {
93 explicit PlrState(size_t min_num_acked_packets) 100 explicit PlrState(size_t min_num_acked_packets)
94 : min_num_acked_packets_(min_num_acked_packets) { 101 : min_num_acked_packets_(min_num_acked_packets) {
95 Reset(); 102 Reset();
96 } 103 }
97 void Reset() { 104 void Reset() {
(...skipping 24 matching lines...) Expand all
122 // of all pairs of consecutive acked packets. 129 // of all pairs of consecutive acked packets.
123 const size_t min_num_acked_pairs_; 130 const size_t min_num_acked_pairs_;
124 size_t num_acked_pairs_; 131 size_t num_acked_pairs_;
125 size_t num_recoverable_losses_; 132 size_t num_recoverable_losses_;
126 } rplr_state_; 133 } rplr_state_;
127 }; 134 };
128 135
129 } // namespace webrtc 136 } // namespace webrtc
130 137
131 #endif // WEBRTC_VOICE_ENGINE_TRANSPORT_FEEDBACK_PACKET_LOSS_TRACKER_H_ 138 #endif // WEBRTC_VOICE_ENGINE_TRANSPORT_FEEDBACK_PACKET_LOSS_TRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698