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.
5 #ifndef MEDIA_AUDIO_AUDIO_INPUT_STREAM_IMPL_H_
6 #define MEDIA_AUDIO_AUDIO_INPUT_STREAM_IMPL_H_
8 #include "base/compiler_specific.h"
9 #include "base/synchronization/lock.h"
10 #include "base/time.h"
11 #include "media/audio/audio_io.h"
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
{
22 AudioInputStreamImpl();
23 virtual ~AudioInputStreamImpl();
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
29 virtual void SetAutomaticGainControl(bool enabled
) OVERRIDE
;
31 // Gets the current automatic gain control state.
32 virtual bool GetAutomaticGainControl() OVERRIDE
;
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();
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
);
44 // Takes a volume sample and stores it in |normalized_volume_|.
45 void GetNormalizedVolume();
47 // True when automatic gain control is enabled, false otherwise.
48 // Guarded by |lock_|.
51 // Stores the maximum volume which is used for normalization to a volume
52 // range of [0.0, 1.0].
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_
;
60 // Protects |agc_is_enabled_| and |volume_| .
63 // Keeps track of the last time the microphone volume level was queried.
64 base::Time last_volume_update_time_
;
66 DISALLOW_COPY_AND_ASSIGN(AudioInputStreamImpl
);
71 #endif // MEDIA_AUDIO_AUDIO_INPUT_STREAM_IMPL_H_