blob: b0946d833e543a872a6ab23c7ddf028d9ecca651 [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
Yves Gerey988cc082018-10-23 12:03:01 +020014#include <stddef.h>
Per Åhgren39f491e2018-02-22 00:39:23 +010015#include <vector>
16
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +020017#include "absl/types/optional.h"
Per Åhgren39f491e2018-02-22 00:39:23 +010018#include "rtc_base/constructormagic.h"
19
20namespace webrtc {
21
22// Estimator of API call skew between render and capture.
23class SkewEstimator {
24 public:
25 explicit SkewEstimator(size_t skew_history_size_log2);
26 ~SkewEstimator();
27
28 // Resets the estimation.
29 void Reset();
30
31 // Updates the skew data for a render call.
32 void LogRenderCall() { ++skew_; }
33
34 // Updates and computes the skew at a capture call. Returns an optional which
35 // is non-null if a reliable skew has been found.
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +020036 absl::optional<int> GetSkewFromCapture();
Per Åhgren39f491e2018-02-22 00:39:23 +010037
38 private:
39 const int skew_history_size_log2_;
40 std::vector<float> skew_history_;
41 int skew_ = 0;
42 int skew_sum_ = 0;
43 size_t next_index_ = 0;
44 bool sufficient_skew_stored_ = false;
45
46 RTC_DISALLOW_COPY_AND_ASSIGN(SkewEstimator);
47};
48
49} // namespace webrtc
50
51#endif // MODULES_AUDIO_PROCESSING_AEC3_SKEW_ESTIMATOR_H_