OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 } else { | 84 } else { |
85 more_to_build = false; | 85 more_to_build = false; |
86 } | 86 } |
87 } | 87 } |
88 } | 88 } |
89 | 89 |
90 void RemoteEstimatorProxy::OnPacketArrival(uint16_t sequence_number, | 90 void RemoteEstimatorProxy::OnPacketArrival(uint16_t sequence_number, |
91 int64_t arrival_time) { | 91 int64_t arrival_time) { |
92 int64_t seq = unwrapper_.Unwrap(sequence_number); | 92 int64_t seq = unwrapper_.Unwrap(sequence_number); |
93 | 93 |
94 if (window_start_seq_ == -1) { | 94 if (packet_arrival_times_.lower_bound(window_start_seq_) == |
95 window_start_seq_ = seq; | 95 packet_arrival_times_.end()) { |
96 // Start new feedback packet, cull old packets. | 96 // Start new feedback packet, cull old packets. |
97 for (auto it = packet_arrival_times_.begin(); | 97 for (auto it = packet_arrival_times_.begin(); |
98 it != packet_arrival_times_.end() && it->first < seq && | 98 it != packet_arrival_times_.end() && it->first < seq && |
99 arrival_time - it->second >= kBackWindowMs;) { | 99 arrival_time - it->second >= kBackWindowMs;) { |
100 auto delete_it = it; | 100 auto delete_it = it; |
101 ++it; | 101 ++it; |
102 packet_arrival_times_.erase(delete_it); | 102 packet_arrival_times_.erase(delete_it); |
103 } | 103 } |
| 104 } |
| 105 |
| 106 if (window_start_seq_ == -1) { |
| 107 window_start_seq_ = sequence_number; |
104 } else if (seq < window_start_seq_) { | 108 } else if (seq < window_start_seq_) { |
105 window_start_seq_ = seq; | 109 window_start_seq_ = seq; |
106 } | 110 } |
107 | 111 |
108 // We are only interested in the first time a packet is received. | 112 // We are only interested in the first time a packet is received. |
109 if (packet_arrival_times_.find(seq) != packet_arrival_times_.end()) | 113 if (packet_arrival_times_.find(seq) != packet_arrival_times_.end()) |
110 return; | 114 return; |
111 | 115 |
112 packet_arrival_times_[seq] = arrival_time; | 116 packet_arrival_times_[seq] = arrival_time; |
113 } | 117 } |
114 | 118 |
115 bool RemoteEstimatorProxy::BuildFeedbackPacket( | 119 bool RemoteEstimatorProxy::BuildFeedbackPacket( |
116 rtcp::TransportFeedback* feedback_packet) { | 120 rtcp::TransportFeedback* feedback_packet) { |
117 rtc::CritScope cs(&lock_); | |
118 if (window_start_seq_ == -1) | |
119 return false; | |
120 | |
121 // window_start_seq_ is the first sequence number to include in the current | 121 // window_start_seq_ is the first sequence number to include in the current |
122 // feedback packet. Some older may still be in the map, in case a reordering | 122 // feedback packet. Some older may still be in the map, in case a reordering |
123 // happens and we need to retransmit them. | 123 // happens and we need to retransmit them. |
124 auto it = packet_arrival_times_.find(window_start_seq_); | 124 rtc::CritScope cs(&lock_); |
125 RTC_DCHECK(it != packet_arrival_times_.end()); | 125 auto it = packet_arrival_times_.lower_bound(window_start_seq_); |
| 126 if (it == packet_arrival_times_.end()) { |
| 127 // Feedback for all packets already sent. |
| 128 return false; |
| 129 } |
126 | 130 |
127 // TODO(sprang): Measure receive times in microseconds and remove the | 131 // TODO(sprang): Measure receive times in microseconds and remove the |
128 // conversions below. | 132 // conversions below. |
| 133 const int64_t first_sequence = it->first; |
129 feedback_packet->WithMediaSourceSsrc(media_ssrc_); | 134 feedback_packet->WithMediaSourceSsrc(media_ssrc_); |
130 feedback_packet->WithBase(static_cast<uint16_t>(it->first & 0xFFFF), | 135 // Base sequence is the expected next (window_start_seq_). This is known, but |
| 136 // we might not have actually received it, so the base time shall be the time |
| 137 // of the first received packet in the feedback. |
| 138 feedback_packet->WithBase(static_cast<uint16_t>(window_start_seq_ & 0xFFFF), |
131 it->second * 1000); | 139 it->second * 1000); |
132 feedback_packet->WithFeedbackSequenceNumber(feedback_sequence_++); | 140 feedback_packet->WithFeedbackSequenceNumber(feedback_sequence_++); |
133 for (; it != packet_arrival_times_.end(); ++it) { | 141 for (; it != packet_arrival_times_.end(); ++it) { |
134 if (!feedback_packet->WithReceivedPacket( | 142 if (!feedback_packet->WithReceivedPacket( |
135 static_cast<uint16_t>(it->first & 0xFFFF), it->second * 1000)) { | 143 static_cast<uint16_t>(it->first & 0xFFFF), it->second * 1000)) { |
136 // If we can't even add the first seq to the feedback packet, we won't be | 144 // If we can't even add the first seq to the feedback packet, we won't be |
137 // able to build it at all. | 145 // able to build it at all. |
138 RTC_CHECK_NE(window_start_seq_, it->first); | 146 RTC_CHECK_NE(first_sequence, it->first); |
139 | 147 |
140 // Could not add timestamp, feedback packet might be full. Return and | 148 // Could not add timestamp, feedback packet might be full. Return and |
141 // try again with a fresh packet. | 149 // try again with a fresh packet. |
142 window_start_seq_ = it->first; | |
143 break; | 150 break; |
144 } | 151 } |
| 152 |
145 // Note: Don't erase items from packet_arrival_times_ after sending, in case | 153 // Note: Don't erase items from packet_arrival_times_ after sending, in case |
146 // they need to be re-sent after a reordering. Removal will be handled | 154 // they need to be re-sent after a reordering. Removal will be handled |
147 // by OnPacketArrival once packets are too old. | 155 // by OnPacketArrival once packets are too old. |
| 156 window_start_seq_ = it->first + 1; |
148 } | 157 } |
149 if (it == packet_arrival_times_.end()) | |
150 window_start_seq_ = -1; | |
151 | 158 |
152 return true; | 159 return true; |
153 } | 160 } |
154 | 161 |
155 } // namespace webrtc | 162 } // namespace webrtc |
OLD | NEW |