| 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(PacketContainer); | 123 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(PacketContainer); |
| 124 }; | 124 }; |
| 125 | 125 |
| 126 class RTCPSender::RtcpContext { | 126 class RTCPSender::RtcpContext { |
| 127 public: | 127 public: |
| 128 RtcpContext(const FeedbackState& feedback_state, | 128 RtcpContext(const FeedbackState& feedback_state, |
| 129 int32_t nack_size, | 129 int32_t nack_size, |
| 130 const uint16_t* nack_list, | 130 const uint16_t* nack_list, |
| 131 bool repeat, | 131 bool repeat, |
| 132 uint64_t picture_id, | 132 uint64_t picture_id, |
| 133 uint32_t ntp_sec, | 133 NtpTime now) |
| 134 uint32_t ntp_frac) | |
| 135 : feedback_state_(feedback_state), | 134 : feedback_state_(feedback_state), |
| 136 nack_size_(nack_size), | 135 nack_size_(nack_size), |
| 137 nack_list_(nack_list), | 136 nack_list_(nack_list), |
| 138 repeat_(repeat), | 137 repeat_(repeat), |
| 139 picture_id_(picture_id), | 138 picture_id_(picture_id), |
| 140 ntp_sec_(ntp_sec), | 139 now_(now) {} |
| 141 ntp_frac_(ntp_frac) {} | |
| 142 | 140 |
| 143 const FeedbackState& feedback_state_; | 141 const FeedbackState& feedback_state_; |
| 144 const int32_t nack_size_; | 142 const int32_t nack_size_; |
| 145 const uint16_t* nack_list_; | 143 const uint16_t* nack_list_; |
| 146 const bool repeat_; | 144 const bool repeat_; |
| 147 const uint64_t picture_id_; | 145 const uint64_t picture_id_; |
| 148 const uint32_t ntp_sec_; | 146 const NtpTime now_; |
| 149 const uint32_t ntp_frac_; | |
| 150 }; | 147 }; |
| 151 | 148 |
| 152 RTCPSender::RTCPSender( | 149 RTCPSender::RTCPSender( |
| 153 bool audio, | 150 bool audio, |
| 154 Clock* clock, | 151 Clock* clock, |
| 155 ReceiveStatistics* receive_statistics, | 152 ReceiveStatistics* receive_statistics, |
| 156 RtcpPacketTypeCounterObserver* packet_type_counter_observer, | 153 RtcpPacketTypeCounterObserver* packet_type_counter_observer, |
| 157 RtcEventLog* event_log, | 154 RtcEventLog* event_log, |
| 158 Transport* outgoing_transport) | 155 Transport* outgoing_transport) |
| 159 : audio_(audio), | 156 : audio_(audio), |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 // timestamp as the last frame's timestamp + the time since the last frame | 443 // timestamp as the last frame's timestamp + the time since the last frame |
| 447 // was captured. | 444 // was captured. |
| 448 uint32_t rtp_rate = | 445 uint32_t rtp_rate = |
| 449 (audio_ ? kBogusRtpRateForAudioRtcp : kVideoPayloadTypeFrequency) / 1000; | 446 (audio_ ? kBogusRtpRateForAudioRtcp : kVideoPayloadTypeFrequency) / 1000; |
| 450 uint32_t rtp_timestamp = | 447 uint32_t rtp_timestamp = |
| 451 timestamp_offset_ + last_rtp_timestamp_ + | 448 timestamp_offset_ + last_rtp_timestamp_ + |
| 452 (clock_->TimeInMilliseconds() - last_frame_capture_time_ms_) * rtp_rate; | 449 (clock_->TimeInMilliseconds() - last_frame_capture_time_ms_) * rtp_rate; |
| 453 | 450 |
| 454 rtcp::SenderReport* report = new rtcp::SenderReport(); | 451 rtcp::SenderReport* report = new rtcp::SenderReport(); |
| 455 report->SetSenderSsrc(ssrc_); | 452 report->SetSenderSsrc(ssrc_); |
| 456 report->SetNtp(NtpTime(ctx.ntp_sec_, ctx.ntp_frac_)); | 453 report->SetNtp(ctx.now_); |
| 457 report->SetRtpTimestamp(rtp_timestamp); | 454 report->SetRtpTimestamp(rtp_timestamp); |
| 458 report->SetPacketCount(ctx.feedback_state_.packets_sent); | 455 report->SetPacketCount(ctx.feedback_state_.packets_sent); |
| 459 report->SetOctetCount(ctx.feedback_state_.media_bytes_sent); | 456 report->SetOctetCount(ctx.feedback_state_.media_bytes_sent); |
| 460 | 457 |
| 461 for (auto it : report_blocks_) | 458 for (auto it : report_blocks_) |
| 462 report->AddReportBlock(it.second); | 459 report->AddReportBlock(it.second); |
| 463 | 460 |
| 464 report_blocks_.clear(); | 461 report_blocks_.clear(); |
| 465 | 462 |
| 466 return std::unique_ptr<rtcp::RtcpPacket>(report); | 463 return std::unique_ptr<rtcp::RtcpPacket>(report); |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 return std::unique_ptr<rtcp::RtcpPacket>(bye); | 692 return std::unique_ptr<rtcp::RtcpPacket>(bye); |
| 696 } | 693 } |
| 697 | 694 |
| 698 std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildExtendedReports( | 695 std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildExtendedReports( |
| 699 const RtcpContext& ctx) { | 696 const RtcpContext& ctx) { |
| 700 std::unique_ptr<rtcp::ExtendedReports> xr(new rtcp::ExtendedReports()); | 697 std::unique_ptr<rtcp::ExtendedReports> xr(new rtcp::ExtendedReports()); |
| 701 xr->SetSenderSsrc(ssrc_); | 698 xr->SetSenderSsrc(ssrc_); |
| 702 | 699 |
| 703 if (!sending_ && xr_send_receiver_reference_time_enabled_) { | 700 if (!sending_ && xr_send_receiver_reference_time_enabled_) { |
| 704 rtcp::Rrtr rrtr; | 701 rtcp::Rrtr rrtr; |
| 705 rrtr.SetNtp(NtpTime(ctx.ntp_sec_, ctx.ntp_frac_)); | 702 rrtr.SetNtp(ctx.now_); |
| 706 xr->SetRrtr(rrtr); | 703 xr->SetRrtr(rrtr); |
| 707 } | 704 } |
| 708 | 705 |
| 709 if (ctx.feedback_state_.has_last_xr_rr) { | 706 if (ctx.feedback_state_.has_last_xr_rr) { |
| 710 xr->AddDlrrItem(ctx.feedback_state_.last_xr_rr); | 707 xr->AddDlrrItem(ctx.feedback_state_.last_xr_rr); |
| 711 } | 708 } |
| 712 | 709 |
| 713 if (video_bitrate_allocation_) { | 710 if (video_bitrate_allocation_) { |
| 714 rtcp::TargetBitrate target_bitrate; | 711 rtcp::TargetBitrate target_bitrate; |
| 715 | 712 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 780 if (sending_ && method_ == RtcpMode::kCompound) { | 777 if (sending_ && method_ == RtcpMode::kCompound) { |
| 781 // Not allowed to send any RTCP packet without sender report. | 778 // Not allowed to send any RTCP packet without sender report. |
| 782 return -1; | 779 return -1; |
| 783 } | 780 } |
| 784 } | 781 } |
| 785 | 782 |
| 786 if (packet_type_counter_.first_packet_time_ms == -1) | 783 if (packet_type_counter_.first_packet_time_ms == -1) |
| 787 packet_type_counter_.first_packet_time_ms = clock_->TimeInMilliseconds(); | 784 packet_type_counter_.first_packet_time_ms = clock_->TimeInMilliseconds(); |
| 788 | 785 |
| 789 // We need to send our NTP even if we haven't received any reports. | 786 // We need to send our NTP even if we haven't received any reports. |
| 790 uint32_t ntp_sec; | |
| 791 uint32_t ntp_frac; | |
| 792 clock_->CurrentNtp(ntp_sec, ntp_frac); | |
| 793 RtcpContext context(feedback_state, nack_size, nack_list, repeat, pictureID, | 787 RtcpContext context(feedback_state, nack_size, nack_list, repeat, pictureID, |
| 794 ntp_sec, ntp_frac); | 788 NtpTime(*clock_)); |
| 795 | 789 |
| 796 PrepareReport(feedback_state); | 790 PrepareReport(feedback_state); |
| 797 | 791 |
| 798 std::unique_ptr<rtcp::RtcpPacket> packet_bye; | 792 std::unique_ptr<rtcp::RtcpPacket> packet_bye; |
| 799 | 793 |
| 800 auto it = report_flags_.begin(); | 794 auto it = report_flags_.begin(); |
| 801 while (it != report_flags_.end()) { | 795 while (it != report_flags_.end()) { |
| 802 auto builder_it = builders_.find(it->type); | 796 auto builder_it = builders_.find(it->type); |
| 803 RTC_DCHECK(builder_it != builders_.end()) | 797 RTC_DCHECK(builder_it != builders_.end()) |
| 804 << "Could not find builder for packet type " << it->type; | 798 << "Could not find builder for packet type " << it->type; |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1055 // but we can't because of an incorrect warning (C4822) in MVS 2013. | 1049 // but we can't because of an incorrect warning (C4822) in MVS 2013. |
| 1056 } sender(transport_, event_log_); | 1050 } sender(transport_, event_log_); |
| 1057 | 1051 |
| 1058 RTC_DCHECK_LE(max_payload_length_, IP_PACKET_SIZE); | 1052 RTC_DCHECK_LE(max_payload_length_, IP_PACKET_SIZE); |
| 1059 uint8_t buffer[IP_PACKET_SIZE]; | 1053 uint8_t buffer[IP_PACKET_SIZE]; |
| 1060 return packet.BuildExternalBuffer(buffer, max_payload_length_, &sender) && | 1054 return packet.BuildExternalBuffer(buffer, max_payload_length_, &sender) && |
| 1061 !sender.send_failure_; | 1055 !sender.send_failure_; |
| 1062 } | 1056 } |
| 1063 | 1057 |
| 1064 } // namespace webrtc | 1058 } // namespace webrtc |
| OLD | NEW |