xref: /aosp_15_r20/external/webrtc/modules/audio_coding/neteq/reorder_optimizer.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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_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 
17 namespace 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.
22 class 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 
GetOptimalDelayMs()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_
44