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; |
stefan-webrtc
2016/09/19 07:24:56
Is this because you want to be able to fill up wit
Irfan
2016/09/19 18:23:30
I restructured this to ensure there is a single ca
| |
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 = is_probing ? (recommended_probe_size - bytes_sent) | |
437 : padding_budget_->bytes_remaining(); | |
429 | 438 |
430 // We can not send padding unless a normal packet has first been sent. If we | 439 if (padding_needed > 0) |
431 // do, timestamps get messed up. | 440 bytes_sent += SendPadding(padding_needed, probe_cluster_id); |
stefan-webrtc
2016/09/19 07:24:56
I'm starting to think that we may want a higher le
Irfan
2016/09/19 18:23:30
Yes, I did want to add a test once the CL looks go
| |
432 if (packet_counter_ > 0) { | 441 } |
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 } | 442 } |
443 if (is_probing) | |
444 prober_->ProbeSent(clock_->TimeInMilliseconds(), bytes_sent); | |
439 } | 445 } |
440 | 446 |
441 bool PacedSender::SendPacket(const paced_sender::Packet& packet, | 447 bool PacedSender::SendPacket(const paced_sender::Packet& packet, |
442 int probe_cluster_id) { | 448 int probe_cluster_id) { |
443 // TODO(holmer): Because of this bug issue 5307 we have to send audio | 449 // 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 | 450 // 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. | 451 // always high priority and that they are the only high priority packets. |
446 if (packet.priority != kHighPriority) { | 452 if (packet.priority != kHighPriority) { |
447 if (paused_) | 453 if (paused_) |
448 return false; | 454 return false; |
449 if (media_budget_->bytes_remaining() == 0 && | 455 if (media_budget_->bytes_remaining() == 0 && |
450 probe_cluster_id == PacketInfo::kNotAProbe) { | 456 probe_cluster_id == PacketInfo::kNotAProbe) { |
451 return false; | 457 return false; |
452 } | 458 } |
453 } | 459 } |
454 critsect_->Leave(); | 460 critsect_->Leave(); |
455 const bool success = packet_sender_->TimeToSendPacket( | 461 const bool success = packet_sender_->TimeToSendPacket( |
456 packet.ssrc, packet.sequence_number, packet.capture_time_ms, | 462 packet.ssrc, packet.sequence_number, packet.capture_time_ms, |
457 packet.retransmission, probe_cluster_id); | 463 packet.retransmission, probe_cluster_id); |
458 critsect_->Enter(); | 464 critsect_->Enter(); |
459 | 465 |
460 if (success) { | 466 if (success) { |
461 prober_->PacketSent(clock_->TimeInMilliseconds(), packet.bytes); | |
462 // TODO(holmer): High priority packets should only be accounted for if we | 467 // TODO(holmer): High priority packets should only be accounted for if we |
463 // are allocating bandwidth for audio. | 468 // are allocating bandwidth for audio. |
464 if (packet.priority != kHighPriority) { | 469 if (packet.priority != kHighPriority) { |
465 // Update media bytes sent. | 470 // Update media bytes sent. |
466 media_budget_->UseBudget(packet.bytes); | 471 media_budget_->UseBudget(packet.bytes); |
467 padding_budget_->UseBudget(packet.bytes); | 472 padding_budget_->UseBudget(packet.bytes); |
468 } | 473 } |
469 } | 474 } |
470 | 475 |
471 return success; | 476 return success; |
472 } | 477 } |
473 | 478 |
474 void PacedSender::SendPadding(size_t padding_needed, int probe_cluster_id) { | 479 size_t PacedSender::SendPadding(size_t padding_needed, int probe_cluster_id) { |
475 critsect_->Leave(); | 480 critsect_->Leave(); |
476 size_t bytes_sent = | 481 size_t bytes_sent = |
477 packet_sender_->TimeToSendPadding(padding_needed, probe_cluster_id); | 482 packet_sender_->TimeToSendPadding(padding_needed, probe_cluster_id); |
478 critsect_->Enter(); | 483 critsect_->Enter(); |
479 | 484 |
480 if (bytes_sent > 0) { | 485 if (bytes_sent > 0) { |
481 prober_->PacketSent(clock_->TimeInMilliseconds(), bytes_sent); | |
482 media_budget_->UseBudget(bytes_sent); | 486 media_budget_->UseBudget(bytes_sent); |
483 padding_budget_->UseBudget(bytes_sent); | 487 padding_budget_->UseBudget(bytes_sent); |
484 } | 488 } |
489 return bytes_sent; | |
485 } | 490 } |
486 | 491 |
487 void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) { | 492 void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) { |
488 media_budget_->IncreaseBudget(delta_time_ms); | 493 media_budget_->IncreaseBudget(delta_time_ms); |
489 padding_budget_->IncreaseBudget(delta_time_ms); | 494 padding_budget_->IncreaseBudget(delta_time_ms); |
490 } | 495 } |
491 } // namespace webrtc | 496 } // namespace webrtc |
OLD | NEW |