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 namespace { | 25 namespace { |
25 // Functor to use when supplying a verifier function for the queue item | 26 // Functor to use when supplying a verifier function for the queue item |
(...skipping 12 matching lines...) Expand all Loading... | |
38 }; | 39 }; |
39 | 40 |
40 } // namespace anonymous | 41 } // namespace anonymous |
41 | 42 |
42 class AudioBuffer; | 43 class AudioBuffer; |
43 class CriticalSectionWrapper; | 44 class CriticalSectionWrapper; |
44 | 45 |
45 class GainControlImpl : public GainControl, | 46 class GainControlImpl : public GainControl, |
46 public ProcessingComponent { | 47 public ProcessingComponent { |
47 public: | 48 public: |
49 // Called with both locks held. | |
hlundin-webrtc
2015/11/05 16:11:22
Is this still true?
peah-webrtc
2015/11/06 09:54:33
Done.
| |
48 GainControlImpl(const AudioProcessing* apm, | 50 GainControlImpl(const AudioProcessing* apm, |
49 CriticalSectionWrapper* crit, | 51 rtc::CriticalSection* crit_render, |
52 rtc::CriticalSection* crit_capture, | |
50 rtc::ThreadChecker* render_thread_checker, | 53 rtc::ThreadChecker* render_thread_checker, |
51 rtc::ThreadChecker* capture_thread_checker); | 54 rtc::ThreadChecker* capture_thread_checker); |
52 virtual ~GainControlImpl(); | 55 virtual ~GainControlImpl(); // Called with both locks held. |
hlundin-webrtc
2015/11/05 16:11:23
Still true?
peah-webrtc
2015/11/06 09:54:32
Done.
| |
53 | 56 |
54 int ProcessRenderAudio(AudioBuffer* audio); | 57 int ProcessRenderAudio( |
hlundin-webrtc
2015/11/05 16:11:22
Same nagging about putting the comments on separat
peah-webrtc
2015/11/06 09:54:33
Fully and totally well motivated!
Done.
| |
55 int AnalyzeCaptureAudio(AudioBuffer* audio); | 58 AudioBuffer* audio); // Called with the render lock held. |
56 int ProcessCaptureAudio(AudioBuffer* audio); | 59 int AnalyzeCaptureAudio( |
60 AudioBuffer* audio); // Called with the capture lock held. | |
61 int ProcessCaptureAudio( | |
62 AudioBuffer* audio); // Called with the capture lock held. | |
57 | 63 |
58 // ProcessingComponent implementation. | 64 // ProcessingComponent implementation. |
59 int Initialize() override; | 65 int Initialize() override; |
60 | 66 |
61 // GainControl implementation. | 67 // GainControl implementation. |
62 bool is_enabled() const override; | 68 bool is_enabled() const override; // Acquires the capture lock. |
63 int stream_analog_level() override; | 69 int stream_analog_level() override; // Acquires the capture lock. |
64 bool is_limiter_enabled() const override; | 70 bool is_limiter_enabled() const override; // Acquires the capture lock. |
65 Mode mode() const override; | 71 Mode mode() const override; // Acquires the capture lock. |
66 | 72 |
67 // Reads render side data that has been queued on the render call. | 73 // Reads render side data that has been queued on the render call. |
68 void ReadQueuedRenderData(); | 74 void ReadQueuedRenderData(); |
69 | 75 |
70 private: | 76 private: |
71 static const size_t kAllowedValuesOfSamplesPerFrame1 = 80; | 77 static const size_t kAllowedValuesOfSamplesPerFrame1 = 80; |
72 static const size_t kAllowedValuesOfSamplesPerFrame2 = 160; | 78 static const size_t kAllowedValuesOfSamplesPerFrame2 = 160; |
73 // TODO(peah): Decrease this once we properly handle hugely unbalanced | 79 // TODO(peah): Decrease this once we properly handle hugely unbalanced |
74 // reverse and forward call numbers. | 80 // reverse and forward call numbers. |
75 static const size_t kMaxNumFramesToBuffer = 100; | 81 static const size_t kMaxNumFramesToBuffer = 100; |
76 | 82 |
77 // GainControl implementation. | 83 // GainControl implementation. |
78 int Enable(bool enable) override; | 84 int Enable( |
79 int set_stream_analog_level(int level) override; | 85 bool enable) override; // Aquires both the render and capture locks. |
80 int set_mode(Mode mode) override; | 86 int set_stream_analog_level( |
81 int set_target_level_dbfs(int level) override; | 87 int level) override; // Acquires the capture lock. |
82 int target_level_dbfs() const override; | 88 int set_mode( |
83 int set_compression_gain_db(int gain) override; | 89 Mode mode) override; // Acquires both the render and capture locks. |
84 int compression_gain_db() const override; | 90 int set_target_level_dbfs(int level) override; // Acquires the capture lock. |
85 int enable_limiter(bool enable) override; | 91 int target_level_dbfs() const override; // Acquires the capture lock. |
86 int set_analog_level_limits(int minimum, int maximum) override; | 92 int set_compression_gain_db(int gain) override; // Acquires the capture lock. |
87 int analog_level_minimum() const override; | 93 int compression_gain_db() const override; // Acquires the capture lock. |
88 int analog_level_maximum() const override; | 94 int enable_limiter(bool enable) override; // Acquires the capture lock. |
89 bool stream_is_saturated() const override; | 95 int set_analog_level_limits(int minimum, int maximum) |
96 override; // Acquires the capture lock. | |
97 int analog_level_minimum() const override; // Acquires the capture lock. | |
98 int analog_level_maximum() const override; // Acquires the capture lock. | |
99 bool stream_is_saturated() const override; // Acquires the capture lock. | |
90 | 100 |
91 // ProcessingComponent implementation. | 101 // ProcessingComponent implementation. |
92 void* CreateHandle() const override; | 102 void* CreateHandle() const override; // Called with both locks held. |
93 int InitializeHandle(void* handle) const override; | 103 int InitializeHandle( |
94 int ConfigureHandle(void* handle) const override; | 104 void* handle) const override; // Called with both locks held. |
95 void DestroyHandle(void* handle) const override; | 105 int ConfigureHandle( |
96 int num_handles_required() const override; | 106 void* handle) const override; // Called with both locks held. |
97 int GetHandleError(void* handle) const override; | 107 void DestroyHandle( |
108 void* handle) const override; // Called with both locks held. | |
109 int num_handles_required() const override; // Called with both locks held. | |
110 int GetHandleError( | |
111 void* handle) const override; // Called with both locks held. | |
98 | 112 |
99 void AllocateRenderQueue(); | 113 void AllocateRenderQueue(); |
100 | 114 |
101 const AudioProcessing* apm_; | 115 const AudioProcessing* apm_; |
102 CriticalSectionWrapper* crit_; | 116 rtc::CriticalSection* const crit_render_; |
117 rtc::CriticalSection* const crit_capture_; | |
103 const rtc::ThreadChecker* const render_thread_checker_; | 118 const rtc::ThreadChecker* const render_thread_checker_; |
104 const rtc::ThreadChecker* const capture_thread_checker_; | 119 const rtc::ThreadChecker* const capture_thread_checker_; |
105 Mode mode_; | 120 Mode mode_; |
106 int minimum_capture_level_; | 121 int minimum_capture_level_; |
107 int maximum_capture_level_; | 122 int maximum_capture_level_; |
108 bool limiter_enabled_; | 123 bool limiter_enabled_; |
109 int target_level_dbfs_; | 124 int target_level_dbfs_; |
110 int compression_gain_db_; | 125 int compression_gain_db_; |
111 std::vector<int> capture_levels_; | 126 std::vector<int> capture_levels_; |
112 int analog_capture_level_; | 127 int analog_capture_level_; |
113 bool was_analog_level_set_; | 128 bool was_analog_level_set_; |
114 bool stream_is_saturated_; | 129 bool stream_is_saturated_; |
115 | 130 |
116 size_t render_queue_element_max_size_; | 131 size_t render_queue_element_max_size_; |
117 std::vector<int16_t> render_queue_buffer_; | 132 std::vector<int16_t> render_queue_buffer_; |
118 std::vector<int16_t> capture_queue_buffer_; | 133 std::vector<int16_t> capture_queue_buffer_; |
119 rtc::scoped_ptr<SwapQueue<std::vector<int16_t>, AgcRenderQueueItemVerifier> > | 134 rtc::scoped_ptr<SwapQueue<std::vector<int16_t>, AgcRenderQueueItemVerifier> > |
120 render_signal_queue_; | 135 render_signal_queue_; |
121 }; | 136 }; |
122 } // namespace webrtc | 137 } // namespace webrtc |
123 | 138 |
124 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_GAIN_CONTROL_IMPL_H_ | 139 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_GAIN_CONTROL_IMPL_H_ |
OLD | NEW |