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 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 ++frame_counts_.delta_frames; | 441 ++frame_counts_.delta_frames; |
442 } | 442 } |
443 if (frame_count_observer_) { | 443 if (frame_count_observer_) { |
444 frame_count_observer_->FrameCountUpdated(frame_counts_, ssrc); | 444 frame_count_observer_->FrameCountUpdated(frame_counts_, ssrc); |
445 } | 445 } |
446 | 446 |
447 return result; | 447 return result; |
448 } | 448 } |
449 | 449 |
450 size_t RTPSender::TrySendRedundantPayloads(size_t bytes_to_send, | 450 size_t RTPSender::TrySendRedundantPayloads(size_t bytes_to_send, |
451 int probe_cluster_id) { | 451 const PacedPacketInfo& pacing_info) { |
452 { | 452 { |
453 rtc::CritScope lock(&send_critsect_); | 453 rtc::CritScope lock(&send_critsect_); |
454 if (!sending_media_) | 454 if (!sending_media_) |
455 return 0; | 455 return 0; |
456 if ((rtx_ & kRtxRedundantPayloads) == 0) | 456 if ((rtx_ & kRtxRedundantPayloads) == 0) |
457 return 0; | 457 return 0; |
458 } | 458 } |
459 | 459 |
460 int bytes_left = static_cast<int>(bytes_to_send); | 460 int bytes_left = static_cast<int>(bytes_to_send); |
461 while (bytes_left > 0) { | 461 while (bytes_left > 0) { |
462 std::unique_ptr<RtpPacketToSend> packet = | 462 std::unique_ptr<RtpPacketToSend> packet = |
463 packet_history_.GetBestFittingPacket(bytes_left); | 463 packet_history_.GetBestFittingPacket(bytes_left); |
464 if (!packet) | 464 if (!packet) |
465 break; | 465 break; |
466 size_t payload_size = packet->payload_size(); | 466 size_t payload_size = packet->payload_size(); |
467 if (!PrepareAndSendPacket(std::move(packet), true, false, probe_cluster_id)) | 467 if (!PrepareAndSendPacket(std::move(packet), true, false, pacing_info)) |
468 break; | 468 break; |
469 bytes_left -= payload_size; | 469 bytes_left -= payload_size; |
470 } | 470 } |
471 return bytes_to_send - bytes_left; | 471 return bytes_to_send - bytes_left; |
472 } | 472 } |
473 | 473 |
474 size_t RTPSender::SendPadData(size_t bytes, int probe_cluster_id) { | 474 size_t RTPSender::SendPadData(size_t bytes, |
| 475 const PacedPacketInfo& pacing_info) { |
475 size_t padding_bytes_in_packet; | 476 size_t padding_bytes_in_packet; |
476 if (audio_configured_) { | 477 if (audio_configured_) { |
477 // Allow smaller padding packets for audio. | 478 // Allow smaller padding packets for audio. |
478 padding_bytes_in_packet = | 479 padding_bytes_in_packet = |
479 std::min(std::max(bytes, kMinAudioPaddingLength), MaxPayloadSize()); | 480 std::min(std::max(bytes, kMinAudioPaddingLength), MaxPayloadSize()); |
480 if (padding_bytes_in_packet > kMaxPaddingLength) | 481 if (padding_bytes_in_packet > kMaxPaddingLength) |
481 padding_bytes_in_packet = kMaxPaddingLength; | 482 padding_bytes_in_packet = kMaxPaddingLength; |
482 } else { | 483 } else { |
483 // Always send full padding packets. This is accounted for by the | 484 // Always send full padding packets. This is accounted for by the |
484 // RtpPacketSender, which will make sure we don't send too much padding even | 485 // RtpPacketSender, which will make sure we don't send too much padding even |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 (now_ms - capture_time_ms) * kTimestampTicksPerMs); | 568 (now_ms - capture_time_ms) * kTimestampTicksPerMs); |
568 } | 569 } |
569 padding_packet.SetExtension<AbsoluteSendTime>(now_ms); | 570 padding_packet.SetExtension<AbsoluteSendTime>(now_ms); |
570 PacketOptions options; | 571 PacketOptions options; |
571 bool has_transport_seq_num = | 572 bool has_transport_seq_num = |
572 UpdateTransportSequenceNumber(&padding_packet, &options.packet_id); | 573 UpdateTransportSequenceNumber(&padding_packet, &options.packet_id); |
573 padding_packet.SetPadding(padding_bytes_in_packet, &random_); | 574 padding_packet.SetPadding(padding_bytes_in_packet, &random_); |
574 | 575 |
575 if (has_transport_seq_num) { | 576 if (has_transport_seq_num) { |
576 AddPacketToTransportFeedback(options.packet_id, padding_packet, | 577 AddPacketToTransportFeedback(options.packet_id, padding_packet, |
577 probe_cluster_id); | 578 pacing_info); |
578 } | 579 } |
579 | 580 |
580 if (!SendPacketToNetwork(padding_packet, options)) | 581 if (!SendPacketToNetwork(padding_packet, options)) |
581 break; | 582 break; |
582 | 583 |
583 bytes_sent += padding_bytes_in_packet; | 584 bytes_sent += padding_bytes_in_packet; |
584 UpdateRtpStats(padding_packet, over_rtx, false); | 585 UpdateRtpStats(padding_packet, over_rtx, false); |
585 } | 586 } |
586 | 587 |
587 return bytes_sent; | 588 return bytes_sent; |
(...skipping 28 matching lines...) Expand all Loading... |
616 packet->capture_time_ms() + clock_delta_ms_; | 617 packet->capture_time_ms() + clock_delta_ms_; |
617 paced_sender_->InsertPacket(RtpPacketSender::kNormalPriority, | 618 paced_sender_->InsertPacket(RtpPacketSender::kNormalPriority, |
618 packet->Ssrc(), packet->SequenceNumber(), | 619 packet->Ssrc(), packet->SequenceNumber(), |
619 corrected_capture_tims_ms, | 620 corrected_capture_tims_ms, |
620 packet->payload_size(), true); | 621 packet->payload_size(), true); |
621 | 622 |
622 return packet->size(); | 623 return packet->size(); |
623 } | 624 } |
624 bool rtx = (RtxStatus() & kRtxRetransmitted) > 0; | 625 bool rtx = (RtxStatus() & kRtxRetransmitted) > 0; |
625 int32_t packet_size = static_cast<int32_t>(packet->size()); | 626 int32_t packet_size = static_cast<int32_t>(packet->size()); |
626 if (!PrepareAndSendPacket(std::move(packet), rtx, true, | 627 if (!PrepareAndSendPacket(std::move(packet), rtx, true, PacedPacketInfo())) |
627 PacedPacketInfo::kNotAProbe)) | |
628 return -1; | 628 return -1; |
629 return packet_size; | 629 return packet_size; |
630 } | 630 } |
631 | 631 |
632 bool RTPSender::SendPacketToNetwork(const RtpPacketToSend& packet, | 632 bool RTPSender::SendPacketToNetwork(const RtpPacketToSend& packet, |
633 const PacketOptions& options) { | 633 const PacketOptions& options) { |
634 int bytes_sent = -1; | 634 int bytes_sent = -1; |
635 if (transport_) { | 635 if (transport_) { |
636 UpdateRtpOverhead(packet); | 636 UpdateRtpOverhead(packet); |
637 bytes_sent = transport_->SendRtp(packet.data(), packet.size(), options) | 637 bytes_sent = transport_->SendRtp(packet.data(), packet.size(), options) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 void RTPSender::OnReceivedRtcpReportBlocks( | 686 void RTPSender::OnReceivedRtcpReportBlocks( |
687 const ReportBlockList& report_blocks) { | 687 const ReportBlockList& report_blocks) { |
688 playout_delay_oracle_.OnReceivedRtcpReportBlocks(report_blocks); | 688 playout_delay_oracle_.OnReceivedRtcpReportBlocks(report_blocks); |
689 } | 689 } |
690 | 690 |
691 // Called from pacer when we can send the packet. | 691 // Called from pacer when we can send the packet. |
692 bool RTPSender::TimeToSendPacket(uint32_t ssrc, | 692 bool RTPSender::TimeToSendPacket(uint32_t ssrc, |
693 uint16_t sequence_number, | 693 uint16_t sequence_number, |
694 int64_t capture_time_ms, | 694 int64_t capture_time_ms, |
695 bool retransmission, | 695 bool retransmission, |
696 int probe_cluster_id) { | 696 const PacedPacketInfo& pacing_info) { |
697 if (!SendingMedia()) | 697 if (!SendingMedia()) |
698 return true; | 698 return true; |
699 | 699 |
700 std::unique_ptr<RtpPacketToSend> packet; | 700 std::unique_ptr<RtpPacketToSend> packet; |
701 if (ssrc == SSRC()) { | 701 if (ssrc == SSRC()) { |
702 packet = packet_history_.GetPacketAndSetSendTime(sequence_number, 0, | 702 packet = packet_history_.GetPacketAndSetSendTime(sequence_number, 0, |
703 retransmission); | 703 retransmission); |
704 } else if (ssrc == FlexfecSsrc()) { | 704 } else if (ssrc == FlexfecSsrc()) { |
705 packet = flexfec_packet_history_.GetPacketAndSetSendTime(sequence_number, 0, | 705 packet = flexfec_packet_history_.GetPacketAndSetSendTime(sequence_number, 0, |
706 retransmission); | 706 retransmission); |
707 } | 707 } |
708 | 708 |
709 if (!packet) { | 709 if (!packet) { |
710 // Packet cannot be found. | 710 // Packet cannot be found. |
711 return true; | 711 return true; |
712 } | 712 } |
713 | 713 |
714 return PrepareAndSendPacket( | 714 return PrepareAndSendPacket( |
715 std::move(packet), | 715 std::move(packet), |
716 retransmission && (RtxStatus() & kRtxRetransmitted) > 0, retransmission, | 716 retransmission && (RtxStatus() & kRtxRetransmitted) > 0, retransmission, |
717 probe_cluster_id); | 717 pacing_info); |
718 } | 718 } |
719 | 719 |
720 bool RTPSender::PrepareAndSendPacket(std::unique_ptr<RtpPacketToSend> packet, | 720 bool RTPSender::PrepareAndSendPacket(std::unique_ptr<RtpPacketToSend> packet, |
721 bool send_over_rtx, | 721 bool send_over_rtx, |
722 bool is_retransmit, | 722 bool is_retransmit, |
723 int probe_cluster_id) { | 723 const PacedPacketInfo& pacing_info) { |
724 RTC_DCHECK(packet); | 724 RTC_DCHECK(packet); |
725 int64_t capture_time_ms = packet->capture_time_ms(); | 725 int64_t capture_time_ms = packet->capture_time_ms(); |
726 RtpPacketToSend* packet_to_send = packet.get(); | 726 RtpPacketToSend* packet_to_send = packet.get(); |
727 | 727 |
728 if (!is_retransmit && packet->Marker()) { | 728 if (!is_retransmit && packet->Marker()) { |
729 TRACE_EVENT_ASYNC_END0(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "PacedSend", | 729 TRACE_EVENT_ASYNC_END0(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "PacedSend", |
730 capture_time_ms); | 730 capture_time_ms); |
731 } | 731 } |
732 | 732 |
733 TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), | 733 TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), |
(...skipping 10 matching lines...) Expand all Loading... |
744 | 744 |
745 int64_t now_ms = clock_->TimeInMilliseconds(); | 745 int64_t now_ms = clock_->TimeInMilliseconds(); |
746 int64_t diff_ms = now_ms - capture_time_ms; | 746 int64_t diff_ms = now_ms - capture_time_ms; |
747 packet_to_send->SetExtension<TransmissionOffset>(kTimestampTicksPerMs * | 747 packet_to_send->SetExtension<TransmissionOffset>(kTimestampTicksPerMs * |
748 diff_ms); | 748 diff_ms); |
749 packet_to_send->SetExtension<AbsoluteSendTime>(now_ms); | 749 packet_to_send->SetExtension<AbsoluteSendTime>(now_ms); |
750 | 750 |
751 PacketOptions options; | 751 PacketOptions options; |
752 if (UpdateTransportSequenceNumber(packet_to_send, &options.packet_id)) { | 752 if (UpdateTransportSequenceNumber(packet_to_send, &options.packet_id)) { |
753 AddPacketToTransportFeedback(options.packet_id, *packet_to_send, | 753 AddPacketToTransportFeedback(options.packet_id, *packet_to_send, |
754 probe_cluster_id); | 754 pacing_info); |
755 } | 755 } |
756 | 756 |
757 if (!is_retransmit && !send_over_rtx) { | 757 if (!is_retransmit && !send_over_rtx) { |
758 UpdateDelayStatistics(packet->capture_time_ms(), now_ms); | 758 UpdateDelayStatistics(packet->capture_time_ms(), now_ms); |
759 UpdateOnSendPacket(options.packet_id, packet->capture_time_ms(), | 759 UpdateOnSendPacket(options.packet_id, packet->capture_time_ms(), |
760 packet->Ssrc()); | 760 packet->Ssrc()); |
761 } | 761 } |
762 | 762 |
763 if (!SendPacketToNetwork(*packet_to_send, options)) | 763 if (!SendPacketToNetwork(*packet_to_send, options)) |
764 return false; | 764 return false; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
806 return true; | 806 return true; |
807 | 807 |
808 // RED+ULPFEC. | 808 // RED+ULPFEC. |
809 int pt_red; | 809 int pt_red; |
810 int pt_fec; | 810 int pt_fec; |
811 video_->GetUlpfecConfig(&pt_red, &pt_fec); | 811 video_->GetUlpfecConfig(&pt_red, &pt_fec); |
812 return static_cast<int>(packet.PayloadType()) == pt_red && | 812 return static_cast<int>(packet.PayloadType()) == pt_red && |
813 static_cast<int>(packet.payload()[0]) == pt_fec; | 813 static_cast<int>(packet.payload()[0]) == pt_fec; |
814 } | 814 } |
815 | 815 |
816 size_t RTPSender::TimeToSendPadding(size_t bytes, int probe_cluster_id) { | 816 size_t RTPSender::TimeToSendPadding(size_t bytes, |
| 817 const PacedPacketInfo& pacing_info) { |
817 if (bytes == 0) | 818 if (bytes == 0) |
818 return 0; | 819 return 0; |
819 size_t bytes_sent = TrySendRedundantPayloads(bytes, probe_cluster_id); | 820 size_t bytes_sent = TrySendRedundantPayloads(bytes, pacing_info); |
820 if (bytes_sent < bytes) | 821 if (bytes_sent < bytes) |
821 bytes_sent += SendPadData(bytes - bytes_sent, probe_cluster_id); | 822 bytes_sent += SendPadData(bytes - bytes_sent, pacing_info); |
822 return bytes_sent; | 823 return bytes_sent; |
823 } | 824 } |
824 | 825 |
825 bool RTPSender::SendToNetwork(std::unique_ptr<RtpPacketToSend> packet, | 826 bool RTPSender::SendToNetwork(std::unique_ptr<RtpPacketToSend> packet, |
826 StorageType storage, | 827 StorageType storage, |
827 RtpPacketSender::Priority priority) { | 828 RtpPacketSender::Priority priority) { |
828 RTC_DCHECK(packet); | 829 RTC_DCHECK(packet); |
829 int64_t now_ms = clock_->TimeInMilliseconds(); | 830 int64_t now_ms = clock_->TimeInMilliseconds(); |
830 | 831 |
831 // |capture_time_ms| <= 0 is considered invalid. | 832 // |capture_time_ms| <= 0 is considered invalid. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 TRACE_EVENT_ASYNC_BEGIN1(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), | 876 TRACE_EVENT_ASYNC_BEGIN1(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), |
876 "PacedSend", corrected_time_ms, | 877 "PacedSend", corrected_time_ms, |
877 "capture_time_ms", corrected_time_ms); | 878 "capture_time_ms", corrected_time_ms); |
878 } | 879 } |
879 return true; | 880 return true; |
880 } | 881 } |
881 | 882 |
882 PacketOptions options; | 883 PacketOptions options; |
883 if (UpdateTransportSequenceNumber(packet.get(), &options.packet_id)) { | 884 if (UpdateTransportSequenceNumber(packet.get(), &options.packet_id)) { |
884 AddPacketToTransportFeedback(options.packet_id, *packet.get(), | 885 AddPacketToTransportFeedback(options.packet_id, *packet.get(), |
885 PacedPacketInfo::kNotAProbe); | 886 PacedPacketInfo()); |
886 } | 887 } |
887 | 888 |
888 UpdateDelayStatistics(packet->capture_time_ms(), now_ms); | 889 UpdateDelayStatistics(packet->capture_time_ms(), now_ms); |
889 UpdateOnSendPacket(options.packet_id, packet->capture_time_ms(), | 890 UpdateOnSendPacket(options.packet_id, packet->capture_time_ms(), |
890 packet->Ssrc()); | 891 packet->Ssrc()); |
891 | 892 |
892 bool sent = SendPacketToNetwork(*packet, options); | 893 bool sent = SendPacketToNetwork(*packet, options); |
893 | 894 |
894 if (sent) { | 895 if (sent) { |
895 { | 896 { |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1242 RtpState RTPSender::GetRtxRtpState() const { | 1243 RtpState RTPSender::GetRtxRtpState() const { |
1243 rtc::CritScope lock(&send_critsect_); | 1244 rtc::CritScope lock(&send_critsect_); |
1244 | 1245 |
1245 RtpState state; | 1246 RtpState state; |
1246 state.sequence_number = sequence_number_rtx_; | 1247 state.sequence_number = sequence_number_rtx_; |
1247 state.start_timestamp = timestamp_offset_; | 1248 state.start_timestamp = timestamp_offset_; |
1248 | 1249 |
1249 return state; | 1250 return state; |
1250 } | 1251 } |
1251 | 1252 |
1252 void RTPSender::AddPacketToTransportFeedback(uint16_t packet_id, | 1253 void RTPSender::AddPacketToTransportFeedback( |
1253 const RtpPacketToSend& packet, | 1254 uint16_t packet_id, |
1254 int probe_cluster_id) { | 1255 const RtpPacketToSend& packet, |
| 1256 const PacedPacketInfo& pacing_info) { |
1255 size_t packet_size = packet.payload_size() + packet.padding_size(); | 1257 size_t packet_size = packet.payload_size() + packet.padding_size(); |
1256 if (send_side_bwe_with_overhead_) { | 1258 if (send_side_bwe_with_overhead_) { |
1257 packet_size = packet.size(); | 1259 packet_size = packet.size(); |
1258 } | 1260 } |
1259 | 1261 |
1260 if (transport_feedback_observer_) { | 1262 if (transport_feedback_observer_) { |
1261 transport_feedback_observer_->AddPacket(packet_id, packet_size, | 1263 transport_feedback_observer_->AddPacket(packet_id, packet_size, |
1262 probe_cluster_id); | 1264 pacing_info); |
1263 } | 1265 } |
1264 } | 1266 } |
1265 | 1267 |
1266 void RTPSender::UpdateRtpOverhead(const RtpPacketToSend& packet) { | 1268 void RTPSender::UpdateRtpOverhead(const RtpPacketToSend& packet) { |
1267 if (!overhead_observer_) | 1269 if (!overhead_observer_) |
1268 return; | 1270 return; |
1269 size_t overhead_bytes_per_packet; | 1271 size_t overhead_bytes_per_packet; |
1270 { | 1272 { |
1271 rtc::CritScope lock(&send_critsect_); | 1273 rtc::CritScope lock(&send_critsect_); |
1272 if (rtp_overhead_bytes_per_packet_ == packet.headers_size()) { | 1274 if (rtp_overhead_bytes_per_packet_ == packet.headers_size()) { |
1273 return; | 1275 return; |
1274 } | 1276 } |
1275 rtp_overhead_bytes_per_packet_ = packet.headers_size(); | 1277 rtp_overhead_bytes_per_packet_ = packet.headers_size(); |
1276 overhead_bytes_per_packet = rtp_overhead_bytes_per_packet_; | 1278 overhead_bytes_per_packet = rtp_overhead_bytes_per_packet_; |
1277 } | 1279 } |
1278 overhead_observer_->OnOverheadChanged(overhead_bytes_per_packet); | 1280 overhead_observer_->OnOverheadChanged(overhead_bytes_per_packet); |
1279 } | 1281 } |
1280 | 1282 |
1281 } // namespace webrtc | 1283 } // namespace webrtc |
OLD | NEW |