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 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 target_bitrate_kbps = min_bitrate_needed_kbps; | 395 target_bitrate_kbps = min_bitrate_needed_kbps; |
396 } | 396 } |
397 | 397 |
398 media_budget_->set_target_rate_kbps(target_bitrate_kbps); | 398 media_budget_->set_target_rate_kbps(target_bitrate_kbps); |
399 | 399 |
400 int64_t delta_time_ms = std::min(kMaxIntervalTimeMs, elapsed_time_ms); | 400 int64_t delta_time_ms = std::min(kMaxIntervalTimeMs, elapsed_time_ms); |
401 UpdateBytesPerInterval(delta_time_ms); | 401 UpdateBytesPerInterval(delta_time_ms); |
402 } | 402 } |
403 | 403 |
404 bool is_probing = prober_->IsProbing(); | 404 bool is_probing = prober_->IsProbing(); |
405 int probe_cluster_id = is_probing ? prober_->CurrentClusterId() | 405 int probe_cluster_id = PacketInfo::kNotAProbe; |
406 : PacketInfo::kNotAProbe; | 406 size_t bytes_sent = 0; |
| 407 size_t recommended_probe_size = 0; |
| 408 if (is_probing) { |
| 409 probe_cluster_id = prober_->CurrentClusterId(); |
| 410 recommended_probe_size = prober_->RecommendedMinProbeSize(); |
| 411 } |
407 while (!packets_->Empty()) { | 412 while (!packets_->Empty()) { |
408 // Since we need to release the lock in order to send, we first pop the | 413 // Since we need to release the lock in order to send, we first pop the |
409 // element from the priority queue but keep it in storage, so that we can | 414 // element from the priority queue but keep it in storage, so that we can |
410 // reinsert it if send fails. | 415 // reinsert it if send fails. |
411 const paced_sender::Packet& packet = packets_->BeginPop(); | 416 const paced_sender::Packet& packet = packets_->BeginPop(); |
412 | 417 |
413 if (SendPacket(packet, probe_cluster_id)) { | 418 if (SendPacket(packet, probe_cluster_id)) { |
414 // Send succeeded, remove it from the queue. | 419 // Send succeeded, remove it from the queue. |
| 420 bytes_sent += packet.bytes; |
415 packets_->FinalizePop(packet); | 421 packets_->FinalizePop(packet); |
416 if (is_probing) | 422 if (is_probing && bytes_sent > recommended_probe_size) |
417 return; | 423 break; |
418 } else { | 424 } else { |
419 // Send failed, put it back into the queue. | 425 // Send failed, put it back into the queue. |
420 packets_->CancelPop(packet); | 426 packets_->CancelPop(packet); |
421 return; | 427 break; |
422 } | 428 } |
423 } | 429 } |
424 | 430 |
425 RTC_DCHECK(packets_->Empty()); | |
426 // TODO(holmer): Remove the paused_ check when issue 5307 has been fixed. | 431 // TODO(holmer): Remove the paused_ check when issue 5307 has been fixed. |
427 if (paused_) | 432 if (packets_->Empty() && !paused_) { |
428 return; | 433 // We can not send padding unless a normal packet has first been sent. If we |
| 434 // do, timestamps get messed up. |
| 435 if (packet_counter_ > 0) { |
| 436 int padding_needed = |
| 437 static_cast<int>(is_probing ? (recommended_probe_size - bytes_sent) |
| 438 : padding_budget_->bytes_remaining()); |
429 | 439 |
430 // We can not send padding unless a normal packet has first been sent. If we | 440 if (padding_needed > 0) |
431 // do, timestamps get messed up. | 441 bytes_sent += SendPadding(padding_needed, probe_cluster_id); |
432 if (packet_counter_ > 0) { | 442 } |
433 size_t padding_needed = is_probing ? prober_->RecommendedPacketSize() | |
434 : padding_budget_->bytes_remaining(); | |
435 | |
436 if (padding_needed > 0) | |
437 SendPadding(padding_needed, probe_cluster_id); | |
438 } | 443 } |
| 444 if (is_probing && bytes_sent > 0) |
| 445 prober_->ProbeSent(clock_->TimeInMilliseconds(), bytes_sent); |
439 } | 446 } |
440 | 447 |
441 bool PacedSender::SendPacket(const paced_sender::Packet& packet, | 448 bool PacedSender::SendPacket(const paced_sender::Packet& packet, |
442 int probe_cluster_id) { | 449 int probe_cluster_id) { |
443 // TODO(holmer): Because of this bug issue 5307 we have to send audio | 450 // TODO(holmer): Because of this bug issue 5307 we have to send audio |
444 // packets even when the pacer is paused. Here we assume audio packets are | 451 // packets even when the pacer is paused. Here we assume audio packets are |
445 // always high priority and that they are the only high priority packets. | 452 // always high priority and that they are the only high priority packets. |
446 if (packet.priority != kHighPriority) { | 453 if (packet.priority != kHighPriority) { |
447 if (paused_) | 454 if (paused_) |
448 return false; | 455 return false; |
449 if (media_budget_->bytes_remaining() == 0 && | 456 if (media_budget_->bytes_remaining() == 0 && |
450 probe_cluster_id == PacketInfo::kNotAProbe) { | 457 probe_cluster_id == PacketInfo::kNotAProbe) { |
451 return false; | 458 return false; |
452 } | 459 } |
453 } | 460 } |
454 critsect_->Leave(); | 461 critsect_->Leave(); |
455 const bool success = packet_sender_->TimeToSendPacket( | 462 const bool success = packet_sender_->TimeToSendPacket( |
456 packet.ssrc, packet.sequence_number, packet.capture_time_ms, | 463 packet.ssrc, packet.sequence_number, packet.capture_time_ms, |
457 packet.retransmission, probe_cluster_id); | 464 packet.retransmission, probe_cluster_id); |
458 critsect_->Enter(); | 465 critsect_->Enter(); |
459 | 466 |
460 if (success) { | 467 if (success) { |
461 prober_->PacketSent(clock_->TimeInMilliseconds(), packet.bytes); | |
462 // TODO(holmer): High priority packets should only be accounted for if we | 468 // TODO(holmer): High priority packets should only be accounted for if we |
463 // are allocating bandwidth for audio. | 469 // are allocating bandwidth for audio. |
464 if (packet.priority != kHighPriority) { | 470 if (packet.priority != kHighPriority) { |
465 // Update media bytes sent. | 471 // Update media bytes sent. |
466 media_budget_->UseBudget(packet.bytes); | 472 media_budget_->UseBudget(packet.bytes); |
467 padding_budget_->UseBudget(packet.bytes); | 473 padding_budget_->UseBudget(packet.bytes); |
468 } | 474 } |
469 } | 475 } |
470 | 476 |
471 return success; | 477 return success; |
472 } | 478 } |
473 | 479 |
474 void PacedSender::SendPadding(size_t padding_needed, int probe_cluster_id) { | 480 size_t PacedSender::SendPadding(size_t padding_needed, int probe_cluster_id) { |
475 critsect_->Leave(); | 481 critsect_->Leave(); |
476 size_t bytes_sent = | 482 size_t bytes_sent = |
477 packet_sender_->TimeToSendPadding(padding_needed, probe_cluster_id); | 483 packet_sender_->TimeToSendPadding(padding_needed, probe_cluster_id); |
478 critsect_->Enter(); | 484 critsect_->Enter(); |
479 | 485 |
480 if (bytes_sent > 0) { | 486 if (bytes_sent > 0) { |
481 prober_->PacketSent(clock_->TimeInMilliseconds(), bytes_sent); | |
482 media_budget_->UseBudget(bytes_sent); | 487 media_budget_->UseBudget(bytes_sent); |
483 padding_budget_->UseBudget(bytes_sent); | 488 padding_budget_->UseBudget(bytes_sent); |
484 } | 489 } |
| 490 return bytes_sent; |
485 } | 491 } |
486 | 492 |
487 void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) { | 493 void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) { |
488 media_budget_->IncreaseBudget(delta_time_ms); | 494 media_budget_->IncreaseBudget(delta_time_ms); |
489 padding_budget_->IncreaseBudget(delta_time_ms); | 495 padding_budget_->IncreaseBudget(delta_time_ms); |
490 } | 496 } |
491 } // namespace webrtc | 497 } // namespace webrtc |
OLD | NEW |