| 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 |
| 11 #include "webrtc/modules/rtp_rtcp/source/rtcp_receiver.h" | 11 #include "webrtc/modules/rtp_rtcp/source/rtcp_receiver.h" |
| 12 | 12 |
| 13 #include <assert.h> | |
| 14 #include <string.h> | 13 #include <string.h> |
| 15 | 14 |
| 16 #include <limits> | 15 #include <limits> |
| 17 #include <map> | 16 #include <map> |
| 18 #include <memory> | 17 #include <memory> |
| 19 #include <utility> | 18 #include <utility> |
| 20 #include <vector> | 19 #include <vector> |
| 21 | 20 |
| 22 #include "webrtc/base/checks.h" | 21 #include "webrtc/base/checks.h" |
| 23 #include "webrtc/base/logging.h" | 22 #include "webrtc/base/logging.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 | 100 |
| 102 RTCPReceiver::RTCPReceiver( | 101 RTCPReceiver::RTCPReceiver( |
| 103 Clock* clock, | 102 Clock* clock, |
| 104 bool receiver_only, | 103 bool receiver_only, |
| 105 RtcpPacketTypeCounterObserver* packet_type_counter_observer, | 104 RtcpPacketTypeCounterObserver* packet_type_counter_observer, |
| 106 RtcpBandwidthObserver* rtcp_bandwidth_observer, | 105 RtcpBandwidthObserver* rtcp_bandwidth_observer, |
| 107 RtcpIntraFrameObserver* rtcp_intra_frame_observer, | 106 RtcpIntraFrameObserver* rtcp_intra_frame_observer, |
| 108 TransportFeedbackObserver* transport_feedback_observer, | 107 TransportFeedbackObserver* transport_feedback_observer, |
| 109 VideoBitrateAllocationObserver* bitrate_allocation_observer, | 108 VideoBitrateAllocationObserver* bitrate_allocation_observer, |
| 110 ModuleRtpRtcp* owner) | 109 ModuleRtpRtcp* owner) |
| 111 : _clock(clock), | 110 : clock_(clock), |
| 112 receiver_only_(receiver_only), | 111 receiver_only_(receiver_only), |
| 113 _rtpRtcp(*owner), | 112 rtp_rtcp_(owner), |
| 114 rtcp_bandwidth_observer_(rtcp_bandwidth_observer), | 113 rtcp_bandwidth_observer_(rtcp_bandwidth_observer), |
| 115 rtcp_intra_frame_observer_(rtcp_intra_frame_observer), | 114 rtcp_intra_frame_observer_(rtcp_intra_frame_observer), |
| 116 transport_feedback_observer_(transport_feedback_observer), | 115 transport_feedback_observer_(transport_feedback_observer), |
| 117 bitrate_allocation_observer_(bitrate_allocation_observer), | 116 bitrate_allocation_observer_(bitrate_allocation_observer), |
| 118 main_ssrc_(0), | 117 main_ssrc_(0), |
| 119 _remoteSSRC(0), | 118 remote_ssrc_(0), |
| 120 _remoteSenderInfo(), | |
| 121 xr_rrtr_status_(false), | 119 xr_rrtr_status_(false), |
| 122 xr_rr_rtt_ms_(0), | 120 xr_rr_rtt_ms_(0), |
| 123 _lastReceivedRrMs(0), | 121 last_received_rr_ms_(0), |
| 124 _lastIncreasedSequenceNumberMs(0), | 122 last_increased_sequence_number_ms_(0), |
| 125 stats_callback_(nullptr), | 123 stats_callback_(nullptr), |
| 126 packet_type_counter_observer_(packet_type_counter_observer), | 124 packet_type_counter_observer_(packet_type_counter_observer), |
| 127 num_skipped_packets_(0), | 125 num_skipped_packets_(0), |
| 128 last_skipped_packets_warning_(clock->TimeInMilliseconds()) { | 126 last_skipped_packets_warning_ms_(clock->TimeInMilliseconds()) { |
| 129 memset(&_remoteSenderInfo, 0, sizeof(_remoteSenderInfo)); | 127 RTC_DCHECK(owner); |
| 128 memset(&remote_sender_info_, 0, sizeof(remote_sender_info_)); |
| 130 } | 129 } |
| 131 | 130 |
| 132 RTCPReceiver::~RTCPReceiver() {} | 131 RTCPReceiver::~RTCPReceiver() {} |
| 133 | 132 |
| 134 bool RTCPReceiver::IncomingPacket(const uint8_t* packet, size_t packet_size) { | 133 bool RTCPReceiver::IncomingPacket(const uint8_t* packet, size_t packet_size) { |
| 135 if (packet_size == 0) { | 134 if (packet_size == 0) { |
| 136 LOG(LS_WARNING) << "Incoming empty RTCP packet"; | 135 LOG(LS_WARNING) << "Incoming empty RTCP packet"; |
| 137 return false; | 136 return false; |
| 138 } | 137 } |
| 139 | 138 |
| 140 PacketInformation packet_information; | 139 PacketInformation packet_information; |
| 141 if (!ParseCompoundPacket(packet, packet + packet_size, &packet_information)) | 140 if (!ParseCompoundPacket(packet, packet + packet_size, &packet_information)) |
| 142 return false; | 141 return false; |
| 143 TriggerCallbacksFromRTCPPacket(packet_information); | 142 TriggerCallbacksFromRtcpPacket(packet_information); |
| 144 return true; | 143 return true; |
| 145 } | 144 } |
| 146 | 145 |
| 147 int64_t RTCPReceiver::LastReceivedReceiverReport() const { | 146 int64_t RTCPReceiver::LastReceivedReceiverReport() const { |
| 148 rtc::CritScope lock(&_criticalSectionRTCPReceiver); | 147 rtc::CritScope lock(&rtcp_receiver_lock_); |
| 149 int64_t last_received_rr = -1; | 148 int64_t last_received_rr = -1; |
| 150 for (const auto& kv : received_infos_) | 149 for (const auto& kv : received_infos_) |
| 151 if (kv.second.last_time_received_ms > last_received_rr) | 150 if (kv.second.last_time_received_ms > last_received_rr) |
| 152 last_received_rr = kv.second.last_time_received_ms; | 151 last_received_rr = kv.second.last_time_received_ms; |
| 153 return last_received_rr; | 152 return last_received_rr; |
| 154 } | 153 } |
| 155 | 154 |
| 156 void RTCPReceiver::SetRemoteSSRC(uint32_t ssrc) { | 155 void RTCPReceiver::SetRemoteSSRC(uint32_t ssrc) { |
| 157 rtc::CritScope lock(&_criticalSectionRTCPReceiver); | 156 rtc::CritScope lock(&rtcp_receiver_lock_); |
| 158 | 157 // New SSRC reset old reports. |
| 159 // new SSRC reset old reports | 158 memset(&remote_sender_info_, 0, sizeof(remote_sender_info_)); |
| 160 memset(&_remoteSenderInfo, 0, sizeof(_remoteSenderInfo)); | |
| 161 last_received_sr_ntp_.Reset(); | 159 last_received_sr_ntp_.Reset(); |
| 162 | 160 remote_ssrc_ = ssrc; |
| 163 _remoteSSRC = ssrc; | |
| 164 } | 161 } |
| 165 | 162 |
| 166 uint32_t RTCPReceiver::RemoteSSRC() const { | 163 uint32_t RTCPReceiver::RemoteSSRC() const { |
| 167 rtc::CritScope lock(&_criticalSectionRTCPReceiver); | 164 rtc::CritScope lock(&rtcp_receiver_lock_); |
| 168 return _remoteSSRC; | 165 return remote_ssrc_; |
| 169 } | 166 } |
| 170 | 167 |
| 171 void RTCPReceiver::SetSsrcs(uint32_t main_ssrc, | 168 void RTCPReceiver::SetSsrcs(uint32_t main_ssrc, |
| 172 const std::set<uint32_t>& registered_ssrcs) { | 169 const std::set<uint32_t>& registered_ssrcs) { |
| 173 rtc::CritScope lock(&_criticalSectionRTCPReceiver); | 170 rtc::CritScope lock(&rtcp_receiver_lock_); |
| 174 main_ssrc_ = main_ssrc; | 171 main_ssrc_ = main_ssrc; |
| 175 registered_ssrcs_ = registered_ssrcs; | 172 registered_ssrcs_ = registered_ssrcs; |
| 176 } | 173 } |
| 177 | 174 |
| 178 int32_t RTCPReceiver::RTT(uint32_t remote_ssrc, | 175 int32_t RTCPReceiver::RTT(uint32_t remote_ssrc, |
| 179 int64_t* last_rtt_ms, | 176 int64_t* last_rtt_ms, |
| 180 int64_t* avg_rtt_ms, | 177 int64_t* avg_rtt_ms, |
| 181 int64_t* min_rtt_ms, | 178 int64_t* min_rtt_ms, |
| 182 int64_t* max_rtt_ms) const { | 179 int64_t* max_rtt_ms) const { |
| 183 rtc::CritScope lock(&_criticalSectionRTCPReceiver); | 180 rtc::CritScope lock(&rtcp_receiver_lock_); |
| 184 | 181 |
| 185 auto it = received_report_blocks_.find(main_ssrc_); | 182 auto it = received_report_blocks_.find(main_ssrc_); |
| 186 if (it == received_report_blocks_.end()) | 183 if (it == received_report_blocks_.end()) |
| 187 return -1; | 184 return -1; |
| 188 | 185 |
| 189 auto it_info = it->second.find(remote_ssrc); | 186 auto it_info = it->second.find(remote_ssrc); |
| 190 if (it_info == it->second.end()) | 187 if (it_info == it->second.end()) |
| 191 return -1; | 188 return -1; |
| 192 | 189 |
| 193 const ReportBlockWithRtt* report_block = &it_info->second; | 190 const ReportBlockWithRtt* report_block = &it_info->second; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 204 if (min_rtt_ms) | 201 if (min_rtt_ms) |
| 205 *min_rtt_ms = report_block->min_rtt_ms; | 202 *min_rtt_ms = report_block->min_rtt_ms; |
| 206 | 203 |
| 207 if (max_rtt_ms) | 204 if (max_rtt_ms) |
| 208 *max_rtt_ms = report_block->max_rtt_ms; | 205 *max_rtt_ms = report_block->max_rtt_ms; |
| 209 | 206 |
| 210 return 0; | 207 return 0; |
| 211 } | 208 } |
| 212 | 209 |
| 213 void RTCPReceiver::SetRtcpXrRrtrStatus(bool enable) { | 210 void RTCPReceiver::SetRtcpXrRrtrStatus(bool enable) { |
| 214 rtc::CritScope lock(&_criticalSectionRTCPReceiver); | 211 rtc::CritScope lock(&rtcp_receiver_lock_); |
| 215 xr_rrtr_status_ = enable; | 212 xr_rrtr_status_ = enable; |
| 216 } | 213 } |
| 217 | 214 |
| 218 bool RTCPReceiver::GetAndResetXrRrRtt(int64_t* rtt_ms) { | 215 bool RTCPReceiver::GetAndResetXrRrRtt(int64_t* rtt_ms) { |
| 219 assert(rtt_ms); | 216 RTC_DCHECK(rtt_ms); |
| 220 rtc::CritScope lock(&_criticalSectionRTCPReceiver); | 217 rtc::CritScope lock(&rtcp_receiver_lock_); |
| 221 if (xr_rr_rtt_ms_ == 0) { | 218 if (xr_rr_rtt_ms_ == 0) { |
| 222 return false; | 219 return false; |
| 223 } | 220 } |
| 224 *rtt_ms = xr_rr_rtt_ms_; | 221 *rtt_ms = xr_rr_rtt_ms_; |
| 225 xr_rr_rtt_ms_ = 0; | 222 xr_rr_rtt_ms_ = 0; |
| 226 return true; | 223 return true; |
| 227 } | 224 } |
| 228 | 225 |
| 229 bool RTCPReceiver::NTP(uint32_t* ReceivedNTPsecs, | 226 bool RTCPReceiver::NTP(uint32_t* received_ntp_secs, |
| 230 uint32_t* ReceivedNTPfrac, | 227 uint32_t* received_ntp_frac, |
| 231 uint32_t* RTCPArrivalTimeSecs, | 228 uint32_t* rtcp_arrival_time_secs, |
| 232 uint32_t* RTCPArrivalTimeFrac, | 229 uint32_t* rtcp_arrival_time_frac, |
| 233 uint32_t* rtcp_timestamp) const { | 230 uint32_t* rtcp_timestamp) const { |
| 234 rtc::CritScope lock(&_criticalSectionRTCPReceiver); | 231 rtc::CritScope lock(&rtcp_receiver_lock_); |
| 235 if (!last_received_sr_ntp_.Valid()) | 232 if (!last_received_sr_ntp_.Valid()) |
| 236 return false; | 233 return false; |
| 237 | 234 |
| 238 // NTP from incoming SenderReport. | 235 // NTP from incoming SenderReport. |
| 239 if (ReceivedNTPsecs) | 236 if (received_ntp_secs) |
| 240 *ReceivedNTPsecs = _remoteSenderInfo.NTPseconds; | 237 *received_ntp_secs = remote_sender_info_.NTPseconds; |
| 241 if (ReceivedNTPfrac) | 238 if (received_ntp_frac) |
| 242 *ReceivedNTPfrac = _remoteSenderInfo.NTPfraction; | 239 *received_ntp_frac = remote_sender_info_.NTPfraction; |
| 243 | 240 |
| 244 // Rtp time from incoming SenderReport. | 241 // Rtp time from incoming SenderReport. |
| 245 if (rtcp_timestamp) | 242 if (rtcp_timestamp) |
| 246 *rtcp_timestamp = _remoteSenderInfo.RTPtimeStamp; | 243 *rtcp_timestamp = remote_sender_info_.RTPtimeStamp; |
| 247 | 244 |
| 248 // Local NTP time when we received a RTCP packet with a send block. | 245 // Local NTP time when we received a RTCP packet with a send block. |
| 249 if (RTCPArrivalTimeSecs) | 246 if (rtcp_arrival_time_secs) |
| 250 *RTCPArrivalTimeSecs = last_received_sr_ntp_.seconds(); | 247 *rtcp_arrival_time_secs = last_received_sr_ntp_.seconds(); |
| 251 if (RTCPArrivalTimeFrac) | 248 if (rtcp_arrival_time_frac) |
| 252 *RTCPArrivalTimeFrac = last_received_sr_ntp_.fractions(); | 249 *rtcp_arrival_time_frac = last_received_sr_ntp_.fractions(); |
| 253 | 250 |
| 254 return true; | 251 return true; |
| 255 } | 252 } |
| 256 | 253 |
| 257 bool RTCPReceiver::LastReceivedXrReferenceTimeInfo( | 254 bool RTCPReceiver::LastReceivedXrReferenceTimeInfo( |
| 258 rtcp::ReceiveTimeInfo* info) const { | 255 rtcp::ReceiveTimeInfo* info) const { |
| 259 RTC_DCHECK(info); | 256 RTC_DCHECK(info); |
| 260 rtc::CritScope lock(&_criticalSectionRTCPReceiver); | 257 rtc::CritScope lock(&rtcp_receiver_lock_); |
| 261 if (!last_received_xr_ntp_.Valid()) | 258 if (!last_received_xr_ntp_.Valid()) |
| 262 return false; | 259 return false; |
| 263 | 260 |
| 264 info->ssrc = remote_time_info_.ssrc; | 261 info->ssrc = remote_time_info_.ssrc; |
| 265 info->last_rr = remote_time_info_.last_rr; | 262 info->last_rr = remote_time_info_.last_rr; |
| 266 | 263 |
| 267 // Get the delay since last received report (RFC 3611). | 264 // Get the delay since last received report (RFC 3611). |
| 268 uint32_t receive_time = CompactNtp(last_received_xr_ntp_); | 265 uint32_t receive_time_ntp = CompactNtp(last_received_xr_ntp_); |
| 269 uint32_t now = CompactNtp(NtpTime(*_clock)); | 266 uint32_t now_ntp = CompactNtp(NtpTime(*clock_)); |
| 270 | 267 |
| 271 info->delay_since_last_rr = now - receive_time; | 268 info->delay_since_last_rr = now_ntp - receive_time_ntp; |
| 272 return true; | 269 return true; |
| 273 } | 270 } |
| 274 | 271 |
| 275 int32_t RTCPReceiver::SenderInfoReceived(RTCPSenderInfo* senderInfo) const { | 272 int32_t RTCPReceiver::SenderInfoReceived(RTCPSenderInfo* sender_info) const { |
| 276 assert(senderInfo); | 273 RTC_DCHECK(sender_info); |
| 277 rtc::CritScope lock(&_criticalSectionRTCPReceiver); | 274 rtc::CritScope lock(&rtcp_receiver_lock_); |
| 278 if (!last_received_sr_ntp_.Valid()) | 275 if (!last_received_sr_ntp_.Valid()) |
| 279 return -1; | 276 return -1; |
| 280 | 277 |
| 281 memcpy(senderInfo, &(_remoteSenderInfo), sizeof(RTCPSenderInfo)); | 278 memcpy(sender_info, &remote_sender_info_, sizeof(RTCPSenderInfo)); |
| 282 return 0; | 279 return 0; |
| 283 } | 280 } |
| 284 | 281 |
| 285 // We can get multiple receive reports when we receive the report from a CE. | 282 // We can get multiple receive reports when we receive the report from a CE. |
| 286 int32_t RTCPReceiver::StatisticsReceived( | 283 int32_t RTCPReceiver::StatisticsReceived( |
| 287 std::vector<RTCPReportBlock>* receive_blocks) const { | 284 std::vector<RTCPReportBlock>* receive_blocks) const { |
| 288 RTC_DCHECK(receive_blocks); | 285 RTC_DCHECK(receive_blocks); |
| 289 rtc::CritScope lock(&_criticalSectionRTCPReceiver); | 286 rtc::CritScope lock(&rtcp_receiver_lock_); |
| 290 for (const auto& reports_per_receiver : received_report_blocks_) | 287 for (const auto& reports_per_receiver : received_report_blocks_) |
| 291 for (const auto& report : reports_per_receiver.second) | 288 for (const auto& report : reports_per_receiver.second) |
| 292 receive_blocks->push_back(report.second.report_block); | 289 receive_blocks->push_back(report.second.report_block); |
| 293 return 0; | 290 return 0; |
| 294 } | 291 } |
| 295 | 292 |
| 296 bool RTCPReceiver::ParseCompoundPacket(const uint8_t* packet_begin, | 293 bool RTCPReceiver::ParseCompoundPacket(const uint8_t* packet_begin, |
| 297 const uint8_t* packet_end, | 294 const uint8_t* packet_end, |
| 298 PacketInformation* packet_information) { | 295 PacketInformation* packet_information) { |
| 299 rtc::CritScope lock(&_criticalSectionRTCPReceiver); | 296 rtc::CritScope lock(&rtcp_receiver_lock_); |
| 300 | 297 |
| 301 CommonHeader rtcp_block; | 298 CommonHeader rtcp_block; |
| 302 for (const uint8_t* next_block = packet_begin; next_block != packet_end; | 299 for (const uint8_t* next_block = packet_begin; next_block != packet_end; |
| 303 next_block = rtcp_block.NextPacket()) { | 300 next_block = rtcp_block.NextPacket()) { |
| 304 ptrdiff_t remaining_blocks_size = packet_end - next_block; | 301 ptrdiff_t remaining_blocks_size = packet_end - next_block; |
| 305 RTC_DCHECK_GT(remaining_blocks_size, 0); | 302 RTC_DCHECK_GT(remaining_blocks_size, 0); |
| 306 if (!rtcp_block.Parse(next_block, remaining_blocks_size)) { | 303 if (!rtcp_block.Parse(next_block, remaining_blocks_size)) { |
| 307 if (next_block == packet_begin) { | 304 if (next_block == packet_begin) { |
| 308 // Failed to parse 1st header, nothing was extracted from this packet. | 305 // Failed to parse 1st header, nothing was extracted from this packet. |
| 309 LOG(LS_WARNING) << "Incoming invalid RTCP packet"; | 306 LOG(LS_WARNING) << "Incoming invalid RTCP packet"; |
| 310 return false; | 307 return false; |
| 311 } | 308 } |
| 312 ++num_skipped_packets_; | 309 ++num_skipped_packets_; |
| 313 break; | 310 break; |
| 314 } | 311 } |
| 315 | 312 |
| 316 if (packet_type_counter_.first_packet_time_ms == -1) | 313 if (packet_type_counter_.first_packet_time_ms == -1) |
| 317 packet_type_counter_.first_packet_time_ms = _clock->TimeInMilliseconds(); | 314 packet_type_counter_.first_packet_time_ms = clock_->TimeInMilliseconds(); |
| 318 | 315 |
| 319 switch (rtcp_block.type()) { | 316 switch (rtcp_block.type()) { |
| 320 case rtcp::SenderReport::kPacketType: | 317 case rtcp::SenderReport::kPacketType: |
| 321 HandleSenderReport(rtcp_block, packet_information); | 318 HandleSenderReport(rtcp_block, packet_information); |
| 322 break; | 319 break; |
| 323 case rtcp::ReceiverReport::kPacketType: | 320 case rtcp::ReceiverReport::kPacketType: |
| 324 HandleReceiverReport(rtcp_block, packet_information); | 321 HandleReceiverReport(rtcp_block, packet_information); |
| 325 break; | 322 break; |
| 326 case rtcp::Sdes::kPacketType: | 323 case rtcp::Sdes::kPacketType: |
| 327 HandleSDES(rtcp_block, packet_information); | 324 HandleSdes(rtcp_block, packet_information); |
| 328 break; | 325 break; |
| 329 case rtcp::ExtendedReports::kPacketType: | 326 case rtcp::ExtendedReports::kPacketType: |
| 330 HandleXr(rtcp_block, packet_information); | 327 HandleXr(rtcp_block, packet_information); |
| 331 break; | 328 break; |
| 332 case rtcp::Bye::kPacketType: | 329 case rtcp::Bye::kPacketType: |
| 333 HandleBYE(rtcp_block); | 330 HandleBye(rtcp_block); |
| 334 break; | 331 break; |
| 335 case rtcp::Rtpfb::kPacketType: | 332 case rtcp::Rtpfb::kPacketType: |
| 336 switch (rtcp_block.fmt()) { | 333 switch (rtcp_block.fmt()) { |
| 337 case rtcp::Nack::kFeedbackMessageType: | 334 case rtcp::Nack::kFeedbackMessageType: |
| 338 HandleNACK(rtcp_block, packet_information); | 335 HandleNack(rtcp_block, packet_information); |
| 339 break; | 336 break; |
| 340 case rtcp::Tmmbr::kFeedbackMessageType: | 337 case rtcp::Tmmbr::kFeedbackMessageType: |
| 341 HandleTMMBR(rtcp_block, packet_information); | 338 HandleTmmbr(rtcp_block, packet_information); |
| 342 break; | 339 break; |
| 343 case rtcp::Tmmbn::kFeedbackMessageType: | 340 case rtcp::Tmmbn::kFeedbackMessageType: |
| 344 HandleTMMBN(rtcp_block, packet_information); | 341 HandleTmmbn(rtcp_block, packet_information); |
| 345 break; | 342 break; |
| 346 case rtcp::RapidResyncRequest::kFeedbackMessageType: | 343 case rtcp::RapidResyncRequest::kFeedbackMessageType: |
| 347 HandleSR_REQ(rtcp_block, packet_information); | 344 HandleSrReq(rtcp_block, packet_information); |
| 348 break; | 345 break; |
| 349 case rtcp::TransportFeedback::kFeedbackMessageType: | 346 case rtcp::TransportFeedback::kFeedbackMessageType: |
| 350 HandleTransportFeedback(rtcp_block, packet_information); | 347 HandleTransportFeedback(rtcp_block, packet_information); |
| 351 break; | 348 break; |
| 352 default: | 349 default: |
| 353 ++num_skipped_packets_; | 350 ++num_skipped_packets_; |
| 354 break; | 351 break; |
| 355 } | 352 } |
| 356 break; | 353 break; |
| 357 case rtcp::Psfb::kPacketType: | 354 case rtcp::Psfb::kPacketType: |
| 358 switch (rtcp_block.fmt()) { | 355 switch (rtcp_block.fmt()) { |
| 359 case rtcp::Pli::kFeedbackMessageType: | 356 case rtcp::Pli::kFeedbackMessageType: |
| 360 HandlePLI(rtcp_block, packet_information); | 357 HandlePli(rtcp_block, packet_information); |
| 361 break; | 358 break; |
| 362 case rtcp::Sli::kFeedbackMessageType: | 359 case rtcp::Sli::kFeedbackMessageType: |
| 363 HandleSLI(rtcp_block, packet_information); | 360 HandleSli(rtcp_block, packet_information); |
| 364 break; | 361 break; |
| 365 case rtcp::Rpsi::kFeedbackMessageType: | 362 case rtcp::Rpsi::kFeedbackMessageType: |
| 366 HandleRPSI(rtcp_block, packet_information); | 363 HandleRpsi(rtcp_block, packet_information); |
| 367 break; | 364 break; |
| 368 case rtcp::Fir::kFeedbackMessageType: | 365 case rtcp::Fir::kFeedbackMessageType: |
| 369 HandleFIR(rtcp_block, packet_information); | 366 HandleFir(rtcp_block, packet_information); |
| 370 break; | 367 break; |
| 371 case rtcp::Remb::kFeedbackMessageType: | 368 case rtcp::Remb::kFeedbackMessageType: |
| 372 HandlePsfbApp(rtcp_block, packet_information); | 369 HandlePsfbApp(rtcp_block, packet_information); |
| 373 break; | 370 break; |
| 374 default: | 371 default: |
| 375 ++num_skipped_packets_; | 372 ++num_skipped_packets_; |
| 376 break; | 373 break; |
| 377 } | 374 } |
| 378 break; | 375 break; |
| 379 default: | 376 default: |
| 380 ++num_skipped_packets_; | 377 ++num_skipped_packets_; |
| 381 break; | 378 break; |
| 382 } | 379 } |
| 383 } | 380 } |
| 384 | 381 |
| 385 if (packet_type_counter_observer_ != NULL) { | 382 if (packet_type_counter_observer_) { |
| 386 packet_type_counter_observer_->RtcpPacketTypesCounterUpdated( | 383 packet_type_counter_observer_->RtcpPacketTypesCounterUpdated( |
| 387 main_ssrc_, packet_type_counter_); | 384 main_ssrc_, packet_type_counter_); |
| 388 } | 385 } |
| 389 | 386 |
| 390 int64_t now = _clock->TimeInMilliseconds(); | 387 int64_t now_ms = clock_->TimeInMilliseconds(); |
| 391 if (now - last_skipped_packets_warning_ >= kMaxWarningLogIntervalMs && | 388 if (now_ms - last_skipped_packets_warning_ms_ >= kMaxWarningLogIntervalMs && |
| 392 num_skipped_packets_ > 0) { | 389 num_skipped_packets_ > 0) { |
| 393 last_skipped_packets_warning_ = now; | 390 last_skipped_packets_warning_ms_ = now_ms; |
| 394 LOG(LS_WARNING) << num_skipped_packets_ | 391 LOG(LS_WARNING) << num_skipped_packets_ |
| 395 << " RTCP blocks were skipped due to being malformed or of " | 392 << " RTCP blocks were skipped due to being malformed or of " |
| 396 "unrecognized/unsupported type, during the past " | 393 "unrecognized/unsupported type, during the past " |
| 397 << (kMaxWarningLogIntervalMs / 1000) << " second period."; | 394 << (kMaxWarningLogIntervalMs / 1000) << " second period."; |
| 398 } | 395 } |
| 399 | 396 |
| 400 return true; | 397 return true; |
| 401 } | 398 } |
| 402 | 399 |
| 403 void RTCPReceiver::HandleSenderReport(const CommonHeader& rtcp_block, | 400 void RTCPReceiver::HandleSenderReport(const CommonHeader& rtcp_block, |
| 404 PacketInformation* packet_information) { | 401 PacketInformation* packet_information) { |
| 405 rtcp::SenderReport sender_report; | 402 rtcp::SenderReport sender_report; |
| 406 if (!sender_report.Parse(rtcp_block)) { | 403 if (!sender_report.Parse(rtcp_block)) { |
| 407 ++num_skipped_packets_; | 404 ++num_skipped_packets_; |
| 408 return; | 405 return; |
| 409 } | 406 } |
| 410 | 407 |
| 411 const uint32_t remoteSSRC = sender_report.sender_ssrc(); | 408 const uint32_t remote_ssrc = sender_report.sender_ssrc(); |
| 412 | 409 |
| 413 packet_information->remote_ssrc = remoteSSRC; | 410 packet_information->remote_ssrc = remote_ssrc; |
| 414 | 411 |
| 415 CreateReceiveInformation(remoteSSRC); | 412 CreateReceiveInformation(remote_ssrc); |
| 416 | 413 |
| 417 TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "SR", | 414 TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "SR", |
| 418 "remote_ssrc", remoteSSRC, "ssrc", main_ssrc_); | 415 "remote_ssrc", remote_ssrc, "ssrc", main_ssrc_); |
| 419 | 416 |
| 420 // Have I received RTP packets from this party? | 417 // Have I received RTP packets from this party? |
| 421 if (_remoteSSRC == remoteSSRC) { | 418 if (remote_ssrc_ == remote_ssrc) { |
| 422 // Only signal that we have received a SR when we accept one. | 419 // Only signal that we have received a SR when we accept one. |
| 423 packet_information->packet_type_flags |= kRtcpSr; | 420 packet_information->packet_type_flags |= kRtcpSr; |
| 424 | 421 |
| 425 // Save the NTP time of this report. | 422 // Save the NTP time of this report. |
| 426 _remoteSenderInfo.NTPseconds = sender_report.ntp().seconds(); | 423 remote_sender_info_.NTPseconds = sender_report.ntp().seconds(); |
| 427 _remoteSenderInfo.NTPfraction = sender_report.ntp().fractions(); | 424 remote_sender_info_.NTPfraction = sender_report.ntp().fractions(); |
| 428 _remoteSenderInfo.RTPtimeStamp = sender_report.rtp_timestamp(); | 425 remote_sender_info_.RTPtimeStamp = sender_report.rtp_timestamp(); |
| 429 _remoteSenderInfo.sendPacketCount = sender_report.sender_packet_count(); | 426 remote_sender_info_.sendPacketCount = sender_report.sender_packet_count(); |
| 430 _remoteSenderInfo.sendOctetCount = sender_report.sender_octet_count(); | 427 remote_sender_info_.sendOctetCount = sender_report.sender_octet_count(); |
| 431 | 428 |
| 432 last_received_sr_ntp_.SetCurrent(*_clock); | 429 last_received_sr_ntp_.SetCurrent(*clock_); |
| 433 } else { | 430 } else { |
| 434 // We will only store the send report from one source, but | 431 // We will only store the send report from one source, but |
| 435 // we will store all the receive blocks. | 432 // we will store all the receive blocks. |
| 436 packet_information->packet_type_flags |= kRtcpRr; | 433 packet_information->packet_type_flags |= kRtcpRr; |
| 437 } | 434 } |
| 438 | 435 |
| 439 for (const rtcp::ReportBlock report_block : sender_report.report_blocks()) | 436 for (const rtcp::ReportBlock report_block : sender_report.report_blocks()) |
| 440 HandleReportBlock(report_block, packet_information, remoteSSRC); | 437 HandleReportBlock(report_block, packet_information, remote_ssrc); |
| 441 } | 438 } |
| 442 | 439 |
| 443 void RTCPReceiver::HandleReceiverReport(const CommonHeader& rtcp_block, | 440 void RTCPReceiver::HandleReceiverReport(const CommonHeader& rtcp_block, |
| 444 PacketInformation* packet_information) { | 441 PacketInformation* packet_information) { |
| 445 rtcp::ReceiverReport receiver_report; | 442 rtcp::ReceiverReport receiver_report; |
| 446 if (!receiver_report.Parse(rtcp_block)) { | 443 if (!receiver_report.Parse(rtcp_block)) { |
| 447 ++num_skipped_packets_; | 444 ++num_skipped_packets_; |
| 448 return; | 445 return; |
| 449 } | 446 } |
| 450 | 447 |
| 451 const uint32_t remoteSSRC = receiver_report.sender_ssrc(); | 448 const uint32_t remote_ssrc = receiver_report.sender_ssrc(); |
| 452 | 449 |
| 453 packet_information->remote_ssrc = remoteSSRC; | 450 packet_information->remote_ssrc = remote_ssrc; |
| 454 | 451 |
| 455 CreateReceiveInformation(remoteSSRC); | 452 CreateReceiveInformation(remote_ssrc); |
| 456 | 453 |
| 457 TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "RR", | 454 TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "RR", |
| 458 "remote_ssrc", remoteSSRC, "ssrc", main_ssrc_); | 455 "remote_ssrc", remote_ssrc, "ssrc", main_ssrc_); |
| 459 | 456 |
| 460 packet_information->packet_type_flags |= kRtcpRr; | 457 packet_information->packet_type_flags |= kRtcpRr; |
| 461 | 458 |
| 462 for (const ReportBlock& report_block : receiver_report.report_blocks()) | 459 for (const ReportBlock& report_block : receiver_report.report_blocks()) |
| 463 HandleReportBlock(report_block, packet_information, remoteSSRC); | 460 HandleReportBlock(report_block, packet_information, remote_ssrc); |
| 464 } | 461 } |
| 465 | 462 |
| 466 void RTCPReceiver::HandleReportBlock(const ReportBlock& report_block, | 463 void RTCPReceiver::HandleReportBlock(const ReportBlock& report_block, |
| 467 PacketInformation* packet_information, | 464 PacketInformation* packet_information, |
| 468 uint32_t remote_ssrc) { | 465 uint32_t remote_ssrc) { |
| 469 // This will be called once per report block in the RTCP packet. | 466 // This will be called once per report block in the RTCP packet. |
| 470 // We filter out all report blocks that are not for us. | 467 // We filter out all report blocks that are not for us. |
| 471 // Each packet has max 31 RR blocks. | 468 // Each packet has max 31 RR blocks. |
| 472 // | 469 // |
| 473 // We can calc RTT if we send a send report and get a report block back. | 470 // We can calc RTT if we send a send report and get a report block back. |
| 474 | 471 |
| 475 // |report_block.source_ssrc()| is the SSRC identifier of the source to | 472 // |report_block.source_ssrc()| is the SSRC identifier of the source to |
| 476 // which the information in this reception report block pertains. | 473 // which the information in this reception report block pertains. |
| 477 | 474 |
| 478 // Filter out all report blocks that are not for us. | 475 // Filter out all report blocks that are not for us. |
| 479 if (registered_ssrcs_.count(report_block.source_ssrc()) == 0) | 476 if (registered_ssrcs_.count(report_block.source_ssrc()) == 0) |
| 480 return; | 477 return; |
| 481 | 478 |
| 482 ReportBlockWithRtt* report_block_info = | 479 ReportBlockWithRtt* report_block_info = |
| 483 &received_report_blocks_[report_block.source_ssrc()][remote_ssrc]; | 480 &received_report_blocks_[report_block.source_ssrc()][remote_ssrc]; |
| 484 | 481 |
| 485 _lastReceivedRrMs = _clock->TimeInMilliseconds(); | 482 last_received_rr_ms_ = clock_->TimeInMilliseconds(); |
| 486 report_block_info->report_block.remoteSSRC = remote_ssrc; | 483 report_block_info->report_block.remoteSSRC = remote_ssrc; |
| 487 report_block_info->report_block.sourceSSRC = report_block.source_ssrc(); | 484 report_block_info->report_block.sourceSSRC = report_block.source_ssrc(); |
| 488 report_block_info->report_block.fractionLost = report_block.fraction_lost(); | 485 report_block_info->report_block.fractionLost = report_block.fraction_lost(); |
| 489 report_block_info->report_block.cumulativeLost = | 486 report_block_info->report_block.cumulativeLost = |
| 490 report_block.cumulative_lost(); | 487 report_block.cumulative_lost(); |
| 491 if (report_block.extended_high_seq_num() > | 488 if (report_block.extended_high_seq_num() > |
| 492 report_block_info->report_block.extendedHighSeqNum) { | 489 report_block_info->report_block.extendedHighSeqNum) { |
| 493 // We have successfully delivered new RTP packets to the remote side after | 490 // We have successfully delivered new RTP packets to the remote side after |
| 494 // the last RR was sent from the remote side. | 491 // the last RR was sent from the remote side. |
| 495 _lastIncreasedSequenceNumberMs = _lastReceivedRrMs; | 492 last_increased_sequence_number_ms_ = last_received_rr_ms_; |
| 496 } | 493 } |
| 497 report_block_info->report_block.extendedHighSeqNum = | 494 report_block_info->report_block.extendedHighSeqNum = |
| 498 report_block.extended_high_seq_num(); | 495 report_block.extended_high_seq_num(); |
| 499 report_block_info->report_block.jitter = report_block.jitter(); | 496 report_block_info->report_block.jitter = report_block.jitter(); |
| 500 report_block_info->report_block.delaySinceLastSR = | 497 report_block_info->report_block.delaySinceLastSR = |
| 501 report_block.delay_since_last_sr(); | 498 report_block.delay_since_last_sr(); |
| 502 report_block_info->report_block.lastSR = report_block.last_sr(); | 499 report_block_info->report_block.lastSR = report_block.last_sr(); |
| 503 | 500 |
| 504 int64_t rtt_ms = 0; | 501 int64_t rtt_ms = 0; |
| 505 uint32_t send_time = report_block.last_sr(); | 502 uint32_t send_time_ntp = report_block.last_sr(); |
| 506 // RFC3550, section 6.4.1, LSR field discription states: | 503 // RFC3550, section 6.4.1, LSR field discription states: |
| 507 // If no SR has been received yet, the field is set to zero. | 504 // If no SR has been received yet, the field is set to zero. |
| 508 // Receiver rtp_rtcp module is not expected to calculate rtt using | 505 // Receiver rtp_rtcp module is not expected to calculate rtt using |
| 509 // Sender Reports even if it accidentally can. | 506 // Sender Reports even if it accidentally can. |
| 510 if (!receiver_only_ && send_time != 0) { | 507 if (!receiver_only_ && send_time_ntp != 0) { |
| 511 uint32_t delay = report_block.delay_since_last_sr(); | 508 uint32_t delay_ntp = report_block.delay_since_last_sr(); |
| 512 // Local NTP time. | 509 // Local NTP time. |
| 513 uint32_t receive_time = CompactNtp(NtpTime(*_clock)); | 510 uint32_t receive_time_ntp = CompactNtp(NtpTime(*clock_)); |
| 514 | 511 |
| 515 // RTT in 1/(2^16) seconds. | 512 // RTT in 1/(2^16) seconds. |
| 516 uint32_t rtt_ntp = receive_time - delay - send_time; | 513 uint32_t rtt_ntp = receive_time_ntp - delay_ntp - send_time_ntp; |
| 517 // Convert to 1/1000 seconds (milliseconds). | 514 // Convert to 1/1000 seconds (milliseconds). |
| 518 rtt_ms = CompactNtpRttToMs(rtt_ntp); | 515 rtt_ms = CompactNtpRttToMs(rtt_ntp); |
| 519 if (rtt_ms > report_block_info->max_rtt_ms) | 516 if (rtt_ms > report_block_info->max_rtt_ms) |
| 520 report_block_info->max_rtt_ms = rtt_ms; | 517 report_block_info->max_rtt_ms = rtt_ms; |
| 521 | 518 |
| 522 if (report_block_info->num_rtts == 0 || | 519 if (report_block_info->num_rtts == 0 || |
| 523 rtt_ms < report_block_info->min_rtt_ms) | 520 rtt_ms < report_block_info->min_rtt_ms) |
| 524 report_block_info->min_rtt_ms = rtt_ms; | 521 report_block_info->min_rtt_ms = rtt_ms; |
| 525 | 522 |
| 526 report_block_info->last_rtt_ms = rtt_ms; | 523 report_block_info->last_rtt_ms = rtt_ms; |
| 527 report_block_info->sum_rtt_ms += rtt_ms; | 524 report_block_info->sum_rtt_ms += rtt_ms; |
| 528 ++report_block_info->num_rtts; | 525 ++report_block_info->num_rtts; |
| 529 } | 526 } |
| 530 | 527 |
| 531 TRACE_COUNTER_ID1(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "RR_RTT", | 528 TRACE_COUNTER_ID1(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "RR_RTT", |
| 532 report_block.source_ssrc(), rtt_ms); | 529 report_block.source_ssrc(), rtt_ms); |
| 533 | 530 |
| 534 packet_information->rtt_ms = rtt_ms; | 531 packet_information->rtt_ms = rtt_ms; |
| 535 packet_information->report_blocks.push_back(report_block_info->report_block); | 532 packet_information->report_blocks.push_back(report_block_info->report_block); |
| 536 } | 533 } |
| 537 | 534 |
| 538 void RTCPReceiver::CreateReceiveInformation(uint32_t remote_ssrc) { | 535 void RTCPReceiver::CreateReceiveInformation(uint32_t remote_ssrc) { |
| 539 // Create or find receive information. | 536 // Create or find receive information. |
| 540 ReceiveInformation* receive_info = &received_infos_[remote_ssrc]; | 537 ReceiveInformation* receive_info = &received_infos_[remote_ssrc]; |
| 541 // Update that this remote is alive. | 538 // Update that this remote is alive. |
| 542 receive_info->last_time_received_ms = _clock->TimeInMilliseconds(); | 539 receive_info->last_time_received_ms = clock_->TimeInMilliseconds(); |
| 543 } | 540 } |
| 544 | 541 |
| 545 RTCPReceiver::ReceiveInformation* RTCPReceiver::GetReceiveInformation( | 542 RTCPReceiver::ReceiveInformation* RTCPReceiver::GetReceiveInformation( |
| 546 uint32_t remote_ssrc) { | 543 uint32_t remote_ssrc) { |
| 547 auto it = received_infos_.find(remote_ssrc); | 544 auto it = received_infos_.find(remote_ssrc); |
| 548 if (it == received_infos_.end()) | 545 if (it == received_infos_.end()) |
| 549 return nullptr; | 546 return nullptr; |
| 550 return &it->second; | 547 return &it->second; |
| 551 } | 548 } |
| 552 | 549 |
| 553 bool RTCPReceiver::RtcpRrTimeout(int64_t rtcp_interval_ms) { | 550 bool RTCPReceiver::RtcpRrTimeout(int64_t rtcp_interval_ms) { |
| 554 rtc::CritScope lock(&_criticalSectionRTCPReceiver); | 551 rtc::CritScope lock(&rtcp_receiver_lock_); |
| 555 if (_lastReceivedRrMs == 0) | 552 if (last_received_rr_ms_ == 0) |
| 556 return false; | 553 return false; |
| 557 | 554 |
| 558 int64_t time_out_ms = kRrTimeoutIntervals * rtcp_interval_ms; | 555 int64_t time_out_ms = kRrTimeoutIntervals * rtcp_interval_ms; |
| 559 if (_clock->TimeInMilliseconds() > _lastReceivedRrMs + time_out_ms) { | 556 if (clock_->TimeInMilliseconds() > last_received_rr_ms_ + time_out_ms) { |
| 560 // Reset the timer to only trigger one log. | 557 // Reset the timer to only trigger one log. |
| 561 _lastReceivedRrMs = 0; | 558 last_received_rr_ms_ = 0; |
| 562 return true; | 559 return true; |
| 563 } | 560 } |
| 564 return false; | 561 return false; |
| 565 } | 562 } |
| 566 | 563 |
| 567 bool RTCPReceiver::RtcpRrSequenceNumberTimeout(int64_t rtcp_interval_ms) { | 564 bool RTCPReceiver::RtcpRrSequenceNumberTimeout(int64_t rtcp_interval_ms) { |
| 568 rtc::CritScope lock(&_criticalSectionRTCPReceiver); | 565 rtc::CritScope lock(&rtcp_receiver_lock_); |
| 569 if (_lastIncreasedSequenceNumberMs == 0) | 566 if (last_increased_sequence_number_ms_ == 0) |
| 570 return false; | 567 return false; |
| 571 | 568 |
| 572 int64_t time_out_ms = kRrTimeoutIntervals * rtcp_interval_ms; | 569 int64_t time_out_ms = kRrTimeoutIntervals * rtcp_interval_ms; |
| 573 if (_clock->TimeInMilliseconds() > | 570 if (clock_->TimeInMilliseconds() > |
| 574 _lastIncreasedSequenceNumberMs + time_out_ms) { | 571 last_increased_sequence_number_ms_ + time_out_ms) { |
| 575 // Reset the timer to only trigger one log. | 572 // Reset the timer to only trigger one log. |
| 576 _lastIncreasedSequenceNumberMs = 0; | 573 last_increased_sequence_number_ms_ = 0; |
| 577 return true; | 574 return true; |
| 578 } | 575 } |
| 579 return false; | 576 return false; |
| 580 } | 577 } |
| 581 | 578 |
| 582 bool RTCPReceiver::UpdateRTCPReceiveInformationTimers() { | 579 bool RTCPReceiver::UpdateRTCPReceiveInformationTimers() { |
| 583 rtc::CritScope lock(&_criticalSectionRTCPReceiver); | 580 rtc::CritScope lock(&rtcp_receiver_lock_); |
| 584 | 581 |
| 585 bool update_bounding_set = false; | 582 bool update_bounding_set = false; |
| 586 int64_t now_ms = _clock->TimeInMilliseconds(); | 583 int64_t now_ms = clock_->TimeInMilliseconds(); |
| 587 // Use audio define since we don't know what interval the remote peer use. | 584 // Use audio define since we don't know what interval the remote peer use. |
| 588 int64_t timeouted_ms = now_ms - 5 * RTCP_INTERVAL_AUDIO_MS; | 585 int64_t timeouted_ms = now_ms - 5 * RTCP_INTERVAL_AUDIO_MS; |
| 589 | 586 |
| 590 for (auto receive_info_it = received_infos_.begin(); | 587 for (auto receive_info_it = received_infos_.begin(); |
| 591 receive_info_it != received_infos_.end();) { | 588 receive_info_it != received_infos_.end();) { |
| 592 ReceiveInformation* receive_info = &receive_info_it->second; | 589 ReceiveInformation* receive_info = &receive_info_it->second; |
| 593 if (receive_info->last_time_received_ms > 0) { | 590 if (receive_info->last_time_received_ms > 0) { |
| 594 if (receive_info->last_time_received_ms < timeouted_ms) { | 591 if (receive_info->last_time_received_ms < timeouted_ms) { |
| 595 // No rtcp packet for the last 5 regular intervals, reset limitations. | 592 // No rtcp packet for the last 5 regular intervals, reset limitations. |
| 596 receive_info->tmmbr.clear(); | 593 receive_info->tmmbr.clear(); |
| 597 // Prevent that we call this over and over again. | 594 // Prevent that we call this over and over again. |
| 598 receive_info->last_time_received_ms = 0; | 595 receive_info->last_time_received_ms = 0; |
| 599 // Send new TMMBN to all channels using the default codec. | 596 // Send new TMMBN to all channels using the default codec. |
| 600 update_bounding_set = true; | 597 update_bounding_set = true; |
| 601 } | 598 } |
| 602 ++receive_info_it; | 599 ++receive_info_it; |
| 603 } else if (receive_info->ready_for_delete) { | 600 } else if (receive_info->ready_for_delete) { |
| 604 // When we dont have a last_time_received_ms and the object is marked | 601 // When we dont have a last_time_received_ms and the object is marked |
| 605 // ready_for_delete it's removed from the map. | 602 // ready_for_delete it's removed from the map. |
| 606 receive_info_it = received_infos_.erase(receive_info_it); | 603 receive_info_it = received_infos_.erase(receive_info_it); |
| 607 } else { | 604 } else { |
| 608 ++receive_info_it; | 605 ++receive_info_it; |
| 609 } | 606 } |
| 610 } | 607 } |
| 611 return update_bounding_set; | 608 return update_bounding_set; |
| 612 } | 609 } |
| 613 | 610 |
| 614 std::vector<rtcp::TmmbItem> RTCPReceiver::BoundingSet(bool* tmmbr_owner) { | 611 std::vector<rtcp::TmmbItem> RTCPReceiver::BoundingSet(bool* tmmbr_owner) { |
| 615 rtc::CritScope lock(&_criticalSectionRTCPReceiver); | 612 rtc::CritScope lock(&rtcp_receiver_lock_); |
| 616 ReceiveInformation* receive_info = GetReceiveInformation(_remoteSSRC); | 613 ReceiveInformation* receive_info = GetReceiveInformation(remote_ssrc_); |
| 617 if (!receive_info) | 614 if (!receive_info) |
| 618 return std::vector<rtcp::TmmbItem>(); | 615 return std::vector<rtcp::TmmbItem>(); |
| 619 | 616 |
| 620 *tmmbr_owner = TMMBRHelp::IsOwner(receive_info->tmmbn, main_ssrc_); | 617 *tmmbr_owner = TMMBRHelp::IsOwner(receive_info->tmmbn, main_ssrc_); |
| 621 return receive_info->tmmbn; | 618 return receive_info->tmmbn; |
| 622 } | 619 } |
| 623 | 620 |
| 624 void RTCPReceiver::HandleSDES(const CommonHeader& rtcp_block, | 621 void RTCPReceiver::HandleSdes(const CommonHeader& rtcp_block, |
| 625 PacketInformation* packet_information) { | 622 PacketInformation* packet_information) { |
| 626 rtcp::Sdes sdes; | 623 rtcp::Sdes sdes; |
| 627 if (!sdes.Parse(rtcp_block)) { | 624 if (!sdes.Parse(rtcp_block)) { |
| 628 ++num_skipped_packets_; | 625 ++num_skipped_packets_; |
| 629 return; | 626 return; |
| 630 } | 627 } |
| 631 | 628 |
| 632 for (const rtcp::Sdes::Chunk& chunk : sdes.chunks()) { | 629 for (const rtcp::Sdes::Chunk& chunk : sdes.chunks()) { |
| 633 received_cnames_[chunk.ssrc] = chunk.cname; | 630 received_cnames_[chunk.ssrc] = chunk.cname; |
| 634 { | 631 { |
| 635 rtc::CritScope lock(&feedbacks_lock_); | 632 rtc::CritScope lock(&feedbacks_lock_); |
| 636 if (stats_callback_) | 633 if (stats_callback_) |
| 637 stats_callback_->CNameChanged(chunk.cname.c_str(), chunk.ssrc); | 634 stats_callback_->CNameChanged(chunk.cname.c_str(), chunk.ssrc); |
| 638 } | 635 } |
| 639 } | 636 } |
| 640 packet_information->packet_type_flags |= kRtcpSdes; | 637 packet_information->packet_type_flags |= kRtcpSdes; |
| 641 } | 638 } |
| 642 | 639 |
| 643 void RTCPReceiver::HandleNACK(const CommonHeader& rtcp_block, | 640 void RTCPReceiver::HandleNack(const CommonHeader& rtcp_block, |
| 644 PacketInformation* packet_information) { | 641 PacketInformation* packet_information) { |
| 645 rtcp::Nack nack; | 642 rtcp::Nack nack; |
| 646 if (!nack.Parse(rtcp_block)) { | 643 if (!nack.Parse(rtcp_block)) { |
| 647 ++num_skipped_packets_; | 644 ++num_skipped_packets_; |
| 648 return; | 645 return; |
| 649 } | 646 } |
| 650 | 647 |
| 651 if (receiver_only_ || main_ssrc_ != nack.media_ssrc()) // Not to us. | 648 if (receiver_only_ || main_ssrc_ != nack.media_ssrc()) // Not to us. |
| 652 return; | 649 return; |
| 653 | 650 |
| 654 packet_information->nack_sequence_numbers.insert( | 651 packet_information->nack_sequence_numbers.insert( |
| 655 packet_information->nack_sequence_numbers.end(), | 652 packet_information->nack_sequence_numbers.end(), |
| 656 nack.packet_ids().begin(), nack.packet_ids().end()); | 653 nack.packet_ids().begin(), nack.packet_ids().end()); |
| 657 for (uint16_t packet_id : nack.packet_ids()) | 654 for (uint16_t packet_id : nack.packet_ids()) |
| 658 nack_stats_.ReportRequest(packet_id); | 655 nack_stats_.ReportRequest(packet_id); |
| 659 | 656 |
| 660 if (!nack.packet_ids().empty()) { | 657 if (!nack.packet_ids().empty()) { |
| 661 packet_information->packet_type_flags |= kRtcpNack; | 658 packet_information->packet_type_flags |= kRtcpNack; |
| 662 ++packet_type_counter_.nack_packets; | 659 ++packet_type_counter_.nack_packets; |
| 663 packet_type_counter_.nack_requests = nack_stats_.requests(); | 660 packet_type_counter_.nack_requests = nack_stats_.requests(); |
| 664 packet_type_counter_.unique_nack_requests = nack_stats_.unique_requests(); | 661 packet_type_counter_.unique_nack_requests = nack_stats_.unique_requests(); |
| 665 } | 662 } |
| 666 } | 663 } |
| 667 | 664 |
| 668 void RTCPReceiver::HandleBYE(const CommonHeader& rtcp_block) { | 665 void RTCPReceiver::HandleBye(const CommonHeader& rtcp_block) { |
| 669 rtcp::Bye bye; | 666 rtcp::Bye bye; |
| 670 if (!bye.Parse(rtcp_block)) { | 667 if (!bye.Parse(rtcp_block)) { |
| 671 ++num_skipped_packets_; | 668 ++num_skipped_packets_; |
| 672 return; | 669 return; |
| 673 } | 670 } |
| 674 | 671 |
| 675 // clear our lists | 672 // Clear our lists. |
| 676 for (auto& reports_per_receiver : received_report_blocks_) | 673 for (auto& reports_per_receiver : received_report_blocks_) |
| 677 reports_per_receiver.second.erase(bye.sender_ssrc()); | 674 reports_per_receiver.second.erase(bye.sender_ssrc()); |
| 678 | 675 |
| 679 // We can't delete it due to TMMBR. | 676 // We can't delete it due to TMMBR. |
| 680 ReceiveInformation* receive_info = GetReceiveInformation(bye.sender_ssrc()); | 677 ReceiveInformation* receive_info = GetReceiveInformation(bye.sender_ssrc()); |
| 681 if (receive_info) | 678 if (receive_info) |
| 682 receive_info->ready_for_delete = true; | 679 receive_info->ready_for_delete = true; |
| 683 | 680 |
| 684 received_cnames_.erase(bye.sender_ssrc()); | 681 received_cnames_.erase(bye.sender_ssrc()); |
| 685 xr_rr_rtt_ms_ = 0; | 682 xr_rr_rtt_ms_ = 0; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 696 if (xr.rrtr()) | 693 if (xr.rrtr()) |
| 697 HandleXrReceiveReferenceTime(xr.sender_ssrc(), *xr.rrtr()); | 694 HandleXrReceiveReferenceTime(xr.sender_ssrc(), *xr.rrtr()); |
| 698 | 695 |
| 699 for (const rtcp::ReceiveTimeInfo& time_info : xr.dlrr().sub_blocks()) | 696 for (const rtcp::ReceiveTimeInfo& time_info : xr.dlrr().sub_blocks()) |
| 700 HandleXrDlrrReportBlock(time_info); | 697 HandleXrDlrrReportBlock(time_info); |
| 701 | 698 |
| 702 if (xr.target_bitrate()) | 699 if (xr.target_bitrate()) |
| 703 HandleXrTargetBitrate(*xr.target_bitrate(), packet_information); | 700 HandleXrTargetBitrate(*xr.target_bitrate(), packet_information); |
| 704 } | 701 } |
| 705 | 702 |
| 706 void RTCPReceiver::HandleXrReceiveReferenceTime( | 703 void RTCPReceiver::HandleXrReceiveReferenceTime(uint32_t sender_ssrc, |
| 707 uint32_t sender_ssrc, | 704 const rtcp::Rrtr& rrtr) { |
| 708 const rtcp::Rrtr& rrtr) { | |
| 709 remote_time_info_.ssrc = sender_ssrc; | 705 remote_time_info_.ssrc = sender_ssrc; |
| 710 remote_time_info_.last_rr = CompactNtp(rrtr.ntp()); | 706 remote_time_info_.last_rr = CompactNtp(rrtr.ntp()); |
| 711 last_received_xr_ntp_.SetCurrent(*_clock); | 707 last_received_xr_ntp_.SetCurrent(*clock_); |
| 712 } | 708 } |
| 713 | 709 |
| 714 void RTCPReceiver::HandleXrDlrrReportBlock(const rtcp::ReceiveTimeInfo& rti) { | 710 void RTCPReceiver::HandleXrDlrrReportBlock(const rtcp::ReceiveTimeInfo& rti) { |
| 715 if (registered_ssrcs_.count(rti.ssrc) == 0) // Not to us. | 711 if (registered_ssrcs_.count(rti.ssrc) == 0) // Not to us. |
| 716 return; | 712 return; |
| 717 | 713 |
| 718 // Caller should explicitly enable rtt calculation using extended reports. | 714 // Caller should explicitly enable rtt calculation using extended reports. |
| 719 if (!xr_rrtr_status_) | 715 if (!xr_rrtr_status_) |
| 720 return; | 716 return; |
| 721 | 717 |
| 722 // The send_time and delay_rr fields are in units of 1/2^16 sec. | 718 // The send_time and delay_rr fields are in units of 1/2^16 sec. |
| 723 uint32_t send_time = rti.last_rr; | 719 uint32_t send_time_ntp = rti.last_rr; |
| 724 // RFC3611, section 4.5, LRR field discription states: | 720 // RFC3611, section 4.5, LRR field discription states: |
| 725 // If no such block has been received, the field is set to zero. | 721 // If no such block has been received, the field is set to zero. |
| 726 if (send_time == 0) | 722 if (send_time_ntp == 0) |
| 727 return; | 723 return; |
| 728 | 724 |
| 729 uint32_t delay_rr = rti.delay_since_last_rr; | 725 uint32_t delay_ntp = rti.delay_since_last_rr; |
| 730 uint32_t now = CompactNtp(NtpTime(*_clock)); | 726 uint32_t now_ntp = CompactNtp(NtpTime(*clock_)); |
| 731 | 727 |
| 732 uint32_t rtt_ntp = now - delay_rr - send_time; | 728 uint32_t rtt_ntp = now_ntp - delay_ntp - send_time_ntp; |
| 733 xr_rr_rtt_ms_ = CompactNtpRttToMs(rtt_ntp); | 729 xr_rr_rtt_ms_ = CompactNtpRttToMs(rtt_ntp); |
| 734 } | 730 } |
| 735 | 731 |
| 736 void RTCPReceiver::HandleXrTargetBitrate( | 732 void RTCPReceiver::HandleXrTargetBitrate( |
| 737 const rtcp::TargetBitrate& target_bitrate, | 733 const rtcp::TargetBitrate& target_bitrate, |
| 738 PacketInformation* packet_information) { | 734 PacketInformation* packet_information) { |
| 739 BitrateAllocation bitrate_allocation; | 735 BitrateAllocation bitrate_allocation; |
| 740 for (const auto& item : target_bitrate.GetTargetBitrates()) { | 736 for (const auto& item : target_bitrate.GetTargetBitrates()) { |
| 741 if (item.spatial_layer >= kMaxSpatialLayers || | 737 if (item.spatial_layer >= kMaxSpatialLayers || |
| 742 item.temporal_layer >= kMaxTemporalStreams) { | 738 item.temporal_layer >= kMaxTemporalStreams) { |
| 743 LOG(LS_WARNING) | 739 LOG(LS_WARNING) |
| 744 << "Invalid layer in XR target bitrate pack: spatial index " | 740 << "Invalid layer in XR target bitrate pack: spatial index " |
| 745 << item.spatial_layer << ", temporal index " << item.temporal_layer | 741 << item.spatial_layer << ", temporal index " << item.temporal_layer |
| 746 << ", dropping."; | 742 << ", dropping."; |
| 747 } else { | 743 } else { |
| 748 bitrate_allocation.SetBitrate(item.spatial_layer, item.temporal_layer, | 744 bitrate_allocation.SetBitrate(item.spatial_layer, item.temporal_layer, |
| 749 item.target_bitrate_kbps * 1000); | 745 item.target_bitrate_kbps * 1000); |
| 750 } | 746 } |
| 751 } | 747 } |
| 752 packet_information->target_bitrate_allocation.emplace(bitrate_allocation); | 748 packet_information->target_bitrate_allocation.emplace(bitrate_allocation); |
| 753 } | 749 } |
| 754 | 750 |
| 755 void RTCPReceiver::HandlePLI(const CommonHeader& rtcp_block, | 751 void RTCPReceiver::HandlePli(const CommonHeader& rtcp_block, |
| 756 PacketInformation* packet_information) { | 752 PacketInformation* packet_information) { |
| 757 rtcp::Pli pli; | 753 rtcp::Pli pli; |
| 758 if (!pli.Parse(rtcp_block)) { | 754 if (!pli.Parse(rtcp_block)) { |
| 759 ++num_skipped_packets_; | 755 ++num_skipped_packets_; |
| 760 return; | 756 return; |
| 761 } | 757 } |
| 762 | 758 |
| 763 if (main_ssrc_ == pli.media_ssrc()) { | 759 if (main_ssrc_ == pli.media_ssrc()) { |
| 764 TRACE_EVENT_INSTANT0(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "PLI"); | 760 TRACE_EVENT_INSTANT0(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "PLI"); |
| 765 | 761 |
| 766 ++packet_type_counter_.pli_packets; | 762 ++packet_type_counter_.pli_packets; |
| 767 // Received a signal that we need to send a new key frame. | 763 // Received a signal that we need to send a new key frame. |
| 768 packet_information->packet_type_flags |= kRtcpPli; | 764 packet_information->packet_type_flags |= kRtcpPli; |
| 769 } | 765 } |
| 770 } | 766 } |
| 771 | 767 |
| 772 void RTCPReceiver::HandleTMMBR(const CommonHeader& rtcp_block, | 768 void RTCPReceiver::HandleTmmbr(const CommonHeader& rtcp_block, |
| 773 PacketInformation* packet_information) { | 769 PacketInformation* packet_information) { |
| 774 rtcp::Tmmbr tmmbr; | 770 rtcp::Tmmbr tmmbr; |
| 775 if (!tmmbr.Parse(rtcp_block)) { | 771 if (!tmmbr.Parse(rtcp_block)) { |
| 776 ++num_skipped_packets_; | 772 ++num_skipped_packets_; |
| 777 return; | 773 return; |
| 778 } | 774 } |
| 779 | 775 |
| 780 uint32_t sender_ssrc = tmmbr.sender_ssrc(); | 776 uint32_t sender_ssrc = tmmbr.sender_ssrc(); |
| 781 ReceiveInformation* receive_info = GetReceiveInformation(sender_ssrc); | 777 ReceiveInformation* receive_info = GetReceiveInformation(sender_ssrc); |
| 782 if (!receive_info) // This remote SSRC must be saved before. | 778 if (!receive_info) // This remote SSRC must be saved before. |
| 783 return; | 779 return; |
| 784 | 780 |
| 785 if (tmmbr.media_ssrc()) { | 781 if (tmmbr.media_ssrc()) { |
| 786 // media_ssrc() SHOULD be 0 if same as SenderSSRC. | 782 // media_ssrc() SHOULD be 0 if same as SenderSSRC. |
| 787 // In relay mode this is a valid number. | 783 // In relay mode this is a valid number. |
| 788 sender_ssrc = tmmbr.media_ssrc(); | 784 sender_ssrc = tmmbr.media_ssrc(); |
| 789 } | 785 } |
| 790 | 786 |
| 791 for (const rtcp::TmmbItem& request : tmmbr.requests()) { | 787 for (const rtcp::TmmbItem& request : tmmbr.requests()) { |
| 792 if (main_ssrc_ == request.ssrc() && request.bitrate_bps()) { | 788 if (main_ssrc_ == request.ssrc() && request.bitrate_bps()) { |
| 793 auto* entry = &receive_info->tmmbr[sender_ssrc]; | 789 auto* entry = &receive_info->tmmbr[sender_ssrc]; |
| 794 entry->tmmbr_item = rtcp::TmmbItem(sender_ssrc, | 790 entry->tmmbr_item = rtcp::TmmbItem(sender_ssrc, |
| 795 request.bitrate_bps(), | 791 request.bitrate_bps(), |
| 796 request.packet_overhead()); | 792 request.packet_overhead()); |
| 797 entry->last_updated_ms = _clock->TimeInMilliseconds(); | 793 entry->last_updated_ms = clock_->TimeInMilliseconds(); |
| 798 | 794 |
| 799 packet_information->packet_type_flags |= kRtcpTmmbr; | 795 packet_information->packet_type_flags |= kRtcpTmmbr; |
| 800 } | 796 } |
| 801 } | 797 } |
| 802 } | 798 } |
| 803 | 799 |
| 804 void RTCPReceiver::HandleTMMBN(const CommonHeader& rtcp_block, | 800 void RTCPReceiver::HandleTmmbn(const CommonHeader& rtcp_block, |
| 805 PacketInformation* packet_information) { | 801 PacketInformation* packet_information) { |
| 806 rtcp::Tmmbn tmmbn; | 802 rtcp::Tmmbn tmmbn; |
| 807 if (!tmmbn.Parse(rtcp_block)) { | 803 if (!tmmbn.Parse(rtcp_block)) { |
| 808 ++num_skipped_packets_; | 804 ++num_skipped_packets_; |
| 809 return; | 805 return; |
| 810 } | 806 } |
| 811 | 807 |
| 812 ReceiveInformation* receive_info = GetReceiveInformation(tmmbn.sender_ssrc()); | 808 ReceiveInformation* receive_info = GetReceiveInformation(tmmbn.sender_ssrc()); |
| 813 if (!receive_info) // This remote SSRC must be saved before. | 809 if (!receive_info) // This remote SSRC must be saved before. |
| 814 return; | 810 return; |
| 815 | 811 |
| 816 packet_information->packet_type_flags |= kRtcpTmmbn; | 812 packet_information->packet_type_flags |= kRtcpTmmbn; |
| 817 | 813 |
| 818 for (const auto& item : tmmbn.items()) | 814 for (const auto& item : tmmbn.items()) |
| 819 receive_info->tmmbn.push_back(item); | 815 receive_info->tmmbn.push_back(item); |
| 820 } | 816 } |
| 821 | 817 |
| 822 void RTCPReceiver::HandleSR_REQ(const CommonHeader& rtcp_block, | 818 void RTCPReceiver::HandleSrReq(const CommonHeader& rtcp_block, |
| 823 PacketInformation* packet_information) { | 819 PacketInformation* packet_information) { |
| 824 rtcp::RapidResyncRequest sr_req; | 820 rtcp::RapidResyncRequest sr_req; |
| 825 if (!sr_req.Parse(rtcp_block)) { | 821 if (!sr_req.Parse(rtcp_block)) { |
| 826 ++num_skipped_packets_; | 822 ++num_skipped_packets_; |
| 827 return; | 823 return; |
| 828 } | 824 } |
| 829 | 825 |
| 830 packet_information->packet_type_flags |= kRtcpSrReq; | 826 packet_information->packet_type_flags |= kRtcpSrReq; |
| 831 } | 827 } |
| 832 | 828 |
| 833 void RTCPReceiver::HandleSLI(const CommonHeader& rtcp_block, | 829 void RTCPReceiver::HandleSli(const CommonHeader& rtcp_block, |
| 834 PacketInformation* packet_information) { | 830 PacketInformation* packet_information) { |
| 835 rtcp::Sli sli; | 831 rtcp::Sli sli; |
| 836 if (!sli.Parse(rtcp_block)) { | 832 if (!sli.Parse(rtcp_block)) { |
| 837 ++num_skipped_packets_; | 833 ++num_skipped_packets_; |
| 838 return; | 834 return; |
| 839 } | 835 } |
| 840 | 836 |
| 841 for (const rtcp::Sli::Macroblocks& item : sli.macroblocks()) { | 837 for (const rtcp::Sli::Macroblocks& item : sli.macroblocks()) { |
| 842 // In theory there could be multiple slices lost. | 838 // In theory there could be multiple slices lost. |
| 843 // Received signal that we need to refresh a slice. | 839 // Received signal that we need to refresh a slice. |
| 844 packet_information->packet_type_flags |= kRtcpSli; | 840 packet_information->packet_type_flags |= kRtcpSli; |
| 845 packet_information->sli_picture_id = item.picture_id(); | 841 packet_information->sli_picture_id = item.picture_id(); |
| 846 } | 842 } |
| 847 } | 843 } |
| 848 | 844 |
| 849 void RTCPReceiver::HandleRPSI(const CommonHeader& rtcp_block, | 845 void RTCPReceiver::HandleRpsi(const CommonHeader& rtcp_block, |
| 850 PacketInformation* packet_information) { | 846 PacketInformation* packet_information) { |
| 851 rtcp::Rpsi rpsi; | 847 rtcp::Rpsi rpsi; |
| 852 if (!rpsi.Parse(rtcp_block)) { | 848 if (!rpsi.Parse(rtcp_block)) { |
| 853 ++num_skipped_packets_; | 849 ++num_skipped_packets_; |
| 854 return; | 850 return; |
| 855 } | 851 } |
| 856 | 852 |
| 857 // Received signal that we have a confirmed reference picture. | 853 // Received signal that we have a confirmed reference picture. |
| 858 packet_information->packet_type_flags |= kRtcpRpsi; | 854 packet_information->packet_type_flags |= kRtcpRpsi; |
| 859 packet_information->rpsi_picture_id = rpsi.picture_id(); | 855 packet_information->rpsi_picture_id = rpsi.picture_id(); |
| 860 } | 856 } |
| 861 | 857 |
| 862 void RTCPReceiver::HandlePsfbApp(const CommonHeader& rtcp_block, | 858 void RTCPReceiver::HandlePsfbApp(const CommonHeader& rtcp_block, |
| 863 PacketInformation* packet_information) { | 859 PacketInformation* packet_information) { |
| 864 rtcp::Remb remb; | 860 rtcp::Remb remb; |
| 865 if (remb.Parse(rtcp_block)) { | 861 if (remb.Parse(rtcp_block)) { |
| 866 packet_information->packet_type_flags |= kRtcpRemb; | 862 packet_information->packet_type_flags |= kRtcpRemb; |
| 867 packet_information->receiver_estimated_max_bitrate_bps = remb.bitrate_bps(); | 863 packet_information->receiver_estimated_max_bitrate_bps = remb.bitrate_bps(); |
| 868 return; | 864 return; |
| 869 } | 865 } |
| 870 | 866 |
| 871 ++num_skipped_packets_; | 867 ++num_skipped_packets_; |
| 872 } | 868 } |
| 873 | 869 |
| 874 void RTCPReceiver::HandleFIR(const CommonHeader& rtcp_block, | 870 void RTCPReceiver::HandleFir(const CommonHeader& rtcp_block, |
| 875 PacketInformation* packet_information) { | 871 PacketInformation* packet_information) { |
| 876 rtcp::Fir fir; | 872 rtcp::Fir fir; |
| 877 if (!fir.Parse(rtcp_block)) { | 873 if (!fir.Parse(rtcp_block)) { |
| 878 ++num_skipped_packets_; | 874 ++num_skipped_packets_; |
| 879 return; | 875 return; |
| 880 } | 876 } |
| 881 | 877 |
| 882 ReceiveInformation* receive_info = GetReceiveInformation(fir.sender_ssrc()); | 878 ReceiveInformation* receive_info = GetReceiveInformation(fir.sender_ssrc()); |
| 883 | 879 |
| 884 for (const rtcp::Fir::Request& fir_request : fir.requests()) { | 880 for (const rtcp::Fir::Request& fir_request : fir.requests()) { |
| 885 // Is it our sender that is requested to generate a new keyframe | 881 // Is it our sender that is requested to generate a new keyframe. |
| 886 if (main_ssrc_ != fir_request.ssrc) | 882 if (main_ssrc_ != fir_request.ssrc) |
| 887 continue; | 883 continue; |
| 888 | 884 |
| 889 ++packet_type_counter_.fir_packets; | 885 ++packet_type_counter_.fir_packets; |
| 890 | 886 |
| 891 if (receive_info) { | 887 if (receive_info) { |
| 892 // Check if we have reported this FIRSequenceNumber before. | 888 // Check if we have reported this FIRSequenceNumber before. |
| 893 if (fir_request.seq_nr == receive_info->last_fir_sequence_number) | 889 if (fir_request.seq_nr == receive_info->last_fir_sequence_number) |
| 894 continue; | 890 continue; |
| 895 | 891 |
| 896 int64_t now_ms = _clock->TimeInMilliseconds(); | 892 int64_t now_ms = clock_->TimeInMilliseconds(); |
| 897 // Sanity: don't go crazy with the callbacks. | 893 // Sanity: don't go crazy with the callbacks. |
| 898 if (now_ms - receive_info->last_fir_request_ms < RTCP_MIN_FRAME_LENGTH_MS) | 894 if (now_ms - receive_info->last_fir_request_ms < RTCP_MIN_FRAME_LENGTH_MS) |
| 899 continue; | 895 continue; |
| 900 | 896 |
| 901 receive_info->last_fir_request_ms = now_ms; | 897 receive_info->last_fir_request_ms = now_ms; |
| 902 receive_info->last_fir_sequence_number = fir_request.seq_nr; | 898 receive_info->last_fir_sequence_number = fir_request.seq_nr; |
| 903 } | 899 } |
| 904 // Received signal that we need to send a new key frame. | 900 // Received signal that we need to send a new key frame. |
| 905 packet_information->packet_type_flags |= kRtcpFir; | 901 packet_information->packet_type_flags |= kRtcpFir; |
| 906 } | 902 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 926 TMMBRHelp::FindBoundingSet(TmmbrReceived()); | 922 TMMBRHelp::FindBoundingSet(TmmbrReceived()); |
| 927 | 923 |
| 928 if (!bounding.empty() && rtcp_bandwidth_observer_) { | 924 if (!bounding.empty() && rtcp_bandwidth_observer_) { |
| 929 // We have a new bandwidth estimate on this channel. | 925 // We have a new bandwidth estimate on this channel. |
| 930 uint64_t bitrate_bps = TMMBRHelp::CalcMinBitrateBps(bounding); | 926 uint64_t bitrate_bps = TMMBRHelp::CalcMinBitrateBps(bounding); |
| 931 if (bitrate_bps <= std::numeric_limits<uint32_t>::max()) | 927 if (bitrate_bps <= std::numeric_limits<uint32_t>::max()) |
| 932 rtcp_bandwidth_observer_->OnReceivedEstimatedBitrate(bitrate_bps); | 928 rtcp_bandwidth_observer_->OnReceivedEstimatedBitrate(bitrate_bps); |
| 933 } | 929 } |
| 934 | 930 |
| 935 // Set bounding set: inform remote clients about the new bandwidth. | 931 // Set bounding set: inform remote clients about the new bandwidth. |
| 936 _rtpRtcp.SetTmmbn(std::move(bounding)); | 932 rtp_rtcp_->SetTmmbn(std::move(bounding)); |
| 937 } | 933 } |
| 938 | 934 |
| 939 void RTCPReceiver::RegisterRtcpStatisticsCallback( | 935 void RTCPReceiver::RegisterRtcpStatisticsCallback( |
| 940 RtcpStatisticsCallback* callback) { | 936 RtcpStatisticsCallback* callback) { |
| 941 rtc::CritScope cs(&feedbacks_lock_); | 937 rtc::CritScope cs(&feedbacks_lock_); |
| 942 stats_callback_ = callback; | 938 stats_callback_ = callback; |
| 943 } | 939 } |
| 944 | 940 |
| 945 RtcpStatisticsCallback* RTCPReceiver::GetRtcpStatisticsCallback() { | 941 RtcpStatisticsCallback* RTCPReceiver::GetRtcpStatisticsCallback() { |
| 946 rtc::CritScope cs(&feedbacks_lock_); | 942 rtc::CritScope cs(&feedbacks_lock_); |
| 947 return stats_callback_; | 943 return stats_callback_; |
| 948 } | 944 } |
| 949 | 945 |
| 950 // Holding no Critical section | 946 // Holding no Critical section. |
| 951 void RTCPReceiver::TriggerCallbacksFromRTCPPacket( | 947 void RTCPReceiver::TriggerCallbacksFromRtcpPacket( |
| 952 const PacketInformation& packet_information) { | 948 const PacketInformation& packet_information) { |
| 953 // Process TMMBR and REMB first to avoid multiple callbacks | 949 // Process TMMBR and REMB first to avoid multiple callbacks |
| 954 // to OnNetworkChanged. | 950 // to OnNetworkChanged. |
| 955 if (packet_information.packet_type_flags & kRtcpTmmbr) { | 951 if (packet_information.packet_type_flags & kRtcpTmmbr) { |
| 956 // Might trigger a OnReceivedBandwidthEstimateUpdate. | 952 // Might trigger a OnReceivedBandwidthEstimateUpdate. |
| 957 UpdateTmmbr(); | 953 UpdateTmmbr(); |
| 958 } | 954 } |
| 959 uint32_t local_ssrc; | 955 uint32_t local_ssrc; |
| 960 std::set<uint32_t> registered_ssrcs; | 956 std::set<uint32_t> registered_ssrcs; |
| 961 { | 957 { |
| 962 // We don't want to hold this critsect when triggering the callbacks below. | 958 // We don't want to hold this critsect when triggering the callbacks below. |
| 963 rtc::CritScope lock(&_criticalSectionRTCPReceiver); | 959 rtc::CritScope lock(&rtcp_receiver_lock_); |
| 964 local_ssrc = main_ssrc_; | 960 local_ssrc = main_ssrc_; |
| 965 registered_ssrcs = registered_ssrcs_; | 961 registered_ssrcs = registered_ssrcs_; |
| 966 } | 962 } |
| 967 if (!receiver_only_ && (packet_information.packet_type_flags & kRtcpSrReq)) { | 963 if (!receiver_only_ && (packet_information.packet_type_flags & kRtcpSrReq)) { |
| 968 _rtpRtcp.OnRequestSendReport(); | 964 rtp_rtcp_->OnRequestSendReport(); |
| 969 } | 965 } |
| 970 if (!receiver_only_ && (packet_information.packet_type_flags & kRtcpNack)) { | 966 if (!receiver_only_ && (packet_information.packet_type_flags & kRtcpNack)) { |
| 971 if (!packet_information.nack_sequence_numbers.empty()) { | 967 if (!packet_information.nack_sequence_numbers.empty()) { |
| 972 LOG(LS_VERBOSE) << "Incoming NACK length: " | 968 LOG(LS_VERBOSE) << "Incoming NACK length: " |
| 973 << packet_information.nack_sequence_numbers.size(); | 969 << packet_information.nack_sequence_numbers.size(); |
| 974 _rtpRtcp.OnReceivedNack(packet_information.nack_sequence_numbers); | 970 rtp_rtcp_->OnReceivedNack(packet_information.nack_sequence_numbers); |
| 975 } | 971 } |
| 976 } | 972 } |
| 977 | 973 |
| 978 // We need feedback that we have received a report block(s) so that we | 974 // We need feedback that we have received a report block(s) so that we |
| 979 // can generate a new packet in a conference relay scenario, one received | 975 // can generate a new packet in a conference relay scenario, one received |
| 980 // report can generate several RTCP packets, based on number relayed/mixed | 976 // report can generate several RTCP packets, based on number relayed/mixed |
| 981 // a send report block should go out to all receivers. | 977 // a send report block should go out to all receivers. |
| 982 if (rtcp_intra_frame_observer_) { | 978 if (rtcp_intra_frame_observer_) { |
| 983 RTC_DCHECK(!receiver_only_); | 979 RTC_DCHECK(!receiver_only_); |
| 984 if ((packet_information.packet_type_flags & kRtcpPli) || | 980 if ((packet_information.packet_type_flags & kRtcpPli) || |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1004 if (rtcp_bandwidth_observer_) { | 1000 if (rtcp_bandwidth_observer_) { |
| 1005 RTC_DCHECK(!receiver_only_); | 1001 RTC_DCHECK(!receiver_only_); |
| 1006 if (packet_information.packet_type_flags & kRtcpRemb) { | 1002 if (packet_information.packet_type_flags & kRtcpRemb) { |
| 1007 LOG(LS_VERBOSE) << "Incoming REMB: " | 1003 LOG(LS_VERBOSE) << "Incoming REMB: " |
| 1008 << packet_information.receiver_estimated_max_bitrate_bps; | 1004 << packet_information.receiver_estimated_max_bitrate_bps; |
| 1009 rtcp_bandwidth_observer_->OnReceivedEstimatedBitrate( | 1005 rtcp_bandwidth_observer_->OnReceivedEstimatedBitrate( |
| 1010 packet_information.receiver_estimated_max_bitrate_bps); | 1006 packet_information.receiver_estimated_max_bitrate_bps); |
| 1011 } | 1007 } |
| 1012 if ((packet_information.packet_type_flags & kRtcpSr) || | 1008 if ((packet_information.packet_type_flags & kRtcpSr) || |
| 1013 (packet_information.packet_type_flags & kRtcpRr)) { | 1009 (packet_information.packet_type_flags & kRtcpRr)) { |
| 1014 int64_t now = _clock->TimeInMilliseconds(); | 1010 int64_t now_ms = clock_->TimeInMilliseconds(); |
| 1015 rtcp_bandwidth_observer_->OnReceivedRtcpReceiverReport( | 1011 rtcp_bandwidth_observer_->OnReceivedRtcpReceiverReport( |
| 1016 packet_information.report_blocks, packet_information.rtt_ms, now); | 1012 packet_information.report_blocks, packet_information.rtt_ms, now_ms); |
| 1017 } | 1013 } |
| 1018 } | 1014 } |
| 1019 if ((packet_information.packet_type_flags & kRtcpSr) || | 1015 if ((packet_information.packet_type_flags & kRtcpSr) || |
| 1020 (packet_information.packet_type_flags & kRtcpRr)) { | 1016 (packet_information.packet_type_flags & kRtcpRr)) { |
| 1021 _rtpRtcp.OnReceivedRtcpReportBlocks(packet_information.report_blocks); | 1017 rtp_rtcp_->OnReceivedRtcpReportBlocks(packet_information.report_blocks); |
| 1022 } | 1018 } |
| 1023 | 1019 |
| 1024 if (transport_feedback_observer_ && | 1020 if (transport_feedback_observer_ && |
| 1025 (packet_information.packet_type_flags & kRtcpTransportFeedback)) { | 1021 (packet_information.packet_type_flags & kRtcpTransportFeedback)) { |
| 1026 uint32_t media_source_ssrc = | 1022 uint32_t media_source_ssrc = |
| 1027 packet_information.transport_feedback->media_ssrc(); | 1023 packet_information.transport_feedback->media_ssrc(); |
| 1028 if (media_source_ssrc == local_ssrc || | 1024 if (media_source_ssrc == local_ssrc || |
| 1029 registered_ssrcs.find(media_source_ssrc) != registered_ssrcs.end()) { | 1025 registered_ssrcs.find(media_source_ssrc) != registered_ssrcs.end()) { |
| 1030 transport_feedback_observer_->OnTransportFeedback( | 1026 transport_feedback_observer_->OnTransportFeedback( |
| 1031 *packet_information.transport_feedback); | 1027 *packet_information.transport_feedback); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1051 stats_callback_->StatisticsUpdated(stats, report_block.sourceSSRC); | 1047 stats_callback_->StatisticsUpdated(stats, report_block.sourceSSRC); |
| 1052 } | 1048 } |
| 1053 } | 1049 } |
| 1054 } | 1050 } |
| 1055 } | 1051 } |
| 1056 | 1052 |
| 1057 int32_t RTCPReceiver::CNAME(uint32_t remoteSSRC, | 1053 int32_t RTCPReceiver::CNAME(uint32_t remoteSSRC, |
| 1058 char cName[RTCP_CNAME_SIZE]) const { | 1054 char cName[RTCP_CNAME_SIZE]) const { |
| 1059 RTC_DCHECK(cName); | 1055 RTC_DCHECK(cName); |
| 1060 | 1056 |
| 1061 rtc::CritScope lock(&_criticalSectionRTCPReceiver); | 1057 rtc::CritScope lock(&rtcp_receiver_lock_); |
| 1062 auto received_cname_it = received_cnames_.find(remoteSSRC); | 1058 auto received_cname_it = received_cnames_.find(remoteSSRC); |
| 1063 if (received_cname_it == received_cnames_.end()) | 1059 if (received_cname_it == received_cnames_.end()) |
| 1064 return -1; | 1060 return -1; |
| 1065 | 1061 |
| 1066 size_t length = received_cname_it->second.copy(cName, RTCP_CNAME_SIZE - 1); | 1062 size_t length = received_cname_it->second.copy(cName, RTCP_CNAME_SIZE - 1); |
| 1067 cName[length] = 0; | 1063 cName[length] = 0; |
| 1068 return 0; | 1064 return 0; |
| 1069 } | 1065 } |
| 1070 | 1066 |
| 1071 std::vector<rtcp::TmmbItem> RTCPReceiver::TmmbrReceived() { | 1067 std::vector<rtcp::TmmbItem> RTCPReceiver::TmmbrReceived() { |
| 1072 rtc::CritScope lock(&_criticalSectionRTCPReceiver); | 1068 rtc::CritScope lock(&rtcp_receiver_lock_); |
| 1073 std::vector<rtcp::TmmbItem> candidates; | 1069 std::vector<rtcp::TmmbItem> candidates; |
| 1074 | 1070 |
| 1075 int64_t now_ms = _clock->TimeInMilliseconds(); | 1071 int64_t now_ms = clock_->TimeInMilliseconds(); |
| 1076 // Use audio define since we don't know what interval the remote peer use. | 1072 // Use audio define since we don't know what interval the remote peer use. |
| 1077 int64_t timeouted_ms = now_ms - 5 * RTCP_INTERVAL_AUDIO_MS; | 1073 int64_t timeouted_ms = now_ms - 5 * RTCP_INTERVAL_AUDIO_MS; |
| 1078 | 1074 |
| 1079 for (auto& kv : received_infos_) { | 1075 for (auto& kv : received_infos_) { |
| 1080 for (auto it = kv.second.tmmbr.begin(); it != kv.second.tmmbr.end();) { | 1076 for (auto it = kv.second.tmmbr.begin(); it != kv.second.tmmbr.end();) { |
| 1081 if (it->second.last_updated_ms < timeouted_ms) { | 1077 if (it->second.last_updated_ms < timeouted_ms) { |
| 1082 // Erase timeout entries. | 1078 // Erase timeout entries. |
| 1083 it = kv.second.tmmbr.erase(it); | 1079 it = kv.second.tmmbr.erase(it); |
| 1084 } else { | 1080 } else { |
| 1085 candidates.push_back(it->second.tmmbr_item); | 1081 candidates.push_back(it->second.tmmbr_item); |
| 1086 ++it; | 1082 ++it; |
| 1087 } | 1083 } |
| 1088 } | 1084 } |
| 1089 } | 1085 } |
| 1090 return candidates; | 1086 return candidates; |
| 1091 } | 1087 } |
| 1092 | 1088 |
| 1093 } // namespace webrtc | 1089 } // namespace webrtc |
| OLD | NEW |