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

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

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