blob: ff2526025a87faafafe67dd09c30b9f747c535bc [file] [log] [blame]
Per Åhgren39f491e2018-02-22 00:39:23 +01001/*
2 * Copyright (c) 2018 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_PROCESSING_AEC3_SKEW_ESTIMATOR_H_
12#define MODULES_AUDIO_PROCESSING_AEC3_SKEW_ESTIMATOR_H_
13
14#include <vector>
15
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +020016#include "absl/types/optional.h"
Per Åhgren39f491e2018-02-22 00:39:23 +010017#include "rtc_base/constructormagic.h"
18
19namespace webrtc {
20
21// Estimator of API call skew between render and capture.
22class SkewEstimator {
23 public:
24 explicit SkewEstimator(size_t skew_history_size_log2);
25 ~SkewEstimator();
26
27 // Resets the estimation.
28 void Reset();
29
30 // Updates the skew data for a render call.
31 void LogRenderCall() { ++skew_; }
32
33 // Updates and computes the skew at a capture call. Returns an optional which
34 // is non-null if a reliable skew has been found.
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +020035 absl::optional<int> GetSkewFromCapture();
Per Åhgren39f491e2018-02-22 00:39:23 +010036
37 private:
38 const int skew_history_size_log2_;
39 std::vector<float> skew_history_;
40 int skew_ = 0;
41 int skew_sum_ = 0;
42 size_t next_index_ = 0;
43 bool sufficient_skew_stored_ = false;
44
45 RTC_DISALLOW_COPY_AND_ASSIGN(SkewEstimator);
46};
47
48} // namespace webrtc
49
50#endif // MODULES_AUDIO_PROCESSING_AEC3_SKEW_ESTIMATOR_H_