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

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

Issue 2340763002: Split RtcpReceiver::HandleSenderReceiverReport into two functions (Closed)
Patch Set: Comments fixes 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
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtcp_receiver.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 if (packet_type_counter_.first_packet_time_ms == -1) { 292 if (packet_type_counter_.first_packet_time_ms == -1) {
293 packet_type_counter_.first_packet_time_ms = _lastReceived; 293 packet_type_counter_.first_packet_time_ms = _lastReceived;
294 } 294 }
295 295
296 RTCPUtility::RTCPPacketTypes pktType = rtcpParser->Begin(); 296 RTCPUtility::RTCPPacketTypes pktType = rtcpParser->Begin();
297 while (pktType != RTCPPacketTypes::kInvalid) { 297 while (pktType != RTCPPacketTypes::kInvalid) {
298 // Each "case" is responsible for iterate the parser to the 298 // Each "case" is responsible for iterate the parser to the
299 // next top level packet. 299 // next top level packet.
300 switch (pktType) { 300 switch (pktType) {
301 case RTCPPacketTypes::kSr: 301 case RTCPPacketTypes::kSr:
302 HandleSenderReport(*rtcpParser, rtcpPacketInformation);
303 break;
302 case RTCPPacketTypes::kRr: 304 case RTCPPacketTypes::kRr:
303 HandleSenderReceiverReport(*rtcpParser, rtcpPacketInformation); 305 HandleReceiverReport(*rtcpParser, rtcpPacketInformation);
304 break; 306 break;
305 case RTCPPacketTypes::kSdes: 307 case RTCPPacketTypes::kSdes:
306 HandleSDES(*rtcpParser, rtcpPacketInformation); 308 HandleSDES(*rtcpParser, rtcpPacketInformation);
307 break; 309 break;
308 case RTCPPacketTypes::kXrHeader: 310 case RTCPPacketTypes::kXrHeader:
309 HandleXrHeader(*rtcpParser, rtcpPacketInformation); 311 HandleXrHeader(*rtcpParser, rtcpPacketInformation);
310 break; 312 break;
311 case RTCPPacketTypes::kXrReceiverReferenceTime: 313 case RTCPPacketTypes::kXrReceiverReferenceTime:
312 HandleXrReceiveReferenceTime(*rtcpParser, rtcpPacketInformation); 314 HandleXrReceiveReferenceTime(*rtcpParser, rtcpPacketInformation);
313 break; 315 break;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 last_skipped_packets_warning_ = now; 369 last_skipped_packets_warning_ = now;
368 LOG(LS_WARNING) << num_skipped_packets_ 370 LOG(LS_WARNING) << num_skipped_packets_
369 << " RTCP blocks were skipped due to being malformed or of " 371 << " RTCP blocks were skipped due to being malformed or of "
370 "unrecognized/unsupported type, during the past " 372 "unrecognized/unsupported type, during the past "
371 << (kMaxWarningLogIntervalMs / 1000) << " second period."; 373 << (kMaxWarningLogIntervalMs / 1000) << " second period.";
372 } 374 }
373 375
374 return 0; 376 return 0;
375 } 377 }
376 378
377 void RTCPReceiver::HandleSenderReceiverReport( 379 void RTCPReceiver::HandleSenderReport(
378 RTCPUtility::RTCPParserV2& rtcpParser, 380 RTCPUtility::RTCPParserV2& rtcpParser,
379 RTCPPacketInformation& rtcpPacketInformation) { 381 RTCPPacketInformation& rtcpPacketInformation) {
380 RTCPUtility::RTCPPacketTypes rtcpPacketType = rtcpParser.PacketType(); 382 RTCPUtility::RTCPPacketTypes rtcpPacketType = rtcpParser.PacketType();
381 const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet(); 383 const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet();
382 384
383 assert((rtcpPacketType == RTCPPacketTypes::kRr) || 385 RTC_DCHECK(rtcpPacketType == RTCPPacketTypes::kSr);
384 (rtcpPacketType == RTCPPacketTypes::kSr));
385 386
386 // SR.SenderSSRC 387 // SR.SenderSSRC
387 // The synchronization source identifier for the originator of this SR packet 388 // The synchronization source identifier for the originator of this SR packet
388 389
389 // rtcpPacket.RR.SenderSSRC 390 const uint32_t remoteSSRC = rtcpPacket.SR.SenderSSRC;
390 // The source of the packet sender, same as of SR? or is this a CE?
391
392 const uint32_t remoteSSRC = (rtcpPacketType == RTCPPacketTypes::kRr)
393 ? rtcpPacket.RR.SenderSSRC
394 : rtcpPacket.SR.SenderSSRC;
395 391
396 rtcpPacketInformation.remoteSSRC = remoteSSRC; 392 rtcpPacketInformation.remoteSSRC = remoteSSRC;
397 393
398 RTCPReceiveInformation* ptrReceiveInfo = CreateReceiveInformation(remoteSSRC); 394 RTCPReceiveInformation* ptrReceiveInfo = CreateReceiveInformation(remoteSSRC);
399 if (!ptrReceiveInfo) { 395 if (!ptrReceiveInfo) {
400 rtcpParser.Iterate(); 396 rtcpParser.Iterate();
401 return; 397 return;
402 } 398 }
403 399
404 if (rtcpPacketType == RTCPPacketTypes::kSr) { 400 TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "SR",
405 TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "SR", 401 "remote_ssrc", remoteSSRC, "ssrc", main_ssrc_);
406 "remote_ssrc", remoteSSRC, "ssrc", main_ssrc_);
407 402
408 if (_remoteSSRC == 403 // Have I received RTP packets from this party?
409 remoteSSRC) // have I received RTP packets from this party 404 if (_remoteSSRC == remoteSSRC) {
410 { 405 // Only signal that we have received a SR when we accept one.
411 // only signal that we have received a SR when we accept one 406 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpSr;
412 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpSr;
413 407
414 rtcpPacketInformation.ntp_secs = rtcpPacket.SR.NTPMostSignificant; 408 rtcpPacketInformation.ntp_secs = rtcpPacket.SR.NTPMostSignificant;
415 rtcpPacketInformation.ntp_frac = rtcpPacket.SR.NTPLeastSignificant; 409 rtcpPacketInformation.ntp_frac = rtcpPacket.SR.NTPLeastSignificant;
416 rtcpPacketInformation.rtp_timestamp = rtcpPacket.SR.RTPTimestamp; 410 rtcpPacketInformation.rtp_timestamp = rtcpPacket.SR.RTPTimestamp;
417 411
418 // We will only store the send report from one source, but 412 // Save the NTP time of this report.
419 // we will store all the receive block 413 _remoteSenderInfo.NTPseconds = rtcpPacket.SR.NTPMostSignificant;
414 _remoteSenderInfo.NTPfraction = rtcpPacket.SR.NTPLeastSignificant;
415 _remoteSenderInfo.RTPtimeStamp = rtcpPacket.SR.RTPTimestamp;
416 _remoteSenderInfo.sendPacketCount = rtcpPacket.SR.SenderPacketCount;
417 _remoteSenderInfo.sendOctetCount = rtcpPacket.SR.SenderOctetCount;
420 418
421 // Save the NTP time of this report 419 _clock->CurrentNtp(_lastReceivedSRNTPsecs, _lastReceivedSRNTPfrac);
422 _remoteSenderInfo.NTPseconds = rtcpPacket.SR.NTPMostSignificant;
423 _remoteSenderInfo.NTPfraction = rtcpPacket.SR.NTPLeastSignificant;
424 _remoteSenderInfo.RTPtimeStamp = rtcpPacket.SR.RTPTimestamp;
425 _remoteSenderInfo.sendPacketCount = rtcpPacket.SR.SenderPacketCount;
426 _remoteSenderInfo.sendOctetCount = rtcpPacket.SR.SenderOctetCount;
427
428 _clock->CurrentNtp(_lastReceivedSRNTPsecs, _lastReceivedSRNTPfrac);
429 } else {
430 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpRr;
431 }
432 } else { 420 } else {
433 TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "RR", 421 // We will only store the send report from one source, but
434 "remote_ssrc", remoteSSRC, "ssrc", main_ssrc_); 422 // we will store all the receive blocks.
435
436 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpRr; 423 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpRr;
437 } 424 }
438 // Update that this remote is alive. 425 // Update that this remote is alive.
439 ptrReceiveInfo->last_time_received_ms = _clock->TimeInMilliseconds(); 426 ptrReceiveInfo->last_time_received_ms = _clock->TimeInMilliseconds();
440 427
441 rtcpPacketType = rtcpParser.Iterate(); 428 rtcpPacketType = rtcpParser.Iterate();
442 429
443 while (rtcpPacketType == RTCPPacketTypes::kReportBlockItem) { 430 while (rtcpPacketType == RTCPPacketTypes::kReportBlockItem) {
444 HandleReportBlock(rtcpPacket, rtcpPacketInformation, remoteSSRC); 431 HandleReportBlock(rtcpPacket, rtcpPacketInformation, remoteSSRC);
445 rtcpPacketType = rtcpParser.Iterate(); 432 rtcpPacketType = rtcpParser.Iterate();
446 } 433 }
447 } 434 }
448 435
436 void RTCPReceiver::HandleReceiverReport(
437 RTCPUtility::RTCPParserV2& rtcpParser,
438 RTCPPacketInformation& rtcpPacketInformation) {
439 RTCPUtility::RTCPPacketTypes rtcpPacketType = rtcpParser.PacketType();
440 const RTCPUtility::RTCPPacket& rtcpPacket = rtcpParser.Packet();
441
442 RTC_DCHECK(rtcpPacketType == RTCPPacketTypes::kRr);
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
448 rtcpPacketInformation.remoteSSRC = remoteSSRC;
449
450 RTCPReceiveInformation* ptrReceiveInfo = CreateReceiveInformation(remoteSSRC);
451 if (!ptrReceiveInfo) {
452 rtcpParser.Iterate();
453 return;
454 }
455
456 TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "RR",
457 "remote_ssrc", remoteSSRC, "ssrc", main_ssrc_);
458
459 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpRr;
460
461 // Update that this remote is alive.
462 ptrReceiveInfo->last_time_received_ms = _clock->TimeInMilliseconds();
463
464 rtcpPacketType = rtcpParser.Iterate();
465
466 while (rtcpPacketType == RTCPPacketTypes::kReportBlockItem) {
467 HandleReportBlock(rtcpPacket, rtcpPacketInformation, remoteSSRC);
468 rtcpPacketType = rtcpParser.Iterate();
469 }
470 }
471
449 void RTCPReceiver::HandleReportBlock( 472 void RTCPReceiver::HandleReportBlock(
450 const RTCPUtility::RTCPPacket& rtcpPacket, 473 const RTCPUtility::RTCPPacket& rtcpPacket,
451 RTCPPacketInformation& rtcpPacketInformation, 474 RTCPPacketInformation& rtcpPacketInformation,
452 uint32_t remoteSSRC) 475 uint32_t remoteSSRC)
453 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver) { 476 EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver) {
454 // This will be called once per report block in the RTCP packet. 477 // This will be called once per report block in the RTCP packet.
455 // We filter out all report blocks that are not for us. 478 // We filter out all report blocks that are not for us.
456 // Each packet has max 31 RR blocks. 479 // Each packet has max 31 RR blocks.
457 // 480 //
458 // We can calc RTT if we send a send report and get a report block back. 481 // We can calc RTT if we send a send report and get a report block back.
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after
1283 1306
1284 for (const auto& kv : _receivedInfoMap) { 1307 for (const auto& kv : _receivedInfoMap) {
1285 RTCPReceiveInformation* receive_info = kv.second; 1308 RTCPReceiveInformation* receive_info = kv.second;
1286 RTC_DCHECK(receive_info); 1309 RTC_DCHECK(receive_info);
1287 receive_info->GetTmmbrSet(now_ms, &candidates); 1310 receive_info->GetTmmbrSet(now_ms, &candidates);
1288 } 1311 }
1289 return candidates; 1312 return candidates;
1290 } 1313 }
1291 1314
1292 } // namespace webrtc 1315 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtcp_receiver.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698