xref: /aosp_15_r20/external/webrtc/modules/audio_processing/include/aec_dump.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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_INCLUDE_AEC_DUMP_H_
12 #define MODULES_AUDIO_PROCESSING_INCLUDE_AEC_DUMP_H_
13 
14 #include <stdint.h>
15 
16 #include <string>
17 
18 #include "absl/base/attributes.h"
19 #include "absl/types/optional.h"
20 #include "modules/audio_processing/include/audio_frame_view.h"
21 #include "modules/audio_processing/include/audio_processing.h"
22 
23 namespace webrtc {
24 
25 // Struct for passing current config from APM without having to
26 // include protobuf headers.
27 struct InternalAPMConfig {
28   InternalAPMConfig();
29   InternalAPMConfig(const InternalAPMConfig&);
30   InternalAPMConfig(InternalAPMConfig&&);
31 
32   InternalAPMConfig& operator=(const InternalAPMConfig&);
33   InternalAPMConfig& operator=(InternalAPMConfig&&) = delete;
34 
35   bool operator==(const InternalAPMConfig& other) const;
36 
37   bool aec_enabled = false;
38   bool aec_delay_agnostic_enabled = false;
39   bool aec_drift_compensation_enabled = false;
40   bool aec_extended_filter_enabled = false;
41   int aec_suppression_level = 0;
42   bool aecm_enabled = false;
43   bool aecm_comfort_noise_enabled = false;
44   int aecm_routing_mode = 0;
45   bool agc_enabled = false;
46   int agc_mode = 0;
47   bool agc_limiter_enabled = false;
48   bool hpf_enabled = false;
49   bool ns_enabled = false;
50   int ns_level = 0;
51   bool transient_suppression_enabled = false;
52   bool noise_robust_agc_enabled = false;
53   bool pre_amplifier_enabled = false;
54   float pre_amplifier_fixed_gain_factor = 1.f;
55   std::string experiments_description = "";
56 };
57 
58 // An interface for recording configuration and input/output streams
59 // of the Audio Processing Module. The recordings are called
60 // 'aec-dumps' and are stored in a protobuf format defined in
61 // debug.proto.
62 // The Write* methods are always safe to call concurrently or
63 // otherwise for all implementing subclasses. The intended mode of
64 // operation is to create a protobuf object from the input, and send
65 // it away to be written to file asynchronously.
66 class AecDump {
67  public:
68   struct AudioProcessingState {
69     int delay;
70     int drift;
71     absl::optional<int> applied_input_volume;
72     bool keypress;
73   };
74 
75   virtual ~AecDump() = default;
76 
77   // Logs Event::Type INIT message.
78   virtual void WriteInitMessage(const ProcessingConfig& api_format,
79                                 int64_t time_now_ms) = 0;
80   ABSL_DEPRECATED("")
WriteInitMessage(const ProcessingConfig & api_format)81   void WriteInitMessage(const ProcessingConfig& api_format) {
82     WriteInitMessage(api_format, 0);
83   }
84 
85   // Logs Event::Type STREAM message. To log an input/output pair,
86   // call the AddCapture* and AddAudioProcessingState methods followed
87   // by a WriteCaptureStreamMessage call.
88   virtual void AddCaptureStreamInput(
89       const AudioFrameView<const float>& src) = 0;
90   virtual void AddCaptureStreamOutput(
91       const AudioFrameView<const float>& src) = 0;
92   virtual void AddCaptureStreamInput(const int16_t* const data,
93                                      int num_channels,
94                                      int samples_per_channel) = 0;
95   virtual void AddCaptureStreamOutput(const int16_t* const data,
96                                       int num_channels,
97                                       int samples_per_channel) = 0;
98   virtual void AddAudioProcessingState(const AudioProcessingState& state) = 0;
99   virtual void WriteCaptureStreamMessage() = 0;
100 
101   // Logs Event::Type REVERSE_STREAM message.
102   virtual void WriteRenderStreamMessage(const int16_t* const data,
103                                         int num_channels,
104                                         int samples_per_channel) = 0;
105   virtual void WriteRenderStreamMessage(
106       const AudioFrameView<const float>& src) = 0;
107 
108   virtual void WriteRuntimeSetting(
109       const AudioProcessing::RuntimeSetting& runtime_setting) = 0;
110 
111   // Logs Event::Type CONFIG message.
112   virtual void WriteConfig(const InternalAPMConfig& config) = 0;
113 };
114 }  // namespace webrtc
115 
116 #endif  // MODULES_AUDIO_PROCESSING_INCLUDE_AEC_DUMP_H_
117