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 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 rtc::scoped_ptr<rtcp::RtcpPacket> RTCPSender::BuildSR(const RtcpContext& ctx) { | 478 rtc::scoped_ptr<rtcp::RtcpPacket> RTCPSender::BuildSR(const RtcpContext& ctx) { |
479 for (int i = (RTCP_NUMBER_OF_SR - 2); i >= 0; i--) { | 479 for (int i = (RTCP_NUMBER_OF_SR - 2); i >= 0; i--) { |
480 // shift old | 480 // shift old |
481 last_send_report_[i + 1] = last_send_report_[i]; | 481 last_send_report_[i + 1] = last_send_report_[i]; |
482 last_rtcp_time_[i + 1] = last_rtcp_time_[i]; | 482 last_rtcp_time_[i + 1] = last_rtcp_time_[i]; |
483 } | 483 } |
484 | 484 |
485 last_rtcp_time_[0] = Clock::NtpToMs(ctx.ntp_sec_, ctx.ntp_frac_); | 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); | 486 last_send_report_[0] = (ctx.ntp_sec_ << 16) + (ctx.ntp_frac_ >> 16); |
487 | 487 |
| 488 // Timestamp shouldn't be esitmated before frame was received. |
| 489 RTC_DCHECK_GE(last_frame_capture_time_ms_, 0); |
488 // The timestamp of this RTCP packet should be estimated as the timestamp of | 490 // 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 | 491 // 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 | 492 // timestamp as the last frame's timestamp + the time since the last frame |
491 // was captured. | 493 // was captured. |
492 uint32_t rtp_timestamp = | 494 uint32_t rtp_timestamp = |
493 start_timestamp_ + last_rtp_timestamp_ + | 495 start_timestamp_ + last_rtp_timestamp_ + |
494 (clock_->TimeInMilliseconds() - last_frame_capture_time_ms_) * | 496 (clock_->TimeInMilliseconds() - last_frame_capture_time_ms_) * |
495 (ctx.feedback_state_.frequency_hz / 1000); | 497 (ctx.feedback_state_.frequency_hz / 1000); |
496 | 498 |
497 rtcp::SenderReport* report = new rtcp::SenderReport(); | 499 rtcp::SenderReport* report = new rtcp::SenderReport(); |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
816 const uint16_t* nack_list, | 818 const uint16_t* nack_list, |
817 bool repeat, | 819 bool repeat, |
818 uint64_t pictureID) { | 820 uint64_t pictureID) { |
819 PacketContainer container(transport_, event_log_); | 821 PacketContainer container(transport_, event_log_); |
820 { | 822 { |
821 CriticalSectionScoped lock(critical_section_rtcp_sender_.get()); | 823 CriticalSectionScoped lock(critical_section_rtcp_sender_.get()); |
822 if (method_ == RtcpMode::kOff) { | 824 if (method_ == RtcpMode::kOff) { |
823 LOG(LS_WARNING) << "Can't send rtcp if it is disabled."; | 825 LOG(LS_WARNING) << "Can't send rtcp if it is disabled."; |
824 return -1; | 826 return -1; |
825 } | 827 } |
| 828 // Add all flags as volatile. Non volatile entries will not be overwritten. |
| 829 // All new volatile flags added will be consumed by the end of this call. |
| 830 SetFlags(packet_types, true); |
| 831 |
| 832 // Prevent sending streams to send SR before any media has been sent. |
| 833 const bool can_calculate_rtp_timestamp = (last_frame_capture_time_ms_ >= 0); |
| 834 if (sending_ && !can_calculate_rtp_timestamp) { |
| 835 bool consumed_report_flag = ConsumeFlag(kRtcpReport); |
| 836 bool consumed_sr_flag = ConsumeFlag(kRtcpSr); |
| 837 bool sender_report = consumed_report_flag || consumed_sr_flag; |
| 838 if (sender_report && AllVolatileFlagsConsumed()) { |
| 839 // This call was for Sender Report and nothing else. |
| 840 return 0; |
| 841 } |
| 842 if (method_ == RtcpMode::kCompound) { |
| 843 // Not allowed to send any RTCP packet without sender report. |
| 844 return -1; |
| 845 } |
| 846 } |
| 847 |
| 848 if (packet_type_counter_.first_packet_time_ms == -1) |
| 849 packet_type_counter_.first_packet_time_ms = clock_->TimeInMilliseconds(); |
826 | 850 |
827 // We need to send our NTP even if we haven't received any reports. | 851 // We need to send our NTP even if we haven't received any reports. |
828 uint32_t ntp_sec; | 852 uint32_t ntp_sec; |
829 uint32_t ntp_frac; | 853 uint32_t ntp_frac; |
830 clock_->CurrentNtp(ntp_sec, ntp_frac); | 854 clock_->CurrentNtp(ntp_sec, ntp_frac); |
831 RtcpContext context(feedback_state, nack_size, nack_list, repeat, pictureID, | 855 RtcpContext context(feedback_state, nack_size, nack_list, repeat, pictureID, |
832 ntp_sec, ntp_frac, &container); | 856 ntp_sec, ntp_frac, &container); |
833 | 857 |
834 PrepareReport(packet_types, feedback_state); | 858 PrepareReport(feedback_state); |
835 | 859 |
836 auto it = report_flags_.begin(); | 860 auto it = report_flags_.begin(); |
837 while (it != report_flags_.end()) { | 861 while (it != report_flags_.end()) { |
838 auto builder_it = builders_.find(it->type); | 862 auto builder_it = builders_.find(it->type); |
839 RTC_DCHECK(builder_it != builders_.end()); | 863 RTC_DCHECK(builder_it != builders_.end()); |
840 if (it->is_volatile) { | 864 if (it->is_volatile) { |
841 report_flags_.erase(it++); | 865 report_flags_.erase(it++); |
842 } else { | 866 } else { |
843 ++it; | 867 ++it; |
844 } | 868 } |
(...skipping 10 matching lines...) Expand all Loading... |
855 remote_ssrc_, packet_type_counter_); | 879 remote_ssrc_, packet_type_counter_); |
856 } | 880 } |
857 | 881 |
858 RTC_DCHECK(AllVolatileFlagsConsumed()); | 882 RTC_DCHECK(AllVolatileFlagsConsumed()); |
859 } | 883 } |
860 | 884 |
861 size_t bytes_sent = container.SendPackets(); | 885 size_t bytes_sent = container.SendPackets(); |
862 return bytes_sent == 0 ? -1 : 0; | 886 return bytes_sent == 0 ? -1 : 0; |
863 } | 887 } |
864 | 888 |
865 void RTCPSender::PrepareReport(const std::set<RTCPPacketType>& packetTypes, | 889 void RTCPSender::PrepareReport(const FeedbackState& feedback_state) { |
866 const FeedbackState& feedback_state) { | |
867 // Add all flags as volatile. Non volatile entries will not be overwritten | |
868 // and all new volatile flags added will be consumed by the end of this call. | |
869 SetFlags(packetTypes, true); | |
870 | |
871 if (packet_type_counter_.first_packet_time_ms == -1) | |
872 packet_type_counter_.first_packet_time_ms = clock_->TimeInMilliseconds(); | |
873 | |
874 bool generate_report; | 890 bool generate_report; |
875 if (IsFlagPresent(kRtcpSr) || IsFlagPresent(kRtcpRr)) { | 891 if (IsFlagPresent(kRtcpSr) || IsFlagPresent(kRtcpRr)) { |
876 // Report type already explicitly set, don't automatically populate. | 892 // Report type already explicitly set, don't automatically populate. |
877 generate_report = true; | 893 generate_report = true; |
878 RTC_DCHECK(ConsumeFlag(kRtcpReport) == false); | 894 RTC_DCHECK(ConsumeFlag(kRtcpReport) == false); |
879 } else { | 895 } else { |
880 generate_report = | 896 generate_report = |
881 (ConsumeFlag(kRtcpReport) && method_ == RtcpMode::kReducedSize) || | 897 (ConsumeFlag(kRtcpReport) && method_ == RtcpMode::kReducedSize) || |
882 method_ == RtcpMode::kCompound; | 898 method_ == RtcpMode::kCompound; |
883 if (generate_report) | 899 if (generate_report) |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1079 // RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(Sender); | 1095 // RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(Sender); |
1080 // but we can't because of an incorrect warning (C4822) in MVS 2013. | 1096 // but we can't because of an incorrect warning (C4822) in MVS 2013. |
1081 } sender(transport_, event_log_); | 1097 } sender(transport_, event_log_); |
1082 | 1098 |
1083 uint8_t buffer[IP_PACKET_SIZE]; | 1099 uint8_t buffer[IP_PACKET_SIZE]; |
1084 return packet.BuildExternalBuffer(buffer, IP_PACKET_SIZE, &sender) && | 1100 return packet.BuildExternalBuffer(buffer, IP_PACKET_SIZE, &sender) && |
1085 !sender.send_failure_; | 1101 !sender.send_failure_; |
1086 } | 1102 } |
1087 | 1103 |
1088 } // namespace webrtc | 1104 } // namespace webrtc |
OLD | NEW |