| 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 |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 tmmbr_send_(0), | 188 tmmbr_send_(0), |
| 189 packet_oh_send_(0), | 189 packet_oh_send_(0), |
| 190 | 190 |
| 191 app_sub_type_(0), | 191 app_sub_type_(0), |
| 192 app_name_(0), | 192 app_name_(0), |
| 193 app_data_(nullptr), | 193 app_data_(nullptr), |
| 194 app_length_(0), | 194 app_length_(0), |
| 195 | 195 |
| 196 xr_send_receiver_reference_time_enabled_(false), | 196 xr_send_receiver_reference_time_enabled_(false), |
| 197 packet_type_counter_observer_(packet_type_counter_observer) { | 197 packet_type_counter_observer_(packet_type_counter_observer) { |
| 198 memset(last_send_report_, 0, sizeof(last_send_report_)); | |
| 199 memset(last_rtcp_time_, 0, sizeof(last_rtcp_time_)); | |
| 200 RTC_DCHECK(transport_ != nullptr); | 198 RTC_DCHECK(transport_ != nullptr); |
| 201 | 199 |
| 202 builders_[kRtcpSr] = &RTCPSender::BuildSR; | 200 builders_[kRtcpSr] = &RTCPSender::BuildSR; |
| 203 builders_[kRtcpRr] = &RTCPSender::BuildRR; | 201 builders_[kRtcpRr] = &RTCPSender::BuildRR; |
| 204 builders_[kRtcpSdes] = &RTCPSender::BuildSDES; | 202 builders_[kRtcpSdes] = &RTCPSender::BuildSDES; |
| 205 builders_[kRtcpPli] = &RTCPSender::BuildPLI; | 203 builders_[kRtcpPli] = &RTCPSender::BuildPLI; |
| 206 builders_[kRtcpFir] = &RTCPSender::BuildFIR; | 204 builders_[kRtcpFir] = &RTCPSender::BuildFIR; |
| 207 builders_[kRtcpSli] = &RTCPSender::BuildSLI; | 205 builders_[kRtcpSli] = &RTCPSender::BuildSLI; |
| 208 builders_[kRtcpRpsi] = &RTCPSender::BuildRPSI; | 206 builders_[kRtcpRpsi] = &RTCPSender::BuildRPSI; |
| 209 builders_[kRtcpRemb] = &RTCPSender::BuildREMB; | 207 builders_[kRtcpRemb] = &RTCPSender::BuildREMB; |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 if (now >= next_time_to_send_rtcp_) { | 436 if (now >= next_time_to_send_rtcp_) { |
| 439 return true; | 437 return true; |
| 440 } else if (now < 0x0000ffff && | 438 } else if (now < 0x0000ffff && |
| 441 next_time_to_send_rtcp_ > 0xffff0000) { // 65 sec margin | 439 next_time_to_send_rtcp_ > 0xffff0000) { // 65 sec margin |
| 442 // wrap | 440 // wrap |
| 443 return true; | 441 return true; |
| 444 } | 442 } |
| 445 return false; | 443 return false; |
| 446 } | 444 } |
| 447 | 445 |
| 448 int64_t RTCPSender::SendTimeOfSendReport(uint32_t sendReport) { | |
| 449 CriticalSectionScoped lock(critical_section_rtcp_sender_.get()); | |
| 450 | |
| 451 // This is only saved when we are the sender | |
| 452 if ((last_send_report_[0] == 0) || (sendReport == 0)) { | |
| 453 return 0; // will be ignored | |
| 454 } else { | |
| 455 for (int i = 0; i < RTCP_NUMBER_OF_SR; ++i) { | |
| 456 if (last_send_report_[i] == sendReport) | |
| 457 return last_rtcp_time_[i]; | |
| 458 } | |
| 459 } | |
| 460 return 0; | |
| 461 } | |
| 462 | |
| 463 bool RTCPSender::SendTimeOfXrRrReport(uint32_t mid_ntp, | |
| 464 int64_t* time_ms) const { | |
| 465 CriticalSectionScoped lock(critical_section_rtcp_sender_.get()); | |
| 466 | |
| 467 if (last_xr_rr_.empty()) { | |
| 468 return false; | |
| 469 } | |
| 470 std::map<uint32_t, int64_t>::const_iterator it = last_xr_rr_.find(mid_ntp); | |
| 471 if (it == last_xr_rr_.end()) { | |
| 472 return false; | |
| 473 } | |
| 474 *time_ms = it->second; | |
| 475 return true; | |
| 476 } | |
| 477 | |
| 478 rtc::scoped_ptr<rtcp::RtcpPacket> RTCPSender::BuildSR(const RtcpContext& ctx) { | 446 rtc::scoped_ptr<rtcp::RtcpPacket> RTCPSender::BuildSR(const RtcpContext& ctx) { |
| 479 for (int i = (RTCP_NUMBER_OF_SR - 2); i >= 0; i--) { | |
| 480 // shift old | |
| 481 last_send_report_[i + 1] = last_send_report_[i]; | |
| 482 last_rtcp_time_[i + 1] = last_rtcp_time_[i]; | |
| 483 } | |
| 484 | |
| 485 last_rtcp_time_[0] = Clock::NtpToMs(ctx.ntp_sec_, ctx.ntp_frac_); | |
| 486 last_send_report_[0] = (ctx.ntp_sec_ << 16) + (ctx.ntp_frac_ >> 16); | |
| 487 | |
| 488 // The timestamp of this RTCP packet should be estimated as the timestamp of | 447 // The timestamp of this RTCP packet should be estimated as the timestamp of |
| 489 // the frame being captured at this moment. We are calculating that | 448 // the frame being captured at this moment. We are calculating that |
| 490 // timestamp as the last frame's timestamp + the time since the last frame | 449 // timestamp as the last frame's timestamp + the time since the last frame |
| 491 // was captured. | 450 // was captured. |
| 492 uint32_t rtp_timestamp = | 451 uint32_t rtp_timestamp = |
| 493 start_timestamp_ + last_rtp_timestamp_ + | 452 start_timestamp_ + last_rtp_timestamp_ + |
| 494 (clock_->TimeInMilliseconds() - last_frame_capture_time_ms_) * | 453 (clock_->TimeInMilliseconds() - last_frame_capture_time_ms_) * |
| 495 (ctx.feedback_state_.frequency_hz / 1000); | 454 (ctx.feedback_state_.frequency_hz / 1000); |
| 496 | 455 |
| 497 rtcp::SenderReport* report = new rtcp::SenderReport(); | 456 rtcp::SenderReport* report = new rtcp::SenderReport(); |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 rtcp::Bye* bye = new rtcp::Bye(); | 704 rtcp::Bye* bye = new rtcp::Bye(); |
| 746 bye->From(ssrc_); | 705 bye->From(ssrc_); |
| 747 for (uint32_t csrc : csrcs_) | 706 for (uint32_t csrc : csrcs_) |
| 748 bye->WithCsrc(csrc); | 707 bye->WithCsrc(csrc); |
| 749 | 708 |
| 750 return rtc::scoped_ptr<rtcp::Bye>(bye); | 709 return rtc::scoped_ptr<rtcp::Bye>(bye); |
| 751 } | 710 } |
| 752 | 711 |
| 753 rtc::scoped_ptr<rtcp::RtcpPacket> RTCPSender::BuildReceiverReferenceTime( | 712 rtc::scoped_ptr<rtcp::RtcpPacket> RTCPSender::BuildReceiverReferenceTime( |
| 754 const RtcpContext& ctx) { | 713 const RtcpContext& ctx) { |
| 755 if (last_xr_rr_.size() >= RTCP_NUMBER_OF_SR) | |
| 756 last_xr_rr_.erase(last_xr_rr_.begin()); | |
| 757 last_xr_rr_.insert(std::pair<uint32_t, int64_t>( | |
| 758 RTCPUtility::MidNtp(ctx.ntp_sec_, ctx.ntp_frac_), | |
| 759 Clock::NtpToMs(ctx.ntp_sec_, ctx.ntp_frac_))); | |
| 760 | 714 |
| 761 rtcp::ExtendedReports* xr = new rtcp::ExtendedReports(); | 715 rtcp::ExtendedReports* xr = new rtcp::ExtendedReports(); |
| 762 xr->From(ssrc_); | 716 xr->From(ssrc_); |
| 763 | 717 |
| 764 rtcp::Rrtr rrtr; | 718 rtcp::Rrtr rrtr; |
| 765 rrtr.WithNtp(NtpTime(ctx.ntp_sec_, ctx.ntp_frac_)); | 719 rrtr.WithNtp(NtpTime(ctx.ntp_sec_, ctx.ntp_frac_)); |
| 766 | 720 |
| 767 xr->WithRrtr(rrtr); | 721 xr->WithRrtr(rrtr); |
| 768 | 722 |
| 769 // TODO(sprang): Merge XR report sending to contain all of RRTR, DLRR, VOIP? | 723 // TODO(sprang): Merge XR report sending to contain all of RRTR, DLRR, VOIP? |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1093 // RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(Sender); | 1047 // RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(Sender); |
| 1094 // but we can't because of an incorrect warning (C4822) in MVS 2013. | 1048 // but we can't because of an incorrect warning (C4822) in MVS 2013. |
| 1095 } sender(transport_, event_log_); | 1049 } sender(transport_, event_log_); |
| 1096 | 1050 |
| 1097 uint8_t buffer[IP_PACKET_SIZE]; | 1051 uint8_t buffer[IP_PACKET_SIZE]; |
| 1098 return packet.BuildExternalBuffer(buffer, IP_PACKET_SIZE, &sender) && | 1052 return packet.BuildExternalBuffer(buffer, IP_PACKET_SIZE, &sender) && |
| 1099 !sender.send_failure_; | 1053 !sender.send_failure_; |
| 1100 } | 1054 } |
| 1101 | 1055 |
| 1102 } // namespace webrtc | 1056 } // namespace webrtc |
| OLD | NEW |