Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2304)

Unified Diff: content/renderer/media/audio_input_device.cc

Issue 9702019: Adds Analog Gain Control (AGC) to the WebRTC client. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added audio_input_stream_impl.h/.cc Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/media/audio_input_device.h ('k') | content/renderer/media/webrtc_audio_device_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 4822ef32e4b3a1f4634fcd9c492828900d394e08..074243624b77a02257950706bdb43d1efb848d45 100644
--- a/content/renderer/media/audio_input_device.cc
+++ b/content/renderer/media/audio_input_device.cc
@@ -48,7 +48,8 @@ AudioInputDevice::AudioInputDevice(size_t buffer_size,
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:38 indent
filter_ = RenderThreadImpl::current()->audio_input_message_filter();
#if defined(OS_MACOSX)
DVLOG(1) << "Using AUDIO_PCM_LOW_LATENCY as input mode on Mac OS X.";
@@ -97,15 +98,27 @@ void AudioInputDevice::Stop() {
}
bool AudioInputDevice::SetVolume(double volume) {
- NOTIMPLEMENTED();
- return false;
+ if (volume < 0 || volume > 1.0)
+ return false;
tommi (sloooow) - chröme 2012/03/26 15:26:38 NOTREACHED?
+
+ 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.
@@ -119,7 +132,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;
@@ -148,6 +162,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
@@ -168,6 +183,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.
+ DCHECK_EQ(0, stream_id_);
+ 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,
@@ -265,7 +292,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;
@@ -301,8 +328,18 @@ void AudioInputDevice::AudioThreadCallback::MapSharedMemory() {
}
void AudioInputDevice::AudioThreadCallback::Process(int pending_data) {
+
tommi (sloooow) - chröme 2012/03/26 15:26:38 remove empty line
+ // 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[0]);
const size_t number_of_frames = audio_parameters_.samples_per_packet;
const int bytes_per_sample = sizeof(memory[0]);
@@ -321,5 +358,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);
}
« no previous file with comments | « content/renderer/media/audio_input_device.h ('k') | content/renderer/media/webrtc_audio_device_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698