| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 namespace media { | 66 namespace media { |
| 67 | 67 |
| 68 template <typename AudioInterface> | 68 template <typename AudioInterface> |
| 69 class MEDIA_EXPORT AgcAudioStream : public AudioInterface { | 69 class MEDIA_EXPORT AgcAudioStream : public AudioInterface { |
| 70 public: | 70 public: |
| 71 // Time between two successive timer events. | 71 // Time between two successive timer events. |
| 72 static const int kIntervalBetweenVolumeUpdatesMs = 1000; | 72 static const int kIntervalBetweenVolumeUpdatesMs = 1000; |
| 73 | 73 |
| 74 AgcAudioStream() | 74 AgcAudioStream() |
| 75 : agc_is_enabled_(false), max_volume_(0.0), normalized_volume_(0.0) { | 75 : agc_is_enabled_(false), max_volume_(0.0), normalized_volume_(0.0) { |
| 76 DVLOG(1) << __FUNCTION__; |
| 76 } | 77 } |
| 77 | 78 |
| 78 virtual ~AgcAudioStream() { | 79 virtual ~AgcAudioStream() { |
| 79 DCHECK(thread_checker_.CalledOnValidThread()); | 80 DCHECK(thread_checker_.CalledOnValidThread()); |
| 81 DVLOG(1) << __FUNCTION__; |
| 80 } | 82 } |
| 81 | 83 |
| 82 protected: | 84 protected: |
| 83 // Starts the periodic timer which periodically checks and updates the | 85 // Starts the periodic timer which periodically checks and updates the |
| 84 // current microphone volume level. | 86 // current microphone volume level. |
| 85 // The timer is only started if AGC mode is first enabled using the | 87 // The timer is only started if AGC mode is first enabled using the |
| 86 // SetAutomaticGainControl() method. | 88 // SetAutomaticGainControl() method. |
| 87 void StartAgc() { | 89 void StartAgc() { |
| 90 DVLOG(1) << "StartAgc()"; |
| 88 DCHECK(thread_checker_.CalledOnValidThread()); | 91 DCHECK(thread_checker_.CalledOnValidThread()); |
| 89 if (!agc_is_enabled_ || timer_.IsRunning()) | 92 if (!agc_is_enabled_ || timer_.IsRunning()) |
| 90 return; | 93 return; |
| 91 | 94 |
| 92 // Query and cache the volume to avoid sending 0 as volume to AGC at the | 95 // Query and cache the volume to avoid sending 0 as volume to AGC at the |
| 93 // beginning of the audio stream, otherwise AGC will try to raise the | 96 // beginning of the audio stream, otherwise AGC will try to raise the |
| 94 // volume from 0. | 97 // volume from 0. |
| 95 QueryAndStoreNewMicrophoneVolume(); | 98 QueryAndStoreNewMicrophoneVolume(); |
| 96 | 99 |
| 97 timer_.Start(FROM_HERE, | 100 timer_.Start(FROM_HERE, |
| 98 base::TimeDelta::FromMilliseconds(kIntervalBetweenVolumeUpdatesMs), | 101 base::TimeDelta::FromMilliseconds(kIntervalBetweenVolumeUpdatesMs), |
| 99 this, &AgcAudioStream::QueryAndStoreNewMicrophoneVolume); | 102 this, &AgcAudioStream::QueryAndStoreNewMicrophoneVolume); |
| 100 } | 103 } |
| 101 | 104 |
| 102 // Stops the periodic timer which periodically checks and updates the | 105 // Stops the periodic timer which periodically checks and updates the |
| 103 // current microphone volume level. | 106 // current microphone volume level. |
| 104 void StopAgc() { | 107 void StopAgc() { |
| 108 DVLOG(1) << "StopAgc()"; |
| 105 DCHECK(thread_checker_.CalledOnValidThread()); | 109 DCHECK(thread_checker_.CalledOnValidThread()); |
| 106 if (timer_.IsRunning()) | 110 if (timer_.IsRunning()) |
| 107 timer_.Stop(); | 111 timer_.Stop(); |
| 108 } | 112 } |
| 109 | 113 |
| 110 // Stores a new microphone volume level by checking the audio input device. | 114 // Stores a new microphone volume level by checking the audio input device. |
| 111 // Called on the audio manager thread. | 115 // Called on the audio manager thread. |
| 112 void UpdateAgcVolume() { | 116 void UpdateAgcVolume() { |
| 113 DCHECK(thread_checker_.CalledOnValidThread()); | 117 DCHECK(thread_checker_.CalledOnValidThread()); |
| 114 | 118 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 | 199 |
| 196 // Protects |normalized_volume_| . | 200 // Protects |normalized_volume_| . |
| 197 base::Lock lock_; | 201 base::Lock lock_; |
| 198 | 202 |
| 199 DISALLOW_COPY_AND_ASSIGN(AgcAudioStream<AudioInterface>); | 203 DISALLOW_COPY_AND_ASSIGN(AgcAudioStream<AudioInterface>); |
| 200 }; | 204 }; |
| 201 | 205 |
| 202 } // namespace media | 206 } // namespace media |
| 203 | 207 |
| 204 #endif // MEDIA_AUDIO_AGC_AUDIO_STREAM_H_ | 208 #endif // MEDIA_AUDIO_AGC_AUDIO_STREAM_H_ |
| OLD | NEW |