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 #include "webrtc/voice_engine/transport_feedback_packet_loss_tracker.h" | 11 #include "webrtc/voice_engine/transport_feedback_packet_loss_tracker.h" |
12 | 12 |
13 #include <limits> | 13 #include <limits> |
14 #include <utility> | 14 #include <utility> |
15 | 15 |
16 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" |
17 #include "webrtc/base/mod_ops.h" | 17 #include "webrtc/base/mod_ops.h" |
18 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | |
18 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" | 19 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" |
19 | 20 |
20 namespace { | 21 namespace { |
21 constexpr uint16_t kSeqNumHalf = 0x8000u; | 22 constexpr uint16_t kSeqNumHalf = 0x8000u; |
22 void UpdateCounter(size_t* counter, bool increment) { | 23 void UpdateCounter(size_t* counter, bool increment) { |
23 if (increment) { | 24 if (increment) { |
24 RTC_DCHECK_LT(*counter, std::numeric_limits<std::size_t>::max()); | 25 RTC_DCHECK_LT(*counter, std::numeric_limits<std::size_t>::max()); |
25 ++(*counter); | 26 ++(*counter); |
26 } else { | 27 } else { |
27 RTC_DCHECK_GT(*counter, 0); | 28 RTC_DCHECK_GT(*counter, 0); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 | 91 |
91 SentPacket sent_packet(send_time_ms, PacketStatus::Unacked); | 92 SentPacket sent_packet(send_time_ms, PacketStatus::Unacked); |
92 packet_status_window_.insert(packet_status_window_.end(), | 93 packet_status_window_.insert(packet_status_window_.end(), |
93 std::make_pair(seq_num, sent_packet)); | 94 std::make_pair(seq_num, sent_packet)); |
94 | 95 |
95 if (packet_status_window_.size() == 1) { | 96 if (packet_status_window_.size() == 1) { |
96 ref_packet_status_ = packet_status_window_.cbegin(); | 97 ref_packet_status_ = packet_status_window_.cbegin(); |
97 } | 98 } |
98 } | 99 } |
99 | 100 |
100 void TransportFeedbackPacketLossTracker::OnReceivedTransportFeedback( | 101 void TransportFeedbackPacketLossTracker::OnPacketFeedbacks( |
101 const rtcp::TransportFeedback& feedback) { | 102 const std::vector<PacketFeedback>& packet_feedbacks) { |
102 const auto& status_vector = feedback.GetStatusVector(); | 103 for (const PacketFeedback& packet : packet_feedbacks) { |
minyue-webrtc
2017/03/20 21:14:35
nit PacketFeedback -> auto
stefan-webrtc
2017/03/21 06:10:56
I prefer not using auto if the underlying type isn
elad.alon_webrtc.org
2017/03/21 09:22:37
(That was my reasoning.)
| |
103 const uint16_t base_seq_num = feedback.GetBaseSequence(); | 104 const auto& it = packet_status_window_.find(packet.sequence_number); |
104 | |
105 uint16_t seq_num = base_seq_num; | |
106 for (size_t i = 0; i < status_vector.size(); ++i, ++seq_num) { | |
107 const auto& it = packet_status_window_.find(seq_num); | |
108 | 105 |
109 // Packets which aren't at least marked as unacked either do not belong to | 106 // Packets which aren't at least marked as unacked either do not belong to |
110 // this media stream, or have been shifted out of window. | 107 // this media stream, or have been shifted out of window. |
111 if (it == packet_status_window_.end()) | 108 if (it == packet_status_window_.end()) |
112 continue; | 109 continue; |
113 | 110 |
114 const bool lost = | 111 const bool lost = packet.arrival_time_ms == PacketFeedback::kNotReceived; |
115 status_vector[i] == | |
116 webrtc::rtcp::TransportFeedback::StatusSymbol::kNotReceived; | |
117 const PacketStatus packet_status = | 112 const PacketStatus packet_status = |
118 lost ? PacketStatus::Lost : PacketStatus::Received; | 113 lost ? PacketStatus::Lost : PacketStatus::Received; |
119 | 114 |
120 UpdatePacketStatus(it, packet_status); | 115 UpdatePacketStatus(it, packet_status); |
121 } | 116 } |
122 } | 117 } |
123 | 118 |
124 rtc::Optional<float> | 119 rtc::Optional<float> |
125 TransportFeedbackPacketLossTracker::GetPacketLossRate() const { | 120 TransportFeedbackPacketLossTracker::GetPacketLossRate() const { |
126 return plr_state_.GetMetric(); | 121 return plr_state_.GetMetric(); |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
364 TransportFeedbackPacketLossTracker::RplrState::GetMetric() const { | 359 TransportFeedbackPacketLossTracker::RplrState::GetMetric() const { |
365 if (num_acked_pairs_ < min_num_acked_pairs_) { | 360 if (num_acked_pairs_ < min_num_acked_pairs_) { |
366 return rtc::Optional<float>(); | 361 return rtc::Optional<float>(); |
367 } else { | 362 } else { |
368 return rtc::Optional<float>( | 363 return rtc::Optional<float>( |
369 static_cast<float>(num_recoverable_losses_) / num_acked_pairs_); | 364 static_cast<float>(num_recoverable_losses_) / num_acked_pairs_); |
370 } | 365 } |
371 } | 366 } |
372 | 367 |
373 } // namespace webrtc | 368 } // namespace webrtc |
OLD | NEW |