Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1100)

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtcp_receiver.cc

Issue 2354333004: RTCPReceiver store cname as std::string. (Closed)
Patch Set: Remove RTCPCnameInformation struct Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "webrtc/modules/rtp_rtcp/source/tmmbr_help.h" 42 #include "webrtc/modules/rtp_rtcp/source/tmmbr_help.h"
43 #include "webrtc/system_wrappers/include/ntp_time.h" 43 #include "webrtc/system_wrappers/include/ntp_time.h"
44 44
45 namespace webrtc { 45 namespace webrtc {
46 namespace { 46 namespace {
47 47
48 using rtcp::CommonHeader; 48 using rtcp::CommonHeader;
49 using rtcp::ReportBlock; 49 using rtcp::ReportBlock;
50 using RTCPHelp::RTCPReceiveInformation; 50 using RTCPHelp::RTCPReceiveInformation;
51 using RTCPHelp::RTCPReportBlockInformation; 51 using RTCPHelp::RTCPReportBlockInformation;
52 using RTCPUtility::RTCPCnameInformation;
53 using RTCPUtility::RTCPPacketReportBlockItem;
54 using RTCPUtility::RTCPPacketTypes;
55 52
56 // The number of RTCP time intervals needed to trigger a timeout. 53 // The number of RTCP time intervals needed to trigger a timeout.
57 const int kRrTimeoutIntervals = 3; 54 const int kRrTimeoutIntervals = 3;
58 55
59 const int64_t kMaxWarningLogIntervalMs = 10000; 56 const int64_t kMaxWarningLogIntervalMs = 10000;
60 57
61 } // namespace 58 } // namespace
62 59
63 struct RTCPReceiver::PacketInformation { 60 struct RTCPReceiver::PacketInformation {
64 uint32_t packet_type_flags = 0; // RTCPPacketTypeFlags bit field. 61 uint32_t packet_type_flags = 0; // RTCPPacketTypeFlags bit field.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 delete it_info->second; 112 delete it_info->second;
116 info_map->erase(it_info); 113 info_map->erase(it_info);
117 } 114 }
118 } 115 }
119 while (!_receivedInfoMap.empty()) { 116 while (!_receivedInfoMap.empty()) {
120 std::map<uint32_t, RTCPReceiveInformation*>::iterator first = 117 std::map<uint32_t, RTCPReceiveInformation*>::iterator first =
121 _receivedInfoMap.begin(); 118 _receivedInfoMap.begin();
122 delete first->second; 119 delete first->second;
123 _receivedInfoMap.erase(first); 120 _receivedInfoMap.erase(first);
124 } 121 }
125 while (!_receivedCnameMap.empty()) {
126 std::map<uint32_t, RTCPCnameInformation*>::iterator first =
127 _receivedCnameMap.begin();
128 delete first->second;
129 _receivedCnameMap.erase(first);
130 }
131 } 122 }
132 123
133 bool RTCPReceiver::IncomingPacket(const uint8_t* packet, size_t packet_size) { 124 bool RTCPReceiver::IncomingPacket(const uint8_t* packet, size_t packet_size) {
134 if (packet_size == 0) { 125 if (packet_size == 0) {
135 LOG(LS_WARNING) << "Incoming empty RTCP packet"; 126 LOG(LS_WARNING) << "Incoming empty RTCP packet";
136 return false; 127 return false;
137 } 128 }
138 129
139 PacketInformation packet_information; 130 PacketInformation packet_information;
140 if (!ParseCompoundPacket(packet, packet + packet_size, &packet_information)) 131 if (!ParseCompoundPacket(packet, packet + packet_size, &packet_information))
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 return NULL; 595 return NULL;
605 } 596 }
606 const ReportBlockInfoMap* info_map = &(it->second); 597 const ReportBlockInfoMap* info_map = &(it->second);
607 ReportBlockInfoMap::const_iterator it_info = info_map->find(remote_ssrc); 598 ReportBlockInfoMap::const_iterator it_info = info_map->find(remote_ssrc);
608 if (it_info == info_map->end()) { 599 if (it_info == info_map->end()) {
609 return NULL; 600 return NULL;
610 } 601 }
611 return it_info->second; 602 return it_info->second;
612 } 603 }
613 604
614 RTCPCnameInformation* RTCPReceiver::CreateCnameInformation(
615 uint32_t remoteSSRC) {
616 rtc::CritScope lock(&_criticalSectionRTCPReceiver);
617
618 std::map<uint32_t, RTCPCnameInformation*>::iterator it =
619 _receivedCnameMap.find(remoteSSRC);
620
621 if (it != _receivedCnameMap.end()) {
622 return it->second;
623 }
624 RTCPCnameInformation* cnameInfo = new RTCPCnameInformation;
625 memset(cnameInfo->name, 0, RTCP_CNAME_SIZE);
626 _receivedCnameMap[remoteSSRC] = cnameInfo;
627 return cnameInfo;
628 }
629
630 RTCPCnameInformation* RTCPReceiver::GetCnameInformation(
631 uint32_t remoteSSRC) const {
632 rtc::CritScope lock(&_criticalSectionRTCPReceiver);
633
634 std::map<uint32_t, RTCPCnameInformation*>::const_iterator it =
635 _receivedCnameMap.find(remoteSSRC);
636
637 if (it == _receivedCnameMap.end()) {
638 return NULL;
639 }
640 return it->second;
641 }
642
643 RTCPReceiveInformation* RTCPReceiver::CreateReceiveInformation( 605 RTCPReceiveInformation* RTCPReceiver::CreateReceiveInformation(
644 uint32_t remoteSSRC) { 606 uint32_t remoteSSRC) {
645 rtc::CritScope lock(&_criticalSectionRTCPReceiver); 607 rtc::CritScope lock(&_criticalSectionRTCPReceiver);
646 608
647 std::map<uint32_t, RTCPReceiveInformation*>::iterator it = 609 std::map<uint32_t, RTCPReceiveInformation*>::iterator it =
648 _receivedInfoMap.find(remoteSSRC); 610 _receivedInfoMap.find(remoteSSRC);
649 611
650 if (it != _receivedInfoMap.end()) { 612 if (it != _receivedInfoMap.end()) {
651 return it->second; 613 return it->second;
652 } 614 }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 720
759 void RTCPReceiver::HandleSDES(const CommonHeader& rtcp_block, 721 void RTCPReceiver::HandleSDES(const CommonHeader& rtcp_block,
760 PacketInformation* packet_information) { 722 PacketInformation* packet_information) {
761 rtcp::Sdes sdes; 723 rtcp::Sdes sdes;
762 if (!sdes.Parse(rtcp_block)) { 724 if (!sdes.Parse(rtcp_block)) {
763 ++num_skipped_packets_; 725 ++num_skipped_packets_;
764 return; 726 return;
765 } 727 }
766 728
767 for (const rtcp::Sdes::Chunk& chunk : sdes.chunks()) { 729 for (const rtcp::Sdes::Chunk& chunk : sdes.chunks()) {
768 RTCPCnameInformation* cnameInfo = CreateCnameInformation(chunk.ssrc); 730 received_cnames_[chunk.ssrc] = chunk.cname;
769 RTC_DCHECK(cnameInfo);
770
771 cnameInfo->name[RTCP_CNAME_SIZE - 1] = 0;
772 strncpy(cnameInfo->name, chunk.cname.c_str(), RTCP_CNAME_SIZE - 1);
773 { 731 {
774 rtc::CritScope lock(&_criticalSectionFeedbacks); 732 rtc::CritScope lock(&_criticalSectionFeedbacks);
775 if (stats_callback_) 733 if (stats_callback_)
776 stats_callback_->CNameChanged(chunk.cname.c_str(), chunk.ssrc); 734 stats_callback_->CNameChanged(chunk.cname.c_str(), chunk.ssrc);
777 } 735 }
778 } 736 }
779 packet_information->packet_type_flags |= kRtcpSdes; 737 packet_information->packet_type_flags |= kRtcpSdes;
780 } 738 }
781 739
782 void RTCPReceiver::HandleNACK(const CommonHeader& rtcp_block, 740 void RTCPReceiver::HandleNACK(const CommonHeader& rtcp_block,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 } 778 }
821 } 779 }
822 780
823 // we can't delete it due to TMMBR 781 // we can't delete it due to TMMBR
824 std::map<uint32_t, RTCPReceiveInformation*>::iterator receiveInfoIt = 782 std::map<uint32_t, RTCPReceiveInformation*>::iterator receiveInfoIt =
825 _receivedInfoMap.find(bye.sender_ssrc()); 783 _receivedInfoMap.find(bye.sender_ssrc());
826 784
827 if (receiveInfoIt != _receivedInfoMap.end()) 785 if (receiveInfoIt != _receivedInfoMap.end())
828 receiveInfoIt->second->ready_for_delete = true; 786 receiveInfoIt->second->ready_for_delete = true;
829 787
830 std::map<uint32_t, RTCPCnameInformation*>::iterator cnameInfoIt = 788 received_cnames_.erase(bye.sender_ssrc());
831 _receivedCnameMap.find(bye.sender_ssrc());
832
833 if (cnameInfoIt != _receivedCnameMap.end()) {
834 delete cnameInfoIt->second;
835 _receivedCnameMap.erase(cnameInfoIt);
836 }
837 xr_rr_rtt_ms_ = 0; 789 xr_rr_rtt_ms_ = 0;
838 } 790 }
839 791
840 void RTCPReceiver::HandleXr(const CommonHeader& rtcp_block, 792 void RTCPReceiver::HandleXr(const CommonHeader& rtcp_block,
841 PacketInformation* packet_information) { 793 PacketInformation* packet_information) {
842 rtcp::ExtendedReports xr; 794 rtcp::ExtendedReports xr;
843 if (!xr.Parse(rtcp_block)) { 795 if (!xr.Parse(rtcp_block)) {
844 ++num_skipped_packets_; 796 ++num_skipped_packets_;
845 return; 797 return;
846 } 798 }
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 stats.jitter = report_block.jitter; 1131 stats.jitter = report_block.jitter;
1180 1132
1181 stats_callback_->StatisticsUpdated(stats, report_block.sourceSSRC); 1133 stats_callback_->StatisticsUpdated(stats, report_block.sourceSSRC);
1182 } 1134 }
1183 } 1135 }
1184 } 1136 }
1185 } 1137 }
1186 1138
1187 int32_t RTCPReceiver::CNAME(uint32_t remoteSSRC, 1139 int32_t RTCPReceiver::CNAME(uint32_t remoteSSRC,
1188 char cName[RTCP_CNAME_SIZE]) const { 1140 char cName[RTCP_CNAME_SIZE]) const {
1189 assert(cName); 1141 RTC_DCHECK(cName);
1190 1142
1191 rtc::CritScope lock(&_criticalSectionRTCPReceiver); 1143 rtc::CritScope lock(&_criticalSectionRTCPReceiver);
1192 RTCPCnameInformation* cnameInfo = GetCnameInformation(remoteSSRC); 1144 auto received_cname_it = received_cnames_.find(remoteSSRC);
1193 if (cnameInfo == NULL) { 1145 if (received_cname_it == received_cnames_.end())
1194 return -1; 1146 return -1;
1195 } 1147
1196 cName[RTCP_CNAME_SIZE - 1] = 0; 1148 size_t length = received_cname_it->second.copy(cName, RTCP_CNAME_SIZE - 1);
1197 strncpy(cName, cnameInfo->name, RTCP_CNAME_SIZE - 1); 1149 cName[length] = 0;
1198 return 0; 1150 return 0;
1199 } 1151 }
1200 1152
1201 std::vector<rtcp::TmmbItem> RTCPReceiver::TmmbrReceived() const { 1153 std::vector<rtcp::TmmbItem> RTCPReceiver::TmmbrReceived() const {
1202 rtc::CritScope lock(&_criticalSectionRTCPReceiver); 1154 rtc::CritScope lock(&_criticalSectionRTCPReceiver);
1203 std::vector<rtcp::TmmbItem> candidates; 1155 std::vector<rtcp::TmmbItem> candidates;
1204 1156
1205 int64_t now_ms = _clock->TimeInMilliseconds(); 1157 int64_t now_ms = _clock->TimeInMilliseconds();
1206 1158
1207 for (const auto& kv : _receivedInfoMap) { 1159 for (const auto& kv : _receivedInfoMap) {
1208 RTCPReceiveInformation* receive_info = kv.second; 1160 RTCPReceiveInformation* receive_info = kv.second;
1209 RTC_DCHECK(receive_info); 1161 RTC_DCHECK(receive_info);
1210 receive_info->GetTmmbrSet(now_ms, &candidates); 1162 receive_info->GetTmmbrSet(now_ms, &candidates);
1211 } 1163 }
1212 return candidates; 1164 return candidates;
1213 } 1165 }
1214 1166
1215 } // namespace webrtc 1167 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtcp_receiver.h ('k') | webrtc/modules/rtp_rtcp/source/rtcp_utility.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698