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

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

Issue 2579613003: Add TransportFeedbackPacketLossTracker. (Closed)
Patch Set: adding a missing file (continuation of PS7) Created 3 years, 11 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
(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 TransportFeedbackInterface;
23 }
24
25 class TransportFeedbackPacketLossTracker final {
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(
35 const rtcp::TransportFeedbackInterface& feedback);
36
37 // Returns true if packet loss rate and packet loss episode duration are ready
38 // and assigns respective values to |*packet_loss_rate| and
39 // |*consecutive_packet_loss_rate|. Continuous packet loss rate is defined as
40 // the probability of losing two adjacent packets.
41 bool GetPacketLossRates(float* packet_loss_rate,
42 float* consecutive_packet_loss_rate) const;
43
44 // Verifies that the internal states are correct. Only used for tests.
45 void Validate() const;
46
47 private:
48 // PacketStatus is a map from sequence number to a boolean. The boolean is
49 // true if it is received.
50 typedef std::map<uint16_t, bool> PacketStatus;
51 typedef PacketStatus::const_iterator PacketStatusIterator;
52
53 void Reset();
54 // ReferenceSequenceNumber() provides a sequence number that defines the
55 // order of packet reception info stored in |packet_status_window_|. In
56 // particular, given any sequence number |x|,
57 // (2^16 + x - ref_seq_num_) % 2^16 defines its actual position in
58 // |packet_status_window_|.
59 uint16_t ReferenceSequenceNumber() const;
60 bool IsOldSequenceNumber(uint16_t seq_num) const;
61 void InsertPacketStatus(uint16_t seq_num, bool received);
62 void RemoveOldestPacketStatus();
63 void ApplyPacketStatus(PacketStatusIterator it);
64 void UndoPacketStatus(PacketStatusIterator it);
65 PacketStatusIterator PreviousPacketStatus(PacketStatusIterator it);
66 PacketStatusIterator NextPacketStatus(PacketStatusIterator it);
67
68 const size_t min_window_size_;
69 const size_t max_window_size_;
70
71 PacketStatus packet_status_window_;
72 // |ref_packet_status_| points to the oldest item in |packet_status_window_|.
73 PacketStatusIterator ref_packet_status_;
74
75 size_t num_received_packets_;
76 size_t num_lost_packets_;
77 size_t num_consecutive_losses_;
78 size_t num_consecutive_old_reports_;
79 };
80
81 } // namespace webrtc
82
83 #endif // WEBRTC_VOICE_ENGINE_TRANSPORT_FEEDBACK_PACKET_LOSS_TRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698