OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef MEDIA_AUDIO_AUDIO_INPUT_STREAM_IMPL_H_ |
| 6 #define MEDIA_AUDIO_AUDIO_INPUT_STREAM_IMPL_H_ |
| 7 |
| 8 #include "base/compiler_specific.h" |
| 9 #include "base/synchronization/lock.h" |
| 10 #include "base/time.h" |
| 11 #include "media/audio/audio_io.h" |
| 12 |
| 13 // AudioInputStreamImpl implements platform-independent parts of the |
| 14 // AudioInputStream interface. Each platform dependent implementation |
| 15 // should derive from this class. |
| 16 // TODO(henrika): we can probably break out more parts from our current |
| 17 // AudioInputStream implementation and move out to this class. |
| 18 class MEDIA_EXPORT AudioInputStreamImpl : public AudioInputStream { |
| 19 public: |
| 20 AudioInputStreamImpl(); |
| 21 virtual ~AudioInputStreamImpl(); |
| 22 |
| 23 // Sets the automatic gain control (AGC) to on or off. When AGC is enabled, |
| 24 // the microphone volume is queried periodically and the volume level is |
| 25 // provided in each AudioInputCallback::OnData() callback and fed to the |
| 26 // render-side AGC. |
| 27 virtual void SetAutomaticGainControl(bool enabled) OVERRIDE; |
| 28 |
| 29 // Gets the current automatic gain control state. |
| 30 virtual bool GetAutomaticGainControl() OVERRIDE; |
| 31 |
| 32 protected: |
| 33 // Stores a new volume level by asking the audio hardware. |
| 34 // This method only has an effect if AGC is enabled. |
| 35 void UpdateAgcVolume(); |
| 36 |
| 37 // Gets the latest stored volume level if AGC is enabled and if |
| 38 // more than one second has passed since the volume was updated the last time. |
| 39 void QueryAgcVolume(double* normalized_volume); |
| 40 |
| 41 private: |
| 42 // Takes a volume sample and stores it in |normalized_volume_|. |
| 43 void GetNormalizedVolume(); |
| 44 |
| 45 // True when automatic gain control is enabled, false otherwise. |
| 46 // Guarded by |lock_|. |
| 47 bool agc_is_enabled_; |
| 48 |
| 49 // Stores the maximum volume which is used for normalization to a volume |
| 50 // range of [0.0, 1.0]. |
| 51 double max_volume_; |
| 52 |
| 53 // Contains last result of internal call to GetVolume(). We save resources |
| 54 // but not querying the capture volume for each callback. Guarded by |lock_|. |
| 55 // The range is normalized to [0.0, 1.0]. |
| 56 double normalized_volume_; |
| 57 |
| 58 // Protects |agc_is_enabled_| and |volume_| . |
| 59 base::Lock lock_; |
| 60 |
| 61 // Keeps track of the last time the microphone volume level was queried. |
| 62 base::Time last_volume_update_time_; |
| 63 |
| 64 DISALLOW_COPY_AND_ASSIGN(AudioInputStreamImpl); |
| 65 }; |
| 66 |
| 67 #endif // MEDIA_AUDIO_AUDIO_INPUT_STREAM_IMPL_H_ |
OLD | NEW |