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