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

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

Issue 21183002: Adding key press detection in the browser process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 4 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
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/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"
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_audio_input_stream.h"
15 #include "content/browser/renderer_host/media/web_contents_capture_util.h" 15 #include "content/browser/renderer_host/media/web_contents_capture_util.h"
16 #include "media/audio/audio_manager_base.h" 16 #include "media/audio/audio_manager_base.h"
17 #include "media/audio/key_press_monitor.h"
17 18
18 namespace content { 19 namespace content {
19 20
20 struct AudioInputRendererHost::AudioEntry { 21 struct AudioInputRendererHost::AudioEntry {
21 AudioEntry(); 22 AudioEntry();
22 ~AudioEntry(); 23 ~AudioEntry();
23 24
24 // The AudioInputController that manages the audio input stream. 25 // The AudioInputController that manages the audio input stream.
25 scoped_refptr<media::AudioInputController> controller; 26 scoped_refptr<media::AudioInputController> controller;
26 27
(...skipping 17 matching lines...) Expand all
44 : stream_id(0), 45 : stream_id(0),
45 shared_memory_segment_count(0), 46 shared_memory_segment_count(0),
46 pending_close(false) { 47 pending_close(false) {
47 } 48 }
48 49
49 AudioInputRendererHost::AudioEntry::~AudioEntry() {} 50 AudioInputRendererHost::AudioEntry::~AudioEntry() {}
50 51
51 AudioInputRendererHost::AudioInputRendererHost( 52 AudioInputRendererHost::AudioInputRendererHost(
52 media::AudioManager* audio_manager, 53 media::AudioManager* audio_manager,
53 MediaStreamManager* media_stream_manager, 54 MediaStreamManager* media_stream_manager,
54 AudioMirroringManager* audio_mirroring_manager) 55 AudioMirroringManager* audio_mirroring_manager,
56 media::KeyPressMonitor* key_press_monitor)
55 : audio_manager_(audio_manager), 57 : audio_manager_(audio_manager),
56 media_stream_manager_(media_stream_manager), 58 media_stream_manager_(media_stream_manager),
57 audio_mirroring_manager_(audio_mirroring_manager) { 59 audio_mirroring_manager_(audio_mirroring_manager),
58 } 60 key_press_monitor_(key_press_monitor) {}
59 61
60 AudioInputRendererHost::~AudioInputRendererHost() { 62 AudioInputRendererHost::~AudioInputRendererHost() {
61 DCHECK(audio_entries_.empty()); 63 DCHECK(audio_entries_.empty());
62 } 64 }
63 65
64 void AudioInputRendererHost::OnChannelClosing() { 66 void AudioInputRendererHost::OnChannelClosing() {
65 BrowserMessageFilter::OnChannelClosing(); 67 BrowserMessageFilter::OnChannelClosing();
66 68
67 // Since the IPC channel is gone, close all requested audio streams. 69 // Since the IPC channel is gone, close all requested audio streams.
68 DeleteEntries(); 70 DeleteEntries();
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 return; 267 return;
266 } 268 }
267 269
268 // If we have successfully created the SyncWriter then assign it to the 270 // If we have successfully created the SyncWriter then assign it to the
269 // entry and construct an AudioInputController. 271 // entry and construct an AudioInputController.
270 entry->writer.reset(writer.release()); 272 entry->writer.reset(writer.release());
271 if (WebContentsCaptureUtil::IsWebContentsDeviceId(device_id)) { 273 if (WebContentsCaptureUtil::IsWebContentsDeviceId(device_id)) {
272 entry->controller = media::AudioInputController::CreateForStream( 274 entry->controller = media::AudioInputController::CreateForStream(
273 audio_manager_->GetMessageLoop(), 275 audio_manager_->GetMessageLoop(),
274 this, 276 this,
275 WebContentsAudioInputStream::Create( 277 WebContentsAudioInputStream::Create(device_id,
276 device_id, audio_params, audio_manager_->GetWorkerLoop(), 278 audio_params,
277 audio_mirroring_manager_), 279 audio_manager_->GetWorkerLoop(),
278 entry->writer.get()); 280 audio_mirroring_manager_),
281 entry->writer.get(),
282 key_press_monitor_);
279 } else { 283 } else {
280 // TODO(henrika): replace CreateLowLatency() with Create() as soon 284 // TODO(henrika): replace CreateLowLatency() with Create() as soon
281 // as satish has ensured that Speech Input also uses the default low- 285 // as satish has ensured that Speech Input also uses the default low-
282 // latency path. See crbug.com/112472 for details. 286 // latency path. See crbug.com/112472 for details.
283 entry->controller = media::AudioInputController::CreateLowLatency( 287 entry->controller =
284 audio_manager_, 288 media::AudioInputController::CreateLowLatency(audio_manager_,
285 this, 289 this,
286 audio_params, 290 audio_params,
287 device_id, 291 device_id,
288 entry->writer.get()); 292 entry->writer.get(),
293 key_press_monitor_);
289 } 294 }
290 295
291 if (!entry->controller.get()) { 296 if (!entry->controller.get()) {
292 SendErrorMessage(stream_id); 297 SendErrorMessage(stream_id);
293 return; 298 return;
294 } 299 }
295 300
296 // Set the initial AGC state for the audio input stream. Note that, the AGC 301 // Set the initial AGC state for the audio input stream. Note that, the AGC
297 // is only supported in AUDIO_PCM_LOW_LATENCY mode. 302 // is only supported in AUDIO_PCM_LOW_LATENCY mode.
298 if (config.params.format() == media::AudioParameters::AUDIO_PCM_LOW_LATENCY) 303 if (config.params.format() == media::AudioParameters::AUDIO_PCM_LOW_LATENCY)
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 // TODO(hclam): Implement a faster look up method. 403 // TODO(hclam): Implement a faster look up method.
399 for (AudioEntryMap::iterator i = audio_entries_.begin(); 404 for (AudioEntryMap::iterator i = audio_entries_.begin();
400 i != audio_entries_.end(); ++i) { 405 i != audio_entries_.end(); ++i) {
401 if (controller == i->second->controller.get()) 406 if (controller == i->second->controller.get())
402 return i->second; 407 return i->second;
403 } 408 }
404 return NULL; 409 return NULL;
405 } 410 }
406 411
407 } // namespace content 412 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698