xref: /aosp_15_r20/external/webrtc/modules/audio_processing/test/aec_dump_based_simulator.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2016 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_AEC_DUMP_BASED_SIMULATOR_H_
12 #define MODULES_AUDIO_PROCESSING_TEST_AEC_DUMP_BASED_SIMULATOR_H_
13 
14 #include <fstream>
15 #include <string>
16 
17 #include "modules/audio_processing/test/audio_processing_simulator.h"
18 #include "rtc_base/ignore_wundef.h"
19 
20 RTC_PUSH_IGNORING_WUNDEF()
21 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD
22 #include "external/webrtc/webrtc/modules/audio_processing/debug.pb.h"
23 #else
24 #include "modules/audio_processing/debug.pb.h"
25 #endif
RTC_POP_IGNORING_WUNDEF()26 RTC_POP_IGNORING_WUNDEF()
27 
28 namespace webrtc {
29 namespace test {
30 
31 // Used to perform an audio processing simulation from an aec dump.
32 class AecDumpBasedSimulator final : public AudioProcessingSimulator {
33  public:
34   AecDumpBasedSimulator(const SimulationSettings& settings,
35                         rtc::scoped_refptr<AudioProcessing> audio_processing,
36                         std::unique_ptr<AudioProcessingBuilder> ap_builder);
37 
38   AecDumpBasedSimulator() = delete;
39   AecDumpBasedSimulator(const AecDumpBasedSimulator&) = delete;
40   AecDumpBasedSimulator& operator=(const AecDumpBasedSimulator&) = delete;
41 
42   ~AecDumpBasedSimulator() override;
43 
44   // Processes the messages in the aecdump file.
45   void Process() override;
46 
47   // Analyzes the data in the aecdump file and reports the resulting statistics.
48   void Analyze() override;
49 
50  private:
51   void HandleEvent(const webrtc::audioproc::Event& event_msg,
52                    int& num_forward_chunks_processed,
53                    int& init_index);
54   void HandleMessage(const webrtc::audioproc::Init& msg, int init_index);
55   void HandleMessage(const webrtc::audioproc::Stream& msg);
56   void HandleMessage(const webrtc::audioproc::ReverseStream& msg);
57   void HandleMessage(const webrtc::audioproc::Config& msg);
58   void HandleMessage(const webrtc::audioproc::RuntimeSetting& msg);
59   void PrepareProcessStreamCall(const webrtc::audioproc::Stream& msg);
60   void PrepareReverseProcessStreamCall(
61       const webrtc::audioproc::ReverseStream& msg);
62   void VerifyProcessStreamBitExactness(const webrtc::audioproc::Stream& msg);
63   void MaybeOpenCallOrderFile();
64   enum InterfaceType {
65     kFixedInterface,
66     kFloatInterface,
67     kNotSpecified,
68   };
69 
70   FILE* dump_input_file_;
71   std::unique_ptr<ChannelBuffer<float>> artificial_nearend_buf_;
72   std::unique_ptr<ChannelBufferWavReader> artificial_nearend_buffer_reader_;
73   bool artificial_nearend_eof_reported_ = false;
74   InterfaceType interface_used_ = InterfaceType::kNotSpecified;
75   std::unique_ptr<std::ofstream> call_order_output_file_;
76   bool finished_processing_specified_init_block_ = false;
77 };
78 
79 }  // namespace test
80 }  // namespace webrtc
81 
82 #endif  // MODULES_AUDIO_PROCESSING_TEST_AEC_DUMP_BASED_SIMULATOR_H_
83