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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
190 builders_[kRtcpPli] = &RTCPSender::BuildPLI; | 190 builders_[kRtcpPli] = &RTCPSender::BuildPLI; |
191 builders_[kRtcpFir] = &RTCPSender::BuildFIR; | 191 builders_[kRtcpFir] = &RTCPSender::BuildFIR; |
192 builders_[kRtcpSli] = &RTCPSender::BuildSLI; | 192 builders_[kRtcpSli] = &RTCPSender::BuildSLI; |
193 builders_[kRtcpRpsi] = &RTCPSender::BuildRPSI; | 193 builders_[kRtcpRpsi] = &RTCPSender::BuildRPSI; |
194 builders_[kRtcpRemb] = &RTCPSender::BuildREMB; | 194 builders_[kRtcpRemb] = &RTCPSender::BuildREMB; |
195 builders_[kRtcpBye] = &RTCPSender::BuildBYE; | 195 builders_[kRtcpBye] = &RTCPSender::BuildBYE; |
196 builders_[kRtcpApp] = &RTCPSender::BuildAPP; | 196 builders_[kRtcpApp] = &RTCPSender::BuildAPP; |
197 builders_[kRtcpTmmbr] = &RTCPSender::BuildTMMBR; | 197 builders_[kRtcpTmmbr] = &RTCPSender::BuildTMMBR; |
198 builders_[kRtcpTmmbn] = &RTCPSender::BuildTMMBN; | 198 builders_[kRtcpTmmbn] = &RTCPSender::BuildTMMBN; |
199 builders_[kRtcpNack] = &RTCPSender::BuildNACK; | 199 builders_[kRtcpNack] = &RTCPSender::BuildNACK; |
200 builders_[kRtcpXrVoipMetric] = &RTCPSender::BuildVoIPMetric; | 200 builders_[kRtcpAnyExtendedReports] = &RTCPSender::BuildExtendedReports; |
201 builders_[kRtcpXrReceiverReferenceTime] = | |
202 &RTCPSender::BuildReceiverReferenceTime; | |
203 builders_[kRtcpXrDlrrReportBlock] = &RTCPSender::BuildDlrr; | |
204 } | 201 } |
205 | 202 |
206 RTCPSender::~RTCPSender() {} | 203 RTCPSender::~RTCPSender() {} |
207 | 204 |
208 RtcpMode RTCPSender::Status() const { | 205 RtcpMode RTCPSender::Status() const { |
209 rtc::CritScope lock(&critical_section_rtcp_sender_); | 206 rtc::CritScope lock(&critical_section_rtcp_sender_); |
210 return method_; | 207 return method_; |
211 } | 208 } |
212 | 209 |
213 void RTCPSender::SetRTCPStatus(RtcpMode new_method) { | 210 void RTCPSender::SetRTCPStatus(RtcpMode new_method) { |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
685 } | 682 } |
686 | 683 |
687 std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildBYE(const RtcpContext& ctx) { | 684 std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildBYE(const RtcpContext& ctx) { |
688 rtcp::Bye* bye = new rtcp::Bye(); | 685 rtcp::Bye* bye = new rtcp::Bye(); |
689 bye->SetSenderSsrc(ssrc_); | 686 bye->SetSenderSsrc(ssrc_); |
690 bye->SetCsrcs(csrcs_); | 687 bye->SetCsrcs(csrcs_); |
691 | 688 |
692 return std::unique_ptr<rtcp::RtcpPacket>(bye); | 689 return std::unique_ptr<rtcp::RtcpPacket>(bye); |
693 } | 690 } |
694 | 691 |
695 std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildReceiverReferenceTime( | 692 std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildExtendedReports( |
696 const RtcpContext& ctx) { | 693 const RtcpContext& ctx) { |
697 | 694 std::unique_ptr<rtcp::ExtendedReports> xr(new rtcp::ExtendedReports()); |
698 rtcp::ExtendedReports* xr = new rtcp::ExtendedReports(); | |
699 xr->SetSenderSsrc(ssrc_); | 695 xr->SetSenderSsrc(ssrc_); |
700 | 696 |
701 rtcp::Rrtr rrtr; | 697 if (!sending_ && xr_send_receiver_reference_time_enabled_) { |
702 rrtr.SetNtp(NtpTime(ctx.ntp_sec_, ctx.ntp_frac_)); | 698 rtcp::Rrtr rrtr; |
699 rrtr.SetNtp(NtpTime(ctx.ntp_sec_, ctx.ntp_frac_)); | |
700 xr->SetRrtr(rrtr); | |
701 } | |
703 | 702 |
704 xr->SetRrtr(rrtr); | 703 if (ctx.feedback_state_.has_last_xr_rr) { |
704 xr->AddDlrrItem(ctx.feedback_state_.last_xr_rr); | |
705 } | |
705 | 706 |
706 // TODO(sprang): Merge XR report sending to contain all of RRTR, DLRR, VOIP? | 707 if (video_bitrate_allocation_) { |
708 rtcp::TargetBitrate target_bitrate; | |
707 | 709 |
708 return std::unique_ptr<rtcp::RtcpPacket>(xr); | 710 for (int sl = 0; sl < kMaxSpatialLayers; ++sl) { |
709 } | 711 for (int tl = 0; tl < kMaxTemporalStreams; ++tl) { |
712 uint32_t layer_bitrate_bps = | |
713 video_bitrate_allocation_->GetBitrate(sl, tl); | |
714 if (layer_bitrate_bps > 0) | |
715 target_bitrate.AddTargetBitrate(sl, tl, layer_bitrate_bps / 1000); | |
716 } | |
717 } | |
710 | 718 |
711 std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildDlrr( | 719 xr->SetTargetBitrate(target_bitrate); |
712 const RtcpContext& ctx) { | 720 video_bitrate_allocation_.reset(); |
713 rtcp::ExtendedReports* xr = new rtcp::ExtendedReports(); | 721 } |
714 xr->SetSenderSsrc(ssrc_); | |
715 RTC_DCHECK(ctx.feedback_state_.has_last_xr_rr); | |
716 xr->AddDlrrItem(ctx.feedback_state_.last_xr_rr); | |
717 | 722 |
718 return std::unique_ptr<rtcp::RtcpPacket>(xr); | 723 if (xr_voip_metric_) { |
719 } | 724 rtcp::VoipMetric voip; |
725 voip.SetMediaSsrc(remote_ssrc_); | |
726 voip.SetVoipMetric(*xr_voip_metric_); | |
727 xr_voip_metric_.reset(); | |
720 | 728 |
721 std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildVoIPMetric( | 729 xr->SetVoipMetric(voip); |
722 const RtcpContext& context) { | 730 } |
723 rtcp::ExtendedReports* xr = new rtcp::ExtendedReports(); | |
724 xr->SetSenderSsrc(ssrc_); | |
725 | 731 |
726 rtcp::VoipMetric voip; | 732 return std::move(xr); |
727 voip.SetMediaSsrc(remote_ssrc_); | |
728 voip.SetVoipMetric(xr_voip_metric_); | |
729 | |
730 xr->SetVoipMetric(voip); | |
731 | |
732 return std::unique_ptr<rtcp::RtcpPacket>(xr); | |
733 } | 733 } |
734 | 734 |
735 int32_t RTCPSender::SendRTCP(const FeedbackState& feedback_state, | 735 int32_t RTCPSender::SendRTCP(const FeedbackState& feedback_state, |
736 RTCPPacketType packetType, | 736 RTCPPacketType packetType, |
737 int32_t nack_size, | 737 int32_t nack_size, |
738 const uint16_t* nack_list, | 738 const uint16_t* nack_list, |
739 bool repeat, | 739 bool repeat, |
740 uint64_t pictureID) { | 740 uint64_t pictureID) { |
741 return SendCompoundRTCP( | 741 return SendCompoundRTCP( |
742 feedback_state, std::set<RTCPPacketType>(&packetType, &packetType + 1), | 742 feedback_state, std::set<RTCPPacketType>(&packetType, &packetType + 1), |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
787 RtcpContext context(feedback_state, nack_size, nack_list, repeat, pictureID, | 787 RtcpContext context(feedback_state, nack_size, nack_list, repeat, pictureID, |
788 ntp_sec, ntp_frac); | 788 ntp_sec, ntp_frac); |
789 | 789 |
790 PrepareReport(feedback_state); | 790 PrepareReport(feedback_state); |
791 | 791 |
792 std::unique_ptr<rtcp::RtcpPacket> packet_bye; | 792 std::unique_ptr<rtcp::RtcpPacket> packet_bye; |
793 | 793 |
794 auto it = report_flags_.begin(); | 794 auto it = report_flags_.begin(); |
795 while (it != report_flags_.end()) { | 795 while (it != report_flags_.end()) { |
796 auto builder_it = builders_.find(it->type); | 796 auto builder_it = builders_.find(it->type); |
797 RTC_DCHECK(builder_it != builders_.end()); | 797 RTC_DCHECK(builder_it != builders_.end()) |
798 << "Could not find builder for packet type " << it->type; | |
798 if (it->is_volatile) { | 799 if (it->is_volatile) { |
799 report_flags_.erase(it++); | 800 report_flags_.erase(it++); |
800 } else { | 801 } else { |
801 ++it; | 802 ++it; |
802 } | 803 } |
803 | 804 |
804 BuilderFunc func = builder_it->second; | 805 BuilderFunc func = builder_it->second; |
805 std::unique_ptr<rtcp::RtcpPacket> packet = (this->*func)(context); | 806 std::unique_ptr<rtcp::RtcpPacket> packet = (this->*func)(context); |
806 if (packet.get() == nullptr) | 807 if (packet.get() == nullptr) |
807 return -1; | 808 return -1; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
842 (ConsumeFlag(kRtcpReport) && method_ == RtcpMode::kReducedSize) || | 843 (ConsumeFlag(kRtcpReport) && method_ == RtcpMode::kReducedSize) || |
843 method_ == RtcpMode::kCompound; | 844 method_ == RtcpMode::kCompound; |
844 if (generate_report) | 845 if (generate_report) |
845 SetFlag(sending_ ? kRtcpSr : kRtcpRr, true); | 846 SetFlag(sending_ ? kRtcpSr : kRtcpRr, true); |
846 } | 847 } |
847 | 848 |
848 if (IsFlagPresent(kRtcpSr) || (IsFlagPresent(kRtcpRr) && !cname_.empty())) | 849 if (IsFlagPresent(kRtcpSr) || (IsFlagPresent(kRtcpRr) && !cname_.empty())) |
849 SetFlag(kRtcpSdes, true); | 850 SetFlag(kRtcpSdes, true); |
850 | 851 |
851 if (generate_report) { | 852 if (generate_report) { |
852 if (!sending_ && xr_send_receiver_reference_time_enabled_) | 853 if ((!sending_ && xr_send_receiver_reference_time_enabled_) || |
853 SetFlag(kRtcpXrReceiverReferenceTime, true); | 854 feedback_state.has_last_xr_rr || video_bitrate_allocation_) { |
stefan-webrtc
2016/12/01 08:42:20
Seems like we now have two checks for this. First
sprang_webrtc
2016/12/01 10:47:58
Because we don't want to have separate builders fo
| |
854 if (feedback_state.has_last_xr_rr) | 855 SetFlag(kRtcpAnyExtendedReports, true); |
855 SetFlag(kRtcpXrDlrrReportBlock, true); | 856 } |
856 | 857 |
857 // generate next time to send an RTCP report | 858 // generate next time to send an RTCP report |
858 uint32_t minIntervalMs = RTCP_INTERVAL_AUDIO_MS; | 859 uint32_t minIntervalMs = RTCP_INTERVAL_AUDIO_MS; |
859 | 860 |
860 if (!audio_) { | 861 if (!audio_) { |
861 if (sending_) { | 862 if (sending_) { |
862 // Calculate bandwidth for video; 360 / send bandwidth in kbit/s. | 863 // Calculate bandwidth for video; 360 / send bandwidth in kbit/s. |
863 uint32_t send_bitrate_kbit = feedback_state.send_bitrate / 1000; | 864 uint32_t send_bitrate_kbit = feedback_state.send_bitrate / 1000; |
864 if (send_bitrate_kbit != 0) | 865 if (send_bitrate_kbit != 0) |
865 minIntervalMs = 360000 / send_bitrate_kbit; | 866 minIntervalMs = 360000 / send_bitrate_kbit; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
952 app_sub_type_ = subType; | 953 app_sub_type_ = subType; |
953 app_name_ = name; | 954 app_name_ = name; |
954 app_data_.reset(new uint8_t[length]); | 955 app_data_.reset(new uint8_t[length]); |
955 app_length_ = length; | 956 app_length_ = length; |
956 memcpy(app_data_.get(), data, length); | 957 memcpy(app_data_.get(), data, length); |
957 return 0; | 958 return 0; |
958 } | 959 } |
959 | 960 |
960 int32_t RTCPSender::SetRTCPVoIPMetrics(const RTCPVoIPMetric* VoIPMetric) { | 961 int32_t RTCPSender::SetRTCPVoIPMetrics(const RTCPVoIPMetric* VoIPMetric) { |
961 rtc::CritScope lock(&critical_section_rtcp_sender_); | 962 rtc::CritScope lock(&critical_section_rtcp_sender_); |
962 memcpy(&xr_voip_metric_, VoIPMetric, sizeof(RTCPVoIPMetric)); | 963 xr_voip_metric_.emplace(*VoIPMetric); |
963 | 964 |
964 SetFlag(kRtcpXrVoipMetric, true); | 965 SetFlag(kRtcpAnyExtendedReports, true); |
965 return 0; | 966 return 0; |
966 } | 967 } |
967 | 968 |
968 void RTCPSender::SendRtcpXrReceiverReferenceTime(bool enable) { | 969 void RTCPSender::SendRtcpXrReceiverReferenceTime(bool enable) { |
969 rtc::CritScope lock(&critical_section_rtcp_sender_); | 970 rtc::CritScope lock(&critical_section_rtcp_sender_); |
970 xr_send_receiver_reference_time_enabled_ = enable; | 971 xr_send_receiver_reference_time_enabled_ = enable; |
971 } | 972 } |
972 | 973 |
973 bool RTCPSender::RtcpXrReceiverReferenceTime() const { | 974 bool RTCPSender::RtcpXrReceiverReferenceTime() const { |
974 rtc::CritScope lock(&critical_section_rtcp_sender_); | 975 rtc::CritScope lock(&critical_section_rtcp_sender_); |
975 return xr_send_receiver_reference_time_enabled_; | 976 return xr_send_receiver_reference_time_enabled_; |
976 } | 977 } |
977 | 978 |
978 void RTCPSender::SetTmmbn(std::vector<rtcp::TmmbItem> bounding_set) { | 979 void RTCPSender::SetTmmbn(std::vector<rtcp::TmmbItem> bounding_set) { |
979 rtc::CritScope lock(&critical_section_rtcp_sender_); | 980 rtc::CritScope lock(&critical_section_rtcp_sender_); |
980 tmmbn_to_send_ = std::move(bounding_set); | 981 tmmbn_to_send_ = std::move(bounding_set); |
981 SetFlag(kRtcpTmmbn, true); | 982 SetFlag(kRtcpTmmbn, true); |
982 } | 983 } |
983 | 984 |
984 void RTCPSender::SetFlag(RTCPPacketType type, bool is_volatile) { | 985 void RTCPSender::SetFlag(RTCPPacketType type, bool is_volatile) { |
985 report_flags_.insert(ReportFlag(type, is_volatile)); | 986 report_flags_.insert(ReportFlag(type, is_volatile)); |
986 } | 987 } |
987 | 988 |
988 void RTCPSender::SetFlags(const std::set<RTCPPacketType>& types, | 989 void RTCPSender::SetFlags(const std::set<RTCPPacketType>& types, |
989 bool is_volatile) { | 990 bool is_volatile) { |
990 for (RTCPPacketType type : types) | 991 for (RTCPPacketType type : types) { |
991 SetFlag(type, is_volatile); | 992 if (type & kRtcpAnyExtendedReports) { |
993 SetFlag(kRtcpAnyExtendedReports, is_volatile); | |
994 } else { | |
995 SetFlag(type, is_volatile); | |
996 } | |
997 } | |
992 } | 998 } |
993 | 999 |
994 bool RTCPSender::IsFlagPresent(RTCPPacketType type) const { | 1000 bool RTCPSender::IsFlagPresent(RTCPPacketType type) const { |
995 return report_flags_.find(ReportFlag(type, false)) != report_flags_.end(); | 1001 return report_flags_.find(ReportFlag(type, false)) != report_flags_.end(); |
996 } | 1002 } |
997 | 1003 |
998 bool RTCPSender::ConsumeFlag(RTCPPacketType type, bool forced) { | 1004 bool RTCPSender::ConsumeFlag(RTCPPacketType type, bool forced) { |
999 auto it = report_flags_.find(ReportFlag(type, false)); | 1005 auto it = report_flags_.find(ReportFlag(type, false)); |
1000 if (it == report_flags_.end()) | 1006 if (it == report_flags_.end()) |
1001 return false; | 1007 return false; |
1002 if (it->is_volatile || forced) | 1008 if (it->is_volatile || forced) |
1003 report_flags_.erase((it)); | 1009 report_flags_.erase((it)); |
1004 return true; | 1010 return true; |
1005 } | 1011 } |
1006 | 1012 |
1007 bool RTCPSender::AllVolatileFlagsConsumed() const { | 1013 bool RTCPSender::AllVolatileFlagsConsumed() const { |
1008 for (const ReportFlag& flag : report_flags_) { | 1014 for (const ReportFlag& flag : report_flags_) { |
1009 if (flag.is_volatile) | 1015 if (flag.is_volatile) |
1010 return false; | 1016 return false; |
1011 } | 1017 } |
1012 return true; | 1018 return true; |
1013 } | 1019 } |
1014 | 1020 |
1021 void RTCPSender::SetVideoBitrateAllocation(const BitrateAllocation& bitrate) { | |
1022 rtc::CritScope lock(&critical_section_rtcp_sender_); | |
1023 video_bitrate_allocation_.emplace(bitrate); | |
1024 } | |
1025 | |
1015 bool RTCPSender::SendFeedbackPacket(const rtcp::TransportFeedback& packet) { | 1026 bool RTCPSender::SendFeedbackPacket(const rtcp::TransportFeedback& packet) { |
1016 class Sender : public rtcp::RtcpPacket::PacketReadyCallback { | 1027 class Sender : public rtcp::RtcpPacket::PacketReadyCallback { |
1017 public: | 1028 public: |
1018 Sender(Transport* transport, RtcEventLog* event_log) | 1029 Sender(Transport* transport, RtcEventLog* event_log) |
1019 : transport_(transport), event_log_(event_log), send_failure_(false) {} | 1030 : transport_(transport), event_log_(event_log), send_failure_(false) {} |
1020 | 1031 |
1021 void OnPacketReady(uint8_t* data, size_t length) override { | 1032 void OnPacketReady(uint8_t* data, size_t length) override { |
1022 if (transport_->SendRtcp(data, length)) { | 1033 if (transport_->SendRtcp(data, length)) { |
1023 if (event_log_) { | 1034 if (event_log_) { |
1024 event_log_->LogRtcpPacket(kOutgoingPacket, MediaType::ANY, data, | 1035 event_log_->LogRtcpPacket(kOutgoingPacket, MediaType::ANY, data, |
(...skipping 12 matching lines...) Expand all Loading... | |
1037 // but we can't because of an incorrect warning (C4822) in MVS 2013. | 1048 // but we can't because of an incorrect warning (C4822) in MVS 2013. |
1038 } sender(transport_, event_log_); | 1049 } sender(transport_, event_log_); |
1039 | 1050 |
1040 RTC_DCHECK_LE(max_payload_length_, static_cast<size_t>(IP_PACKET_SIZE)); | 1051 RTC_DCHECK_LE(max_payload_length_, static_cast<size_t>(IP_PACKET_SIZE)); |
1041 uint8_t buffer[IP_PACKET_SIZE]; | 1052 uint8_t buffer[IP_PACKET_SIZE]; |
1042 return packet.BuildExternalBuffer(buffer, max_payload_length_, &sender) && | 1053 return packet.BuildExternalBuffer(buffer, max_payload_length_, &sender) && |
1043 !sender.send_failure_; | 1054 !sender.send_failure_; |
1044 } | 1055 } |
1045 | 1056 |
1046 } // namespace webrtc | 1057 } // namespace webrtc |
OLD | NEW |