• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2020 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_TEST_AUDIO_PROCESSING_BUILDER_FOR_TESTING_H_
12 #define MODULES_AUDIO_PROCESSING_TEST_AUDIO_PROCESSING_BUILDER_FOR_TESTING_H_
13 
14 #include <list>
15 #include <memory>
16 #include <utility>
17 #include <vector>
18 
19 #include "modules/audio_processing/include/audio_processing.h"
20 
21 namespace webrtc {
22 
23 // Facilitates building of AudioProcessingImp for the tests.
24 class AudioProcessingBuilderForTesting {
25  public:
26   AudioProcessingBuilderForTesting();
27   ~AudioProcessingBuilderForTesting();
28   // The AudioProcessingBuilderForTesting takes ownership of the
29   // echo_control_factory.
SetEchoControlFactory(std::unique_ptr<EchoControlFactory> echo_control_factory)30   AudioProcessingBuilderForTesting& SetEchoControlFactory(
31       std::unique_ptr<EchoControlFactory> echo_control_factory) {
32     echo_control_factory_ = std::move(echo_control_factory);
33     return *this;
34   }
35   // The AudioProcessingBuilderForTesting takes ownership of the
36   // capture_post_processing.
SetCapturePostProcessing(std::unique_ptr<CustomProcessing> capture_post_processing)37   AudioProcessingBuilderForTesting& SetCapturePostProcessing(
38       std::unique_ptr<CustomProcessing> capture_post_processing) {
39     capture_post_processing_ = std::move(capture_post_processing);
40     return *this;
41   }
42   // The AudioProcessingBuilderForTesting takes ownership of the
43   // render_pre_processing.
SetRenderPreProcessing(std::unique_ptr<CustomProcessing> render_pre_processing)44   AudioProcessingBuilderForTesting& SetRenderPreProcessing(
45       std::unique_ptr<CustomProcessing> render_pre_processing) {
46     render_pre_processing_ = std::move(render_pre_processing);
47     return *this;
48   }
49   // The AudioProcessingBuilderForTesting takes ownership of the echo_detector.
SetEchoDetector(rtc::scoped_refptr<EchoDetector> echo_detector)50   AudioProcessingBuilderForTesting& SetEchoDetector(
51       rtc::scoped_refptr<EchoDetector> echo_detector) {
52     echo_detector_ = std::move(echo_detector);
53     return *this;
54   }
55   // The AudioProcessingBuilderForTesting takes ownership of the
56   // capture_analyzer.
SetCaptureAnalyzer(std::unique_ptr<CustomAudioAnalyzer> capture_analyzer)57   AudioProcessingBuilderForTesting& SetCaptureAnalyzer(
58       std::unique_ptr<CustomAudioAnalyzer> capture_analyzer) {
59     capture_analyzer_ = std::move(capture_analyzer);
60     return *this;
61   }
62   // This creates an APM instance using the previously set components. Calling
63   // the Create function resets the AudioProcessingBuilderForTesting to its
64   // initial state.
65   AudioProcessing* Create();
66   AudioProcessing* Create(const webrtc::Config& config);
67 
68  private:
69   // Transfers the ownership to a non-testing builder.
70   void TransferOwnershipsToBuilder(AudioProcessingBuilder* builder);
71 
72   std::unique_ptr<EchoControlFactory> echo_control_factory_;
73   std::unique_ptr<CustomProcessing> capture_post_processing_;
74   std::unique_ptr<CustomProcessing> render_pre_processing_;
75   rtc::scoped_refptr<EchoDetector> echo_detector_;
76   std::unique_ptr<CustomAudioAnalyzer> capture_analyzer_;
77 };
78 
79 }  // namespace webrtc
80 
81 #endif  // MODULES_AUDIO_PROCESSING_TEST_AUDIO_PROCESSING_BUILDER_FOR_TESTING_H_
82