OLD | NEW |
---|---|
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" |
11 #include "content/browser/renderer_host/media/audio_input_device_manager.h" | 11 #include "content/browser/renderer_host/media/audio_input_device_manager.h" |
12 #include "content/browser/renderer_host/media/audio_input_sync_writer.h" | 12 #include "content/browser/renderer_host/media/audio_input_sync_writer.h" |
13 #include "content/browser/renderer_host/media/media_stream_manager.h" | 13 #include "content/browser/renderer_host/media/media_stream_manager.h" |
14 #include "content/browser/renderer_host/media/web_contents_audio_input_stream.h" | |
14 #include "content/browser/renderer_host/media/web_contents_capture_util.h" | 15 #include "content/browser/renderer_host/media/web_contents_capture_util.h" |
15 #include "content/common/media/audio_messages.h" | 16 #include "content/common/media/audio_messages.h" |
16 | 17 |
17 namespace content { | 18 namespace content { |
18 | 19 |
19 struct AudioInputRendererHost::AudioEntry { | 20 struct AudioInputRendererHost::AudioEntry { |
20 AudioEntry(); | 21 AudioEntry(); |
21 ~AudioEntry(); | 22 ~AudioEntry(); |
22 | 23 |
23 // The AudioInputController that manages the audio input stream. | 24 // The AudioInputController that manages the audio input stream. |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 IPC_MESSAGE_HANDLER(AudioInputHostMsg_AssociateStreamWithConsumer, | 188 IPC_MESSAGE_HANDLER(AudioInputHostMsg_AssociateStreamWithConsumer, |
188 OnAssociateStreamWithConsumer) | 189 OnAssociateStreamWithConsumer) |
189 IPC_MESSAGE_HANDLER(AudioInputHostMsg_RecordStream, OnRecordStream) | 190 IPC_MESSAGE_HANDLER(AudioInputHostMsg_RecordStream, OnRecordStream) |
190 IPC_MESSAGE_HANDLER(AudioInputHostMsg_CloseStream, OnCloseStream) | 191 IPC_MESSAGE_HANDLER(AudioInputHostMsg_CloseStream, OnCloseStream) |
191 IPC_MESSAGE_HANDLER(AudioInputHostMsg_SetVolume, OnSetVolume) | 192 IPC_MESSAGE_HANDLER(AudioInputHostMsg_SetVolume, OnSetVolume) |
192 IPC_MESSAGE_UNHANDLED(handled = false) | 193 IPC_MESSAGE_UNHANDLED(handled = false) |
193 IPC_END_MESSAGE_MAP_EX() | 194 IPC_END_MESSAGE_MAP_EX() |
194 | 195 |
195 return handled; | 196 return handled; |
196 } | 197 } |
198 | |
197 void AudioInputRendererHost::OnStartDevice(int stream_id, int session_id) { | 199 void AudioInputRendererHost::OnStartDevice(int stream_id, int session_id) { |
198 VLOG(1) << "AudioInputRendererHost::OnStartDevice(stream_id=" | 200 VLOG(1) << "AudioInputRendererHost::OnStartDevice(stream_id=" |
199 << stream_id << ", session_id = " << session_id << ")"; | 201 << stream_id << ", session_id = " << session_id << ")"; |
200 | 202 |
201 // Add the session entry to the map. | 203 // Add the session entry to the map. |
202 session_entries_[session_id] = stream_id; | 204 session_entries_[session_id] = stream_id; |
203 | 205 |
204 // Start the device with the session_id. If the device is started | 206 // Start the device with the session_id. If the device is started |
205 // successfully, OnDeviceStarted() callback will be triggered. | 207 // successfully, OnDeviceStarted() callback will be triggered. |
206 media_stream_manager_->audio_input_device_manager()->Start(session_id, this); | 208 media_stream_manager_->audio_input_device_manager()->Start(session_id, this); |
(...skipping 11 matching lines...) Expand all Loading... | |
218 return; | 220 return; |
219 } | 221 } |
220 | 222 |
221 media::AudioParameters audio_params(params); | 223 media::AudioParameters audio_params(params); |
222 | 224 |
223 if (media_stream_manager_->audio_input_device_manager()-> | 225 if (media_stream_manager_->audio_input_device_manager()-> |
224 ShouldUseFakeDevice()) { | 226 ShouldUseFakeDevice()) { |
225 audio_params.Reset(media::AudioParameters::AUDIO_FAKE, | 227 audio_params.Reset(media::AudioParameters::AUDIO_FAKE, |
226 params.channel_layout(), params.sample_rate(), | 228 params.channel_layout(), params.sample_rate(), |
227 params.bits_per_sample(), params.frames_per_buffer()); | 229 params.bits_per_sample(), params.frames_per_buffer()); |
228 } else if (WebContentsCaptureUtil::IsWebContentsDeviceId(device_id)) { | |
229 audio_params.Reset(media::AudioParameters::AUDIO_VIRTUAL, | |
230 params.channel_layout(), params.sample_rate(), | |
231 params.bits_per_sample(), params.frames_per_buffer()); | |
232 } | 230 } |
233 | 231 |
234 uint32 buffer_size = audio_params.GetBytesPerBuffer(); | 232 uint32 buffer_size = audio_params.GetBytesPerBuffer(); |
235 | 233 |
236 // Create a new AudioEntry structure. | 234 // Create a new AudioEntry structure. |
237 scoped_ptr<AudioEntry> entry(new AudioEntry()); | 235 scoped_ptr<AudioEntry> entry(new AudioEntry()); |
238 | 236 |
239 uint32 mem_size = sizeof(media::AudioInputBufferParameters) + buffer_size; | 237 uint32 mem_size = sizeof(media::AudioInputBufferParameters) + buffer_size; |
240 | 238 |
241 // Create the shared memory and share it with the renderer process | 239 // Create the shared memory and share it with the renderer process |
242 // using a new SyncWriter object. | 240 // using a new SyncWriter object. |
243 if (!entry->shared_memory.CreateAndMapAnonymous(mem_size)) { | 241 if (!entry->shared_memory.CreateAndMapAnonymous(mem_size)) { |
244 // If creation of shared memory failed then send an error message. | 242 // If creation of shared memory failed then send an error message. |
245 SendErrorMessage(stream_id); | 243 SendErrorMessage(stream_id); |
246 return; | 244 return; |
247 } | 245 } |
248 | 246 |
249 scoped_ptr<AudioInputSyncWriter> writer( | 247 scoped_ptr<AudioInputSyncWriter> writer( |
250 new AudioInputSyncWriter(&entry->shared_memory)); | 248 new AudioInputSyncWriter(&entry->shared_memory)); |
251 | 249 |
252 if (!writer->Init()) { | 250 if (!writer->Init()) { |
253 SendErrorMessage(stream_id); | 251 SendErrorMessage(stream_id); |
254 return; | 252 return; |
255 } | 253 } |
256 | 254 |
257 // If we have successfully created the SyncWriter then assign it to the | 255 // If we have successfully created the SyncWriter then assign it to the |
258 // entry and construct an AudioInputController. | 256 // entry and construct an AudioInputController. |
259 // TODO(henrika): replace CreateLowLatency() with Create() as soon | 257 // TODO(henrika): replace CreateLowLatency() with Create() as soon |
tommi (sloooow) - chröme
2013/01/14 14:06:48
should this TODO be moved into the else block belo
miu
2013/01/14 21:53:03
Done.
| |
260 // as satish has ensured that Speech Input also uses the default low- | 258 // as satish has ensured that Speech Input also uses the default low- |
261 // latency path. See crbug.com/112472 for details. | 259 // latency path. See crbug.com/112472 for details. |
262 entry->writer.reset(writer.release()); | 260 entry->writer.reset(writer.release()); |
263 entry->controller = media::AudioInputController::CreateLowLatency( | 261 if (WebContentsCaptureUtil::IsWebContentsDeviceId(device_id)) { |
264 audio_manager_, | 262 entry->controller = media::AudioInputController::CreateForStream( |
265 this, | 263 audio_manager_, |
266 audio_params, | 264 this, |
267 device_id, | 265 WebContentsAudioInputStream::Create( |
268 entry->writer.get()); | 266 device_id, audio_params, audio_manager_->GetMessageLoop()), |
267 entry->writer.get()); | |
268 } else { | |
269 entry->controller = media::AudioInputController::CreateLowLatency( | |
270 audio_manager_, | |
271 this, | |
272 audio_params, | |
273 device_id, | |
274 entry->writer.get()); | |
275 } | |
269 | 276 |
270 if (!entry->controller) { | 277 if (!entry->controller) { |
271 SendErrorMessage(stream_id); | 278 SendErrorMessage(stream_id); |
272 return; | 279 return; |
273 } | 280 } |
274 | 281 |
275 // Set the initial AGC state for the audio input stream. Note that, the AGC | 282 // Set the initial AGC state for the audio input stream. Note that, the AGC |
276 // is only supported in AUDIO_PCM_LOW_LATENCY mode. | 283 // is only supported in AUDIO_PCM_LOW_LATENCY mode. |
277 if (params.format() == media::AudioParameters::AUDIO_PCM_LOW_LATENCY) | 284 if (params.format() == media::AudioParameters::AUDIO_PCM_LOW_LATENCY) |
278 entry->controller->SetAutomaticGainControl(automatic_gain_control); | 285 entry->controller->SetAutomaticGainControl(automatic_gain_control); |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
449 for (SessionEntryMap::iterator it = session_entries_.begin(); | 456 for (SessionEntryMap::iterator it = session_entries_.begin(); |
450 it != session_entries_.end(); ++it) { | 457 it != session_entries_.end(); ++it) { |
451 if (stream_id == it->second) { | 458 if (stream_id == it->second) { |
452 return it->first; | 459 return it->first; |
453 } | 460 } |
454 } | 461 } |
455 return 0; | 462 return 0; |
456 } | 463 } |
457 | 464 |
458 } // namespace content | 465 } // namespace content |
OLD | NEW |