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 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
428 return true; | 428 return true; |
429 } else if (now < 0x0000ffff && | 429 } else if (now < 0x0000ffff && |
430 next_time_to_send_rtcp_ > 0xffff0000) { // 65 sec margin | 430 next_time_to_send_rtcp_ > 0xffff0000) { // 65 sec margin |
431 // wrap | 431 // wrap |
432 return true; | 432 return true; |
433 } | 433 } |
434 return false; | 434 return false; |
435 } | 435 } |
436 | 436 |
437 std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildSR(const RtcpContext& ctx) { | 437 std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildSR(const RtcpContext& ctx) { |
438 // Timestamp shouldn't be esitmated before frame was received. | |
pbos-webrtc
2016/06/16 11:39:43
estimated
pbos-webrtc
2016/06/16 11:39:43
was transmitted?
danilchap
2016/06/16 12:05:02
type Done.
received by rtp_rtcp module for transmi
| |
439 RTC_DCHECK_GE(last_frame_capture_time_ms_, 0); | |
438 // The timestamp of this RTCP packet should be estimated as the timestamp of | 440 // The timestamp of this RTCP packet should be estimated as the timestamp of |
439 // the frame being captured at this moment. We are calculating that | 441 // the frame being captured at this moment. We are calculating that |
440 // timestamp as the last frame's timestamp + the time since the last frame | 442 // timestamp as the last frame's timestamp + the time since the last frame |
441 // was captured. | 443 // was captured. |
442 uint32_t rtp_timestamp = | 444 uint32_t rtp_timestamp = |
443 start_timestamp_ + last_rtp_timestamp_ + | 445 start_timestamp_ + last_rtp_timestamp_ + |
444 (clock_->TimeInMilliseconds() - last_frame_capture_time_ms_) * | 446 (clock_->TimeInMilliseconds() - last_frame_capture_time_ms_) * |
445 (ctx.feedback_state_.frequency_hz / 1000); | 447 (ctx.feedback_state_.frequency_hz / 1000); |
446 | 448 |
447 rtcp::SenderReport* report = new rtcp::SenderReport(); | 449 rtcp::SenderReport* report = new rtcp::SenderReport(); |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
763 const uint16_t* nack_list, | 765 const uint16_t* nack_list, |
764 bool repeat, | 766 bool repeat, |
765 uint64_t pictureID) { | 767 uint64_t pictureID) { |
766 PacketContainer container(transport_, event_log_); | 768 PacketContainer container(transport_, event_log_); |
767 { | 769 { |
768 rtc::CritScope lock(&critical_section_rtcp_sender_); | 770 rtc::CritScope lock(&critical_section_rtcp_sender_); |
769 if (method_ == RtcpMode::kOff) { | 771 if (method_ == RtcpMode::kOff) { |
770 LOG(LS_WARNING) << "Can't send rtcp if it is disabled."; | 772 LOG(LS_WARNING) << "Can't send rtcp if it is disabled."; |
771 return -1; | 773 return -1; |
772 } | 774 } |
775 // Add all flags as volatile. Non volatile entries will not be overwritten. | |
776 // All new volatile flags added will be consumed by the end of this call. | |
777 SetFlags(packet_types, true); | |
778 | |
779 // Prevent sending streams to send SR before any media has been sent. | |
780 const bool can_calculate_rtp_timestamp = (last_frame_capture_time_ms_ >= 0); | |
781 if (!can_calculate_rtp_timestamp) { | |
782 bool consumed_sr_flag = ConsumeFlag(kRtcpSr); | |
783 bool consumed_report_flag = sending_ && ConsumeFlag(kRtcpReport); | |
784 bool sender_report = consumed_report_flag || consumed_sr_flag; | |
785 if (sender_report && AllVolatileFlagsConsumed()) { | |
786 // This call was for Sender Report and nothing else. | |
787 return 0; | |
788 } | |
789 if (sending_ && method_ == RtcpMode::kCompound) { | |
790 // Not allowed to send any RTCP packet without sender report. | |
791 return -1; | |
792 } | |
793 } | |
794 | |
795 if (packet_type_counter_.first_packet_time_ms == -1) | |
796 packet_type_counter_.first_packet_time_ms = clock_->TimeInMilliseconds(); | |
773 | 797 |
774 // We need to send our NTP even if we haven't received any reports. | 798 // We need to send our NTP even if we haven't received any reports. |
775 uint32_t ntp_sec; | 799 uint32_t ntp_sec; |
776 uint32_t ntp_frac; | 800 uint32_t ntp_frac; |
777 clock_->CurrentNtp(ntp_sec, ntp_frac); | 801 clock_->CurrentNtp(ntp_sec, ntp_frac); |
778 RtcpContext context(feedback_state, nack_size, nack_list, repeat, pictureID, | 802 RtcpContext context(feedback_state, nack_size, nack_list, repeat, pictureID, |
779 ntp_sec, ntp_frac); | 803 ntp_sec, ntp_frac); |
780 | 804 |
781 PrepareReport(packet_types, feedback_state); | 805 PrepareReport(feedback_state); |
782 | 806 |
783 std::unique_ptr<rtcp::RtcpPacket> packet_bye; | 807 std::unique_ptr<rtcp::RtcpPacket> packet_bye; |
784 | 808 |
785 auto it = report_flags_.begin(); | 809 auto it = report_flags_.begin(); |
786 while (it != report_flags_.end()) { | 810 while (it != report_flags_.end()) { |
787 auto builder_it = builders_.find(it->type); | 811 auto builder_it = builders_.find(it->type); |
788 RTC_DCHECK(builder_it != builders_.end()); | 812 RTC_DCHECK(builder_it != builders_.end()); |
789 if (it->is_volatile) { | 813 if (it->is_volatile) { |
790 report_flags_.erase(it++); | 814 report_flags_.erase(it++); |
791 } else { | 815 } else { |
(...skipping 23 matching lines...) Expand all Loading... | |
815 remote_ssrc_, packet_type_counter_); | 839 remote_ssrc_, packet_type_counter_); |
816 } | 840 } |
817 | 841 |
818 RTC_DCHECK(AllVolatileFlagsConsumed()); | 842 RTC_DCHECK(AllVolatileFlagsConsumed()); |
819 } | 843 } |
820 | 844 |
821 size_t bytes_sent = container.SendPackets(max_payload_length_); | 845 size_t bytes_sent = container.SendPackets(max_payload_length_); |
822 return bytes_sent == 0 ? -1 : 0; | 846 return bytes_sent == 0 ? -1 : 0; |
823 } | 847 } |
824 | 848 |
825 void RTCPSender::PrepareReport(const std::set<RTCPPacketType>& packetTypes, | 849 void RTCPSender::PrepareReport(const FeedbackState& feedback_state) { |
826 const FeedbackState& feedback_state) { | |
827 // Add all flags as volatile. Non volatile entries will not be overwritten | |
828 // and all new volatile flags added will be consumed by the end of this call. | |
829 SetFlags(packetTypes, true); | |
830 | |
831 if (packet_type_counter_.first_packet_time_ms == -1) | |
832 packet_type_counter_.first_packet_time_ms = clock_->TimeInMilliseconds(); | |
833 | |
834 bool generate_report; | 850 bool generate_report; |
835 if (IsFlagPresent(kRtcpSr) || IsFlagPresent(kRtcpRr)) { | 851 if (IsFlagPresent(kRtcpSr) || IsFlagPresent(kRtcpRr)) { |
836 // Report type already explicitly set, don't automatically populate. | 852 // Report type already explicitly set, don't automatically populate. |
837 generate_report = true; | 853 generate_report = true; |
838 RTC_DCHECK(ConsumeFlag(kRtcpReport) == false); | 854 RTC_DCHECK(ConsumeFlag(kRtcpReport) == false); |
839 } else { | 855 } else { |
840 generate_report = | 856 generate_report = |
841 (ConsumeFlag(kRtcpReport) && method_ == RtcpMode::kReducedSize) || | 857 (ConsumeFlag(kRtcpReport) && method_ == RtcpMode::kReducedSize) || |
842 method_ == RtcpMode::kCompound; | 858 method_ == RtcpMode::kCompound; |
843 if (generate_report) | 859 if (generate_report) |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1041 // but we can't because of an incorrect warning (C4822) in MVS 2013. | 1057 // but we can't because of an incorrect warning (C4822) in MVS 2013. |
1042 } sender(transport_, event_log_); | 1058 } sender(transport_, event_log_); |
1043 | 1059 |
1044 RTC_DCHECK_LE(max_payload_length_, static_cast<size_t>(IP_PACKET_SIZE)); | 1060 RTC_DCHECK_LE(max_payload_length_, static_cast<size_t>(IP_PACKET_SIZE)); |
1045 uint8_t buffer[IP_PACKET_SIZE]; | 1061 uint8_t buffer[IP_PACKET_SIZE]; |
1046 return packet.BuildExternalBuffer(buffer, max_payload_length_, &sender) && | 1062 return packet.BuildExternalBuffer(buffer, max_payload_length_, &sender) && |
1047 !sender.send_failure_; | 1063 !sender.send_failure_; |
1048 } | 1064 } |
1049 | 1065 |
1050 } // namespace webrtc | 1066 } // namespace webrtc |
OLD | NEW |