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

Side by Side Diff: content/browser/renderer_host/media/audio_input_renderer_host.cc

Issue 9702019: Adds Analog Gain Control (AGC) to the WebRTC client. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/renderer_host/media/audio_input_renderer_host.h" 5 #include "content/browser/renderer_host/media/audio_input_renderer_host.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/process.h" 9 #include "base/process.h"
10 #include "base/shared_memory.h" 10 #include "base/shared_memory.h"
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 } 167 }
168 168
169 bool AudioInputRendererHost::OnMessageReceived(const IPC::Message& message, 169 bool AudioInputRendererHost::OnMessageReceived(const IPC::Message& message,
170 bool* message_was_ok) { 170 bool* message_was_ok) {
171 bool handled = true; 171 bool handled = true;
172 IPC_BEGIN_MESSAGE_MAP_EX(AudioInputRendererHost, message, *message_was_ok) 172 IPC_BEGIN_MESSAGE_MAP_EX(AudioInputRendererHost, message, *message_was_ok)
173 IPC_MESSAGE_HANDLER(AudioInputHostMsg_StartDevice, OnStartDevice) 173 IPC_MESSAGE_HANDLER(AudioInputHostMsg_StartDevice, OnStartDevice)
174 IPC_MESSAGE_HANDLER(AudioInputHostMsg_CreateStream, OnCreateStream) 174 IPC_MESSAGE_HANDLER(AudioInputHostMsg_CreateStream, OnCreateStream)
175 IPC_MESSAGE_HANDLER(AudioInputHostMsg_RecordStream, OnRecordStream) 175 IPC_MESSAGE_HANDLER(AudioInputHostMsg_RecordStream, OnRecordStream)
176 IPC_MESSAGE_HANDLER(AudioInputHostMsg_CloseStream, OnCloseStream) 176 IPC_MESSAGE_HANDLER(AudioInputHostMsg_CloseStream, OnCloseStream)
177 IPC_MESSAGE_HANDLER(AudioInputHostMsg_GetVolume, OnGetVolume)
178 IPC_MESSAGE_HANDLER(AudioInputHostMsg_SetVolume, OnSetVolume) 177 IPC_MESSAGE_HANDLER(AudioInputHostMsg_SetVolume, OnSetVolume)
179 IPC_MESSAGE_UNHANDLED(handled = false) 178 IPC_MESSAGE_UNHANDLED(handled = false)
180 IPC_END_MESSAGE_MAP_EX() 179 IPC_END_MESSAGE_MAP_EX()
181 180
182 return handled; 181 return handled;
183 } 182 }
184 void AudioInputRendererHost::OnStartDevice(int stream_id, int session_id) { 183 void AudioInputRendererHost::OnStartDevice(int stream_id, int session_id) {
185 VLOG(1) << "AudioInputRendererHost::OnStartDevice(stream_id=" 184 VLOG(1) << "AudioInputRendererHost::OnStartDevice(stream_id="
186 << stream_id << ", session_id = " << session_id << ")"; 185 << stream_id << ", session_id = " << session_id << ")";
187 186
188 // Get access to the AudioInputDeviceManager to start the device. 187 // Get access to the AudioInputDeviceManager to start the device.
189 media_stream::AudioInputDeviceManager* audio_input_man = 188 media_stream::AudioInputDeviceManager* audio_input_man =
190 media_stream::MediaStreamManager::GetForResourceContext( 189 media_stream::MediaStreamManager::GetForResourceContext(
191 resource_context_, audio_manager_)->audio_input_device_manager(); 190 resource_context_, audio_manager_)->audio_input_device_manager();
192 191
193 // Add the session entry to the map. 192 // Add the session entry to the map.
194 session_entries_[session_id] = stream_id; 193 session_entries_[session_id] = stream_id;
195 194
196 // Start the device with the session_id. If the device is started 195 // Start the device with the session_id. If the device is started
197 // successfully, OnDeviceStarted() callback will be triggered. 196 // successfully, OnDeviceStarted() callback will be triggered.
198 audio_input_man->Start(session_id, this); 197 audio_input_man->Start(session_id, this);
199 } 198 }
200 199
201 void AudioInputRendererHost::OnCreateStream(int stream_id, 200 void AudioInputRendererHost::OnCreateStream(int stream_id,
202 const AudioParameters& params, 201 const AudioParameters& params,
203 const std::string& device_id) { 202 const std::string& device_id,
203 bool automatic_gain_control) {
204 VLOG(1) << "AudioInputRendererHost::OnCreateStream(stream_id=" 204 VLOG(1) << "AudioInputRendererHost::OnCreateStream(stream_id="
205 << stream_id << ")"; 205 << stream_id << ")";
206 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 206 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
207 DCHECK(LookupById(stream_id) == NULL); 207 DCHECK(LookupById(stream_id) == NULL);
208 208
209 AudioParameters audio_params(params); 209 AudioParameters audio_params(params);
210 210
211 DCHECK_GT(audio_params.frames_per_buffer(), 0); 211 DCHECK_GT(audio_params.frames_per_buffer(), 0);
212 uint32 buffer_size = audio_params.GetBytesPerBuffer(); 212 uint32 buffer_size = audio_params.GetBytesPerBuffer();
213 213
214 // Create a new AudioEntry structure. 214 // Create a new AudioEntry structure.
215 scoped_ptr<AudioEntry> entry(new AudioEntry()); 215 scoped_ptr<AudioEntry> entry(new AudioEntry());
216 216
217 uint32 mem_size = sizeof(AudioInputBufferParameters) + buffer_size;
218
217 // Create the shared memory and share it with the renderer process 219 // Create the shared memory and share it with the renderer process
218 // using a new SyncWriter object. 220 // using a new SyncWriter object.
219 if (!entry->shared_memory.CreateAndMapAnonymous(buffer_size)) { 221 if (!entry->shared_memory.CreateAndMapAnonymous(mem_size)) {
220 // If creation of shared memory failed then send an error message. 222 // If creation of shared memory failed then send an error message.
221 SendErrorMessage(stream_id); 223 SendErrorMessage(stream_id);
222 return; 224 return;
223 } 225 }
224 226
225 scoped_ptr<AudioInputSyncWriter> writer( 227 scoped_ptr<AudioInputSyncWriter> writer(
226 new AudioInputSyncWriter(&entry->shared_memory)); 228 new AudioInputSyncWriter(&entry->shared_memory));
227 229
228 if (!writer->Init()) { 230 if (!writer->Init()) {
229 SendErrorMessage(stream_id); 231 SendErrorMessage(stream_id);
(...skipping 11 matching lines...) Expand all
241 this, 243 this,
242 audio_params, 244 audio_params,
243 device_id, 245 device_id,
244 entry->writer.get()); 246 entry->writer.get());
245 247
246 if (!entry->controller) { 248 if (!entry->controller) {
247 SendErrorMessage(stream_id); 249 SendErrorMessage(stream_id);
248 return; 250 return;
249 } 251 }
250 252
253 // Set the initial AGC state for the audio input stream.
254 entry->controller->SetAutomaticGainControl(automatic_gain_control);
255
251 // If we have created the controller successfully create a entry and add it 256 // If we have created the controller successfully create a entry and add it
252 // to the map. 257 // to the map.
253 entry->stream_id = stream_id; 258 entry->stream_id = stream_id;
254 259
255 audio_entries_.insert(std::make_pair(stream_id, entry.release())); 260 audio_entries_.insert(std::make_pair(stream_id, entry.release()));
256 } 261 }
257 262
258 void AudioInputRendererHost::OnRecordStream(int stream_id) { 263 void AudioInputRendererHost::OnRecordStream(int stream_id) {
259 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 264 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
260 265
(...skipping 22 matching lines...) Expand all
283 288
284 void AudioInputRendererHost::OnSetVolume(int stream_id, double volume) { 289 void AudioInputRendererHost::OnSetVolume(int stream_id, double volume) {
285 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 290 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
286 291
287 AudioEntry* entry = LookupById(stream_id); 292 AudioEntry* entry = LookupById(stream_id);
288 if (!entry) { 293 if (!entry) {
289 SendErrorMessage(stream_id); 294 SendErrorMessage(stream_id);
290 return; 295 return;
291 } 296 }
292 297
293 // TODO(henrika): TBI. 298 entry->controller->SetVolume(volume);
294 NOTIMPLEMENTED();
295 }
296
297 void AudioInputRendererHost::OnGetVolume(int stream_id) {
298 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
299
300 AudioEntry* entry = LookupById(stream_id);
301 if (!entry) {
302 SendErrorMessage(stream_id);
303 return;
304 }
305
306 // TODO(henrika): TBI.
307 NOTIMPLEMENTED();
308 } 299 }
309 300
310 void AudioInputRendererHost::SendErrorMessage(int stream_id) { 301 void AudioInputRendererHost::SendErrorMessage(int stream_id) {
311 Send(new AudioInputMsg_NotifyStreamStateChanged(stream_id, 302 Send(new AudioInputMsg_NotifyStreamStateChanged(stream_id,
312 kAudioStreamError)); 303 kAudioStreamError));
313 } 304 }
314 305
315 void AudioInputRendererHost::DeleteEntries() { 306 void AudioInputRendererHost::DeleteEntries() {
316 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 307 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
317 308
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 418 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
428 419
429 for (SessionEntryMap::iterator it = session_entries_.begin(); 420 for (SessionEntryMap::iterator it = session_entries_.begin();
430 it != session_entries_.end(); ++it) { 421 it != session_entries_.end(); ++it) {
431 if (stream_id == it->second) { 422 if (stream_id == it->second) {
432 return it->first; 423 return it->first;
433 } 424 }
434 } 425 }
435 return 0; 426 return 0;
436 } 427 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698