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_->RecommendedProbeSize(); | |
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) { |
stefan-webrtc
2016/09/16 07:42:53
This may look like a bug to the reader as it seems
Irfan
2016/09/19 06:05:11
Not sure I follow. The is_probing flag indicates w
stefan-webrtc
2016/09/19 07:24:56
I'm thinking of the case where we have paced out,
Irfan
2016/09/19 18:23:30
We report once the aggregate bytes is above the re
| |
423 prober_->ProbeSent(clock_->TimeInMilliseconds(), bytes_sent); | |
417 return; | 424 return; |
425 } | |
418 } else { | 426 } else { |
419 // Send failed, put it back into the queue. | 427 // Send failed, put it back into the queue. |
420 packets_->CancelPop(packet); | 428 packets_->CancelPop(packet); |
421 return; | 429 return; |
422 } | 430 } |
423 } | 431 } |
424 | 432 |
425 RTC_DCHECK(packets_->Empty()); | 433 RTC_DCHECK(packets_->Empty()); |
426 // TODO(holmer): Remove the paused_ check when issue 5307 has been fixed. | 434 // TODO(holmer): Remove the paused_ check when issue 5307 has been fixed. |
427 if (paused_) | 435 if (paused_) |
428 return; | 436 return; |
429 | 437 |
430 // We can not send padding unless a normal packet has first been sent. If we | 438 // We can not send padding unless a normal packet has first been sent. If we |
431 // do, timestamps get messed up. | 439 // do, timestamps get messed up. |
432 if (packet_counter_ > 0) { | 440 if (packet_counter_ > 0) { |
433 size_t padding_needed = is_probing ? prober_->RecommendedPacketSize() | 441 size_t padding_needed = is_probing ? (recommended_probe_size - bytes_sent) |
434 : padding_budget_->bytes_remaining(); | 442 : padding_budget_->bytes_remaining(); |
435 | 443 |
436 if (padding_needed > 0) | 444 if (padding_needed > 0) |
437 SendPadding(padding_needed, probe_cluster_id); | 445 bytes_sent += SendPadding(padding_needed, probe_cluster_id); |
438 } | 446 } |
447 if (is_probing) | |
448 prober_->ProbeSent(clock_->TimeInMilliseconds(), bytes_sent); | |
439 } | 449 } |
440 | 450 |
441 bool PacedSender::SendPacket(const paced_sender::Packet& packet, | 451 bool PacedSender::SendPacket(const paced_sender::Packet& packet, |
442 int probe_cluster_id) { | 452 int probe_cluster_id) { |
443 // TODO(holmer): Because of this bug issue 5307 we have to send audio | 453 // 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 | 454 // 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. | 455 // always high priority and that they are the only high priority packets. |
446 if (packet.priority != kHighPriority) { | 456 if (packet.priority != kHighPriority) { |
447 if (paused_) | 457 if (paused_) |
448 return false; | 458 return false; |
449 if (media_budget_->bytes_remaining() == 0 && | 459 if (media_budget_->bytes_remaining() == 0 && |
450 probe_cluster_id == PacketInfo::kNotAProbe) { | 460 probe_cluster_id == PacketInfo::kNotAProbe) { |
451 return false; | 461 return false; |
452 } | 462 } |
453 } | 463 } |
454 critsect_->Leave(); | 464 critsect_->Leave(); |
455 const bool success = packet_sender_->TimeToSendPacket( | 465 const bool success = packet_sender_->TimeToSendPacket( |
456 packet.ssrc, packet.sequence_number, packet.capture_time_ms, | 466 packet.ssrc, packet.sequence_number, packet.capture_time_ms, |
457 packet.retransmission, probe_cluster_id); | 467 packet.retransmission, probe_cluster_id); |
458 critsect_->Enter(); | 468 critsect_->Enter(); |
459 | 469 |
460 if (success) { | 470 if (success) { |
461 prober_->PacketSent(clock_->TimeInMilliseconds(), packet.bytes); | |
462 // 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 |
463 // are allocating bandwidth for audio. | 472 // are allocating bandwidth for audio. |
464 if (packet.priority != kHighPriority) { | 473 if (packet.priority != kHighPriority) { |
465 // Update media bytes sent. | 474 // Update media bytes sent. |
466 media_budget_->UseBudget(packet.bytes); | 475 media_budget_->UseBudget(packet.bytes); |
467 padding_budget_->UseBudget(packet.bytes); | 476 padding_budget_->UseBudget(packet.bytes); |
468 } | 477 } |
469 } | 478 } |
470 | 479 |
471 return success; | 480 return success; |
472 } | 481 } |
473 | 482 |
474 void PacedSender::SendPadding(size_t padding_needed, int probe_cluster_id) { | 483 size_t PacedSender::SendPadding(size_t padding_needed, int probe_cluster_id) { |
475 critsect_->Leave(); | 484 critsect_->Leave(); |
476 size_t bytes_sent = | 485 size_t bytes_sent = |
477 packet_sender_->TimeToSendPadding(padding_needed, probe_cluster_id); | 486 packet_sender_->TimeToSendPadding(padding_needed, probe_cluster_id); |
478 critsect_->Enter(); | 487 critsect_->Enter(); |
479 | 488 |
480 if (bytes_sent > 0) { | 489 if (bytes_sent > 0) { |
481 prober_->PacketSent(clock_->TimeInMilliseconds(), bytes_sent); | |
482 media_budget_->UseBudget(bytes_sent); | 490 media_budget_->UseBudget(bytes_sent); |
483 padding_budget_->UseBudget(bytes_sent); | 491 padding_budget_->UseBudget(bytes_sent); |
484 } | 492 } |
493 return bytes_sent; | |
485 } | 494 } |
486 | 495 |
487 void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) { | 496 void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) { |
488 media_budget_->IncreaseBudget(delta_time_ms); | 497 media_budget_->IncreaseBudget(delta_time_ms); |
489 padding_budget_->IncreaseBudget(delta_time_ms); | 498 padding_budget_->IncreaseBudget(delta_time_ms); |
490 } | 499 } |
491 } // namespace webrtc | 500 } // namespace webrtc |
OLD | NEW |