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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 namespace webrtc { | 48 namespace webrtc { |
49 namespace { | 49 namespace { |
50 | 50 |
51 using rtcp::CommonHeader; | 51 using rtcp::CommonHeader; |
52 using rtcp::ReportBlock; | 52 using rtcp::ReportBlock; |
53 | 53 |
54 // The number of RTCP time intervals needed to trigger a timeout. | 54 // The number of RTCP time intervals needed to trigger a timeout. |
55 const int kRrTimeoutIntervals = 3; | 55 const int kRrTimeoutIntervals = 3; |
56 | 56 |
57 const int64_t kMaxWarningLogIntervalMs = 10000; | 57 const int64_t kMaxWarningLogIntervalMs = 10000; |
| 58 const int64_t kRtcpMinFrameLengthMs = 17; |
58 | 59 |
59 } // namespace | 60 } // namespace |
60 | 61 |
61 struct RTCPReceiver::PacketInformation { | 62 struct RTCPReceiver::PacketInformation { |
62 uint32_t packet_type_flags = 0; // RTCPPacketTypeFlags bit field. | 63 uint32_t packet_type_flags = 0; // RTCPPacketTypeFlags bit field. |
63 | 64 |
64 uint32_t remote_ssrc = 0; | 65 uint32_t remote_ssrc = 0; |
65 std::vector<uint16_t> nack_sequence_numbers; | 66 std::vector<uint16_t> nack_sequence_numbers; |
66 ReportBlockList report_blocks; | 67 ReportBlockList report_blocks; |
67 int64_t rtt_ms = 0; | 68 int64_t rtt_ms = 0; |
68 uint8_t sli_picture_id = 0; | 69 uint8_t sli_picture_id = 0; |
69 uint64_t rpsi_picture_id = 0; | 70 uint64_t rpsi_picture_id = 0; |
70 uint32_t receiver_estimated_max_bitrate_bps = 0; | 71 uint32_t receiver_estimated_max_bitrate_bps = 0; |
71 std::unique_ptr<rtcp::TransportFeedback> transport_feedback; | 72 std::unique_ptr<rtcp::TransportFeedback> transport_feedback; |
72 rtc::Optional<BitrateAllocation> target_bitrate_allocation; | 73 rtc::Optional<BitrateAllocation> target_bitrate_allocation; |
73 }; | 74 }; |
74 | 75 |
75 struct RTCPReceiver::ReceiveInformation { | 76 struct RTCPReceiver::ReceiveInformation { |
76 struct TimedTmmbrItem { | 77 struct TimedTmmbrItem { |
77 rtcp::TmmbItem tmmbr_item; | 78 rtcp::TmmbItem tmmbr_item; |
78 int64_t last_updated_ms; | 79 int64_t last_updated_ms; |
79 }; | 80 }; |
80 | 81 |
81 int64_t last_time_received_ms = 0; | 82 int64_t last_time_received_ms = 0; |
82 | 83 |
83 int64_t last_fir_request_ms = 0; | |
84 int32_t last_fir_sequence_number = -1; | |
85 | |
86 bool ready_for_delete = false; | 84 bool ready_for_delete = false; |
87 | 85 |
88 std::vector<rtcp::TmmbItem> tmmbn; | 86 std::vector<rtcp::TmmbItem> tmmbn; |
89 std::map<uint32_t, TimedTmmbrItem> tmmbr; | 87 std::map<uint32_t, TimedTmmbrItem> tmmbr; |
90 }; | 88 }; |
91 | 89 |
92 struct RTCPReceiver::ReportBlockWithRtt { | 90 struct RTCPReceiver::ReportBlockWithRtt { |
93 RTCPReportBlock report_block; | 91 RTCPReportBlock report_block; |
94 | 92 |
95 int64_t last_rtt_ms = 0; | 93 int64_t last_rtt_ms = 0; |
96 int64_t min_rtt_ms = 0; | 94 int64_t min_rtt_ms = 0; |
97 int64_t max_rtt_ms = 0; | 95 int64_t max_rtt_ms = 0; |
98 int64_t sum_rtt_ms = 0; | 96 int64_t sum_rtt_ms = 0; |
99 size_t num_rtts = 0; | 97 size_t num_rtts = 0; |
100 }; | 98 }; |
101 | 99 |
| 100 struct RTCPReceiver::LastFirStatus { |
| 101 LastFirStatus(int64_t now_ms, uint8_t sequence_number) |
| 102 : request_ms(now_ms), sequence_number(sequence_number) {} |
| 103 int64_t request_ms; |
| 104 uint8_t sequence_number; |
| 105 }; |
| 106 |
102 RTCPReceiver::RTCPReceiver( | 107 RTCPReceiver::RTCPReceiver( |
103 Clock* clock, | 108 Clock* clock, |
104 bool receiver_only, | 109 bool receiver_only, |
105 RtcpPacketTypeCounterObserver* packet_type_counter_observer, | 110 RtcpPacketTypeCounterObserver* packet_type_counter_observer, |
106 RtcpBandwidthObserver* rtcp_bandwidth_observer, | 111 RtcpBandwidthObserver* rtcp_bandwidth_observer, |
107 RtcpIntraFrameObserver* rtcp_intra_frame_observer, | 112 RtcpIntraFrameObserver* rtcp_intra_frame_observer, |
108 TransportFeedbackObserver* transport_feedback_observer, | 113 TransportFeedbackObserver* transport_feedback_observer, |
109 VideoBitrateAllocationObserver* bitrate_allocation_observer, | 114 VideoBitrateAllocationObserver* bitrate_allocation_observer, |
110 ModuleRtpRtcp* owner) | 115 ModuleRtpRtcp* owner) |
111 : clock_(clock), | 116 : clock_(clock), |
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 | 681 |
677 // Clear our lists. | 682 // Clear our lists. |
678 for (auto& reports_per_receiver : received_report_blocks_) | 683 for (auto& reports_per_receiver : received_report_blocks_) |
679 reports_per_receiver.second.erase(bye.sender_ssrc()); | 684 reports_per_receiver.second.erase(bye.sender_ssrc()); |
680 | 685 |
681 // We can't delete it due to TMMBR. | 686 // We can't delete it due to TMMBR. |
682 ReceiveInformation* receive_info = GetReceiveInformation(bye.sender_ssrc()); | 687 ReceiveInformation* receive_info = GetReceiveInformation(bye.sender_ssrc()); |
683 if (receive_info) | 688 if (receive_info) |
684 receive_info->ready_for_delete = true; | 689 receive_info->ready_for_delete = true; |
685 | 690 |
| 691 last_fir_.erase(bye.sender_ssrc()); |
686 received_cnames_.erase(bye.sender_ssrc()); | 692 received_cnames_.erase(bye.sender_ssrc()); |
687 xr_rr_rtt_ms_ = 0; | 693 xr_rr_rtt_ms_ = 0; |
688 } | 694 } |
689 | 695 |
690 void RTCPReceiver::HandleXr(const CommonHeader& rtcp_block, | 696 void RTCPReceiver::HandleXr(const CommonHeader& rtcp_block, |
691 PacketInformation* packet_information) { | 697 PacketInformation* packet_information) { |
692 rtcp::ExtendedReports xr; | 698 rtcp::ExtendedReports xr; |
693 if (!xr.Parse(rtcp_block)) { | 699 if (!xr.Parse(rtcp_block)) { |
694 ++num_skipped_packets_; | 700 ++num_skipped_packets_; |
695 return; | 701 return; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
873 } | 879 } |
874 | 880 |
875 void RTCPReceiver::HandleFir(const CommonHeader& rtcp_block, | 881 void RTCPReceiver::HandleFir(const CommonHeader& rtcp_block, |
876 PacketInformation* packet_information) { | 882 PacketInformation* packet_information) { |
877 rtcp::Fir fir; | 883 rtcp::Fir fir; |
878 if (!fir.Parse(rtcp_block)) { | 884 if (!fir.Parse(rtcp_block)) { |
879 ++num_skipped_packets_; | 885 ++num_skipped_packets_; |
880 return; | 886 return; |
881 } | 887 } |
882 | 888 |
883 ReceiveInformation* receive_info = GetReceiveInformation(fir.sender_ssrc()); | |
884 | |
885 for (const rtcp::Fir::Request& fir_request : fir.requests()) { | 889 for (const rtcp::Fir::Request& fir_request : fir.requests()) { |
886 // Is it our sender that is requested to generate a new keyframe. | 890 // Is it our sender that is requested to generate a new keyframe. |
887 if (main_ssrc_ != fir_request.ssrc) | 891 if (main_ssrc_ != fir_request.ssrc) |
888 continue; | 892 continue; |
889 | 893 |
890 ++packet_type_counter_.fir_packets; | 894 ++packet_type_counter_.fir_packets; |
891 | 895 |
892 if (receive_info) { | 896 int64_t now_ms = clock_->TimeInMilliseconds(); |
| 897 auto inserted = last_fir_.insert(std::make_pair( |
| 898 fir.sender_ssrc(), LastFirStatus(now_ms, fir_request.seq_nr))); |
| 899 if (!inserted.second) { // There was already an entry. |
| 900 LastFirStatus* last_fir = &inserted.first->second; |
| 901 |
893 // Check if we have reported this FIRSequenceNumber before. | 902 // Check if we have reported this FIRSequenceNumber before. |
894 if (fir_request.seq_nr == receive_info->last_fir_sequence_number) | 903 if (fir_request.seq_nr == last_fir->sequence_number) |
895 continue; | 904 continue; |
896 | 905 |
897 int64_t now_ms = clock_->TimeInMilliseconds(); | |
898 // Sanity: don't go crazy with the callbacks. | 906 // Sanity: don't go crazy with the callbacks. |
899 if (now_ms - receive_info->last_fir_request_ms < RTCP_MIN_FRAME_LENGTH_MS) | 907 if (now_ms - last_fir->request_ms < kRtcpMinFrameLengthMs) |
900 continue; | 908 continue; |
901 | 909 |
902 receive_info->last_fir_request_ms = now_ms; | 910 last_fir->request_ms = now_ms; |
903 receive_info->last_fir_sequence_number = fir_request.seq_nr; | 911 last_fir->sequence_number = fir_request.seq_nr; |
904 } | 912 } |
905 // Received signal that we need to send a new key frame. | 913 // Received signal that we need to send a new key frame. |
906 packet_information->packet_type_flags |= kRtcpFir; | 914 packet_information->packet_type_flags |= kRtcpFir; |
907 } | 915 } |
908 } | 916 } |
909 | 917 |
910 void RTCPReceiver::HandleTransportFeedback( | 918 void RTCPReceiver::HandleTransportFeedback( |
911 const CommonHeader& rtcp_block, | 919 const CommonHeader& rtcp_block, |
912 PacketInformation* packet_information) { | 920 PacketInformation* packet_information) { |
913 std::unique_ptr<rtcp::TransportFeedback> transport_feedback( | 921 std::unique_ptr<rtcp::TransportFeedback> transport_feedback( |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1085 } else { | 1093 } else { |
1086 candidates.push_back(it->second.tmmbr_item); | 1094 candidates.push_back(it->second.tmmbr_item); |
1087 ++it; | 1095 ++it; |
1088 } | 1096 } |
1089 } | 1097 } |
1090 } | 1098 } |
1091 return candidates; | 1099 return candidates; |
1092 } | 1100 } |
1093 | 1101 |
1094 } // namespace webrtc | 1102 } // namespace webrtc |
OLD | NEW |