blob: 06f6bc7e50659e3ecc7102c76d3e6a8a6a701fea [file] [log] [blame]
Jakob Ivarsson58ed02e2021-09-08 16:35:50 +02001/*
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_REORDER_OPTIMIZER_H_
12#define MODULES_AUDIO_CODING_NETEQ_REORDER_OPTIMIZER_H_
13
14#include "absl/types/optional.h"
15#include "modules/audio_coding/neteq/histogram.h"
16
17namespace webrtc {
18
19// Calculates an optimal delay to reduce the chance of missing reordered
20// packets. The delay/loss trade-off can be tune using the `ms_per_loss_percent`
21// parameter.
22class ReorderOptimizer {
23 public:
24 ReorderOptimizer(int forget_factor,
25 int ms_per_loss_percent,
26 absl::optional<int> start_forget_weight);
27
28 void Update(int relative_delay_ms, bool reordered, int base_delay_ms);
29
30 absl::optional<int> GetOptimalDelayMs() const { return optimal_delay_ms_; }
31
32 void Reset();
33
34 private:
35 int MinimizeCostFunction(int base_delay_ms) const;
36
37 Histogram histogram_;
38 const int ms_per_loss_percent_;
39 absl::optional<int> optimal_delay_ms_;
40};
41
42} // namespace webrtc
43#endif // MODULES_AUDIO_CODING_NETEQ_REORDER_OPTIMIZER_H_