OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2016 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_VOICE_ENGINE_TRANSPORT_FEEDBACK_PACKET_LOSS_TRACKER_H_ | |
12 #define WEBRTC_VOICE_ENGINE_TRANSPORT_FEEDBACK_PACKET_LOSS_TRACKER_H_ | |
13 | |
14 #include <map> | |
15 | |
16 #include "webrtc/base/optional.h" | |
17 #include "webrtc/modules/include/module_common_types.h" | |
18 | |
19 namespace webrtc { | |
20 | |
21 namespace rtcp { | |
22 class TransportFeedback; | |
23 } | |
24 | |
25 class TransportFeedbackPacketLossTracker final { | |
kwiberg-webrtc
2016/12/22 02:31:41
Bonus points for using "final"!
minyue-webrtc
2016/12/28 14:48:33
Acknowledged.
| |
26 public: | |
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 | |
29 // available for making a reliable estimation, GetPacketLossRates() will | |
30 // return false to indicate packet loss metrics are not ready. | |
31 TransportFeedbackPacketLossTracker(size_t min_window_size, | |
32 size_t max_window_size); | |
33 | |
34 void OnReceivedTransportFeedback(const rtcp::TransportFeedback& feedback); | |
35 | |
36 // Returns true if packet loss rate and packet loss episode duration are ready | |
37 // and assigns respective values to |*packet_loss_rate| and | |
38 // |*consecutive_packet_loss_rate|. Continuous packet loss rate is defined as | |
39 // the probability of losing two adjacent packets. | |
40 bool GetPacketLossRates(float* packet_loss_rate, | |
41 float* consecutive_packet_loss_rate) const; | |
kwiberg-webrtc
2016/12/22 02:31:41
Consider returning Optional<PacketLossRates>, wher
minyue-webrtc
2016/12/28 14:48:33
Actually, the return API is subject to a change. W
kwiberg-webrtc
2017/01/05 02:51:11
Acknowledged.
| |
42 | |
43 // Verifies that the internal states are correct. Only used for tests. | |
44 void Validate() const; | |
kwiberg-webrtc
2016/12/22 02:31:41
Make this private, and DCHECK it at the beginning
minyue-webrtc
2016/12/28 14:48:33
We think it is too expensive. We currently keep th
kwiberg-webrtc
2017/01/05 02:51:11
Acknowledged.
| |
45 | |
46 private: | |
47 // PacketStatus is a map from sequence number to a boolean. The boolean is | |
48 // true if it is received. | |
49 typedef std::map<uint16_t, bool> PacketStatus; | |
kwiberg-webrtc
2016/12/22 02:31:41
Is there a difference between false and a missing
minyue-webrtc
2016/12/28 14:48:33
yes, missing entries are not taken into account
s
kwiberg-webrtc
2017/01/05 02:51:11
Please document this.
| |
50 typedef PacketStatus::const_iterator PacketStatusIterator; | |
51 | |
52 void Reset(); | |
53 // ReferenceSequenceNumber() provides a sequence number that defines the | |
54 // order of packet reception info stored in |packet_status_window_|. In | |
55 // particular, given any sequence number |x|, | |
56 // (2^16 + x - ref_seq_num_) % 2^16 defines its actual position in | |
57 // |packet_status_window_|. | |
58 uint16_t ReferenceSequenceNumber() const; | |
59 bool IsOldSequenceNumber(uint16_t seq_num) const; | |
60 void InsertPacketStatus(uint16_t seq_num, bool received); | |
61 void RemoveOldestPacketStatus(); | |
62 void ApplyPacketStatus(PacketStatusIterator it); | |
63 void UndoPacketStatus(PacketStatusIterator it); | |
64 PacketStatusIterator PreviousPacketStatus(PacketStatusIterator it); | |
65 PacketStatusIterator NextPacketStatus(PacketStatusIterator it); | |
66 | |
67 const size_t min_window_size_; | |
68 const size_t max_window_size_; | |
69 | |
70 PacketStatus packet_status_window_; | |
71 // |ref_packet_status_| points to the oldest item in |packet_status_window_|. | |
72 PacketStatusIterator ref_packet_status_; | |
73 | |
74 size_t num_received_packets_; | |
75 size_t num_lost_packets_; | |
76 size_t num_consecutive_losses_; | |
77 size_t num_consecutive_old_reports_; | |
78 }; | |
79 | |
80 } // namespace webrtc | |
81 | |
82 #endif // WEBRTC_VOICE_ENGINE_TRANSPORT_FEEDBACK_PACKET_LOSS_TRACKER_H_ | |
OLD | NEW |