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