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