Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(547)

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtcp_sender.cc

Issue 1639253007: Validates sending RTCP before RTP. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 estimated before first media frame.
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 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 const uint16_t* nack_list, 761 const uint16_t* nack_list,
760 bool repeat, 762 bool repeat,
761 uint64_t pictureID) { 763 uint64_t pictureID) {
762 PacketContainer container(transport_, event_log_); 764 PacketContainer container(transport_, event_log_);
763 { 765 {
764 rtc::CritScope lock(&critical_section_rtcp_sender_); 766 rtc::CritScope lock(&critical_section_rtcp_sender_);
765 if (method_ == RtcpMode::kOff) { 767 if (method_ == RtcpMode::kOff) {
766 LOG(LS_WARNING) << "Can't send rtcp if it is disabled."; 768 LOG(LS_WARNING) << "Can't send rtcp if it is disabled.";
767 return -1; 769 return -1;
768 } 770 }
771 // Add all flags as volatile. Non volatile entries will not be overwritten.
772 // All new volatile flags added will be consumed by the end of this call.
773 SetFlags(packet_types, true);
774
775 // Prevent sending streams to send SR before any media has been sent.
776 const bool can_calculate_rtp_timestamp = (last_frame_capture_time_ms_ >= 0);
777 if (!can_calculate_rtp_timestamp) {
778 bool consumed_sr_flag = ConsumeFlag(kRtcpSr);
779 bool consumed_report_flag = sending_ && ConsumeFlag(kRtcpReport);
780 bool sender_report = consumed_report_flag || consumed_sr_flag;
781 if (sender_report && AllVolatileFlagsConsumed()) {
782 // This call was for Sender Report and nothing else.
783 return 0;
784 }
785 if (sending_ && method_ == RtcpMode::kCompound) {
786 // Not allowed to send any RTCP packet without sender report.
787 return -1;
788 }
789 }
790
791 if (packet_type_counter_.first_packet_time_ms == -1)
792 packet_type_counter_.first_packet_time_ms = clock_->TimeInMilliseconds();
769 793
770 // We need to send our NTP even if we haven't received any reports. 794 // We need to send our NTP even if we haven't received any reports.
771 uint32_t ntp_sec; 795 uint32_t ntp_sec;
772 uint32_t ntp_frac; 796 uint32_t ntp_frac;
773 clock_->CurrentNtp(ntp_sec, ntp_frac); 797 clock_->CurrentNtp(ntp_sec, ntp_frac);
774 RtcpContext context(feedback_state, nack_size, nack_list, repeat, pictureID, 798 RtcpContext context(feedback_state, nack_size, nack_list, repeat, pictureID,
775 ntp_sec, ntp_frac); 799 ntp_sec, ntp_frac);
776 800
777 PrepareReport(packet_types, feedback_state); 801 PrepareReport(feedback_state);
778 802
779 std::unique_ptr<rtcp::RtcpPacket> packet_bye; 803 std::unique_ptr<rtcp::RtcpPacket> packet_bye;
780 804
781 auto it = report_flags_.begin(); 805 auto it = report_flags_.begin();
782 while (it != report_flags_.end()) { 806 while (it != report_flags_.end()) {
783 auto builder_it = builders_.find(it->type); 807 auto builder_it = builders_.find(it->type);
784 RTC_DCHECK(builder_it != builders_.end()); 808 RTC_DCHECK(builder_it != builders_.end());
785 if (it->is_volatile) { 809 if (it->is_volatile) {
786 report_flags_.erase(it++); 810 report_flags_.erase(it++);
787 } else { 811 } else {
(...skipping 23 matching lines...) Expand all
811 remote_ssrc_, packet_type_counter_); 835 remote_ssrc_, packet_type_counter_);
812 } 836 }
813 837
814 RTC_DCHECK(AllVolatileFlagsConsumed()); 838 RTC_DCHECK(AllVolatileFlagsConsumed());
815 } 839 }
816 840
817 size_t bytes_sent = container.SendPackets(max_payload_length_); 841 size_t bytes_sent = container.SendPackets(max_payload_length_);
818 return bytes_sent == 0 ? -1 : 0; 842 return bytes_sent == 0 ? -1 : 0;
819 } 843 }
820 844
821 void RTCPSender::PrepareReport(const std::set<RTCPPacketType>& packetTypes, 845 void RTCPSender::PrepareReport(const FeedbackState& feedback_state) {
822 const FeedbackState& feedback_state) {
823 // Add all flags as volatile. Non volatile entries will not be overwritten
824 // and all new volatile flags added will be consumed by the end of this call.
825 SetFlags(packetTypes, true);
826
827 if (packet_type_counter_.first_packet_time_ms == -1)
828 packet_type_counter_.first_packet_time_ms = clock_->TimeInMilliseconds();
829
830 bool generate_report; 846 bool generate_report;
831 if (IsFlagPresent(kRtcpSr) || IsFlagPresent(kRtcpRr)) { 847 if (IsFlagPresent(kRtcpSr) || IsFlagPresent(kRtcpRr)) {
832 // Report type already explicitly set, don't automatically populate. 848 // Report type already explicitly set, don't automatically populate.
833 generate_report = true; 849 generate_report = true;
834 RTC_DCHECK(ConsumeFlag(kRtcpReport) == false); 850 RTC_DCHECK(ConsumeFlag(kRtcpReport) == false);
835 } else { 851 } else {
836 generate_report = 852 generate_report =
837 (ConsumeFlag(kRtcpReport) && method_ == RtcpMode::kReducedSize) || 853 (ConsumeFlag(kRtcpReport) && method_ == RtcpMode::kReducedSize) ||
838 method_ == RtcpMode::kCompound; 854 method_ == RtcpMode::kCompound;
839 if (generate_report) 855 if (generate_report)
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 // but we can't because of an incorrect warning (C4822) in MVS 2013. 1053 // but we can't because of an incorrect warning (C4822) in MVS 2013.
1038 } sender(transport_, event_log_); 1054 } sender(transport_, event_log_);
1039 1055
1040 RTC_DCHECK_LE(max_payload_length_, static_cast<size_t>(IP_PACKET_SIZE)); 1056 RTC_DCHECK_LE(max_payload_length_, static_cast<size_t>(IP_PACKET_SIZE));
1041 uint8_t buffer[IP_PACKET_SIZE]; 1057 uint8_t buffer[IP_PACKET_SIZE];
1042 return packet.BuildExternalBuffer(buffer, max_payload_length_, &sender) && 1058 return packet.BuildExternalBuffer(buffer, max_payload_length_, &sender) &&
1043 !sender.send_failure_; 1059 !sender.send_failure_;
1044 } 1060 }
1045 1061
1046 } // namespace webrtc 1062 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698