1 /*
2  *  Copyright (c) 2017 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_MATCHED_FILTER_LAG_AGGREGATOR_H_
12 #define MODULES_AUDIO_PROCESSING_AEC3_MATCHED_FILTER_LAG_AGGREGATOR_H_
13 
14 #include <vector>
15 
16 #include "api/optional.h"
17 #include "modules/audio_processing/aec3/matched_filter.h"
18 #include "rtc_base/constructormagic.h"
19 
20 namespace webrtc {
21 
22 class ApmDataDumper;
23 
24 // Aggregates lag estimates produced by the MatchedFilter class into a single
25 // reliable combined lag estimate.
26 class MatchedFilterLagAggregator {
27  public:
28   MatchedFilterLagAggregator(ApmDataDumper* data_dumper, size_t max_filter_lag);
29   ~MatchedFilterLagAggregator();
30 
31   // Resets the aggregator.
32   void Reset();
33 
34   // Aggregates the provided lag estimates.
35   rtc::Optional<size_t> Aggregate(
36       rtc::ArrayView<const MatchedFilter::LagEstimate> lag_estimates);
37 
38  private:
39   ApmDataDumper* const data_dumper_;
40   std::vector<int> histogram_;
41   std::array<int, 250> histogram_data_;
42   int histogram_data_index_ = 0;
43 
44   RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(MatchedFilterLagAggregator);
45 };
46 }  // namespace webrtc
47 
48 #endif  // MODULES_AUDIO_PROCESSING_AEC3_MATCHED_FILTER_LAG_AGGREGATOR_H_
49