rtp_rtcp_impl.cc revision 4ef438e2defd6c46404f6b367287364cde66b7fb
1/* 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 3 * 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 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11#include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h" 12 13#include <assert.h> 14#include <string.h> 15 16#include "webrtc/common_types.h" 17#include "webrtc/system_wrappers/interface/logging.h" 18#include "webrtc/system_wrappers/interface/trace.h" 19 20#ifdef _WIN32 21// Disable warning C4355: 'this' : used in base member initializer list. 22#pragma warning(disable : 4355) 23#endif 24 25namespace webrtc { 26 27RtpRtcp::Configuration::Configuration() 28 : id(-1), 29 audio(false), 30 clock(NULL), 31 default_module(NULL), 32 receive_statistics(NullObjectReceiveStatistics()), 33 outgoing_transport(NULL), 34 rtcp_feedback(NULL), 35 intra_frame_callback(NULL), 36 bandwidth_callback(NULL), 37 rtt_stats(NULL), 38 audio_messages(NullObjectRtpAudioFeedback()), 39 remote_bitrate_estimator(NULL), 40 paced_sender(NULL), 41 send_bitrate_observer(NULL), 42 send_frame_count_observer(NULL) { 43} 44 45RtpRtcp* RtpRtcp::CreateRtpRtcp(const RtpRtcp::Configuration& configuration) { 46 if (configuration.clock) { 47 return new ModuleRtpRtcpImpl(configuration); 48 } else { 49 RtpRtcp::Configuration configuration_copy; 50 memcpy(&configuration_copy, &configuration, 51 sizeof(RtpRtcp::Configuration)); 52 configuration_copy.clock = Clock::GetRealTimeClock(); 53 ModuleRtpRtcpImpl* rtp_rtcp_instance = 54 new ModuleRtpRtcpImpl(configuration_copy); 55 return rtp_rtcp_instance; 56 } 57} 58 59ModuleRtpRtcpImpl::ModuleRtpRtcpImpl(const Configuration& configuration) 60 : rtp_sender_(configuration.id, 61 configuration.audio, 62 configuration.clock, 63 configuration.outgoing_transport, 64 configuration.audio_messages, 65 configuration.paced_sender, 66 configuration.send_bitrate_observer, 67 configuration.send_frame_count_observer), 68 rtcp_sender_(configuration.id, 69 configuration.audio, 70 configuration.clock, 71 configuration.receive_statistics), 72 rtcp_receiver_(configuration.id, configuration.clock, this), 73 clock_(configuration.clock), 74 id_(configuration.id), 75 audio_(configuration.audio), 76 collision_detected_(false), 77 last_process_time_(configuration.clock->TimeInMilliseconds()), 78 last_bitrate_process_time_(configuration.clock->TimeInMilliseconds()), 79 last_rtt_process_time_(configuration.clock->TimeInMilliseconds()), 80 packet_overhead_(28), // IPV4 UDP. 81 critical_section_module_ptrs_( 82 CriticalSectionWrapper::CreateCriticalSection()), 83 critical_section_module_ptrs_feedback_( 84 CriticalSectionWrapper::CreateCriticalSection()), 85 default_module_( 86 static_cast<ModuleRtpRtcpImpl*>(configuration.default_module)), 87 padding_index_(-1), // Start padding at the first child module. 88 nack_method_(kNackOff), 89 nack_last_time_sent_full_(0), 90 nack_last_seq_number_sent_(0), 91 simulcast_(false), 92 key_frame_req_method_(kKeyFrameReqFirRtp), 93 remote_bitrate_(configuration.remote_bitrate_estimator), 94 rtt_stats_(configuration.rtt_stats), 95 critical_section_rtt_(CriticalSectionWrapper::CreateCriticalSection()), 96 rtt_ms_(0) { 97 send_video_codec_.codecType = kVideoCodecUnknown; 98 99 if (default_module_) { 100 default_module_->RegisterChildModule(this); 101 } 102 // TODO(pwestin) move to constructors of each rtp/rtcp sender/receiver object. 103 rtcp_receiver_.RegisterRtcpObservers(configuration.intra_frame_callback, 104 configuration.bandwidth_callback, 105 configuration.rtcp_feedback); 106 rtcp_sender_.RegisterSendTransport(configuration.outgoing_transport); 107 108 // Make sure that RTCP objects are aware of our SSRC. 109 uint32_t SSRC = rtp_sender_.SSRC(); 110 rtcp_sender_.SetSSRC(SSRC); 111 SetRtcpReceiverSsrcs(SSRC); 112} 113 114ModuleRtpRtcpImpl::~ModuleRtpRtcpImpl() { 115 // All child modules MUST be deleted before deleting the default. 116 assert(child_modules_.empty()); 117 118 // Deregister for the child modules. 119 // Will go in to the default and remove it self. 120 if (default_module_) { 121 default_module_->DeRegisterChildModule(this); 122 } 123} 124 125void ModuleRtpRtcpImpl::RegisterChildModule(RtpRtcp* module) { 126 CriticalSectionScoped lock( 127 critical_section_module_ptrs_.get()); 128 CriticalSectionScoped double_lock( 129 critical_section_module_ptrs_feedback_.get()); 130 131 // We use two locks for protecting child_modules_, one 132 // (critical_section_module_ptrs_feedback_) for incoming 133 // messages (BitrateSent) and critical_section_module_ptrs_ 134 // for all outgoing messages sending packets etc. 135 child_modules_.push_back(static_cast<ModuleRtpRtcpImpl*>(module)); 136} 137 138void ModuleRtpRtcpImpl::DeRegisterChildModule(RtpRtcp* remove_module) { 139 CriticalSectionScoped lock( 140 critical_section_module_ptrs_.get()); 141 CriticalSectionScoped double_lock( 142 critical_section_module_ptrs_feedback_.get()); 143 144 std::vector<ModuleRtpRtcpImpl*>::iterator it = child_modules_.begin(); 145 while (it != child_modules_.end()) { 146 RtpRtcp* module = *it; 147 if (module == remove_module) { 148 child_modules_.erase(it); 149 return; 150 } 151 it++; 152 } 153} 154 155// Returns the number of milliseconds until the module want a worker thread 156// to call Process. 157int32_t ModuleRtpRtcpImpl::TimeUntilNextProcess() { 158 const int64_t now = clock_->TimeInMilliseconds(); 159 return kRtpRtcpMaxIdleTimeProcess - (now - last_process_time_); 160} 161 162// Process any pending tasks such as timeouts (non time critical events). 163int32_t ModuleRtpRtcpImpl::Process() { 164 const int64_t now = clock_->TimeInMilliseconds(); 165 last_process_time_ = now; 166 167 if (now >= last_bitrate_process_time_ + kRtpRtcpBitrateProcessTimeMs) { 168 rtp_sender_.ProcessBitrate(); 169 last_bitrate_process_time_ = now; 170 } 171 172 if (!IsDefaultModule()) { 173 bool process_rtt = now >= last_rtt_process_time_ + kRtpRtcpRttProcessTimeMs; 174 if (rtcp_sender_.Sending()) { 175 // Process RTT if we have received a receiver report and we haven't 176 // processed RTT for at least |kRtpRtcpRttProcessTimeMs| milliseconds. 177 if (rtcp_receiver_.LastReceivedReceiverReport() > 178 last_rtt_process_time_ && process_rtt) { 179 std::vector<RTCPReportBlock> receive_blocks; 180 rtcp_receiver_.StatisticsReceived(&receive_blocks); 181 uint16_t max_rtt = 0; 182 for (std::vector<RTCPReportBlock>::iterator it = receive_blocks.begin(); 183 it != receive_blocks.end(); ++it) { 184 uint16_t rtt = 0; 185 rtcp_receiver_.RTT(it->remoteSSRC, &rtt, NULL, NULL, NULL); 186 max_rtt = (rtt > max_rtt) ? rtt : max_rtt; 187 } 188 // Report the rtt. 189 if (rtt_stats_ && max_rtt != 0) 190 rtt_stats_->OnRttUpdate(max_rtt); 191 } 192 193 // Verify receiver reports are delivered and the reported sequence number 194 // is increasing. 195 int64_t rtcp_interval = RtcpReportInterval(); 196 if (rtcp_receiver_.RtcpRrTimeout(rtcp_interval)) { 197 LOG_F(LS_WARNING) << "Timeout: No RTCP RR received."; 198 } else if (rtcp_receiver_.RtcpRrSequenceNumberTimeout(rtcp_interval)) { 199 LOG_F(LS_WARNING) << 200 "Timeout: No increase in RTCP RR extended highest sequence number."; 201 } 202 203 if (remote_bitrate_ && rtcp_sender_.TMMBR()) { 204 unsigned int target_bitrate = 0; 205 std::vector<unsigned int> ssrcs; 206 if (remote_bitrate_->LatestEstimate(&ssrcs, &target_bitrate)) { 207 if (!ssrcs.empty()) { 208 target_bitrate = target_bitrate / ssrcs.size(); 209 } 210 rtcp_sender_.SetTargetBitrate(target_bitrate); 211 } 212 } 213 } else { 214 // Report rtt from receiver. 215 if (process_rtt) { 216 uint16_t rtt_ms; 217 if (rtt_stats_ && rtcp_receiver_.GetAndResetXrRrRtt(&rtt_ms)) { 218 rtt_stats_->OnRttUpdate(rtt_ms); 219 } 220 } 221 } 222 223 // Get processed rtt. 224 if (process_rtt) { 225 last_rtt_process_time_ = now; 226 if (rtt_stats_) { 227 set_rtt_ms(rtt_stats_->LastProcessedRtt()); 228 } 229 } 230 231 if (rtcp_sender_.TimeToSendRTCPReport()) { 232 RTCPSender::FeedbackState feedback_state(this); 233 rtcp_sender_.SendRTCP(feedback_state, kRtcpReport); 234 } 235 } 236 237 if (UpdateRTCPReceiveInformationTimers()) { 238 // A receiver has timed out 239 rtcp_receiver_.UpdateTMMBR(); 240 } 241 return 0; 242} 243 244void ModuleRtpRtcpImpl::SetRTXSendStatus(int mode) { 245 rtp_sender_.SetRTXStatus(mode); 246} 247 248void ModuleRtpRtcpImpl::RTXSendStatus(int* mode, 249 uint32_t* ssrc, 250 int* payload_type) const { 251 rtp_sender_.RTXStatus(mode, ssrc, payload_type); 252} 253 254void ModuleRtpRtcpImpl::SetRtxSsrc(uint32_t ssrc) { 255 rtp_sender_.SetRtxSsrc(ssrc); 256} 257 258void ModuleRtpRtcpImpl::SetRtxSendPayloadType(int payload_type) { 259 rtp_sender_.SetRtxPayloadType(payload_type); 260} 261 262int32_t ModuleRtpRtcpImpl::IncomingRtcpPacket( 263 const uint8_t* rtcp_packet, 264 const uint16_t length) { 265 // Allow receive of non-compound RTCP packets. 266 RTCPUtility::RTCPParserV2 rtcp_parser(rtcp_packet, length, true); 267 268 const bool valid_rtcpheader = rtcp_parser.IsValid(); 269 if (!valid_rtcpheader) { 270 LOG(LS_WARNING) << "Incoming invalid RTCP packet"; 271 return -1; 272 } 273 RTCPHelp::RTCPPacketInformation rtcp_packet_information; 274 int32_t ret_val = rtcp_receiver_.IncomingRTCPPacket( 275 rtcp_packet_information, &rtcp_parser); 276 if (ret_val == 0) { 277 rtcp_receiver_.TriggerCallbacksFromRTCPPacket(rtcp_packet_information); 278 } 279 return ret_val; 280} 281 282int32_t ModuleRtpRtcpImpl::RegisterSendPayload( 283 const CodecInst& voice_codec) { 284 return rtp_sender_.RegisterPayload( 285 voice_codec.plname, 286 voice_codec.pltype, 287 voice_codec.plfreq, 288 voice_codec.channels, 289 (voice_codec.rate < 0) ? 0 : voice_codec.rate); 290} 291 292int32_t ModuleRtpRtcpImpl::RegisterSendPayload( 293 const VideoCodec& video_codec) { 294 send_video_codec_ = video_codec; 295 { 296 // simulcast_ is accessed when accessing child_modules_, so this write needs 297 // to be protected by the same lock. 298 CriticalSectionScoped lock(critical_section_module_ptrs_.get()); 299 simulcast_ = video_codec.numberOfSimulcastStreams > 1; 300 } 301 return rtp_sender_.RegisterPayload(video_codec.plName, 302 video_codec.plType, 303 90000, 304 0, 305 video_codec.maxBitrate); 306} 307 308int32_t ModuleRtpRtcpImpl::DeRegisterSendPayload( 309 const int8_t payload_type) { 310 return rtp_sender_.DeRegisterSendPayload(payload_type); 311} 312 313int8_t ModuleRtpRtcpImpl::SendPayloadType() const { 314 return rtp_sender_.SendPayloadType(); 315} 316 317uint32_t ModuleRtpRtcpImpl::StartTimestamp() const { 318 return rtp_sender_.StartTimestamp(); 319} 320 321// Configure start timestamp, default is a random number. 322int32_t ModuleRtpRtcpImpl::SetStartTimestamp( 323 const uint32_t timestamp) { 324 rtcp_sender_.SetStartTimestamp(timestamp); 325 rtp_sender_.SetStartTimestamp(timestamp, true); 326 return 0; // TODO(pwestin): change to void. 327} 328 329uint16_t ModuleRtpRtcpImpl::SequenceNumber() const { 330 return rtp_sender_.SequenceNumber(); 331} 332 333// Set SequenceNumber, default is a random number. 334int32_t ModuleRtpRtcpImpl::SetSequenceNumber( 335 const uint16_t seq_num) { 336 rtp_sender_.SetSequenceNumber(seq_num); 337 return 0; // TODO(pwestin): change to void. 338} 339 340void ModuleRtpRtcpImpl::SetRtpStateForSsrc(uint32_t ssrc, 341 const RtpState& rtp_state) { 342 if (rtp_sender_.SSRC() == ssrc) { 343 rtp_sender_.SetRtpState(rtp_state); 344 return; 345 } 346 if (rtp_sender_.RtxSsrc() == ssrc) { 347 rtp_sender_.SetRtxRtpState(rtp_state); 348 return; 349 } 350 351 CriticalSectionScoped lock(critical_section_module_ptrs_.get()); 352 for (size_t i = 0; i < child_modules_.size(); ++i) { 353 child_modules_[i]->SetRtpStateForSsrc(ssrc, rtp_state); 354 } 355} 356 357bool ModuleRtpRtcpImpl::GetRtpStateForSsrc(uint32_t ssrc, RtpState* rtp_state) { 358 if (rtp_sender_.SSRC() == ssrc) { 359 *rtp_state = rtp_sender_.GetRtpState(); 360 return true; 361 } 362 363 if (rtp_sender_.RtxSsrc() == ssrc) { 364 *rtp_state = rtp_sender_.GetRtxRtpState(); 365 return true; 366 } 367 368 CriticalSectionScoped lock(critical_section_module_ptrs_.get()); 369 for (size_t i = 0; i < child_modules_.size(); ++i) { 370 if (child_modules_[i]->GetRtpStateForSsrc(ssrc, rtp_state)) 371 return true; 372 } 373 return false; 374} 375 376uint32_t ModuleRtpRtcpImpl::SSRC() const { 377 return rtp_sender_.SSRC(); 378} 379 380// Configure SSRC, default is a random number. 381void ModuleRtpRtcpImpl::SetSSRC(const uint32_t ssrc) { 382 rtp_sender_.SetSSRC(ssrc); 383 rtcp_sender_.SetSSRC(ssrc); 384 SetRtcpReceiverSsrcs(ssrc); 385} 386 387int32_t ModuleRtpRtcpImpl::SetCSRCStatus(const bool include) { 388 rtcp_sender_.SetCSRCStatus(include); 389 rtp_sender_.SetCSRCStatus(include); 390 return 0; // TODO(pwestin): change to void. 391} 392 393int32_t ModuleRtpRtcpImpl::CSRCs( 394 uint32_t arr_of_csrc[kRtpCsrcSize]) const { 395 return rtp_sender_.CSRCs(arr_of_csrc); 396} 397 398int32_t ModuleRtpRtcpImpl::SetCSRCs( 399 const uint32_t arr_of_csrc[kRtpCsrcSize], 400 const uint8_t arr_length) { 401 if (IsDefaultModule()) { 402 // For default we need to update all child modules too. 403 CriticalSectionScoped lock(critical_section_module_ptrs_.get()); 404 405 std::vector<ModuleRtpRtcpImpl*>::iterator it = child_modules_.begin(); 406 while (it != child_modules_.end()) { 407 RtpRtcp* module = *it; 408 if (module) { 409 module->SetCSRCs(arr_of_csrc, arr_length); 410 } 411 it++; 412 } 413 } else { 414 rtcp_sender_.SetCSRCs(arr_of_csrc, arr_length); 415 rtp_sender_.SetCSRCs(arr_of_csrc, arr_length); 416 } 417 return 0; // TODO(pwestin): change to void. 418} 419 420uint32_t ModuleRtpRtcpImpl::PacketCountSent() const { 421 return rtp_sender_.Packets(); 422} 423 424uint32_t ModuleRtpRtcpImpl::ByteCountSent() const { 425 return rtp_sender_.Bytes(); 426} 427 428int ModuleRtpRtcpImpl::CurrentSendFrequencyHz() const { 429 return rtp_sender_.SendPayloadFrequency(); 430} 431 432int32_t ModuleRtpRtcpImpl::SetSendingStatus(const bool sending) { 433 if (rtcp_sender_.Sending() != sending) { 434 // Sends RTCP BYE when going from true to false 435 RTCPSender::FeedbackState feedback_state(this); 436 if (rtcp_sender_.SetSendingStatus(feedback_state, sending) != 0) { 437 LOG(LS_WARNING) << "Failed to send RTCP BYE"; 438 } 439 440 collision_detected_ = false; 441 442 // Generate a new time_stamp if true and not configured via API 443 // Generate a new SSRC for the next "call" if false 444 rtp_sender_.SetSendingStatus(sending); 445 if (sending) { 446 // Make sure the RTCP sender has the same timestamp offset. 447 rtcp_sender_.SetStartTimestamp(rtp_sender_.StartTimestamp()); 448 } 449 450 // Make sure that RTCP objects are aware of our SSRC (it could have changed 451 // Due to collision) 452 uint32_t SSRC = rtp_sender_.SSRC(); 453 rtcp_sender_.SetSSRC(SSRC); 454 SetRtcpReceiverSsrcs(SSRC); 455 456 return 0; 457 } 458 return 0; 459} 460 461bool ModuleRtpRtcpImpl::Sending() const { 462 return rtcp_sender_.Sending(); 463} 464 465int32_t ModuleRtpRtcpImpl::SetSendingMediaStatus(const bool sending) { 466 rtp_sender_.SetSendingMediaStatus(sending); 467 return 0; 468} 469 470bool ModuleRtpRtcpImpl::SendingMedia() const { 471 if (!IsDefaultModule()) { 472 return rtp_sender_.SendingMedia(); 473 } 474 475 CriticalSectionScoped lock(critical_section_module_ptrs_.get()); 476 std::vector<ModuleRtpRtcpImpl*>::const_iterator it = child_modules_.begin(); 477 while (it != child_modules_.end()) { 478 RTPSender& rtp_sender = (*it)->rtp_sender_; 479 if (rtp_sender.SendingMedia()) { 480 return true; 481 } 482 it++; 483 } 484 return false; 485} 486 487int32_t ModuleRtpRtcpImpl::SendOutgoingData( 488 FrameType frame_type, 489 int8_t payload_type, 490 uint32_t time_stamp, 491 int64_t capture_time_ms, 492 const uint8_t* payload_data, 493 uint32_t payload_size, 494 const RTPFragmentationHeader* fragmentation, 495 const RTPVideoHeader* rtp_video_hdr) { 496 rtcp_sender_.SetLastRtpTime(time_stamp, capture_time_ms); 497 498 if (!IsDefaultModule()) { 499 // Don't send RTCP from default module. 500 if (rtcp_sender_.TimeToSendRTCPReport(kVideoFrameKey == frame_type)) { 501 RTCPSender::FeedbackState feedback_state(this); 502 rtcp_sender_.SendRTCP(feedback_state, kRtcpReport); 503 } 504 return rtp_sender_.SendOutgoingData(frame_type, 505 payload_type, 506 time_stamp, 507 capture_time_ms, 508 payload_data, 509 payload_size, 510 fragmentation, 511 NULL, 512 &(rtp_video_hdr->codecHeader)); 513 } 514 int32_t ret_val = -1; 515 CriticalSectionScoped lock(critical_section_module_ptrs_.get()); 516 if (simulcast_) { 517 if (rtp_video_hdr == NULL) { 518 return -1; 519 } 520 int idx = 0; 521 std::vector<ModuleRtpRtcpImpl*>::iterator it = child_modules_.begin(); 522 for (; idx < rtp_video_hdr->simulcastIdx; ++it) { 523 if (it == child_modules_.end()) { 524 return -1; 525 } 526 if ((*it)->SendingMedia()) { 527 ++idx; 528 } 529 } 530 for (; it != child_modules_.end(); ++it) { 531 if ((*it)->SendingMedia()) { 532 break; 533 } 534 ++idx; 535 } 536 if (it == child_modules_.end()) { 537 return -1; 538 } 539 return (*it)->SendOutgoingData(frame_type, 540 payload_type, 541 time_stamp, 542 capture_time_ms, 543 payload_data, 544 payload_size, 545 fragmentation, 546 rtp_video_hdr); 547 } else { 548 std::vector<ModuleRtpRtcpImpl*>::iterator it = child_modules_.begin(); 549 // Send to all "child" modules 550 while (it != child_modules_.end()) { 551 if ((*it)->SendingMedia()) { 552 ret_val = (*it)->SendOutgoingData(frame_type, 553 payload_type, 554 time_stamp, 555 capture_time_ms, 556 payload_data, 557 payload_size, 558 fragmentation, 559 rtp_video_hdr); 560 } 561 it++; 562 } 563 } 564 return ret_val; 565} 566 567bool ModuleRtpRtcpImpl::TimeToSendPacket(uint32_t ssrc, 568 uint16_t sequence_number, 569 int64_t capture_time_ms, 570 bool retransmission) { 571 if (!IsDefaultModule()) { 572 // Don't send from default module. 573 if (SendingMedia() && ssrc == rtp_sender_.SSRC()) { 574 return rtp_sender_.TimeToSendPacket(sequence_number, capture_time_ms, 575 retransmission); 576 } 577 } else { 578 CriticalSectionScoped lock(critical_section_module_ptrs_.get()); 579 std::vector<ModuleRtpRtcpImpl*>::iterator it = child_modules_.begin(); 580 while (it != child_modules_.end()) { 581 if ((*it)->SendingMedia() && ssrc == (*it)->rtp_sender_.SSRC()) { 582 return (*it)->rtp_sender_.TimeToSendPacket(sequence_number, 583 capture_time_ms, 584 retransmission); 585 } 586 ++it; 587 } 588 } 589 // No RTP sender is interested in sending this packet. 590 return true; 591} 592 593int ModuleRtpRtcpImpl::TimeToSendPadding(int bytes) { 594 if (!IsDefaultModule()) { 595 // Don't send from default module. 596 if (SendingMedia()) { 597 return rtp_sender_.TimeToSendPadding(bytes); 598 } 599 } else { 600 CriticalSectionScoped lock(critical_section_module_ptrs_.get()); 601 // Decide what media stream to pad on based on a round-robin scheme. 602 for (size_t i = 0; i < child_modules_.size(); ++i) { 603 padding_index_ = (padding_index_ + 1) % child_modules_.size(); 604 // Send padding on one of the modules sending media. 605 if (child_modules_[padding_index_]->SendingMedia() && 606 child_modules_[padding_index_]->rtp_sender_.GetTargetBitrate() > 0) { 607 return child_modules_[padding_index_]->rtp_sender_.TimeToSendPadding( 608 bytes); 609 } 610 } 611 } 612 return 0; 613} 614 615bool ModuleRtpRtcpImpl::GetSendSideDelay(int* avg_send_delay_ms, 616 int* max_send_delay_ms) const { 617 assert(avg_send_delay_ms); 618 assert(max_send_delay_ms); 619 620 if (IsDefaultModule()) { 621 // This API is only supported for child modules. 622 return false; 623 } 624 return rtp_sender_.GetSendSideDelay(avg_send_delay_ms, max_send_delay_ms); 625} 626 627uint16_t ModuleRtpRtcpImpl::MaxPayloadLength() const { 628 return rtp_sender_.MaxPayloadLength(); 629} 630 631uint16_t ModuleRtpRtcpImpl::MaxDataPayloadLength() const { 632 // Assuming IP/UDP. 633 uint16_t min_data_payload_length = IP_PACKET_SIZE - 28; 634 635 if (IsDefaultModule()) { 636 // For default we need to update all child modules too. 637 CriticalSectionScoped lock(critical_section_module_ptrs_.get()); 638 std::vector<ModuleRtpRtcpImpl*>::const_iterator it = child_modules_.begin(); 639 while (it != child_modules_.end()) { 640 RtpRtcp* module = *it; 641 if (module) { 642 uint16_t data_payload_length = 643 module->MaxDataPayloadLength(); 644 if (data_payload_length < min_data_payload_length) { 645 min_data_payload_length = data_payload_length; 646 } 647 } 648 it++; 649 } 650 } 651 652 uint16_t data_payload_length = rtp_sender_.MaxDataPayloadLength(); 653 if (data_payload_length < min_data_payload_length) { 654 min_data_payload_length = data_payload_length; 655 } 656 return min_data_payload_length; 657} 658 659int32_t ModuleRtpRtcpImpl::SetTransportOverhead( 660 const bool tcp, 661 const bool ipv6, 662 const uint8_t authentication_overhead) { 663 uint16_t packet_overhead = 0; 664 if (ipv6) { 665 packet_overhead = 40; 666 } else { 667 packet_overhead = 20; 668 } 669 if (tcp) { 670 // TCP. 671 packet_overhead += 20; 672 } else { 673 // UDP. 674 packet_overhead += 8; 675 } 676 packet_overhead += authentication_overhead; 677 678 if (packet_overhead == packet_overhead_) { 679 // Ok same as before. 680 return 0; 681 } 682 // Calc diff. 683 int16_t packet_over_head_diff = packet_overhead - packet_overhead_; 684 685 // Store new. 686 packet_overhead_ = packet_overhead; 687 688 uint16_t length = 689 rtp_sender_.MaxPayloadLength() - packet_over_head_diff; 690 return rtp_sender_.SetMaxPayloadLength(length, packet_overhead_); 691} 692 693int32_t ModuleRtpRtcpImpl::SetMaxTransferUnit(const uint16_t mtu) { 694 if (mtu > IP_PACKET_SIZE) { 695 LOG(LS_ERROR) << "Invalid mtu: " << mtu; 696 return -1; 697 } 698 return rtp_sender_.SetMaxPayloadLength(mtu - packet_overhead_, 699 packet_overhead_); 700} 701 702RTCPMethod ModuleRtpRtcpImpl::RTCP() const { 703 if (rtcp_sender_.Status() != kRtcpOff) { 704 return rtcp_receiver_.Status(); 705 } 706 return kRtcpOff; 707} 708 709// Configure RTCP status i.e on/off. 710int32_t ModuleRtpRtcpImpl::SetRTCPStatus(const RTCPMethod method) { 711 if (rtcp_sender_.SetRTCPStatus(method) == 0) { 712 return rtcp_receiver_.SetRTCPStatus(method); 713 } 714 return -1; 715} 716 717// Only for internal test. 718uint32_t ModuleRtpRtcpImpl::LastSendReport( 719 uint32_t& last_rtcptime) { 720 return rtcp_sender_.LastSendReport(last_rtcptime); 721} 722 723int32_t ModuleRtpRtcpImpl::SetCNAME(const char c_name[RTCP_CNAME_SIZE]) { 724 return rtcp_sender_.SetCNAME(c_name); 725} 726 727int32_t ModuleRtpRtcpImpl::AddMixedCNAME( 728 const uint32_t ssrc, 729 const char c_name[RTCP_CNAME_SIZE]) { 730 return rtcp_sender_.AddMixedCNAME(ssrc, c_name); 731} 732 733int32_t ModuleRtpRtcpImpl::RemoveMixedCNAME(const uint32_t ssrc) { 734 return rtcp_sender_.RemoveMixedCNAME(ssrc); 735} 736 737int32_t ModuleRtpRtcpImpl::RemoteCNAME( 738 const uint32_t remote_ssrc, 739 char c_name[RTCP_CNAME_SIZE]) const { 740 return rtcp_receiver_.CNAME(remote_ssrc, c_name); 741} 742 743int32_t ModuleRtpRtcpImpl::RemoteNTP( 744 uint32_t* received_ntpsecs, 745 uint32_t* received_ntpfrac, 746 uint32_t* rtcp_arrival_time_secs, 747 uint32_t* rtcp_arrival_time_frac, 748 uint32_t* rtcp_timestamp) const { 749 return rtcp_receiver_.NTP(received_ntpsecs, 750 received_ntpfrac, 751 rtcp_arrival_time_secs, 752 rtcp_arrival_time_frac, 753 rtcp_timestamp); 754} 755 756// Get RoundTripTime. 757int32_t ModuleRtpRtcpImpl::RTT(const uint32_t remote_ssrc, 758 uint16_t* rtt, 759 uint16_t* avg_rtt, 760 uint16_t* min_rtt, 761 uint16_t* max_rtt) const { 762 int32_t ret = rtcp_receiver_.RTT(remote_ssrc, rtt, avg_rtt, min_rtt, max_rtt); 763 if (rtt && *rtt == 0) { 764 // Try to get RTT from RtcpRttStats class. 765 *rtt = static_cast<uint16_t>(rtt_ms()); 766 } 767 return ret; 768} 769 770// Reset RoundTripTime statistics. 771int32_t ModuleRtpRtcpImpl::ResetRTT(const uint32_t remote_ssrc) { 772 return rtcp_receiver_.ResetRTT(remote_ssrc); 773} 774 775// Reset RTP data counters for the sending side. 776int32_t ModuleRtpRtcpImpl::ResetSendDataCountersRTP() { 777 rtp_sender_.ResetDataCounters(); 778 return 0; // TODO(pwestin): change to void. 779} 780 781// Force a send of an RTCP packet. 782// Normal SR and RR are triggered via the process function. 783int32_t ModuleRtpRtcpImpl::SendRTCP(uint32_t rtcp_packet_type) { 784 RTCPSender::FeedbackState feedback_state(this); 785 return rtcp_sender_.SendRTCP(feedback_state, rtcp_packet_type); 786} 787 788int32_t ModuleRtpRtcpImpl::SetRTCPApplicationSpecificData( 789 const uint8_t sub_type, 790 const uint32_t name, 791 const uint8_t* data, 792 const uint16_t length) { 793 return rtcp_sender_.SetApplicationSpecificData(sub_type, name, data, length); 794} 795 796// (XR) VOIP metric. 797int32_t ModuleRtpRtcpImpl::SetRTCPVoIPMetrics( 798 const RTCPVoIPMetric* voip_metric) { 799 return rtcp_sender_.SetRTCPVoIPMetrics(voip_metric); 800} 801 802void ModuleRtpRtcpImpl::SetRtcpXrRrtrStatus(bool enable) { 803 return rtcp_sender_.SendRtcpXrReceiverReferenceTime(enable); 804} 805 806bool ModuleRtpRtcpImpl::RtcpXrRrtrStatus() const { 807 return rtcp_sender_.RtcpXrReceiverReferenceTime(); 808} 809 810int32_t ModuleRtpRtcpImpl::DataCountersRTP( 811 uint32_t* bytes_sent, 812 uint32_t* packets_sent) const { 813 if (bytes_sent) { 814 *bytes_sent = rtp_sender_.Bytes(); 815 } 816 if (packets_sent) { 817 *packets_sent = rtp_sender_.Packets(); 818 } 819 return 0; 820} 821 822int32_t ModuleRtpRtcpImpl::RemoteRTCPStat(RTCPSenderInfo* sender_info) { 823 return rtcp_receiver_.SenderInfoReceived(sender_info); 824} 825 826// Received RTCP report. 827int32_t ModuleRtpRtcpImpl::RemoteRTCPStat( 828 std::vector<RTCPReportBlock>* receive_blocks) const { 829 return rtcp_receiver_.StatisticsReceived(receive_blocks); 830} 831 832int32_t ModuleRtpRtcpImpl::AddRTCPReportBlock( 833 const uint32_t ssrc, 834 const RTCPReportBlock* report_block) { 835 return rtcp_sender_.AddExternalReportBlock(ssrc, report_block); 836} 837 838int32_t ModuleRtpRtcpImpl::RemoveRTCPReportBlock( 839 const uint32_t ssrc) { 840 return rtcp_sender_.RemoveExternalReportBlock(ssrc); 841} 842 843void ModuleRtpRtcpImpl::GetRtcpPacketTypeCounters( 844 RtcpPacketTypeCounter* packets_sent, 845 RtcpPacketTypeCounter* packets_received) const { 846 rtcp_sender_.GetPacketTypeCounter(packets_sent); 847 rtcp_receiver_.GetPacketTypeCounter(packets_received); 848} 849 850// (REMB) Receiver Estimated Max Bitrate. 851bool ModuleRtpRtcpImpl::REMB() const { 852 return rtcp_sender_.REMB(); 853} 854 855int32_t ModuleRtpRtcpImpl::SetREMBStatus(const bool enable) { 856 return rtcp_sender_.SetREMBStatus(enable); 857} 858 859int32_t ModuleRtpRtcpImpl::SetREMBData(const uint32_t bitrate, 860 const uint8_t number_of_ssrc, 861 const uint32_t* ssrc) { 862 return rtcp_sender_.SetREMBData(bitrate, number_of_ssrc, ssrc); 863} 864 865// (IJ) Extended jitter report. 866bool ModuleRtpRtcpImpl::IJ() const { 867 return rtcp_sender_.IJ(); 868} 869 870int32_t ModuleRtpRtcpImpl::SetIJStatus(const bool enable) { 871 return rtcp_sender_.SetIJStatus(enable); 872} 873 874int32_t ModuleRtpRtcpImpl::RegisterSendRtpHeaderExtension( 875 const RTPExtensionType type, 876 const uint8_t id) { 877 return rtp_sender_.RegisterRtpHeaderExtension(type, id); 878} 879 880int32_t ModuleRtpRtcpImpl::DeregisterSendRtpHeaderExtension( 881 const RTPExtensionType type) { 882 return rtp_sender_.DeregisterRtpHeaderExtension(type); 883} 884 885// (TMMBR) Temporary Max Media Bit Rate. 886bool ModuleRtpRtcpImpl::TMMBR() const { 887 return rtcp_sender_.TMMBR(); 888} 889 890int32_t ModuleRtpRtcpImpl::SetTMMBRStatus(const bool enable) { 891 return rtcp_sender_.SetTMMBRStatus(enable); 892} 893 894int32_t ModuleRtpRtcpImpl::SetTMMBN(const TMMBRSet* bounding_set) { 895 uint32_t max_bitrate_kbit = 896 rtp_sender_.MaxConfiguredBitrateVideo() / 1000; 897 return rtcp_sender_.SetTMMBN(bounding_set, max_bitrate_kbit); 898} 899 900// Returns the currently configured retransmission mode. 901int ModuleRtpRtcpImpl::SelectiveRetransmissions() const { 902 return rtp_sender_.SelectiveRetransmissions(); 903} 904 905// Enable or disable a retransmission mode, which decides which packets will 906// be retransmitted if NACKed. 907int ModuleRtpRtcpImpl::SetSelectiveRetransmissions(uint8_t settings) { 908 return rtp_sender_.SetSelectiveRetransmissions(settings); 909} 910 911// Send a Negative acknowledgment packet. 912int32_t ModuleRtpRtcpImpl::SendNACK(const uint16_t* nack_list, 913 const uint16_t size) { 914 // Use RTT from RtcpRttStats class if provided. 915 uint16_t rtt = rtt_ms(); 916 if (rtt == 0) { 917 rtcp_receiver_.RTT(rtcp_receiver_.RemoteSSRC(), NULL, &rtt, NULL, NULL); 918 } 919 920 int64_t wait_time = 5 + ((rtt * 3) >> 1); // 5 + RTT * 1.5. 921 if (wait_time == 5) { 922 wait_time = 100; // During startup we don't have an RTT. 923 } 924 const int64_t now = clock_->TimeInMilliseconds(); 925 const int64_t time_limit = now - wait_time; 926 uint16_t nackLength = size; 927 uint16_t start_id = 0; 928 929 if (nack_last_time_sent_full_ < time_limit) { 930 // Send list. Set the timer to make sure we only send a full NACK list once 931 // within every time_limit. 932 nack_last_time_sent_full_ = now; 933 } else { 934 // Only send if extended list. 935 if (nack_last_seq_number_sent_ == nack_list[size - 1]) { 936 // Last seq num is the same don't send list. 937 return 0; 938 } else { 939 // Send NACKs only for new sequence numbers to avoid re-sending 940 // NACKs for sequences we have already sent. 941 for (int i = 0; i < size; ++i) { 942 if (nack_last_seq_number_sent_ == nack_list[i]) { 943 start_id = i + 1; 944 break; 945 } 946 } 947 nackLength = size - start_id; 948 } 949 } 950 // Our RTCP NACK implementation is limited to kRtcpMaxNackFields sequence 951 // numbers per RTCP packet. 952 if (nackLength > kRtcpMaxNackFields) { 953 nackLength = kRtcpMaxNackFields; 954 } 955 nack_last_seq_number_sent_ = nack_list[start_id + nackLength - 1]; 956 957 RTCPSender::FeedbackState feedback_state(this); 958 return rtcp_sender_.SendRTCP( 959 feedback_state, kRtcpNack, nackLength, &nack_list[start_id]); 960} 961 962// Store the sent packets, needed to answer to a Negative acknowledgment 963// requests. 964int32_t ModuleRtpRtcpImpl::SetStorePacketsStatus( 965 const bool enable, 966 const uint16_t number_to_store) { 967 rtp_sender_.SetStorePacketsStatus(enable, number_to_store); 968 return 0; // TODO(pwestin): change to void. 969} 970 971bool ModuleRtpRtcpImpl::StorePackets() const { 972 return rtp_sender_.StorePackets(); 973} 974 975void ModuleRtpRtcpImpl::RegisterSendChannelRtcpStatisticsCallback( 976 RtcpStatisticsCallback* callback) { 977 rtcp_receiver_.RegisterRtcpStatisticsCallback(callback); 978} 979 980RtcpStatisticsCallback* ModuleRtpRtcpImpl:: 981 GetSendChannelRtcpStatisticsCallback() { 982 return rtcp_receiver_.GetRtcpStatisticsCallback(); 983} 984 985// Send a TelephoneEvent tone using RFC 2833 (4733). 986int32_t ModuleRtpRtcpImpl::SendTelephoneEventOutband( 987 const uint8_t key, 988 const uint16_t time_ms, 989 const uint8_t level) { 990 return rtp_sender_.SendTelephoneEvent(key, time_ms, level); 991} 992 993bool ModuleRtpRtcpImpl::SendTelephoneEventActive( 994 int8_t& telephone_event) const { 995 return rtp_sender_.SendTelephoneEventActive(&telephone_event); 996} 997 998// Set audio packet size, used to determine when it's time to send a DTMF 999// packet in silence (CNG). 1000int32_t ModuleRtpRtcpImpl::SetAudioPacketSize( 1001 const uint16_t packet_size_samples) { 1002 return rtp_sender_.SetAudioPacketSize(packet_size_samples); 1003} 1004 1005int32_t ModuleRtpRtcpImpl::SetAudioLevel( 1006 const uint8_t level_d_bov) { 1007 return rtp_sender_.SetAudioLevel(level_d_bov); 1008} 1009 1010// Set payload type for Redundant Audio Data RFC 2198. 1011int32_t ModuleRtpRtcpImpl::SetSendREDPayloadType( 1012 const int8_t payload_type) { 1013 return rtp_sender_.SetRED(payload_type); 1014} 1015 1016// Get payload type for Redundant Audio Data RFC 2198. 1017int32_t ModuleRtpRtcpImpl::SendREDPayloadType( 1018 int8_t& payload_type) const { 1019 return rtp_sender_.RED(&payload_type); 1020} 1021 1022RtpVideoCodecTypes ModuleRtpRtcpImpl::SendVideoCodec() const { 1023 return rtp_sender_.VideoCodecType(); 1024} 1025 1026void ModuleRtpRtcpImpl::SetTargetSendBitrate( 1027 const std::vector<uint32_t>& stream_bitrates) { 1028 if (IsDefaultModule()) { 1029 CriticalSectionScoped lock(critical_section_module_ptrs_.get()); 1030 if (simulcast_) { 1031 std::vector<ModuleRtpRtcpImpl*>::iterator it = child_modules_.begin(); 1032 for (size_t i = 0; 1033 it != child_modules_.end() && i < stream_bitrates.size(); ++it) { 1034 if ((*it)->SendingMedia()) { 1035 RTPSender& rtp_sender = (*it)->rtp_sender_; 1036 rtp_sender.SetTargetBitrate(stream_bitrates[i]); 1037 ++i; 1038 } 1039 } 1040 } else { 1041 if (stream_bitrates.size() > 1) 1042 return; 1043 std::vector<ModuleRtpRtcpImpl*>::iterator it = child_modules_.begin(); 1044 for (; it != child_modules_.end(); ++it) { 1045 RTPSender& rtp_sender = (*it)->rtp_sender_; 1046 rtp_sender.SetTargetBitrate(stream_bitrates[0]); 1047 } 1048 } 1049 } else { 1050 if (stream_bitrates.size() > 1) 1051 return; 1052 rtp_sender_.SetTargetBitrate(stream_bitrates[0]); 1053 } 1054} 1055 1056int32_t ModuleRtpRtcpImpl::SetKeyFrameRequestMethod( 1057 const KeyFrameRequestMethod method) { 1058 key_frame_req_method_ = method; 1059 return 0; 1060} 1061 1062int32_t ModuleRtpRtcpImpl::RequestKeyFrame() { 1063 switch (key_frame_req_method_) { 1064 case kKeyFrameReqFirRtp: 1065 return rtp_sender_.SendRTPIntraRequest(); 1066 case kKeyFrameReqPliRtcp: 1067 return SendRTCP(kRtcpPli); 1068 case kKeyFrameReqFirRtcp: 1069 return SendRTCP(kRtcpFir); 1070 } 1071 return -1; 1072} 1073 1074int32_t ModuleRtpRtcpImpl::SendRTCPSliceLossIndication( 1075 const uint8_t picture_id) { 1076 RTCPSender::FeedbackState feedback_state(this); 1077 return rtcp_sender_.SendRTCP( 1078 feedback_state, kRtcpSli, 0, 0, false, picture_id); 1079} 1080 1081int32_t ModuleRtpRtcpImpl::SetCameraDelay(const int32_t delay_ms) { 1082 if (IsDefaultModule()) { 1083 CriticalSectionScoped lock(critical_section_module_ptrs_.get()); 1084 std::vector<ModuleRtpRtcpImpl*>::iterator it = child_modules_.begin(); 1085 while (it != child_modules_.end()) { 1086 RtpRtcp* module = *it; 1087 if (module) { 1088 module->SetCameraDelay(delay_ms); 1089 } 1090 it++; 1091 } 1092 return 0; 1093 } 1094 return rtcp_sender_.SetCameraDelay(delay_ms); 1095} 1096 1097int32_t ModuleRtpRtcpImpl::SetGenericFECStatus( 1098 const bool enable, 1099 const uint8_t payload_type_red, 1100 const uint8_t payload_type_fec) { 1101 return rtp_sender_.SetGenericFECStatus(enable, 1102 payload_type_red, 1103 payload_type_fec); 1104} 1105 1106int32_t ModuleRtpRtcpImpl::GenericFECStatus( 1107 bool& enable, 1108 uint8_t& payload_type_red, 1109 uint8_t& payload_type_fec) { 1110 bool child_enabled = false; 1111 if (IsDefaultModule()) { 1112 // For default we need to check all child modules too. 1113 CriticalSectionScoped lock(critical_section_module_ptrs_.get()); 1114 std::vector<ModuleRtpRtcpImpl*>::iterator it = child_modules_.begin(); 1115 while (it != child_modules_.end()) { 1116 RtpRtcp* module = *it; 1117 if (module) { 1118 bool enabled = false; 1119 uint8_t dummy_ptype_red = 0; 1120 uint8_t dummy_ptype_fec = 0; 1121 if (module->GenericFECStatus(enabled, 1122 dummy_ptype_red, 1123 dummy_ptype_fec) == 0 && enabled) { 1124 child_enabled = true; 1125 break; 1126 } 1127 } 1128 it++; 1129 } 1130 } 1131 int32_t ret_val = rtp_sender_.GenericFECStatus(&enable, 1132 &payload_type_red, 1133 &payload_type_fec); 1134 if (child_enabled) { 1135 // Returns true if enabled for any child module. 1136 enable = child_enabled; 1137 } 1138 return ret_val; 1139} 1140 1141int32_t ModuleRtpRtcpImpl::SetFecParameters( 1142 const FecProtectionParams* delta_params, 1143 const FecProtectionParams* key_params) { 1144 if (IsDefaultModule()) { 1145 // For default we need to update all child modules too. 1146 CriticalSectionScoped lock(critical_section_module_ptrs_.get()); 1147 1148 std::vector<ModuleRtpRtcpImpl*>::iterator it = child_modules_.begin(); 1149 while (it != child_modules_.end()) { 1150 RtpRtcp* module = *it; 1151 if (module) { 1152 module->SetFecParameters(delta_params, key_params); 1153 } 1154 it++; 1155 } 1156 return 0; 1157 } 1158 return rtp_sender_.SetFecParameters(delta_params, key_params); 1159} 1160 1161void ModuleRtpRtcpImpl::SetRemoteSSRC(const uint32_t ssrc) { 1162 // Inform about the incoming SSRC. 1163 rtcp_sender_.SetRemoteSSRC(ssrc); 1164 rtcp_receiver_.SetRemoteSSRC(ssrc); 1165 1166 // Check for a SSRC collision. 1167 if (rtp_sender_.SSRC() == ssrc && !collision_detected_) { 1168 // If we detect a collision change the SSRC but only once. 1169 collision_detected_ = true; 1170 uint32_t new_ssrc = rtp_sender_.GenerateNewSSRC(); 1171 if (new_ssrc == 0) { 1172 // Configured via API ignore. 1173 return; 1174 } 1175 if (kRtcpOff != rtcp_sender_.Status()) { 1176 // Send RTCP bye on the current SSRC. 1177 SendRTCP(kRtcpBye); 1178 } 1179 // Change local SSRC and inform all objects about the new SSRC. 1180 rtcp_sender_.SetSSRC(new_ssrc); 1181 SetRtcpReceiverSsrcs(new_ssrc); 1182 } 1183} 1184 1185void ModuleRtpRtcpImpl::BitrateSent(uint32_t* total_rate, 1186 uint32_t* video_rate, 1187 uint32_t* fec_rate, 1188 uint32_t* nack_rate) const { 1189 if (IsDefaultModule()) { 1190 // For default we need to update the send bitrate. 1191 CriticalSectionScoped lock(critical_section_module_ptrs_feedback_.get()); 1192 1193 if (total_rate != NULL) 1194 *total_rate = 0; 1195 if (video_rate != NULL) 1196 *video_rate = 0; 1197 if (fec_rate != NULL) 1198 *fec_rate = 0; 1199 if (nack_rate != NULL) 1200 *nack_rate = 0; 1201 1202 std::vector<ModuleRtpRtcpImpl*>::const_iterator it = child_modules_.begin(); 1203 while (it != child_modules_.end()) { 1204 RtpRtcp* module = *it; 1205 if (module) { 1206 uint32_t child_total_rate = 0; 1207 uint32_t child_video_rate = 0; 1208 uint32_t child_fec_rate = 0; 1209 uint32_t child_nack_rate = 0; 1210 module->BitrateSent(&child_total_rate, 1211 &child_video_rate, 1212 &child_fec_rate, 1213 &child_nack_rate); 1214 if (total_rate != NULL && child_total_rate > *total_rate) 1215 *total_rate = child_total_rate; 1216 if (video_rate != NULL && child_video_rate > *video_rate) 1217 *video_rate = child_video_rate; 1218 if (fec_rate != NULL && child_fec_rate > *fec_rate) 1219 *fec_rate = child_fec_rate; 1220 if (nack_rate != NULL && child_nack_rate > *nack_rate) 1221 *nack_rate = child_nack_rate; 1222 } 1223 it++; 1224 } 1225 return; 1226 } 1227 if (total_rate != NULL) 1228 *total_rate = rtp_sender_.BitrateSent(); 1229 if (video_rate != NULL) 1230 *video_rate = rtp_sender_.VideoBitrateSent(); 1231 if (fec_rate != NULL) 1232 *fec_rate = rtp_sender_.FecOverheadRate(); 1233 if (nack_rate != NULL) 1234 *nack_rate = rtp_sender_.NackOverheadRate(); 1235} 1236 1237void ModuleRtpRtcpImpl::OnRequestIntraFrame() { 1238 RequestKeyFrame(); 1239} 1240 1241void ModuleRtpRtcpImpl::OnRequestSendReport() { 1242 SendRTCP(kRtcpSr); 1243} 1244 1245int32_t ModuleRtpRtcpImpl::SendRTCPReferencePictureSelection( 1246 const uint64_t picture_id) { 1247 RTCPSender::FeedbackState feedback_state(this); 1248 return rtcp_sender_.SendRTCP( 1249 feedback_state, kRtcpRpsi, 0, 0, false, picture_id); 1250} 1251 1252uint32_t ModuleRtpRtcpImpl::SendTimeOfSendReport( 1253 const uint32_t send_report) { 1254 return rtcp_sender_.SendTimeOfSendReport(send_report); 1255} 1256 1257bool ModuleRtpRtcpImpl::SendTimeOfXrRrReport( 1258 uint32_t mid_ntp, int64_t* time_ms) const { 1259 return rtcp_sender_.SendTimeOfXrRrReport(mid_ntp, time_ms); 1260} 1261 1262void ModuleRtpRtcpImpl::OnReceivedNACK( 1263 const std::list<uint16_t>& nack_sequence_numbers) { 1264 if (!rtp_sender_.StorePackets() || 1265 nack_sequence_numbers.size() == 0) { 1266 return; 1267 } 1268 // Use RTT from RtcpRttStats class if provided. 1269 uint16_t rtt = rtt_ms(); 1270 if (rtt == 0) { 1271 rtcp_receiver_.RTT(rtcp_receiver_.RemoteSSRC(), NULL, &rtt, NULL, NULL); 1272 } 1273 rtp_sender_.OnReceivedNACK(nack_sequence_numbers, rtt); 1274} 1275 1276int32_t ModuleRtpRtcpImpl::LastReceivedNTP( 1277 uint32_t& rtcp_arrival_time_secs, // When we got the last report. 1278 uint32_t& rtcp_arrival_time_frac, 1279 uint32_t& remote_sr) { 1280 // Remote SR: NTP inside the last received (mid 16 bits from sec and frac). 1281 uint32_t ntp_secs = 0; 1282 uint32_t ntp_frac = 0; 1283 1284 if (-1 == rtcp_receiver_.NTP(&ntp_secs, 1285 &ntp_frac, 1286 &rtcp_arrival_time_secs, 1287 &rtcp_arrival_time_frac, 1288 NULL)) { 1289 return -1; 1290 } 1291 remote_sr = ((ntp_secs & 0x0000ffff) << 16) + ((ntp_frac & 0xffff0000) >> 16); 1292 return 0; 1293} 1294 1295bool ModuleRtpRtcpImpl::LastReceivedXrReferenceTimeInfo( 1296 RtcpReceiveTimeInfo* info) const { 1297 return rtcp_receiver_.LastReceivedXrReferenceTimeInfo(info); 1298} 1299 1300bool ModuleRtpRtcpImpl::UpdateRTCPReceiveInformationTimers() { 1301 // If this returns true this channel has timed out. 1302 // Periodically check if this is true and if so call UpdateTMMBR. 1303 return rtcp_receiver_.UpdateRTCPReceiveInformationTimers(); 1304} 1305 1306// Called from RTCPsender. 1307int32_t ModuleRtpRtcpImpl::BoundingSet(bool& tmmbr_owner, 1308 TMMBRSet*& bounding_set) { 1309 return rtcp_receiver_.BoundingSet(tmmbr_owner, bounding_set); 1310} 1311 1312int64_t ModuleRtpRtcpImpl::RtcpReportInterval() { 1313 if (audio_) 1314 return RTCP_INTERVAL_AUDIO_MS; 1315 else 1316 return RTCP_INTERVAL_VIDEO_MS; 1317} 1318 1319void ModuleRtpRtcpImpl::SetRtcpReceiverSsrcs(uint32_t main_ssrc) { 1320 std::set<uint32_t> ssrcs; 1321 ssrcs.insert(main_ssrc); 1322 int rtx_mode = kRtxOff; 1323 uint32_t rtx_ssrc = 0; 1324 int rtx_payload_type = 0; 1325 rtp_sender_.RTXStatus(&rtx_mode, &rtx_ssrc, &rtx_payload_type); 1326 if (rtx_mode != kRtxOff) 1327 ssrcs.insert(rtx_ssrc); 1328 rtcp_receiver_.SetSsrcs(main_ssrc, ssrcs); 1329} 1330 1331void ModuleRtpRtcpImpl::set_rtt_ms(uint32_t rtt_ms) { 1332 CriticalSectionScoped cs(critical_section_rtt_.get()); 1333 rtt_ms_ = rtt_ms; 1334} 1335 1336uint32_t ModuleRtpRtcpImpl::rtt_ms() const { 1337 CriticalSectionScoped cs(critical_section_rtt_.get()); 1338 return rtt_ms_; 1339} 1340 1341void ModuleRtpRtcpImpl::RegisterSendChannelRtpStatisticsCallback( 1342 StreamDataCountersCallback* callback) { 1343 rtp_sender_.RegisterRtpStatisticsCallback(callback); 1344} 1345 1346StreamDataCountersCallback* 1347 ModuleRtpRtcpImpl::GetSendChannelRtpStatisticsCallback() const { 1348 return rtp_sender_.GetRtpStatisticsCallback(); 1349} 1350 1351bool ModuleRtpRtcpImpl::IsDefaultModule() const { 1352 CriticalSectionScoped cs(critical_section_module_ptrs_.get()); 1353 return !child_modules_.empty(); 1354} 1355 1356} // Namespace webrtc 1357