tor-browser

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

underrun_optimizer.h (1668B)


      1 /*
      2 *  Copyright (c) 2021 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 #ifndef MODULES_AUDIO_CODING_NETEQ_UNDERRUN_OPTIMIZER_H_
     12 #define MODULES_AUDIO_CODING_NETEQ_UNDERRUN_OPTIMIZER_H_
     13 
     14 #include <memory>
     15 #include <optional>
     16 
     17 #include "api/neteq/tick_timer.h"
     18 #include "modules/audio_coding/neteq/histogram.h"
     19 
     20 namespace webrtc {
     21 
     22 // Estimates probability of buffer underrun due to late packet arrival.
     23 // The optimal delay is decided such that the probability of underrun is lower
     24 // than 1 - `histogram_quantile`.
     25 class UnderrunOptimizer {
     26 public:
     27  UnderrunOptimizer(const TickTimer* tick_timer,
     28                    int histogram_quantile,
     29                    int forget_factor,
     30                    std::optional<int> start_forget_weight,
     31                    std::optional<int> resample_interval_ms);
     32 
     33  void Update(int relative_delay_ms);
     34 
     35  std::optional<int> GetOptimalDelayMs() const { return optimal_delay_ms_; }
     36 
     37  void Reset();
     38 
     39 private:
     40  const TickTimer* tick_timer_;
     41  Histogram histogram_;
     42  const int histogram_quantile_;  // In Q30.
     43  const std::optional<int> resample_interval_ms_;
     44  std::unique_ptr<TickTimer::Stopwatch> resample_stopwatch_;
     45  int max_delay_in_interval_ms_ = 0;
     46  std::optional<int> optimal_delay_ms_;
     47 };
     48 
     49 }  // namespace webrtc
     50 #endif  // MODULES_AUDIO_CODING_NETEQ_UNDERRUN_OPTIMIZER_H_