audio_processing_impl.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. /*
  2. * Copyright (c) 2012 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. #ifndef MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_
  11. #define MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_
  12. #include <stdio.h>
  13. #include <list>
  14. #include <memory>
  15. #include <string>
  16. #include <vector>
  17. #include "api/function_view.h"
  18. #include "modules/audio_processing/aec3/echo_canceller3.h"
  19. #include "modules/audio_processing/agc/agc_manager_direct.h"
  20. #include "modules/audio_processing/agc/gain_control.h"
  21. #include "modules/audio_processing/audio_buffer.h"
  22. #include "modules/audio_processing/echo_control_mobile_impl.h"
  23. #include "modules/audio_processing/gain_control_impl.h"
  24. #include "modules/audio_processing/gain_controller2.h"
  25. #include "modules/audio_processing/high_pass_filter.h"
  26. #include "modules/audio_processing/include/aec_dump.h"
  27. #include "modules/audio_processing/include/audio_frame_proxies.h"
  28. #include "modules/audio_processing/include/audio_processing.h"
  29. #include "modules/audio_processing/include/audio_processing_statistics.h"
  30. #include "modules/audio_processing/level_estimator.h"
  31. #include "modules/audio_processing/ns/noise_suppressor.h"
  32. #include "modules/audio_processing/optionally_built_submodule_creators.h"
  33. #include "modules/audio_processing/render_queue_item_verifier.h"
  34. #include "modules/audio_processing/residual_echo_detector.h"
  35. #include "modules/audio_processing/rms_level.h"
  36. #include "modules/audio_processing/transient/transient_suppressor.h"
  37. #include "modules/audio_processing/voice_detection.h"
  38. #include "rtc_base/gtest_prod_util.h"
  39. #include "rtc_base/ignore_wundef.h"
  40. #include "rtc_base/swap_queue.h"
  41. #include "rtc_base/synchronization/mutex.h"
  42. #include "rtc_base/thread_annotations.h"
  43. namespace webrtc {
  44. class ApmDataDumper;
  45. class AudioConverter;
  46. class AudioProcessingImpl : public AudioProcessing {
  47. public:
  48. // Methods forcing APM to run in a single-threaded manner.
  49. // Acquires both the render and capture locks.
  50. explicit AudioProcessingImpl(const webrtc::Config& config);
  51. // AudioProcessingImpl takes ownership of capture post processor.
  52. AudioProcessingImpl(const webrtc::Config& config,
  53. std::unique_ptr<CustomProcessing> capture_post_processor,
  54. std::unique_ptr<CustomProcessing> render_pre_processor,
  55. std::unique_ptr<EchoControlFactory> echo_control_factory,
  56. rtc::scoped_refptr<EchoDetector> echo_detector,
  57. std::unique_ptr<CustomAudioAnalyzer> capture_analyzer);
  58. ~AudioProcessingImpl() override;
  59. int Initialize() override;
  60. int Initialize(int capture_input_sample_rate_hz,
  61. int capture_output_sample_rate_hz,
  62. int render_sample_rate_hz,
  63. ChannelLayout capture_input_layout,
  64. ChannelLayout capture_output_layout,
  65. ChannelLayout render_input_layout) override;
  66. int Initialize(const ProcessingConfig& processing_config) override;
  67. void ApplyConfig(const AudioProcessing::Config& config) override;
  68. bool CreateAndAttachAecDump(const std::string& file_name,
  69. int64_t max_log_size_bytes,
  70. rtc::TaskQueue* worker_queue) override;
  71. bool CreateAndAttachAecDump(FILE* handle,
  72. int64_t max_log_size_bytes,
  73. rtc::TaskQueue* worker_queue) override;
  74. // TODO(webrtc:5298) Deprecated variant.
  75. void AttachAecDump(std::unique_ptr<AecDump> aec_dump) override;
  76. void DetachAecDump() override;
  77. void SetRuntimeSetting(RuntimeSetting setting) override;
  78. // Capture-side exclusive methods possibly running APM in a
  79. // multi-threaded manner. Acquire the capture lock.
  80. int ProcessStream(const int16_t* const src,
  81. const StreamConfig& input_config,
  82. const StreamConfig& output_config,
  83. int16_t* const dest) override;
  84. int ProcessStream(const float* const* src,
  85. const StreamConfig& input_config,
  86. const StreamConfig& output_config,
  87. float* const* dest) override;
  88. bool GetLinearAecOutput(
  89. rtc::ArrayView<std::array<float, 160>> linear_output) const override;
  90. void set_output_will_be_muted(bool muted) override;
  91. int set_stream_delay_ms(int delay) override;
  92. void set_stream_key_pressed(bool key_pressed) override;
  93. void set_stream_analog_level(int level) override;
  94. int recommended_stream_analog_level() const
  95. RTC_LOCKS_EXCLUDED(mutex_capture_) override;
  96. // Render-side exclusive methods possibly running APM in a
  97. // multi-threaded manner. Acquire the render lock.
  98. int ProcessReverseStream(const int16_t* const src,
  99. const StreamConfig& input_config,
  100. const StreamConfig& output_config,
  101. int16_t* const dest) override;
  102. int AnalyzeReverseStream(const float* const* data,
  103. const StreamConfig& reverse_config) override;
  104. int ProcessReverseStream(const float* const* src,
  105. const StreamConfig& input_config,
  106. const StreamConfig& output_config,
  107. float* const* dest) override;
  108. // Methods only accessed from APM submodules or
  109. // from AudioProcessing tests in a single-threaded manner.
  110. // Hence there is no need for locks in these.
  111. int proc_sample_rate_hz() const override;
  112. int proc_split_sample_rate_hz() const override;
  113. size_t num_input_channels() const override;
  114. size_t num_proc_channels() const override;
  115. size_t num_output_channels() const override;
  116. size_t num_reverse_channels() const override;
  117. int stream_delay_ms() const override;
  118. AudioProcessingStats GetStatistics(bool has_remote_tracks) override {
  119. return GetStatistics();
  120. }
  121. AudioProcessingStats GetStatistics() override {
  122. return stats_reporter_.GetStatistics();
  123. }
  124. // TODO(peah): Remove MutateConfig once the new API allows that.
  125. void MutateConfig(rtc::FunctionView<void(AudioProcessing::Config*)> mutator);
  126. AudioProcessing::Config GetConfig() const override;
  127. protected:
  128. // Overridden in a mock.
  129. virtual void InitializeLocked()
  130. RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_render_, mutex_capture_);
  131. private:
  132. // TODO(peah): These friend classes should be removed as soon as the new
  133. // parameter setting scheme allows.
  134. FRIEND_TEST_ALL_PREFIXES(ApmConfiguration, DefaultBehavior);
  135. FRIEND_TEST_ALL_PREFIXES(ApmConfiguration, ValidConfigBehavior);
  136. FRIEND_TEST_ALL_PREFIXES(ApmConfiguration, InValidConfigBehavior);
  137. FRIEND_TEST_ALL_PREFIXES(ApmWithSubmodulesExcludedTest,
  138. ToggleTransientSuppressor);
  139. FRIEND_TEST_ALL_PREFIXES(ApmWithSubmodulesExcludedTest,
  140. ReinitializeTransientSuppressor);
  141. FRIEND_TEST_ALL_PREFIXES(ApmWithSubmodulesExcludedTest,
  142. BitexactWithDisabledModules);
  143. int recommended_stream_analog_level_locked() const
  144. RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
  145. void OverrideSubmoduleCreationForTesting(
  146. const ApmSubmoduleCreationOverrides& overrides);
  147. // Class providing thread-safe message pipe functionality for
  148. // |runtime_settings_|.
  149. class RuntimeSettingEnqueuer {
  150. public:
  151. explicit RuntimeSettingEnqueuer(
  152. SwapQueue<RuntimeSetting>* runtime_settings);
  153. ~RuntimeSettingEnqueuer();
  154. void Enqueue(RuntimeSetting setting);
  155. private:
  156. SwapQueue<RuntimeSetting>& runtime_settings_;
  157. };
  158. std::unique_ptr<ApmDataDumper> data_dumper_;
  159. static int instance_count_;
  160. const bool use_setup_specific_default_aec3_config_;
  161. SwapQueue<RuntimeSetting> capture_runtime_settings_;
  162. SwapQueue<RuntimeSetting> render_runtime_settings_;
  163. RuntimeSettingEnqueuer capture_runtime_settings_enqueuer_;
  164. RuntimeSettingEnqueuer render_runtime_settings_enqueuer_;
  165. // EchoControl factory.
  166. std::unique_ptr<EchoControlFactory> echo_control_factory_;
  167. class SubmoduleStates {
  168. public:
  169. SubmoduleStates(bool capture_post_processor_enabled,
  170. bool render_pre_processor_enabled,
  171. bool capture_analyzer_enabled);
  172. // Updates the submodule state and returns true if it has changed.
  173. bool Update(bool high_pass_filter_enabled,
  174. bool mobile_echo_controller_enabled,
  175. bool residual_echo_detector_enabled,
  176. bool noise_suppressor_enabled,
  177. bool adaptive_gain_controller_enabled,
  178. bool gain_controller2_enabled,
  179. bool pre_amplifier_enabled,
  180. bool echo_controller_enabled,
  181. bool voice_detector_enabled,
  182. bool transient_suppressor_enabled);
  183. bool CaptureMultiBandSubModulesActive() const;
  184. bool CaptureMultiBandProcessingPresent() const;
  185. bool CaptureMultiBandProcessingActive(bool ec_processing_active) const;
  186. bool CaptureFullBandProcessingActive() const;
  187. bool CaptureAnalyzerActive() const;
  188. bool RenderMultiBandSubModulesActive() const;
  189. bool RenderFullBandProcessingActive() const;
  190. bool RenderMultiBandProcessingActive() const;
  191. bool HighPassFilteringRequired() const;
  192. private:
  193. const bool capture_post_processor_enabled_ = false;
  194. const bool render_pre_processor_enabled_ = false;
  195. const bool capture_analyzer_enabled_ = false;
  196. bool high_pass_filter_enabled_ = false;
  197. bool mobile_echo_controller_enabled_ = false;
  198. bool residual_echo_detector_enabled_ = false;
  199. bool noise_suppressor_enabled_ = false;
  200. bool adaptive_gain_controller_enabled_ = false;
  201. bool gain_controller2_enabled_ = false;
  202. bool pre_amplifier_enabled_ = false;
  203. bool echo_controller_enabled_ = false;
  204. bool voice_detector_enabled_ = false;
  205. bool transient_suppressor_enabled_ = false;
  206. bool first_update_ = true;
  207. };
  208. // Methods for modifying the formats struct that is used by both
  209. // the render and capture threads. The check for whether modifications are
  210. // needed is done while holding a single lock only, thereby avoiding that the
  211. // capture thread blocks the render thread.
  212. // Called by render: Holds the render lock when reading the format struct and
  213. // acquires both locks if reinitialization is required.
  214. int MaybeInitializeRender(const ProcessingConfig& processing_config)
  215. RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_render_);
  216. // Called by capture: Holds the capture lock when reading the format struct
  217. // and acquires both locks if reinitialization is needed.
  218. int MaybeInitializeCapture(const StreamConfig& input_config,
  219. const StreamConfig& output_config);
  220. // Method for updating the state keeping track of the active submodules.
  221. // Returns a bool indicating whether the state has changed.
  222. bool UpdateActiveSubmoduleStates()
  223. RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
  224. // Methods requiring APM running in a single-threaded manner, requiring both
  225. // the render and capture lock to be acquired.
  226. int InitializeLocked(const ProcessingConfig& config)
  227. RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_render_, mutex_capture_);
  228. void InitializeResidualEchoDetector()
  229. RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_render_, mutex_capture_);
  230. void InitializeEchoController()
  231. RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_render_, mutex_capture_);
  232. // Initializations of capture-only submodules, requiring the capture lock
  233. // already acquired.
  234. void InitializeHighPassFilter(bool forced_reset)
  235. RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
  236. void InitializeVoiceDetector() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
  237. void InitializeGainController1() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
  238. void InitializeTransientSuppressor()
  239. RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
  240. void InitializeGainController2() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
  241. void InitializeNoiseSuppressor() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
  242. void InitializePreAmplifier() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
  243. void InitializePostProcessor() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
  244. void InitializeAnalyzer() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
  245. // Initializations of render-only submodules, requiring the render lock
  246. // already acquired.
  247. void InitializePreProcessor() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_render_);
  248. // Sample rate used for the fullband processing.
  249. int proc_fullband_sample_rate_hz() const
  250. RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
  251. // Empties and handles the respective RuntimeSetting queues.
  252. void HandleCaptureRuntimeSettings()
  253. RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
  254. void HandleRenderRuntimeSettings()
  255. RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_render_);
  256. void EmptyQueuedRenderAudio() RTC_LOCKS_EXCLUDED(mutex_capture_);
  257. void EmptyQueuedRenderAudioLocked()
  258. RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
  259. void AllocateRenderQueue()
  260. RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_render_, mutex_capture_);
  261. void QueueBandedRenderAudio(AudioBuffer* audio)
  262. RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_render_);
  263. void QueueNonbandedRenderAudio(AudioBuffer* audio)
  264. RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_render_);
  265. // Capture-side exclusive methods possibly running APM in a multi-threaded
  266. // manner that are called with the render lock already acquired.
  267. int ProcessCaptureStreamLocked() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
  268. // Render-side exclusive methods possibly running APM in a multi-threaded
  269. // manner that are called with the render lock already acquired.
  270. // TODO(ekm): Remove once all clients updated to new interface.
  271. int AnalyzeReverseStreamLocked(const float* const* src,
  272. const StreamConfig& input_config,
  273. const StreamConfig& output_config)
  274. RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_render_);
  275. int ProcessRenderStreamLocked() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_render_);
  276. // Collects configuration settings from public and private
  277. // submodules to be saved as an audioproc::Config message on the
  278. // AecDump if it is attached. If not |forced|, only writes the current
  279. // config if it is different from the last saved one; if |forced|,
  280. // writes the config regardless of the last saved.
  281. void WriteAecDumpConfigMessage(bool forced)
  282. RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
  283. // Notifies attached AecDump of current configuration and capture data.
  284. void RecordUnprocessedCaptureStream(const float* const* capture_stream)
  285. RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
  286. void RecordUnprocessedCaptureStream(const int16_t* const data,
  287. const StreamConfig& config)
  288. RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
  289. // Notifies attached AecDump of current configuration and
  290. // processed capture data and issues a capture stream recording
  291. // request.
  292. void RecordProcessedCaptureStream(
  293. const float* const* processed_capture_stream)
  294. RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
  295. void RecordProcessedCaptureStream(const int16_t* const data,
  296. const StreamConfig& config)
  297. RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
  298. // Notifies attached AecDump about current state (delay, drift, etc).
  299. void RecordAudioProcessingState()
  300. RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
  301. // AecDump instance used for optionally logging APM config, input
  302. // and output to file in the AEC-dump format defined in debug.proto.
  303. std::unique_ptr<AecDump> aec_dump_;
  304. // Hold the last config written with AecDump for avoiding writing
  305. // the same config twice.
  306. InternalAPMConfig apm_config_for_aec_dump_ RTC_GUARDED_BY(mutex_capture_);
  307. // Critical sections.
  308. mutable Mutex mutex_render_ RTC_ACQUIRED_BEFORE(mutex_capture_);
  309. mutable Mutex mutex_capture_;
  310. // Struct containing the Config specifying the behavior of APM.
  311. AudioProcessing::Config config_;
  312. // Overrides for testing the exclusion of some submodules from the build.
  313. ApmSubmoduleCreationOverrides submodule_creation_overrides_
  314. RTC_GUARDED_BY(mutex_capture_);
  315. // Class containing information about what submodules are active.
  316. SubmoduleStates submodule_states_;
  317. // Struct containing the pointers to the submodules.
  318. struct Submodules {
  319. Submodules(std::unique_ptr<CustomProcessing> capture_post_processor,
  320. std::unique_ptr<CustomProcessing> render_pre_processor,
  321. rtc::scoped_refptr<EchoDetector> echo_detector,
  322. std::unique_ptr<CustomAudioAnalyzer> capture_analyzer)
  323. : echo_detector(std::move(echo_detector)),
  324. capture_post_processor(std::move(capture_post_processor)),
  325. render_pre_processor(std::move(render_pre_processor)),
  326. capture_analyzer(std::move(capture_analyzer)) {}
  327. // Accessed internally from capture or during initialization.
  328. std::unique_ptr<AgcManagerDirect> agc_manager;
  329. std::unique_ptr<GainControlImpl> gain_control;
  330. std::unique_ptr<GainController2> gain_controller2;
  331. std::unique_ptr<HighPassFilter> high_pass_filter;
  332. rtc::scoped_refptr<EchoDetector> echo_detector;
  333. std::unique_ptr<EchoControl> echo_controller;
  334. std::unique_ptr<EchoControlMobileImpl> echo_control_mobile;
  335. std::unique_ptr<NoiseSuppressor> noise_suppressor;
  336. std::unique_ptr<TransientSuppressor> transient_suppressor;
  337. std::unique_ptr<CustomProcessing> capture_post_processor;
  338. std::unique_ptr<CustomProcessing> render_pre_processor;
  339. std::unique_ptr<GainApplier> pre_amplifier;
  340. std::unique_ptr<CustomAudioAnalyzer> capture_analyzer;
  341. std::unique_ptr<LevelEstimator> output_level_estimator;
  342. std::unique_ptr<VoiceDetection> voice_detector;
  343. } submodules_;
  344. // State that is written to while holding both the render and capture locks
  345. // but can be read without any lock being held.
  346. // As this is only accessed internally of APM, and all internal methods in APM
  347. // either are holding the render or capture locks, this construct is safe as
  348. // it is not possible to read the variables while writing them.
  349. struct ApmFormatState {
  350. ApmFormatState()
  351. : // Format of processing streams at input/output call sites.
  352. api_format({{{kSampleRate16kHz, 1, false},
  353. {kSampleRate16kHz, 1, false},
  354. {kSampleRate16kHz, 1, false},
  355. {kSampleRate16kHz, 1, false}}}),
  356. render_processing_format(kSampleRate16kHz, 1) {}
  357. ProcessingConfig api_format;
  358. StreamConfig render_processing_format;
  359. } formats_;
  360. // APM constants.
  361. const struct ApmConstants {
  362. ApmConstants(bool multi_channel_render_support,
  363. bool multi_channel_capture_support,
  364. bool enforce_split_band_hpf)
  365. : multi_channel_render_support(multi_channel_render_support),
  366. multi_channel_capture_support(multi_channel_capture_support),
  367. enforce_split_band_hpf(enforce_split_band_hpf) {}
  368. bool multi_channel_render_support;
  369. bool multi_channel_capture_support;
  370. bool enforce_split_band_hpf;
  371. } constants_;
  372. struct ApmCaptureState {
  373. ApmCaptureState();
  374. ~ApmCaptureState();
  375. bool was_stream_delay_set;
  376. bool output_will_be_muted;
  377. bool key_pressed;
  378. std::unique_ptr<AudioBuffer> capture_audio;
  379. std::unique_ptr<AudioBuffer> capture_fullband_audio;
  380. std::unique_ptr<AudioBuffer> linear_aec_output;
  381. // Only the rate and samples fields of capture_processing_format_ are used
  382. // because the capture processing number of channels is mutable and is
  383. // tracked by the capture_audio_.
  384. StreamConfig capture_processing_format;
  385. int split_rate;
  386. bool echo_path_gain_change;
  387. int prev_analog_mic_level;
  388. float prev_pre_amp_gain;
  389. int playout_volume;
  390. int prev_playout_volume;
  391. AudioProcessingStats stats;
  392. struct KeyboardInfo {
  393. void Extract(const float* const* data, const StreamConfig& stream_config);
  394. size_t num_keyboard_frames = 0;
  395. const float* keyboard_data = nullptr;
  396. } keyboard_info;
  397. int cached_stream_analog_level_ = 0;
  398. } capture_ RTC_GUARDED_BY(mutex_capture_);
  399. struct ApmCaptureNonLockedState {
  400. ApmCaptureNonLockedState()
  401. : capture_processing_format(kSampleRate16kHz),
  402. split_rate(kSampleRate16kHz),
  403. stream_delay_ms(0) {}
  404. // Only the rate and samples fields of capture_processing_format_ are used
  405. // because the forward processing number of channels is mutable and is
  406. // tracked by the capture_audio_.
  407. StreamConfig capture_processing_format;
  408. int split_rate;
  409. int stream_delay_ms;
  410. bool echo_controller_enabled = false;
  411. } capture_nonlocked_;
  412. struct ApmRenderState {
  413. ApmRenderState();
  414. ~ApmRenderState();
  415. std::unique_ptr<AudioConverter> render_converter;
  416. std::unique_ptr<AudioBuffer> render_audio;
  417. } render_ RTC_GUARDED_BY(mutex_render_);
  418. // Class for statistics reporting. The class is thread-safe and no lock is
  419. // needed when accessing it.
  420. class ApmStatsReporter {
  421. public:
  422. ApmStatsReporter();
  423. ~ApmStatsReporter();
  424. // Returns the most recently reported statistics.
  425. AudioProcessingStats GetStatistics();
  426. // Update the cached statistics.
  427. void UpdateStatistics(const AudioProcessingStats& new_stats);
  428. private:
  429. Mutex mutex_stats_;
  430. AudioProcessingStats cached_stats_ RTC_GUARDED_BY(mutex_stats_);
  431. SwapQueue<AudioProcessingStats> stats_message_queue_;
  432. } stats_reporter_;
  433. std::vector<int16_t> aecm_render_queue_buffer_ RTC_GUARDED_BY(mutex_render_);
  434. std::vector<int16_t> aecm_capture_queue_buffer_
  435. RTC_GUARDED_BY(mutex_capture_);
  436. size_t agc_render_queue_element_max_size_ RTC_GUARDED_BY(mutex_render_)
  437. RTC_GUARDED_BY(mutex_capture_) = 0;
  438. std::vector<int16_t> agc_render_queue_buffer_ RTC_GUARDED_BY(mutex_render_);
  439. std::vector<int16_t> agc_capture_queue_buffer_ RTC_GUARDED_BY(mutex_capture_);
  440. size_t red_render_queue_element_max_size_ RTC_GUARDED_BY(mutex_render_)
  441. RTC_GUARDED_BY(mutex_capture_) = 0;
  442. std::vector<float> red_render_queue_buffer_ RTC_GUARDED_BY(mutex_render_);
  443. std::vector<float> red_capture_queue_buffer_ RTC_GUARDED_BY(mutex_capture_);
  444. RmsLevel capture_input_rms_ RTC_GUARDED_BY(mutex_capture_);
  445. RmsLevel capture_output_rms_ RTC_GUARDED_BY(mutex_capture_);
  446. int capture_rms_interval_counter_ RTC_GUARDED_BY(mutex_capture_) = 0;
  447. // Lock protection not needed.
  448. std::unique_ptr<
  449. SwapQueue<std::vector<int16_t>, RenderQueueItemVerifier<int16_t>>>
  450. aecm_render_signal_queue_;
  451. std::unique_ptr<
  452. SwapQueue<std::vector<int16_t>, RenderQueueItemVerifier<int16_t>>>
  453. agc_render_signal_queue_;
  454. std::unique_ptr<SwapQueue<std::vector<float>, RenderQueueItemVerifier<float>>>
  455. red_render_signal_queue_;
  456. };
  457. } // namespace webrtc
  458. #endif // MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_