Chromium Code Reviews| 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 <limits> | 16 #include <limits> |
| 17 #include <memory> | |
| 18 #include <utility> | |
| 17 | 19 |
| 18 #include "webrtc/base/checks.h" | 20 #include "webrtc/base/checks.h" |
| 19 #include "webrtc/base/logging.h" | 21 #include "webrtc/base/logging.h" |
| 20 #include "webrtc/base/trace_event.h" | 22 #include "webrtc/base/trace_event.h" |
| 21 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/bye.h" | 23 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/bye.h" |
| 22 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.h" | 24 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.h" |
| 23 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/compound_packet.h" | 25 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/compound_packet.h" |
| 24 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/extended_reports.h" | 26 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/extended_reports.h" |
| 25 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/fir.h" | 27 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/fir.h" |
| 26 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/nack.h" | 28 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/nack.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 38 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" | 40 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" |
| 39 #include "webrtc/modules/rtp_rtcp/source/time_util.h" | 41 #include "webrtc/modules/rtp_rtcp/source/time_util.h" |
| 40 #include "webrtc/modules/rtp_rtcp/source/tmmbr_help.h" | 42 #include "webrtc/modules/rtp_rtcp/source/tmmbr_help.h" |
| 41 #include "webrtc/system_wrappers/include/ntp_time.h" | 43 #include "webrtc/system_wrappers/include/ntp_time.h" |
| 42 | 44 |
| 43 namespace webrtc { | 45 namespace webrtc { |
| 44 namespace { | 46 namespace { |
| 45 | 47 |
| 46 using rtcp::CommonHeader; | 48 using rtcp::CommonHeader; |
| 47 using rtcp::ReportBlock; | 49 using rtcp::ReportBlock; |
| 48 using RTCPHelp::RTCPPacketInformation; | |
| 49 using RTCPHelp::RTCPReceiveInformation; | 50 using RTCPHelp::RTCPReceiveInformation; |
| 50 using RTCPHelp::RTCPReportBlockInformation; | 51 using RTCPHelp::RTCPReportBlockInformation; |
| 51 using RTCPUtility::RTCPCnameInformation; | 52 using RTCPUtility::RTCPCnameInformation; |
| 52 using RTCPUtility::RTCPPacketReportBlockItem; | 53 using RTCPUtility::RTCPPacketReportBlockItem; |
| 53 using RTCPUtility::RTCPPacketTypes; | 54 using RTCPUtility::RTCPPacketTypes; |
| 54 | 55 |
| 55 // The number of RTCP time intervals needed to trigger a timeout. | 56 // The number of RTCP time intervals needed to trigger a timeout. |
| 56 const int kRrTimeoutIntervals = 3; | 57 const int kRrTimeoutIntervals = 3; |
| 57 | 58 |
| 58 const int64_t kMaxWarningLogIntervalMs = 10000; | 59 const int64_t kMaxWarningLogIntervalMs = 10000; |
| 59 | 60 |
| 60 } // namespace | 61 } // namespace |
| 61 | 62 |
| 63 struct RTCPReceiver::PacketInformation { | |
| 64 uint32_t packet_type_flags = 0; // RTCPPacketTypeFlags bit field. | |
|
philipel
2016/09/23 13:27:39
Are the member variables divided into logical grou
danilchap
2016/09/23 13:35:31
Good point, thank you.
Removed all empty lines, bu
| |
| 65 uint32_t remote_ssrc = 0; | |
| 66 | |
| 67 std::vector<uint16_t> nack_sequence_numbers; | |
| 68 | |
| 69 ReportBlockList report_blocks; | |
| 70 int64_t rtt_ms = 0; | |
| 71 | |
| 72 uint8_t sli_picture_id = 0; | |
| 73 uint64_t rpsi_picture_id = 0; | |
| 74 uint32_t receiver_estimated_max_bitrate_bps = 0; | |
| 75 | |
| 76 std::unique_ptr<rtcp::TransportFeedback> transport_feedback; | |
| 77 }; | |
| 78 | |
| 62 RTCPReceiver::RTCPReceiver( | 79 RTCPReceiver::RTCPReceiver( |
| 63 Clock* clock, | 80 Clock* clock, |
| 64 bool receiver_only, | 81 bool receiver_only, |
| 65 RtcpPacketTypeCounterObserver* packet_type_counter_observer, | 82 RtcpPacketTypeCounterObserver* packet_type_counter_observer, |
| 66 RtcpBandwidthObserver* rtcp_bandwidth_observer, | 83 RtcpBandwidthObserver* rtcp_bandwidth_observer, |
| 67 RtcpIntraFrameObserver* rtcp_intra_frame_observer, | 84 RtcpIntraFrameObserver* rtcp_intra_frame_observer, |
| 68 TransportFeedbackObserver* transport_feedback_observer, | 85 TransportFeedbackObserver* transport_feedback_observer, |
| 69 ModuleRtpRtcp* owner) | 86 ModuleRtpRtcp* owner) |
| 70 : _clock(clock), | 87 : _clock(clock), |
| 71 receiver_only_(receiver_only), | 88 receiver_only_(receiver_only), |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 _receivedCnameMap.erase(first); | 132 _receivedCnameMap.erase(first); |
| 116 } | 133 } |
| 117 } | 134 } |
| 118 | 135 |
| 119 bool RTCPReceiver::IncomingPacket(const uint8_t* packet, size_t packet_size) { | 136 bool RTCPReceiver::IncomingPacket(const uint8_t* packet, size_t packet_size) { |
| 120 if (packet_size == 0) { | 137 if (packet_size == 0) { |
| 121 LOG(LS_WARNING) << "Incoming empty RTCP packet"; | 138 LOG(LS_WARNING) << "Incoming empty RTCP packet"; |
| 122 return false; | 139 return false; |
| 123 } | 140 } |
| 124 | 141 |
| 125 RTCPHelp::RTCPPacketInformation packet_information; | 142 PacketInformation packet_information; |
| 126 if (!ParseCompoundPacket(packet, packet + packet_size, &packet_information)) | 143 if (!ParseCompoundPacket(packet, packet + packet_size, &packet_information)) |
| 127 return false; | 144 return false; |
| 128 TriggerCallbacksFromRTCPPacket(packet_information); | 145 TriggerCallbacksFromRTCPPacket(packet_information); |
| 129 return true; | 146 return true; |
| 130 } | 147 } |
| 131 | 148 |
| 132 int64_t RTCPReceiver::LastReceivedReceiverReport() const { | 149 int64_t RTCPReceiver::LastReceivedReceiverReport() const { |
| 133 rtc::CritScope lock(&_criticalSectionRTCPReceiver); | 150 rtc::CritScope lock(&_criticalSectionRTCPReceiver); |
| 134 int64_t last_received_rr = -1; | 151 int64_t last_received_rr = -1; |
| 135 for (ReceivedInfoMap::const_iterator it = _receivedInfoMap.begin(); | 152 for (ReceivedInfoMap::const_iterator it = _receivedInfoMap.begin(); |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 289 for (; it != _receivedReportBlockMap.end(); ++it) { | 306 for (; it != _receivedReportBlockMap.end(); ++it) { |
| 290 const ReportBlockInfoMap* info_map = &(it->second); | 307 const ReportBlockInfoMap* info_map = &(it->second); |
| 291 ReportBlockInfoMap::const_iterator it_info = info_map->begin(); | 308 ReportBlockInfoMap::const_iterator it_info = info_map->begin(); |
| 292 for (; it_info != info_map->end(); ++it_info) { | 309 for (; it_info != info_map->end(); ++it_info) { |
| 293 receiveBlocks->push_back(it_info->second->remoteReceiveBlock); | 310 receiveBlocks->push_back(it_info->second->remoteReceiveBlock); |
| 294 } | 311 } |
| 295 } | 312 } |
| 296 return 0; | 313 return 0; |
| 297 } | 314 } |
| 298 | 315 |
| 299 bool RTCPReceiver::ParseCompoundPacket( | 316 bool RTCPReceiver::ParseCompoundPacket(const uint8_t* packet_begin, |
| 300 const uint8_t* packet_begin, | 317 const uint8_t* packet_end, |
| 301 const uint8_t* packet_end, | 318 PacketInformation* packet_information) { |
| 302 RTCPPacketInformation* packet_information) { | |
| 303 rtc::CritScope lock(&_criticalSectionRTCPReceiver); | 319 rtc::CritScope lock(&_criticalSectionRTCPReceiver); |
| 304 | 320 |
| 305 CommonHeader rtcp_block; | 321 CommonHeader rtcp_block; |
| 306 for (const uint8_t* next_block = packet_begin; next_block != packet_end; | 322 for (const uint8_t* next_block = packet_begin; next_block != packet_end; |
| 307 next_block = rtcp_block.NextPacket()) { | 323 next_block = rtcp_block.NextPacket()) { |
| 308 ptrdiff_t remaining_blocks_size = packet_end - next_block; | 324 ptrdiff_t remaining_blocks_size = packet_end - next_block; |
| 309 RTC_DCHECK_GT(remaining_blocks_size, 0); | 325 RTC_DCHECK_GT(remaining_blocks_size, 0); |
| 310 if (!rtcp_block.Parse(next_block, remaining_blocks_size)) { | 326 if (!rtcp_block.Parse(next_block, remaining_blocks_size)) { |
| 311 if (next_block == packet_begin) { | 327 if (next_block == packet_begin) { |
| 312 // Failed to parse 1st header, nothing was extracted from this packet. | 328 // Failed to parse 1st header, nothing was extracted from this packet. |
| 313 LOG(LS_WARNING) << "Incoming invalid RTCP packet"; | 329 LOG(LS_WARNING) << "Incoming invalid RTCP packet"; |
| 314 return false; | 330 return false; |
| 315 } | 331 } |
| 316 ++num_skipped_packets_; | 332 ++num_skipped_packets_; |
| 317 break; | 333 break; |
| 318 } | 334 } |
| 319 | 335 |
| 320 if (packet_type_counter_.first_packet_time_ms == -1) | 336 if (packet_type_counter_.first_packet_time_ms == -1) |
| 321 packet_type_counter_.first_packet_time_ms = _clock->TimeInMilliseconds(); | 337 packet_type_counter_.first_packet_time_ms = _clock->TimeInMilliseconds(); |
| 322 | 338 |
| 323 switch (rtcp_block.type()) { | 339 switch (rtcp_block.type()) { |
| 324 case rtcp::SenderReport::kPacketType: | 340 case rtcp::SenderReport::kPacketType: |
| 325 HandleSenderReport(rtcp_block, *packet_information); | 341 HandleSenderReport(rtcp_block, packet_information); |
| 326 break; | 342 break; |
| 327 case rtcp::ReceiverReport::kPacketType: | 343 case rtcp::ReceiverReport::kPacketType: |
| 328 HandleReceiverReport(rtcp_block, *packet_information); | 344 HandleReceiverReport(rtcp_block, packet_information); |
| 329 break; | 345 break; |
| 330 case rtcp::Sdes::kPacketType: | 346 case rtcp::Sdes::kPacketType: |
| 331 HandleSDES(rtcp_block, *packet_information); | 347 HandleSDES(rtcp_block, packet_information); |
| 332 break; | 348 break; |
| 333 case rtcp::ExtendedReports::kPacketType: | 349 case rtcp::ExtendedReports::kPacketType: |
| 334 HandleXr(rtcp_block, *packet_information); | 350 HandleXr(rtcp_block, packet_information); |
| 335 break; | 351 break; |
| 336 case rtcp::Bye::kPacketType: | 352 case rtcp::Bye::kPacketType: |
| 337 HandleBYE(rtcp_block); | 353 HandleBYE(rtcp_block); |
| 338 break; | 354 break; |
| 339 case rtcp::Rtpfb::kPacketType: | 355 case rtcp::Rtpfb::kPacketType: |
| 340 switch (rtcp_block.fmt()) { | 356 switch (rtcp_block.fmt()) { |
| 341 case rtcp::Nack::kFeedbackMessageType: | 357 case rtcp::Nack::kFeedbackMessageType: |
| 342 HandleNACK(rtcp_block, *packet_information); | 358 HandleNACK(rtcp_block, packet_information); |
| 343 break; | 359 break; |
| 344 case rtcp::Tmmbr::kFeedbackMessageType: | 360 case rtcp::Tmmbr::kFeedbackMessageType: |
| 345 HandleTMMBR(rtcp_block, *packet_information); | 361 HandleTMMBR(rtcp_block, packet_information); |
| 346 break; | 362 break; |
| 347 case rtcp::Tmmbn::kFeedbackMessageType: | 363 case rtcp::Tmmbn::kFeedbackMessageType: |
| 348 HandleTMMBN(rtcp_block, *packet_information); | 364 HandleTMMBN(rtcp_block, packet_information); |
| 349 break; | 365 break; |
| 350 case rtcp::RapidResyncRequest::kFeedbackMessageType: | 366 case rtcp::RapidResyncRequest::kFeedbackMessageType: |
| 351 HandleSR_REQ(rtcp_block, *packet_information); | 367 HandleSR_REQ(rtcp_block, packet_information); |
| 352 break; | 368 break; |
| 353 case rtcp::TransportFeedback::kFeedbackMessageType: | 369 case rtcp::TransportFeedback::kFeedbackMessageType: |
| 354 HandleTransportFeedback(rtcp_block, packet_information); | 370 HandleTransportFeedback(rtcp_block, packet_information); |
| 355 break; | 371 break; |
| 356 default: | 372 default: |
| 357 ++num_skipped_packets_; | 373 ++num_skipped_packets_; |
| 358 break; | 374 break; |
| 359 } | 375 } |
| 360 break; | 376 break; |
| 361 case rtcp::Psfb::kPacketType: | 377 case rtcp::Psfb::kPacketType: |
| 362 switch (rtcp_block.fmt()) { | 378 switch (rtcp_block.fmt()) { |
| 363 case rtcp::Pli::kFeedbackMessageType: | 379 case rtcp::Pli::kFeedbackMessageType: |
| 364 HandlePLI(rtcp_block, *packet_information); | 380 HandlePLI(rtcp_block, packet_information); |
| 365 break; | 381 break; |
| 366 case rtcp::Sli::kFeedbackMessageType: | 382 case rtcp::Sli::kFeedbackMessageType: |
| 367 HandleSLI(rtcp_block, *packet_information); | 383 HandleSLI(rtcp_block, packet_information); |
| 368 break; | 384 break; |
| 369 case rtcp::Rpsi::kFeedbackMessageType: | 385 case rtcp::Rpsi::kFeedbackMessageType: |
| 370 HandleRPSI(rtcp_block, *packet_information); | 386 HandleRPSI(rtcp_block, packet_information); |
| 371 break; | 387 break; |
| 372 case rtcp::Fir::kFeedbackMessageType: | 388 case rtcp::Fir::kFeedbackMessageType: |
| 373 HandleFIR(rtcp_block, *packet_information); | 389 HandleFIR(rtcp_block, packet_information); |
| 374 break; | 390 break; |
| 375 case rtcp::Remb::kFeedbackMessageType: | 391 case rtcp::Remb::kFeedbackMessageType: |
| 376 HandlePsfbApp(rtcp_block, *packet_information); | 392 HandlePsfbApp(rtcp_block, packet_information); |
| 377 break; | 393 break; |
| 378 default: | 394 default: |
| 379 ++num_skipped_packets_; | 395 ++num_skipped_packets_; |
| 380 break; | 396 break; |
| 381 } | 397 } |
| 382 break; | 398 break; |
| 383 default: | 399 default: |
| 384 ++num_skipped_packets_; | 400 ++num_skipped_packets_; |
| 385 break; | 401 break; |
| 386 } | 402 } |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 397 last_skipped_packets_warning_ = now; | 413 last_skipped_packets_warning_ = now; |
| 398 LOG(LS_WARNING) << num_skipped_packets_ | 414 LOG(LS_WARNING) << num_skipped_packets_ |
| 399 << " RTCP blocks were skipped due to being malformed or of " | 415 << " RTCP blocks were skipped due to being malformed or of " |
| 400 "unrecognized/unsupported type, during the past " | 416 "unrecognized/unsupported type, during the past " |
| 401 << (kMaxWarningLogIntervalMs / 1000) << " second period."; | 417 << (kMaxWarningLogIntervalMs / 1000) << " second period."; |
| 402 } | 418 } |
| 403 | 419 |
| 404 return true; | 420 return true; |
| 405 } | 421 } |
| 406 | 422 |
| 407 void RTCPReceiver::HandleSenderReport( | 423 void RTCPReceiver::HandleSenderReport(const CommonHeader& rtcp_block, |
| 408 const CommonHeader& rtcp_block, | 424 PacketInformation* packet_information) { |
| 409 RTCPPacketInformation& rtcpPacketInformation) { | |
| 410 rtcp::SenderReport sender_report; | 425 rtcp::SenderReport sender_report; |
| 411 if (!sender_report.Parse(rtcp_block)) { | 426 if (!sender_report.Parse(rtcp_block)) { |
| 412 ++num_skipped_packets_; | 427 ++num_skipped_packets_; |
| 413 return; | 428 return; |
| 414 } | 429 } |
| 415 | 430 |
| 416 const uint32_t remoteSSRC = sender_report.sender_ssrc(); | 431 const uint32_t remoteSSRC = sender_report.sender_ssrc(); |
| 417 | 432 |
| 418 rtcpPacketInformation.remoteSSRC = remoteSSRC; | 433 packet_information->remote_ssrc = remoteSSRC; |
| 419 | 434 |
| 420 RTCPReceiveInformation* ptrReceiveInfo = CreateReceiveInformation(remoteSSRC); | 435 RTCPReceiveInformation* ptrReceiveInfo = CreateReceiveInformation(remoteSSRC); |
| 421 if (!ptrReceiveInfo) | 436 if (!ptrReceiveInfo) |
| 422 return; | 437 return; |
| 423 | 438 |
| 424 TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "SR", | 439 TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "SR", |
| 425 "remote_ssrc", remoteSSRC, "ssrc", main_ssrc_); | 440 "remote_ssrc", remoteSSRC, "ssrc", main_ssrc_); |
| 426 | 441 |
| 427 // Have I received RTP packets from this party? | 442 // Have I received RTP packets from this party? |
| 428 if (_remoteSSRC == remoteSSRC) { | 443 if (_remoteSSRC == remoteSSRC) { |
| 429 // Only signal that we have received a SR when we accept one. | 444 // Only signal that we have received a SR when we accept one. |
| 430 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpSr; | 445 packet_information->packet_type_flags |= kRtcpSr; |
| 431 | |
| 432 rtcpPacketInformation.ntp_secs = sender_report.ntp().seconds(); | |
| 433 rtcpPacketInformation.ntp_frac = sender_report.ntp().fractions(); | |
| 434 rtcpPacketInformation.rtp_timestamp = sender_report.rtp_timestamp(); | |
| 435 | 446 |
| 436 // Save the NTP time of this report. | 447 // Save the NTP time of this report. |
| 437 _remoteSenderInfo.NTPseconds = sender_report.ntp().seconds(); | 448 _remoteSenderInfo.NTPseconds = sender_report.ntp().seconds(); |
| 438 _remoteSenderInfo.NTPfraction = sender_report.ntp().fractions(); | 449 _remoteSenderInfo.NTPfraction = sender_report.ntp().fractions(); |
| 439 _remoteSenderInfo.RTPtimeStamp = sender_report.rtp_timestamp(); | 450 _remoteSenderInfo.RTPtimeStamp = sender_report.rtp_timestamp(); |
| 440 _remoteSenderInfo.sendPacketCount = sender_report.sender_packet_count(); | 451 _remoteSenderInfo.sendPacketCount = sender_report.sender_packet_count(); |
| 441 _remoteSenderInfo.sendOctetCount = sender_report.sender_octet_count(); | 452 _remoteSenderInfo.sendOctetCount = sender_report.sender_octet_count(); |
| 442 | 453 |
| 443 _clock->CurrentNtp(_lastReceivedSRNTPsecs, _lastReceivedSRNTPfrac); | 454 _clock->CurrentNtp(_lastReceivedSRNTPsecs, _lastReceivedSRNTPfrac); |
| 444 } else { | 455 } else { |
| 445 // We will only store the send report from one source, but | 456 // We will only store the send report from one source, but |
| 446 // we will store all the receive blocks. | 457 // we will store all the receive blocks. |
| 447 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpRr; | 458 packet_information->packet_type_flags |= kRtcpRr; |
| 448 } | 459 } |
| 449 // Update that this remote is alive. | 460 // Update that this remote is alive. |
| 450 ptrReceiveInfo->last_time_received_ms = _clock->TimeInMilliseconds(); | 461 ptrReceiveInfo->last_time_received_ms = _clock->TimeInMilliseconds(); |
| 451 | 462 |
| 452 for (const rtcp::ReportBlock report_block : sender_report.report_blocks()) | 463 for (const rtcp::ReportBlock report_block : sender_report.report_blocks()) |
| 453 HandleReportBlock(report_block, rtcpPacketInformation, remoteSSRC); | 464 HandleReportBlock(report_block, packet_information, remoteSSRC); |
| 454 } | 465 } |
| 455 | 466 |
| 456 void RTCPReceiver::HandleReceiverReport( | 467 void RTCPReceiver::HandleReceiverReport(const CommonHeader& rtcp_block, |
| 457 const CommonHeader& rtcp_block, | 468 PacketInformation* packet_information) { |
| 458 RTCPPacketInformation& rtcpPacketInformation) { | |
| 459 rtcp::ReceiverReport receiver_report; | 469 rtcp::ReceiverReport receiver_report; |
| 460 if (!receiver_report.Parse(rtcp_block)) { | 470 if (!receiver_report.Parse(rtcp_block)) { |
| 461 ++num_skipped_packets_; | 471 ++num_skipped_packets_; |
| 462 return; | 472 return; |
| 463 } | 473 } |
| 464 | 474 |
| 465 const uint32_t remoteSSRC = receiver_report.sender_ssrc(); | 475 const uint32_t remoteSSRC = receiver_report.sender_ssrc(); |
| 466 | 476 |
| 467 rtcpPacketInformation.remoteSSRC = remoteSSRC; | 477 packet_information->remote_ssrc = remoteSSRC; |
| 468 | 478 |
| 469 RTCPReceiveInformation* ptrReceiveInfo = CreateReceiveInformation(remoteSSRC); | 479 RTCPReceiveInformation* ptrReceiveInfo = CreateReceiveInformation(remoteSSRC); |
| 470 if (!ptrReceiveInfo) | 480 if (!ptrReceiveInfo) |
| 471 return; | 481 return; |
| 472 | 482 |
| 473 TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "RR", | 483 TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "RR", |
| 474 "remote_ssrc", remoteSSRC, "ssrc", main_ssrc_); | 484 "remote_ssrc", remoteSSRC, "ssrc", main_ssrc_); |
| 475 | 485 |
| 476 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpRr; | 486 packet_information->packet_type_flags |= kRtcpRr; |
| 477 | 487 |
| 478 // Update that this remote is alive. | 488 // Update that this remote is alive. |
| 479 ptrReceiveInfo->last_time_received_ms = _clock->TimeInMilliseconds(); | 489 ptrReceiveInfo->last_time_received_ms = _clock->TimeInMilliseconds(); |
| 480 | 490 |
| 481 for (const ReportBlock& report_block : receiver_report.report_blocks()) | 491 for (const ReportBlock& report_block : receiver_report.report_blocks()) |
| 482 HandleReportBlock(report_block, rtcpPacketInformation, remoteSSRC); | 492 HandleReportBlock(report_block, packet_information, remoteSSRC); |
| 483 } | 493 } |
| 484 | 494 |
| 485 void RTCPReceiver::HandleReportBlock( | 495 void RTCPReceiver::HandleReportBlock(const ReportBlock& report_block, |
| 486 const ReportBlock& report_block, | 496 PacketInformation* packet_information, |
| 487 RTCPPacketInformation& rtcpPacketInformation, | 497 uint32_t remoteSSRC) { |
| 488 uint32_t remoteSSRC) { | |
| 489 // This will be called once per report block in the RTCP packet. | 498 // This will be called once per report block in the RTCP packet. |
| 490 // We filter out all report blocks that are not for us. | 499 // We filter out all report blocks that are not for us. |
| 491 // Each packet has max 31 RR blocks. | 500 // Each packet has max 31 RR blocks. |
| 492 // | 501 // |
| 493 // We can calc RTT if we send a send report and get a report block back. | 502 // We can calc RTT if we send a send report and get a report block back. |
| 494 | 503 |
| 495 // |rtcpPacket.ReportBlockItem.SSRC| is the SSRC identifier of the source to | 504 // |rtcpPacket.ReportBlockItem.SSRC| is the SSRC identifier of the source to |
| 496 // which the information in this reception report block pertains. | 505 // which the information in this reception report block pertains. |
| 497 | 506 |
| 498 // Filter out all report blocks that are not for us. | 507 // Filter out all report blocks that are not for us. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 567 } else { | 576 } else { |
| 568 // First RTT. | 577 // First RTT. |
| 569 reportBlock->avgRTT = rtt; | 578 reportBlock->avgRTT = rtt; |
| 570 } | 579 } |
| 571 reportBlock->numAverageCalcs++; | 580 reportBlock->numAverageCalcs++; |
| 572 } | 581 } |
| 573 | 582 |
| 574 TRACE_COUNTER_ID1(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "RR_RTT", | 583 TRACE_COUNTER_ID1(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "RR_RTT", |
| 575 report_block.source_ssrc(), rtt); | 584 report_block.source_ssrc(), rtt); |
| 576 | 585 |
| 577 rtcpPacketInformation.AddReportInfo(*reportBlock); | 586 packet_information->rtt_ms = rtt; |
| 587 packet_information->report_blocks.push_back(reportBlock->remoteReceiveBlock); | |
| 578 } | 588 } |
| 579 | 589 |
| 580 RTCPReportBlockInformation* RTCPReceiver::CreateOrGetReportBlockInformation( | 590 RTCPReportBlockInformation* RTCPReceiver::CreateOrGetReportBlockInformation( |
| 581 uint32_t remote_ssrc, | 591 uint32_t remote_ssrc, |
| 582 uint32_t source_ssrc) { | 592 uint32_t source_ssrc) { |
| 583 RTCPReportBlockInformation* info = | 593 RTCPReportBlockInformation* info = |
| 584 GetReportBlockInformation(remote_ssrc, source_ssrc); | 594 GetReportBlockInformation(remote_ssrc, source_ssrc); |
| 585 if (info == NULL) { | 595 if (info == NULL) { |
| 586 info = new RTCPReportBlockInformation; | 596 info = new RTCPReportBlockInformation; |
| 587 _receivedReportBlockMap[source_ssrc][remote_ssrc] = info; | 597 _receivedReportBlockMap[source_ssrc][remote_ssrc] = info; |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 743 return std::vector<rtcp::TmmbItem>(); | 753 return std::vector<rtcp::TmmbItem>(); |
| 744 } | 754 } |
| 745 RTCPReceiveInformation* receiveInfo = receiveInfoIt->second; | 755 RTCPReceiveInformation* receiveInfo = receiveInfoIt->second; |
| 746 RTC_DCHECK(receiveInfo); | 756 RTC_DCHECK(receiveInfo); |
| 747 | 757 |
| 748 *tmmbr_owner = TMMBRHelp::IsOwner(receiveInfo->tmmbn, main_ssrc_); | 758 *tmmbr_owner = TMMBRHelp::IsOwner(receiveInfo->tmmbn, main_ssrc_); |
| 749 return receiveInfo->tmmbn; | 759 return receiveInfo->tmmbn; |
| 750 } | 760 } |
| 751 | 761 |
| 752 void RTCPReceiver::HandleSDES(const CommonHeader& rtcp_block, | 762 void RTCPReceiver::HandleSDES(const CommonHeader& rtcp_block, |
| 753 RTCPPacketInformation& rtcpPacketInformation) { | 763 PacketInformation* packet_information) { |
| 754 rtcp::Sdes sdes; | 764 rtcp::Sdes sdes; |
| 755 if (!sdes.Parse(rtcp_block)) { | 765 if (!sdes.Parse(rtcp_block)) { |
| 756 ++num_skipped_packets_; | 766 ++num_skipped_packets_; |
| 757 return; | 767 return; |
| 758 } | 768 } |
| 759 | 769 |
| 760 for (const rtcp::Sdes::Chunk& chunk : sdes.chunks()) { | 770 for (const rtcp::Sdes::Chunk& chunk : sdes.chunks()) { |
| 761 RTCPCnameInformation* cnameInfo = CreateCnameInformation(chunk.ssrc); | 771 RTCPCnameInformation* cnameInfo = CreateCnameInformation(chunk.ssrc); |
| 762 RTC_DCHECK(cnameInfo); | 772 RTC_DCHECK(cnameInfo); |
| 763 | 773 |
| 764 cnameInfo->name[RTCP_CNAME_SIZE - 1] = 0; | 774 cnameInfo->name[RTCP_CNAME_SIZE - 1] = 0; |
| 765 strncpy(cnameInfo->name, chunk.cname.c_str(), RTCP_CNAME_SIZE - 1); | 775 strncpy(cnameInfo->name, chunk.cname.c_str(), RTCP_CNAME_SIZE - 1); |
| 766 { | 776 { |
| 767 rtc::CritScope lock(&_criticalSectionFeedbacks); | 777 rtc::CritScope lock(&_criticalSectionFeedbacks); |
| 768 if (stats_callback_) | 778 if (stats_callback_) |
| 769 stats_callback_->CNameChanged(chunk.cname.c_str(), chunk.ssrc); | 779 stats_callback_->CNameChanged(chunk.cname.c_str(), chunk.ssrc); |
| 770 } | 780 } |
| 771 } | 781 } |
| 772 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpSdes; | 782 packet_information->packet_type_flags |= kRtcpSdes; |
| 773 } | 783 } |
| 774 | 784 |
| 775 void RTCPReceiver::HandleNACK(const CommonHeader& rtcp_block, | 785 void RTCPReceiver::HandleNACK(const CommonHeader& rtcp_block, |
| 776 RTCPPacketInformation& rtcpPacketInformation) { | 786 PacketInformation* packet_information) { |
| 777 rtcp::Nack nack; | 787 rtcp::Nack nack; |
| 778 if (!nack.Parse(rtcp_block)) { | 788 if (!nack.Parse(rtcp_block)) { |
| 779 ++num_skipped_packets_; | 789 ++num_skipped_packets_; |
| 780 return; | 790 return; |
| 781 } | 791 } |
| 782 | 792 |
| 783 if (receiver_only_ || main_ssrc_ != nack.media_ssrc()) // Not to us. | 793 if (receiver_only_ || main_ssrc_ != nack.media_ssrc()) // Not to us. |
| 784 return; | 794 return; |
| 785 | 795 |
| 786 rtcpPacketInformation.nackSequenceNumbers = nack.packet_ids(); | 796 packet_information->nack_sequence_numbers = nack.packet_ids(); |
| 787 for (uint16_t packet_id : nack.packet_ids()) | 797 for (uint16_t packet_id : nack.packet_ids()) |
| 788 nack_stats_.ReportRequest(packet_id); | 798 nack_stats_.ReportRequest(packet_id); |
| 789 | 799 |
| 790 if (!nack.packet_ids().empty()) { | 800 if (!nack.packet_ids().empty()) { |
| 791 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpNack; | 801 packet_information->packet_type_flags |= kRtcpNack; |
| 792 ++packet_type_counter_.nack_packets; | 802 ++packet_type_counter_.nack_packets; |
| 793 packet_type_counter_.nack_requests = nack_stats_.requests(); | 803 packet_type_counter_.nack_requests = nack_stats_.requests(); |
| 794 packet_type_counter_.unique_nack_requests = nack_stats_.unique_requests(); | 804 packet_type_counter_.unique_nack_requests = nack_stats_.unique_requests(); |
| 795 } | 805 } |
| 796 } | 806 } |
| 797 | 807 |
| 798 void RTCPReceiver::HandleBYE(const CommonHeader& rtcp_block) { | 808 void RTCPReceiver::HandleBYE(const CommonHeader& rtcp_block) { |
| 799 rtcp::Bye bye; | 809 rtcp::Bye bye; |
| 800 if (!bye.Parse(rtcp_block)) { | 810 if (!bye.Parse(rtcp_block)) { |
| 801 ++num_skipped_packets_; | 811 ++num_skipped_packets_; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 824 _receivedCnameMap.find(bye.sender_ssrc()); | 834 _receivedCnameMap.find(bye.sender_ssrc()); |
| 825 | 835 |
| 826 if (cnameInfoIt != _receivedCnameMap.end()) { | 836 if (cnameInfoIt != _receivedCnameMap.end()) { |
| 827 delete cnameInfoIt->second; | 837 delete cnameInfoIt->second; |
| 828 _receivedCnameMap.erase(cnameInfoIt); | 838 _receivedCnameMap.erase(cnameInfoIt); |
| 829 } | 839 } |
| 830 xr_rr_rtt_ms_ = 0; | 840 xr_rr_rtt_ms_ = 0; |
| 831 } | 841 } |
| 832 | 842 |
| 833 void RTCPReceiver::HandleXr(const CommonHeader& rtcp_block, | 843 void RTCPReceiver::HandleXr(const CommonHeader& rtcp_block, |
| 834 RTCPPacketInformation& rtcpPacketInformation) { | 844 PacketInformation* packet_information) { |
| 835 rtcp::ExtendedReports xr; | 845 rtcp::ExtendedReports xr; |
| 836 if (!xr.Parse(rtcp_block)) { | 846 if (!xr.Parse(rtcp_block)) { |
| 837 ++num_skipped_packets_; | 847 ++num_skipped_packets_; |
| 838 return; | 848 return; |
| 839 } | 849 } |
| 840 | 850 |
| 841 rtcpPacketInformation.xr_originator_ssrc = xr.sender_ssrc(); | |
| 842 for (const rtcp::Rrtr& rrtr : xr.rrtrs()) | 851 for (const rtcp::Rrtr& rrtr : xr.rrtrs()) |
| 843 HandleXrReceiveReferenceTime(rrtr, rtcpPacketInformation); | 852 HandleXrReceiveReferenceTime(xr.sender_ssrc(), rrtr); |
| 844 | 853 |
| 845 for (const rtcp::Dlrr& dlrr : xr.dlrrs()) { | 854 for (const rtcp::Dlrr& dlrr : xr.dlrrs()) { |
| 846 for (const rtcp::ReceiveTimeInfo& time_info : dlrr.sub_blocks()) | 855 for (const rtcp::ReceiveTimeInfo& time_info : dlrr.sub_blocks()) |
| 847 HandleXrDlrrReportBlock(time_info, rtcpPacketInformation); | 856 HandleXrDlrrReportBlock(time_info); |
| 848 } | 857 } |
| 849 } | 858 } |
| 850 | 859 |
| 851 void RTCPReceiver::HandleXrReceiveReferenceTime( | 860 void RTCPReceiver::HandleXrReceiveReferenceTime( |
| 852 const rtcp::Rrtr& rrtr, | 861 uint32_t sender_ssrc, |
| 853 RTCPPacketInformation& rtcpPacketInformation) { | 862 const rtcp::Rrtr& rrtr) { |
| 854 _remoteXRReceiveTimeInfo.sourceSSRC = | 863 _remoteXRReceiveTimeInfo.sourceSSRC = sender_ssrc; |
| 855 rtcpPacketInformation.xr_originator_ssrc; | |
| 856 | |
| 857 _remoteXRReceiveTimeInfo.lastRR = CompactNtp(rrtr.ntp()); | 864 _remoteXRReceiveTimeInfo.lastRR = CompactNtp(rrtr.ntp()); |
| 858 | |
| 859 _clock->CurrentNtp(_lastReceivedXRNTPsecs, _lastReceivedXRNTPfrac); | 865 _clock->CurrentNtp(_lastReceivedXRNTPsecs, _lastReceivedXRNTPfrac); |
| 860 | |
| 861 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpXrReceiverReferenceTime; | |
| 862 } | 866 } |
| 863 | 867 |
| 864 void RTCPReceiver::HandleXrDlrrReportBlock( | 868 void RTCPReceiver::HandleXrDlrrReportBlock(const rtcp::ReceiveTimeInfo& rti) { |
| 865 const rtcp::ReceiveTimeInfo& rti, | |
| 866 RTCPPacketInformation& rtcpPacketInformation) { | |
| 867 if (registered_ssrcs_.count(rti.ssrc) == 0) // Not to us. | 869 if (registered_ssrcs_.count(rti.ssrc) == 0) // Not to us. |
| 868 return; | 870 return; |
| 869 | 871 |
| 870 rtcpPacketInformation.xr_dlrr_item = true; | |
| 871 | |
| 872 // Caller should explicitly enable rtt calculation using extended reports. | 872 // Caller should explicitly enable rtt calculation using extended reports. |
| 873 if (!xr_rrtr_status_) | 873 if (!xr_rrtr_status_) |
| 874 return; | 874 return; |
| 875 | 875 |
| 876 // The send_time and delay_rr fields are in units of 1/2^16 sec. | 876 // The send_time and delay_rr fields are in units of 1/2^16 sec. |
| 877 uint32_t send_time = rti.last_rr; | 877 uint32_t send_time = rti.last_rr; |
| 878 // RFC3611, section 4.5, LRR field discription states: | 878 // RFC3611, section 4.5, LRR field discription states: |
| 879 // If no such block has been received, the field is set to zero. | 879 // If no such block has been received, the field is set to zero. |
| 880 if (send_time == 0) | 880 if (send_time == 0) |
| 881 return; | 881 return; |
| 882 | 882 |
| 883 uint32_t delay_rr = rti.delay_since_last_rr; | 883 uint32_t delay_rr = rti.delay_since_last_rr; |
| 884 uint32_t now = CompactNtp(NtpTime(*_clock)); | 884 uint32_t now = CompactNtp(NtpTime(*_clock)); |
| 885 | 885 |
| 886 uint32_t rtt_ntp = now - delay_rr - send_time; | 886 uint32_t rtt_ntp = now - delay_rr - send_time; |
| 887 xr_rr_rtt_ms_ = CompactNtpRttToMs(rtt_ntp); | 887 xr_rr_rtt_ms_ = CompactNtpRttToMs(rtt_ntp); |
| 888 | |
| 889 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpXrDlrrReportBlock; | |
| 890 } | 888 } |
| 891 | 889 |
| 892 void RTCPReceiver::HandlePLI(const CommonHeader& rtcp_block, | 890 void RTCPReceiver::HandlePLI(const CommonHeader& rtcp_block, |
| 893 RTCPPacketInformation& rtcpPacketInformation) { | 891 PacketInformation* packet_information) { |
| 894 rtcp::Pli pli; | 892 rtcp::Pli pli; |
| 895 if (!pli.Parse(rtcp_block)) { | 893 if (!pli.Parse(rtcp_block)) { |
| 896 ++num_skipped_packets_; | 894 ++num_skipped_packets_; |
| 897 return; | 895 return; |
| 898 } | 896 } |
| 899 | 897 |
| 900 if (main_ssrc_ == pli.media_ssrc()) { | 898 if (main_ssrc_ == pli.media_ssrc()) { |
| 901 TRACE_EVENT_INSTANT0(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "PLI"); | 899 TRACE_EVENT_INSTANT0(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "PLI"); |
| 902 | 900 |
| 903 ++packet_type_counter_.pli_packets; | 901 ++packet_type_counter_.pli_packets; |
| 904 // Received a signal that we need to send a new key frame. | 902 // Received a signal that we need to send a new key frame. |
| 905 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpPli; | 903 packet_information->packet_type_flags |= kRtcpPli; |
| 906 } | 904 } |
| 907 } | 905 } |
| 908 | 906 |
| 909 void RTCPReceiver::HandleTMMBR(const CommonHeader& rtcp_block, | 907 void RTCPReceiver::HandleTMMBR(const CommonHeader& rtcp_block, |
| 910 RTCPPacketInformation& rtcpPacketInformation) { | 908 PacketInformation* packet_information) { |
| 911 rtcp::Tmmbr tmmbr; | 909 rtcp::Tmmbr tmmbr; |
| 912 if (!tmmbr.Parse(rtcp_block)) { | 910 if (!tmmbr.Parse(rtcp_block)) { |
| 913 ++num_skipped_packets_; | 911 ++num_skipped_packets_; |
| 914 return; | 912 return; |
| 915 } | 913 } |
| 916 | 914 |
| 917 uint32_t senderSSRC = tmmbr.sender_ssrc(); | 915 uint32_t senderSSRC = tmmbr.sender_ssrc(); |
| 918 RTCPReceiveInformation* ptrReceiveInfo = GetReceiveInformation(senderSSRC); | 916 RTCPReceiveInformation* ptrReceiveInfo = GetReceiveInformation(senderSSRC); |
| 919 if (!ptrReceiveInfo) // This remote SSRC must be saved before. | 917 if (!ptrReceiveInfo) // This remote SSRC must be saved before. |
| 920 return; | 918 return; |
| 921 | 919 |
| 922 if (tmmbr.media_ssrc()) { | 920 if (tmmbr.media_ssrc()) { |
| 923 // media_ssrc() SHOULD be 0 if same as SenderSSRC. | 921 // media_ssrc() SHOULD be 0 if same as SenderSSRC. |
| 924 // In relay mode this is a valid number. | 922 // In relay mode this is a valid number. |
| 925 senderSSRC = tmmbr.media_ssrc(); | 923 senderSSRC = tmmbr.media_ssrc(); |
| 926 } | 924 } |
| 927 | 925 |
| 928 for (const rtcp::TmmbItem& request : tmmbr.requests()) { | 926 for (const rtcp::TmmbItem& request : tmmbr.requests()) { |
| 929 if (main_ssrc_ == request.ssrc() && request.bitrate_bps()) { | 927 if (main_ssrc_ == request.ssrc() && request.bitrate_bps()) { |
| 930 ptrReceiveInfo->InsertTmmbrItem(senderSSRC, request, | 928 ptrReceiveInfo->InsertTmmbrItem(senderSSRC, request, |
| 931 _clock->TimeInMilliseconds()); | 929 _clock->TimeInMilliseconds()); |
| 932 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpTmmbr; | 930 packet_information->packet_type_flags |= kRtcpTmmbr; |
| 933 } | 931 } |
| 934 } | 932 } |
| 935 } | 933 } |
| 936 | 934 |
| 937 void RTCPReceiver::HandleTMMBN(const CommonHeader& rtcp_block, | 935 void RTCPReceiver::HandleTMMBN(const CommonHeader& rtcp_block, |
| 938 RTCPPacketInformation& rtcpPacketInformation) { | 936 PacketInformation* packet_information) { |
| 939 rtcp::Tmmbn tmmbn; | 937 rtcp::Tmmbn tmmbn; |
| 940 if (!tmmbn.Parse(rtcp_block)) { | 938 if (!tmmbn.Parse(rtcp_block)) { |
| 941 ++num_skipped_packets_; | 939 ++num_skipped_packets_; |
| 942 return; | 940 return; |
| 943 } | 941 } |
| 944 | 942 |
| 945 RTCPReceiveInformation* ptrReceiveInfo = | 943 RTCPReceiveInformation* ptrReceiveInfo = |
| 946 GetReceiveInformation(tmmbn.sender_ssrc()); | 944 GetReceiveInformation(tmmbn.sender_ssrc()); |
| 947 if (!ptrReceiveInfo) // This remote SSRC must be saved before. | 945 if (!ptrReceiveInfo) // This remote SSRC must be saved before. |
| 948 return; | 946 return; |
| 949 | 947 |
| 950 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpTmmbn; | 948 packet_information->packet_type_flags |= kRtcpTmmbn; |
| 951 | 949 |
| 952 for (const auto& item : tmmbn.items()) | 950 for (const auto& item : tmmbn.items()) |
| 953 ptrReceiveInfo->tmmbn.push_back(item); | 951 ptrReceiveInfo->tmmbn.push_back(item); |
| 954 } | 952 } |
| 955 | 953 |
| 956 void RTCPReceiver::HandleSR_REQ(const CommonHeader& rtcp_block, | 954 void RTCPReceiver::HandleSR_REQ(const CommonHeader& rtcp_block, |
| 957 RTCPPacketInformation& rtcpPacketInformation) { | 955 PacketInformation* packet_information) { |
| 958 rtcp::RapidResyncRequest sr_req; | 956 rtcp::RapidResyncRequest sr_req; |
| 959 if (!sr_req.Parse(rtcp_block)) { | 957 if (!sr_req.Parse(rtcp_block)) { |
| 960 ++num_skipped_packets_; | 958 ++num_skipped_packets_; |
| 961 return; | 959 return; |
| 962 } | 960 } |
| 963 | 961 |
| 964 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpSrReq; | 962 packet_information->packet_type_flags |= kRtcpSrReq; |
| 965 } | 963 } |
| 966 | 964 |
| 967 void RTCPReceiver::HandleSLI(const CommonHeader& rtcp_block, | 965 void RTCPReceiver::HandleSLI(const CommonHeader& rtcp_block, |
| 968 RTCPPacketInformation& rtcpPacketInformation) { | 966 PacketInformation* packet_information) { |
| 969 rtcp::Sli sli; | 967 rtcp::Sli sli; |
| 970 if (!sli.Parse(rtcp_block)) { | 968 if (!sli.Parse(rtcp_block)) { |
| 971 ++num_skipped_packets_; | 969 ++num_skipped_packets_; |
| 972 return; | 970 return; |
| 973 } | 971 } |
| 974 | 972 |
| 975 for (const rtcp::Sli::Macroblocks& item : sli.macroblocks()) { | 973 for (const rtcp::Sli::Macroblocks& item : sli.macroblocks()) { |
| 976 // In theory there could be multiple slices lost. | 974 // In theory there could be multiple slices lost. |
| 977 // Received signal that we need to refresh a slice. | 975 // Received signal that we need to refresh a slice. |
| 978 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpSli; | 976 packet_information->packet_type_flags |= kRtcpSli; |
| 979 rtcpPacketInformation.sliPictureId = item.picture_id(); | 977 packet_information->sli_picture_id = item.picture_id(); |
| 980 } | 978 } |
| 981 } | 979 } |
| 982 | 980 |
| 983 void RTCPReceiver::HandleRPSI( | 981 void RTCPReceiver::HandleRPSI(const CommonHeader& rtcp_block, |
| 984 const CommonHeader& rtcp_block, | 982 PacketInformation* packet_information) { |
| 985 RTCPHelp::RTCPPacketInformation& rtcpPacketInformation) { | |
| 986 rtcp::Rpsi rpsi; | 983 rtcp::Rpsi rpsi; |
| 987 if (!rpsi.Parse(rtcp_block)) { | 984 if (!rpsi.Parse(rtcp_block)) { |
| 988 ++num_skipped_packets_; | 985 ++num_skipped_packets_; |
| 989 return; | 986 return; |
| 990 } | 987 } |
| 991 | 988 |
| 992 // Received signal that we have a confirmed reference picture. | 989 // Received signal that we have a confirmed reference picture. |
| 993 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpRpsi; | 990 packet_information->packet_type_flags |= kRtcpRpsi; |
| 994 rtcpPacketInformation.rpsiPictureId = rpsi.picture_id(); | 991 packet_information->rpsi_picture_id = rpsi.picture_id(); |
| 995 } | 992 } |
| 996 | 993 |
| 997 void RTCPReceiver::HandlePsfbApp(const CommonHeader& rtcp_block, | 994 void RTCPReceiver::HandlePsfbApp(const CommonHeader& rtcp_block, |
| 998 RTCPPacketInformation& rtcpPacketInformation) { | 995 PacketInformation* packet_information) { |
| 999 rtcp::Remb remb; | 996 rtcp::Remb remb; |
| 1000 if (remb.Parse(rtcp_block)) { | 997 if (remb.Parse(rtcp_block)) { |
| 1001 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpRemb; | 998 packet_information->packet_type_flags |= kRtcpRemb; |
| 1002 rtcpPacketInformation.receiverEstimatedMaxBitrate = remb.bitrate_bps(); | 999 packet_information->receiver_estimated_max_bitrate_bps = remb.bitrate_bps(); |
| 1003 return; | 1000 return; |
| 1004 } | 1001 } |
| 1005 | 1002 |
| 1006 ++num_skipped_packets_; | 1003 ++num_skipped_packets_; |
| 1007 } | 1004 } |
| 1008 | 1005 |
| 1009 void RTCPReceiver::HandleFIR(const CommonHeader& rtcp_block, | 1006 void RTCPReceiver::HandleFIR(const CommonHeader& rtcp_block, |
| 1010 RTCPPacketInformation& rtcpPacketInformation) { | 1007 PacketInformation* packet_information) { |
| 1011 rtcp::Fir fir; | 1008 rtcp::Fir fir; |
| 1012 if (!fir.Parse(rtcp_block)) { | 1009 if (!fir.Parse(rtcp_block)) { |
| 1013 ++num_skipped_packets_; | 1010 ++num_skipped_packets_; |
| 1014 return; | 1011 return; |
| 1015 } | 1012 } |
| 1016 | 1013 |
| 1017 RTCPReceiveInformation* ptrReceiveInfo = | 1014 RTCPReceiveInformation* ptrReceiveInfo = |
| 1018 GetReceiveInformation(fir.sender_ssrc()); | 1015 GetReceiveInformation(fir.sender_ssrc()); |
| 1019 | 1016 |
| 1020 for (const rtcp::Fir::Request& fir_request : fir.requests()) { | 1017 for (const rtcp::Fir::Request& fir_request : fir.requests()) { |
| 1021 // Is it our sender that is requested to generate a new keyframe | 1018 // Is it our sender that is requested to generate a new keyframe |
| 1022 if (main_ssrc_ != fir_request.ssrc) | 1019 if (main_ssrc_ != fir_request.ssrc) |
| 1023 continue; | 1020 continue; |
| 1024 | 1021 |
| 1025 ++packet_type_counter_.fir_packets; | 1022 ++packet_type_counter_.fir_packets; |
| 1026 | 1023 |
| 1027 // rtcpPacket.FIR.MediaSSRC SHOULD be 0 but we ignore to check it | 1024 // rtcpPacket.FIR.MediaSSRC SHOULD be 0 but we ignore to check it |
| 1028 // we don't know who this originate from | 1025 // we don't know who this originate from |
| 1029 if (ptrReceiveInfo) { | 1026 if (ptrReceiveInfo) { |
| 1030 // check if we have reported this FIRSequenceNumber before | 1027 // check if we have reported this FIRSequenceNumber before |
| 1031 if (fir_request.seq_nr != ptrReceiveInfo->last_fir_sequence_number) { | 1028 if (fir_request.seq_nr != ptrReceiveInfo->last_fir_sequence_number) { |
| 1032 int64_t now = _clock->TimeInMilliseconds(); | 1029 int64_t now = _clock->TimeInMilliseconds(); |
| 1033 // sanity; don't go crazy with the callbacks | 1030 // sanity; don't go crazy with the callbacks |
| 1034 if ((now - ptrReceiveInfo->last_fir_request_ms) > | 1031 if ((now - ptrReceiveInfo->last_fir_request_ms) > |
| 1035 RTCP_MIN_FRAME_LENGTH_MS) { | 1032 RTCP_MIN_FRAME_LENGTH_MS) { |
| 1036 ptrReceiveInfo->last_fir_request_ms = now; | 1033 ptrReceiveInfo->last_fir_request_ms = now; |
| 1037 ptrReceiveInfo->last_fir_sequence_number = fir_request.seq_nr; | 1034 ptrReceiveInfo->last_fir_sequence_number = fir_request.seq_nr; |
| 1038 // received signal that we need to send a new key frame | 1035 // received signal that we need to send a new key frame |
| 1039 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpFir; | 1036 packet_information->packet_type_flags |= kRtcpFir; |
| 1040 } | 1037 } |
| 1041 } | 1038 } |
| 1042 } else { | 1039 } else { |
| 1043 // received signal that we need to send a new key frame | 1040 // received signal that we need to send a new key frame |
| 1044 rtcpPacketInformation.rtcpPacketTypeFlags |= kRtcpFir; | 1041 packet_information->packet_type_flags |= kRtcpFir; |
| 1045 } | 1042 } |
| 1046 } | 1043 } |
| 1047 } | 1044 } |
| 1048 | 1045 |
| 1049 void RTCPReceiver::HandleTransportFeedback( | 1046 void RTCPReceiver::HandleTransportFeedback( |
| 1050 const CommonHeader& rtcp_block, | 1047 const CommonHeader& rtcp_block, |
| 1051 RTCPHelp::RTCPPacketInformation* rtcp_packet_information) { | 1048 PacketInformation* packet_information) { |
| 1052 std::unique_ptr<rtcp::TransportFeedback> transport_feedback( | 1049 std::unique_ptr<rtcp::TransportFeedback> transport_feedback( |
| 1053 new rtcp::TransportFeedback()); | 1050 new rtcp::TransportFeedback()); |
| 1054 if (!transport_feedback->Parse(rtcp_block)) { | 1051 if (!transport_feedback->Parse(rtcp_block)) { |
| 1055 ++num_skipped_packets_; | 1052 ++num_skipped_packets_; |
| 1056 return; | 1053 return; |
| 1057 } | 1054 } |
| 1058 | 1055 |
| 1059 rtcp_packet_information->rtcpPacketTypeFlags |= kRtcpTransportFeedback; | 1056 packet_information->packet_type_flags |= kRtcpTransportFeedback; |
| 1060 rtcp_packet_information->transport_feedback_ = std::move(transport_feedback); | 1057 packet_information->transport_feedback = std::move(transport_feedback); |
| 1061 } | 1058 } |
| 1062 | 1059 |
| 1063 void RTCPReceiver::UpdateTmmbr() { | 1060 void RTCPReceiver::UpdateTmmbr() { |
| 1064 // Find bounding set. | 1061 // Find bounding set. |
| 1065 std::vector<rtcp::TmmbItem> bounding = | 1062 std::vector<rtcp::TmmbItem> bounding = |
| 1066 TMMBRHelp::FindBoundingSet(TmmbrReceived()); | 1063 TMMBRHelp::FindBoundingSet(TmmbrReceived()); |
| 1067 | 1064 |
| 1068 if (!bounding.empty() && _cbRtcpBandwidthObserver) { | 1065 if (!bounding.empty() && _cbRtcpBandwidthObserver) { |
| 1069 // We have a new bandwidth estimate on this channel. | 1066 // We have a new bandwidth estimate on this channel. |
| 1070 uint64_t bitrate_bps = TMMBRHelp::CalcMinBitrateBps(bounding); | 1067 uint64_t bitrate_bps = TMMBRHelp::CalcMinBitrateBps(bounding); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1082 stats_callback_ = callback; | 1079 stats_callback_ = callback; |
| 1083 } | 1080 } |
| 1084 | 1081 |
| 1085 RtcpStatisticsCallback* RTCPReceiver::GetRtcpStatisticsCallback() { | 1082 RtcpStatisticsCallback* RTCPReceiver::GetRtcpStatisticsCallback() { |
| 1086 rtc::CritScope cs(&_criticalSectionFeedbacks); | 1083 rtc::CritScope cs(&_criticalSectionFeedbacks); |
| 1087 return stats_callback_; | 1084 return stats_callback_; |
| 1088 } | 1085 } |
| 1089 | 1086 |
| 1090 // Holding no Critical section | 1087 // Holding no Critical section |
| 1091 void RTCPReceiver::TriggerCallbacksFromRTCPPacket( | 1088 void RTCPReceiver::TriggerCallbacksFromRTCPPacket( |
| 1092 RTCPPacketInformation& rtcpPacketInformation) { | 1089 const PacketInformation& packet_information) { |
| 1093 // Process TMMBR and REMB first to avoid multiple callbacks | 1090 // Process TMMBR and REMB first to avoid multiple callbacks |
| 1094 // to OnNetworkChanged. | 1091 // to OnNetworkChanged. |
| 1095 if (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpTmmbr) { | 1092 if (packet_information.packet_type_flags & kRtcpTmmbr) { |
| 1096 // Might trigger a OnReceivedBandwidthEstimateUpdate. | 1093 // Might trigger a OnReceivedBandwidthEstimateUpdate. |
| 1097 UpdateTmmbr(); | 1094 UpdateTmmbr(); |
| 1098 } | 1095 } |
| 1099 uint32_t local_ssrc; | 1096 uint32_t local_ssrc; |
| 1100 std::set<uint32_t> registered_ssrcs; | 1097 std::set<uint32_t> registered_ssrcs; |
| 1101 { | 1098 { |
| 1102 // We don't want to hold this critsect when triggering the callbacks below. | 1099 // We don't want to hold this critsect when triggering the callbacks below. |
| 1103 rtc::CritScope lock(&_criticalSectionRTCPReceiver); | 1100 rtc::CritScope lock(&_criticalSectionRTCPReceiver); |
| 1104 local_ssrc = main_ssrc_; | 1101 local_ssrc = main_ssrc_; |
| 1105 registered_ssrcs = registered_ssrcs_; | 1102 registered_ssrcs = registered_ssrcs_; |
| 1106 } | 1103 } |
| 1107 if (!receiver_only_ && | 1104 if (!receiver_only_ && (packet_information.packet_type_flags & kRtcpSrReq)) { |
| 1108 (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpSrReq)) { | |
| 1109 _rtpRtcp.OnRequestSendReport(); | 1105 _rtpRtcp.OnRequestSendReport(); |
| 1110 } | 1106 } |
| 1111 if (!receiver_only_ && | 1107 if (!receiver_only_ && (packet_information.packet_type_flags & kRtcpNack)) { |
| 1112 (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpNack)) { | 1108 if (!packet_information.nack_sequence_numbers.empty()) { |
| 1113 if (rtcpPacketInformation.nackSequenceNumbers.size() > 0) { | |
| 1114 LOG(LS_VERBOSE) << "Incoming NACK length: " | 1109 LOG(LS_VERBOSE) << "Incoming NACK length: " |
| 1115 << rtcpPacketInformation.nackSequenceNumbers.size(); | 1110 << packet_information.nack_sequence_numbers.size(); |
| 1116 _rtpRtcp.OnReceivedNack(rtcpPacketInformation.nackSequenceNumbers); | 1111 _rtpRtcp.OnReceivedNack(packet_information.nack_sequence_numbers); |
| 1117 } | 1112 } |
| 1118 } | 1113 } |
| 1119 { | 1114 { |
| 1120 // We need feedback that we have received a report block(s) so that we | 1115 // We need feedback that we have received a report block(s) so that we |
| 1121 // can generate a new packet in a conference relay scenario, one received | 1116 // can generate a new packet in a conference relay scenario, one received |
| 1122 // report can generate several RTCP packets, based on number relayed/mixed | 1117 // report can generate several RTCP packets, based on number relayed/mixed |
| 1123 // a send report block should go out to all receivers. | 1118 // a send report block should go out to all receivers. |
| 1124 if (_cbRtcpIntraFrameObserver) { | 1119 if (_cbRtcpIntraFrameObserver) { |
| 1125 RTC_DCHECK(!receiver_only_); | 1120 RTC_DCHECK(!receiver_only_); |
| 1126 if ((rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpPli) || | 1121 if ((packet_information.packet_type_flags & kRtcpPli) || |
| 1127 (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpFir)) { | 1122 (packet_information.packet_type_flags & kRtcpFir)) { |
| 1128 if (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpPli) { | 1123 if (packet_information.packet_type_flags & kRtcpPli) { |
| 1129 LOG(LS_VERBOSE) << "Incoming PLI from SSRC " | 1124 LOG(LS_VERBOSE) << "Incoming PLI from SSRC " |
| 1130 << rtcpPacketInformation.remoteSSRC; | 1125 << packet_information.remote_ssrc; |
| 1131 } else { | 1126 } else { |
| 1132 LOG(LS_VERBOSE) << "Incoming FIR from SSRC " | 1127 LOG(LS_VERBOSE) << "Incoming FIR from SSRC " |
| 1133 << rtcpPacketInformation.remoteSSRC; | 1128 << packet_information.remote_ssrc; |
| 1134 } | 1129 } |
| 1135 _cbRtcpIntraFrameObserver->OnReceivedIntraFrameRequest(local_ssrc); | 1130 _cbRtcpIntraFrameObserver->OnReceivedIntraFrameRequest(local_ssrc); |
| 1136 } | 1131 } |
| 1137 if (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpSli) { | 1132 if (packet_information.packet_type_flags & kRtcpSli) { |
| 1138 _cbRtcpIntraFrameObserver->OnReceivedSLI( | 1133 _cbRtcpIntraFrameObserver->OnReceivedSLI( |
| 1139 local_ssrc, rtcpPacketInformation.sliPictureId); | 1134 local_ssrc, packet_information.sli_picture_id); |
| 1140 } | 1135 } |
| 1141 if (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpRpsi) { | 1136 if (packet_information.packet_type_flags & kRtcpRpsi) { |
| 1142 _cbRtcpIntraFrameObserver->OnReceivedRPSI( | 1137 _cbRtcpIntraFrameObserver->OnReceivedRPSI( |
| 1143 local_ssrc, rtcpPacketInformation.rpsiPictureId); | 1138 local_ssrc, packet_information.rpsi_picture_id); |
| 1144 } | 1139 } |
| 1145 } | 1140 } |
| 1146 if (_cbRtcpBandwidthObserver) { | 1141 if (_cbRtcpBandwidthObserver) { |
| 1147 RTC_DCHECK(!receiver_only_); | 1142 RTC_DCHECK(!receiver_only_); |
| 1148 if (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpRemb) { | 1143 if (packet_information.packet_type_flags & kRtcpRemb) { |
| 1149 LOG(LS_VERBOSE) << "Incoming REMB: " | 1144 LOG(LS_VERBOSE) |
| 1150 << rtcpPacketInformation.receiverEstimatedMaxBitrate; | 1145 << "Incoming REMB: " |
| 1146 << packet_information.receiver_estimated_max_bitrate_bps; | |
| 1151 _cbRtcpBandwidthObserver->OnReceivedEstimatedBitrate( | 1147 _cbRtcpBandwidthObserver->OnReceivedEstimatedBitrate( |
| 1152 rtcpPacketInformation.receiverEstimatedMaxBitrate); | 1148 packet_information.receiver_estimated_max_bitrate_bps); |
| 1153 } | 1149 } |
| 1154 if ((rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpSr) || | 1150 if ((packet_information.packet_type_flags & kRtcpSr) || |
| 1155 (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpRr)) { | 1151 (packet_information.packet_type_flags & kRtcpRr)) { |
| 1156 int64_t now = _clock->TimeInMilliseconds(); | 1152 int64_t now = _clock->TimeInMilliseconds(); |
| 1157 _cbRtcpBandwidthObserver->OnReceivedRtcpReceiverReport( | 1153 _cbRtcpBandwidthObserver->OnReceivedRtcpReceiverReport( |
| 1158 rtcpPacketInformation.report_blocks, rtcpPacketInformation.rtt, | 1154 packet_information.report_blocks, packet_information.rtt_ms, now); |
| 1159 now); | |
| 1160 } | 1155 } |
| 1161 } | 1156 } |
| 1162 if ((rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpSr) || | 1157 if ((packet_information.packet_type_flags & kRtcpSr) || |
| 1163 (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpRr)) { | 1158 (packet_information.packet_type_flags & kRtcpRr)) { |
| 1164 _rtpRtcp.OnReceivedRtcpReportBlocks(rtcpPacketInformation.report_blocks); | 1159 _rtpRtcp.OnReceivedRtcpReportBlocks(packet_information.report_blocks); |
| 1165 } | 1160 } |
| 1166 | 1161 |
| 1167 if (_cbTransportFeedbackObserver && | 1162 if (_cbTransportFeedbackObserver && |
| 1168 (rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpTransportFeedback)) { | 1163 (packet_information.packet_type_flags & kRtcpTransportFeedback)) { |
| 1169 uint32_t media_source_ssrc = | 1164 uint32_t media_source_ssrc = |
| 1170 rtcpPacketInformation.transport_feedback_->GetMediaSourceSsrc(); | 1165 packet_information.transport_feedback->media_ssrc(); |
| 1171 if (media_source_ssrc == local_ssrc || | 1166 if (media_source_ssrc == local_ssrc || |
| 1172 registered_ssrcs.find(media_source_ssrc) != registered_ssrcs.end()) { | 1167 registered_ssrcs.find(media_source_ssrc) != registered_ssrcs.end()) { |
| 1173 _cbTransportFeedbackObserver->OnTransportFeedback( | 1168 _cbTransportFeedbackObserver->OnTransportFeedback( |
| 1174 *rtcpPacketInformation.transport_feedback_.get()); | 1169 *packet_information.transport_feedback); |
| 1175 } | 1170 } |
| 1176 } | 1171 } |
| 1177 } | 1172 } |
| 1178 | 1173 |
| 1179 if (!receiver_only_) { | 1174 if (!receiver_only_) { |
| 1180 rtc::CritScope cs(&_criticalSectionFeedbacks); | 1175 rtc::CritScope cs(&_criticalSectionFeedbacks); |
| 1181 if (stats_callback_) { | 1176 if (stats_callback_) { |
| 1182 for (ReportBlockList::const_iterator it = | 1177 for (const auto& report_block : packet_information.report_blocks) { |
| 1183 rtcpPacketInformation.report_blocks.begin(); | |
| 1184 it != rtcpPacketInformation.report_blocks.end(); ++it) { | |
| 1185 RtcpStatistics stats; | 1178 RtcpStatistics stats; |
| 1186 stats.cumulative_lost = it->cumulativeLost; | 1179 stats.cumulative_lost = report_block.cumulativeLost; |
| 1187 stats.extended_max_sequence_number = it->extendedHighSeqNum; | 1180 stats.extended_max_sequence_number = report_block.extendedHighSeqNum; |
| 1188 stats.fraction_lost = it->fractionLost; | 1181 stats.fraction_lost = report_block.fractionLost; |
| 1189 stats.jitter = it->jitter; | 1182 stats.jitter = report_block.jitter; |
| 1190 | 1183 |
| 1191 stats_callback_->StatisticsUpdated(stats, it->sourceSSRC); | 1184 stats_callback_->StatisticsUpdated(stats, report_block.sourceSSRC); |
| 1192 } | 1185 } |
| 1193 } | 1186 } |
| 1194 } | 1187 } |
| 1195 } | 1188 } |
| 1196 | 1189 |
| 1197 int32_t RTCPReceiver::CNAME(uint32_t remoteSSRC, | 1190 int32_t RTCPReceiver::CNAME(uint32_t remoteSSRC, |
| 1198 char cName[RTCP_CNAME_SIZE]) const { | 1191 char cName[RTCP_CNAME_SIZE]) const { |
| 1199 assert(cName); | 1192 assert(cName); |
| 1200 | 1193 |
| 1201 rtc::CritScope lock(&_criticalSectionRTCPReceiver); | 1194 rtc::CritScope lock(&_criticalSectionRTCPReceiver); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1216 | 1209 |
| 1217 for (const auto& kv : _receivedInfoMap) { | 1210 for (const auto& kv : _receivedInfoMap) { |
| 1218 RTCPReceiveInformation* receive_info = kv.second; | 1211 RTCPReceiveInformation* receive_info = kv.second; |
| 1219 RTC_DCHECK(receive_info); | 1212 RTC_DCHECK(receive_info); |
| 1220 receive_info->GetTmmbrSet(now_ms, &candidates); | 1213 receive_info->GetTmmbrSet(now_ms, &candidates); |
| 1221 } | 1214 } |
| 1222 return candidates; | 1215 return candidates; |
| 1223 } | 1216 } |
| 1224 | 1217 |
| 1225 } // namespace webrtc | 1218 } // namespace webrtc |
| OLD | NEW |