| Index: media/audio/audio_input_stream_impl.cc
|
| diff --git a/media/audio/audio_input_stream_impl.cc b/media/audio/audio_input_stream_impl.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..7932a949f860490c0794918df564dc2d251fd081
|
| --- /dev/null
|
| +++ b/media/audio/audio_input_stream_impl.cc
|
| @@ -0,0 +1,62 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "media/audio/audio_input_stream_impl.h"
|
| +
|
| +static const int kMinIntervalBetweenVolumeUpdatesMs = 1000;
|
| +
|
| +AudioInputStreamImpl::AudioInputStreamImpl()
|
| + : agc_is_enabled_(false),
|
| + volume_(0.0) {
|
| +}
|
| +
|
| +AudioInputStreamImpl::~AudioInputStreamImpl() {
|
| +}
|
| +
|
| +void AudioInputStreamImpl::SetAutomaticGainControl(bool enabled) {
|
| + agc_is_enabled_ = enabled;
|
| +}
|
| +
|
| +bool AudioInputStreamImpl::GetAutomaticGainControl() {
|
| + return agc_is_enabled_;
|
| +}
|
| +
|
| +void AudioInputStreamImpl::UpdateAgcVolume() {
|
| + base::AutoLock lock(lock_);
|
| +
|
| + // We take new volume samples once every second when the AGC is enabled.
|
| + // To ensure that a new setting has an immediate effect, the new volume
|
| + // setting is cached here. It will ensure that the next OnData() callback
|
| + // will contain a new valid volume level. If this approach was not taken,
|
| + // we could report invalid volume levels to the client for a time period
|
| + // of up to one second.
|
| + if (agc_is_enabled_) {
|
| + volume_ = GetVolume();
|
| + }
|
| +}
|
| +
|
| +void AudioInputStreamImpl::QueryAgcVolume(double* volume) {
|
| + base::AutoLock lock(lock_);
|
| +
|
| + // Only modify the |volume| output reference if AGC is enabled and if
|
| + // more than one second has passed since the volume was updated the last time.
|
| + if (agc_is_enabled_) {
|
| + base::Time now = base::Time::Now();
|
| + if ((now - last_volume_update_time_).InMilliseconds() >
|
| + kMinIntervalBetweenVolumeUpdatesMs) {
|
| + // Retrieve the current volume level by asking the audio hardware.
|
| + // Range is [0.0,1.0].
|
| + *volume = static_cast<double>(GetVolume());
|
| +
|
| + // Store copy of latest volume level.
|
| + volume_ = *volume;
|
| +
|
| + // Ensure that we don't ask for a new volume level at each call.
|
| + last_volume_update_time_ = now;
|
| + } else {
|
| + *volume = volume_;
|
| + }
|
| + }
|
| +}
|
| +
|
|
|