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

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: Improved volume updating on Mac 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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) 177 IPC_MESSAGE_HANDLER(AudioInputHostMsg_GetVolume, OnGetVolume)
178 IPC_MESSAGE_HANDLER(AudioInputHostMsg_SetVolume, OnSetVolume) 178 IPC_MESSAGE_HANDLER(AudioInputHostMsg_SetVolume, OnSetVolume)
179 IPC_MESSAGE_HANDLER(AudioInputHostMsg_SetAutomaticGainControl,
180 OnSetAutomaticGainControl)
179 IPC_MESSAGE_UNHANDLED(handled = false) 181 IPC_MESSAGE_UNHANDLED(handled = false)
180 IPC_END_MESSAGE_MAP_EX() 182 IPC_END_MESSAGE_MAP_EX()
181 183
182 return handled; 184 return handled;
183 } 185 }
184 void AudioInputRendererHost::OnStartDevice(int stream_id, int session_id) { 186 void AudioInputRendererHost::OnStartDevice(int stream_id, int session_id) {
185 VLOG(1) << "AudioInputRendererHost::OnStartDevice(stream_id=" 187 VLOG(1) << "AudioInputRendererHost::OnStartDevice(stream_id="
186 << stream_id << ", session_id = " << session_id << ")"; 188 << stream_id << ", session_id = " << session_id << ")";
187 189
188 // Get access to the AudioInputDeviceManager to start the device. 190 // Get access to the AudioInputDeviceManager to start the device.
189 media_stream::AudioInputDeviceManager* audio_input_man = 191 media_stream::AudioInputDeviceManager* audio_input_man =
190 media_stream::MediaStreamManager::GetForResourceContext( 192 media_stream::MediaStreamManager::GetForResourceContext(
191 resource_context_, audio_manager_)->audio_input_device_manager(); 193 resource_context_, audio_manager_)->audio_input_device_manager();
192 194
193 // Add the session entry to the map. 195 // Add the session entry to the map.
194 session_entries_[session_id] = stream_id; 196 session_entries_[session_id] = stream_id;
195 197
196 // Start the device with the session_id. If the device is started 198 // Start the device with the session_id. If the device is started
197 // successfully, OnDeviceStarted() callback will be triggered. 199 // successfully, OnDeviceStarted() callback will be triggered.
198 audio_input_man->Start(session_id, this); 200 audio_input_man->Start(session_id, this);
199 } 201 }
200 202
201 void AudioInputRendererHost::OnCreateStream(int stream_id, 203 void AudioInputRendererHost::OnCreateStream(int stream_id,
202 const AudioParameters& params, 204 const AudioParameters& params,
203 const std::string& device_id) { 205 const std::string& device_id,
206 bool automatic_gain_control) {
204 VLOG(1) << "AudioInputRendererHost::OnCreateStream(stream_id=" 207 VLOG(1) << "AudioInputRendererHost::OnCreateStream(stream_id="
205 << stream_id << ")"; 208 << stream_id << ")";
206 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
207 DCHECK(LookupById(stream_id) == NULL); 210 DCHECK(LookupById(stream_id) == NULL);
208 211
209 AudioParameters audio_params(params); 212 AudioParameters audio_params(params);
210 213
211 DCHECK_GT(audio_params.samples_per_packet, 0); 214 DCHECK_GT(audio_params.samples_per_packet, 0);
212 uint32 packet_size = audio_params.GetPacketSize(); 215 uint32 packet_size = audio_params.GetPacketSize();
213 216
214 // Create a new AudioEntry structure. 217 // Create a new AudioEntry structure.
215 scoped_ptr<AudioEntry> entry(new AudioEntry()); 218 scoped_ptr<AudioEntry> entry(new AudioEntry());
216 219
220 uint32 mem_size = AudioInputBuffer::kSizeOfStructMinusArr + packet_size;
tommi (sloooow) - chröme 2012/03/16 13:31:05 nit: change kSizeOfStructMinusArr -> kSizeOfStruct
henrika (OOO until Aug 14) 2012/03/21 10:16:04 Done.
221
217 // Create the shared memory and share it with the renderer process 222 // Create the shared memory and share it with the renderer process
218 // using a new SyncWriter object. 223 // using a new SyncWriter object.
219 if (!entry->shared_memory.CreateAndMapAnonymous(packet_size)) { 224 if (!entry->shared_memory.CreateAndMapAnonymous(mem_size)) {
220 // If creation of shared memory failed then send an error message. 225 // If creation of shared memory failed then send an error message.
221 SendErrorMessage(stream_id); 226 SendErrorMessage(stream_id);
222 return; 227 return;
223 } 228 }
224 229
225 scoped_ptr<AudioInputSyncWriter> writer( 230 scoped_ptr<AudioInputSyncWriter> writer(
226 new AudioInputSyncWriter(&entry->shared_memory)); 231 new AudioInputSyncWriter(&entry->shared_memory));
227 232
228 if (!writer->Init()) { 233 if (!writer->Init()) {
229 SendErrorMessage(stream_id); 234 SendErrorMessage(stream_id);
(...skipping 11 matching lines...) Expand all
241 this, 246 this,
242 audio_params, 247 audio_params,
243 device_id, 248 device_id,
244 entry->writer.get()); 249 entry->writer.get());
245 250
246 if (!entry->controller) { 251 if (!entry->controller) {
247 SendErrorMessage(stream_id); 252 SendErrorMessage(stream_id);
248 return; 253 return;
249 } 254 }
250 255
256 // Set the initial AGC state for the audio input stream.
257 entry->controller->SetAutomaticGainControl(automatic_gain_control);
258
251 // If we have created the controller successfully create a entry and add it 259 // If we have created the controller successfully create a entry and add it
252 // to the map. 260 // to the map.
253 entry->stream_id = stream_id; 261 entry->stream_id = stream_id;
254 262
255 audio_entries_.insert(std::make_pair(stream_id, entry.release())); 263 audio_entries_.insert(std::make_pair(stream_id, entry.release()));
256 } 264 }
257 265
258 void AudioInputRendererHost::OnRecordStream(int stream_id) { 266 void AudioInputRendererHost::OnRecordStream(int stream_id) {
259 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 267 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
260 268
(...skipping 22 matching lines...) Expand all
283 291
284 void AudioInputRendererHost::OnSetVolume(int stream_id, double volume) { 292 void AudioInputRendererHost::OnSetVolume(int stream_id, double volume) {
285 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 293 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
286 294
287 AudioEntry* entry = LookupById(stream_id); 295 AudioEntry* entry = LookupById(stream_id);
288 if (!entry) { 296 if (!entry) {
289 SendErrorMessage(stream_id); 297 SendErrorMessage(stream_id);
290 return; 298 return;
291 } 299 }
292 300
293 // TODO(henrika): TBI. 301 entry->controller->SetVolume(volume);
302 }
303
304 void AudioInputRendererHost::OnGetVolume(int stream_id) {
294 NOTIMPLEMENTED(); 305 NOTIMPLEMENTED();
tommi (sloooow) - chröme 2012/03/16 13:31:05 Do we need to implement this at some point or neve
scherkus (not reviewing) 2012/03/20 13:49:41 AFAIK GetVolume() is completely unused
henrika (OOO until Aug 14) 2012/03/21 10:16:04 Yeah, you are correct. I might as well drop it act
295 } 306 }
296 307
297 void AudioInputRendererHost::OnGetVolume(int stream_id) { 308 void AudioInputRendererHost::OnSetAutomaticGainControl(int stream_id,
309 bool enabled) {
298 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 310 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
299 311
300 AudioEntry* entry = LookupById(stream_id); 312 AudioEntry* entry = LookupById(stream_id);
301 if (!entry) { 313 if (!entry) {
302 SendErrorMessage(stream_id); 314 SendErrorMessage(stream_id);
303 return; 315 return;
304 } 316 }
305 317
306 // TODO(henrika): TBI. 318 entry->controller->SetAutomaticGainControl(enabled);
307 NOTIMPLEMENTED();
308 } 319 }
309 320
310 void AudioInputRendererHost::SendErrorMessage(int stream_id) { 321 void AudioInputRendererHost::SendErrorMessage(int stream_id) {
311 Send(new AudioInputMsg_NotifyStreamStateChanged(stream_id, 322 Send(new AudioInputMsg_NotifyStreamStateChanged(stream_id,
312 kAudioStreamError)); 323 kAudioStreamError));
313 } 324 }
314 325
315 void AudioInputRendererHost::DeleteEntries() { 326 void AudioInputRendererHost::DeleteEntries() {
316 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 327 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
317 328
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 448 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
438 449
439 for (SessionEntryMap::iterator it = session_entries_.begin(); 450 for (SessionEntryMap::iterator it = session_entries_.begin();
440 it != session_entries_.end(); ++it) { 451 it != session_entries_.end(); ++it) {
441 if (stream_id == it->second) { 452 if (stream_id == it->second) {
442 return it->first; 453 return it->first;
443 } 454 }
444 } 455 }
445 return 0; 456 return 0;
446 } 457 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698