tor-browser

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

delay_manager.h (2450B)


      1 /*
      2 *  Copyright (c) 2012 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_DELAY_MANAGER_H_
     12 #define MODULES_AUDIO_CODING_NETEQ_DELAY_MANAGER_H_
     13 
     14 #include <memory>
     15 #include <optional>
     16 
     17 #include "api/field_trials_view.h"
     18 #include "api/neteq/delay_manager_interface.h"
     19 #include "api/neteq/neteq_controller.h"
     20 #include "api/neteq/tick_timer.h"
     21 #include "modules/audio_coding/neteq/reorder_optimizer.h"
     22 #include "modules/audio_coding/neteq/underrun_optimizer.h"
     23 
     24 namespace webrtc {
     25 
     26 class DelayManager : public DelayManagerInterface {
     27 public:
     28  struct Config {
     29    explicit Config(const FieldTrialsView& field_trials);
     30    void Log();
     31 
     32    // Options that can be configured via field trial.
     33    double quantile = 0.95;
     34    double forget_factor = 0.983;
     35    std::optional<double> start_forget_weight = 2;
     36    std::optional<int> resample_interval_ms = 500;
     37 
     38    bool use_reorder_optimizer = true;
     39    double reorder_forget_factor = 0.9993;
     40    int ms_per_loss_percent = 20;
     41  };
     42 
     43  DelayManager(const Config& config, const TickTimer* tick_timer);
     44 
     45  ~DelayManager() override = default;
     46 
     47  DelayManager(const DelayManager&) = delete;
     48  DelayManager& operator=(const DelayManager&) = delete;
     49 
     50  // Updates the delay manager that a new packet arrived with delay
     51  // `arrival_delay_ms`. This updates the statistics and a new target buffer
     52  // level is calculated. The `reordered` flag indicates if the packet was
     53  // reordered.
     54  void Update(int arrival_delay_ms,
     55              bool reordered,
     56              NetEqController::PacketArrivedInfo info) override;
     57 
     58  // Resets all state.
     59  void Reset() override;
     60 
     61  // Gets the target buffer level in milliseconds. If a minimum or maximum delay
     62  // has been set, the target delay reported here also respects the configured
     63  // min/max delay.
     64  int TargetDelayMs() const override;
     65 
     66 private:
     67  UnderrunOptimizer underrun_optimizer_;
     68  std::unique_ptr<ReorderOptimizer> reorder_optimizer_;
     69  int target_level_ms_ = 0;  // Currently preferred buffer level.
     70 };
     71 
     72 }  // namespace webrtc
     73 #endif  // MODULES_AUDIO_CODING_NETEQ_DELAY_MANAGER_H_