diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_sender.cc b/webrtc/modules/rtp_rtcp/source/rtcp_sender.cc index 154093b156..4a509b001e 100644 --- a/webrtc/modules/rtp_rtcp/source/rtcp_sender.cc +++ b/webrtc/modules/rtp_rtcp/source/rtcp_sender.cc @@ -639,16 +639,11 @@ std::unique_ptr RTCPSender::BuildTMMBR( std::unique_ptr RTCPSender::BuildTMMBN( const RtcpContext& ctx) { - TMMBRSet* boundingSet = tmmbr_help_.BoundingSetToSend(); - if (boundingSet == nullptr) - return nullptr; - rtcp::Tmmbn* tmmbn = new rtcp::Tmmbn(); tmmbn->From(ssrc_); - for (uint32_t i = 0; i < boundingSet->lengthOfSet(); i++) { - if (boundingSet->Tmmbr(i) > 0) { - tmmbn->WithTmmbr(boundingSet->Ssrc(i), boundingSet->Tmmbr(i), - boundingSet->PacketOH(i)); + for (const rtcp::TmmbItem& tmmbr : tmmbn_to_send_) { + if (tmmbr.bitrate_bps() > 0) { + tmmbn->WithTmmbr(tmmbr); } } @@ -975,14 +970,14 @@ bool RTCPSender::RtcpXrReceiverReferenceTime() const { } // no callbacks allowed inside this function -int32_t RTCPSender::SetTMMBN(const TMMBRSet* boundingSet) { +void RTCPSender::SetTMMBN(const std::vector* bounding_set) { rtc::CritScope lock(&critical_section_rtcp_sender_); - - if (0 == tmmbr_help_.SetTMMBRBoundingSetToSend(boundingSet)) { - SetFlag(kRtcpTmmbn, true); - return 0; + if (bounding_set) { + tmmbn_to_send_ = *bounding_set; + } else { + tmmbn_to_send_.clear(); } - return -1; + SetFlag(kRtcpTmmbn, true); } void RTCPSender::SetFlag(RTCPPacketType type, bool is_volatile) { diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_sender.h b/webrtc/modules/rtp_rtcp/source/rtcp_sender.h index 4ee751f37c..02719aa1c5 100644 --- a/webrtc/modules/rtp_rtcp/source/rtcp_sender.h +++ b/webrtc/modules/rtp_rtcp/source/rtcp_sender.h @@ -135,7 +135,7 @@ class RTCPSender { void SetMaxPayloadLength(size_t max_payload_length); - int32_t SetTMMBN(const TMMBRSet* boundingSet); + void SetTMMBN(const std::vector* boundingSet); int32_t SetApplicationSpecificData(uint8_t subType, uint32_t name, @@ -241,6 +241,8 @@ class RTCPSender { std::vector remb_ssrcs_ GUARDED_BY(critical_section_rtcp_sender_); TMMBRHelp tmmbr_help_ GUARDED_BY(critical_section_rtcp_sender_); + std::vector tmmbn_to_send_ + GUARDED_BY(critical_section_rtcp_sender_); uint32_t tmmbr_send_ GUARDED_BY(critical_section_rtcp_sender_); uint32_t packet_oh_send_ GUARDED_BY(critical_section_rtcp_sender_); size_t max_payload_length_; diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_sender_unittest.cc b/webrtc/modules/rtp_rtcp/source/rtcp_sender_unittest.cc index 8817d4d3e8..a4d6e59c8f 100644 --- a/webrtc/modules/rtp_rtcp/source/rtcp_sender_unittest.cc +++ b/webrtc/modules/rtp_rtcp/source/rtcp_sender_unittest.cc @@ -688,13 +688,14 @@ TEST_F(RtcpSenderTest, TmmbrIncludedInCompoundPacketIfEnabled) { TEST_F(RtcpSenderTest, SendTmmbn) { rtcp_sender_->SetRTCPStatus(RtcpMode::kCompound); - TMMBRSet bounding_set; - bounding_set.VerifyAndAllocateSet(1); + std::vector bounding_set; const uint32_t kBitrateKbps = 32768; const uint32_t kPacketOh = 40; const uint32_t kSourceSsrc = 12345; - bounding_set.AddEntry(kBitrateKbps, kPacketOh, kSourceSsrc); - EXPECT_EQ(0, rtcp_sender_->SetTMMBN(&bounding_set)); + const rtcp::TmmbItem tmmbn(kSourceSsrc, kBitrateKbps * 1000, kPacketOh); + bounding_set.push_back(tmmbn); + rtcp_sender_->SetTMMBN(&bounding_set); + EXPECT_EQ(0, rtcp_sender_->SendRTCP(feedback_state(), kRtcpSr)); EXPECT_EQ(1, parser()->sender_report()->num_packets()); EXPECT_EQ(1, parser()->tmmbn()->num_packets()); @@ -713,8 +714,8 @@ TEST_F(RtcpSenderTest, SendTmmbn) { // situation where this caused confusion. TEST_F(RtcpSenderTest, SendsTmmbnIfSetAndEmpty) { rtcp_sender_->SetRTCPStatus(RtcpMode::kCompound); - TMMBRSet bounding_set; - EXPECT_EQ(0, rtcp_sender_->SetTMMBN(&bounding_set)); + std::vector bounding_set; + rtcp_sender_->SetTMMBN(&bounding_set); EXPECT_EQ(0, rtcp_sender_->SendRTCP(feedback_state(), kRtcpSr)); EXPECT_EQ(1, parser()->sender_report()->num_packets()); EXPECT_EQ(1, parser()->tmmbn()->num_packets()); diff --git a/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.cc b/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.cc index 8a1e2fc36c..214472f81a 100644 --- a/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.cc +++ b/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.cc @@ -680,8 +680,9 @@ void ModuleRtpRtcpImpl::SetTMMBRStatus(const bool enable) { rtcp_sender_.SetTMMBRStatus(enable); } -int32_t ModuleRtpRtcpImpl::SetTMMBN(const TMMBRSet* bounding_set) { - return rtcp_sender_.SetTMMBN(bounding_set); +void ModuleRtpRtcpImpl::SetTMMBN( + const std::vector* bounding_set) { + rtcp_sender_.SetTMMBN(bounding_set); } // Returns the currently configured retransmission mode. diff --git a/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h b/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h index 997a19b9ad..7bbb06e528 100644 --- a/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h +++ b/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h @@ -202,7 +202,7 @@ class ModuleRtpRtcpImpl : public RtpRtcp { void SetTMMBRStatus(bool enable) override; - int32_t SetTMMBN(const TMMBRSet* bounding_set); + void SetTMMBN(const std::vector* bounding_set); uint16_t MaxPayloadLength() const override; diff --git a/webrtc/modules/rtp_rtcp/source/tmmbr_help.cc b/webrtc/modules/rtp_rtcp/source/tmmbr_help.cc index af95090892..43d3a82ab2 100644 --- a/webrtc/modules/rtp_rtcp/source/tmmbr_help.cc +++ b/webrtc/modules/rtp_rtcp/source/tmmbr_help.cc @@ -69,7 +69,6 @@ void TMMBRSet::ClearEntry(uint32_t idx) { TMMBRHelp::TMMBRHelp() : _candidateSet(), _boundingSet(), - _boundingSetToSend(), _ptrIntersectionBoundingSet(NULL), _ptrMaxPRBoundingSet(NULL) { } @@ -105,39 +104,6 @@ TMMBRSet* TMMBRHelp::BoundingSet() { return &_boundingSet; } -int32_t -TMMBRHelp::SetTMMBRBoundingSetToSend(const TMMBRSet* boundingSetToSend) -{ - rtc::CritScope lock(&_criticalSection); - - if (boundingSetToSend == NULL) - { - _boundingSetToSend.clearSet(); - return 0; - } - - VerifyAndAllocateBoundingSetToSend(boundingSetToSend->lengthOfSet()); - _boundingSetToSend.clearSet(); - for (uint32_t i = 0; i < boundingSetToSend->lengthOfSet(); i++) - { - // cap at our configured max bitrate - uint32_t bitrate = boundingSetToSend->Tmmbr(i); - _boundingSetToSend.SetEntry(i, bitrate, - boundingSetToSend->PacketOH(i), - boundingSetToSend->Ssrc(i)); - } - return 0; -} - -int32_t -TMMBRHelp::VerifyAndAllocateBoundingSetToSend(uint32_t minimumSize) -{ - rtc::CritScope lock(&_criticalSection); - - _boundingSetToSend.VerifyAndAllocateSet(minimumSize); - return 0; -} - TMMBRSet* TMMBRHelp::VerifyAndAllocateCandidateSet(uint32_t minimumSize) { @@ -153,12 +119,6 @@ TMMBRHelp::CandidateSet() return &_candidateSet; } -TMMBRSet* -TMMBRHelp::BoundingSetToSend() -{ - return &_boundingSetToSend; -} - int32_t TMMBRHelp::FindTMMBRBoundingSet(TMMBRSet*& boundingSet) { diff --git a/webrtc/modules/rtp_rtcp/source/tmmbr_help.h b/webrtc/modules/rtp_rtcp/source/tmmbr_help.h index c73d53b09a..ffafb1409b 100644 --- a/webrtc/modules/rtp_rtcp/source/tmmbr_help.h +++ b/webrtc/modules/rtp_rtcp/source/tmmbr_help.h @@ -63,11 +63,9 @@ public: TMMBRSet* BoundingSet(); // used for debuging TMMBRSet* CandidateSet(); - TMMBRSet* BoundingSetToSend(); TMMBRSet* VerifyAndAllocateCandidateSet(const uint32_t minimumSize); int32_t FindTMMBRBoundingSet(TMMBRSet*& boundingSet); - int32_t SetTMMBRBoundingSetToSend(const TMMBRSet* boundingSetToSend); bool IsOwner(const uint32_t ssrc, const uint32_t length) const; @@ -75,15 +73,12 @@ public: protected: TMMBRSet* VerifyAndAllocateBoundingSet(uint32_t minimumSize); - int32_t VerifyAndAllocateBoundingSetToSend(uint32_t minimumSize); - int32_t FindTMMBRBoundingSet(int32_t numCandidates, TMMBRSet& candidateSet); private: rtc::CriticalSection _criticalSection; TMMBRSet _candidateSet; TMMBRSet _boundingSet; - TMMBRSet _boundingSetToSend; float* _ptrIntersectionBoundingSet; float* _ptrMaxPRBoundingSet;