| 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 372 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 383                 ssrc) == config_.rtp.rtx.ssrcs.end()) { | 383                 ssrc) == config_.rtp.rtx.ssrcs.end()) { | 
| 384     return nullptr; | 384     return nullptr; | 
| 385   } | 385   } | 
| 386 | 386 | 
| 387   return &stats_.substreams[ssrc];  // Insert new entry and return ptr. | 387   return &stats_.substreams[ssrc];  // Insert new entry and return ptr. | 
| 388 } | 388 } | 
| 389 | 389 | 
| 390 void SendStatisticsProxy::OnInactiveSsrc(uint32_t ssrc) { | 390 void SendStatisticsProxy::OnInactiveSsrc(uint32_t ssrc) { | 
| 391   rtc::CritScope lock(&crit_); | 391   rtc::CritScope lock(&crit_); | 
| 392   VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); | 392   VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); | 
| 393   if (stats == nullptr) | 393   if (!stats) | 
| 394     return; | 394     return; | 
| 395 | 395 | 
| 396   stats->total_bitrate_bps = 0; | 396   stats->total_bitrate_bps = 0; | 
| 397   stats->retransmit_bitrate_bps = 0; | 397   stats->retransmit_bitrate_bps = 0; | 
| 398   stats->height = 0; | 398   stats->height = 0; | 
| 399   stats->width = 0; | 399   stats->width = 0; | 
| 400 } | 400 } | 
| 401 | 401 | 
| 402 void SendStatisticsProxy::OnSetRates(uint32_t bitrate_bps, int framerate) { | 402 void SendStatisticsProxy::OnSetRates(uint32_t bitrate_bps, int framerate) { | 
| 403   rtc::CritScope lock(&crit_); | 403   rtc::CritScope lock(&crit_); | 
| 404   stats_.target_media_bitrate_bps = bitrate_bps; | 404   stats_.target_media_bitrate_bps = bitrate_bps; | 
| 405 } | 405 } | 
| 406 | 406 | 
| 407 void SendStatisticsProxy::OnSendEncodedImage( | 407 void SendStatisticsProxy::OnSendEncodedImage( | 
| 408     const EncodedImage& encoded_image, | 408     const EncodedImage& encoded_image, | 
| 409     const RTPVideoHeader* rtp_video_header) { | 409     const RTPVideoHeader* rtp_video_header) { | 
| 410   size_t simulcast_idx = | 410   size_t simulcast_idx = rtp_video_header ? rtp_video_header->simulcastIdx : 0; | 
| 411       rtp_video_header != nullptr ? rtp_video_header->simulcastIdx : 0; |  | 
| 412   if (simulcast_idx >= config_.rtp.ssrcs.size()) { | 411   if (simulcast_idx >= config_.rtp.ssrcs.size()) { | 
| 413     LOG(LS_ERROR) << "Encoded image outside simulcast range (" << simulcast_idx | 412     LOG(LS_ERROR) << "Encoded image outside simulcast range (" << simulcast_idx | 
| 414                   << " >= " << config_.rtp.ssrcs.size() << ")."; | 413                   << " >= " << config_.rtp.ssrcs.size() << ")."; | 
| 415     return; | 414     return; | 
| 416   } | 415   } | 
| 417   uint32_t ssrc = config_.rtp.ssrcs[simulcast_idx]; | 416   uint32_t ssrc = config_.rtp.ssrcs[simulcast_idx]; | 
| 418 | 417 | 
| 419   rtc::CritScope lock(&crit_); | 418   rtc::CritScope lock(&crit_); | 
| 420   VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); | 419   VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); | 
| 421   if (stats == nullptr) | 420   if (!stats) | 
| 422     return; | 421     return; | 
| 423 | 422 | 
| 424   stats->width = encoded_image._encodedWidth; | 423   stats->width = encoded_image._encodedWidth; | 
| 425   stats->height = encoded_image._encodedHeight; | 424   stats->height = encoded_image._encodedHeight; | 
| 426   update_times_[ssrc].resolution_update_ms = clock_->TimeInMilliseconds(); | 425   update_times_[ssrc].resolution_update_ms = clock_->TimeInMilliseconds(); | 
| 427 | 426 | 
| 428   uma_container_->key_frame_counter_.Add(encoded_image._frameType == | 427   uma_container_->key_frame_counter_.Add(encoded_image._frameType == | 
| 429                                          kVideoFrameKey); | 428                                          kVideoFrameKey); | 
| 430 | 429 | 
| 431   stats_.bw_limited_resolution = | 430   stats_.bw_limited_resolution = | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
| 443   } | 442   } | 
| 444   if (encoded_image.adapt_reason_.bw_resolutions_disabled != -1) { | 443   if (encoded_image.adapt_reason_.bw_resolutions_disabled != -1) { | 
| 445     bool bw_limited = encoded_image.adapt_reason_.bw_resolutions_disabled > 0; | 444     bool bw_limited = encoded_image.adapt_reason_.bw_resolutions_disabled > 0; | 
| 446     uma_container_->bw_limited_frame_counter_.Add(bw_limited); | 445     uma_container_->bw_limited_frame_counter_.Add(bw_limited); | 
| 447     if (bw_limited) { | 446     if (bw_limited) { | 
| 448       uma_container_->bw_resolutions_disabled_counter_.Add( | 447       uma_container_->bw_resolutions_disabled_counter_.Add( | 
| 449           encoded_image.adapt_reason_.bw_resolutions_disabled); | 448           encoded_image.adapt_reason_.bw_resolutions_disabled); | 
| 450     } | 449     } | 
| 451   } | 450   } | 
| 452 | 451 | 
| 453   if (encoded_image.qp_ != -1 && rtp_video_header != nullptr && | 452   if (encoded_image.qp_ != -1 && rtp_video_header && | 
| 454       rtp_video_header->codec == kRtpVideoVp8) { | 453       rtp_video_header->codec == kRtpVideoVp8) { | 
| 455     int spatial_idx = | 454     int spatial_idx = | 
| 456         (config_.rtp.ssrcs.size() == 1) ? -1 : static_cast<int>(simulcast_idx); | 455         (config_.rtp.ssrcs.size() == 1) ? -1 : static_cast<int>(simulcast_idx); | 
| 457     uma_container_->qp_counters_[spatial_idx].vp8.Add(encoded_image.qp_); | 456     uma_container_->qp_counters_[spatial_idx].vp8.Add(encoded_image.qp_); | 
| 458   } | 457   } | 
| 459 | 458 | 
| 460   // TODO(asapersson): This is incorrect if simulcast layers are encoded on | 459   // TODO(asapersson): This is incorrect if simulcast layers are encoded on | 
| 461   // different threads and there is no guarantee that one frame of all layers | 460   // different threads and there is no guarantee that one frame of all layers | 
| 462   // are encoded before the next start. | 461   // are encoded before the next start. | 
| 463   if (last_sent_frame_timestamp_ > 0 && | 462   if (last_sent_frame_timestamp_ > 0 && | 
| (...skipping 20 matching lines...) Expand all  Loading... | 
| 484   uma_container_->input_frame_rate_tracker_.AddSamples(1); | 483   uma_container_->input_frame_rate_tracker_.AddSamples(1); | 
| 485   uma_container_->input_width_counter_.Add(width); | 484   uma_container_->input_width_counter_.Add(width); | 
| 486   uma_container_->input_height_counter_.Add(height); | 485   uma_container_->input_height_counter_.Add(height); | 
| 487 } | 486 } | 
| 488 | 487 | 
| 489 void SendStatisticsProxy::RtcpPacketTypesCounterUpdated( | 488 void SendStatisticsProxy::RtcpPacketTypesCounterUpdated( | 
| 490     uint32_t ssrc, | 489     uint32_t ssrc, | 
| 491     const RtcpPacketTypeCounter& packet_counter) { | 490     const RtcpPacketTypeCounter& packet_counter) { | 
| 492   rtc::CritScope lock(&crit_); | 491   rtc::CritScope lock(&crit_); | 
| 493   VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); | 492   VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); | 
| 494   if (stats == nullptr) | 493   if (!stats) | 
| 495     return; | 494     return; | 
| 496 | 495 | 
| 497   stats->rtcp_packet_type_counts = packet_counter; | 496   stats->rtcp_packet_type_counts = packet_counter; | 
| 498   if (uma_container_->first_rtcp_stats_time_ms_ == -1) | 497   if (uma_container_->first_rtcp_stats_time_ms_ == -1) | 
| 499     uma_container_->first_rtcp_stats_time_ms_ = clock_->TimeInMilliseconds(); | 498     uma_container_->first_rtcp_stats_time_ms_ = clock_->TimeInMilliseconds(); | 
| 500 } | 499 } | 
| 501 | 500 | 
| 502 void SendStatisticsProxy::StatisticsUpdated(const RtcpStatistics& statistics, | 501 void SendStatisticsProxy::StatisticsUpdated(const RtcpStatistics& statistics, | 
| 503                                             uint32_t ssrc) { | 502                                             uint32_t ssrc) { | 
| 504   rtc::CritScope lock(&crit_); | 503   rtc::CritScope lock(&crit_); | 
| 505   VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); | 504   VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); | 
| 506   if (stats == nullptr) | 505   if (!stats) | 
| 507     return; | 506     return; | 
| 508 | 507 | 
| 509   stats->rtcp_stats = statistics; | 508   stats->rtcp_stats = statistics; | 
| 510   uma_container_->report_block_stats_.Store(statistics, 0, ssrc); | 509   uma_container_->report_block_stats_.Store(statistics, 0, ssrc); | 
| 511 } | 510 } | 
| 512 | 511 | 
| 513 void SendStatisticsProxy::CNameChanged(const char* cname, uint32_t ssrc) {} | 512 void SendStatisticsProxy::CNameChanged(const char* cname, uint32_t ssrc) {} | 
| 514 | 513 | 
| 515 void SendStatisticsProxy::DataCountersUpdated( | 514 void SendStatisticsProxy::DataCountersUpdated( | 
| 516     const StreamDataCounters& counters, | 515     const StreamDataCounters& counters, | 
| 517     uint32_t ssrc) { | 516     uint32_t ssrc) { | 
| 518   rtc::CritScope lock(&crit_); | 517   rtc::CritScope lock(&crit_); | 
| 519   VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); | 518   VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); | 
| 520   RTC_DCHECK(stats != nullptr) | 519   RTC_DCHECK(stats) << "DataCountersUpdated reported for unknown ssrc: " | 
| 521       << "DataCountersUpdated reported for unknown ssrc: " << ssrc; | 520                     << ssrc; | 
| 522 | 521 | 
| 523   stats->rtp_stats = counters; | 522   stats->rtp_stats = counters; | 
| 524   if (uma_container_->first_rtp_stats_time_ms_ == -1) | 523   if (uma_container_->first_rtp_stats_time_ms_ == -1) | 
| 525     uma_container_->first_rtp_stats_time_ms_ = clock_->TimeInMilliseconds(); | 524     uma_container_->first_rtp_stats_time_ms_ = clock_->TimeInMilliseconds(); | 
| 526 } | 525 } | 
| 527 | 526 | 
| 528 void SendStatisticsProxy::Notify(const BitrateStatistics& total_stats, | 527 void SendStatisticsProxy::Notify(const BitrateStatistics& total_stats, | 
| 529                                  const BitrateStatistics& retransmit_stats, | 528                                  const BitrateStatistics& retransmit_stats, | 
| 530                                  uint32_t ssrc) { | 529                                  uint32_t ssrc) { | 
| 531   rtc::CritScope lock(&crit_); | 530   rtc::CritScope lock(&crit_); | 
| 532   VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); | 531   VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); | 
| 533   if (stats == nullptr) | 532   if (!stats) | 
| 534     return; | 533     return; | 
| 535 | 534 | 
| 536   stats->total_bitrate_bps = total_stats.bitrate_bps; | 535   stats->total_bitrate_bps = total_stats.bitrate_bps; | 
| 537   stats->retransmit_bitrate_bps = retransmit_stats.bitrate_bps; | 536   stats->retransmit_bitrate_bps = retransmit_stats.bitrate_bps; | 
| 538 } | 537 } | 
| 539 | 538 | 
| 540 void SendStatisticsProxy::FrameCountUpdated(const FrameCounts& frame_counts, | 539 void SendStatisticsProxy::FrameCountUpdated(const FrameCounts& frame_counts, | 
| 541                                             uint32_t ssrc) { | 540                                             uint32_t ssrc) { | 
| 542   rtc::CritScope lock(&crit_); | 541   rtc::CritScope lock(&crit_); | 
| 543   VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); | 542   VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); | 
| 544   if (stats == nullptr) | 543   if (!stats) | 
| 545     return; | 544     return; | 
| 546 | 545 | 
| 547   stats->frame_counts = frame_counts; | 546   stats->frame_counts = frame_counts; | 
| 548 } | 547 } | 
| 549 | 548 | 
| 550 void SendStatisticsProxy::SendSideDelayUpdated(int avg_delay_ms, | 549 void SendStatisticsProxy::SendSideDelayUpdated(int avg_delay_ms, | 
| 551                                                int max_delay_ms, | 550                                                int max_delay_ms, | 
| 552                                                uint32_t ssrc) { | 551                                                uint32_t ssrc) { | 
| 553   rtc::CritScope lock(&crit_); | 552   rtc::CritScope lock(&crit_); | 
| 554   VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); | 553   VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); | 
| 555   if (stats == nullptr) | 554   if (!stats) | 
| 556     return; | 555     return; | 
| 557   stats->avg_delay_ms = avg_delay_ms; | 556   stats->avg_delay_ms = avg_delay_ms; | 
| 558   stats->max_delay_ms = max_delay_ms; | 557   stats->max_delay_ms = max_delay_ms; | 
| 559 | 558 | 
| 560   uma_container_->delay_counter_.Add(avg_delay_ms); | 559   uma_container_->delay_counter_.Add(avg_delay_ms); | 
| 561   uma_container_->max_delay_counter_.Add(max_delay_ms); | 560   uma_container_->max_delay_counter_.Add(max_delay_ms); | 
| 562 } | 561 } | 
| 563 | 562 | 
| 564 void SendStatisticsProxy::SampleCounter::Add(int sample) { | 563 void SendStatisticsProxy::SampleCounter::Add(int sample) { | 
| 565   sum += sample; | 564   sum += sample; | 
| (...skipping 22 matching lines...) Expand all  Loading... | 
| 588   return Fraction(min_required_samples, 1000.0f); | 587   return Fraction(min_required_samples, 1000.0f); | 
| 589 } | 588 } | 
| 590 | 589 | 
| 591 int SendStatisticsProxy::BoolSampleCounter::Fraction( | 590 int SendStatisticsProxy::BoolSampleCounter::Fraction( | 
| 592     int min_required_samples, float multiplier) const { | 591     int min_required_samples, float multiplier) const { | 
| 593   if (num_samples < min_required_samples || num_samples == 0) | 592   if (num_samples < min_required_samples || num_samples == 0) | 
| 594     return -1; | 593     return -1; | 
| 595   return static_cast<int>((sum * multiplier / num_samples) + 0.5f); | 594   return static_cast<int>((sum * multiplier / num_samples) + 0.5f); | 
| 596 } | 595 } | 
| 597 }  // namespace webrtc | 596 }  // namespace webrtc | 
| OLD | NEW | 
|---|