Chromium Code Reviews| 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 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 kHighVarianceThreshold, | 66 kHighVarianceThreshold, |
| 67 kBadFraction, | 67 kBadFraction, |
| 68 kNumMeasurementsVariance), | 68 kNumMeasurementsVariance), |
| 69 num_bad_states_(0), | 69 num_bad_states_(0), |
| 70 num_certain_states_(0), | 70 num_certain_states_(0), |
| 71 // 1000ms window, scale 1000 for ms to s. | 71 // 1000ms window, scale 1000 for ms to s. |
| 72 decode_fps_estimator_(1000, 1000), | 72 decode_fps_estimator_(1000, 1000), |
| 73 renders_fps_estimator_(1000, 1000), | 73 renders_fps_estimator_(1000, 1000), |
| 74 render_fps_tracker_(100, 10u), | 74 render_fps_tracker_(100, 10u), |
| 75 render_pixel_tracker_(100, 10u), | 75 render_pixel_tracker_(100, 10u), |
| 76 total_byte_tracker_(100, 10u), // bucket_interval_ms, bucket_count | |
| 76 freq_offset_counter_(clock, nullptr, kFreqOffsetProcessIntervalMs), | 77 freq_offset_counter_(clock, nullptr, kFreqOffsetProcessIntervalMs), |
| 77 first_report_block_time_ms_(-1), | 78 first_report_block_time_ms_(-1), |
| 78 avg_rtt_ms_(0), | 79 avg_rtt_ms_(0) { |
| 79 frame_window_accumulated_bytes_(0) { | |
| 80 stats_.ssrc = config_.rtp.remote_ssrc; | 80 stats_.ssrc = config_.rtp.remote_ssrc; |
| 81 // TODO(brandtr): Replace |rtx_stats_| with a single instance of | 81 // TODO(brandtr): Replace |rtx_stats_| with a single instance of |
| 82 // StreamDataCounters. | 82 // StreamDataCounters. |
| 83 if (config_.rtp.rtx_ssrc) { | 83 if (config_.rtp.rtx_ssrc) { |
| 84 rtx_stats_[config_.rtp.rtx_ssrc] = StreamDataCounters(); | 84 rtx_stats_[config_.rtp.rtx_ssrc] = StreamDataCounters(); |
| 85 } | 85 } |
| 86 } | 86 } |
| 87 | 87 |
| 88 ReceiveStatisticsProxy::~ReceiveStatisticsProxy() { | 88 ReceiveStatisticsProxy::~ReceiveStatisticsProxy() { |
| 89 UpdateHistograms(); | 89 UpdateHistograms(); |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 305 qp_sample_.Reset(); | 305 qp_sample_.Reset(); |
| 306 | 306 |
| 307 if (fps_threshold_.IsHigh() || variance_threshold_.IsHigh() || | 307 if (fps_threshold_.IsHigh() || variance_threshold_.IsHigh() || |
| 308 qp_threshold_.IsHigh()) { | 308 qp_threshold_.IsHigh()) { |
| 309 if (any_bad) | 309 if (any_bad) |
| 310 ++num_bad_states_; | 310 ++num_bad_states_; |
| 311 ++num_certain_states_; | 311 ++num_certain_states_; |
| 312 } | 312 } |
| 313 } | 313 } |
| 314 | 314 |
| 315 void ReceiveStatisticsProxy::UpdateFrameAndBitrate(int64_t now_ms) const { | 315 void ReceiveStatisticsProxy::UpdateFramerate(int64_t now_ms) const { |
| 316 int64_t old_frames_ms = now_ms - kRateStatisticsWindowSizeMs; | 316 int64_t old_frames_ms = now_ms - kRateStatisticsWindowSizeMs; |
| 317 while (!frame_window_.empty() && | 317 while (!frame_window_.empty() && |
| 318 frame_window_.begin()->first < old_frames_ms) { | 318 frame_window_.begin()->first < old_frames_ms) { |
| 319 frame_window_accumulated_bytes_ -= frame_window_.begin()->second; | |
| 320 frame_window_.erase(frame_window_.begin()); | 319 frame_window_.erase(frame_window_.begin()); |
| 321 } | 320 } |
| 322 | 321 |
| 323 size_t framerate = | 322 size_t framerate = |
| 324 (frame_window_.size() * 1000 + 500) / kRateStatisticsWindowSizeMs; | 323 (frame_window_.size() * 1000 + 500) / kRateStatisticsWindowSizeMs; |
| 325 size_t bitrate_bps = | |
| 326 frame_window_accumulated_bytes_ * 8000 / kRateStatisticsWindowSizeMs; | |
| 327 stats_.network_frame_rate = static_cast<int>(framerate); | 324 stats_.network_frame_rate = static_cast<int>(framerate); |
| 328 stats_.total_bitrate_bps = static_cast<int>(bitrate_bps); | |
| 329 } | 325 } |
| 330 | 326 |
| 331 VideoReceiveStream::Stats ReceiveStatisticsProxy::GetStats() const { | 327 VideoReceiveStream::Stats ReceiveStatisticsProxy::GetStats() const { |
| 332 rtc::CritScope lock(&crit_); | 328 rtc::CritScope lock(&crit_); |
| 333 UpdateFrameAndBitrate(clock_->TimeInMilliseconds()); | 329 UpdateFramerate(clock_->TimeInMilliseconds()); |
| 330 stats_.total_bitrate_bps = | |
| 331 static_cast<int>(total_byte_tracker_.ComputeRate() * 8); | |
| 334 return stats_; | 332 return stats_; |
| 335 } | 333 } |
| 336 | 334 |
| 337 void ReceiveStatisticsProxy::OnIncomingPayloadType(int payload_type) { | 335 void ReceiveStatisticsProxy::OnIncomingPayloadType(int payload_type) { |
| 338 rtc::CritScope lock(&crit_); | 336 rtc::CritScope lock(&crit_); |
| 339 stats_.current_payload_type = payload_type; | 337 stats_.current_payload_type = payload_type; |
| 340 } | 338 } |
| 341 | 339 |
| 342 void ReceiveStatisticsProxy::OnDecoderImplementationName( | 340 void ReceiveStatisticsProxy::OnDecoderImplementationName( |
| 343 const char* implementation_name) { | 341 const char* implementation_name) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 405 // TODO(pbos): Handle both local and remote ssrcs here and RTC_DCHECK that we | 403 // TODO(pbos): Handle both local and remote ssrcs here and RTC_DCHECK that we |
| 406 // receive stats from one of them. | 404 // receive stats from one of them. |
| 407 if (stats_.ssrc != ssrc) | 405 if (stats_.ssrc != ssrc) |
| 408 return; | 406 return; |
| 409 stats_.c_name = cname; | 407 stats_.c_name = cname; |
| 410 } | 408 } |
| 411 | 409 |
| 412 void ReceiveStatisticsProxy::DataCountersUpdated( | 410 void ReceiveStatisticsProxy::DataCountersUpdated( |
| 413 const webrtc::StreamDataCounters& counters, | 411 const webrtc::StreamDataCounters& counters, |
| 414 uint32_t ssrc) { | 412 uint32_t ssrc) { |
| 413 size_t last_total_bytes = 0; | |
| 414 size_t total_bytes = 0; | |
| 415 rtc::CritScope lock(&crit_); | 415 rtc::CritScope lock(&crit_); |
| 416 if (ssrc == stats_.ssrc) { | 416 if (ssrc == stats_.ssrc) { |
| 417 last_total_bytes = stats_.rtp_stats.transmitted.TotalBytes(); | |
| 418 total_bytes = counters.transmitted.TotalBytes(); | |
| 417 stats_.rtp_stats = counters; | 419 stats_.rtp_stats = counters; |
| 418 } else { | 420 } else { |
| 419 auto it = rtx_stats_.find(ssrc); | 421 auto it = rtx_stats_.find(ssrc); |
| 420 if (it != rtx_stats_.end()) { | 422 if (it != rtx_stats_.end()) { |
| 423 last_total_bytes = it->second.transmitted.TotalBytes(); | |
| 424 total_bytes = counters.transmitted.TotalBytes(); | |
| 421 it->second = counters; | 425 it->second = counters; |
| 422 } else { | 426 } else { |
| 423 RTC_NOTREACHED() << "Unexpected stream ssrc: " << ssrc; | 427 RTC_NOTREACHED() << "Unexpected stream ssrc: " << ssrc; |
| 424 } | 428 } |
| 425 } | 429 } |
| 430 if (total_bytes > last_total_bytes) | |
|
stefan-webrtc
2017/03/28 07:13:02
What should we do if this is not true? Seems like
åsapersson
2017/03/28 07:59:23
Not sure if it can happen but if the counters are
stefan-webrtc
2017/03/28 09:18:53
Ok.
| |
| 431 total_byte_tracker_.AddSamples(total_bytes - last_total_bytes); | |
| 426 } | 432 } |
| 427 | 433 |
| 428 void ReceiveStatisticsProxy::OnDecodedFrame(rtc::Optional<uint8_t> qp) { | 434 void ReceiveStatisticsProxy::OnDecodedFrame(rtc::Optional<uint8_t> qp) { |
| 429 uint64_t now = clock_->TimeInMilliseconds(); | 435 uint64_t now = clock_->TimeInMilliseconds(); |
| 430 | 436 |
| 431 rtc::CritScope lock(&crit_); | 437 rtc::CritScope lock(&crit_); |
| 432 ++stats_.frames_decoded; | 438 ++stats_.frames_decoded; |
| 433 if (qp) { | 439 if (qp) { |
| 434 if (!stats_.qp_sum) { | 440 if (!stats_.qp_sum) { |
| 435 if (stats_.frames_decoded != 1) { | 441 if (stats_.frames_decoded != 1) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 495 | 501 |
| 496 void ReceiveStatisticsProxy::OnCompleteFrame(bool is_keyframe, | 502 void ReceiveStatisticsProxy::OnCompleteFrame(bool is_keyframe, |
| 497 size_t size_bytes) { | 503 size_t size_bytes) { |
| 498 rtc::CritScope lock(&crit_); | 504 rtc::CritScope lock(&crit_); |
| 499 if (is_keyframe) | 505 if (is_keyframe) |
| 500 ++stats_.frame_counts.key_frames; | 506 ++stats_.frame_counts.key_frames; |
| 501 else | 507 else |
| 502 ++stats_.frame_counts.delta_frames; | 508 ++stats_.frame_counts.delta_frames; |
| 503 | 509 |
| 504 int64_t now_ms = clock_->TimeInMilliseconds(); | 510 int64_t now_ms = clock_->TimeInMilliseconds(); |
| 505 frame_window_accumulated_bytes_ += size_bytes; | |
| 506 frame_window_.insert(std::make_pair(now_ms, size_bytes)); | 511 frame_window_.insert(std::make_pair(now_ms, size_bytes)); |
| 507 UpdateFrameAndBitrate(now_ms); | 512 UpdateFramerate(now_ms); |
| 508 } | 513 } |
| 509 | 514 |
| 510 void ReceiveStatisticsProxy::OnFrameCountsUpdated( | 515 void ReceiveStatisticsProxy::OnFrameCountsUpdated( |
| 511 const FrameCounts& frame_counts) { | 516 const FrameCounts& frame_counts) { |
| 512 rtc::CritScope lock(&crit_); | 517 rtc::CritScope lock(&crit_); |
| 513 stats_.frame_counts = frame_counts; | 518 stats_.frame_counts = frame_counts; |
| 514 } | 519 } |
| 515 | 520 |
| 516 void ReceiveStatisticsProxy::OnDiscardedPacketsUpdated(int discarded_packets) { | 521 void ReceiveStatisticsProxy::OnDiscardedPacketsUpdated(int discarded_packets) { |
| 517 rtc::CritScope lock(&crit_); | 522 rtc::CritScope lock(&crit_); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 548 sum = 0; | 553 sum = 0; |
| 549 } | 554 } |
| 550 | 555 |
| 551 void ReceiveStatisticsProxy::OnRttUpdate(int64_t avg_rtt_ms, | 556 void ReceiveStatisticsProxy::OnRttUpdate(int64_t avg_rtt_ms, |
| 552 int64_t max_rtt_ms) { | 557 int64_t max_rtt_ms) { |
| 553 rtc::CritScope lock(&crit_); | 558 rtc::CritScope lock(&crit_); |
| 554 avg_rtt_ms_ = avg_rtt_ms; | 559 avg_rtt_ms_ = avg_rtt_ms; |
| 555 } | 560 } |
| 556 | 561 |
| 557 } // namespace webrtc | 562 } // namespace webrtc |
| OLD | NEW |