| 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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 return kNotFound; | 171 return kNotFound; |
| 172 } | 172 } |
| 173 | 173 |
| 174 const RTPHeader* PacketBuffer::NextRtpHeader() const { | 174 const RTPHeader* PacketBuffer::NextRtpHeader() const { |
| 175 if (Empty()) { | 175 if (Empty()) { |
| 176 return NULL; | 176 return NULL; |
| 177 } | 177 } |
| 178 return const_cast<const RTPHeader*>(&(buffer_.front()->header)); | 178 return const_cast<const RTPHeader*>(&(buffer_.front()->header)); |
| 179 } | 179 } |
| 180 | 180 |
| 181 Packet* PacketBuffer::GetNextPacket(int* discard_count) { | 181 Packet* PacketBuffer::GetNextPacket(size_t* discard_count) { |
| 182 if (Empty()) { | 182 if (Empty()) { |
| 183 // Buffer is empty. | 183 // Buffer is empty. |
| 184 return NULL; | 184 return NULL; |
| 185 } | 185 } |
| 186 | 186 |
| 187 Packet* packet = buffer_.front(); | 187 Packet* packet = buffer_.front(); |
| 188 // Assert that the packet sanity checks in InsertPacket method works. | 188 // Assert that the packet sanity checks in InsertPacket method works. |
| 189 assert(packet && packet->payload); | 189 assert(packet && packet->payload); |
| 190 buffer_.pop_front(); | 190 buffer_.pop_front(); |
| 191 | 191 |
| 192 // Discard other packets with the same timestamp. These are duplicates or | 192 // Discard other packets with the same timestamp. These are duplicates or |
| 193 // redundant payloads that should not be used. | 193 // redundant payloads that should not be used. |
| 194 int discards = 0; | 194 size_t discards = 0; |
| 195 | 195 |
| 196 while (!Empty() && | 196 while (!Empty() && |
| 197 buffer_.front()->header.timestamp == packet->header.timestamp) { | 197 buffer_.front()->header.timestamp == packet->header.timestamp) { |
| 198 if (DiscardNextPacket() != kOK) { | 198 if (DiscardNextPacket() != kOK) { |
| 199 assert(false); // Must be ok by design. | 199 assert(false); // Must be ok by design. |
| 200 } | 200 } |
| 201 ++discards; | 201 ++discards; |
| 202 } | 202 } |
| 203 // The way of inserting packet should not cause any packet discarding here. | 203 // The way of inserting packet should not cause any packet discarding here. |
| 204 // TODO(minyue): remove |discard_count|. | 204 // TODO(minyue): remove |discard_count|. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 230 assert(false); // Must be ok by design. | 230 assert(false); // Must be ok by design. |
| 231 } | 231 } |
| 232 } | 232 } |
| 233 return 0; | 233 return 0; |
| 234 } | 234 } |
| 235 | 235 |
| 236 int PacketBuffer::DiscardAllOldPackets(uint32_t timestamp_limit) { | 236 int PacketBuffer::DiscardAllOldPackets(uint32_t timestamp_limit) { |
| 237 return DiscardOldPackets(timestamp_limit, 0); | 237 return DiscardOldPackets(timestamp_limit, 0); |
| 238 } | 238 } |
| 239 | 239 |
| 240 int PacketBuffer::NumPacketsInBuffer() const { | 240 size_t PacketBuffer::NumPacketsInBuffer() const { |
| 241 return static_cast<int>(buffer_.size()); | 241 return buffer_.size(); |
| 242 } | 242 } |
| 243 | 243 |
| 244 int PacketBuffer::NumSamplesInBuffer(DecoderDatabase* decoder_database, | 244 size_t PacketBuffer::NumSamplesInBuffer(DecoderDatabase* decoder_database, |
| 245 int last_decoded_length) const { | 245 size_t last_decoded_length) const { |
| 246 PacketList::const_iterator it; | 246 PacketList::const_iterator it; |
| 247 int num_samples = 0; | 247 size_t num_samples = 0; |
| 248 int last_duration = last_decoded_length; | 248 size_t last_duration = last_decoded_length; |
| 249 for (it = buffer_.begin(); it != buffer_.end(); ++it) { | 249 for (it = buffer_.begin(); it != buffer_.end(); ++it) { |
| 250 Packet* packet = (*it); | 250 Packet* packet = (*it); |
| 251 AudioDecoder* decoder = | 251 AudioDecoder* decoder = |
| 252 decoder_database->GetDecoder(packet->header.payloadType); | 252 decoder_database->GetDecoder(packet->header.payloadType); |
| 253 if (decoder && !packet->sync_packet) { | 253 if (decoder && !packet->sync_packet) { |
| 254 if (!packet->primary) { | 254 if (!packet->primary) { |
| 255 continue; | 255 continue; |
| 256 } | 256 } |
| 257 int duration = | 257 int duration = |
| 258 decoder->PacketDuration(packet->payload, packet->payload_length); | 258 decoder->PacketDuration(packet->payload, packet->payload_length); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 288 // Continue while the list is not empty. | 288 // Continue while the list is not empty. |
| 289 } | 289 } |
| 290 } | 290 } |
| 291 | 291 |
| 292 void PacketBuffer::BufferStat(int* num_packets, int* max_num_packets) const { | 292 void PacketBuffer::BufferStat(int* num_packets, int* max_num_packets) const { |
| 293 *num_packets = static_cast<int>(buffer_.size()); | 293 *num_packets = static_cast<int>(buffer_.size()); |
| 294 *max_num_packets = static_cast<int>(max_number_of_packets_); | 294 *max_num_packets = static_cast<int>(max_number_of_packets_); |
| 295 } | 295 } |
| 296 | 296 |
| 297 } // namespace webrtc | 297 } // namespace webrtc |
| OLD | NEW |