From 95321246593bc5fa1f0d60fff6edba0d2fb13342 Mon Sep 17 00:00:00 2001 From: danilchap Date: Tue, 27 Sep 2016 07:05:32 -0700 Subject: [PATCH] RTCPReceiver store cname as std::string. simplifying cname management. Remove RTCPUtility::RTCPCnameInformation since it was last use of the structure. BUG=webrtc:5565 NOTRY=true Review-Url: https://codereview.webrtc.org/2354333004 Cr-Commit-Position: refs/heads/master@{#14399} --- .../modules/rtp_rtcp/source/rtcp_receiver.cc | 64 +++---------------- .../modules/rtp_rtcp/source/rtcp_receiver.h | 9 +-- webrtc/modules/rtp_rtcp/source/rtcp_utility.h | 4 -- 3 files changed, 11 insertions(+), 66 deletions(-) diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_receiver.cc b/webrtc/modules/rtp_rtcp/source/rtcp_receiver.cc index d81b3831f0..638922cdcc 100644 --- a/webrtc/modules/rtp_rtcp/source/rtcp_receiver.cc +++ b/webrtc/modules/rtp_rtcp/source/rtcp_receiver.cc @@ -49,9 +49,6 @@ using rtcp::CommonHeader; using rtcp::ReportBlock; using RTCPHelp::RTCPReceiveInformation; using RTCPHelp::RTCPReportBlockInformation; -using RTCPUtility::RTCPCnameInformation; -using RTCPUtility::RTCPPacketReportBlockItem; -using RTCPUtility::RTCPPacketTypes; // The number of RTCP time intervals needed to trigger a timeout. const int kRrTimeoutIntervals = 3; @@ -122,12 +119,6 @@ RTCPReceiver::~RTCPReceiver() { delete first->second; _receivedInfoMap.erase(first); } - while (!_receivedCnameMap.empty()) { - std::map::iterator first = - _receivedCnameMap.begin(); - delete first->second; - _receivedCnameMap.erase(first); - } } bool RTCPReceiver::IncomingPacket(const uint8_t* packet, size_t packet_size) { @@ -611,35 +602,6 @@ RTCPReportBlockInformation* RTCPReceiver::GetReportBlockInformation( return it_info->second; } -RTCPCnameInformation* RTCPReceiver::CreateCnameInformation( - uint32_t remoteSSRC) { - rtc::CritScope lock(&_criticalSectionRTCPReceiver); - - std::map::iterator it = - _receivedCnameMap.find(remoteSSRC); - - if (it != _receivedCnameMap.end()) { - return it->second; - } - RTCPCnameInformation* cnameInfo = new RTCPCnameInformation; - memset(cnameInfo->name, 0, RTCP_CNAME_SIZE); - _receivedCnameMap[remoteSSRC] = cnameInfo; - return cnameInfo; -} - -RTCPCnameInformation* RTCPReceiver::GetCnameInformation( - uint32_t remoteSSRC) const { - rtc::CritScope lock(&_criticalSectionRTCPReceiver); - - std::map::const_iterator it = - _receivedCnameMap.find(remoteSSRC); - - if (it == _receivedCnameMap.end()) { - return NULL; - } - return it->second; -} - RTCPReceiveInformation* RTCPReceiver::CreateReceiveInformation( uint32_t remoteSSRC) { rtc::CritScope lock(&_criticalSectionRTCPReceiver); @@ -765,11 +727,7 @@ void RTCPReceiver::HandleSDES(const CommonHeader& rtcp_block, } for (const rtcp::Sdes::Chunk& chunk : sdes.chunks()) { - RTCPCnameInformation* cnameInfo = CreateCnameInformation(chunk.ssrc); - RTC_DCHECK(cnameInfo); - - cnameInfo->name[RTCP_CNAME_SIZE - 1] = 0; - strncpy(cnameInfo->name, chunk.cname.c_str(), RTCP_CNAME_SIZE - 1); + received_cnames_[chunk.ssrc] = chunk.cname; { rtc::CritScope lock(&_criticalSectionFeedbacks); if (stats_callback_) @@ -827,13 +785,7 @@ void RTCPReceiver::HandleBYE(const CommonHeader& rtcp_block) { if (receiveInfoIt != _receivedInfoMap.end()) receiveInfoIt->second->ready_for_delete = true; - std::map::iterator cnameInfoIt = - _receivedCnameMap.find(bye.sender_ssrc()); - - if (cnameInfoIt != _receivedCnameMap.end()) { - delete cnameInfoIt->second; - _receivedCnameMap.erase(cnameInfoIt); - } + received_cnames_.erase(bye.sender_ssrc()); xr_rr_rtt_ms_ = 0; } @@ -1186,15 +1138,15 @@ void RTCPReceiver::TriggerCallbacksFromRTCPPacket( int32_t RTCPReceiver::CNAME(uint32_t remoteSSRC, char cName[RTCP_CNAME_SIZE]) const { - assert(cName); + RTC_DCHECK(cName); rtc::CritScope lock(&_criticalSectionRTCPReceiver); - RTCPCnameInformation* cnameInfo = GetCnameInformation(remoteSSRC); - if (cnameInfo == NULL) { + auto received_cname_it = received_cnames_.find(remoteSSRC); + if (received_cname_it == received_cnames_.end()) return -1; - } - cName[RTCP_CNAME_SIZE - 1] = 0; - strncpy(cName, cnameInfo->name, RTCP_CNAME_SIZE - 1); + + size_t length = received_cname_it->second.copy(cName, RTCP_CNAME_SIZE - 1); + cName[length] = 0; return 0; } diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_receiver.h b/webrtc/modules/rtp_rtcp/source/rtcp_receiver.h index 5e3ab07814..0fbcdbcc6d 100644 --- a/webrtc/modules/rtp_rtcp/source/rtcp_receiver.h +++ b/webrtc/modules/rtp_rtcp/source/rtcp_receiver.h @@ -13,6 +13,7 @@ #include #include +#include #include #include "webrtc/base/criticalsection.h" @@ -127,11 +128,6 @@ class RTCPReceiver { void TriggerCallbacksFromRTCPPacket( const PacketInformation& packet_information); - RTCPUtility::RTCPCnameInformation* CreateCnameInformation( - uint32_t remoteSSRC); - RTCPUtility::RTCPCnameInformation* GetCnameInformation( - uint32_t remoteSSRC) const; - RTCPHelp::RTCPReceiveInformation* CreateReceiveInformation( uint32_t remoteSSRC); RTCPHelp::RTCPReceiveInformation* GetReceiveInformation(uint32_t remoteSSRC); @@ -249,7 +245,8 @@ class RTCPReceiver { ReportBlockMap _receivedReportBlockMap GUARDED_BY(_criticalSectionRTCPReceiver); ReceivedInfoMap _receivedInfoMap; - std::map _receivedCnameMap; + std::map received_cnames_ + GUARDED_BY(_criticalSectionRTCPReceiver); // The last time we received an RTCP RR. int64_t _lastReceivedRrMs; diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_utility.h b/webrtc/modules/rtp_rtcp/source/rtcp_utility.h index 629de4e99e..86fee8ea68 100644 --- a/webrtc/modules/rtp_rtcp/source/rtcp_utility.h +++ b/webrtc/modules/rtp_rtcp/source/rtcp_utility.h @@ -49,10 +49,6 @@ class NackStats { uint32_t MidNtp(uint32_t ntp_sec, uint32_t ntp_frac); -// CNAME -struct RTCPCnameInformation { - char name[RTCP_CNAME_SIZE]; -}; struct RTCPPacketRR { uint32_t SenderSSRC; uint8_t NumberOfReportBlocks;