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

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

Issue 599443003: Activate and inactivate keyboard mic on ChromeOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@check_kmic_set_effect
Patch Set: Created 6 years, 3 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_device_manager.h" 5 #include "content/browser/renderer_host/media/audio_input_device_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "content/public/browser/browser_thread.h" 9 #include "content/public/browser/browser_thread.h"
10 #include "content/public/common/media_stream_request.h" 10 #include "content/public/common/media_stream_request.h"
11 #include "media/audio/audio_input_ipc.h" 11 #include "media/audio/audio_input_ipc.h"
12 #include "media/audio/audio_manager_base.h" 12 #include "media/audio/audio_manager_base.h"
13 #include "media/audio/audio_parameters.h" 13 #include "media/audio/audio_parameters.h"
14 #include "media/base/channel_layout.h" 14 #include "media/base/channel_layout.h"
15 #include "media/base/scoped_histogram_timer.h" 15 #include "media/base/scoped_histogram_timer.h"
16 16
17 #if defined(OS_CHROMEOS)
18 #include "chromeos/audio/cras_audio_handler.h"
19 #endif
20
17 namespace content { 21 namespace content {
18 22
19 const int AudioInputDeviceManager::kFakeOpenSessionId = 1; 23 const int AudioInputDeviceManager::kFakeOpenSessionId = 1;
20 24
21 namespace { 25 namespace {
22 // Starting id for the first capture session. 26 // Starting id for the first capture session.
23 const int kFirstSessionId = AudioInputDeviceManager::kFakeOpenSessionId + 1; 27 const int kFirstSessionId = AudioInputDeviceManager::kFakeOpenSessionId + 1;
24 } 28 }
25 29
26 AudioInputDeviceManager::AudioInputDeviceManager( 30 AudioInputDeviceManager::AudioInputDeviceManager(
27 media::AudioManager* audio_manager) 31 media::AudioManager* audio_manager)
28 : listener_(NULL), 32 : listener_(NULL),
29 next_capture_session_id_(kFirstSessionId), 33 next_capture_session_id_(kFirstSessionId),
30 use_fake_device_(false), 34 use_fake_device_(false),
35 #if defined(OS_CHROMEOS)
36 keyboard_mic_streams_count_(0),
37 #endif
31 audio_manager_(audio_manager) { 38 audio_manager_(audio_manager) {
32 } 39 }
33 40
34 AudioInputDeviceManager::~AudioInputDeviceManager() { 41 AudioInputDeviceManager::~AudioInputDeviceManager() {
35 } 42 }
36 43
37 const StreamDeviceInfo* AudioInputDeviceManager::GetOpenedDeviceInfoById( 44 const StreamDeviceInfo* AudioInputDeviceManager::GetOpenedDeviceInfoById(
38 int session_id) { 45 int session_id) {
39 DCHECK_CURRENTLY_ON(BrowserThread::IO); 46 DCHECK_CURRENTLY_ON(BrowserThread::IO);
40 StreamDeviceList::iterator device = GetDevice(session_id); 47 StreamDeviceList::iterator device = GetDevice(session_id);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 void AudioInputDeviceManager::UseFakeDevice() { 109 void AudioInputDeviceManager::UseFakeDevice() {
103 DCHECK_CURRENTLY_ON(BrowserThread::IO); 110 DCHECK_CURRENTLY_ON(BrowserThread::IO);
104 use_fake_device_ = true; 111 use_fake_device_ = true;
105 } 112 }
106 113
107 bool AudioInputDeviceManager::ShouldUseFakeDevice() const { 114 bool AudioInputDeviceManager::ShouldUseFakeDevice() const {
108 DCHECK_CURRENTLY_ON(BrowserThread::IO); 115 DCHECK_CURRENTLY_ON(BrowserThread::IO);
109 return use_fake_device_; 116 return use_fake_device_;
110 } 117 }
111 118
119 #if defined(OS_CHROMEOS)
120 void AudioInputDeviceManager::RegisterKeyboardMicStream(
121 const base::Closure& callback) {
122 DCHECK_CURRENTLY_ON(BrowserThread::IO);
123
124 ++keyboard_mic_streams_count_;
125 if (keyboard_mic_streams_count_ == 1) {
126 BrowserThread::PostTaskAndReply(
127 BrowserThread::UI,
128 FROM_HERE,
129 base::Bind(
130 &AudioInputDeviceManager::SetKeyboardMicStreamActiveOnUIThread,
131 this,
132 true),
133 callback);
134 } else {
135 callback.Run();
136 }
137 }
138
139 void AudioInputDeviceManager::UnregisterKeyboardMicStream() {
140 DCHECK_CURRENTLY_ON(BrowserThread::IO);
141
142 --keyboard_mic_streams_count_;
143 DCHECK_GE(keyboard_mic_streams_count_, 0);
144 if (keyboard_mic_streams_count_ == 0) {
145 BrowserThread::PostTask(
146 BrowserThread::UI,
147 FROM_HERE,
148 base::Bind(
149 &AudioInputDeviceManager::SetKeyboardMicStreamActiveOnUIThread,
150 this,
151 false));
152 }
153 }
154 #endif
155
112 void AudioInputDeviceManager::EnumerateOnDeviceThread( 156 void AudioInputDeviceManager::EnumerateOnDeviceThread(
113 MediaStreamType stream_type) { 157 MediaStreamType stream_type) {
114 SCOPED_UMA_HISTOGRAM_TIMER( 158 SCOPED_UMA_HISTOGRAM_TIMER(
115 "Media.AudioInputDeviceManager.EnumerateOnDeviceThreadTime"); 159 "Media.AudioInputDeviceManager.EnumerateOnDeviceThreadTime");
116 DCHECK(IsOnDeviceThread()); 160 DCHECK(IsOnDeviceThread());
117 DCHECK_EQ(MEDIA_DEVICE_AUDIO_CAPTURE, stream_type); 161 DCHECK_EQ(MEDIA_DEVICE_AUDIO_CAPTURE, stream_type);
118 162
119 media::AudioDeviceNames device_names; 163 media::AudioDeviceNames device_names;
120 if (use_fake_device_) { 164 if (use_fake_device_) {
121 // Use the fake devices. 165 // Use the fake devices.
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 static const char kFakeDeviceName2[] = "Fake Audio 2"; 287 static const char kFakeDeviceName2[] = "Fake Audio 2";
244 static const char kFakeDeviceId2[] = "fake_audio_2"; 288 static const char kFakeDeviceId2[] = "fake_audio_2";
245 DCHECK(device_names->empty()); 289 DCHECK(device_names->empty());
246 DCHECK(use_fake_device_); 290 DCHECK(use_fake_device_);
247 device_names->push_back(media::AudioDeviceName(kFakeDeviceName1, 291 device_names->push_back(media::AudioDeviceName(kFakeDeviceName1,
248 kFakeDeviceId1)); 292 kFakeDeviceId1));
249 device_names->push_back(media::AudioDeviceName(kFakeDeviceName2, 293 device_names->push_back(media::AudioDeviceName(kFakeDeviceName2,
250 kFakeDeviceId2)); 294 kFakeDeviceId2));
251 } 295 }
252 296
297 #if defined(OS_CHROMEOS)
298 void AudioInputDeviceManager::SetKeyboardMicStreamActiveOnUIThread(
299 bool active) {
300 DCHECK_CURRENTLY_ON(BrowserThread::UI);
301 chromeos::CrasAudioHandler::Get()->SetKeyboardMicActive(active);
302 }
303 #endif
304
305
253 } // namespace content 306 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698