File: delay_manager.h

package info (click to toggle)
thunderbird 1%3A140.2.0esr-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 4,608,024 kB
  • sloc: cpp: 7,671,407; javascript: 5,900,746; ansic: 3,898,904; python: 1,413,115; xml: 653,997; asm: 462,286; java: 180,948; sh: 113,489; makefile: 20,460; perl: 14,288; objc: 13,059; yacc: 4,583; pascal: 3,352; lex: 1,720; ruby: 1,222; exp: 762; sql: 715; awk: 580; php: 436; lisp: 430; sed: 70; csh: 10
file content (69 lines) | stat: -rw-r--r-- 2,249 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
 *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#ifndef MODULES_AUDIO_CODING_NETEQ_DELAY_MANAGER_H_
#define MODULES_AUDIO_CODING_NETEQ_DELAY_MANAGER_H_

#include <memory>
#include <optional>

#include "api/field_trials_view.h"
#include "api/neteq/tick_timer.h"
#include "modules/audio_coding/neteq/reorder_optimizer.h"
#include "modules/audio_coding/neteq/underrun_optimizer.h"

namespace webrtc {

class DelayManager {
 public:
  struct Config {
    explicit Config(const FieldTrialsView& field_trials);
    void Log();

    // Options that can be configured via field trial.
    double quantile = 0.95;
    double forget_factor = 0.983;
    std::optional<double> start_forget_weight = 2;
    std::optional<int> resample_interval_ms = 500;

    bool use_reorder_optimizer = true;
    double reorder_forget_factor = 0.9993;
    int ms_per_loss_percent = 20;
  };

  DelayManager(const Config& config, const TickTimer* tick_timer);

  virtual ~DelayManager();

  DelayManager(const DelayManager&) = delete;
  DelayManager& operator=(const DelayManager&) = delete;

  // Updates the delay manager that a new packet arrived with delay
  // `arrival_delay_ms`. This updates the statistics and a new target buffer
  // level is calculated. The `reordered` flag indicates if the packet was
  // reordered.
  virtual void Update(int arrival_delay_ms, bool reordered);

  // Resets all state.
  virtual void Reset();

  // Gets the target buffer level in milliseconds. If a minimum or maximum delay
  // has been set, the target delay reported here also respects the configured
  // min/max delay.
  virtual int TargetDelayMs() const;

 private:
  UnderrunOptimizer underrun_optimizer_;
  std::unique_ptr<ReorderOptimizer> reorder_optimizer_;
  int target_level_ms_ = 0;  // Currently preferred buffer level.
};

}  // namespace webrtc
#endif  // MODULES_AUDIO_CODING_NETEQ_DELAY_MANAGER_H_