Per Åhgren | 39f491e | 2018-02-22 00:39:23 +0100 | [diff] [blame] | 1 | /* |
| 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 Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame^] | 14 | #include <stddef.h> |
Per Åhgren | 39f491e | 2018-02-22 00:39:23 +0100 | [diff] [blame] | 15 | #include <vector> |
| 16 | |
Danil Chapovalov | db9f7ab | 2018-06-19 10:50:11 +0200 | [diff] [blame] | 17 | #include "absl/types/optional.h" |
Per Åhgren | 39f491e | 2018-02-22 00:39:23 +0100 | [diff] [blame] | 18 | #include "rtc_base/constructormagic.h" |
| 19 | |
| 20 | namespace webrtc { |
| 21 | |
| 22 | // Estimator of API call skew between render and capture. |
| 23 | class 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 Chapovalov | db9f7ab | 2018-06-19 10:50:11 +0200 | [diff] [blame] | 36 | absl::optional<int> GetSkewFromCapture(); |
Per Åhgren | 39f491e | 2018-02-22 00:39:23 +0100 | [diff] [blame] | 37 | |
| 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_ |