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

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

Issue 1474693002: [Splitting] TMMBRHelp class simplifted (and disappear because become too simple) (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 7 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 26 matching lines...) Expand all
37 const int64_t kMaxWarningLogIntervalMs = 10000; 37 const int64_t kMaxWarningLogIntervalMs = 10000;
38 38
39 RTCPReceiver::RTCPReceiver( 39 RTCPReceiver::RTCPReceiver(
40 Clock* clock, 40 Clock* clock,
41 bool receiver_only, 41 bool receiver_only,
42 RtcpPacketTypeCounterObserver* packet_type_counter_observer, 42 RtcpPacketTypeCounterObserver* packet_type_counter_observer,
43 RtcpBandwidthObserver* rtcp_bandwidth_observer, 43 RtcpBandwidthObserver* rtcp_bandwidth_observer,
44 RtcpIntraFrameObserver* rtcp_intra_frame_observer, 44 RtcpIntraFrameObserver* rtcp_intra_frame_observer,
45 TransportFeedbackObserver* transport_feedback_observer, 45 TransportFeedbackObserver* transport_feedback_observer,
46 ModuleRtpRtcpImpl* owner) 46 ModuleRtpRtcpImpl* owner)
47 : TMMBRHelp(), 47 : _clock(clock),
48 _clock(clock),
49 receiver_only_(receiver_only), 48 receiver_only_(receiver_only),
50 _lastReceived(0), 49 _lastReceived(0),
51 _rtpRtcp(*owner), 50 _rtpRtcp(*owner),
52 _cbRtcpBandwidthObserver(rtcp_bandwidth_observer), 51 _cbRtcpBandwidthObserver(rtcp_bandwidth_observer),
53 _cbRtcpIntraFrameObserver(rtcp_intra_frame_observer), 52 _cbRtcpIntraFrameObserver(rtcp_intra_frame_observer),
54 _cbTransportFeedbackObserver(transport_feedback_observer), 53 _cbTransportFeedbackObserver(transport_feedback_observer),
55 main_ssrc_(0), 54 main_ssrc_(0),
56 _remoteSSRC(0), 55 _remoteSSRC(0),
57 _remoteSenderInfo(), 56 _remoteSenderInfo(),
58 _lastReceivedSRNTPsecs(0), 57 _lastReceivedSRNTPsecs(0),
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 } 687 }
689 // time since last received rtcp packet 688 // time since last received rtcp packet
690 // when we dont have a lastTimeReceived and the object is marked 689 // when we dont have a lastTimeReceived and the object is marked
691 // readyForDelete it's removed from the map 690 // readyForDelete it's removed from the map
692 if (receiveInfo->lastTimeReceived) { 691 if (receiveInfo->lastTimeReceived) {
693 /// use audio define since we don't know what interval the remote peer is 692 /// use audio define since we don't know what interval the remote peer is
694 // using 693 // using
695 if ((timeNow - receiveInfo->lastTimeReceived) > 694 if ((timeNow - receiveInfo->lastTimeReceived) >
696 5 * RTCP_INTERVAL_AUDIO_MS) { 695 5 * RTCP_INTERVAL_AUDIO_MS) {
697 // no rtcp packet for the last five regular intervals, reset limitations 696 // no rtcp packet for the last five regular intervals, reset limitations
698 receiveInfo->TmmbrSet.clearSet(); 697 receiveInfo->TmmbrSet.clear();
699 // prevent that we call this over and over again 698 // prevent that we call this over and over again
700 receiveInfo->lastTimeReceived = 0; 699 receiveInfo->lastTimeReceived = 0;
701 // send new TMMBN to all channels using the default codec 700 // send new TMMBN to all channels using the default codec
702 updateBoundingSet = true; 701 updateBoundingSet = true;
703 } 702 }
704 receiveInfoIt++; 703 receiveInfoIt++;
705 } else if (receiveInfo->readyForDelete) { 704 } else if (receiveInfo->readyForDelete) {
706 // store our current receiveInfoItem 705 // store our current receiveInfoItem
707 std::map<uint32_t, RTCPReceiveInformation*>::iterator 706 std::map<uint32_t, RTCPReceiveInformation*>::iterator
708 receiveInfoItemToBeErased = receiveInfoIt; 707 receiveInfoItemToBeErased = receiveInfoIt;
709 receiveInfoIt++; 708 receiveInfoIt++;
710 delete receiveInfoItemToBeErased->second; 709 delete receiveInfoItemToBeErased->second;
711 _receivedInfoMap.erase(receiveInfoItemToBeErased); 710 _receivedInfoMap.erase(receiveInfoItemToBeErased);
712 } else { 711 } else {
713 receiveInfoIt++; 712 receiveInfoIt++;
714 } 713 }
715 } 714 }
716 return updateBoundingSet; 715 return updateBoundingSet;
717 } 716 }
718 717
719 int32_t RTCPReceiver::BoundingSet(bool* tmmbrOwner, TMMBRSet* boundingSetRec) { 718 int32_t RTCPReceiver::BoundingSet(bool* tmmbrOwner,
719 std::vector<rtcp::TmmbItem>* boundingSetRec) {
720 rtc::CritScope lock(&_criticalSectionRTCPReceiver); 720 rtc::CritScope lock(&_criticalSectionRTCPReceiver);
721 721
722 std::map<uint32_t, RTCPReceiveInformation*>::iterator receiveInfoIt = 722 std::map<uint32_t, RTCPReceiveInformation*>::iterator receiveInfoIt =
723 _receivedInfoMap.find(_remoteSSRC); 723 _receivedInfoMap.find(_remoteSSRC);
724 724
725 if (receiveInfoIt == _receivedInfoMap.end()) { 725 if (receiveInfoIt == _receivedInfoMap.end()) {
726 return -1; 726 return -1;
727 } 727 }
728 RTCPReceiveInformation* receiveInfo = receiveInfoIt->second; 728 RTCPReceiveInformation* receiveInfo = receiveInfoIt->second;
729 if (receiveInfo == NULL) { 729 if (receiveInfo == NULL) {
730 return -1; 730 return -1;
731 } 731 }
732 if (receiveInfo->TmmbnBoundingSet.lengthOfSet() > 0) { 732 if (receiveInfo->TmmbnBoundingSet.size() > 0) {
733 boundingSetRec->VerifyAndAllocateSet( 733 boundingSetRec->clear();
734 receiveInfo->TmmbnBoundingSet.lengthOfSet() + 1); 734 boundingSetRec->reserve(receiveInfo->TmmbnBoundingSet.size() + 1);
735 for(uint32_t i=0; i< receiveInfo->TmmbnBoundingSet.lengthOfSet(); 735 for (uint32_t i = 0; i < receiveInfo->TmmbnBoundingSet.size(); i++) {
736 i++) { 736 if (receiveInfo->TmmbnBoundingSet[i].ssrc() == main_ssrc_) {
737 if(receiveInfo->TmmbnBoundingSet.Ssrc(i) == main_ssrc_) {
738 // owner of bounding set 737 // owner of bounding set
739 *tmmbrOwner = true; 738 *tmmbrOwner = true;
740 } 739 }
741 boundingSetRec->SetEntry(i, 740 boundingSetRec->push_back(receiveInfo->TmmbnBoundingSet[i]);
742 receiveInfo->TmmbnBoundingSet.Tmmbr(i),
743 receiveInfo->TmmbnBoundingSet.PacketOH(i),
744 receiveInfo->TmmbnBoundingSet.Ssrc(i));
745 } 741 }
746 } 742 }
747 return receiveInfo->TmmbnBoundingSet.lengthOfSet(); 743 return receiveInfo->TmmbnBoundingSet.size();
748 } 744 }
749 745
750 void RTCPReceiver::HandleSDES(RTCPUtility::RTCPParserV2& rtcpParser, 746 void RTCPReceiver::HandleSDES(RTCPUtility::RTCPParserV2& rtcpParser,
751 RTCPPacketInformation& rtcpPacketInformation) { 747 RTCPPacketInformation& rtcpPacketInformation) {
752 RTCPUtility::RTCPPacketTypes pktType = rtcpParser.Iterate(); 748 RTCPUtility::RTCPPacketTypes pktType = rtcpParser.Iterate();
753 while (pktType == RTCPPacketTypes::kSdesChunk) { 749 while (pktType == RTCPPacketTypes::kSdesChunk) {
754 HandleSDESChunk(rtcpParser); 750 HandleSDESChunk(rtcpParser);
755 pktType = rtcpParser.Iterate(); 751 pktType = rtcpParser.Iterate();
756 } 752 }
757 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpSdes; 753 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpSdes;
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 } 1054 }
1059 1055
1060 void RTCPReceiver::HandleSR_REQ(RTCPUtility::RTCPParserV2& rtcpParser, 1056 void RTCPReceiver::HandleSR_REQ(RTCPUtility::RTCPParserV2& rtcpParser,
1061 RTCPPacketInformation& rtcpPacketInformation) { 1057 RTCPPacketInformation& rtcpPacketInformation) {
1062 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpSrReq; 1058 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpSrReq;
1063 rtcpParser.Iterate(); 1059 rtcpParser.Iterate();
1064 } 1060 }
1065 1061
1066 void RTCPReceiver::HandleTMMBNItem(RTCPReceiveInformation& receiveInfo, 1062 void RTCPReceiver::HandleTMMBNItem(RTCPReceiveInformation& receiveInfo,
1067 const RTCPUtility::RTCPPacket& rtcpPacket) { 1063 const RTCPUtility::RTCPPacket& rtcpPacket) {
1068 receiveInfo.TmmbnBoundingSet.AddEntry( 1064 receiveInfo.TmmbnBoundingSet.push_back(
1069 rtcpPacket.TMMBNItem.MaxTotalMediaBitRate, 1065 rtcp::TmmbItem(rtcpPacket.TMMBNItem.SSRC,
1070 rtcpPacket.TMMBNItem.MeasuredOverhead, 1066 rtcpPacket.TMMBNItem.MaxTotalMediaBitRate * 1000,
1071 rtcpPacket.TMMBNItem.SSRC); 1067 rtcpPacket.TMMBNItem.MeasuredOverhead));
1072 } 1068 }
1073 1069
1074 void RTCPReceiver::HandleSLI(RTCPUtility::RTCPParserV2& rtcpParser, 1070 void RTCPReceiver::HandleSLI(RTCPUtility::RTCPParserV2& rtcpParser,
1075 RTCPPacketInformation& rtcpPacketInformation) { 1071 RTCPPacketInformation& rtcpPacketInformation) {
1076 const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); 1072 const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet();
1077 RTCPUtility::RTCPPacketTypes pktType = rtcpParser.Iterate(); 1073 RTCPUtility::RTCPPacketTypes pktType = rtcpParser.Iterate();
1078 while (pktType == RTCPPacketTypes::kPsfbSliItem) { 1074 while (pktType == RTCPPacketTypes::kPsfbSliItem) {
1079 HandleSLIItem(rtcpPacket, rtcpPacketInformation); 1075 HandleSLIItem(rtcpPacket, rtcpPacketInformation);
1080 pktType = rtcpParser.Iterate(); 1076 pktType = rtcpParser.Iterate();
1081 } 1077 }
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1225 RTCPUtility::RTCPParserV2* rtcp_parser, 1221 RTCPUtility::RTCPParserV2* rtcp_parser,
1226 RTCPHelp::RTCPPacketInformation* rtcp_packet_information) { 1222 RTCPHelp::RTCPPacketInformation* rtcp_packet_information) {
1227 rtcp::RtcpPacket* packet = rtcp_parser->ReleaseRtcpPacket(); 1223 rtcp::RtcpPacket* packet = rtcp_parser->ReleaseRtcpPacket();
1228 RTC_DCHECK(packet != nullptr); 1224 RTC_DCHECK(packet != nullptr);
1229 rtcp_packet_information->rtcpPacketTypeFlags |= kRtcpTransportFeedback; 1225 rtcp_packet_information->rtcpPacketTypeFlags |= kRtcpTransportFeedback;
1230 rtcp_packet_information->transport_feedback_.reset( 1226 rtcp_packet_information->transport_feedback_.reset(
1231 static_cast<rtcp::TransportFeedback*>(packet)); 1227 static_cast<rtcp::TransportFeedback*>(packet));
1232 1228
1233 rtcp_parser->Iterate(); 1229 rtcp_parser->Iterate();
1234 } 1230 }
1231
1235 int32_t RTCPReceiver::UpdateTMMBR() { 1232 int32_t RTCPReceiver::UpdateTMMBR() {
1236 int32_t numBoundingSet = 0; 1233 std::vector<rtcp::TmmbItem> candidates = TMMBRReceived();
1237 uint32_t bitrate = 0; 1234 // Find bounding set
1238 uint32_t accNumCandidates = 0; 1235 FindTMMBRBoundingSet(&candidates);
1239 1236
1240 int32_t size = TMMBRReceived(0, 0, NULL);
1241 if (size > 0) {
1242 TMMBRSet* candidateSet = VerifyAndAllocateCandidateSet(size);
1243 // Get candidate set from receiver.
1244 accNumCandidates = TMMBRReceived(size, accNumCandidates, candidateSet);
1245 } else {
1246 // Candidate set empty.
1247 VerifyAndAllocateCandidateSet(0); // resets candidate set
1248 }
1249 // Find bounding set
1250 TMMBRSet* boundingSet = NULL;
1251 numBoundingSet = FindTMMBRBoundingSet(boundingSet);
1252 if (numBoundingSet == -1) {
1253 LOG(LS_WARNING) << "Failed to find TMMBR bounding set.";
1254 return -1;
1255 }
1256 // Set bounding set 1237 // Set bounding set
1257 // Inform remote clients about the new bandwidth 1238 // Inform remote clients about the new bandwidth
1258 // inform the remote client 1239 // inform the remote client
1259 _rtpRtcp.SetTMMBN(boundingSet); 1240 _rtpRtcp.SetTMMBN(&candidates);
1260 1241
1261 // might trigger a TMMBN 1242 // might trigger a TMMBN
1262 if (numBoundingSet == 0) { 1243 if (candidates.empty()) {
1263 // owner of max bitrate request has timed out 1244 // owner of max bitrate request has timed out
1264 // empty bounding set has been sent 1245 // empty bounding set has been sent
1265 return 0; 1246 return 0;
1266 } 1247 }
1267 // Get net bitrate from bounding set depending on sent packet rate 1248 if (_cbRtcpBandwidthObserver) {
1268 if (CalcMinBitRate(&bitrate)) { 1249 // Get net bitrate from bounding set depending on sent packet rate
1250 uint32_t min_bitrate_bps = std::numeric_limits<uint32_t>::max();
1251 for (const rtcp::TmmbItem& entry : candidates) {
1252 if (min_bitrate_bps > entry.bitrate_bps()) {
1253 min_bitrate_bps = entry.bitrate_bps();
1254 }
1255 }
1256 if (min_bitrate_bps < MIN_VIDEO_BW_MANAGEMENT_BITRATE * 1000)
1257 min_bitrate_bps = MIN_VIDEO_BW_MANAGEMENT_BITRATE * 1000;
1269 // we have a new bandwidth estimate on this channel 1258 // we have a new bandwidth estimate on this channel
1270 if (_cbRtcpBandwidthObserver) { 1259 _cbRtcpBandwidthObserver->OnReceivedEstimatedBitrate(min_bitrate_bps);
1271 _cbRtcpBandwidthObserver->OnReceivedEstimatedBitrate(bitrate * 1000);
1272 }
1273 } 1260 }
1274 return 0; 1261 return 0;
1275 } 1262 }
1276 1263
1277 void RTCPReceiver::RegisterRtcpStatisticsCallback( 1264 void RTCPReceiver::RegisterRtcpStatisticsCallback(
1278 RtcpStatisticsCallback* callback) { 1265 RtcpStatisticsCallback* callback) {
1279 rtc::CritScope cs(&_criticalSectionFeedbacks); 1266 rtc::CritScope cs(&_criticalSectionFeedbacks);
1280 stats_callback_ = callback; 1267 stats_callback_ = callback;
1281 } 1268 }
1282 1269
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1397 RTCPCnameInformation* cnameInfo = GetCnameInformation(remoteSSRC); 1384 RTCPCnameInformation* cnameInfo = GetCnameInformation(remoteSSRC);
1398 if (cnameInfo == NULL) { 1385 if (cnameInfo == NULL) {
1399 return -1; 1386 return -1;
1400 } 1387 }
1401 cName[RTCP_CNAME_SIZE - 1] = 0; 1388 cName[RTCP_CNAME_SIZE - 1] = 0;
1402 strncpy(cName, cnameInfo->name, RTCP_CNAME_SIZE - 1); 1389 strncpy(cName, cnameInfo->name, RTCP_CNAME_SIZE - 1);
1403 return 0; 1390 return 0;
1404 } 1391 }
1405 1392
1406 // no callbacks allowed inside this function 1393 // no callbacks allowed inside this function
1407 int32_t RTCPReceiver::TMMBRReceived(uint32_t size, 1394 std::vector<rtcp::TmmbItem> RTCPReceiver::TMMBRReceived() const {
1408 uint32_t accNumCandidates,
1409 TMMBRSet* candidateSet) const {
1410 rtc::CritScope lock(&_criticalSectionRTCPReceiver); 1395 rtc::CritScope lock(&_criticalSectionRTCPReceiver);
1396 std::vector<rtcp::TmmbItem> candidates;
1411 1397
1412 std::map<uint32_t, RTCPReceiveInformation*>::const_iterator 1398 for (auto receive_info_it : _receivedInfoMap) {
1413 receiveInfoIt = _receivedInfoMap.begin(); 1399 RTCPReceiveInformation* receive_info = receive_info_it.second;
1414 if (receiveInfoIt == _receivedInfoMap.end()) { 1400 RTC_DCHECK(receive_info);
1415 return -1; 1401 receive_info->GetTMMBRSet(_clock->TimeInMilliseconds(), &candidates);
1416 } 1402 }
1417 uint32_t num = accNumCandidates; 1403 return candidates;
1418 if (candidateSet) {
1419 while( num < size && receiveInfoIt != _receivedInfoMap.end()) {
1420 RTCPReceiveInformation* receiveInfo = receiveInfoIt->second;
1421 if (receiveInfo == NULL) {
1422 return 0;
1423 }
1424 for (uint32_t i = 0;
1425 (num < size) && (i < receiveInfo->TmmbrSet.lengthOfSet()); i++) {
1426 if (receiveInfo->GetTMMBRSet(i, num, candidateSet,
1427 _clock->TimeInMilliseconds()) == 0) {
1428 num++;
1429 }
1430 }
1431 receiveInfoIt++;
1432 }
1433 } else {
1434 while (receiveInfoIt != _receivedInfoMap.end()) {
1435 RTCPReceiveInformation* receiveInfo = receiveInfoIt->second;
1436 if(receiveInfo == NULL) {
1437 return -1;
1438 }
1439 num += receiveInfo->TmmbrSet.lengthOfSet();
1440 receiveInfoIt++;
1441 }
1442 }
1443 return num;
1444 } 1404 }
1445 1405
1446 } // namespace webrtc 1406 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtcp_receiver.h ('k') | webrtc/modules/rtp_rtcp/source/rtcp_receiver_help.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698