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