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