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 121 matching lines...) Loading... |
132 | 132 |
133 const FeedbackState& feedback_state_; | 133 const FeedbackState& feedback_state_; |
134 const int32_t nack_size_; | 134 const int32_t nack_size_; |
135 const uint16_t* nack_list_; | 135 const uint16_t* nack_list_; |
136 const NtpTime now_; | 136 const NtpTime now_; |
137 }; | 137 }; |
138 | 138 |
139 RTCPSender::RTCPSender( | 139 RTCPSender::RTCPSender( |
140 bool audio, | 140 bool audio, |
141 Clock* clock, | 141 Clock* clock, |
142 ReceiveStatistics* receive_statistics, | 142 ReceiveStatisticsReporter* receive_statistics, |
143 RtcpPacketTypeCounterObserver* packet_type_counter_observer, | 143 RtcpPacketTypeCounterObserver* packet_type_counter_observer, |
144 RtcEventLog* event_log, | 144 RtcEventLog* event_log, |
145 Transport* outgoing_transport) | 145 Transport* outgoing_transport) |
146 : audio_(audio), | 146 : audio_(audio), |
147 clock_(clock), | 147 clock_(clock), |
148 random_(clock_->TimeInMicroseconds()), | 148 random_(clock_->TimeInMicroseconds()), |
149 method_(RtcpMode::kOff), | 149 method_(RtcpMode::kOff), |
150 event_log_(event_log), | 150 event_log_(event_log), |
151 transport_(outgoing_transport), | 151 transport_(outgoing_transport), |
152 using_nack_(false), | 152 using_nack_(false), |
(...skipping 295 matching lines...) Loading... |
448 uint32_t rtp_timestamp = | 448 uint32_t rtp_timestamp = |
449 timestamp_offset_ + last_rtp_timestamp_ + | 449 timestamp_offset_ + last_rtp_timestamp_ + |
450 (clock_->TimeInMilliseconds() - last_frame_capture_time_ms_) * rtp_rate; | 450 (clock_->TimeInMilliseconds() - last_frame_capture_time_ms_) * rtp_rate; |
451 | 451 |
452 rtcp::SenderReport* report = new rtcp::SenderReport(); | 452 rtcp::SenderReport* report = new rtcp::SenderReport(); |
453 report->SetSenderSsrc(ssrc_); | 453 report->SetSenderSsrc(ssrc_); |
454 report->SetNtp(ctx.now_); | 454 report->SetNtp(ctx.now_); |
455 report->SetRtpTimestamp(rtp_timestamp); | 455 report->SetRtpTimestamp(rtp_timestamp); |
456 report->SetPacketCount(ctx.feedback_state_.packets_sent); | 456 report->SetPacketCount(ctx.feedback_state_.packets_sent); |
457 report->SetOctetCount(ctx.feedback_state_.media_bytes_sent); | 457 report->SetOctetCount(ctx.feedback_state_.media_bytes_sent); |
458 | 458 report->SetReportBlocks(std::move(report_blocks_)); |
459 for (auto it : report_blocks_) | |
460 report->AddReportBlock(it.second); | |
461 | |
462 report_blocks_.clear(); | 459 report_blocks_.clear(); |
463 | 460 |
464 return std::unique_ptr<rtcp::RtcpPacket>(report); | 461 return std::unique_ptr<rtcp::RtcpPacket>(report); |
465 } | 462 } |
466 | 463 |
467 std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildSDES( | 464 std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildSDES( |
468 const RtcpContext& ctx) { | 465 const RtcpContext& ctx) { |
469 size_t length_cname = cname_.length(); | 466 size_t length_cname = cname_.length(); |
470 RTC_CHECK_LT(length_cname, RTCP_CNAME_SIZE); | 467 RTC_CHECK_LT(length_cname, RTCP_CNAME_SIZE); |
471 | 468 |
472 rtcp::Sdes* sdes = new rtcp::Sdes(); | 469 rtcp::Sdes* sdes = new rtcp::Sdes(); |
473 sdes->AddCName(ssrc_, cname_); | 470 sdes->AddCName(ssrc_, cname_); |
474 | 471 |
475 for (const auto& it : csrc_cnames_) | 472 for (const auto& it : csrc_cnames_) |
476 RTC_CHECK(sdes->AddCName(it.first, it.second)); | 473 RTC_CHECK(sdes->AddCName(it.first, it.second)); |
477 | 474 |
478 return std::unique_ptr<rtcp::RtcpPacket>(sdes); | 475 return std::unique_ptr<rtcp::RtcpPacket>(sdes); |
479 } | 476 } |
480 | 477 |
481 std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildRR(const RtcpContext& ctx) { | 478 std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildRR(const RtcpContext& ctx) { |
482 rtcp::ReceiverReport* report = new rtcp::ReceiverReport(); | 479 rtcp::ReceiverReport* report = new rtcp::ReceiverReport(); |
483 report->SetSenderSsrc(ssrc_); | 480 report->SetSenderSsrc(ssrc_); |
484 for (auto it : report_blocks_) | 481 report->SetReportBlocks(std::move(report_blocks_)); |
485 report->AddReportBlock(it.second); | |
486 | |
487 report_blocks_.clear(); | 482 report_blocks_.clear(); |
488 return std::unique_ptr<rtcp::RtcpPacket>(report); | 483 return std::unique_ptr<rtcp::RtcpPacket>(report); |
489 } | 484 } |
490 | 485 |
491 std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildPLI(const RtcpContext& ctx) { | 486 std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildPLI(const RtcpContext& ctx) { |
492 rtcp::Pli* pli = new rtcp::Pli(); | 487 rtcp::Pli* pli = new rtcp::Pli(); |
493 pli->SetSenderSsrc(ssrc_); | 488 pli->SetSenderSsrc(ssrc_); |
494 pli->SetMediaSsrc(remote_ssrc_); | 489 pli->SetMediaSsrc(remote_ssrc_); |
495 | 490 |
496 TRACE_EVENT_INSTANT0(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), | 491 TRACE_EVENT_INSTANT0(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), |
(...skipping 326 matching lines...) Loading... |
823 } | 818 } |
824 if (minIntervalMs > RTCP_INTERVAL_VIDEO_MS) | 819 if (minIntervalMs > RTCP_INTERVAL_VIDEO_MS) |
825 minIntervalMs = RTCP_INTERVAL_VIDEO_MS; | 820 minIntervalMs = RTCP_INTERVAL_VIDEO_MS; |
826 } | 821 } |
827 // The interval between RTCP packets is varied randomly over the | 822 // The interval between RTCP packets is varied randomly over the |
828 // range [1/2,3/2] times the calculated interval. | 823 // range [1/2,3/2] times the calculated interval. |
829 uint32_t timeToNext = | 824 uint32_t timeToNext = |
830 random_.Rand(minIntervalMs * 1 / 2, minIntervalMs * 3 / 2); | 825 random_.Rand(minIntervalMs * 1 / 2, minIntervalMs * 3 / 2); |
831 next_time_to_send_rtcp_ = clock_->TimeInMilliseconds() + timeToNext; | 826 next_time_to_send_rtcp_ = clock_->TimeInMilliseconds() + timeToNext; |
832 | 827 |
833 if (receive_statistics_) { | 828 if (!receive_statistics_) |
834 StatisticianMap statisticians = | 829 return; |
835 receive_statistics_->GetActiveStatisticians(); | 830 RTC_DCHECK(report_blocks_.empty()); |
836 RTC_DCHECK(report_blocks_.empty()); | 831 report_blocks_ = receive_statistics_->GetActiveStatistics(); |
837 for (auto& it : statisticians) { | 832 if (report_blocks_.size() > RTCP_MAX_REPORT_BLOCKS) |
838 AddReportBlock(feedback_state, it.first, it.second); | 833 report_blocks_.resize(RTCP_MAX_REPORT_BLOCKS); |
839 } | 834 |
| 835 if (report_blocks_.empty()) |
| 836 return; |
| 837 if (feedback_state.last_rr_ntp_secs == 0 && |
| 838 feedback_state.last_rr_ntp_frac == 0) |
| 839 return; |
| 840 NtpTime ntp = clock_->CurrentNtpTime(); |
| 841 // Delay since last received report. |
| 842 uint32_t now = CompactNtp(ntp); |
| 843 |
| 844 uint32_t receive_time = feedback_state.last_rr_ntp_secs & 0x0000FFFF; |
| 845 receive_time <<= 16; |
| 846 receive_time += (feedback_state.last_rr_ntp_frac & 0xffff0000) >> 16; |
| 847 |
| 848 uint32_t delay_last_sr = now - receive_time; |
| 849 for (auto& rb : report_blocks_) { |
| 850 rb.SetLastSr(feedback_state.remote_sr); |
| 851 rb.SetDelayLastSr(delay_last_sr); |
840 } | 852 } |
841 } | 853 } |
842 } | 854 } |
843 | 855 |
844 bool RTCPSender::AddReportBlock(const FeedbackState& feedback_state, | |
845 uint32_t ssrc, | |
846 StreamStatistician* statistician) { | |
847 // Do we have receive statistics to send? | |
848 RtcpStatistics stats; | |
849 if (!statistician->GetStatistics(&stats, true)) | |
850 return false; | |
851 | |
852 if (report_blocks_.size() >= RTCP_MAX_REPORT_BLOCKS) { | |
853 LOG(LS_WARNING) << "Too many report blocks."; | |
854 return false; | |
855 } | |
856 RTC_DCHECK(report_blocks_.find(ssrc) == report_blocks_.end()); | |
857 rtcp::ReportBlock* block = &report_blocks_[ssrc]; | |
858 block->SetMediaSsrc(ssrc); | |
859 block->SetFractionLost(stats.fraction_lost); | |
860 if (!block->SetCumulativeLost(stats.cumulative_lost)) { | |
861 report_blocks_.erase(ssrc); | |
862 LOG(LS_WARNING) << "Cumulative lost is oversized."; | |
863 return false; | |
864 } | |
865 block->SetExtHighestSeqNum(stats.extended_max_sequence_number); | |
866 block->SetJitter(stats.jitter); | |
867 block->SetLastSr(feedback_state.remote_sr); | |
868 | |
869 // TODO(sprang): Do we really need separate time stamps for each report? | |
870 // Get our NTP as late as possible to avoid a race. | |
871 NtpTime ntp = clock_->CurrentNtpTime(); | |
872 | |
873 // Delay since last received report. | |
874 if ((feedback_state.last_rr_ntp_secs != 0) || | |
875 (feedback_state.last_rr_ntp_frac != 0)) { | |
876 // Get the 16 lowest bits of seconds and the 16 highest bits of fractions. | |
877 uint32_t now = CompactNtp(ntp); | |
878 | |
879 uint32_t receiveTime = feedback_state.last_rr_ntp_secs & 0x0000FFFF; | |
880 receiveTime <<= 16; | |
881 receiveTime += (feedback_state.last_rr_ntp_frac & 0xffff0000) >> 16; | |
882 | |
883 block->SetDelayLastSr(now - receiveTime); | |
884 } | |
885 return true; | |
886 } | |
887 | |
888 void RTCPSender::SetCsrcs(const std::vector<uint32_t>& csrcs) { | 856 void RTCPSender::SetCsrcs(const std::vector<uint32_t>& csrcs) { |
889 RTC_DCHECK_LE(csrcs.size(), kRtpCsrcSize); | 857 RTC_DCHECK_LE(csrcs.size(), kRtpCsrcSize); |
890 rtc::CritScope lock(&critical_section_rtcp_sender_); | 858 rtc::CritScope lock(&critical_section_rtcp_sender_); |
891 csrcs_ = csrcs; | 859 csrcs_ = csrcs; |
892 } | 860 } |
893 | 861 |
894 int32_t RTCPSender::SetApplicationSpecificData(uint8_t subType, | 862 int32_t RTCPSender::SetApplicationSpecificData(uint8_t subType, |
895 uint32_t name, | 863 uint32_t name, |
896 const uint8_t* data, | 864 const uint8_t* data, |
897 uint16_t length) { | 865 uint16_t length) { |
(...skipping 110 matching lines...) Loading... |
1008 max_packet_size = max_packet_size_; | 976 max_packet_size = max_packet_size_; |
1009 } | 977 } |
1010 | 978 |
1011 RTC_DCHECK_LE(max_packet_size, IP_PACKET_SIZE); | 979 RTC_DCHECK_LE(max_packet_size, IP_PACKET_SIZE); |
1012 uint8_t buffer[IP_PACKET_SIZE]; | 980 uint8_t buffer[IP_PACKET_SIZE]; |
1013 return packet.BuildExternalBuffer(buffer, max_packet_size, &sender) && | 981 return packet.BuildExternalBuffer(buffer, max_packet_size, &sender) && |
1014 !sender.send_failure_; | 982 !sender.send_failure_; |
1015 } | 983 } |
1016 | 984 |
1017 } // namespace webrtc | 985 } // namespace webrtc |
OLD | NEW |