OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_GAIN_CONTROL_IMPL_H_ | 11 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_GAIN_CONTROL_IMPL_H_ |
12 #define WEBRTC_MODULES_AUDIO_PROCESSING_GAIN_CONTROL_IMPL_H_ | 12 #define WEBRTC_MODULES_AUDIO_PROCESSING_GAIN_CONTROL_IMPL_H_ |
13 | 13 |
14 #include <memory> | 14 #include <memory> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "webrtc/base/constructormagic.h" | 17 #include "webrtc/base/constructormagic.h" |
18 #include "webrtc/base/criticalsection.h" | 18 #include "webrtc/base/criticalsection.h" |
19 #include "webrtc/base/thread_annotations.h" | 19 #include "webrtc/base/thread_annotations.h" |
20 #include "webrtc/common_audio/swap_queue.h" | 20 #include "webrtc/common_audio/swap_queue.h" |
21 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 21 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
22 #include "webrtc/modules/audio_processing/render_queue_item_verifier.h" | 22 #include "webrtc/modules/audio_processing/render_queue_item_verifier.h" |
23 | 23 |
24 namespace webrtc { | 24 namespace webrtc { |
25 | 25 |
26 class AudioBuffer; | 26 class AudioBuffer; |
27 | 27 |
28 class GainControlImpl : public GainControl { | 28 class GainControlImpl : public GainControl { |
29 public: | 29 public: |
30 GainControlImpl(const AudioProcessing* apm, | 30 GainControlImpl(rtc::CriticalSection* crit_render, |
31 rtc::CriticalSection* crit_render, | |
32 rtc::CriticalSection* crit_capture); | 31 rtc::CriticalSection* crit_capture); |
33 ~GainControlImpl() override; | 32 ~GainControlImpl() override; |
34 | 33 |
35 int ProcessRenderAudio(AudioBuffer* audio); | 34 int ProcessRenderAudio(AudioBuffer* audio); |
36 int AnalyzeCaptureAudio(AudioBuffer* audio); | 35 int AnalyzeCaptureAudio(AudioBuffer* audio); |
37 int ProcessCaptureAudio(AudioBuffer* audio); | 36 int ProcessCaptureAudio(AudioBuffer* audio, bool stream_has_echo); |
38 | 37 |
39 void Initialize(); | 38 void Initialize(size_t num_proc_channels, int sample_rate_hz); |
40 | 39 |
41 // GainControl implementation. | 40 // GainControl implementation. |
42 bool is_enabled() const override; | 41 bool is_enabled() const override; |
43 int stream_analog_level() override; | 42 int stream_analog_level() override; |
44 bool is_limiter_enabled() const override; | 43 bool is_limiter_enabled() const override; |
45 Mode mode() const override; | 44 Mode mode() const override; |
46 | 45 |
47 // Reads render side data that has been queued on the render call. | 46 // Reads render side data that has been queued on the render call. |
48 void ReadQueuedRenderData(); | 47 void ReadQueuedRenderData(); |
49 | 48 |
50 private: | 49 private: |
51 class GainController; | 50 class GainController; |
52 | 51 |
53 // GainControl implementation. | 52 // GainControl implementation. |
54 int Enable(bool enable) override; | 53 int Enable(bool enable) override; |
55 int set_stream_analog_level(int level) override; | 54 int set_stream_analog_level(int level) override; |
56 int set_mode(Mode mode) override; | 55 int set_mode(Mode mode) override; |
57 int set_target_level_dbfs(int level) override; | 56 int set_target_level_dbfs(int level) override; |
58 int target_level_dbfs() const override; | 57 int target_level_dbfs() const override; |
59 int set_compression_gain_db(int gain) override; | 58 int set_compression_gain_db(int gain) override; |
60 int compression_gain_db() const override; | 59 int compression_gain_db() const override; |
61 int enable_limiter(bool enable) override; | 60 int enable_limiter(bool enable) override; |
62 int set_analog_level_limits(int minimum, int maximum) override; | 61 int set_analog_level_limits(int minimum, int maximum) override; |
63 int analog_level_minimum() const override; | 62 int analog_level_minimum() const override; |
64 int analog_level_maximum() const override; | 63 int analog_level_maximum() const override; |
65 bool stream_is_saturated() const override; | 64 bool stream_is_saturated() const override; |
66 | 65 |
67 size_t num_handles_required() const; | |
68 | |
69 void AllocateRenderQueue(); | 66 void AllocateRenderQueue(); |
70 int Configure(); | 67 int Configure(); |
71 | 68 |
72 // Not guarded as its public API is thread safe. | |
73 const AudioProcessing* apm_; | |
74 | |
75 rtc::CriticalSection* const crit_render_ ACQUIRED_BEFORE(crit_capture_); | 69 rtc::CriticalSection* const crit_render_ ACQUIRED_BEFORE(crit_capture_); |
76 rtc::CriticalSection* const crit_capture_; | 70 rtc::CriticalSection* const crit_capture_; |
77 | 71 |
78 bool enabled_ = false; | 72 bool enabled_ = false; |
79 | 73 |
80 Mode mode_ GUARDED_BY(crit_capture_); | 74 Mode mode_ GUARDED_BY(crit_capture_); |
81 int minimum_capture_level_ GUARDED_BY(crit_capture_); | 75 int minimum_capture_level_ GUARDED_BY(crit_capture_); |
82 int maximum_capture_level_ GUARDED_BY(crit_capture_); | 76 int maximum_capture_level_ GUARDED_BY(crit_capture_); |
83 bool limiter_enabled_ GUARDED_BY(crit_capture_); | 77 bool limiter_enabled_ GUARDED_BY(crit_capture_); |
84 int target_level_dbfs_ GUARDED_BY(crit_capture_); | 78 int target_level_dbfs_ GUARDED_BY(crit_capture_); |
85 int compression_gain_db_ GUARDED_BY(crit_capture_); | 79 int compression_gain_db_ GUARDED_BY(crit_capture_); |
86 int analog_capture_level_ GUARDED_BY(crit_capture_); | 80 int analog_capture_level_ GUARDED_BY(crit_capture_); |
87 bool was_analog_level_set_ GUARDED_BY(crit_capture_); | 81 bool was_analog_level_set_ GUARDED_BY(crit_capture_); |
88 bool stream_is_saturated_ GUARDED_BY(crit_capture_); | 82 bool stream_is_saturated_ GUARDED_BY(crit_capture_); |
89 | 83 |
90 size_t render_queue_element_max_size_ GUARDED_BY(crit_render_) | 84 size_t render_queue_element_max_size_ GUARDED_BY(crit_render_) |
91 GUARDED_BY(crit_capture_); | 85 GUARDED_BY(crit_capture_); |
92 std::vector<int16_t> render_queue_buffer_ GUARDED_BY(crit_render_); | 86 std::vector<int16_t> render_queue_buffer_ GUARDED_BY(crit_render_); |
93 std::vector<int16_t> capture_queue_buffer_ GUARDED_BY(crit_capture_); | 87 std::vector<int16_t> capture_queue_buffer_ GUARDED_BY(crit_capture_); |
94 | 88 |
95 // Lock protection not needed. | 89 // Lock protection not needed. |
96 std::unique_ptr< | 90 std::unique_ptr< |
97 SwapQueue<std::vector<int16_t>, RenderQueueItemVerifier<int16_t>>> | 91 SwapQueue<std::vector<int16_t>, RenderQueueItemVerifier<int16_t>>> |
98 render_signal_queue_; | 92 render_signal_queue_; |
99 | 93 |
100 std::vector<std::unique_ptr<GainController>> gain_controllers_; | 94 std::vector<std::unique_ptr<GainController>> gain_controllers_; |
101 | 95 |
| 96 rtc::Optional<size_t> num_proc_channels_ GUARDED_BY(crit_capture_); |
| 97 rtc::Optional<int> sample_rate_hz_ GUARDED_BY(crit_capture_); |
| 98 |
102 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(GainControlImpl); | 99 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(GainControlImpl); |
103 }; | 100 }; |
104 } // namespace webrtc | 101 } // namespace webrtc |
105 | 102 |
106 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_GAIN_CONTROL_IMPL_H_ | 103 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_GAIN_CONTROL_IMPL_H_ |
OLD | NEW |