tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

api_call_jitter_metrics.cc (4062B)


      1 /*
      2 *  Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
      3 *
      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
      6 *  tree. An additional intellectual property rights grant can be found
      7 *  in the file PATENTS.  All contributing project authors may
      8 *  be found in the AUTHORS file in the root of the source tree.
      9 */
     10 
     11 #include "modules/audio_processing/aec3/api_call_jitter_metrics.h"
     12 
     13 #include <algorithm>
     14 #include <limits>
     15 
     16 #include "system_wrappers/include/metrics.h"
     17 
     18 namespace webrtc {
     19 namespace {
     20 
     21 bool TimeToReportMetrics(int frames_since_last_report) {
     22  constexpr int kNumFramesPerSecond = 100;
     23  constexpr int kReportingIntervalFrames = 10 * kNumFramesPerSecond;
     24  return frames_since_last_report == kReportingIntervalFrames;
     25 }
     26 
     27 }  // namespace
     28 
     29 ApiCallJitterMetrics::Jitter::Jitter()
     30    : max_(0), min_(std::numeric_limits<int>::max()) {}
     31 
     32 void ApiCallJitterMetrics::Jitter::Update(int num_api_calls_in_a_row) {
     33  min_ = std::min(min_, num_api_calls_in_a_row);
     34  max_ = std::max(max_, num_api_calls_in_a_row);
     35 }
     36 
     37 void ApiCallJitterMetrics::Jitter::Reset() {
     38  min_ = std::numeric_limits<int>::max();
     39  max_ = 0;
     40 }
     41 
     42 void ApiCallJitterMetrics::Reset() {
     43  render_jitter_.Reset();
     44  capture_jitter_.Reset();
     45  num_api_calls_in_a_row_ = 0;
     46  frames_since_last_report_ = 0;
     47  last_call_was_render_ = false;
     48  proper_call_observed_ = false;
     49 }
     50 
     51 void ApiCallJitterMetrics::ReportRenderCall() {
     52  if (!last_call_was_render_) {
     53    // If the previous call was a capture and a proper call has been observed
     54    // (containing both render and capture data), storing the last number of
     55    // capture calls into the metrics.
     56    if (proper_call_observed_) {
     57      capture_jitter_.Update(num_api_calls_in_a_row_);
     58    }
     59 
     60    // Reset the call counter to start counting render calls.
     61    num_api_calls_in_a_row_ = 0;
     62  }
     63  ++num_api_calls_in_a_row_;
     64  last_call_was_render_ = true;
     65 }
     66 
     67 void ApiCallJitterMetrics::ReportCaptureCall() {
     68  if (last_call_was_render_) {
     69    // If the previous call was a render and a proper call has been observed
     70    // (containing both render and capture data), storing the last number of
     71    // render calls into the metrics.
     72    if (proper_call_observed_) {
     73      render_jitter_.Update(num_api_calls_in_a_row_);
     74    }
     75    // Reset the call counter to start counting capture calls.
     76    num_api_calls_in_a_row_ = 0;
     77 
     78    // If this statement is reached, at least one render and one capture call
     79    // have been observed.
     80    proper_call_observed_ = true;
     81  }
     82  ++num_api_calls_in_a_row_;
     83  last_call_was_render_ = false;
     84 
     85  // Only report and update jitter metrics for when a proper call, containing
     86  // both render and capture data, has been observed.
     87  if (proper_call_observed_ &&
     88      TimeToReportMetrics(++frames_since_last_report_)) {
     89    // Report jitter, where the base basic unit is frames.
     90    constexpr int kMaxJitterToReport = 50;
     91 
     92    // Report max and min jitter for render and capture, in units of 20 ms.
     93    RTC_HISTOGRAM_COUNTS_LINEAR(
     94        "WebRTC.Audio.EchoCanceller.MaxRenderJitter",
     95        std::min(kMaxJitterToReport, render_jitter().max()), 1,
     96        kMaxJitterToReport, kMaxJitterToReport);
     97    RTC_HISTOGRAM_COUNTS_LINEAR(
     98        "WebRTC.Audio.EchoCanceller.MinRenderJitter",
     99        std::min(kMaxJitterToReport, render_jitter().min()), 1,
    100        kMaxJitterToReport, kMaxJitterToReport);
    101 
    102    RTC_HISTOGRAM_COUNTS_LINEAR(
    103        "WebRTC.Audio.EchoCanceller.MaxCaptureJitter",
    104        std::min(kMaxJitterToReport, capture_jitter().max()), 1,
    105        kMaxJitterToReport, kMaxJitterToReport);
    106    RTC_HISTOGRAM_COUNTS_LINEAR(
    107        "WebRTC.Audio.EchoCanceller.MinCaptureJitter",
    108        std::min(kMaxJitterToReport, capture_jitter().min()), 1,
    109        kMaxJitterToReport, kMaxJitterToReport);
    110 
    111    frames_since_last_report_ = 0;
    112    Reset();
    113  }
    114 }
    115 
    116 bool ApiCallJitterMetrics::WillReportMetricsAtNextCapture() const {
    117  return TimeToReportMetrics(frames_since_last_report_ + 1);
    118 }
    119 
    120 }  // namespace webrtc