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..a7304f5de7dfb7a2ce07461eda73c0b5e89b51bc 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) { |
tommi (sloooow) - chröme
2012/03/26 15:26:40
indent is off.
henrika (OOO until Aug 14)
2012/03/27 09:20:38
Done.
|
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()); |
+ // The state of the AGC can not be modified while capturing is active. |
tommi (sloooow) - chröme
2012/03/26 15:26:40
Are the reasons for this still valid?
henrika (OOO until Aug 14)
2012/03/27 09:20:38
Yes, I have removed locks in on the media side und
|
+ DCHECK_EQ(0, stream_id_); |
scherkus (not reviewing)
2012/03/26 22:41:04
want to move that comment into a DCHECK() message?
henrika (OOO until Aug 14)
2012/03/27 09:20:38
Done.
|
+ 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,18 @@ void AudioInputDevice::AudioThreadCallback::MapSharedMemory() { |
} |
void AudioInputDevice::AudioThreadCallback::Process(int pending_data) { |
+ |
tommi (sloooow) - chröme
2012/03/26 15:26:40
remove this empty line
henrika (OOO until Aug 14)
2012/03/27 09:20:38
Done.
|
+ // 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 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); |
tommi (sloooow) - chröme
2012/03/26 15:26:40
nit: &buffer->audio[0]
henrika (OOO until Aug 14)
2012/03/27 09:20:38
Done.
|
const size_t number_of_frames = audio_parameters_.frames_per_buffer(); |
const int bytes_per_sample = sizeof(memory[0]); |
@@ -306,5 +343,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); |
} |