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 <vector> | 14 #include <vector> |
15 | 15 |
| 16 #include "webrtc/base/criticalsection.h" |
16 #include "webrtc/base/scoped_ptr.h" | 17 #include "webrtc/base/scoped_ptr.h" |
17 #include "webrtc/base/thread_checker.h" | 18 #include "webrtc/base/thread_checker.h" |
18 #include "webrtc/common_audio/swap_queue.h" | 19 #include "webrtc/common_audio/swap_queue.h" |
19 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 20 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
20 #include "webrtc/modules/audio_processing/processing_component.h" | 21 #include "webrtc/modules/audio_processing/processing_component.h" |
21 | 22 |
22 namespace webrtc { | 23 namespace webrtc { |
23 | 24 |
24 class AudioBuffer; | 25 class AudioBuffer; |
25 class CriticalSectionWrapper; | |
26 | 26 |
27 class GainControlImpl : public GainControl, | 27 class GainControlImpl : public GainControl, |
28 public ProcessingComponent { | 28 public ProcessingComponent { |
29 public: | 29 public: |
30 GainControlImpl(const AudioProcessing* apm, | 30 GainControlImpl(const AudioProcessing* apm, |
31 CriticalSectionWrapper* crit, | 31 rtc::CriticalSection* crit_render, |
| 32 rtc::CriticalSection* crit_capture, |
32 const rtc::ThreadChecker* render_thread_checker, | 33 const rtc::ThreadChecker* render_thread_checker, |
33 const rtc::ThreadChecker* capture_thread_checker); | 34 const rtc::ThreadChecker* capture_thread_checker); |
34 virtual ~GainControlImpl(); | 35 virtual ~GainControlImpl(); |
35 | 36 |
| 37 // Called with the render lock held. |
36 int ProcessRenderAudio(AudioBuffer* audio); | 38 int ProcessRenderAudio(AudioBuffer* audio); |
| 39 // Called with the render lock held. |
37 int AnalyzeCaptureAudio(AudioBuffer* audio); | 40 int AnalyzeCaptureAudio(AudioBuffer* audio); |
| 41 // Called with the render lock held. |
38 int ProcessCaptureAudio(AudioBuffer* audio); | 42 int ProcessCaptureAudio(AudioBuffer* audio); |
39 | 43 |
40 // ProcessingComponent implementation. | 44 // ProcessingComponent implementation. |
41 int Initialize() override; | 45 int Initialize() override; |
42 | 46 |
43 // GainControl implementation. | 47 // GainControl implementation. |
| 48 // Acquires the capture lock. |
44 bool is_enabled() const override; | 49 bool is_enabled() const override; |
| 50 // Acquires the capture lock. |
45 int stream_analog_level() override; | 51 int stream_analog_level() override; |
| 52 // Acquires the capture lock. |
46 bool is_limiter_enabled() const override; | 53 bool is_limiter_enabled() const override; |
| 54 // Acquires the capture lock. |
47 Mode mode() const override; | 55 Mode mode() const override; |
48 | 56 |
49 // Reads render side data that has been queued on the render call. | 57 // Reads render side data that has been queued on the render call. |
50 void ReadQueuedRenderData(); | 58 void ReadQueuedRenderData(); |
51 | 59 |
52 private: | 60 private: |
53 // GainControl implementation. | 61 // GainControl implementation. |
| 62 // Aquires both the render and capture locks. |
54 int Enable(bool enable) override; | 63 int Enable(bool enable) override; |
| 64 // Acquires the capture lock. |
55 int set_stream_analog_level(int level) override; | 65 int set_stream_analog_level(int level) override; |
| 66 // Acquires both the render and capture locks. |
56 int set_mode(Mode mode) override; | 67 int set_mode(Mode mode) override; |
| 68 // Acquires the capture lock. |
57 int set_target_level_dbfs(int level) override; | 69 int set_target_level_dbfs(int level) override; |
| 70 // Acquires the capture lock. |
58 int target_level_dbfs() const override; | 71 int target_level_dbfs() const override; |
| 72 // Acquires the capture lock. |
59 int set_compression_gain_db(int gain) override; | 73 int set_compression_gain_db(int gain) override; |
| 74 // Acquires the capture lock. |
60 int compression_gain_db() const override; | 75 int compression_gain_db() const override; |
| 76 // Acquires the capture lock. |
61 int enable_limiter(bool enable) override; | 77 int enable_limiter(bool enable) override; |
| 78 // Acquires the capture lock. |
62 int set_analog_level_limits(int minimum, int maximum) override; | 79 int set_analog_level_limits(int minimum, int maximum) override; |
| 80 // Acquires the capture lock. |
63 int analog_level_minimum() const override; | 81 int analog_level_minimum() const override; |
| 82 // Acquires the capture lock. |
64 int analog_level_maximum() const override; | 83 int analog_level_maximum() const override; |
| 84 // Acquires the capture lock. |
65 bool stream_is_saturated() const override; | 85 bool stream_is_saturated() const override; |
66 | 86 |
67 // ProcessingComponent implementation. | 87 // ProcessingComponent implementation. |
| 88 // Called with both locks held. |
68 void* CreateHandle() const override; | 89 void* CreateHandle() const override; |
69 int InitializeHandle(void* handle) const override; | 90 int InitializeHandle(void* handle) const override; |
70 int ConfigureHandle(void* handle) const override; | 91 int ConfigureHandle(void* handle) const override; |
71 void DestroyHandle(void* handle) const override; | 92 void DestroyHandle(void* handle) const override; |
72 int num_handles_required() const override; | 93 int num_handles_required() const override; |
73 int GetHandleError(void* handle) const override; | 94 int GetHandleError(void* handle) const override; |
74 | 95 |
75 void AllocateRenderQueue(); | 96 void AllocateRenderQueue(); |
76 | 97 |
77 const AudioProcessing* apm_; | 98 const AudioProcessing* apm_; |
78 CriticalSectionWrapper* crit_; | 99 rtc::CriticalSection* const crit_render_; |
| 100 rtc::CriticalSection* const crit_capture_; |
79 const rtc::ThreadChecker* const render_thread_checker_; | 101 const rtc::ThreadChecker* const render_thread_checker_; |
80 const rtc::ThreadChecker* const capture_thread_checker_; | 102 const rtc::ThreadChecker* const capture_thread_checker_; |
81 Mode mode_; | 103 Mode mode_; |
82 int minimum_capture_level_; | 104 int minimum_capture_level_; |
83 int maximum_capture_level_; | 105 int maximum_capture_level_; |
84 bool limiter_enabled_; | 106 bool limiter_enabled_; |
85 int target_level_dbfs_; | 107 int target_level_dbfs_; |
86 int compression_gain_db_; | 108 int compression_gain_db_; |
87 std::vector<int> capture_levels_; | 109 std::vector<int> capture_levels_; |
88 int analog_capture_level_; | 110 int analog_capture_level_; |
89 bool was_analog_level_set_; | 111 bool was_analog_level_set_; |
90 bool stream_is_saturated_; | 112 bool stream_is_saturated_; |
91 | 113 |
92 size_t render_queue_element_max_size_; | 114 size_t render_queue_element_max_size_; |
93 std::vector<int16_t> render_queue_buffer_; | 115 std::vector<int16_t> render_queue_buffer_; |
94 std::vector<int16_t> capture_queue_buffer_; | 116 std::vector<int16_t> capture_queue_buffer_; |
95 rtc::scoped_ptr< | 117 rtc::scoped_ptr< |
96 SwapQueue<std::vector<int16_t>, RenderQueueItemVerifier<int16_t>>> | 118 SwapQueue<std::vector<int16_t>, RenderQueueItemVerifier<int16_t>>> |
97 render_signal_queue_; | 119 render_signal_queue_; |
98 }; | 120 }; |
99 } // namespace webrtc | 121 } // namespace webrtc |
100 | 122 |
101 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_GAIN_CONTROL_IMPL_H_ | 123 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_GAIN_CONTROL_IMPL_H_ |
OLD | NEW |