| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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/receive_statistics_impl.h" | 11 #include "webrtc/modules/rtp_rtcp/source/receive_statistics_impl.h" |
| 12 | 12 |
| 13 #include <math.h> | 13 #include <math.h> |
| 14 | 14 |
| 15 #include "webrtc/base/scoped_ptr.h" | |
| 16 #include "webrtc/modules/rtp_rtcp/source/bitrate.h" | 15 #include "webrtc/modules/rtp_rtcp/source/bitrate.h" |
| 17 #include "webrtc/modules/rtp_rtcp/source/time_util.h" | 16 #include "webrtc/modules/rtp_rtcp/source/time_util.h" |
| 18 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | |
| 19 | 17 |
| 20 namespace webrtc { | 18 namespace webrtc { |
| 21 | 19 |
| 22 const int64_t kStatisticsTimeoutMs = 8000; | 20 const int64_t kStatisticsTimeoutMs = 8000; |
| 23 const int64_t kStatisticsProcessIntervalMs = 1000; | 21 const int64_t kStatisticsProcessIntervalMs = 1000; |
| 24 | 22 |
| 25 StreamStatistician::~StreamStatistician() {} | 23 StreamStatistician::~StreamStatistician() {} |
| 26 | 24 |
| 27 StreamStatisticianImpl::StreamStatisticianImpl( | 25 StreamStatisticianImpl::StreamStatisticianImpl( |
| 28 Clock* clock, | 26 Clock* clock, |
| 29 RtcpStatisticsCallback* rtcp_callback, | 27 RtcpStatisticsCallback* rtcp_callback, |
| 30 StreamDataCountersCallback* rtp_callback) | 28 StreamDataCountersCallback* rtp_callback) |
| 31 : clock_(clock), | 29 : clock_(clock), |
| 32 stream_lock_(CriticalSectionWrapper::CreateCriticalSection()), | |
| 33 incoming_bitrate_(clock, NULL), | 30 incoming_bitrate_(clock, NULL), |
| 34 ssrc_(0), | 31 ssrc_(0), |
| 35 max_reordering_threshold_(kDefaultMaxReorderingThreshold), | 32 max_reordering_threshold_(kDefaultMaxReorderingThreshold), |
| 36 jitter_q4_(0), | 33 jitter_q4_(0), |
| 37 cumulative_loss_(0), | 34 cumulative_loss_(0), |
| 38 jitter_q4_transmission_time_offset_(0), | 35 jitter_q4_transmission_time_offset_(0), |
| 39 last_receive_time_ms_(0), | 36 last_receive_time_ms_(0), |
| 40 last_received_timestamp_(0), | 37 last_received_timestamp_(0), |
| 41 last_received_transmission_time_offset_(0), | 38 last_received_transmission_time_offset_(0), |
| 42 received_seq_first_(0), | 39 received_seq_first_(0), |
| 43 received_seq_max_(0), | 40 received_seq_max_(0), |
| 44 received_seq_wraps_(0), | 41 received_seq_wraps_(0), |
| 45 received_packet_overhead_(12), | 42 received_packet_overhead_(12), |
| 46 last_report_inorder_packets_(0), | 43 last_report_inorder_packets_(0), |
| 47 last_report_old_packets_(0), | 44 last_report_old_packets_(0), |
| 48 last_report_seq_max_(0), | 45 last_report_seq_max_(0), |
| 49 rtcp_callback_(rtcp_callback), | 46 rtcp_callback_(rtcp_callback), |
| 50 rtp_callback_(rtp_callback) {} | 47 rtp_callback_(rtp_callback) {} |
| 51 | 48 |
| 52 void StreamStatisticianImpl::IncomingPacket(const RTPHeader& header, | 49 void StreamStatisticianImpl::IncomingPacket(const RTPHeader& header, |
| 53 size_t packet_length, | 50 size_t packet_length, |
| 54 bool retransmitted) { | 51 bool retransmitted) { |
| 55 UpdateCounters(header, packet_length, retransmitted); | 52 UpdateCounters(header, packet_length, retransmitted); |
| 56 NotifyRtpCallback(); | 53 NotifyRtpCallback(); |
| 57 } | 54 } |
| 58 | 55 |
| 59 void StreamStatisticianImpl::UpdateCounters(const RTPHeader& header, | 56 void StreamStatisticianImpl::UpdateCounters(const RTPHeader& header, |
| 60 size_t packet_length, | 57 size_t packet_length, |
| 61 bool retransmitted) { | 58 bool retransmitted) { |
| 62 CriticalSectionScoped cs(stream_lock_.get()); | 59 rtc::CritScope cs(&stream_lock_); |
| 63 bool in_order = InOrderPacketInternal(header.sequenceNumber); | 60 bool in_order = InOrderPacketInternal(header.sequenceNumber); |
| 64 ssrc_ = header.ssrc; | 61 ssrc_ = header.ssrc; |
| 65 incoming_bitrate_.Update(packet_length); | 62 incoming_bitrate_.Update(packet_length); |
| 66 receive_counters_.transmitted.AddPacket(packet_length, header); | 63 receive_counters_.transmitted.AddPacket(packet_length, header); |
| 67 if (!in_order && retransmitted) { | 64 if (!in_order && retransmitted) { |
| 68 receive_counters_.retransmitted.AddPacket(packet_length, header); | 65 receive_counters_.retransmitted.AddPacket(packet_length, header); |
| 69 } | 66 } |
| 70 | 67 |
| 71 if (receive_counters_.transmitted.packets == 1) { | 68 if (receive_counters_.transmitted.packets == 1) { |
| 72 received_seq_first_ = header.sequenceNumber; | 69 received_seq_first_ = header.sequenceNumber; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 (time_diff_samples_ext << 4) - jitter_q4_transmission_time_offset_; | 140 (time_diff_samples_ext << 4) - jitter_q4_transmission_time_offset_; |
| 144 jitter_q4_transmission_time_offset_ += | 141 jitter_q4_transmission_time_offset_ += |
| 145 ((jitter_diffQ4TransmissionTimeOffset + 8) >> 4); | 142 ((jitter_diffQ4TransmissionTimeOffset + 8) >> 4); |
| 146 } | 143 } |
| 147 } | 144 } |
| 148 | 145 |
| 149 void StreamStatisticianImpl::NotifyRtpCallback() { | 146 void StreamStatisticianImpl::NotifyRtpCallback() { |
| 150 StreamDataCounters data; | 147 StreamDataCounters data; |
| 151 uint32_t ssrc; | 148 uint32_t ssrc; |
| 152 { | 149 { |
| 153 CriticalSectionScoped cs(stream_lock_.get()); | 150 rtc::CritScope cs(&stream_lock_); |
| 154 data = receive_counters_; | 151 data = receive_counters_; |
| 155 ssrc = ssrc_; | 152 ssrc = ssrc_; |
| 156 } | 153 } |
| 157 rtp_callback_->DataCountersUpdated(data, ssrc); | 154 rtp_callback_->DataCountersUpdated(data, ssrc); |
| 158 } | 155 } |
| 159 | 156 |
| 160 void StreamStatisticianImpl::NotifyRtcpCallback() { | 157 void StreamStatisticianImpl::NotifyRtcpCallback() { |
| 161 RtcpStatistics data; | 158 RtcpStatistics data; |
| 162 uint32_t ssrc; | 159 uint32_t ssrc; |
| 163 { | 160 { |
| 164 CriticalSectionScoped cs(stream_lock_.get()); | 161 rtc::CritScope cs(&stream_lock_); |
| 165 data = last_reported_statistics_; | 162 data = last_reported_statistics_; |
| 166 ssrc = ssrc_; | 163 ssrc = ssrc_; |
| 167 } | 164 } |
| 168 rtcp_callback_->StatisticsUpdated(data, ssrc); | 165 rtcp_callback_->StatisticsUpdated(data, ssrc); |
| 169 } | 166 } |
| 170 | 167 |
| 171 void StreamStatisticianImpl::FecPacketReceived(const RTPHeader& header, | 168 void StreamStatisticianImpl::FecPacketReceived(const RTPHeader& header, |
| 172 size_t packet_length) { | 169 size_t packet_length) { |
| 173 { | 170 { |
| 174 CriticalSectionScoped cs(stream_lock_.get()); | 171 rtc::CritScope cs(&stream_lock_); |
| 175 receive_counters_.fec.AddPacket(packet_length, header); | 172 receive_counters_.fec.AddPacket(packet_length, header); |
| 176 } | 173 } |
| 177 NotifyRtpCallback(); | 174 NotifyRtpCallback(); |
| 178 } | 175 } |
| 179 | 176 |
| 180 void StreamStatisticianImpl::SetMaxReorderingThreshold( | 177 void StreamStatisticianImpl::SetMaxReorderingThreshold( |
| 181 int max_reordering_threshold) { | 178 int max_reordering_threshold) { |
| 182 CriticalSectionScoped cs(stream_lock_.get()); | 179 rtc::CritScope cs(&stream_lock_); |
| 183 max_reordering_threshold_ = max_reordering_threshold; | 180 max_reordering_threshold_ = max_reordering_threshold; |
| 184 } | 181 } |
| 185 | 182 |
| 186 bool StreamStatisticianImpl::GetStatistics(RtcpStatistics* statistics, | 183 bool StreamStatisticianImpl::GetStatistics(RtcpStatistics* statistics, |
| 187 bool reset) { | 184 bool reset) { |
| 188 { | 185 { |
| 189 CriticalSectionScoped cs(stream_lock_.get()); | 186 rtc::CritScope cs(&stream_lock_); |
| 190 if (received_seq_first_ == 0 && | 187 if (received_seq_first_ == 0 && |
| 191 receive_counters_.transmitted.payload_bytes == 0) { | 188 receive_counters_.transmitted.payload_bytes == 0) { |
| 192 // We have not received anything. | 189 // We have not received anything. |
| 193 return false; | 190 return false; |
| 194 } | 191 } |
| 195 | 192 |
| 196 if (!reset) { | 193 if (!reset) { |
| 197 if (last_report_inorder_packets_ == 0) { | 194 if (last_report_inorder_packets_ == 0) { |
| 198 // No report. | 195 // No report. |
| 199 return false; | 196 return false; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 receive_counters_.transmitted.packets - | 272 receive_counters_.transmitted.packets - |
| 276 receive_counters_.retransmitted.packets; | 273 receive_counters_.retransmitted.packets; |
| 277 last_report_old_packets_ = receive_counters_.retransmitted.packets; | 274 last_report_old_packets_ = receive_counters_.retransmitted.packets; |
| 278 last_report_seq_max_ = received_seq_max_; | 275 last_report_seq_max_ = received_seq_max_; |
| 279 | 276 |
| 280 return stats; | 277 return stats; |
| 281 } | 278 } |
| 282 | 279 |
| 283 void StreamStatisticianImpl::GetDataCounters( | 280 void StreamStatisticianImpl::GetDataCounters( |
| 284 size_t* bytes_received, uint32_t* packets_received) const { | 281 size_t* bytes_received, uint32_t* packets_received) const { |
| 285 CriticalSectionScoped cs(stream_lock_.get()); | 282 rtc::CritScope cs(&stream_lock_); |
| 286 if (bytes_received) { | 283 if (bytes_received) { |
| 287 *bytes_received = receive_counters_.transmitted.payload_bytes + | 284 *bytes_received = receive_counters_.transmitted.payload_bytes + |
| 288 receive_counters_.transmitted.header_bytes + | 285 receive_counters_.transmitted.header_bytes + |
| 289 receive_counters_.transmitted.padding_bytes; | 286 receive_counters_.transmitted.padding_bytes; |
| 290 } | 287 } |
| 291 if (packets_received) { | 288 if (packets_received) { |
| 292 *packets_received = receive_counters_.transmitted.packets; | 289 *packets_received = receive_counters_.transmitted.packets; |
| 293 } | 290 } |
| 294 } | 291 } |
| 295 | 292 |
| 296 void StreamStatisticianImpl::GetReceiveStreamDataCounters( | 293 void StreamStatisticianImpl::GetReceiveStreamDataCounters( |
| 297 StreamDataCounters* data_counters) const { | 294 StreamDataCounters* data_counters) const { |
| 298 CriticalSectionScoped cs(stream_lock_.get()); | 295 rtc::CritScope cs(&stream_lock_); |
| 299 *data_counters = receive_counters_; | 296 *data_counters = receive_counters_; |
| 300 } | 297 } |
| 301 | 298 |
| 302 uint32_t StreamStatisticianImpl::BitrateReceived() const { | 299 uint32_t StreamStatisticianImpl::BitrateReceived() const { |
| 303 CriticalSectionScoped cs(stream_lock_.get()); | 300 rtc::CritScope cs(&stream_lock_); |
| 304 return incoming_bitrate_.BitrateNow(); | 301 return incoming_bitrate_.BitrateNow(); |
| 305 } | 302 } |
| 306 | 303 |
| 307 void StreamStatisticianImpl::ProcessBitrate() { | 304 void StreamStatisticianImpl::ProcessBitrate() { |
| 308 CriticalSectionScoped cs(stream_lock_.get()); | 305 rtc::CritScope cs(&stream_lock_); |
| 309 incoming_bitrate_.Process(); | 306 incoming_bitrate_.Process(); |
| 310 } | 307 } |
| 311 | 308 |
| 312 void StreamStatisticianImpl::LastReceiveTimeNtp(uint32_t* secs, | 309 void StreamStatisticianImpl::LastReceiveTimeNtp(uint32_t* secs, |
| 313 uint32_t* frac) const { | 310 uint32_t* frac) const { |
| 314 CriticalSectionScoped cs(stream_lock_.get()); | 311 rtc::CritScope cs(&stream_lock_); |
| 315 *secs = last_receive_time_ntp_.seconds(); | 312 *secs = last_receive_time_ntp_.seconds(); |
| 316 *frac = last_receive_time_ntp_.fractions(); | 313 *frac = last_receive_time_ntp_.fractions(); |
| 317 } | 314 } |
| 318 | 315 |
| 319 bool StreamStatisticianImpl::IsRetransmitOfOldPacket( | 316 bool StreamStatisticianImpl::IsRetransmitOfOldPacket( |
| 320 const RTPHeader& header, int64_t min_rtt) const { | 317 const RTPHeader& header, int64_t min_rtt) const { |
| 321 CriticalSectionScoped cs(stream_lock_.get()); | 318 rtc::CritScope cs(&stream_lock_); |
| 322 if (InOrderPacketInternal(header.sequenceNumber)) { | 319 if (InOrderPacketInternal(header.sequenceNumber)) { |
| 323 return false; | 320 return false; |
| 324 } | 321 } |
| 325 uint32_t frequency_khz = header.payload_type_frequency / 1000; | 322 uint32_t frequency_khz = header.payload_type_frequency / 1000; |
| 326 assert(frequency_khz > 0); | 323 assert(frequency_khz > 0); |
| 327 | 324 |
| 328 int64_t time_diff_ms = clock_->TimeInMilliseconds() - | 325 int64_t time_diff_ms = clock_->TimeInMilliseconds() - |
| 329 last_receive_time_ms_; | 326 last_receive_time_ms_; |
| 330 | 327 |
| 331 // Diff in time stamp since last received in order. | 328 // Diff in time stamp since last received in order. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 345 if (max_delay_ms == 0) { | 342 if (max_delay_ms == 0) { |
| 346 max_delay_ms = 1; | 343 max_delay_ms = 1; |
| 347 } | 344 } |
| 348 } else { | 345 } else { |
| 349 max_delay_ms = (min_rtt / 3) + 1; | 346 max_delay_ms = (min_rtt / 3) + 1; |
| 350 } | 347 } |
| 351 return time_diff_ms > rtp_time_stamp_diff_ms + max_delay_ms; | 348 return time_diff_ms > rtp_time_stamp_diff_ms + max_delay_ms; |
| 352 } | 349 } |
| 353 | 350 |
| 354 bool StreamStatisticianImpl::IsPacketInOrder(uint16_t sequence_number) const { | 351 bool StreamStatisticianImpl::IsPacketInOrder(uint16_t sequence_number) const { |
| 355 CriticalSectionScoped cs(stream_lock_.get()); | 352 rtc::CritScope cs(&stream_lock_); |
| 356 return InOrderPacketInternal(sequence_number); | 353 return InOrderPacketInternal(sequence_number); |
| 357 } | 354 } |
| 358 | 355 |
| 359 bool StreamStatisticianImpl::InOrderPacketInternal( | 356 bool StreamStatisticianImpl::InOrderPacketInternal( |
| 360 uint16_t sequence_number) const { | 357 uint16_t sequence_number) const { |
| 361 // First packet is always in order. | 358 // First packet is always in order. |
| 362 if (last_receive_time_ms_ == 0) | 359 if (last_receive_time_ms_ == 0) |
| 363 return true; | 360 return true; |
| 364 | 361 |
| 365 if (IsNewerSequenceNumber(sequence_number, received_seq_max_)) { | 362 if (IsNewerSequenceNumber(sequence_number, received_seq_max_)) { |
| 366 return true; | 363 return true; |
| 367 } else { | 364 } else { |
| 368 // If we have a restart of the remote side this packet is still in order. | 365 // If we have a restart of the remote side this packet is still in order. |
| 369 return !IsNewerSequenceNumber(sequence_number, received_seq_max_ - | 366 return !IsNewerSequenceNumber(sequence_number, received_seq_max_ - |
| 370 max_reordering_threshold_); | 367 max_reordering_threshold_); |
| 371 } | 368 } |
| 372 } | 369 } |
| 373 | 370 |
| 374 ReceiveStatistics* ReceiveStatistics::Create(Clock* clock) { | 371 ReceiveStatistics* ReceiveStatistics::Create(Clock* clock) { |
| 375 return new ReceiveStatisticsImpl(clock); | 372 return new ReceiveStatisticsImpl(clock); |
| 376 } | 373 } |
| 377 | 374 |
| 378 ReceiveStatisticsImpl::ReceiveStatisticsImpl(Clock* clock) | 375 ReceiveStatisticsImpl::ReceiveStatisticsImpl(Clock* clock) |
| 379 : clock_(clock), | 376 : clock_(clock), |
| 380 receive_statistics_lock_(CriticalSectionWrapper::CreateCriticalSection()), | |
| 381 last_rate_update_ms_(0), | 377 last_rate_update_ms_(0), |
| 382 rtcp_stats_callback_(NULL), | 378 rtcp_stats_callback_(NULL), |
| 383 rtp_stats_callback_(NULL) {} | 379 rtp_stats_callback_(NULL) {} |
| 384 | 380 |
| 385 ReceiveStatisticsImpl::~ReceiveStatisticsImpl() { | 381 ReceiveStatisticsImpl::~ReceiveStatisticsImpl() { |
| 386 while (!statisticians_.empty()) { | 382 while (!statisticians_.empty()) { |
| 387 delete statisticians_.begin()->second; | 383 delete statisticians_.begin()->second; |
| 388 statisticians_.erase(statisticians_.begin()); | 384 statisticians_.erase(statisticians_.begin()); |
| 389 } | 385 } |
| 390 } | 386 } |
| 391 | 387 |
| 392 void ReceiveStatisticsImpl::IncomingPacket(const RTPHeader& header, | 388 void ReceiveStatisticsImpl::IncomingPacket(const RTPHeader& header, |
| 393 size_t packet_length, | 389 size_t packet_length, |
| 394 bool retransmitted) { | 390 bool retransmitted) { |
| 395 StreamStatisticianImpl* impl; | 391 StreamStatisticianImpl* impl; |
| 396 { | 392 { |
| 397 CriticalSectionScoped cs(receive_statistics_lock_.get()); | 393 rtc::CritScope cs(&receive_statistics_lock_); |
| 398 StatisticianImplMap::iterator it = statisticians_.find(header.ssrc); | 394 StatisticianImplMap::iterator it = statisticians_.find(header.ssrc); |
| 399 if (it != statisticians_.end()) { | 395 if (it != statisticians_.end()) { |
| 400 impl = it->second; | 396 impl = it->second; |
| 401 } else { | 397 } else { |
| 402 impl = new StreamStatisticianImpl(clock_, this, this); | 398 impl = new StreamStatisticianImpl(clock_, this, this); |
| 403 statisticians_[header.ssrc] = impl; | 399 statisticians_[header.ssrc] = impl; |
| 404 } | 400 } |
| 405 } | 401 } |
| 406 // StreamStatisticianImpl instance is created once and only destroyed when | 402 // StreamStatisticianImpl instance is created once and only destroyed when |
| 407 // this whole ReceiveStatisticsImpl is destroyed. StreamStatisticianImpl has | 403 // this whole ReceiveStatisticsImpl is destroyed. StreamStatisticianImpl has |
| 408 // it's own locking so don't hold receive_statistics_lock_ (potential | 404 // it's own locking so don't hold receive_statistics_lock_ (potential |
| 409 // deadlock). | 405 // deadlock). |
| 410 impl->IncomingPacket(header, packet_length, retransmitted); | 406 impl->IncomingPacket(header, packet_length, retransmitted); |
| 411 } | 407 } |
| 412 | 408 |
| 413 void ReceiveStatisticsImpl::FecPacketReceived(const RTPHeader& header, | 409 void ReceiveStatisticsImpl::FecPacketReceived(const RTPHeader& header, |
| 414 size_t packet_length) { | 410 size_t packet_length) { |
| 415 CriticalSectionScoped cs(receive_statistics_lock_.get()); | 411 rtc::CritScope cs(&receive_statistics_lock_); |
| 416 StatisticianImplMap::iterator it = statisticians_.find(header.ssrc); | 412 StatisticianImplMap::iterator it = statisticians_.find(header.ssrc); |
| 417 // Ignore FEC if it is the first packet. | 413 // Ignore FEC if it is the first packet. |
| 418 if (it != statisticians_.end()) { | 414 if (it != statisticians_.end()) { |
| 419 it->second->FecPacketReceived(header, packet_length); | 415 it->second->FecPacketReceived(header, packet_length); |
| 420 } | 416 } |
| 421 } | 417 } |
| 422 | 418 |
| 423 StatisticianMap ReceiveStatisticsImpl::GetActiveStatisticians() const { | 419 StatisticianMap ReceiveStatisticsImpl::GetActiveStatisticians() const { |
| 424 CriticalSectionScoped cs(receive_statistics_lock_.get()); | 420 rtc::CritScope cs(&receive_statistics_lock_); |
| 425 StatisticianMap active_statisticians; | 421 StatisticianMap active_statisticians; |
| 426 for (StatisticianImplMap::const_iterator it = statisticians_.begin(); | 422 for (StatisticianImplMap::const_iterator it = statisticians_.begin(); |
| 427 it != statisticians_.end(); ++it) { | 423 it != statisticians_.end(); ++it) { |
| 428 uint32_t secs; | 424 uint32_t secs; |
| 429 uint32_t frac; | 425 uint32_t frac; |
| 430 it->second->LastReceiveTimeNtp(&secs, &frac); | 426 it->second->LastReceiveTimeNtp(&secs, &frac); |
| 431 if (clock_->CurrentNtpInMilliseconds() - | 427 if (clock_->CurrentNtpInMilliseconds() - |
| 432 Clock::NtpToMs(secs, frac) < kStatisticsTimeoutMs) { | 428 Clock::NtpToMs(secs, frac) < kStatisticsTimeoutMs) { |
| 433 active_statisticians[it->first] = it->second; | 429 active_statisticians[it->first] = it->second; |
| 434 } | 430 } |
| 435 } | 431 } |
| 436 return active_statisticians; | 432 return active_statisticians; |
| 437 } | 433 } |
| 438 | 434 |
| 439 StreamStatistician* ReceiveStatisticsImpl::GetStatistician( | 435 StreamStatistician* ReceiveStatisticsImpl::GetStatistician( |
| 440 uint32_t ssrc) const { | 436 uint32_t ssrc) const { |
| 441 CriticalSectionScoped cs(receive_statistics_lock_.get()); | 437 rtc::CritScope cs(&receive_statistics_lock_); |
| 442 StatisticianImplMap::const_iterator it = statisticians_.find(ssrc); | 438 StatisticianImplMap::const_iterator it = statisticians_.find(ssrc); |
| 443 if (it == statisticians_.end()) | 439 if (it == statisticians_.end()) |
| 444 return NULL; | 440 return NULL; |
| 445 return it->second; | 441 return it->second; |
| 446 } | 442 } |
| 447 | 443 |
| 448 void ReceiveStatisticsImpl::SetMaxReorderingThreshold( | 444 void ReceiveStatisticsImpl::SetMaxReorderingThreshold( |
| 449 int max_reordering_threshold) { | 445 int max_reordering_threshold) { |
| 450 CriticalSectionScoped cs(receive_statistics_lock_.get()); | 446 rtc::CritScope cs(&receive_statistics_lock_); |
| 451 for (StatisticianImplMap::iterator it = statisticians_.begin(); | 447 for (StatisticianImplMap::iterator it = statisticians_.begin(); |
| 452 it != statisticians_.end(); ++it) { | 448 it != statisticians_.end(); ++it) { |
| 453 it->second->SetMaxReorderingThreshold(max_reordering_threshold); | 449 it->second->SetMaxReorderingThreshold(max_reordering_threshold); |
| 454 } | 450 } |
| 455 } | 451 } |
| 456 | 452 |
| 457 void ReceiveStatisticsImpl::Process() { | 453 void ReceiveStatisticsImpl::Process() { |
| 458 CriticalSectionScoped cs(receive_statistics_lock_.get()); | 454 rtc::CritScope cs(&receive_statistics_lock_); |
| 459 for (StatisticianImplMap::iterator it = statisticians_.begin(); | 455 for (StatisticianImplMap::iterator it = statisticians_.begin(); |
| 460 it != statisticians_.end(); ++it) { | 456 it != statisticians_.end(); ++it) { |
| 461 it->second->ProcessBitrate(); | 457 it->second->ProcessBitrate(); |
| 462 } | 458 } |
| 463 last_rate_update_ms_ = clock_->TimeInMilliseconds(); | 459 last_rate_update_ms_ = clock_->TimeInMilliseconds(); |
| 464 } | 460 } |
| 465 | 461 |
| 466 int64_t ReceiveStatisticsImpl::TimeUntilNextProcess() { | 462 int64_t ReceiveStatisticsImpl::TimeUntilNextProcess() { |
| 467 CriticalSectionScoped cs(receive_statistics_lock_.get()); | 463 rtc::CritScope cs(&receive_statistics_lock_); |
| 468 int64_t time_since_last_update = clock_->TimeInMilliseconds() - | 464 int64_t time_since_last_update = clock_->TimeInMilliseconds() - |
| 469 last_rate_update_ms_; | 465 last_rate_update_ms_; |
| 470 return std::max<int64_t>( | 466 return std::max<int64_t>( |
| 471 kStatisticsProcessIntervalMs - time_since_last_update, 0); | 467 kStatisticsProcessIntervalMs - time_since_last_update, 0); |
| 472 } | 468 } |
| 473 | 469 |
| 474 void ReceiveStatisticsImpl::RegisterRtcpStatisticsCallback( | 470 void ReceiveStatisticsImpl::RegisterRtcpStatisticsCallback( |
| 475 RtcpStatisticsCallback* callback) { | 471 RtcpStatisticsCallback* callback) { |
| 476 CriticalSectionScoped cs(receive_statistics_lock_.get()); | 472 rtc::CritScope cs(&receive_statistics_lock_); |
| 477 if (callback != NULL) | 473 if (callback != NULL) |
| 478 assert(rtcp_stats_callback_ == NULL); | 474 assert(rtcp_stats_callback_ == NULL); |
| 479 rtcp_stats_callback_ = callback; | 475 rtcp_stats_callback_ = callback; |
| 480 } | 476 } |
| 481 | 477 |
| 482 void ReceiveStatisticsImpl::StatisticsUpdated(const RtcpStatistics& statistics, | 478 void ReceiveStatisticsImpl::StatisticsUpdated(const RtcpStatistics& statistics, |
| 483 uint32_t ssrc) { | 479 uint32_t ssrc) { |
| 484 CriticalSectionScoped cs(receive_statistics_lock_.get()); | 480 rtc::CritScope cs(&receive_statistics_lock_); |
| 485 if (rtcp_stats_callback_) | 481 if (rtcp_stats_callback_) |
| 486 rtcp_stats_callback_->StatisticsUpdated(statistics, ssrc); | 482 rtcp_stats_callback_->StatisticsUpdated(statistics, ssrc); |
| 487 } | 483 } |
| 488 | 484 |
| 489 void ReceiveStatisticsImpl::CNameChanged(const char* cname, uint32_t ssrc) { | 485 void ReceiveStatisticsImpl::CNameChanged(const char* cname, uint32_t ssrc) { |
| 490 CriticalSectionScoped cs(receive_statistics_lock_.get()); | 486 rtc::CritScope cs(&receive_statistics_lock_); |
| 491 if (rtcp_stats_callback_) | 487 if (rtcp_stats_callback_) |
| 492 rtcp_stats_callback_->CNameChanged(cname, ssrc); | 488 rtcp_stats_callback_->CNameChanged(cname, ssrc); |
| 493 } | 489 } |
| 494 | 490 |
| 495 void ReceiveStatisticsImpl::RegisterRtpStatisticsCallback( | 491 void ReceiveStatisticsImpl::RegisterRtpStatisticsCallback( |
| 496 StreamDataCountersCallback* callback) { | 492 StreamDataCountersCallback* callback) { |
| 497 CriticalSectionScoped cs(receive_statistics_lock_.get()); | 493 rtc::CritScope cs(&receive_statistics_lock_); |
| 498 if (callback != NULL) | 494 if (callback != NULL) |
| 499 assert(rtp_stats_callback_ == NULL); | 495 assert(rtp_stats_callback_ == NULL); |
| 500 rtp_stats_callback_ = callback; | 496 rtp_stats_callback_ = callback; |
| 501 } | 497 } |
| 502 | 498 |
| 503 void ReceiveStatisticsImpl::DataCountersUpdated(const StreamDataCounters& stats, | 499 void ReceiveStatisticsImpl::DataCountersUpdated(const StreamDataCounters& stats, |
| 504 uint32_t ssrc) { | 500 uint32_t ssrc) { |
| 505 CriticalSectionScoped cs(receive_statistics_lock_.get()); | 501 rtc::CritScope cs(&receive_statistics_lock_); |
| 506 if (rtp_stats_callback_) { | 502 if (rtp_stats_callback_) { |
| 507 rtp_stats_callback_->DataCountersUpdated(stats, ssrc); | 503 rtp_stats_callback_->DataCountersUpdated(stats, ssrc); |
| 508 } | 504 } |
| 509 } | 505 } |
| 510 | 506 |
| 511 void NullReceiveStatistics::IncomingPacket(const RTPHeader& rtp_header, | 507 void NullReceiveStatistics::IncomingPacket(const RTPHeader& rtp_header, |
| 512 size_t packet_length, | 508 size_t packet_length, |
| 513 bool retransmitted) {} | 509 bool retransmitted) {} |
| 514 | 510 |
| 515 void NullReceiveStatistics::FecPacketReceived(const RTPHeader& header, | 511 void NullReceiveStatistics::FecPacketReceived(const RTPHeader& header, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 531 | 527 |
| 532 void NullReceiveStatistics::Process() {} | 528 void NullReceiveStatistics::Process() {} |
| 533 | 529 |
| 534 void NullReceiveStatistics::RegisterRtcpStatisticsCallback( | 530 void NullReceiveStatistics::RegisterRtcpStatisticsCallback( |
| 535 RtcpStatisticsCallback* callback) {} | 531 RtcpStatisticsCallback* callback) {} |
| 536 | 532 |
| 537 void NullReceiveStatistics::RegisterRtpStatisticsCallback( | 533 void NullReceiveStatistics::RegisterRtpStatisticsCallback( |
| 538 StreamDataCountersCallback* callback) {} | 534 StreamDataCountersCallback* callback) {} |
| 539 | 535 |
| 540 } // namespace webrtc | 536 } // namespace webrtc |
| OLD | NEW |