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 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 rtc::CritScope lock(&send_critsect_); | 435 rtc::CritScope lock(&send_critsect_); |
436 if (!sending_media_) | 436 if (!sending_media_) |
437 return 0; | 437 return 0; |
438 if ((rtx_ & kRtxRedundantPayloads) == 0) | 438 if ((rtx_ & kRtxRedundantPayloads) == 0) |
439 return 0; | 439 return 0; |
440 } | 440 } |
441 | 441 |
442 int bytes_left = static_cast<int>(bytes_to_send); | 442 int bytes_left = static_cast<int>(bytes_to_send); |
443 while (bytes_left > 0) { | 443 while (bytes_left > 0) { |
444 std::unique_ptr<RtpPacketToSend> packet = | 444 std::unique_ptr<RtpPacketToSend> packet = |
445 packet_history_.GetBestFittingPacket(bytes_left); | 445 packet_history_.GetBestFittingPacket(bytes_left, |
| 446 send_side_bwe_with_overhead_); |
446 if (!packet) | 447 if (!packet) |
447 break; | 448 break; |
448 size_t payload_size = packet->payload_size(); | 449 // When WebRTC-SendSideBwe-WithOverhead is enabled, the padding budget |
| 450 // includes overhead. |
| 451 const size_t used_bytes = |
| 452 send_side_bwe_with_overhead_ |
| 453 ? packet->payload_size() + packet->headers_size() |
| 454 : packet->payload_size(); |
449 if (!PrepareAndSendPacket(std::move(packet), true, false, pacing_info)) | 455 if (!PrepareAndSendPacket(std::move(packet), true, false, pacing_info)) |
450 break; | 456 break; |
451 bytes_left -= payload_size; | 457 bytes_left -= used_bytes; |
452 } | 458 } |
453 return bytes_to_send - bytes_left; | 459 return bytes_to_send - bytes_left; |
454 } | 460 } |
455 | 461 |
456 size_t RTPSender::SendPadData(size_t bytes, | 462 size_t RTPSender::SendPadData(size_t bytes, |
457 const PacedPacketInfo& pacing_info) { | 463 const PacedPacketInfo& pacing_info) { |
458 size_t padding_bytes_in_packet; | 464 // Always send full padding packets. This is accounted for by the |
| 465 // RtpPacketSender, which will make sure we don't send too much padding even |
| 466 // if a single packet is larger than requested. |
| 467 // We do this to avoid frequently sending small packets on higher bitrates. |
| 468 size_t padding_bytes_in_packet = |
| 469 std::min(MaxPayloadSize(), kMaxPaddingLength); |
| 470 |
459 if (audio_configured_) { | 471 if (audio_configured_) { |
460 // Allow smaller padding packets for audio. | 472 // Allow smaller padding packets for audio. |
| 473 |
| 474 // When WebRTC-SendSideBwe-WithOverhead is enabled, the padding budget |
| 475 // includes overhead. |
| 476 const size_t padding_bytes_if_one_packet = |
| 477 send_side_bwe_with_overhead_ |
| 478 ? std::max<int>(0, bytes - RtpHeaderLength()) |
| 479 : bytes; |
461 padding_bytes_in_packet = | 480 padding_bytes_in_packet = |
462 std::min(std::max(bytes, kMinAudioPaddingLength), MaxPayloadSize()); | 481 std::min(padding_bytes_in_packet, |
463 if (padding_bytes_in_packet > kMaxPaddingLength) | 482 std::max(padding_bytes_if_one_packet, kMinAudioPaddingLength)); |
464 padding_bytes_in_packet = kMaxPaddingLength; | |
465 } else { | |
466 // Always send full padding packets. This is accounted for by the | |
467 // RtpPacketSender, which will make sure we don't send too much padding even | |
468 // if a single packet is larger than requested. | |
469 // We do this to avoid frequently sending small packets on higher bitrates. | |
470 padding_bytes_in_packet = std::min(MaxPayloadSize(), kMaxPaddingLength); | |
471 } | 483 } |
| 484 |
472 size_t bytes_sent = 0; | 485 size_t bytes_sent = 0; |
473 while (bytes_sent < bytes) { | 486 while (bytes_sent < bytes) { |
474 int64_t now_ms = clock_->TimeInMilliseconds(); | 487 int64_t now_ms = clock_->TimeInMilliseconds(); |
475 uint32_t ssrc; | 488 uint32_t ssrc; |
476 uint32_t timestamp; | 489 uint32_t timestamp; |
477 int64_t capture_time_ms; | 490 int64_t capture_time_ms; |
478 uint16_t sequence_number; | 491 uint16_t sequence_number; |
479 int payload_type; | 492 int payload_type; |
480 bool over_rtx; | 493 bool over_rtx; |
481 { | 494 { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 padding_packet.SetSsrc(ssrc); | 559 padding_packet.SetSsrc(ssrc); |
547 | 560 |
548 if (capture_time_ms > 0) { | 561 if (capture_time_ms > 0) { |
549 padding_packet.SetExtension<TransmissionOffset>( | 562 padding_packet.SetExtension<TransmissionOffset>( |
550 (now_ms - capture_time_ms) * kTimestampTicksPerMs); | 563 (now_ms - capture_time_ms) * kTimestampTicksPerMs); |
551 } | 564 } |
552 padding_packet.SetExtension<AbsoluteSendTime>(now_ms); | 565 padding_packet.SetExtension<AbsoluteSendTime>(now_ms); |
553 PacketOptions options; | 566 PacketOptions options; |
554 bool has_transport_seq_num = | 567 bool has_transport_seq_num = |
555 UpdateTransportSequenceNumber(&padding_packet, &options.packet_id); | 568 UpdateTransportSequenceNumber(&padding_packet, &options.packet_id); |
| 569 |
556 padding_packet.SetPadding(padding_bytes_in_packet, &random_); | 570 padding_packet.SetPadding(padding_bytes_in_packet, &random_); |
557 | 571 |
558 if (has_transport_seq_num) { | 572 if (has_transport_seq_num) { |
559 AddPacketToTransportFeedback(options.packet_id, padding_packet, | 573 AddPacketToTransportFeedback(options.packet_id, padding_packet, |
560 pacing_info); | 574 pacing_info); |
561 } | 575 } |
562 | 576 |
563 if (!SendPacketToNetwork(padding_packet, options, pacing_info)) | 577 if (!SendPacketToNetwork(padding_packet, options, pacing_info)) |
564 break; | 578 break; |
565 | 579 |
566 bytes_sent += padding_bytes_in_packet; | 580 // When WebRTC-SendSideBwe-WithOverhead is enabled, the padding budget |
| 581 // includes overhead. |
| 582 bytes_sent += |
| 583 send_side_bwe_with_overhead_ |
| 584 ? padding_packet.padding_size() + padding_packet.headers_size() |
| 585 : padding_packet.padding_size(); |
567 UpdateRtpStats(padding_packet, over_rtx, false); | 586 UpdateRtpStats(padding_packet, over_rtx, false); |
568 } | 587 } |
569 | 588 |
570 return bytes_sent; | 589 return bytes_sent; |
571 } | 590 } |
572 | 591 |
573 void RTPSender::SetStorePacketsStatus(bool enable, uint16_t number_to_store) { | 592 void RTPSender::SetStorePacketsStatus(bool enable, uint16_t number_to_store) { |
574 packet_history_.SetStorePacketsStatus(enable, number_to_store); | 593 packet_history_.SetStorePacketsStatus(enable, number_to_store); |
575 } | 594 } |
576 | 595 |
(...skipping 13 matching lines...) Expand all Loading... |
590 // TODO(sprang): Add histograms for nack success or failure reasons. | 609 // TODO(sprang): Add histograms for nack success or failure reasons. |
591 RTC_DCHECK(retransmission_rate_limiter_); | 610 RTC_DCHECK(retransmission_rate_limiter_); |
592 if (!retransmission_rate_limiter_->TryUseRate(packet->size())) | 611 if (!retransmission_rate_limiter_->TryUseRate(packet->size())) |
593 return -1; | 612 return -1; |
594 | 613 |
595 if (paced_sender_) { | 614 if (paced_sender_) { |
596 // Convert from TickTime to Clock since capture_time_ms is based on | 615 // Convert from TickTime to Clock since capture_time_ms is based on |
597 // TickTime. | 616 // TickTime. |
598 int64_t corrected_capture_tims_ms = | 617 int64_t corrected_capture_tims_ms = |
599 packet->capture_time_ms() + clock_delta_ms_; | 618 packet->capture_time_ms() + clock_delta_ms_; |
| 619 const size_t packet_size = |
| 620 send_side_bwe_with_overhead_ |
| 621 ? packet->payload_size() + packet->headers_size() |
| 622 : packet->payload_size(); |
600 paced_sender_->InsertPacket(RtpPacketSender::kNormalPriority, | 623 paced_sender_->InsertPacket(RtpPacketSender::kNormalPriority, |
601 packet->Ssrc(), packet->SequenceNumber(), | 624 packet->Ssrc(), packet->SequenceNumber(), |
602 corrected_capture_tims_ms, | 625 corrected_capture_tims_ms, packet_size, true); |
603 packet->payload_size(), true); | |
604 | 626 |
605 return packet->size(); | 627 return packet->size(); |
606 } | 628 } |
607 bool rtx = (RtxStatus() & kRtxRetransmitted) > 0; | 629 bool rtx = (RtxStatus() & kRtxRetransmitted) > 0; |
608 int32_t packet_size = static_cast<int32_t>(packet->size()); | 630 int32_t packet_size = static_cast<int32_t>(packet->size()); |
609 if (!PrepareAndSendPacket(std::move(packet), rtx, true, PacedPacketInfo())) | 631 if (!PrepareAndSendPacket(std::move(packet), rtx, true, PacedPacketInfo())) |
610 return -1; | 632 return -1; |
611 return packet_size; | 633 return packet_size; |
612 } | 634 } |
613 | 635 |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 NackOverheadRate() / 1000, packet->Ssrc()); | 857 NackOverheadRate() / 1000, packet->Ssrc()); |
836 } | 858 } |
837 | 859 |
838 uint32_t ssrc = packet->Ssrc(); | 860 uint32_t ssrc = packet->Ssrc(); |
839 rtc::Optional<uint32_t> flexfec_ssrc = FlexfecSsrc(); | 861 rtc::Optional<uint32_t> flexfec_ssrc = FlexfecSsrc(); |
840 if (paced_sender_) { | 862 if (paced_sender_) { |
841 uint16_t seq_no = packet->SequenceNumber(); | 863 uint16_t seq_no = packet->SequenceNumber(); |
842 // Correct offset between implementations of millisecond time stamps in | 864 // Correct offset between implementations of millisecond time stamps in |
843 // TickTime and Clock. | 865 // TickTime and Clock. |
844 int64_t corrected_time_ms = packet->capture_time_ms() + clock_delta_ms_; | 866 int64_t corrected_time_ms = packet->capture_time_ms() + clock_delta_ms_; |
845 size_t payload_length = packet->payload_size(); | 867 const size_t packet_size = |
| 868 send_side_bwe_with_overhead_ |
| 869 ? packet->payload_size() + packet->headers_size() |
| 870 : packet->payload_size(); |
846 if (ssrc == flexfec_ssrc) { | 871 if (ssrc == flexfec_ssrc) { |
847 // Store FlexFEC packets in the history here, so they can be found | 872 // Store FlexFEC packets in the history here, so they can be found |
848 // when the pacer calls TimeToSendPacket. | 873 // when the pacer calls TimeToSendPacket. |
849 flexfec_packet_history_.PutRtpPacket(std::move(packet), storage, false); | 874 flexfec_packet_history_.PutRtpPacket(std::move(packet), storage, false); |
850 } else { | 875 } else { |
851 packet_history_.PutRtpPacket(std::move(packet), storage, false); | 876 packet_history_.PutRtpPacket(std::move(packet), storage, false); |
852 } | 877 } |
853 | 878 |
854 paced_sender_->InsertPacket(priority, ssrc, seq_no, corrected_time_ms, | 879 paced_sender_->InsertPacket(priority, ssrc, seq_no, corrected_time_ms, |
855 payload_length, false); | 880 packet_size, false); |
| 881 |
856 if (last_capture_time_ms_sent_ == 0 || | 882 if (last_capture_time_ms_sent_ == 0 || |
857 corrected_time_ms > last_capture_time_ms_sent_) { | 883 corrected_time_ms > last_capture_time_ms_sent_) { |
858 last_capture_time_ms_sent_ = corrected_time_ms; | 884 last_capture_time_ms_sent_ = corrected_time_ms; |
859 TRACE_EVENT_ASYNC_BEGIN1(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), | 885 TRACE_EVENT_ASYNC_BEGIN1(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), |
860 "PacedSend", corrected_time_ms, | 886 "PacedSend", corrected_time_ms, |
861 "capture_time_ms", corrected_time_ms); | 887 "capture_time_ms", corrected_time_ms); |
862 } | 888 } |
863 return true; | 889 return true; |
864 } | 890 } |
865 | 891 |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1230 state.sequence_number = sequence_number_rtx_; | 1256 state.sequence_number = sequence_number_rtx_; |
1231 state.start_timestamp = timestamp_offset_; | 1257 state.start_timestamp = timestamp_offset_; |
1232 | 1258 |
1233 return state; | 1259 return state; |
1234 } | 1260 } |
1235 | 1261 |
1236 void RTPSender::AddPacketToTransportFeedback( | 1262 void RTPSender::AddPacketToTransportFeedback( |
1237 uint16_t packet_id, | 1263 uint16_t packet_id, |
1238 const RtpPacketToSend& packet, | 1264 const RtpPacketToSend& packet, |
1239 const PacedPacketInfo& pacing_info) { | 1265 const PacedPacketInfo& pacing_info) { |
1240 size_t packet_size = packet.payload_size() + packet.padding_size(); | 1266 const size_t packet_size = |
1241 if (send_side_bwe_with_overhead_) { | 1267 send_side_bwe_with_overhead_ |
1242 packet_size = packet.size(); | 1268 ? packet.size() |
1243 } | 1269 : packet.payload_size() + packet.padding_size(); |
1244 | |
1245 if (transport_feedback_observer_) { | 1270 if (transport_feedback_observer_) { |
1246 transport_feedback_observer_->AddPacket(SSRC(), packet_id, packet_size, | 1271 transport_feedback_observer_->AddPacket(SSRC(), packet_id, packet_size, |
1247 pacing_info); | 1272 pacing_info); |
1248 } | 1273 } |
1249 } | 1274 } |
1250 | 1275 |
1251 void RTPSender::UpdateRtpOverhead(const RtpPacketToSend& packet) { | 1276 void RTPSender::UpdateRtpOverhead(const RtpPacketToSend& packet) { |
1252 if (!overhead_observer_) | 1277 if (!overhead_observer_) |
1253 return; | 1278 return; |
1254 size_t overhead_bytes_per_packet; | 1279 size_t overhead_bytes_per_packet; |
1255 { | 1280 { |
1256 rtc::CritScope lock(&send_critsect_); | 1281 rtc::CritScope lock(&send_critsect_); |
1257 if (rtp_overhead_bytes_per_packet_ == packet.headers_size()) { | 1282 if (rtp_overhead_bytes_per_packet_ == packet.headers_size()) { |
1258 return; | 1283 return; |
1259 } | 1284 } |
1260 rtp_overhead_bytes_per_packet_ = packet.headers_size(); | 1285 rtp_overhead_bytes_per_packet_ = packet.headers_size(); |
1261 overhead_bytes_per_packet = rtp_overhead_bytes_per_packet_; | 1286 overhead_bytes_per_packet = rtp_overhead_bytes_per_packet_; |
1262 } | 1287 } |
1263 overhead_observer_->OnOverheadChanged(overhead_bytes_per_packet); | 1288 overhead_observer_->OnOverheadChanged(overhead_bytes_per_packet); |
1264 } | 1289 } |
1265 | 1290 |
1266 } // namespace webrtc | 1291 } // namespace webrtc |
OLD | NEW |