| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MEDIA_AUDIO_AGC_AUDIO_STREAM_H_ | 5 #ifndef MEDIA_AUDIO_AGC_AUDIO_STREAM_H_ |
| 6 #define MEDIA_AUDIO_AGC_AUDIO_STREAM_H_ | 6 #define MEDIA_AUDIO_AGC_AUDIO_STREAM_H_ |
| 7 | 7 |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 } | 126 } |
| 127 | 127 |
| 128 // Gets the latest stored volume level if AGC is enabled. | 128 // Gets the latest stored volume level if AGC is enabled. |
| 129 // Called at each capture callback on a real-time capture thread (platform | 129 // Called at each capture callback on a real-time capture thread (platform |
| 130 // dependent). | 130 // dependent). |
| 131 void GetAgcVolume(double* normalized_volume) { | 131 void GetAgcVolume(double* normalized_volume) { |
| 132 base::AutoLock lock(lock_); | 132 base::AutoLock lock(lock_); |
| 133 *normalized_volume = normalized_volume_; | 133 *normalized_volume = normalized_volume_; |
| 134 } | 134 } |
| 135 | 135 |
| 136 // Gets the current automatic gain control state. |
| 137 bool GetAutomaticGainControl() override { |
| 138 DCHECK(thread_checker_.CalledOnValidThread()); |
| 139 return agc_is_enabled_; |
| 140 } |
| 141 |
| 136 private: | 142 private: |
| 137 // Sets the automatic gain control (AGC) to on or off. When AGC is enabled, | 143 // Sets the automatic gain control (AGC) to on or off. When AGC is enabled, |
| 138 // the microphone volume is queried periodically and the volume level can | 144 // the microphone volume is queried periodically and the volume level can |
| 139 // be read in each AudioInputCallback::OnData() callback and fed to the | 145 // be read in each AudioInputCallback::OnData() callback and fed to the |
| 140 // render-side AGC. User must call StartAgc() as well to start measuring | 146 // render-side AGC. User must call StartAgc() as well to start measuring |
| 141 // the microphone level. | 147 // the microphone level. |
| 142 bool SetAutomaticGainControl(bool enabled) override { | 148 bool SetAutomaticGainControl(bool enabled) override { |
| 143 DVLOG(1) << "SetAutomaticGainControl(enabled=" << enabled << ")"; | 149 DVLOG(1) << "SetAutomaticGainControl(enabled=" << enabled << ")"; |
| 144 DCHECK(thread_checker_.CalledOnValidThread()); | 150 DCHECK(thread_checker_.CalledOnValidThread()); |
| 145 agc_is_enabled_ = enabled; | 151 agc_is_enabled_ = enabled; |
| 146 return true; | 152 return true; |
| 147 } | 153 } |
| 148 | 154 |
| 149 // Gets the current automatic gain control state. | |
| 150 bool GetAutomaticGainControl() override { | |
| 151 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 152 return agc_is_enabled_; | |
| 153 } | |
| 154 | |
| 155 // Takes a new microphone volume sample and stores it in |normalized_volume_|. | 155 // Takes a new microphone volume sample and stores it in |normalized_volume_|. |
| 156 // Range is normalized to [0.0,1.0] or [0.0, 1.5] on Linux. | 156 // Range is normalized to [0.0,1.0] or [0.0, 1.5] on Linux. |
| 157 // This method is called periodically when AGC is enabled and always on the | 157 // This method is called periodically when AGC is enabled and always on the |
| 158 // audio manager thread. We use it to read the current microphone level and | 158 // audio manager thread. We use it to read the current microphone level and |
| 159 // to store it so it can be read by the main capture thread. By using this | 159 // to store it so it can be read by the main capture thread. By using this |
| 160 // approach, we can avoid accessing audio hardware from a real-time audio | 160 // approach, we can avoid accessing audio hardware from a real-time audio |
| 161 // thread and it leads to a more stable capture performance. | 161 // thread and it leads to a more stable capture performance. |
| 162 void QueryAndStoreNewMicrophoneVolume() { | 162 void QueryAndStoreNewMicrophoneVolume() { |
| 163 DCHECK(thread_checker_.CalledOnValidThread()); | 163 DCHECK(thread_checker_.CalledOnValidThread()); |
| 164 | 164 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 | 197 |
| 198 // Protects |normalized_volume_| . | 198 // Protects |normalized_volume_| . |
| 199 base::Lock lock_; | 199 base::Lock lock_; |
| 200 | 200 |
| 201 DISALLOW_COPY_AND_ASSIGN(AgcAudioStream<AudioInterface>); | 201 DISALLOW_COPY_AND_ASSIGN(AgcAudioStream<AudioInterface>); |
| 202 }; | 202 }; |
| 203 | 203 |
| 204 } // namespace media | 204 } // namespace media |
| 205 | 205 |
| 206 #endif // MEDIA_AUDIO_AGC_AUDIO_STREAM_H_ | 206 #endif // MEDIA_AUDIO_AGC_AUDIO_STREAM_H_ |
| OLD | NEW |