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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 ++node_it; | 150 ++node_it; |
151 ++number_packets_received; | 151 ++number_packets_received; |
152 } | 152 } |
153 // Interval width between oldest and newest sequence number. | 153 // Interval width between oldest and newest sequence number. |
154 // There was an overflow if newest_seq_nb < oldest_seq_nb. | 154 // There was an overflow if newest_seq_nb < oldest_seq_nb. |
155 int gap = static_cast<uint16_t>(newest_seq_nb - oldest_seq_nb + 1); | 155 int gap = static_cast<uint16_t>(newest_seq_nb - oldest_seq_nb + 1); |
156 | 156 |
157 return static_cast<float>(gap - number_packets_received) / gap; | 157 return static_cast<float>(gap - number_packets_received) / gap; |
158 } | 158 } |
159 | 159 |
| 160 LinkedSet::~LinkedSet() { |
| 161 while (!empty()) |
| 162 RemoveTail(); |
| 163 } |
| 164 |
160 void LinkedSet::Insert(uint16_t sequence_number, | 165 void LinkedSet::Insert(uint16_t sequence_number, |
161 int64_t send_time_ms, | 166 int64_t send_time_ms, |
162 int64_t arrival_time_ms, | 167 int64_t arrival_time_ms, |
163 size_t payload_size) { | 168 size_t payload_size) { |
164 std::map<uint16_t, PacketNodeIt>::iterator it = map_.find(sequence_number); | 169 std::map<uint16_t, PacketNodeIt>::iterator it = map_.find(sequence_number); |
165 if (it != map_.end()) { | 170 if (it != map_.end()) { |
166 PacketNodeIt node_it = it->second; | 171 PacketNodeIt node_it = it->second; |
167 PacketIdentifierNode* node = *node_it; | 172 PacketIdentifierNode* node = *node_it; |
168 node->arrival_time_ms = arrival_time_ms; | 173 node->arrival_time_ms = arrival_time_ms; |
169 if (node_it != list_.begin()) { | 174 if (node_it != list_.begin()) { |
170 list_.erase(node_it); | 175 list_.erase(node_it); |
171 list_.push_front(node); | 176 list_.push_front(node); |
172 map_[sequence_number] = list_.begin(); | 177 map_[sequence_number] = list_.begin(); |
173 } | 178 } |
174 } else { | 179 } else { |
175 if (size() == capacity_) { | 180 if (size() == capacity_) { |
176 RemoveTail(); | 181 RemoveTail(); |
177 } | 182 } |
178 UpdateHead(new PacketIdentifierNode(sequence_number, send_time_ms, | 183 UpdateHead(new PacketIdentifierNode(sequence_number, send_time_ms, |
179 arrival_time_ms, payload_size)); | 184 arrival_time_ms, payload_size)); |
180 } | 185 } |
181 } | 186 } |
182 void LinkedSet::RemoveTail() { | 187 void LinkedSet::RemoveTail() { |
183 map_.erase(list_.back()->sequence_number); | 188 map_.erase(list_.back()->sequence_number); |
| 189 delete list_.back(); |
184 list_.pop_back(); | 190 list_.pop_back(); |
185 } | 191 } |
186 void LinkedSet::UpdateHead(PacketIdentifierNode* new_head) { | 192 void LinkedSet::UpdateHead(PacketIdentifierNode* new_head) { |
187 list_.push_front(new_head); | 193 list_.push_front(new_head); |
188 map_[new_head->sequence_number] = list_.begin(); | 194 map_[new_head->sequence_number] = list_.begin(); |
189 } | 195 } |
190 | 196 |
191 } // namespace bwe | 197 } // namespace bwe |
192 } // namespace testing | 198 } // namespace testing |
193 } // namespace webrtc | 199 } // namespace webrtc |
OLD | NEW |