| 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 <cstdlib> | 15 #include <cstdlib> | 
| 16 | 16 | 
| 17 #include "webrtc/modules/rtp_rtcp/source/bitrate.h" | 17 #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h" | 
| 18 #include "webrtc/modules/rtp_rtcp/source/time_util.h" | 18 #include "webrtc/modules/rtp_rtcp/source/time_util.h" | 
| 19 | 19 | 
| 20 namespace webrtc { | 20 namespace webrtc { | 
| 21 | 21 | 
| 22 const int64_t kStatisticsTimeoutMs = 8000; | 22 const int64_t kStatisticsTimeoutMs = 8000; | 
| 23 const int64_t kStatisticsProcessIntervalMs = 1000; | 23 const int64_t kStatisticsProcessIntervalMs = 1000; | 
| 24 | 24 | 
| 25 StreamStatistician::~StreamStatistician() {} | 25 StreamStatistician::~StreamStatistician() {} | 
| 26 | 26 | 
| 27 StreamStatisticianImpl::StreamStatisticianImpl( | 27 StreamStatisticianImpl::StreamStatisticianImpl( | 
| 28     Clock* clock, | 28     Clock* clock, | 
| 29     RtcpStatisticsCallback* rtcp_callback, | 29     RtcpStatisticsCallback* rtcp_callback, | 
| 30     StreamDataCountersCallback* rtp_callback) | 30     StreamDataCountersCallback* rtp_callback) | 
| 31     : clock_(clock), | 31     : clock_(clock), | 
| 32       incoming_bitrate_(clock, NULL), | 32       incoming_bitrate_(kStatisticsProcessIntervalMs, | 
|  | 33                         RateStatistics::kBpsScale), | 
| 33       ssrc_(0), | 34       ssrc_(0), | 
| 34       max_reordering_threshold_(kDefaultMaxReorderingThreshold), | 35       max_reordering_threshold_(kDefaultMaxReorderingThreshold), | 
| 35       jitter_q4_(0), | 36       jitter_q4_(0), | 
| 36       cumulative_loss_(0), | 37       cumulative_loss_(0), | 
| 37       jitter_q4_transmission_time_offset_(0), | 38       jitter_q4_transmission_time_offset_(0), | 
| 38       last_receive_time_ms_(0), | 39       last_receive_time_ms_(0), | 
| 39       last_received_timestamp_(0), | 40       last_received_timestamp_(0), | 
| 40       last_received_transmission_time_offset_(0), | 41       last_received_transmission_time_offset_(0), | 
| 41       received_seq_first_(0), | 42       received_seq_first_(0), | 
| 42       received_seq_max_(0), | 43       received_seq_max_(0), | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
| 54   UpdateCounters(header, packet_length, retransmitted); | 55   UpdateCounters(header, packet_length, retransmitted); | 
| 55   NotifyRtpCallback(); | 56   NotifyRtpCallback(); | 
| 56 } | 57 } | 
| 57 | 58 | 
| 58 void StreamStatisticianImpl::UpdateCounters(const RTPHeader& header, | 59 void StreamStatisticianImpl::UpdateCounters(const RTPHeader& header, | 
| 59                                             size_t packet_length, | 60                                             size_t packet_length, | 
| 60                                             bool retransmitted) { | 61                                             bool retransmitted) { | 
| 61   rtc::CritScope cs(&stream_lock_); | 62   rtc::CritScope cs(&stream_lock_); | 
| 62   bool in_order = InOrderPacketInternal(header.sequenceNumber); | 63   bool in_order = InOrderPacketInternal(header.sequenceNumber); | 
| 63   ssrc_ = header.ssrc; | 64   ssrc_ = header.ssrc; | 
| 64   incoming_bitrate_.Update(packet_length); | 65   incoming_bitrate_.Update(packet_length, clock_->TimeInMilliseconds()); | 
| 65   receive_counters_.transmitted.AddPacket(packet_length, header); | 66   receive_counters_.transmitted.AddPacket(packet_length, header); | 
| 66   if (!in_order && retransmitted) { | 67   if (!in_order && retransmitted) { | 
| 67     receive_counters_.retransmitted.AddPacket(packet_length, header); | 68     receive_counters_.retransmitted.AddPacket(packet_length, header); | 
| 68   } | 69   } | 
| 69 | 70 | 
| 70   if (receive_counters_.transmitted.packets == 1) { | 71   if (receive_counters_.transmitted.packets == 1) { | 
| 71     received_seq_first_ = header.sequenceNumber; | 72     received_seq_first_ = header.sequenceNumber; | 
| 72     receive_counters_.first_packet_time_ms = clock_->TimeInMilliseconds(); | 73     receive_counters_.first_packet_time_ms = clock_->TimeInMilliseconds(); | 
| 73   } | 74   } | 
| 74 | 75 | 
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 293 } | 294 } | 
| 294 | 295 | 
| 295 void StreamStatisticianImpl::GetReceiveStreamDataCounters( | 296 void StreamStatisticianImpl::GetReceiveStreamDataCounters( | 
| 296     StreamDataCounters* data_counters) const { | 297     StreamDataCounters* data_counters) const { | 
| 297   rtc::CritScope cs(&stream_lock_); | 298   rtc::CritScope cs(&stream_lock_); | 
| 298   *data_counters = receive_counters_; | 299   *data_counters = receive_counters_; | 
| 299 } | 300 } | 
| 300 | 301 | 
| 301 uint32_t StreamStatisticianImpl::BitrateReceived() const { | 302 uint32_t StreamStatisticianImpl::BitrateReceived() const { | 
| 302   rtc::CritScope cs(&stream_lock_); | 303   rtc::CritScope cs(&stream_lock_); | 
| 303   return incoming_bitrate_.BitrateNow(); | 304   return incoming_bitrate_.Rate(clock_->TimeInMilliseconds()).value_or(0); | 
| 304 } |  | 
| 305 |  | 
| 306 void StreamStatisticianImpl::ProcessBitrate() { |  | 
| 307   rtc::CritScope cs(&stream_lock_); |  | 
| 308   incoming_bitrate_.Process(); |  | 
| 309 } | 305 } | 
| 310 | 306 | 
| 311 void StreamStatisticianImpl::LastReceiveTimeNtp(uint32_t* secs, | 307 void StreamStatisticianImpl::LastReceiveTimeNtp(uint32_t* secs, | 
| 312                                                 uint32_t* frac) const { | 308                                                 uint32_t* frac) const { | 
| 313   rtc::CritScope cs(&stream_lock_); | 309   rtc::CritScope cs(&stream_lock_); | 
| 314   *secs = last_receive_time_ntp_.seconds(); | 310   *secs = last_receive_time_ntp_.seconds(); | 
| 315   *frac = last_receive_time_ntp_.fractions(); | 311   *frac = last_receive_time_ntp_.fractions(); | 
| 316 } | 312 } | 
| 317 | 313 | 
| 318 bool StreamStatisticianImpl::IsRetransmitOfOldPacket( | 314 bool StreamStatisticianImpl::IsRetransmitOfOldPacket( | 
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 369                                   max_reordering_threshold_); | 365                                   max_reordering_threshold_); | 
| 370   } | 366   } | 
| 371 } | 367 } | 
| 372 | 368 | 
| 373 ReceiveStatistics* ReceiveStatistics::Create(Clock* clock) { | 369 ReceiveStatistics* ReceiveStatistics::Create(Clock* clock) { | 
| 374   return new ReceiveStatisticsImpl(clock); | 370   return new ReceiveStatisticsImpl(clock); | 
| 375 } | 371 } | 
| 376 | 372 | 
| 377 ReceiveStatisticsImpl::ReceiveStatisticsImpl(Clock* clock) | 373 ReceiveStatisticsImpl::ReceiveStatisticsImpl(Clock* clock) | 
| 378     : clock_(clock), | 374     : clock_(clock), | 
| 379       last_rate_update_ms_(0), |  | 
| 380       rtcp_stats_callback_(NULL), | 375       rtcp_stats_callback_(NULL), | 
| 381       rtp_stats_callback_(NULL) {} | 376       rtp_stats_callback_(NULL) {} | 
| 382 | 377 | 
| 383 ReceiveStatisticsImpl::~ReceiveStatisticsImpl() { | 378 ReceiveStatisticsImpl::~ReceiveStatisticsImpl() { | 
| 384   while (!statisticians_.empty()) { | 379   while (!statisticians_.empty()) { | 
| 385     delete statisticians_.begin()->second; | 380     delete statisticians_.begin()->second; | 
| 386     statisticians_.erase(statisticians_.begin()); | 381     statisticians_.erase(statisticians_.begin()); | 
| 387   } | 382   } | 
| 388 } | 383 } | 
| 389 | 384 | 
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 445 | 440 | 
| 446 void ReceiveStatisticsImpl::SetMaxReorderingThreshold( | 441 void ReceiveStatisticsImpl::SetMaxReorderingThreshold( | 
| 447     int max_reordering_threshold) { | 442     int max_reordering_threshold) { | 
| 448   rtc::CritScope cs(&receive_statistics_lock_); | 443   rtc::CritScope cs(&receive_statistics_lock_); | 
| 449   for (StatisticianImplMap::iterator it = statisticians_.begin(); | 444   for (StatisticianImplMap::iterator it = statisticians_.begin(); | 
| 450        it != statisticians_.end(); ++it) { | 445        it != statisticians_.end(); ++it) { | 
| 451     it->second->SetMaxReorderingThreshold(max_reordering_threshold); | 446     it->second->SetMaxReorderingThreshold(max_reordering_threshold); | 
| 452   } | 447   } | 
| 453 } | 448 } | 
| 454 | 449 | 
| 455 void ReceiveStatisticsImpl::Process() { |  | 
| 456   rtc::CritScope cs(&receive_statistics_lock_); |  | 
| 457   for (StatisticianImplMap::iterator it = statisticians_.begin(); |  | 
| 458        it != statisticians_.end(); ++it) { |  | 
| 459     it->second->ProcessBitrate(); |  | 
| 460   } |  | 
| 461   last_rate_update_ms_ = clock_->TimeInMilliseconds(); |  | 
| 462 } |  | 
| 463 |  | 
| 464 int64_t ReceiveStatisticsImpl::TimeUntilNextProcess() { |  | 
| 465   rtc::CritScope cs(&receive_statistics_lock_); |  | 
| 466   int64_t time_since_last_update = clock_->TimeInMilliseconds() - |  | 
| 467       last_rate_update_ms_; |  | 
| 468   return std::max<int64_t>( |  | 
| 469       kStatisticsProcessIntervalMs - time_since_last_update, 0); |  | 
| 470 } |  | 
| 471 |  | 
| 472 void ReceiveStatisticsImpl::RegisterRtcpStatisticsCallback( | 450 void ReceiveStatisticsImpl::RegisterRtcpStatisticsCallback( | 
| 473     RtcpStatisticsCallback* callback) { | 451     RtcpStatisticsCallback* callback) { | 
| 474   rtc::CritScope cs(&receive_statistics_lock_); | 452   rtc::CritScope cs(&receive_statistics_lock_); | 
| 475   if (callback != NULL) | 453   if (callback != NULL) | 
| 476     assert(rtcp_stats_callback_ == NULL); | 454     assert(rtcp_stats_callback_ == NULL); | 
| 477   rtcp_stats_callback_ = callback; | 455   rtcp_stats_callback_ = callback; | 
| 478 } | 456 } | 
| 479 | 457 | 
| 480 void ReceiveStatisticsImpl::StatisticsUpdated(const RtcpStatistics& statistics, | 458 void ReceiveStatisticsImpl::StatisticsUpdated(const RtcpStatistics& statistics, | 
| 481                                               uint32_t ssrc) { | 459                                               uint32_t ssrc) { | 
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 518 } | 496 } | 
| 519 | 497 | 
| 520 StreamStatistician* NullReceiveStatistics::GetStatistician( | 498 StreamStatistician* NullReceiveStatistics::GetStatistician( | 
| 521     uint32_t ssrc) const { | 499     uint32_t ssrc) const { | 
| 522   return NULL; | 500   return NULL; | 
| 523 } | 501 } | 
| 524 | 502 | 
| 525 void NullReceiveStatistics::SetMaxReorderingThreshold( | 503 void NullReceiveStatistics::SetMaxReorderingThreshold( | 
| 526     int max_reordering_threshold) {} | 504     int max_reordering_threshold) {} | 
| 527 | 505 | 
| 528 int64_t NullReceiveStatistics::TimeUntilNextProcess() { return 0; } |  | 
| 529 |  | 
| 530 void NullReceiveStatistics::Process() {} |  | 
| 531 |  | 
| 532 void NullReceiveStatistics::RegisterRtcpStatisticsCallback( | 506 void NullReceiveStatistics::RegisterRtcpStatisticsCallback( | 
| 533     RtcpStatisticsCallback* callback) {} | 507     RtcpStatisticsCallback* callback) {} | 
| 534 | 508 | 
| 535 void NullReceiveStatistics::RegisterRtpStatisticsCallback( | 509 void NullReceiveStatistics::RegisterRtpStatisticsCallback( | 
| 536     StreamDataCountersCallback* callback) {} | 510     StreamDataCountersCallback* callback) {} | 
| 537 | 511 | 
| 538 }  // namespace webrtc | 512 }  // namespace webrtc | 
| OLD | NEW | 
|---|