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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 | 69 |
70 int PacketBuffer::InsertPacket(Packet* packet) { | 70 int PacketBuffer::InsertPacket(Packet* packet) { |
71 if (!packet || packet->empty()) { | 71 if (!packet || packet->empty()) { |
72 if (packet) { | 72 if (packet) { |
73 delete packet; | 73 delete packet; |
74 } | 74 } |
75 LOG(LS_WARNING) << "InsertPacket invalid packet"; | 75 LOG(LS_WARNING) << "InsertPacket invalid packet"; |
76 return kInvalidPacket; | 76 return kInvalidPacket; |
77 } | 77 } |
78 | 78 |
| 79 RTC_DCHECK_GE(packet->priority.codec_level, 0); |
| 80 RTC_DCHECK_GE(packet->priority.red_level, 0); |
| 81 |
79 int return_val = kOK; | 82 int return_val = kOK; |
80 | 83 |
81 packet->waiting_time = tick_timer_->GetNewStopwatch(); | 84 packet->waiting_time = tick_timer_->GetNewStopwatch(); |
82 | 85 |
83 if (buffer_.size() >= max_number_of_packets_) { | 86 if (buffer_.size() >= max_number_of_packets_) { |
84 // Buffer is full. Flush it. | 87 // Buffer is full. Flush it. |
85 Flush(); | 88 Flush(); |
86 LOG(LS_WARNING) << "Packet buffer flushed"; | 89 LOG(LS_WARNING) << "Packet buffer flushed"; |
87 return_val = kFlushed; | 90 return_val = kFlushed; |
88 } | 91 } |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 } | 258 } |
256 return 0; | 259 return 0; |
257 } | 260 } |
258 | 261 |
259 int PacketBuffer::DiscardAllOldPackets(uint32_t timestamp_limit) { | 262 int PacketBuffer::DiscardAllOldPackets(uint32_t timestamp_limit) { |
260 return DiscardOldPackets(timestamp_limit, 0); | 263 return DiscardOldPackets(timestamp_limit, 0); |
261 } | 264 } |
262 | 265 |
263 void PacketBuffer::DiscardPacketsWithPayloadType(uint8_t payload_type) { | 266 void PacketBuffer::DiscardPacketsWithPayloadType(uint8_t payload_type) { |
264 for (auto it = buffer_.begin(); it != buffer_.end(); /* */) { | 267 for (auto it = buffer_.begin(); it != buffer_.end(); /* */) { |
265 Packet *packet = *it; | 268 Packet* packet = *it; |
266 if (packet->header.payloadType == payload_type) { | 269 if (packet->header.payloadType == payload_type) { |
267 delete packet; | 270 delete packet; |
268 it = buffer_.erase(it); | 271 it = buffer_.erase(it); |
269 } else { | 272 } else { |
270 ++it; | 273 ++it; |
271 } | 274 } |
272 } | 275 } |
273 } | 276 } |
274 | 277 |
275 size_t PacketBuffer::NumPacketsInBuffer() const { | 278 size_t PacketBuffer::NumPacketsInBuffer() const { |
276 return buffer_.size(); | 279 return buffer_.size(); |
277 } | 280 } |
278 | 281 |
279 size_t PacketBuffer::NumSamplesInBuffer(size_t last_decoded_length) const { | 282 size_t PacketBuffer::NumSamplesInBuffer(size_t last_decoded_length) const { |
280 size_t num_samples = 0; | 283 size_t num_samples = 0; |
281 size_t last_duration = last_decoded_length; | 284 size_t last_duration = last_decoded_length; |
282 for (Packet* packet : buffer_) { | 285 for (Packet* packet : buffer_) { |
283 if (packet->frame) { | 286 if (packet->frame) { |
284 if (!packet->primary) { | 287 // TODO(hlundin): Verify that it's fine to count all packets and remove |
| 288 // this check. |
| 289 if (packet->priority != Packet::Priority(0, 0)) { |
285 continue; | 290 continue; |
286 } | 291 } |
287 size_t duration = packet->frame->Duration(); | 292 size_t duration = packet->frame->Duration(); |
288 if (duration > 0) { | 293 if (duration > 0) { |
289 last_duration = duration; // Save the most up-to-date (valid) duration. | 294 last_duration = duration; // Save the most up-to-date (valid) duration. |
290 } | 295 } |
291 } | 296 } |
292 num_samples += last_duration; | 297 num_samples += last_duration; |
293 } | 298 } |
294 return num_samples; | 299 return num_samples; |
(...skipping 14 matching lines...) Expand all Loading... |
309 // Continue while the list is not empty. | 314 // Continue while the list is not empty. |
310 } | 315 } |
311 } | 316 } |
312 | 317 |
313 void PacketBuffer::BufferStat(int* num_packets, int* max_num_packets) const { | 318 void PacketBuffer::BufferStat(int* num_packets, int* max_num_packets) const { |
314 *num_packets = static_cast<int>(buffer_.size()); | 319 *num_packets = static_cast<int>(buffer_.size()); |
315 *max_num_packets = static_cast<int>(max_number_of_packets_); | 320 *max_num_packets = static_cast<int>(max_number_of_packets_); |
316 } | 321 } |
317 | 322 |
318 } // namespace webrtc | 323 } // namespace webrtc |
OLD | NEW |