| Index: content/renderer/media/audio_input_device.cc
|
| diff --git a/content/renderer/media/audio_input_device.cc b/content/renderer/media/audio_input_device.cc
|
| index 24e9da923a14f3f8ad72d060fe3381fcb28efb51..11a3938c0026b412229bdaadbd9699bb5ce5844b 100644
|
| --- a/content/renderer/media/audio_input_device.cc
|
| +++ b/content/renderer/media/audio_input_device.cc
|
| @@ -47,7 +47,8 @@ AudioInputDevice::AudioInputDevice(const AudioParameters& params,
|
| volume_(1.0),
|
| stream_id_(0),
|
| session_id_(0),
|
| - pending_device_ready_(false) {
|
| + pending_device_ready_(false),
|
| + agc_is_enabled_(false) {
|
| filter_ = RenderThreadImpl::current()->audio_input_message_filter();
|
| }
|
|
|
| @@ -82,15 +83,27 @@ void AudioInputDevice::Stop() {
|
| }
|
|
|
| bool AudioInputDevice::SetVolume(double volume) {
|
| - NOTIMPLEMENTED();
|
| - return false;
|
| + if (volume < 0 || volume > 1.0)
|
| + return false;
|
| +
|
| + message_loop()->PostTask(FROM_HERE,
|
| + base::Bind(&AudioInputDevice::SetVolumeOnIOThread, this, volume));
|
| +
|
| + return true;
|
| }
|
|
|
| bool AudioInputDevice::GetVolume(double* volume) {
|
| - NOTIMPLEMENTED();
|
| + NOTREACHED();
|
| return false;
|
| }
|
|
|
| +void AudioInputDevice::SetAutomaticGainControl(bool enabled) {
|
| + DVLOG(1) << "SetAutomaticGainControl(enabled=" << enabled << ")";
|
| + message_loop()->PostTask(FROM_HERE,
|
| + base::Bind(&AudioInputDevice::SetAutomaticGainControlOnIOThread,
|
| + this, enabled));
|
| +}
|
| +
|
| void AudioInputDevice::InitializeOnIOThread() {
|
| DCHECK(message_loop()->BelongsToCurrentThread());
|
| // Make sure we don't call Start() more than once.
|
| @@ -104,7 +117,8 @@ void AudioInputDevice::InitializeOnIOThread() {
|
| // and create the stream when getting a OnDeviceReady() callback.
|
| if (!session_id_) {
|
| Send(new AudioInputHostMsg_CreateStream(
|
| - stream_id_, audio_parameters_, AudioManagerBase::kDefaultDeviceId));
|
| + stream_id_, audio_parameters_, AudioManagerBase::kDefaultDeviceId,
|
| + agc_is_enabled_));
|
| } else {
|
| Send(new AudioInputHostMsg_StartDevice(stream_id_, session_id_));
|
| pending_device_ready_ = true;
|
| @@ -133,6 +147,7 @@ void AudioInputDevice::ShutDownOnIOThread() {
|
| stream_id_ = 0;
|
| session_id_ = 0;
|
| pending_device_ready_ = false;
|
| + agc_is_enabled_ = false;
|
| }
|
|
|
| // We can run into an issue where ShutDownOnIOThread is called right after
|
| @@ -153,6 +168,18 @@ void AudioInputDevice::SetVolumeOnIOThread(double volume) {
|
| Send(new AudioInputHostMsg_SetVolume(stream_id_, volume));
|
| }
|
|
|
| +void AudioInputDevice::SetAutomaticGainControlOnIOThread(bool enabled) {
|
| + DCHECK(message_loop()->BelongsToCurrentThread());
|
| + DCHECK_EQ(0, stream_id_) <<
|
| + "The AGC state can not be modified while capturing is active.";
|
| + if (stream_id_)
|
| + return;
|
| +
|
| + // We simply store the new AGC setting here. This value will be used when
|
| + // a new stream is initialized and by GetAutomaticGainControl().
|
| + agc_is_enabled_ = enabled;
|
| +}
|
| +
|
| void AudioInputDevice::OnStreamCreated(
|
| base::SharedMemoryHandle handle,
|
| base::SyncSocket::Handle socket_handle,
|
| @@ -250,7 +277,7 @@ void AudioInputDevice::OnDeviceReady(const std::string& device_id) {
|
| stream_id_ = 0;
|
| } else {
|
| Send(new AudioInputHostMsg_CreateStream(stream_id_, audio_parameters_,
|
| - device_id));
|
| + device_id, agc_is_enabled_));
|
| }
|
|
|
| pending_device_ready_ = false;
|
| @@ -286,8 +313,17 @@ void AudioInputDevice::AudioThreadCallback::MapSharedMemory() {
|
| }
|
|
|
| void AudioInputDevice::AudioThreadCallback::Process(int pending_data) {
|
| + // The shared memory represents parameters, size of the data buffer and the
|
| + // actual data buffer containing audio data. Map the memory into this
|
| + // structure and parse out parameters and the data area.
|
| + AudioInputBuffer* buffer =
|
| + reinterpret_cast<AudioInputBuffer*>(shared_memory_.memory());
|
| + uint32 size = buffer->params.size;
|
| + DCHECK_EQ(size, memory_length_ - sizeof(AudioInputBufferParameters));
|
| + double volume = buffer->params.volume;
|
| +
|
| int audio_delay_milliseconds = pending_data / bytes_per_ms_;
|
| - int16* memory = reinterpret_cast<int16*>(shared_memory_.memory());
|
| + int16* memory = reinterpret_cast<int16*>(&buffer->audio[0]);
|
| const size_t number_of_frames = audio_parameters_.frames_per_buffer();
|
| const int bytes_per_sample = sizeof(memory[0]);
|
|
|
| @@ -306,5 +342,5 @@ void AudioInputDevice::AudioThreadCallback::Process(int pending_data) {
|
| // Deliver captured data to the client in floating point format
|
| // and update the audio-delay measurement.
|
| capture_callback_->Capture(audio_data_, number_of_frames,
|
| - audio_delay_milliseconds);
|
| + audio_delay_milliseconds, volume);
|
| }
|
|
|