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 |
11 #include "webrtc/modules/rtp_rtcp/source/rtcp_receiver.h" | 11 #include "webrtc/modules/rtp_rtcp/source/rtcp_receiver.h" |
12 | 12 |
13 #include <assert.h> | 13 #include <assert.h> |
14 #include <string.h> | 14 #include <string.h> |
15 | 15 |
16 #include <algorithm> | 16 #include <algorithm> |
17 | 17 |
18 #include "webrtc/base/checks.h" | 18 #include "webrtc/base/checks.h" |
19 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" | 19 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" |
20 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" | |
21 #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h" | 20 #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h" |
22 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" | 21 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" |
23 #include "webrtc/system_wrappers/interface/logging.h" | 22 #include "webrtc/system_wrappers/interface/logging.h" |
24 #include "webrtc/system_wrappers/interface/trace_event.h" | 23 #include "webrtc/system_wrappers/interface/trace_event.h" |
25 | 24 |
26 namespace webrtc { | 25 namespace webrtc { |
27 using namespace RTCPUtility; | 26 using namespace RTCPUtility; |
28 using namespace RTCPHelp; | 27 using namespace RTCPHelp; |
29 | 28 |
30 // The number of RTCP time intervals needed to trigger a timeout. | 29 // The number of RTCP time intervals needed to trigger a timeout. |
31 const int kRrTimeoutIntervals = 3; | 30 const int kRrTimeoutIntervals = 3; |
32 | 31 |
33 const int64_t kMaxWarningLogIntervalMs = 10000; | |
34 | |
35 RTCPReceiver::RTCPReceiver( | 32 RTCPReceiver::RTCPReceiver( |
36 Clock* clock, | 33 Clock* clock, |
37 bool receiver_only, | 34 bool receiver_only, |
38 RtcpPacketTypeCounterObserver* packet_type_counter_observer, | 35 RtcpPacketTypeCounterObserver* packet_type_counter_observer, |
39 RtcpBandwidthObserver* rtcp_bandwidth_observer, | 36 RtcpBandwidthObserver* rtcp_bandwidth_observer, |
40 RtcpIntraFrameObserver* rtcp_intra_frame_observer, | 37 RtcpIntraFrameObserver* rtcp_intra_frame_observer, |
41 TransportFeedbackObserver* transport_feedback_observer, | |
42 ModuleRtpRtcpImpl* owner) | 38 ModuleRtpRtcpImpl* owner) |
43 : TMMBRHelp(), | 39 : TMMBRHelp(), |
44 _clock(clock), | 40 _clock(clock), |
45 receiver_only_(receiver_only), | 41 receiver_only_(receiver_only), |
46 _method(kRtcpOff), | 42 _method(kRtcpOff), |
47 _lastReceived(0), | 43 _lastReceived(0), |
48 _rtpRtcp(*owner), | 44 _rtpRtcp(*owner), |
49 _criticalSectionFeedbacks( | 45 _criticalSectionFeedbacks( |
50 CriticalSectionWrapper::CreateCriticalSection()), | 46 CriticalSectionWrapper::CreateCriticalSection()), |
51 _cbRtcpBandwidthObserver(rtcp_bandwidth_observer), | 47 _cbRtcpBandwidthObserver(rtcp_bandwidth_observer), |
52 _cbRtcpIntraFrameObserver(rtcp_intra_frame_observer), | 48 _cbRtcpIntraFrameObserver(rtcp_intra_frame_observer), |
53 _cbTransportFeedbackObserver(transport_feedback_observer), | |
54 _criticalSectionRTCPReceiver( | 49 _criticalSectionRTCPReceiver( |
55 CriticalSectionWrapper::CreateCriticalSection()), | 50 CriticalSectionWrapper::CreateCriticalSection()), |
56 main_ssrc_(0), | 51 main_ssrc_(0), |
57 _remoteSSRC(0), | 52 _remoteSSRC(0), |
58 _remoteSenderInfo(), | 53 _remoteSenderInfo(), |
59 _lastReceivedSRNTPsecs(0), | 54 _lastReceivedSRNTPsecs(0), |
60 _lastReceivedSRNTPfrac(0), | 55 _lastReceivedSRNTPfrac(0), |
61 _lastReceivedXRNTPsecs(0), | 56 _lastReceivedXRNTPsecs(0), |
62 _lastReceivedXRNTPfrac(0), | 57 _lastReceivedXRNTPfrac(0), |
63 xr_rr_rtt_ms_(0), | 58 xr_rr_rtt_ms_(0), |
64 _receivedInfoMap(), | 59 _receivedInfoMap(), |
65 _packetTimeOutMS(0), | 60 _packetTimeOutMS(0), |
66 _lastReceivedRrMs(0), | 61 _lastReceivedRrMs(0), |
67 _lastIncreasedSequenceNumberMs(0), | 62 _lastIncreasedSequenceNumberMs(0), |
68 stats_callback_(NULL), | 63 stats_callback_(NULL), |
69 packet_type_counter_observer_(packet_type_counter_observer), | 64 packet_type_counter_observer_(packet_type_counter_observer) { |
70 num_skipped_packets_(0), | |
71 last_skipped_packets_warning_(clock->TimeInMilliseconds()) { | |
72 memset(&_remoteSenderInfo, 0, sizeof(_remoteSenderInfo)); | 65 memset(&_remoteSenderInfo, 0, sizeof(_remoteSenderInfo)); |
73 } | 66 } |
74 | 67 |
75 RTCPReceiver::~RTCPReceiver() { | 68 RTCPReceiver::~RTCPReceiver() { |
76 delete _criticalSectionRTCPReceiver; | 69 delete _criticalSectionRTCPReceiver; |
77 delete _criticalSectionFeedbacks; | 70 delete _criticalSectionFeedbacks; |
78 | 71 |
79 ReportBlockMap::iterator it = _receivedReportBlockMap.begin(); | 72 ReportBlockMap::iterator it = _receivedReportBlockMap.begin(); |
80 for (; it != _receivedReportBlockMap.end(); ++it) { | 73 for (; it != _receivedReportBlockMap.end(); ++it) { |
81 ReportBlockInfoMap* info_map = &(it->second); | 74 ReportBlockInfoMap* info_map = &(it->second); |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 HandlePsfbApp(*rtcpParser, rtcpPacketInformation); | 342 HandlePsfbApp(*rtcpParser, rtcpPacketInformation); |
350 break; | 343 break; |
351 case RTCPPacketTypes::kApp: | 344 case RTCPPacketTypes::kApp: |
352 // generic application messages | 345 // generic application messages |
353 HandleAPP(*rtcpParser, rtcpPacketInformation); | 346 HandleAPP(*rtcpParser, rtcpPacketInformation); |
354 break; | 347 break; |
355 case RTCPPacketTypes::kAppItem: | 348 case RTCPPacketTypes::kAppItem: |
356 // generic application messages | 349 // generic application messages |
357 HandleAPPItem(*rtcpParser, rtcpPacketInformation); | 350 HandleAPPItem(*rtcpParser, rtcpPacketInformation); |
358 break; | 351 break; |
359 case RTCPPacketTypes::kTransportFeedback: | |
360 HandleTransportFeedback(rtcpParser, &rtcpPacketInformation); | |
361 break; | |
362 default: | 352 default: |
363 rtcpParser->Iterate(); | 353 rtcpParser->Iterate(); |
364 break; | 354 break; |
365 } | 355 } |
366 pktType = rtcpParser->PacketType(); | 356 pktType = rtcpParser->PacketType(); |
367 } | 357 } |
368 | 358 |
369 if (packet_type_counter_observer_ != NULL) { | 359 if (packet_type_counter_observer_ != NULL) { |
370 packet_type_counter_observer_->RtcpPacketTypesCounterUpdated( | 360 packet_type_counter_observer_->RtcpPacketTypesCounterUpdated( |
371 main_ssrc_, packet_type_counter_); | 361 main_ssrc_, packet_type_counter_); |
372 } | 362 } |
373 | 363 |
374 num_skipped_packets_ += rtcpParser->NumSkippedBlocks(); | |
375 | |
376 int64_t now = _clock->TimeInMilliseconds(); | |
377 if (now - last_skipped_packets_warning_ >= kMaxWarningLogIntervalMs && | |
378 num_skipped_packets_ > 0) { | |
379 last_skipped_packets_warning_ = now; | |
380 LOG(LS_WARNING) | |
381 << num_skipped_packets_ | |
382 << " RTCP blocks were skipped due to being malformed or of " | |
383 "unrecognized/unsupported type, during the past " | |
384 << (kMaxWarningLogIntervalMs / 1000) << " second period."; | |
385 } | |
386 | |
387 return 0; | 364 return 0; |
388 } | 365 } |
389 | 366 |
390 // no need for critsect we have _criticalSectionRTCPReceiver | 367 // no need for critsect we have _criticalSectionRTCPReceiver |
391 void | 368 void |
392 RTCPReceiver::HandleSenderReceiverReport(RTCPUtility::RTCPParserV2& rtcpParser, | 369 RTCPReceiver::HandleSenderReceiverReport(RTCPUtility::RTCPParserV2& rtcpParser, |
393 RTCPPacketInformation& rtcpPacketInform
ation) | 370 RTCPPacketInformation& rtcpPacketInform
ation) |
394 { | 371 { |
395 RTCPUtility::RTCPPacketTypes rtcpPacketType = rtcpParser.PacketType(); | 372 RTCPUtility::RTCPPacketTypes rtcpPacketType = rtcpParser.PacketType(); |
396 const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); | 373 const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); |
(...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1268 | 1245 |
1269 void RTCPReceiver::HandleAPPItem(RTCPUtility::RTCPParserV2& rtcpParser, | 1246 void RTCPReceiver::HandleAPPItem(RTCPUtility::RTCPParserV2& rtcpParser, |
1270 RTCPPacketInformation& rtcpPacketInformation) { | 1247 RTCPPacketInformation& rtcpPacketInformation) { |
1271 const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); | 1248 const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); |
1272 | 1249 |
1273 rtcpPacketInformation.AddApplicationData(rtcpPacket.APP.Data, rtcpPacket.APP.S
ize); | 1250 rtcpPacketInformation.AddApplicationData(rtcpPacket.APP.Data, rtcpPacket.APP.S
ize); |
1274 | 1251 |
1275 rtcpParser.Iterate(); | 1252 rtcpParser.Iterate(); |
1276 } | 1253 } |
1277 | 1254 |
1278 void RTCPReceiver::HandleTransportFeedback( | |
1279 RTCPUtility::RTCPParserV2* rtcp_parser, | |
1280 RTCPHelp::RTCPPacketInformation* rtcp_packet_information) { | |
1281 rtcp::RtcpPacket* packet = rtcp_parser->ReleaseRtcpPacket(); | |
1282 RTC_DCHECK(packet != nullptr); | |
1283 rtcp_packet_information->rtcpPacketTypeFlags |= kRtcpTransportFeedback; | |
1284 rtcp_packet_information->transport_feedback_.reset( | |
1285 static_cast<rtcp::TransportFeedback*>(packet)); | |
1286 | |
1287 rtcp_parser->Iterate(); | |
1288 } | |
1289 int32_t RTCPReceiver::UpdateTMMBR() { | 1255 int32_t RTCPReceiver::UpdateTMMBR() { |
1290 int32_t numBoundingSet = 0; | 1256 int32_t numBoundingSet = 0; |
1291 uint32_t bitrate = 0; | 1257 uint32_t bitrate = 0; |
1292 uint32_t accNumCandidates = 0; | 1258 uint32_t accNumCandidates = 0; |
1293 | 1259 |
1294 int32_t size = TMMBRReceived(0, 0, NULL); | 1260 int32_t size = TMMBRReceived(0, 0, NULL); |
1295 if (size > 0) { | 1261 if (size > 0) { |
1296 TMMBRSet* candidateSet = VerifyAndAllocateCandidateSet(size); | 1262 TMMBRSet* candidateSet = VerifyAndAllocateCandidateSet(size); |
1297 // Get candidate set from receiver. | 1263 // Get candidate set from receiver. |
1298 accNumCandidates = TMMBRReceived(size, accNumCandidates, candidateSet); | 1264 accNumCandidates = TMMBRReceived(size, accNumCandidates, candidateSet); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1348 // Might trigger a OnReceivedBandwidthEstimateUpdate. | 1314 // Might trigger a OnReceivedBandwidthEstimateUpdate. |
1349 UpdateTMMBR(); | 1315 UpdateTMMBR(); |
1350 } | 1316 } |
1351 unsigned int local_ssrc; | 1317 unsigned int local_ssrc; |
1352 { | 1318 { |
1353 // We don't want to hold this critsect when triggering the callbacks below. | 1319 // We don't want to hold this critsect when triggering the callbacks below. |
1354 CriticalSectionScoped lock(_criticalSectionRTCPReceiver); | 1320 CriticalSectionScoped lock(_criticalSectionRTCPReceiver); |
1355 local_ssrc = main_ssrc_; | 1321 local_ssrc = main_ssrc_; |
1356 } | 1322 } |
1357 if (!receiver_only_ && | 1323 if (!receiver_only_ && |
1358 (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpSrReq)) { | 1324 rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpSrReq) { |
1359 _rtpRtcp.OnRequestSendReport(); | 1325 _rtpRtcp.OnRequestSendReport(); |
1360 } | 1326 } |
1361 if (!receiver_only_ && | 1327 if (!receiver_only_ && |
1362 (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpNack)) { | 1328 rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpNack) { |
1363 if (rtcpPacketInformation.nackSequenceNumbers.size() > 0) { | 1329 if (rtcpPacketInformation.nackSequenceNumbers.size() > 0) { |
1364 LOG(LS_VERBOSE) << "Incoming NACK length: " | 1330 LOG(LS_VERBOSE) << "Incoming NACK length: " |
1365 << rtcpPacketInformation.nackSequenceNumbers.size(); | 1331 << rtcpPacketInformation.nackSequenceNumbers.size(); |
1366 _rtpRtcp.OnReceivedNACK(rtcpPacketInformation.nackSequenceNumbers); | 1332 _rtpRtcp.OnReceivedNACK(rtcpPacketInformation.nackSequenceNumbers); |
1367 } | 1333 } |
1368 } | 1334 } |
1369 { | 1335 { |
1370 // We need feedback that we have received a report block(s) so that we | 1336 // We need feedback that we have received a report block(s) so that we |
1371 // can generate a new packet in a conference relay scenario, one received | 1337 // can generate a new packet in a conference relay scenario, one received |
1372 // report can generate several RTCP packets, based on number relayed/mixed | 1338 // report can generate several RTCP packets, based on number relayed/mixed |
(...skipping 30 matching lines...) Expand all Loading... |
1403 } | 1369 } |
1404 if ((rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpSr) || | 1370 if ((rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpSr) || |
1405 (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpRr)) { | 1371 (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpRr)) { |
1406 int64_t now = _clock->TimeInMilliseconds(); | 1372 int64_t now = _clock->TimeInMilliseconds(); |
1407 _cbRtcpBandwidthObserver->OnReceivedRtcpReceiverReport( | 1373 _cbRtcpBandwidthObserver->OnReceivedRtcpReceiverReport( |
1408 rtcpPacketInformation.report_blocks, | 1374 rtcpPacketInformation.report_blocks, |
1409 rtcpPacketInformation.rtt, | 1375 rtcpPacketInformation.rtt, |
1410 now); | 1376 now); |
1411 } | 1377 } |
1412 } | 1378 } |
1413 if (_cbTransportFeedbackObserver && | |
1414 (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpTransportFeedback)) { | |
1415 uint32_t media_source_ssrc = | |
1416 rtcpPacketInformation.transport_feedback_->GetMediaSourceSsrc(); | |
1417 if (media_source_ssrc == main_ssrc_ || | |
1418 registered_ssrcs_.find(media_source_ssrc) != | |
1419 registered_ssrcs_.end()) { | |
1420 _cbTransportFeedbackObserver->OnTransportFeedback( | |
1421 *rtcpPacketInformation.transport_feedback_.get()); | |
1422 } | |
1423 } | |
1424 } | 1379 } |
1425 | 1380 |
1426 if (!receiver_only_) { | 1381 if (!receiver_only_) { |
1427 CriticalSectionScoped cs(_criticalSectionFeedbacks); | 1382 CriticalSectionScoped cs(_criticalSectionFeedbacks); |
1428 if (stats_callback_) { | 1383 if (stats_callback_) { |
1429 for (ReportBlockList::const_iterator it = | 1384 for (ReportBlockList::const_iterator it = |
1430 rtcpPacketInformation.report_blocks.begin(); | 1385 rtcpPacketInformation.report_blocks.begin(); |
1431 it != rtcpPacketInformation.report_blocks.end(); | 1386 it != rtcpPacketInformation.report_blocks.end(); |
1432 ++it) { | 1387 ++it) { |
1433 RtcpStatistics stats; | 1388 RtcpStatistics stats; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1490 return -1; | 1445 return -1; |
1491 } | 1446 } |
1492 num += receiveInfo->TmmbrSet.lengthOfSet(); | 1447 num += receiveInfo->TmmbrSet.lengthOfSet(); |
1493 receiveInfoIt++; | 1448 receiveInfoIt++; |
1494 } | 1449 } |
1495 } | 1450 } |
1496 return num; | 1451 return num; |
1497 } | 1452 } |
1498 | 1453 |
1499 } // namespace webrtc | 1454 } // namespace webrtc |
OLD | NEW |