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 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 } | 382 } |
383 while (!packets_->Empty()) { | 383 while (!packets_->Empty()) { |
384 if (media_budget_->bytes_remaining() == 0 && !prober_->IsProbing()) | 384 if (media_budget_->bytes_remaining() == 0 && !prober_->IsProbing()) |
385 return 0; | 385 return 0; |
386 | 386 |
387 // Since we need to release the lock in order to send, we first pop the | 387 // Since we need to release the lock in order to send, we first pop the |
388 // element from the priority queue but keep it in storage, so that we can | 388 // element from the priority queue but keep it in storage, so that we can |
389 // reinsert it if send fails. | 389 // reinsert it if send fails. |
390 const paced_sender::Packet& packet = packets_->BeginPop(); | 390 const paced_sender::Packet& packet = packets_->BeginPop(); |
391 | 391 |
392 // TODO(holmer): Because of this bug issue 5307 we have to send audio | 392 if (SendPacket(packet)) { |
393 // packets even when the pacer is paused. Here we assume audio packets are | |
394 // always high priority and that they are the only high priority packets. | |
395 if ((!paused_ || packet.priority == kHighPriority) && SendPacket(packet)) { | |
396 // Send succeeded, remove it from the queue. | 393 // Send succeeded, remove it from the queue. |
397 packets_->FinalizePop(packet); | 394 packets_->FinalizePop(packet); |
398 if (prober_->IsProbing()) | 395 if (prober_->IsProbing()) |
399 return 0; | 396 return 0; |
400 } else { | 397 } else { |
401 // Send failed, put it back into the queue. | 398 // Send failed, put it back into the queue. |
402 packets_->CancelPop(packet); | 399 packets_->CancelPop(packet); |
403 return 0; | 400 return 0; |
404 } | 401 } |
405 } | 402 } |
406 | 403 |
407 // TODO(holmer): Remove the paused_ check when issue 5307 has been fixed. | 404 // TODO(holmer): Remove the paused_ check when issue 5307 has been fixed. |
408 if (paused_ || !packets_->Empty()) | 405 if (paused_ || !packets_->Empty()) |
409 return 0; | 406 return 0; |
410 | 407 |
411 size_t padding_needed; | 408 size_t padding_needed; |
412 if (prober_->IsProbing()) { | 409 if (prober_->IsProbing()) { |
413 padding_needed = prober_->RecommendedPacketSize(); | 410 padding_needed = prober_->RecommendedPacketSize(); |
414 } else { | 411 } else { |
415 padding_needed = padding_budget_->bytes_remaining(); | 412 padding_needed = padding_budget_->bytes_remaining(); |
416 } | 413 } |
417 | 414 |
418 if (padding_needed > 0) | 415 if (padding_needed > 0) |
419 SendPadding(static_cast<size_t>(padding_needed)); | 416 SendPadding(static_cast<size_t>(padding_needed)); |
420 return 0; | 417 return 0; |
421 } | 418 } |
422 | 419 |
423 bool PacedSender::SendPacket(const paced_sender::Packet& packet) { | 420 bool PacedSender::SendPacket(const paced_sender::Packet& packet) { |
| 421 // TODO(holmer): Because of this bug issue 5307 we have to send audio |
| 422 // packets even when the pacer is paused. Here we assume audio packets are |
| 423 // always high priority and that they are the only high priority packets. |
| 424 if (paused_ && packet.priority != kHighPriority) |
| 425 return false; |
424 critsect_->Leave(); | 426 critsect_->Leave(); |
425 const bool success = callback_->TimeToSendPacket(packet.ssrc, | 427 const bool success = callback_->TimeToSendPacket(packet.ssrc, |
426 packet.sequence_number, | 428 packet.sequence_number, |
427 packet.capture_time_ms, | 429 packet.capture_time_ms, |
428 packet.retransmission); | 430 packet.retransmission); |
429 critsect_->Enter(); | 431 critsect_->Enter(); |
430 | 432 |
431 if (success) { | 433 // TODO(holmer): High priority packets should only be accounted for if we are |
| 434 // allocating bandwidth for audio. |
| 435 if (success && packet.priority != kHighPriority) { |
432 // Update media bytes sent. | 436 // Update media bytes sent. |
433 prober_->PacketSent(clock_->TimeInMilliseconds(), packet.bytes); | 437 prober_->PacketSent(clock_->TimeInMilliseconds(), packet.bytes); |
434 media_budget_->UseBudget(packet.bytes); | 438 media_budget_->UseBudget(packet.bytes); |
435 padding_budget_->UseBudget(packet.bytes); | 439 padding_budget_->UseBudget(packet.bytes); |
436 } | 440 } |
437 | 441 |
438 return success; | 442 return success; |
439 } | 443 } |
440 | 444 |
441 void PacedSender::SendPadding(size_t padding_needed) { | 445 void PacedSender::SendPadding(size_t padding_needed) { |
442 critsect_->Leave(); | 446 critsect_->Leave(); |
443 size_t bytes_sent = callback_->TimeToSendPadding(padding_needed); | 447 size_t bytes_sent = callback_->TimeToSendPadding(padding_needed); |
444 critsect_->Enter(); | 448 critsect_->Enter(); |
445 | 449 |
446 if (bytes_sent > 0) { | 450 if (bytes_sent > 0) { |
447 prober_->PacketSent(clock_->TimeInMilliseconds(), bytes_sent); | 451 prober_->PacketSent(clock_->TimeInMilliseconds(), bytes_sent); |
448 media_budget_->UseBudget(bytes_sent); | 452 media_budget_->UseBudget(bytes_sent); |
449 padding_budget_->UseBudget(bytes_sent); | 453 padding_budget_->UseBudget(bytes_sent); |
450 } | 454 } |
451 } | 455 } |
452 | 456 |
453 void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) { | 457 void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) { |
454 media_budget_->IncreaseBudget(delta_time_ms); | 458 media_budget_->IncreaseBudget(delta_time_ms); |
455 padding_budget_->IncreaseBudget(delta_time_ms); | 459 padding_budget_->IncreaseBudget(delta_time_ms); |
456 } | 460 } |
457 } // namespace webrtc | 461 } // namespace webrtc |
OLD | NEW |