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