Chromium Code Reviews| Index: webrtc/voice_engine/transport_feedback_packet_loss_tracker.h |
| diff --git a/webrtc/voice_engine/transport_feedback_packet_loss_tracker.h b/webrtc/voice_engine/transport_feedback_packet_loss_tracker.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9f30f2dc23705bbe5b2bc690bf31c60ff5e8996e |
| --- /dev/null |
| +++ b/webrtc/voice_engine/transport_feedback_packet_loss_tracker.h |
| @@ -0,0 +1,82 @@ |
| +/* |
| + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| + * |
| + * Use of this source code is governed by a BSD-style license |
| + * that can be found in the LICENSE file in the root of the source |
| + * tree. An additional intellectual property rights grant can be found |
| + * in the file PATENTS. All contributing project authors may |
| + * be found in the AUTHORS file in the root of the source tree. |
| + */ |
| + |
| +#ifndef WEBRTC_VOICE_ENGINE_TRANSPORT_FEEDBACK_PACKET_LOSS_TRACKER_H_ |
| +#define WEBRTC_VOICE_ENGINE_TRANSPORT_FEEDBACK_PACKET_LOSS_TRACKER_H_ |
| + |
| +#include <map> |
| + |
| +#include "webrtc/base/optional.h" |
| +#include "webrtc/modules/include/module_common_types.h" |
| + |
| +namespace webrtc { |
| + |
| +namespace rtcp { |
| +class TransportFeedback; |
| +} |
| + |
| +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.
|
| + public: |
| + // Up to |max_window_size| latest packet statuses wil be used for calculating |
| + // the packet loss metrics. When less than |min_window_size| samples are |
| + // available for making a reliable estimation, GetPacketLossRates() will |
| + // return false to indicate packet loss metrics are not ready. |
| + TransportFeedbackPacketLossTracker(size_t min_window_size, |
| + size_t max_window_size); |
| + |
| + void OnReceivedTransportFeedback(const rtcp::TransportFeedback& feedback); |
| + |
| + // Returns true if packet loss rate and packet loss episode duration are ready |
| + // and assigns respective values to |*packet_loss_rate| and |
| + // |*consecutive_packet_loss_rate|. Continuous packet loss rate is defined as |
| + // the probability of losing two adjacent packets. |
| + bool GetPacketLossRates(float* packet_loss_rate, |
| + 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.
|
| + |
| + // Verifies that the internal states are correct. Only used for tests. |
| + 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.
|
| + |
| + private: |
| + // PacketStatus is a map from sequence number to a boolean. The boolean is |
| + // true if it is received. |
| + 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.
|
| + typedef PacketStatus::const_iterator PacketStatusIterator; |
| + |
| + void Reset(); |
| + // ReferenceSequenceNumber() provides a sequence number that defines the |
| + // order of packet reception info stored in |packet_status_window_|. In |
| + // particular, given any sequence number |x|, |
| + // (2^16 + x - ref_seq_num_) % 2^16 defines its actual position in |
| + // |packet_status_window_|. |
| + uint16_t ReferenceSequenceNumber() const; |
| + bool IsOldSequenceNumber(uint16_t seq_num) const; |
| + void InsertPacketStatus(uint16_t seq_num, bool received); |
| + void RemoveOldestPacketStatus(); |
| + void ApplyPacketStatus(PacketStatusIterator it); |
| + void UndoPacketStatus(PacketStatusIterator it); |
| + PacketStatusIterator PreviousPacketStatus(PacketStatusIterator it); |
| + PacketStatusIterator NextPacketStatus(PacketStatusIterator it); |
| + |
| + const size_t min_window_size_; |
| + const size_t max_window_size_; |
| + |
| + PacketStatus packet_status_window_; |
| + // |ref_packet_status_| points to the oldest item in |packet_status_window_|. |
| + PacketStatusIterator ref_packet_status_; |
| + |
| + size_t num_received_packets_; |
| + size_t num_lost_packets_; |
| + size_t num_consecutive_losses_; |
| + size_t num_consecutive_old_reports_; |
| +}; |
| + |
| +} // namespace webrtc |
| + |
| +#endif // WEBRTC_VOICE_ENGINE_TRANSPORT_FEEDBACK_PACKET_LOSS_TRACKER_H_ |