OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 stored_packets_[index].send_time = clock_->TimeInMilliseconds(); | 155 stored_packets_[index].send_time = clock_->TimeInMilliseconds(); |
156 return GetPacket(index); | 156 return GetPacket(index); |
157 } | 157 } |
158 | 158 |
159 std::unique_ptr<RtpPacketToSend> RtpPacketHistory::GetPacket(int index) const { | 159 std::unique_ptr<RtpPacketToSend> RtpPacketHistory::GetPacket(int index) const { |
160 const RtpPacketToSend& stored = *stored_packets_[index].packet; | 160 const RtpPacketToSend& stored = *stored_packets_[index].packet; |
161 return std::unique_ptr<RtpPacketToSend>(new RtpPacketToSend(stored)); | 161 return std::unique_ptr<RtpPacketToSend>(new RtpPacketToSend(stored)); |
162 } | 162 } |
163 | 163 |
164 std::unique_ptr<RtpPacketToSend> RtpPacketHistory::GetBestFittingPacket( | 164 std::unique_ptr<RtpPacketToSend> RtpPacketHistory::GetBestFittingPacket( |
165 size_t packet_length) const { | 165 size_t packet_length, |
| 166 bool include_header) const { |
166 rtc::CritScope cs(&critsect_); | 167 rtc::CritScope cs(&critsect_); |
167 if (!store_) | 168 if (!store_) |
168 return nullptr; | 169 return nullptr; |
169 int index = FindBestFittingPacket(packet_length); | 170 int index = FindBestFittingPacket(packet_length, include_header); |
170 if (index < 0) | 171 if (index < 0) |
171 return nullptr; | 172 return nullptr; |
172 return GetPacket(index); | 173 return GetPacket(index); |
173 } | 174 } |
174 | 175 |
175 bool RtpPacketHistory::FindSeqNum(uint16_t sequence_number, int* index) const { | 176 bool RtpPacketHistory::FindSeqNum(uint16_t sequence_number, int* index) const { |
176 if (prev_index_ > 0) { | 177 if (prev_index_ > 0) { |
177 *index = prev_index_ - 1; | 178 *index = prev_index_ - 1; |
178 } else { | 179 } else { |
179 *index = stored_packets_.size() - 1; // Wrap. | 180 *index = stored_packets_.size() - 1; // Wrap. |
(...skipping 13 matching lines...) Expand all Loading... |
193 *index = m; | 194 *index = m; |
194 temp_sequence_number = stored_packets_[*index].sequence_number; | 195 temp_sequence_number = stored_packets_[*index].sequence_number; |
195 break; | 196 break; |
196 } | 197 } |
197 } | 198 } |
198 } | 199 } |
199 return temp_sequence_number == sequence_number && | 200 return temp_sequence_number == sequence_number && |
200 stored_packets_[*index].packet; | 201 stored_packets_[*index].packet; |
201 } | 202 } |
202 | 203 |
203 int RtpPacketHistory::FindBestFittingPacket(size_t size) const { | 204 int RtpPacketHistory::FindBestFittingPacket(size_t size, |
| 205 bool include_header) const { |
204 if (size < kMinPacketRequestBytes || stored_packets_.empty()) | 206 if (size < kMinPacketRequestBytes || stored_packets_.empty()) |
205 return -1; | 207 return -1; |
206 size_t min_diff = std::numeric_limits<size_t>::max(); | 208 size_t min_diff = std::numeric_limits<size_t>::max(); |
207 int best_index = -1; // Returned unchanged if we don't find anything. | 209 int best_index = -1; // Returned unchanged if we don't find anything. |
208 for (size_t i = 0; i < stored_packets_.size(); ++i) { | 210 for (size_t i = 0; i < stored_packets_.size(); ++i) { |
209 if (!stored_packets_[i].packet) | 211 if (!stored_packets_[i].packet) |
210 continue; | 212 continue; |
211 size_t stored_size = stored_packets_[i].packet->size(); | 213 size_t stored_size = include_header |
| 214 ? stored_packets_[i].packet->size() |
| 215 : stored_packets_[i].packet->size() - |
| 216 stored_packets_[i].packet->headers_size(); |
212 size_t diff = | 217 size_t diff = |
213 (stored_size > size) ? (stored_size - size) : (size - stored_size); | 218 (stored_size > size) ? (stored_size - size) : (size - stored_size); |
214 if (diff < min_diff) { | 219 if (diff < min_diff) { |
215 min_diff = diff; | 220 min_diff = diff; |
216 best_index = static_cast<int>(i); | 221 best_index = static_cast<int>(i); |
217 } | 222 } |
218 } | 223 } |
219 return best_index; | 224 return best_index; |
220 } | 225 } |
221 | 226 |
222 } // namespace webrtc | 227 } // namespace webrtc |
OLD | NEW |