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 0c2fd4573c58f71897c8fb1321457157e547b463..4c17c34a49ae6afabac3210ca4986f7a46632b30 100644 |
--- a/content/renderer/media/audio_input_device.cc |
+++ b/content/renderer/media/audio_input_device.cc |
@@ -99,15 +99,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. |
@@ -121,7 +133,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; |
@@ -150,6 +163,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 |
@@ -170,6 +184,21 @@ void AudioInputDevice::SetVolumeOnIOThread(double volume) { |
Send(new AudioInputHostMsg_SetVolume(stream_id_, volume)); |
} |
+void AudioInputDevice::SetAutomaticGainControlOnIOThread(bool enabled) { |
+ DCHECK(message_loop()->BelongsToCurrentThread()); |
+ if (stream_id_) { |
+ // We enter this scope if InitializeOnIOThread() has already been called. |
+ // It means that an audio stream already exists but AGC is disabled. |
+ // We must therefore modify the current AGC setting for the existing |
+ // stream using IPC. |
+ Send(new AudioInputHostMsg_SetAutomaticGainControl(stream_id_, enabled)); |
+ } |
+ |
+ // Always store new AGC setting. 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, |
@@ -261,7 +290,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; |
@@ -298,7 +327,14 @@ void AudioInputDevice::AudioThreadCallback::MapSharedMemory() { |
void AudioInputDevice::AudioThreadCallback::Process(int pending_data) { |
int audio_delay_milliseconds = pending_data / bytes_per_ms_; |
- int16* memory = reinterpret_cast<int16*>(shared_memory_.memory()); |
+ |
+ AudioInputBuffer* buffer = |
+ reinterpret_cast<AudioInputBuffer*>(shared_memory_.memory()); |
tommi (sloooow) - chröme
2012/03/16 13:31:05
indent
henrika (OOO until Aug 14)
2012/03/21 10:16:04
Done.
|
+ |
+ // TODO(henrika): uint32 size = buffer->size; |
tommi (sloooow) - chröme
2012/03/16 13:31:05
ping
henrika (OOO until Aug 14)
2012/03/21 10:16:04
Added DCHECK which uses the size variable.
|
+ |
+ double volume = buffer->volume; |
+ int16* memory = reinterpret_cast<int16*>(buffer->audio); |
tommi (sloooow) - chröme
2012/03/16 13:31:05
nit: &buffer->audio[0]
henrika (OOO until Aug 14)
2012/03/21 10:16:04
Done.
|
const size_t number_of_frames = audio_parameters_.samples_per_packet; |
const int bytes_per_sample = sizeof(memory[0]); |
@@ -317,5 +353,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); |
} |