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/memory/shared_memory.h" | 8 #include "base/memory/shared_memory.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/process/process.h" | 10 #include "base/process/process.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 : stream_id(0), | 44 : stream_id(0), |
45 shared_memory_segment_count(0), | 45 shared_memory_segment_count(0), |
46 pending_close(false) { | 46 pending_close(false) { |
47 } | 47 } |
48 | 48 |
49 AudioInputRendererHost::AudioEntry::~AudioEntry() {} | 49 AudioInputRendererHost::AudioEntry::~AudioEntry() {} |
50 | 50 |
51 AudioInputRendererHost::AudioInputRendererHost( | 51 AudioInputRendererHost::AudioInputRendererHost( |
52 media::AudioManager* audio_manager, | 52 media::AudioManager* audio_manager, |
53 MediaStreamManager* media_stream_manager, | 53 MediaStreamManager* media_stream_manager, |
54 AudioMirroringManager* audio_mirroring_manager, | 54 AudioMirroringManager* audio_mirroring_manager) |
55 media::UserInputMonitor* user_input_monitor) | |
56 : audio_manager_(audio_manager), | 55 : audio_manager_(audio_manager), |
57 media_stream_manager_(media_stream_manager), | 56 media_stream_manager_(media_stream_manager), |
58 audio_mirroring_manager_(audio_mirroring_manager), | 57 audio_mirroring_manager_(audio_mirroring_manager) { |
59 user_input_monitor_(user_input_monitor) {} | 58 } |
60 | 59 |
61 AudioInputRendererHost::~AudioInputRendererHost() { | 60 AudioInputRendererHost::~AudioInputRendererHost() { |
62 DCHECK(audio_entries_.empty()); | 61 DCHECK(audio_entries_.empty()); |
63 } | 62 } |
64 | 63 |
65 void AudioInputRendererHost::OnChannelClosing() { | 64 void AudioInputRendererHost::OnChannelClosing() { |
66 BrowserMessageFilter::OnChannelClosing(); | 65 BrowserMessageFilter::OnChannelClosing(); |
67 | 66 |
68 // Since the IPC channel is gone, close all requested audio streams. | 67 // Since the IPC channel is gone, close all requested audio streams. |
69 DeleteEntries(); | 68 DeleteEntries(); |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 return; | 265 return; |
267 } | 266 } |
268 | 267 |
269 // If we have successfully created the SyncWriter then assign it to the | 268 // If we have successfully created the SyncWriter then assign it to the |
270 // entry and construct an AudioInputController. | 269 // entry and construct an AudioInputController. |
271 entry->writer.reset(writer.release()); | 270 entry->writer.reset(writer.release()); |
272 if (WebContentsCaptureUtil::IsWebContentsDeviceId(device_id)) { | 271 if (WebContentsCaptureUtil::IsWebContentsDeviceId(device_id)) { |
273 entry->controller = media::AudioInputController::CreateForStream( | 272 entry->controller = media::AudioInputController::CreateForStream( |
274 audio_manager_->GetMessageLoop(), | 273 audio_manager_->GetMessageLoop(), |
275 this, | 274 this, |
276 WebContentsAudioInputStream::Create(device_id, | 275 WebContentsAudioInputStream::Create( |
277 audio_params, | 276 device_id, audio_params, audio_manager_->GetWorkerLoop(), |
278 audio_manager_->GetWorkerLoop(), | 277 audio_mirroring_manager_), |
279 audio_mirroring_manager_), | 278 entry->writer.get()); |
280 entry->writer.get(), | |
281 user_input_monitor_); | |
282 } else { | 279 } else { |
283 // TODO(henrika): replace CreateLowLatency() with Create() as soon | 280 // TODO(henrika): replace CreateLowLatency() with Create() as soon |
284 // as satish has ensured that Speech Input also uses the default low- | 281 // as satish has ensured that Speech Input also uses the default low- |
285 // latency path. See crbug.com/112472 for details. | 282 // latency path. See crbug.com/112472 for details. |
286 entry->controller = | 283 entry->controller = media::AudioInputController::CreateLowLatency( |
287 media::AudioInputController::CreateLowLatency(audio_manager_, | 284 audio_manager_, |
288 this, | 285 this, |
289 audio_params, | 286 audio_params, |
290 device_id, | 287 device_id, |
291 entry->writer.get(), | 288 entry->writer.get()); |
292 user_input_monitor_); | |
293 } | 289 } |
294 | 290 |
295 if (!entry->controller.get()) { | 291 if (!entry->controller.get()) { |
296 SendErrorMessage(stream_id); | 292 SendErrorMessage(stream_id); |
297 return; | 293 return; |
298 } | 294 } |
299 | 295 |
300 // Set the initial AGC state for the audio input stream. Note that, the AGC | 296 // Set the initial AGC state for the audio input stream. Note that, the AGC |
301 // is only supported in AUDIO_PCM_LOW_LATENCY mode. | 297 // is only supported in AUDIO_PCM_LOW_LATENCY mode. |
302 if (config.params.format() == media::AudioParameters::AUDIO_PCM_LOW_LATENCY) | 298 if (config.params.format() == media::AudioParameters::AUDIO_PCM_LOW_LATENCY) |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 // TODO(hclam): Implement a faster look up method. | 398 // TODO(hclam): Implement a faster look up method. |
403 for (AudioEntryMap::iterator i = audio_entries_.begin(); | 399 for (AudioEntryMap::iterator i = audio_entries_.begin(); |
404 i != audio_entries_.end(); ++i) { | 400 i != audio_entries_.end(); ++i) { |
405 if (controller == i->second->controller.get()) | 401 if (controller == i->second->controller.get()) |
406 return i->second; | 402 return i->second; |
407 } | 403 } |
408 return NULL; | 404 return NULL; |
409 } | 405 } |
410 | 406 |
411 } // namespace content | 407 } // namespace content |
OLD | NEW |