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/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 // Gets the current automatic gain control state. | 142 // Gets the current automatic gain control state. |
143 virtual bool GetAutomaticGainControl() OVERRIDE { | 143 virtual bool GetAutomaticGainControl() OVERRIDE { |
144 DCHECK(thread_checker_.CalledOnValidThread()); | 144 DCHECK(thread_checker_.CalledOnValidThread()); |
145 return agc_is_enabled_; | 145 return agc_is_enabled_; |
146 } | 146 } |
147 | 147 |
148 // Takes a new microphone volume sample and stores it in |normalized_volume_|. | 148 // Takes a new microphone volume sample and stores it in |normalized_volume_|. |
149 // Range is normalized to [0.0,1.0] or [0.0, 1.5] on Linux. | 149 // Range is normalized to [0.0,1.0] or [0.0, 1.5] on Linux. |
150 void QueryAndStoreNewMicrophoneVolume() { | 150 void QueryAndStoreNewMicrophoneVolume() { |
151 DCHECK(thread_checker_.CalledOnValidThread()); | 151 DCHECK(thread_checker_.CalledOnValidThread()); |
152 DCHECK(timer_.IsRunning()); | 152 |
| 153 // Avoid updating the volume member if AGC is not running. |
| 154 if (!timer_.IsRunning()) |
| 155 return; |
153 | 156 |
154 // Cach the maximum volume if this is the first time we ask for it. | 157 // Cach the maximum volume if this is the first time we ask for it. |
155 if (max_volume_ == 0.0) | 158 if (max_volume_ == 0.0) |
156 max_volume_ = static_cast<AudioInterface*>(this)->GetMaxVolume(); | 159 max_volume_ = static_cast<AudioInterface*>(this)->GetMaxVolume(); |
157 | 160 |
158 // Retrieve the current volume level by asking the audio hardware. | 161 // Retrieve the current volume level by asking the audio hardware. |
159 // Range is normalized to [0.0,1.0] or [0.0, 1.5] on Linux. | 162 // Range is normalized to [0.0,1.0] or [0.0, 1.5] on Linux. |
160 if (max_volume_ != 0.0) { | 163 if (max_volume_ != 0.0) { |
161 double normalized_volume = | 164 double normalized_volume = |
162 static_cast<AudioInterface*>(this)->GetVolume() / max_volume_; | 165 static_cast<AudioInterface*>(this)->GetVolume() / max_volume_; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 | 199 |
197 // Protects |normalized_volume_| . | 200 // Protects |normalized_volume_| . |
198 base::Lock lock_; | 201 base::Lock lock_; |
199 | 202 |
200 DISALLOW_COPY_AND_ASSIGN(AgcAudioStream<AudioInterface>); | 203 DISALLOW_COPY_AND_ASSIGN(AgcAudioStream<AudioInterface>); |
201 }; | 204 }; |
202 | 205 |
203 } // namespace media | 206 } // namespace media |
204 | 207 |
205 #endif // MEDIA_AUDIO_AGC_AUDIO_STREAM_H_ | 208 #endif // MEDIA_AUDIO_AGC_AUDIO_STREAM_H_ |
OLD | NEW |