niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
bjornv@webrtc.org | 0c6f931 | 2012-01-30 09:39:08 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 11 | #ifndef MODULES_AUDIO_PROCESSING_GAIN_CONTROL_IMPL_H_ |
| 12 | #define MODULES_AUDIO_PROCESSING_GAIN_CONTROL_IMPL_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
kwiberg | 88788ad | 2016-02-19 07:04:49 -0800 | [diff] [blame] | 14 | #include <memory> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 15 | #include <vector> |
| 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 17 | #include "modules/audio_processing/include/audio_processing.h" |
| 18 | #include "modules/audio_processing/render_queue_item_verifier.h" |
| 19 | #include "rtc_base/constructormagic.h" |
| 20 | #include "rtc_base/criticalsection.h" |
| 21 | #include "rtc_base/swap_queue.h" |
| 22 | #include "rtc_base/thread_annotations.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | |
| 24 | namespace webrtc { |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 25 | |
peah | 135259a | 2016-10-28 03:12:11 -0700 | [diff] [blame] | 26 | class ApmDataDumper; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 27 | class AudioBuffer; |
| 28 | |
peah | bfa9711 | 2016-03-10 21:09:04 -0800 | [diff] [blame] | 29 | class GainControlImpl : public GainControl { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 30 | public: |
peah | b8fbb54 | 2016-03-15 02:28:08 -0700 | [diff] [blame] | 31 | GainControlImpl(rtc::CriticalSection* crit_render, |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 32 | rtc::CriticalSection* crit_capture); |
peah | bfa9711 | 2016-03-10 21:09:04 -0800 | [diff] [blame] | 33 | ~GainControlImpl() override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 34 | |
peah | 701d628 | 2016-10-25 05:42:20 -0700 | [diff] [blame] | 35 | void ProcessRenderAudio(rtc::ArrayView<const int16_t> packed_render_audio); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 36 | int AnalyzeCaptureAudio(AudioBuffer* audio); |
peah | b8fbb54 | 2016-03-15 02:28:08 -0700 | [diff] [blame] | 37 | int ProcessCaptureAudio(AudioBuffer* audio, bool stream_has_echo); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 38 | |
peah | b8fbb54 | 2016-03-15 02:28:08 -0700 | [diff] [blame] | 39 | void Initialize(size_t num_proc_channels, int sample_rate_hz); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 40 | |
peah | 701d628 | 2016-10-25 05:42:20 -0700 | [diff] [blame] | 41 | static void PackRenderAudioBuffer(AudioBuffer* audio, |
| 42 | std::vector<int16_t>* packed_buffer); |
| 43 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 44 | // GainControl implementation. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 45 | bool is_enabled() const override; |
| 46 | int stream_analog_level() override; |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 47 | bool is_limiter_enabled() const override; |
| 48 | Mode mode() const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 49 | |
aluebs | 11d4a42 | 2016-04-28 14:58:32 -0700 | [diff] [blame] | 50 | int compression_gain_db() const override; |
| 51 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 52 | private: |
peah | bfa9711 | 2016-03-10 21:09:04 -0800 | [diff] [blame] | 53 | class GainController; |
| 54 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 55 | // GainControl implementation. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 56 | int Enable(bool enable) override; |
| 57 | int set_stream_analog_level(int level) override; |
| 58 | int set_mode(Mode mode) override; |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 59 | int set_target_level_dbfs(int level) override; |
| 60 | int target_level_dbfs() const override; |
| 61 | int set_compression_gain_db(int gain) override; |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 62 | int enable_limiter(bool enable) override; |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 63 | int set_analog_level_limits(int minimum, int maximum) override; |
| 64 | int analog_level_minimum() const override; |
| 65 | int analog_level_maximum() const override; |
| 66 | bool stream_is_saturated() const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 67 | |
peah | bfa9711 | 2016-03-10 21:09:04 -0800 | [diff] [blame] | 68 | int Configure(); |
peah | 4d291f7 | 2015-11-16 23:52:25 -0800 | [diff] [blame] | 69 | |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 70 | rtc::CriticalSection* const crit_render_ RTC_ACQUIRED_BEFORE(crit_capture_); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 71 | rtc::CriticalSection* const crit_capture_; |
| 72 | |
peah | 135259a | 2016-10-28 03:12:11 -0700 | [diff] [blame] | 73 | std::unique_ptr<ApmDataDumper> data_dumper_; |
| 74 | |
peah | bfa9711 | 2016-03-10 21:09:04 -0800 | [diff] [blame] | 75 | bool enabled_ = false; |
| 76 | |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 77 | Mode mode_ RTC_GUARDED_BY(crit_capture_); |
| 78 | int minimum_capture_level_ RTC_GUARDED_BY(crit_capture_); |
| 79 | int maximum_capture_level_ RTC_GUARDED_BY(crit_capture_); |
| 80 | bool limiter_enabled_ RTC_GUARDED_BY(crit_capture_); |
| 81 | int target_level_dbfs_ RTC_GUARDED_BY(crit_capture_); |
| 82 | int compression_gain_db_ RTC_GUARDED_BY(crit_capture_); |
| 83 | int analog_capture_level_ RTC_GUARDED_BY(crit_capture_); |
| 84 | bool was_analog_level_set_ RTC_GUARDED_BY(crit_capture_); |
| 85 | bool stream_is_saturated_ RTC_GUARDED_BY(crit_capture_); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 86 | |
peah | bfa9711 | 2016-03-10 21:09:04 -0800 | [diff] [blame] | 87 | std::vector<std::unique_ptr<GainController>> gain_controllers_; |
| 88 | |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 89 | rtc::Optional<size_t> num_proc_channels_ RTC_GUARDED_BY(crit_capture_); |
| 90 | rtc::Optional<int> sample_rate_hz_ RTC_GUARDED_BY(crit_capture_); |
peah | b8fbb54 | 2016-03-15 02:28:08 -0700 | [diff] [blame] | 91 | |
peah | 135259a | 2016-10-28 03:12:11 -0700 | [diff] [blame] | 92 | static int instance_counter_; |
peah | bfa9711 | 2016-03-10 21:09:04 -0800 | [diff] [blame] | 93 | RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(GainControlImpl); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 94 | }; |
| 95 | } // namespace webrtc |
| 96 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 97 | #endif // MODULES_AUDIO_PROCESSING_GAIN_CONTROL_IMPL_H_ |