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 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 int64_t elapsed_time_ms = (elapsed_time_us + 500) / 1000; | 381 int64_t elapsed_time_ms = (elapsed_time_us + 500) / 1000; |
382 return std::max<int64_t>(kMinPacketLimitMs - elapsed_time_ms, 0); | 382 return std::max<int64_t>(kMinPacketLimitMs - elapsed_time_ms, 0); |
383 } | 383 } |
384 | 384 |
385 void PacedSender::Process() { | 385 void PacedSender::Process() { |
386 int64_t now_us = clock_->TimeInMicroseconds(); | 386 int64_t now_us = clock_->TimeInMicroseconds(); |
387 CriticalSectionScoped cs(critsect_.get()); | 387 CriticalSectionScoped cs(critsect_.get()); |
388 int64_t elapsed_time_ms = (now_us - time_last_update_us_ + 500) / 1000; | 388 int64_t elapsed_time_ms = (now_us - time_last_update_us_ + 500) / 1000; |
389 time_last_update_us_ = now_us; | 389 time_last_update_us_ = now_us; |
390 int target_bitrate_kbps = pacing_bitrate_kbps_; | 390 int target_bitrate_kbps = pacing_bitrate_kbps_; |
391 // TODO(holmer): Remove the !paused_ check when issue 5307 has been fixed. | |
392 if (!paused_ && elapsed_time_ms > 0) { | 391 if (!paused_ && elapsed_time_ms > 0) { |
393 size_t queue_size_bytes = packets_->SizeInBytes(); | 392 size_t queue_size_bytes = packets_->SizeInBytes(); |
394 if (queue_size_bytes > 0) { | 393 if (queue_size_bytes > 0) { |
395 // Assuming equal size packets and input/output rate, the average packet | 394 // Assuming equal size packets and input/output rate, the average packet |
396 // has avg_time_left_ms left to get queue_size_bytes out of the queue, if | 395 // has avg_time_left_ms left to get queue_size_bytes out of the queue, if |
397 // time constraint shall be met. Determine bitrate needed for that. | 396 // time constraint shall be met. Determine bitrate needed for that. |
398 packets_->UpdateQueueTime(clock_->TimeInMilliseconds()); | 397 packets_->UpdateQueueTime(clock_->TimeInMilliseconds()); |
399 int64_t avg_time_left_ms = std::max<int64_t>( | 398 int64_t avg_time_left_ms = std::max<int64_t>( |
400 1, kMaxQueueLengthMs - packets_->AverageQueueTimeMs()); | 399 1, kMaxQueueLengthMs - packets_->AverageQueueTimeMs()); |
401 int min_bitrate_needed_kbps = | 400 int min_bitrate_needed_kbps = |
(...skipping 28 matching lines...) Expand all Loading... |
430 packets_->FinalizePop(packet); | 429 packets_->FinalizePop(packet); |
431 if (is_probing && bytes_sent > recommended_probe_size) | 430 if (is_probing && bytes_sent > recommended_probe_size) |
432 break; | 431 break; |
433 } else { | 432 } else { |
434 // Send failed, put it back into the queue. | 433 // Send failed, put it back into the queue. |
435 packets_->CancelPop(packet); | 434 packets_->CancelPop(packet); |
436 break; | 435 break; |
437 } | 436 } |
438 } | 437 } |
439 | 438 |
440 // TODO(holmer): Remove the paused_ check when issue 5307 has been fixed. | |
441 if (packets_->Empty() && !paused_) { | 439 if (packets_->Empty() && !paused_) { |
442 // We can not send padding unless a normal packet has first been sent. If we | 440 // We can not send padding unless a normal packet has first been sent. If we |
443 // do, timestamps get messed up. | 441 // do, timestamps get messed up. |
444 if (packet_counter_ > 0) { | 442 if (packet_counter_ > 0) { |
445 int padding_needed = | 443 int padding_needed = |
446 static_cast<int>(is_probing ? (recommended_probe_size - bytes_sent) | 444 static_cast<int>(is_probing ? (recommended_probe_size - bytes_sent) |
447 : padding_budget_->bytes_remaining()); | 445 : padding_budget_->bytes_remaining()); |
448 | 446 |
449 if (padding_needed > 0) | 447 if (padding_needed > 0) |
450 bytes_sent += SendPadding(padding_needed, probe_cluster_id); | 448 bytes_sent += SendPadding(padding_needed, probe_cluster_id); |
451 } | 449 } |
452 } | 450 } |
453 if (is_probing && bytes_sent > 0) | 451 if (is_probing && bytes_sent > 0) |
454 prober_->ProbeSent(clock_->TimeInMilliseconds(), bytes_sent); | 452 prober_->ProbeSent(clock_->TimeInMilliseconds(), bytes_sent); |
455 alr_detector_->OnBytesSent(bytes_sent, now_us / 1000); | 453 alr_detector_->OnBytesSent(bytes_sent, now_us / 1000); |
456 } | 454 } |
457 | 455 |
458 bool PacedSender::SendPacket(const paced_sender::Packet& packet, | 456 bool PacedSender::SendPacket(const paced_sender::Packet& packet, |
459 int probe_cluster_id) { | 457 int probe_cluster_id) { |
460 // TODO(holmer): Because of this bug issue 5307 we have to send audio | 458 if (paused_) |
461 // packets even when the pacer is paused. Here we assume audio packets are | 459 return false; |
462 // always high priority and that they are the only high priority packets. | 460 if (media_budget_->bytes_remaining() == 0 && |
463 if (packet.priority != kHighPriority) { | 461 probe_cluster_id == PacketInfo::kNotAProbe) { |
464 if (paused_) | 462 return false; |
465 return false; | |
466 if (media_budget_->bytes_remaining() == 0 && | |
467 probe_cluster_id == PacketInfo::kNotAProbe) { | |
468 return false; | |
469 } | |
470 } | 463 } |
471 critsect_->Leave(); | 464 critsect_->Leave(); |
472 const bool success = packet_sender_->TimeToSendPacket( | 465 const bool success = packet_sender_->TimeToSendPacket( |
473 packet.ssrc, packet.sequence_number, packet.capture_time_ms, | 466 packet.ssrc, packet.sequence_number, packet.capture_time_ms, |
474 packet.retransmission, probe_cluster_id); | 467 packet.retransmission, probe_cluster_id); |
475 critsect_->Enter(); | 468 critsect_->Enter(); |
476 | 469 |
477 if (success) { | 470 if (success) { |
478 // TODO(holmer): High priority packets should only be accounted for if we | 471 // TODO(holmer): High priority packets should only be accounted for if we |
479 // are allocating bandwidth for audio. | 472 // are allocating bandwidth for audio. |
(...skipping 21 matching lines...) Expand all Loading... |
501 void PacedSender::UpdateBudgetWithElapsedTime(int64_t delta_time_ms) { | 494 void PacedSender::UpdateBudgetWithElapsedTime(int64_t delta_time_ms) { |
502 media_budget_->IncreaseBudget(delta_time_ms); | 495 media_budget_->IncreaseBudget(delta_time_ms); |
503 padding_budget_->IncreaseBudget(delta_time_ms); | 496 padding_budget_->IncreaseBudget(delta_time_ms); |
504 } | 497 } |
505 | 498 |
506 void PacedSender::UpdateBudgetWithBytesSent(size_t bytes_sent) { | 499 void PacedSender::UpdateBudgetWithBytesSent(size_t bytes_sent) { |
507 media_budget_->UseBudget(bytes_sent); | 500 media_budget_->UseBudget(bytes_sent); |
508 padding_budget_->UseBudget(bytes_sent); | 501 padding_budget_->UseBudget(bytes_sent); |
509 } | 502 } |
510 } // namespace webrtc | 503 } // namespace webrtc |
OLD | NEW |