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

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

Issue 2316093002: Replace rtcp packet parsing in the RtcpReceiver. (Closed)
Patch Set: Minor style fixes thanks to Feedback Created 4 years, 3 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 <limits> 16 #include <limits>
17 17
18 #include "webrtc/base/checks.h" 18 #include "webrtc/base/checks.h"
19 #include "webrtc/base/logging.h" 19 #include "webrtc/base/logging.h"
20 #include "webrtc/base/trace_event.h" 20 #include "webrtc/base/trace_event.h"
21 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/bye.h"
22 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.h"
23 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/compound_packet.h"
24 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/extended_reports.h"
25 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/fir.h"
26 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/nack.h"
27 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/pli.h"
28 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/rapid_resync_request.h"
29 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/receiver_report.h"
30 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/remb.h"
31 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/rpsi.h"
32 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sdes.h"
33 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sender_report.h"
34 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sli.h"
35 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbn.h"
36 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbr.h"
21 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" 37 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
22 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" 38 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
23 #include "webrtc/modules/rtp_rtcp/source/time_util.h" 39 #include "webrtc/modules/rtp_rtcp/source/time_util.h"
24 #include "webrtc/modules/rtp_rtcp/source/tmmbr_help.h" 40 #include "webrtc/modules/rtp_rtcp/source/tmmbr_help.h"
25 #include "webrtc/system_wrappers/include/ntp_time.h" 41 #include "webrtc/system_wrappers/include/ntp_time.h"
26 42
27 namespace webrtc { 43 namespace webrtc {
44 namespace {
45
46 using rtcp::CommonHeader;
47 using rtcp::ReportBlock;
28 using RTCPHelp::RTCPPacketInformation; 48 using RTCPHelp::RTCPPacketInformation;
29 using RTCPHelp::RTCPReceiveInformation; 49 using RTCPHelp::RTCPReceiveInformation;
30 using RTCPHelp::RTCPReportBlockInformation; 50 using RTCPHelp::RTCPReportBlockInformation;
31 using RTCPUtility::kBtVoipMetric;
32 using RTCPUtility::RTCPCnameInformation; 51 using RTCPUtility::RTCPCnameInformation;
33 using RTCPUtility::RTCPPacketReportBlockItem; 52 using RTCPUtility::RTCPPacketReportBlockItem;
34 using RTCPUtility::RTCPPacketTypes; 53 using RTCPUtility::RTCPPacketTypes;
35 54
36 // The number of RTCP time intervals needed to trigger a timeout. 55 // The number of RTCP time intervals needed to trigger a timeout.
37 const int kRrTimeoutIntervals = 3; 56 const int kRrTimeoutIntervals = 3;
38 57
39 const int64_t kMaxWarningLogIntervalMs = 10000; 58 const int64_t kMaxWarningLogIntervalMs = 10000;
40 59
60 } // namespace
61
41 RTCPReceiver::RTCPReceiver( 62 RTCPReceiver::RTCPReceiver(
42 Clock* clock, 63 Clock* clock,
43 bool receiver_only, 64 bool receiver_only,
44 RtcpPacketTypeCounterObserver* packet_type_counter_observer, 65 RtcpPacketTypeCounterObserver* packet_type_counter_observer,
45 RtcpBandwidthObserver* rtcp_bandwidth_observer, 66 RtcpBandwidthObserver* rtcp_bandwidth_observer,
46 RtcpIntraFrameObserver* rtcp_intra_frame_observer, 67 RtcpIntraFrameObserver* rtcp_intra_frame_observer,
47 TransportFeedbackObserver* transport_feedback_observer, 68 TransportFeedbackObserver* transport_feedback_observer,
48 ModuleRtpRtcp* owner) 69 ModuleRtpRtcp* owner)
49 : _clock(clock), 70 : _clock(clock),
50 receiver_only_(receiver_only), 71 receiver_only_(receiver_only),
51 _lastReceived(0),
52 _rtpRtcp(*owner), 72 _rtpRtcp(*owner),
53 _cbRtcpBandwidthObserver(rtcp_bandwidth_observer), 73 _cbRtcpBandwidthObserver(rtcp_bandwidth_observer),
54 _cbRtcpIntraFrameObserver(rtcp_intra_frame_observer), 74 _cbRtcpIntraFrameObserver(rtcp_intra_frame_observer),
55 _cbTransportFeedbackObserver(transport_feedback_observer), 75 _cbTransportFeedbackObserver(transport_feedback_observer),
56 main_ssrc_(0), 76 main_ssrc_(0),
57 _remoteSSRC(0), 77 _remoteSSRC(0),
58 _remoteSenderInfo(), 78 _remoteSenderInfo(),
59 _lastReceivedSRNTPsecs(0), 79 _lastReceivedSRNTPsecs(0),
60 _lastReceivedSRNTPfrac(0), 80 _lastReceivedSRNTPfrac(0),
61 _lastReceivedXRNTPsecs(0), 81 _lastReceivedXRNTPsecs(0),
(...skipping 28 matching lines...) Expand all
90 } 110 }
91 while (!_receivedCnameMap.empty()) { 111 while (!_receivedCnameMap.empty()) {
92 std::map<uint32_t, RTCPCnameInformation*>::iterator first = 112 std::map<uint32_t, RTCPCnameInformation*>::iterator first =
93 _receivedCnameMap.begin(); 113 _receivedCnameMap.begin();
94 delete first->second; 114 delete first->second;
95 _receivedCnameMap.erase(first); 115 _receivedCnameMap.erase(first);
96 } 116 }
97 } 117 }
98 118
99 bool RTCPReceiver::IncomingPacket(const uint8_t* packet, size_t packet_size) { 119 bool RTCPReceiver::IncomingPacket(const uint8_t* packet, size_t packet_size) {
100 // Allow receive of non-compound RTCP packets. 120 if (packet_size == 0) {
101 RTCPUtility::RTCPParserV2 rtcp_parser(packet, packet_size, true); 121 LOG(LS_WARNING) << "Incoming empty RTCP packet";
102
103 if (!rtcp_parser.IsValid()) {
104 LOG(LS_WARNING) << "Incoming invalid RTCP packet";
105 return false; 122 return false;
106 } 123 }
107 RTCPHelp::RTCPPacketInformation rtcp_packet_information; 124
108 IncomingRTCPPacket(rtcp_packet_information, &rtcp_parser); 125 RTCPHelp::RTCPPacketInformation packet_information;
109 TriggerCallbacksFromRTCPPacket(rtcp_packet_information); 126 if (!ParseCompoundPacket(packet, packet + packet_size, &packet_information))
127 return false;
128 TriggerCallbacksFromRTCPPacket(packet_information);
110 return true; 129 return true;
111 } 130 }
112 131
113 int64_t RTCPReceiver::LastReceived() {
114 rtc::CritScope lock(&_criticalSectionRTCPReceiver);
115 return _lastReceived;
116 }
117
118 int64_t RTCPReceiver::LastReceivedReceiverReport() const { 132 int64_t RTCPReceiver::LastReceivedReceiverReport() const {
119 rtc::CritScope lock(&_criticalSectionRTCPReceiver); 133 rtc::CritScope lock(&_criticalSectionRTCPReceiver);
120 int64_t last_received_rr = -1; 134 int64_t last_received_rr = -1;
121 for (ReceivedInfoMap::const_iterator it = _receivedInfoMap.begin(); 135 for (ReceivedInfoMap::const_iterator it = _receivedInfoMap.begin();
122 it != _receivedInfoMap.end(); ++it) { 136 it != _receivedInfoMap.end(); ++it) {
123 if (it->second->last_time_received_ms > last_received_rr) { 137 if (it->second->last_time_received_ms > last_received_rr) {
124 last_received_rr = it->second->last_time_received_ms; 138 last_received_rr = it->second->last_time_received_ms;
125 } 139 }
126 } 140 }
127 return last_received_rr; 141 return last_received_rr;
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 for (; it != _receivedReportBlockMap.end(); ++it) { 289 for (; it != _receivedReportBlockMap.end(); ++it) {
276 const ReportBlockInfoMap* info_map = &(it->second); 290 const ReportBlockInfoMap* info_map = &(it->second);
277 ReportBlockInfoMap::const_iterator it_info = info_map->begin(); 291 ReportBlockInfoMap::const_iterator it_info = info_map->begin();
278 for (; it_info != info_map->end(); ++it_info) { 292 for (; it_info != info_map->end(); ++it_info) {
279 receiveBlocks->push_back(it_info->second->remoteReceiveBlock); 293 receiveBlocks->push_back(it_info->second->remoteReceiveBlock);
280 } 294 }
281 } 295 }
282 return 0; 296 return 0;
283 } 297 }
284 298
285 int32_t RTCPReceiver::IncomingRTCPPacket( 299 bool RTCPReceiver::ParseCompoundPacket(
286 RTCPPacketInformation& rtcpPacketInformation, 300 const uint8_t* packet_begin,
287 RTCPUtility::RTCPParserV2* rtcpParser) { 301 const uint8_t* packet_end,
302 RTCPPacketInformation* packet_information) {
288 rtc::CritScope lock(&_criticalSectionRTCPReceiver); 303 rtc::CritScope lock(&_criticalSectionRTCPReceiver);
289 304
290 _lastReceived = _clock->TimeInMilliseconds(); 305 CommonHeader rtcp_block;
306 for (const uint8_t* next_block = packet_begin; next_block != packet_end;
307 next_block = rtcp_block.NextPacket()) {
308 ptrdiff_t remaining_blocks_size = packet_end - next_block;
309 RTC_DCHECK_GT(remaining_blocks_size, 0);
310 if (!rtcp_block.Parse(next_block, remaining_blocks_size)) {
311 bool first_block = next_block == packet_begin;
312 if (first_block) {
sprang_webrtc 2016/09/19 14:10:53 Don't need this temp bool? Also, would be nice wit
danilchap 2016/09/19 18:06:23 It served as a comment what is really checked ther
313 LOG(LS_WARNING) << "Incoming invalid RTCP packet";
314 return false;
315 }
316 ++num_skipped_packets_;
317 break;
318 }
291 319
292 if (packet_type_counter_.first_packet_time_ms == -1) { 320 if (packet_type_counter_.first_packet_time_ms == -1)
293 packet_type_counter_.first_packet_time_ms = _lastReceived; 321 packet_type_counter_.first_packet_time_ms = _clock->TimeInMilliseconds();
294 }
295 322
296 RTCPUtility::RTCPPacketTypes pktType = rtcpParser->Begin(); 323 switch (rtcp_block.type()) {
297 while (pktType != RTCPPacketTypes::kInvalid) { 324 case rtcp::SenderReport::kPacketType:
298 // Each "case" is responsible for iterate the parser to the 325 HandleSenderReport(rtcp_block, *packet_information);
299 // next top level packet.
300 switch (pktType) {
301 case RTCPPacketTypes::kSr:
302 HandleSenderReport(*rtcpParser, rtcpPacketInformation);
303 break; 326 break;
304 case RTCPPacketTypes::kRr: 327 case rtcp::ReceiverReport::kPacketType:
305 HandleReceiverReport(*rtcpParser, rtcpPacketInformation); 328 HandleReceiverReport(rtcp_block, *packet_information);
306 break; 329 break;
307 case RTCPPacketTypes::kSdes: 330 case rtcp::Sdes::kPacketType:
308 HandleSDES(*rtcpParser, rtcpPacketInformation); 331 HandleSDES(rtcp_block, *packet_information);
309 break; 332 break;
310 case RTCPPacketTypes::kXrHeader: 333 case rtcp::ExtendedReports::kPacketType:
311 HandleXrHeader(*rtcpParser, rtcpPacketInformation); 334 HandleXr(rtcp_block, *packet_information);
312 break; 335 break;
313 case RTCPPacketTypes::kXrReceiverReferenceTime: 336 case rtcp::Bye::kPacketType:
314 HandleXrReceiveReferenceTime(*rtcpParser, rtcpPacketInformation); 337 HandleBYE(rtcp_block);
315 break; 338 break;
316 case RTCPPacketTypes::kXrDlrrReportBlock: 339 case rtcp::Rtpfb::kPacketType:
317 HandleXrDlrrReportBlock(*rtcpParser, rtcpPacketInformation); 340 switch (rtcp_block.fmt()) {
341 case rtcp::Nack::kFeedbackMessageType:
342 HandleNACK(rtcp_block, *packet_information);
343 break;
344 case rtcp::Tmmbr::kFeedbackMessageType:
345 HandleTMMBR(rtcp_block, *packet_information);
346 break;
347 case rtcp::Tmmbn::kFeedbackMessageType:
348 HandleTMMBN(rtcp_block, *packet_information);
349 break;
350 case rtcp::RapidResyncRequest::kFeedbackMessageType:
351 HandleSR_REQ(rtcp_block, *packet_information);
352 break;
353 case rtcp::TransportFeedback::kFeedbackMessageType:
354 HandleTransportFeedback(rtcp_block, packet_information);
355 break;
356 default:
357 ++num_skipped_packets_;
358 break;
359 }
318 break; 360 break;
319 case RTCPPacketTypes::kBye: 361 case rtcp::Psfb::kPacketType:
320 HandleBYE(*rtcpParser); 362 switch (rtcp_block.fmt()) {
321 break; 363 case rtcp::Pli::kFeedbackMessageType:
322 case RTCPPacketTypes::kRtpfbNack: 364 HandlePLI(rtcp_block, *packet_information);
323 HandleNACK(*rtcpParser, rtcpPacketInformation); 365 break;
324 break; 366 case rtcp::Sli::kFeedbackMessageType:
325 case RTCPPacketTypes::kRtpfbTmmbr: 367 HandleSLI(rtcp_block, *packet_information);
326 HandleTMMBR(*rtcpParser, rtcpPacketInformation); 368 break;
327 break; 369 case rtcp::Rpsi::kFeedbackMessageType:
328 case RTCPPacketTypes::kRtpfbTmmbn: 370 HandleRPSI(rtcp_block, *packet_information);
329 HandleTMMBN(*rtcpParser, rtcpPacketInformation); 371 break;
330 break; 372 case rtcp::Fir::kFeedbackMessageType:
331 case RTCPPacketTypes::kRtpfbSrReq: 373 HandleFIR(rtcp_block, *packet_information);
332 HandleSR_REQ(*rtcpParser, rtcpPacketInformation); 374 break;
333 break; 375 case rtcp::Remb::kFeedbackMessageType:
334 case RTCPPacketTypes::kPsfbPli: 376 HandlePsfbApp(rtcp_block, *packet_information);
335 HandlePLI(*rtcpParser, rtcpPacketInformation); 377 break;
336 break; 378 default:
337 case RTCPPacketTypes::kPsfbSli: 379 ++num_skipped_packets_;
338 HandleSLI(*rtcpParser, rtcpPacketInformation); 380 break;
339 break; 381 }
340 case RTCPPacketTypes::kPsfbRpsi:
341 HandleRPSI(*rtcpParser, rtcpPacketInformation);
342 break;
343 case RTCPPacketTypes::kPsfbFir:
344 HandleFIR(*rtcpParser, rtcpPacketInformation);
345 break;
346 case RTCPPacketTypes::kPsfbApp:
347 HandlePsfbApp(*rtcpParser, rtcpPacketInformation);
348 break;
349 case RTCPPacketTypes::kTransportFeedback:
350 HandleTransportFeedback(rtcpParser, &rtcpPacketInformation);
351 break; 382 break;
352 default: 383 default:
353 rtcpParser->Iterate(); 384 ++num_skipped_packets_;
354 break; 385 break;
355 } 386 }
356 pktType = rtcpParser->PacketType();
357 } 387 }
358 388
359 if (packet_type_counter_observer_ != NULL) { 389 if (packet_type_counter_observer_ != NULL) {
360 packet_type_counter_observer_->RtcpPacketTypesCounterUpdated( 390 packet_type_counter_observer_->RtcpPacketTypesCounterUpdated(
361 main_ssrc_, packet_type_counter_); 391 main_ssrc_, packet_type_counter_);
362 } 392 }
363 393
364 num_skipped_packets_ += rtcpParser->NumSkippedBlocks();
365
366 int64_t now = _clock->TimeInMilliseconds(); 394 int64_t now = _clock->TimeInMilliseconds();
367 if (now - last_skipped_packets_warning_ >= kMaxWarningLogIntervalMs && 395 if (now - last_skipped_packets_warning_ >= kMaxWarningLogIntervalMs &&
368 num_skipped_packets_ > 0) { 396 num_skipped_packets_ > 0) {
369 last_skipped_packets_warning_ = now; 397 last_skipped_packets_warning_ = now;
370 LOG(LS_WARNING) << num_skipped_packets_ 398 LOG(LS_WARNING) << num_skipped_packets_
371 << " RTCP blocks were skipped due to being malformed or of " 399 << " RTCP blocks were skipped due to being malformed or of "
372 "unrecognized/unsupported type, during the past " 400 "unrecognized/unsupported type, during the past "
373 << (kMaxWarningLogIntervalMs / 1000) << " second period."; 401 << (kMaxWarningLogIntervalMs / 1000) << " second period.";
374 } 402 }
375 403
376 return 0; 404 return true;
377 } 405 }
378 406
379 void RTCPReceiver::HandleSenderReport( 407 void RTCPReceiver::HandleSenderReport(
380 RTCPUtility::RTCPParserV2& rtcpParser, 408 const CommonHeader& rtcp_block,
381 RTCPPacketInformation& rtcpPacketInformation) { 409 RTCPPacketInformation& rtcpPacketInformation) {
382 RTCPUtility::RTCPPacketTypes rtcpPacketType = rtcpParser.PacketType(); 410 rtcp::SenderReport sender_report;
383 const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); 411 if (!sender_report.Parse(rtcp_block)) {
412 ++num_skipped_packets_;
413 return;
414 }
384 415
385 RTC_DCHECK(rtcpPacketType == RTCPPacketTypes::kSr); 416 const uint32_t remoteSSRC = sender_report.sender_ssrc();
386
387 // SR.SenderSSRC
388 // The synchronization source identifier for the originator of this SR packet
389
390 const uint32_t remoteSSRC = rtcpPacket.SR.SenderSSRC;
391 417
392 rtcpPacketInformation.remoteSSRC = remoteSSRC; 418 rtcpPacketInformation.remoteSSRC = remoteSSRC;
393 419
394 RTCPReceiveInformation* ptrReceiveInfo = CreateReceiveInformation(remoteSSRC); 420 RTCPReceiveInformation* ptrReceiveInfo = CreateReceiveInformation(remoteSSRC);
395 if (!ptrReceiveInfo) { 421 if (!ptrReceiveInfo)
396 rtcpParser.Iterate();
397 return; 422 return;
398 }
399 423
400 TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "SR", 424 TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "SR",
401 "remote_ssrc", remoteSSRC, "ssrc", main_ssrc_); 425 "remote_ssrc", remoteSSRC, "ssrc", main_ssrc_);
402 426
403 // Have I received RTP packets from this party? 427 // Have I received RTP packets from this party?
404 if (_remoteSSRC == remoteSSRC) { 428 if (_remoteSSRC == remoteSSRC) {
405 // Only signal that we have received a SR when we accept one. 429 // Only signal that we have received a SR when we accept one.
406 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpSr; 430 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpSr;
407 431
408 rtcpPacketInformation.ntp_secs = rtcpPacket.SR.NTPMostSignificant; 432 rtcpPacketInformation.ntp_secs = sender_report.ntp().seconds();
409 rtcpPacketInformation.ntp_frac = rtcpPacket.SR.NTPLeastSignificant; 433 rtcpPacketInformation.ntp_frac = sender_report.ntp().fractions();
410 rtcpPacketInformation.rtp_timestamp = rtcpPacket.SR.RTPTimestamp; 434 rtcpPacketInformation.rtp_timestamp = sender_report.rtp_timestamp();
411 435
412 // Save the NTP time of this report. 436 // Save the NTP time of this report.
413 _remoteSenderInfo.NTPseconds = rtcpPacket.SR.NTPMostSignificant; 437 _remoteSenderInfo.NTPseconds = sender_report.ntp().seconds();
414 _remoteSenderInfo.NTPfraction = rtcpPacket.SR.NTPLeastSignificant; 438 _remoteSenderInfo.NTPfraction = sender_report.ntp().fractions();
415 _remoteSenderInfo.RTPtimeStamp = rtcpPacket.SR.RTPTimestamp; 439 _remoteSenderInfo.RTPtimeStamp = sender_report.rtp_timestamp();
416 _remoteSenderInfo.sendPacketCount = rtcpPacket.SR.SenderPacketCount; 440 _remoteSenderInfo.sendPacketCount = sender_report.sender_packet_count();
417 _remoteSenderInfo.sendOctetCount = rtcpPacket.SR.SenderOctetCount; 441 _remoteSenderInfo.sendOctetCount = sender_report.sender_octet_count();
418 442
419 _clock->CurrentNtp(_lastReceivedSRNTPsecs, _lastReceivedSRNTPfrac); 443 _clock->CurrentNtp(_lastReceivedSRNTPsecs, _lastReceivedSRNTPfrac);
420 } else { 444 } else {
421 // We will only store the send report from one source, but 445 // We will only store the send report from one source, but
422 // we will store all the receive blocks. 446 // we will store all the receive blocks.
423 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpRr; 447 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpRr;
424 } 448 }
425 // Update that this remote is alive. 449 // Update that this remote is alive.
426 ptrReceiveInfo->last_time_received_ms = _clock->TimeInMilliseconds(); 450 ptrReceiveInfo->last_time_received_ms = _clock->TimeInMilliseconds();
427 451
428 rtcpPacketType = rtcpParser.Iterate(); 452 for (const rtcp::ReportBlock report_block : sender_report.report_blocks())
429 453 HandleReportBlock(report_block, rtcpPacketInformation, remoteSSRC);
430 while (rtcpPacketType == RTCPPacketTypes::kReportBlockItem) {
431 HandleReportBlock(rtcpPacket, rtcpPacketInformation, remoteSSRC);
432 rtcpPacketType = rtcpParser.Iterate();
433 }
434 } 454 }
435 455
436 void RTCPReceiver::HandleReceiverReport( 456 void RTCPReceiver::HandleReceiverReport(
437 RTCPUtility::RTCPParserV2& rtcpParser, 457 const CommonHeader& rtcp_block,
438 RTCPPacketInformation& rtcpPacketInformation) { 458 RTCPPacketInformation& rtcpPacketInformation) {
439 RTCPUtility::RTCPPacketTypes rtcpPacketType = rtcpParser.PacketType(); 459 rtcp::ReceiverReport receiver_report;
440 const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); 460 if (!receiver_report.Parse(rtcp_block)) {
461 ++num_skipped_packets_;
462 return;
463 }
441 464
442 RTC_DCHECK(rtcpPacketType == RTCPPacketTypes::kRr); 465 const uint32_t remoteSSRC = receiver_report.sender_ssrc();
443
444 // rtcpPacket.RR.SenderSSRC
445 // The source of the packet sender, same as of SR? or is this a CE?
446 const uint32_t remoteSSRC = rtcpPacket.RR.SenderSSRC;
447 466
448 rtcpPacketInformation.remoteSSRC = remoteSSRC; 467 rtcpPacketInformation.remoteSSRC = remoteSSRC;
449 468
450 RTCPReceiveInformation* ptrReceiveInfo = CreateReceiveInformation(remoteSSRC); 469 RTCPReceiveInformation* ptrReceiveInfo = CreateReceiveInformation(remoteSSRC);
451 if (!ptrReceiveInfo) { 470 if (!ptrReceiveInfo)
452 rtcpParser.Iterate();
453 return; 471 return;
454 }
455 472
456 TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "RR", 473 TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "RR",
457 "remote_ssrc", remoteSSRC, "ssrc", main_ssrc_); 474 "remote_ssrc", remoteSSRC, "ssrc", main_ssrc_);
458 475
459 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpRr; 476 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpRr;
460 477
461 // Update that this remote is alive. 478 // Update that this remote is alive.
462 ptrReceiveInfo->last_time_received_ms = _clock->TimeInMilliseconds(); 479 ptrReceiveInfo->last_time_received_ms = _clock->TimeInMilliseconds();
463 480
464 rtcpPacketType = rtcpParser.Iterate(); 481 for (const ReportBlock& report_block : receiver_report.report_blocks())
465 482 HandleReportBlock(report_block, rtcpPacketInformation, remoteSSRC);
466 while (rtcpPacketType == RTCPPacketTypes::kReportBlockItem) {
467 HandleReportBlock(rtcpPacket, rtcpPacketInformation, remoteSSRC);
468 rtcpPacketType = rtcpParser.Iterate();
469 }
470 } 483 }
471 484
472 void RTCPReceiver::HandleReportBlock( 485 void RTCPReceiver::HandleReportBlock(
473 const RTCPUtility::RTCPPacket& rtcpPacket, 486 const ReportBlock& report_block,
474 RTCPPacketInformation& rtcpPacketInformation, 487 RTCPPacketInformation& rtcpPacketInformation,
475 uint32_t remoteSSRC) 488 uint32_t remoteSSRC) {
476 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver) {
477 // This will be called once per report block in the RTCP packet. 489 // This will be called once per report block in the RTCP packet.
478 // We filter out all report blocks that are not for us. 490 // We filter out all report blocks that are not for us.
479 // Each packet has max 31 RR blocks. 491 // Each packet has max 31 RR blocks.
480 // 492 //
481 // We can calc RTT if we send a send report and get a report block back. 493 // We can calc RTT if we send a send report and get a report block back.
482 494
483 // |rtcpPacket.ReportBlockItem.SSRC| is the SSRC identifier of the source to 495 // |rtcpPacket.ReportBlockItem.SSRC| is the SSRC identifier of the source to
484 // which the information in this reception report block pertains. 496 // which the information in this reception report block pertains.
485 497
486 // Filter out all report blocks that are not for us. 498 // Filter out all report blocks that are not for us.
487 if (registered_ssrcs_.find(rtcpPacket.ReportBlockItem.SSRC) == 499 if (registered_ssrcs_.count(report_block.source_ssrc()) == 0)
488 registered_ssrcs_.end()) {
489 // This block is not for us ignore it.
490 return; 500 return;
491 }
492 501
493 RTCPReportBlockInformation* reportBlock = CreateOrGetReportBlockInformation( 502 RTCPReportBlockInformation* reportBlock =
494 remoteSSRC, rtcpPacket.ReportBlockItem.SSRC); 503 CreateOrGetReportBlockInformation(remoteSSRC, report_block.source_ssrc());
495 if (reportBlock == NULL) { 504 if (reportBlock == NULL) {
496 LOG(LS_WARNING) << "Failed to CreateReportBlockInformation(" << remoteSSRC 505 LOG(LS_WARNING) << "Failed to CreateReportBlockInformation(" << remoteSSRC
497 << ")"; 506 << ")";
498 return; 507 return;
499 } 508 }
500 509
501 _lastReceivedRrMs = _clock->TimeInMilliseconds(); 510 _lastReceivedRrMs = _clock->TimeInMilliseconds();
502 const RTCPPacketReportBlockItem& rb = rtcpPacket.ReportBlockItem;
503 reportBlock->remoteReceiveBlock.remoteSSRC = remoteSSRC; 511 reportBlock->remoteReceiveBlock.remoteSSRC = remoteSSRC;
504 reportBlock->remoteReceiveBlock.sourceSSRC = rb.SSRC; 512 reportBlock->remoteReceiveBlock.sourceSSRC = report_block.source_ssrc();
505 reportBlock->remoteReceiveBlock.fractionLost = rb.FractionLost; 513 reportBlock->remoteReceiveBlock.fractionLost = report_block.fraction_lost();
506 reportBlock->remoteReceiveBlock.cumulativeLost = 514 reportBlock->remoteReceiveBlock.cumulativeLost =
507 rb.CumulativeNumOfPacketsLost; 515 report_block.cumulative_lost();
508 if (rb.ExtendedHighestSequenceNumber > 516 if (report_block.extended_high_seq_num() >
509 reportBlock->remoteReceiveBlock.extendedHighSeqNum) { 517 reportBlock->remoteReceiveBlock.extendedHighSeqNum) {
510 // We have successfully delivered new RTP packets to the remote side after 518 // We have successfully delivered new RTP packets to the remote side after
511 // the last RR was sent from the remote side. 519 // the last RR was sent from the remote side.
512 _lastIncreasedSequenceNumberMs = _lastReceivedRrMs; 520 _lastIncreasedSequenceNumberMs = _lastReceivedRrMs;
513 } 521 }
514 reportBlock->remoteReceiveBlock.extendedHighSeqNum = 522 reportBlock->remoteReceiveBlock.extendedHighSeqNum =
515 rb.ExtendedHighestSequenceNumber; 523 report_block.extended_high_seq_num();
516 reportBlock->remoteReceiveBlock.jitter = rb.Jitter; 524 reportBlock->remoteReceiveBlock.jitter = report_block.jitter();
517 reportBlock->remoteReceiveBlock.delaySinceLastSR = rb.DelayLastSR; 525 reportBlock->remoteReceiveBlock.delaySinceLastSR =
518 reportBlock->remoteReceiveBlock.lastSR = rb.LastSR; 526 report_block.delay_since_last_sr();
527 reportBlock->remoteReceiveBlock.lastSR = report_block.last_sr();
519 528
520 if (rtcpPacket.ReportBlockItem.Jitter > reportBlock->remoteMaxJitter) { 529 if (report_block.jitter() > reportBlock->remoteMaxJitter)
521 reportBlock->remoteMaxJitter = rtcpPacket.ReportBlockItem.Jitter; 530 reportBlock->remoteMaxJitter = report_block.jitter();
522 }
523 531
524 int64_t rtt = 0; 532 int64_t rtt = 0;
525 uint32_t send_time = rtcpPacket.ReportBlockItem.LastSR; 533 uint32_t send_time = report_block.last_sr();
526 // RFC3550, section 6.4.1, LSR field discription states: 534 // RFC3550, section 6.4.1, LSR field discription states:
527 // If no SR has been received yet, the field is set to zero. 535 // If no SR has been received yet, the field is set to zero.
528 // Receiver rtp_rtcp module is not expected to calculate rtt using 536 // Receiver rtp_rtcp module is not expected to calculate rtt using
529 // Sender Reports even if it accidentally can. 537 // Sender Reports even if it accidentally can.
530 if (!receiver_only_ && send_time != 0) { 538 if (!receiver_only_ && send_time != 0) {
531 uint32_t delay = rtcpPacket.ReportBlockItem.DelayLastSR; 539 uint32_t delay = report_block.delay_since_last_sr();
532 // Local NTP time. 540 // Local NTP time.
533 uint32_t receive_time = CompactNtp(NtpTime(*_clock)); 541 uint32_t receive_time = CompactNtp(NtpTime(*_clock));
534 542
535 // RTT in 1/(2^16) seconds. 543 // RTT in 1/(2^16) seconds.
536 uint32_t rtt_ntp = receive_time - delay - send_time; 544 uint32_t rtt_ntp = receive_time - delay - send_time;
537 // Convert to 1/1000 seconds (milliseconds). 545 // Convert to 1/1000 seconds (milliseconds).
538 rtt = CompactNtpRttToMs(rtt_ntp); 546 rtt = CompactNtpRttToMs(rtt_ntp);
539 if (rtt > reportBlock->maxRTT) { 547 if (rtt > reportBlock->maxRTT) {
540 // Store max RTT. 548 // Store max RTT.
541 reportBlock->maxRTT = rtt; 549 reportBlock->maxRTT = rtt;
(...skipping 14 matching lines...) Expand all
556 float newAverage = 564 float newAverage =
557 ((ac / (ac + 1)) * reportBlock->avgRTT) + ((1 / (ac + 1)) * rtt); 565 ((ac / (ac + 1)) * reportBlock->avgRTT) + ((1 / (ac + 1)) * rtt);
558 reportBlock->avgRTT = static_cast<int64_t>(newAverage + 0.5f); 566 reportBlock->avgRTT = static_cast<int64_t>(newAverage + 0.5f);
559 } else { 567 } else {
560 // First RTT. 568 // First RTT.
561 reportBlock->avgRTT = rtt; 569 reportBlock->avgRTT = rtt;
562 } 570 }
563 reportBlock->numAverageCalcs++; 571 reportBlock->numAverageCalcs++;
564 } 572 }
565 573
566 TRACE_COUNTER_ID1(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "RR_RTT", rb.SSRC, 574 TRACE_COUNTER_ID1(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "RR_RTT",
567 rtt); 575 report_block.source_ssrc(), rtt);
568 576
569 rtcpPacketInformation.AddReportInfo(*reportBlock); 577 rtcpPacketInformation.AddReportInfo(*reportBlock);
570 } 578 }
571 579
572 RTCPReportBlockInformation* RTCPReceiver::CreateOrGetReportBlockInformation( 580 RTCPReportBlockInformation* RTCPReceiver::CreateOrGetReportBlockInformation(
573 uint32_t remote_ssrc, 581 uint32_t remote_ssrc,
574 uint32_t source_ssrc) { 582 uint32_t source_ssrc) {
575 RTCPReportBlockInformation* info = 583 RTCPReportBlockInformation* info =
576 GetReportBlockInformation(remote_ssrc, source_ssrc); 584 GetReportBlockInformation(remote_ssrc, source_ssrc);
577 if (info == NULL) { 585 if (info == NULL) {
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 if (receiveInfoIt == _receivedInfoMap.end()) { 742 if (receiveInfoIt == _receivedInfoMap.end()) {
735 return std::vector<rtcp::TmmbItem>(); 743 return std::vector<rtcp::TmmbItem>();
736 } 744 }
737 RTCPReceiveInformation* receiveInfo = receiveInfoIt->second; 745 RTCPReceiveInformation* receiveInfo = receiveInfoIt->second;
738 RTC_DCHECK(receiveInfo); 746 RTC_DCHECK(receiveInfo);
739 747
740 *tmmbr_owner = TMMBRHelp::IsOwner(receiveInfo->tmmbn, main_ssrc_); 748 *tmmbr_owner = TMMBRHelp::IsOwner(receiveInfo->tmmbn, main_ssrc_);
741 return receiveInfo->tmmbn; 749 return receiveInfo->tmmbn;
742 } 750 }
743 751
744 void RTCPReceiver::HandleSDES(RTCPUtility::RTCPParserV2& rtcpParser, 752 void RTCPReceiver::HandleSDES(const CommonHeader& rtcp_block,
745 RTCPPacketInformation& rtcpPacketInformation) { 753 RTCPPacketInformation& rtcpPacketInformation) {
746 RTCPUtility::RTCPPacketTypes pktType = rtcpParser.Iterate(); 754 rtcp::Sdes sdes;
747 while (pktType == RTCPPacketTypes::kSdesChunk) { 755 if (!sdes.Parse(rtcp_block)) {
748 const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); 756 ++num_skipped_packets_;
749 RTCPCnameInformation* cnameInfo = 757 return;
750 CreateCnameInformation(rtcpPacket.CName.SenderSSRC); 758 }
759
760 for (const auto& chunk : sdes.chunks()) {
sprang_webrtc 2016/09/19 14:10:53 nit: Personally I prefer the actual type here, rat
danilchap 2016/09/19 18:06:23 Done. type not very descriptive.... but probably b
761 RTCPCnameInformation* cnameInfo = CreateCnameInformation(chunk.ssrc);
751 RTC_DCHECK(cnameInfo); 762 RTC_DCHECK(cnameInfo);
752 763
753 cnameInfo->name[RTCP_CNAME_SIZE - 1] = 0; 764 cnameInfo->name[RTCP_CNAME_SIZE - 1] = 0;
754 strncpy(cnameInfo->name, rtcpPacket.CName.CName, RTCP_CNAME_SIZE - 1); 765 strncpy(cnameInfo->name, chunk.cname.c_str(), RTCP_CNAME_SIZE - 1);
755 { 766 {
756 rtc::CritScope lock(&_criticalSectionFeedbacks); 767 rtc::CritScope lock(&_criticalSectionFeedbacks);
757 if (stats_callback_) { 768 if (stats_callback_) {
758 stats_callback_->CNameChanged(rtcpPacket.CName.CName, 769 stats_callback_->CNameChanged(chunk.cname.c_str(), chunk.ssrc);
759 rtcpPacket.CName.SenderSSRC);
760 } 770 }
761 } 771 }
762
763 pktType = rtcpParser.Iterate();
764 } 772 }
765 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpSdes; 773 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpSdes;
766 } 774 }
767 775
768 void RTCPReceiver::HandleNACK(RTCPUtility::RTCPParserV2& rtcpParser, 776 void RTCPReceiver::HandleNACK(const CommonHeader& rtcp_block,
769 RTCPPacketInformation& rtcpPacketInformation) { 777 RTCPPacketInformation& rtcpPacketInformation) {
770 const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); 778 rtcp::Nack nack;
771 if (receiver_only_ || main_ssrc_ != rtcpPacket.NACK.MediaSSRC) { 779 if (!nack.Parse(rtcp_block)) {
772 // Not to us. 780 ++num_skipped_packets_;
773 rtcpParser.Iterate();
774 return; 781 return;
775 } 782 }
776 rtcpPacketInformation.ResetNACKPacketIdArray();
777 783
778 RTCPUtility::RTCPPacketTypes pktType = rtcpParser.Iterate(); 784 if (receiver_only_ || main_ssrc_ != nack.media_ssrc()) // Not to us.
779 while (pktType == RTCPPacketTypes::kRtpfbNackItem) { 785 return;
780 rtcpPacketInformation.AddNACKPacket(rtcpPacket.NACKItem.PacketID);
781 nack_stats_.ReportRequest(rtcpPacket.NACKItem.PacketID);
782 786
783 uint16_t bitMask = rtcpPacket.NACKItem.BitMask; 787 rtcpPacketInformation.nackSequenceNumbers = nack.packet_ids();
784 if (bitMask) { 788 for (uint16_t packet_id : nack.packet_ids())
785 for (int i = 1; i <= 16; ++i) { 789 nack_stats_.ReportRequest(packet_id);
786 if (bitMask & 0x01) { 790
787 rtcpPacketInformation.AddNACKPacket(rtcpPacket.NACKItem.PacketID + i); 791 if (!nack.packet_ids().empty()) {
788 nack_stats_.ReportRequest(rtcpPacket.NACKItem.PacketID + i);
789 }
790 bitMask = bitMask >> 1;
791 }
792 }
793 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpNack; 792 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpNack;
794
795 pktType = rtcpParser.Iterate();
796 }
797
798 if (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpNack) {
799 ++packet_type_counter_.nack_packets; 793 ++packet_type_counter_.nack_packets;
800 packet_type_counter_.nack_requests = nack_stats_.requests(); 794 packet_type_counter_.nack_requests = nack_stats_.requests();
801 packet_type_counter_.unique_nack_requests = nack_stats_.unique_requests(); 795 packet_type_counter_.unique_nack_requests = nack_stats_.unique_requests();
802 } 796 }
803 } 797 }
804 798
805 void RTCPReceiver::HandleBYE(RTCPUtility::RTCPParserV2& rtcpParser) { 799 void RTCPReceiver::HandleBYE(const CommonHeader& rtcp_block) {
806 const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); 800 rtcp::Bye bye;
801 if (!bye.Parse(rtcp_block)) {
802 ++num_skipped_packets_;
803 return;
804 }
807 805
808 // clear our lists 806 // clear our lists
809 ReportBlockMap::iterator it = _receivedReportBlockMap.begin(); 807 ReportBlockMap::iterator it = _receivedReportBlockMap.begin();
810 for (; it != _receivedReportBlockMap.end(); ++it) { 808 for (; it != _receivedReportBlockMap.end(); ++it) {
811 ReportBlockInfoMap* info_map = &(it->second); 809 ReportBlockInfoMap* info_map = &(it->second);
812 ReportBlockInfoMap::iterator it_info = 810 ReportBlockInfoMap::iterator it_info = info_map->find(bye.sender_ssrc());
813 info_map->find(rtcpPacket.BYE.SenderSSRC);
814 if (it_info != info_map->end()) { 811 if (it_info != info_map->end()) {
815 delete it_info->second; 812 delete it_info->second;
816 info_map->erase(it_info); 813 info_map->erase(it_info);
817 } 814 }
818 } 815 }
819 816
820 // we can't delete it due to TMMBR 817 // we can't delete it due to TMMBR
821 std::map<uint32_t, RTCPReceiveInformation*>::iterator receiveInfoIt = 818 std::map<uint32_t, RTCPReceiveInformation*>::iterator receiveInfoIt =
822 _receivedInfoMap.find(rtcpPacket.BYE.SenderSSRC); 819 _receivedInfoMap.find(bye.sender_ssrc());
823 820
824 if (receiveInfoIt != _receivedInfoMap.end()) { 821 if (receiveInfoIt != _receivedInfoMap.end())
825 receiveInfoIt->second->ready_for_delete = true; 822 receiveInfoIt->second->ready_for_delete = true;
826 }
827 823
828 std::map<uint32_t, RTCPCnameInformation*>::iterator cnameInfoIt = 824 std::map<uint32_t, RTCPCnameInformation*>::iterator cnameInfoIt =
829 _receivedCnameMap.find(rtcpPacket.BYE.SenderSSRC); 825 _receivedCnameMap.find(bye.sender_ssrc());
830 826
831 if (cnameInfoIt != _receivedCnameMap.end()) { 827 if (cnameInfoIt != _receivedCnameMap.end()) {
832 delete cnameInfoIt->second; 828 delete cnameInfoIt->second;
833 _receivedCnameMap.erase(cnameInfoIt); 829 _receivedCnameMap.erase(cnameInfoIt);
834 } 830 }
835 xr_rr_rtt_ms_ = 0; 831 xr_rr_rtt_ms_ = 0;
836 rtcpParser.Iterate(); 832 }
837 } 833
838 834 void RTCPReceiver::HandleXr(const CommonHeader& rtcp_block,
839 void RTCPReceiver::HandleXrHeader( 835 RTCPPacketInformation& rtcpPacketInformation) {
840 RTCPUtility::RTCPParserV2& parser, 836 rtcp::ExtendedReports xr;
837 if (!xr.Parse(rtcp_block)) {
838 ++num_skipped_packets_;
839 return;
840 }
841
842 rtcpPacketInformation.xr_originator_ssrc = xr.sender_ssrc();
843 for (const rtcp::Rrtr& rrtr : xr.rrtrs())
844 HandleXrReceiveReferenceTime(rrtr, rtcpPacketInformation);
845
846 for (const rtcp::Dlrr& dlrr : xr.dlrrs()) {
847 for (const rtcp::ReceiveTimeInfo& time_info : dlrr.sub_blocks())
848 HandleXrDlrrReportBlock(time_info, rtcpPacketInformation);
849 }
850 }
851
852 void RTCPReceiver::HandleXrReceiveReferenceTime(
853 const rtcp::Rrtr& rrtr,
841 RTCPPacketInformation& rtcpPacketInformation) { 854 RTCPPacketInformation& rtcpPacketInformation) {
842 const RTCPUtility::RTCPPacket& packet = parser.Packet();
843
844 rtcpPacketInformation.xr_originator_ssrc = packet.XR.OriginatorSSRC;
845
846 parser.Iterate();
847 }
848
849 void RTCPReceiver::HandleXrReceiveReferenceTime(
850 RTCPUtility::RTCPParserV2& parser,
851 RTCPPacketInformation& rtcpPacketInformation) {
852 const RTCPUtility::RTCPPacket& packet = parser.Packet();
853
854 _remoteXRReceiveTimeInfo.sourceSSRC = 855 _remoteXRReceiveTimeInfo.sourceSSRC =
855 rtcpPacketInformation.xr_originator_ssrc; 856 rtcpPacketInformation.xr_originator_ssrc;
856 857
857 _remoteXRReceiveTimeInfo.lastRR = RTCPUtility::MidNtp( 858 _remoteXRReceiveTimeInfo.lastRR = CompactNtp(rrtr.ntp());
858 packet.XRReceiverReferenceTimeItem.NTPMostSignificant,
859 packet.XRReceiverReferenceTimeItem.NTPLeastSignificant);
860 859
861 _clock->CurrentNtp(_lastReceivedXRNTPsecs, _lastReceivedXRNTPfrac); 860 _clock->CurrentNtp(_lastReceivedXRNTPsecs, _lastReceivedXRNTPfrac);
862 861
863 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpXrReceiverReferenceTime; 862 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpXrReceiverReferenceTime;
864
865 parser.Iterate();
866 } 863 }
867 864
868 void RTCPReceiver::HandleXrDlrrReportBlock( 865 void RTCPReceiver::HandleXrDlrrReportBlock(
869 RTCPUtility::RTCPParserV2& parser, 866 const rtcp::ReceiveTimeInfo& rti,
870 RTCPPacketInformation& rtcpPacketInformation) { 867 RTCPPacketInformation& rtcpPacketInformation) {
871 const RTCPUtility::RTCPPacket& packet = parser.Packet(); 868 if (registered_ssrcs_.count(rti.ssrc) == 0) // Not to us.
872 // Iterate through sub-block(s), if any. 869 return;
873 RTCPUtility::RTCPPacketTypes packet_type = parser.Iterate(); 870
874 871 rtcpPacketInformation.xr_dlrr_item = true;
875 while (packet_type == RTCPPacketTypes::kXrDlrrReportBlockItem) { 872
876 if (registered_ssrcs_.find(packet.XRDLRRReportBlockItem.SSRC) == 873 // Caller should explicitly enable rtt calculation using extended reports.
877 registered_ssrcs_.end()) { 874 if (!xr_rrtr_status_)
878 // Not to us. 875 return;
879 return; 876
880 } 877 // The send_time and delay_rr fields are in units of 1/2^16 sec.
881 878 uint32_t send_time = rti.last_rr;
882 rtcpPacketInformation.xr_dlrr_item = true; 879 // RFC3611, section 4.5, LRR field discription states:
883 880 // If no such block has been received, the field is set to zero.
884 // Caller should explicitly enable rtt calculation using extended reports. 881 if (send_time == 0)
885 if (!xr_rrtr_status_) 882 return;
886 return; 883
887 884 uint32_t delay_rr = rti.delay_since_last_rr;
888 // The send_time and delay_rr fields are in units of 1/2^16 sec. 885 uint32_t now = CompactNtp(NtpTime(*_clock));
889 uint32_t send_time = packet.XRDLRRReportBlockItem.LastRR; 886
890 // RFC3611, section 4.5, LRR field discription states: 887 uint32_t rtt_ntp = now - delay_rr - send_time;
891 // If no such block has been received, the field is set to zero. 888 xr_rr_rtt_ms_ = CompactNtpRttToMs(rtt_ntp);
892 if (send_time == 0) 889
893 return; 890 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpXrDlrrReportBlock;
894 891 }
895 uint32_t delay_rr = packet.XRDLRRReportBlockItem.DelayLastRR; 892
896 uint32_t now = CompactNtp(NtpTime(*_clock)); 893 void RTCPReceiver::HandlePLI(const CommonHeader& rtcp_block,
897
898 uint32_t rtt_ntp = now - delay_rr - send_time;
899 xr_rr_rtt_ms_ = CompactNtpRttToMs(rtt_ntp);
900
901 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpXrDlrrReportBlock;
902
903 packet_type = parser.Iterate();
904 }
905 }
906
907 void RTCPReceiver::HandlePLI(RTCPUtility::RTCPParserV2& rtcpParser,
908 RTCPPacketInformation& rtcpPacketInformation) { 894 RTCPPacketInformation& rtcpPacketInformation) {
909 const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); 895 rtcp::Pli pli;
910 if (main_ssrc_ == rtcpPacket.PLI.MediaSSRC) { 896 if (!pli.Parse(rtcp_block)) {
897 ++num_skipped_packets_;
898 return;
899 }
900
901 if (main_ssrc_ == pli.media_ssrc()) {
911 TRACE_EVENT_INSTANT0(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "PLI"); 902 TRACE_EVENT_INSTANT0(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "PLI");
912 903
913 ++packet_type_counter_.pli_packets; 904 ++packet_type_counter_.pli_packets;
914 // Received a signal that we need to send a new key frame. 905 // Received a signal that we need to send a new key frame.
915 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpPli; 906 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpPli;
916 } 907 }
917 rtcpParser.Iterate(); 908 }
918 } 909
919 910 void RTCPReceiver::HandleTMMBR(const CommonHeader& rtcp_block,
920 void RTCPReceiver::HandleTMMBR(RTCPUtility::RTCPParserV2& rtcpParser,
921 RTCPPacketInformation& rtcpPacketInformation) { 911 RTCPPacketInformation& rtcpPacketInformation) {
922 const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); 912 rtcp::Tmmbr tmmbr;
923 913 if (!tmmbr.Parse(rtcp_block)) {
924 uint32_t senderSSRC = rtcpPacket.TMMBR.SenderSSRC; 914 ++num_skipped_packets_;
915 return;
916 }
917
918 uint32_t senderSSRC = tmmbr.sender_ssrc();
925 RTCPReceiveInformation* ptrReceiveInfo = GetReceiveInformation(senderSSRC); 919 RTCPReceiveInformation* ptrReceiveInfo = GetReceiveInformation(senderSSRC);
926 if (ptrReceiveInfo == NULL) { 920 if (!ptrReceiveInfo) // This remote SSRC must be saved before.
927 // This remote SSRC must be saved before. 921 return;
928 rtcpParser.Iterate(); 922
929 return; 923 if (tmmbr.media_ssrc()) {
930 } 924 // media_ssrc() SHOULD be 0 if same as SenderSSRC.
931 if (rtcpPacket.TMMBR.MediaSSRC) { 925 // In relay mode this is a valid number.
932 // rtcpPacket.TMMBR.MediaSSRC SHOULD be 0 if same as SenderSSRC 926 senderSSRC = tmmbr.media_ssrc();
933 // in relay mode this is a valid number 927 }
934 senderSSRC = rtcpPacket.TMMBR.MediaSSRC; 928
935 } 929 for (const rtcp::TmmbItem& request : tmmbr.requests()) {
936 930 if (main_ssrc_ == request.ssrc() && request.bitrate_bps()) {
937 // Use packet length to calc max number of TMMBR blocks 931 ptrReceiveInfo->InsertTmmbrItem(senderSSRC, request,
938 // each TMMBR block is 8 bytes 932 _clock->TimeInMilliseconds());
939 ptrdiff_t maxNumOfTMMBRBlocks = rtcpParser.LengthLeft() / 8;
940
941 // sanity, we can't have more than what's in one packet
942 if (maxNumOfTMMBRBlocks > 200) {
943 assert(false);
944 rtcpParser.Iterate();
945 return;
946 }
947
948 RTCPUtility::RTCPPacketTypes pktType = rtcpParser.Iterate();
949 while (pktType == RTCPPacketTypes::kRtpfbTmmbrItem) {
950 if (main_ssrc_ == rtcpPacket.TMMBRItem.SSRC &&
951 rtcpPacket.TMMBRItem.MaxTotalMediaBitRate > 0) {
952 ptrReceiveInfo->InsertTmmbrItem(
953 senderSSRC,
954 rtcp::TmmbItem(rtcpPacket.TMMBRItem.SSRC,
955 rtcpPacket.TMMBRItem.MaxTotalMediaBitRate * 1000,
956 rtcpPacket.TMMBRItem.MeasuredOverhead),
957 _clock->TimeInMilliseconds());
958 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpTmmbr; 933 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpTmmbr;
959 } 934 }
960 935 }
961 pktType = rtcpParser.Iterate(); 936 }
962 } 937
963 } 938 void RTCPReceiver::HandleTMMBN(const CommonHeader& rtcp_block,
964
965 void RTCPReceiver::HandleTMMBN(RTCPUtility::RTCPParserV2& rtcpParser,
966 RTCPPacketInformation& rtcpPacketInformation) { 939 RTCPPacketInformation& rtcpPacketInformation) {
967 const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); 940 rtcp::Tmmbn tmmbn;
941 if (!tmmbn.Parse(rtcp_block)) {
942 ++num_skipped_packets_;
943 return;
944 }
945
968 RTCPReceiveInformation* ptrReceiveInfo = 946 RTCPReceiveInformation* ptrReceiveInfo =
969 GetReceiveInformation(rtcpPacket.TMMBN.SenderSSRC); 947 GetReceiveInformation(tmmbn.sender_ssrc());
970 if (ptrReceiveInfo == NULL) { 948 if (!ptrReceiveInfo) // This remote SSRC must be saved before.
971 // This remote SSRC must be saved before. 949 return;
972 rtcpParser.Iterate(); 950
973 return;
974 }
975 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpTmmbn; 951 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpTmmbn;
976 // Use packet length to calc max number of TMMBN blocks 952
977 // each TMMBN block is 8 bytes 953 for (const auto& item : tmmbn.items())
978 ptrdiff_t maxNumOfTMMBNBlocks = rtcpParser.LengthLeft() / 8; 954 ptrReceiveInfo->tmmbn.push_back(item);
979 955 }
980 // sanity, we cant have more than what's in one packet 956
981 if (maxNumOfTMMBNBlocks > 200) { 957 void RTCPReceiver::HandleSR_REQ(const CommonHeader& rtcp_block,
982 assert(false);
983 rtcpParser.Iterate();
984 return;
985 }
986
987 RTCPUtility::RTCPPacketTypes pktType = rtcpParser.Iterate();
988 while (pktType == RTCPPacketTypes::kRtpfbTmmbnItem) {
989 ptrReceiveInfo->tmmbn.emplace_back(
990 rtcpPacket.TMMBNItem.SSRC,
991 rtcpPacket.TMMBNItem.MaxTotalMediaBitRate * 1000,
992 rtcpPacket.TMMBNItem.MeasuredOverhead);
993 pktType = rtcpParser.Iterate();
994 }
995 }
996
997 void RTCPReceiver::HandleSR_REQ(RTCPUtility::RTCPParserV2& rtcpParser,
998 RTCPPacketInformation& rtcpPacketInformation) { 958 RTCPPacketInformation& rtcpPacketInformation) {
959 rtcp::RapidResyncRequest sr_req;
960 if (!sr_req.Parse(rtcp_block)) {
961 ++num_skipped_packets_;
962 return;
963 }
964
999 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpSrReq; 965 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpSrReq;
1000 rtcpParser.Iterate(); 966 }
1001 } 967
1002 968 void RTCPReceiver::HandleSLI(const CommonHeader& rtcp_block,
1003 void RTCPReceiver::HandleSLI(RTCPUtility::RTCPParserV2& rtcpParser,
1004 RTCPPacketInformation& rtcpPacketInformation) { 969 RTCPPacketInformation& rtcpPacketInformation) {
1005 const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); 970 rtcp::Sli sli;
1006 RTCPUtility::RTCPPacketTypes pktType = rtcpParser.Iterate(); 971 if (!sli.Parse(rtcp_block)) {
1007 while (pktType == RTCPPacketTypes::kPsfbSliItem) { 972 ++num_skipped_packets_;
1008 // in theory there could be multiple slices lost 973 return;
1009 rtcpPacketInformation.rtcpPacketTypeFlags |= 974 }
1010 kRtcpSli; // received signal that we need to refresh a slice 975
1011 rtcpPacketInformation.sliPictureId = rtcpPacket.SLIItem.PictureId; 976 for (const rtcp::Sli::Macroblocks& item : sli.macroblocks()) {
1012 977 // In theory there could be multiple slices lost.
1013 pktType = rtcpParser.Iterate(); 978 // Received signal that we need to refresh a slice.
979 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpSli;
980 rtcpPacketInformation.sliPictureId = item.picture_id();
1014 } 981 }
1015 } 982 }
1016 983
1017 void RTCPReceiver::HandleRPSI( 984 void RTCPReceiver::HandleRPSI(
1018 RTCPUtility::RTCPParserV2& rtcpParser, 985 const CommonHeader& rtcp_block,
1019 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation) { 986 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation) {
1020 const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); 987 rtcp::Rpsi rpsi;
1021 RTCPUtility::RTCPPacketTypes pktType = rtcpParser.Iterate(); 988 if (!rpsi.Parse(rtcp_block)) {
1022 if (pktType == RTCPPacketTypes::kPsfbRpsiItem) { 989 ++num_skipped_packets_;
1023 if (rtcpPacket.RPSI.NumberOfValidBits % 8 != 0) { 990 return;
1024 // to us unknown 991 }
1025 // continue 992
1026 rtcpParser.Iterate(); 993 // Received signal that we have a confirmed reference picture.
1027 return; 994 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpRpsi;
1028 } 995 rtcpPacketInformation.rpsiPictureId = rpsi.picture_id();
1029 // Received signal that we have a confirmed reference picture. 996 }
1030 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpRpsi; 997
1031 rtcpPacketInformation.rpsiPictureId = 0; 998 void RTCPReceiver::HandlePsfbApp(const CommonHeader& rtcp_block,
1032
1033 // convert NativeBitString to rpsiPictureId
1034 uint8_t numberOfBytes = rtcpPacket.RPSI.NumberOfValidBits / 8;
1035 for (uint8_t n = 0; n < (numberOfBytes - 1); n++) {
1036 rtcpPacketInformation.rpsiPictureId +=
1037 (rtcpPacket.RPSI.NativeBitString[n] & 0x7f);
1038 rtcpPacketInformation.rpsiPictureId <<= 7; // prepare next
1039 }
1040 rtcpPacketInformation.rpsiPictureId +=
1041 (rtcpPacket.RPSI.NativeBitString[numberOfBytes - 1] & 0x7f);
1042 }
1043 }
1044
1045 void RTCPReceiver::HandlePsfbApp(RTCPUtility::RTCPParserV2& rtcpParser,
1046 RTCPPacketInformation& rtcpPacketInformation) { 999 RTCPPacketInformation& rtcpPacketInformation) {
1047 RTCPUtility::RTCPPacketTypes pktType = rtcpParser.Iterate(); 1000 rtcp::Remb remb;
1048 if (pktType == RTCPPacketTypes::kPsfbRemb) { 1001 if (remb.Parse(rtcp_block)) {
1049 pktType = rtcpParser.Iterate(); 1002 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpRemb;
1050 if (pktType == RTCPPacketTypes::kPsfbRembItem) { 1003 rtcpPacketInformation.receiverEstimatedMaxBitrate = remb.bitrate_bps();
1051 const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); 1004 return;
1052 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpRemb; 1005 }
1053 rtcpPacketInformation.receiverEstimatedMaxBitrate = 1006
1054 rtcpPacket.REMBItem.BitRate; 1007 ++num_skipped_packets_;
1055 1008 }
1056 rtcpParser.Iterate(); 1009
1057 } 1010 void RTCPReceiver::HandleFIR(const CommonHeader& rtcp_block,
1058 }
1059 }
1060
1061 void RTCPReceiver::HandleFIR(RTCPUtility::RTCPParserV2& rtcpParser,
1062 RTCPPacketInformation& rtcpPacketInformation) { 1011 RTCPPacketInformation& rtcpPacketInformation) {
1063 const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); 1012 rtcp::Fir fir;
1013 if (!fir.Parse(rtcp_block)) {
1014 ++num_skipped_packets_;
1015 return;
1016 }
1017
1064 RTCPReceiveInformation* ptrReceiveInfo = 1018 RTCPReceiveInformation* ptrReceiveInfo =
1065 GetReceiveInformation(rtcpPacket.FIR.SenderSSRC); 1019 GetReceiveInformation(fir.sender_ssrc());
1066 1020
1067 RTCPUtility::RTCPPacketTypes pktType = rtcpParser.Iterate(); 1021 for (const rtcp::Fir::Request& fir_request : fir.requests()) {
1068 while (pktType == RTCPPacketTypes::kPsfbFirItem) {
1069 // Is it our sender that is requested to generate a new keyframe 1022 // Is it our sender that is requested to generate a new keyframe
1070 if (main_ssrc_ != rtcpPacket.FIRItem.SSRC) { 1023 if (main_ssrc_ != fir_request.ssrc)
1071 return; 1024 continue;
1072 }
1073 1025
1074 ++packet_type_counter_.fir_packets; 1026 ++packet_type_counter_.fir_packets;
1075 1027
1076 // rtcpPacket.FIR.MediaSSRC SHOULD be 0 but we ignore to check it 1028 // rtcpPacket.FIR.MediaSSRC SHOULD be 0 but we ignore to check it
1077 // we don't know who this originate from 1029 // we don't know who this originate from
1078 if (ptrReceiveInfo) { 1030 if (ptrReceiveInfo) {
1079 // check if we have reported this FIRSequenceNumber before 1031 // check if we have reported this FIRSequenceNumber before
1080 if (rtcpPacket.FIRItem.CommandSequenceNumber != 1032 if (fir_request.seq_nr != ptrReceiveInfo->last_fir_sequence_number) {
1081 ptrReceiveInfo->last_fir_sequence_number) {
1082 int64_t now = _clock->TimeInMilliseconds(); 1033 int64_t now = _clock->TimeInMilliseconds();
1083 // sanity; don't go crazy with the callbacks 1034 // sanity; don't go crazy with the callbacks
1084 if ((now - ptrReceiveInfo->last_fir_request_ms) > 1035 if ((now - ptrReceiveInfo->last_fir_request_ms) >
1085 RTCP_MIN_FRAME_LENGTH_MS) { 1036 RTCP_MIN_FRAME_LENGTH_MS) {
1086 ptrReceiveInfo->last_fir_request_ms = now; 1037 ptrReceiveInfo->last_fir_request_ms = now;
1087 ptrReceiveInfo->last_fir_sequence_number = 1038 ptrReceiveInfo->last_fir_sequence_number = fir_request.seq_nr;
1088 rtcpPacket.FIRItem.CommandSequenceNumber;
1089 // received signal that we need to send a new key frame 1039 // received signal that we need to send a new key frame
1090 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpFir; 1040 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpFir;
1091 } 1041 }
1092 } 1042 }
1093 } else { 1043 } else {
1094 // received signal that we need to send a new key frame 1044 // received signal that we need to send a new key frame
1095 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpFir; 1045 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpFir;
1096 } 1046 }
1097
1098 pktType = rtcpParser.Iterate();
1099 } 1047 }
1100 } 1048 }
1101 1049
1102 void RTCPReceiver::HandleTransportFeedback( 1050 void RTCPReceiver::HandleTransportFeedback(
1103 RTCPUtility::RTCPParserV2* rtcp_parser, 1051 const CommonHeader& rtcp_block,
1104 RTCPHelp::RTCPPacketInformation* rtcp_packet_information) { 1052 RTCPHelp::RTCPPacketInformation* rtcp_packet_information) {
1105 rtcp::RtcpPacket* packet = rtcp_parser->ReleaseRtcpPacket(); 1053 std::unique_ptr<rtcp::TransportFeedback> transport_feedback(
1106 RTC_DCHECK(packet != nullptr); 1054 new rtcp::TransportFeedback());
1055 if (!transport_feedback->Parse(rtcp_block)) {
1056 ++num_skipped_packets_;
1057 return;
1058 }
1059
1107 rtcp_packet_information->rtcpPacketTypeFlags |= kRtcpTransportFeedback; 1060 rtcp_packet_information->rtcpPacketTypeFlags |= kRtcpTransportFeedback;
1108 rtcp_packet_information->transport_feedback_.reset( 1061 rtcp_packet_information->transport_feedback_ = std::move(transport_feedback);
1109 static_cast<rtcp::TransportFeedback*>(packet));
1110
1111 rtcp_parser->Iterate();
1112 } 1062 }
1113 1063
1114 void RTCPReceiver::UpdateTmmbr() { 1064 void RTCPReceiver::UpdateTmmbr() {
1115 // Find bounding set. 1065 // Find bounding set.
1116 std::vector<rtcp::TmmbItem> bounding = 1066 std::vector<rtcp::TmmbItem> bounding =
1117 TMMBRHelp::FindBoundingSet(TmmbrReceived()); 1067 TMMBRHelp::FindBoundingSet(TmmbrReceived());
1118 1068
1119 if (!bounding.empty() && _cbRtcpBandwidthObserver) { 1069 if (!bounding.empty() && _cbRtcpBandwidthObserver) {
1120 // We have a new bandwidth estimate on this channel. 1070 // We have a new bandwidth estimate on this channel.
1121 uint64_t bitrate_bps = TMMBRHelp::CalcMinBitrateBps(bounding); 1071 uint64_t bitrate_bps = TMMBRHelp::CalcMinBitrateBps(bounding);
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1267 1217
1268 for (const auto& kv : _receivedInfoMap) { 1218 for (const auto& kv : _receivedInfoMap) {
1269 RTCPReceiveInformation* receive_info = kv.second; 1219 RTCPReceiveInformation* receive_info = kv.second;
1270 RTC_DCHECK(receive_info); 1220 RTC_DCHECK(receive_info);
1271 receive_info->GetTmmbrSet(now_ms, &candidates); 1221 receive_info->GetTmmbrSet(now_ms, &candidates);
1272 } 1222 }
1273 return candidates; 1223 return candidates;
1274 } 1224 }
1275 1225
1276 } // namespace webrtc 1226 } // 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