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 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 rtcp::Bye* bye = new rtcp::Bye(); | 702 rtcp::Bye* bye = new rtcp::Bye(); |
744 bye->From(ssrc_); | 703 bye->From(ssrc_); |
745 for (uint32_t csrc : csrcs_) | 704 for (uint32_t csrc : csrcs_) |
746 bye->WithCsrc(csrc); | 705 bye->WithCsrc(csrc); |
747 | 706 |
748 return rtc::scoped_ptr<rtcp::Bye>(bye); | 707 return rtc::scoped_ptr<rtcp::Bye>(bye); |
749 } | 708 } |
750 | 709 |
751 rtc::scoped_ptr<rtcp::RtcpPacket> RTCPSender::BuildReceiverReferenceTime( | 710 rtc::scoped_ptr<rtcp::RtcpPacket> RTCPSender::BuildReceiverReferenceTime( |
752 const RtcpContext& ctx) { | 711 const RtcpContext& ctx) { |
753 if (last_xr_rr_.size() >= RTCP_NUMBER_OF_SR) | |
754 last_xr_rr_.erase(last_xr_rr_.begin()); | |
755 last_xr_rr_.insert(std::pair<uint32_t, int64_t>( | |
756 RTCPUtility::MidNtp(ctx.ntp_sec_, ctx.ntp_frac_), | |
757 Clock::NtpToMs(ctx.ntp_sec_, ctx.ntp_frac_))); | |
758 | 712 |
759 rtcp::ExtendedReports* xr = new rtcp::ExtendedReports(); | 713 rtcp::ExtendedReports* xr = new rtcp::ExtendedReports(); |
760 xr->From(ssrc_); | 714 xr->From(ssrc_); |
761 | 715 |
762 rtcp::Rrtr rrtr; | 716 rtcp::Rrtr rrtr; |
763 rrtr.WithNtp(NtpTime(ctx.ntp_sec_, ctx.ntp_frac_)); | 717 rrtr.WithNtp(NtpTime(ctx.ntp_sec_, ctx.ntp_frac_)); |
764 | 718 |
765 xr->WithRrtr(rrtr); | 719 xr->WithRrtr(rrtr); |
766 | 720 |
767 // TODO(sprang): Merge XR report sending to contain all of RRTR, DLRR, VOIP? | 721 // TODO(sprang): Merge XR report sending to contain all of RRTR, DLRR, VOIP? |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1079 // RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(Sender); | 1033 // RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(Sender); |
1080 // but we can't because of an incorrect warning (C4822) in MVS 2013. | 1034 // but we can't because of an incorrect warning (C4822) in MVS 2013. |
1081 } sender(transport_, event_log_); | 1035 } sender(transport_, event_log_); |
1082 | 1036 |
1083 uint8_t buffer[IP_PACKET_SIZE]; | 1037 uint8_t buffer[IP_PACKET_SIZE]; |
1084 return packet.BuildExternalBuffer(buffer, IP_PACKET_SIZE, &sender) && | 1038 return packet.BuildExternalBuffer(buffer, IP_PACKET_SIZE, &sender) && |
1085 !sender.send_failure_; | 1039 !sender.send_failure_; |
1086 } | 1040 } |
1087 | 1041 |
1088 } // namespace webrtc | 1042 } // namespace webrtc |
OLD | NEW |