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

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

Issue 260073013: Added automatic mode to FakeInputAudioStream to generate automatic beeps (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: addressed the comments. Created 6 years, 7 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_device_name.h" 11 #include "media/audio/audio_device_name.h"
12 #include "media/audio/audio_input_ipc.h" 12 #include "media/audio/audio_input_ipc.h"
13 #include "media/audio/audio_manager_base.h" 13 #include "media/audio/audio_manager_base.h"
14 #include "media/audio/audio_parameters.h" 14 #include "media/audio/audio_parameters.h"
15 #include "media/base/channel_layout.h" 15 #include "media/base/channel_layout.h"
16 #include "media/base/scoped_histogram_timer.h" 16 #include "media/base/scoped_histogram_timer.h"
17 17
18 namespace content { 18 namespace content {
19 19
20 const int AudioInputDeviceManager::kFakeOpenSessionId = 1; 20 const int AudioInputDeviceManager::kFakeOpenSessionId = 1;
21 21
22 const char kFakeDeviceName[] = "Fake Audio";
23 const char kFakeDeviceId[] = "fake_audio";
24
22 namespace { 25 namespace {
23 // Starting id for the first capture session. 26 // Starting id for the first capture session.
24 const int kFirstSessionId = AudioInputDeviceManager::kFakeOpenSessionId + 1; 27 const int kFirstSessionId = AudioInputDeviceManager::kFakeOpenSessionId + 1;
25 } 28 }
26 29
27 AudioInputDeviceManager::AudioInputDeviceManager( 30 AudioInputDeviceManager::AudioInputDeviceManager(
28 media::AudioManager* audio_manager) 31 media::AudioManager* audio_manager)
29 : listener_(NULL), 32 : listener_(NULL),
30 next_capture_session_id_(kFirstSessionId), 33 next_capture_session_id_(kFirstSessionId),
31 use_fake_device_(false), 34 use_fake_device_(false),
32 audio_manager_(audio_manager) { 35 audio_manager_(audio_manager) {
33 // TODO(xians): Remove this fake_device after the unittests do not need it. 36 // TODO(xians): Remove this fake_device after the unittests do not need it.
34 StreamDeviceInfo fake_device(MEDIA_DEVICE_AUDIO_CAPTURE, 37 StreamDeviceInfo fake_device(MEDIA_DEVICE_AUDIO_CAPTURE,
35 media::AudioManagerBase::kDefaultDeviceName, 38 kFakeDeviceName,
36 media::AudioManagerBase::kDefaultDeviceId, 39 kFakeDeviceId,
37 44100, media::CHANNEL_LAYOUT_STEREO, 40 44100, media::CHANNEL_LAYOUT_STEREO,
38 0); 41 0);
39 fake_device.session_id = kFakeOpenSessionId; 42 fake_device.session_id = kFakeOpenSessionId;
40 devices_.push_back(fake_device); 43 devices_.push_back(fake_device);
41 } 44 }
42 45
43 AudioInputDeviceManager::~AudioInputDeviceManager() { 46 AudioInputDeviceManager::~AudioInputDeviceManager() {
44 } 47 }
45 48
46 const StreamDeviceInfo* AudioInputDeviceManager::GetOpenedDeviceInfoById( 49 const StreamDeviceInfo* AudioInputDeviceManager::GetOpenedDeviceInfoById(
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 bool AudioInputDeviceManager::ShouldUseFakeDevice() const { 119 bool AudioInputDeviceManager::ShouldUseFakeDevice() const {
117 DCHECK_CURRENTLY_ON(BrowserThread::IO); 120 DCHECK_CURRENTLY_ON(BrowserThread::IO);
118 return use_fake_device_; 121 return use_fake_device_;
119 } 122 }
120 123
121 void AudioInputDeviceManager::EnumerateOnDeviceThread( 124 void AudioInputDeviceManager::EnumerateOnDeviceThread(
122 MediaStreamType stream_type) { 125 MediaStreamType stream_type) {
123 SCOPED_UMA_HISTOGRAM_TIMER( 126 SCOPED_UMA_HISTOGRAM_TIMER(
124 "Media.AudioInputDeviceManager.EnumerateOnDeviceThreadTime"); 127 "Media.AudioInputDeviceManager.EnumerateOnDeviceThreadTime");
125 DCHECK(IsOnDeviceThread()); 128 DCHECK(IsOnDeviceThread());
129 DCHECK_EQ(MEDIA_DEVICE_AUDIO_CAPTURE, stream_type);
126 130
131 // Enumerate the devices on the OS.
132 // AudioManager is guaranteed to outlive MediaStreamManager in
133 // BrowserMainloop.
127 media::AudioDeviceNames device_names; 134 media::AudioDeviceNames device_names;
128 135 audio_manager_->GetAudioInputDeviceNames(&device_names);
129 switch (stream_type) {
130 case MEDIA_DEVICE_AUDIO_CAPTURE:
131 // AudioManager is guaranteed to outlive MediaStreamManager in
132 // BrowserMainloop.
133 audio_manager_->GetAudioInputDeviceNames(&device_names);
134 break;
135
136 default:
137 NOTREACHED();
138 break;
139 }
140 136
141 scoped_ptr<StreamDeviceInfoArray> devices(new StreamDeviceInfoArray()); 137 scoped_ptr<StreamDeviceInfoArray> devices(new StreamDeviceInfoArray());
142 for (media::AudioDeviceNames::iterator it = device_names.begin(); 138 for (media::AudioDeviceNames::iterator it = device_names.begin();
143 it != device_names.end(); ++it) { 139 it != device_names.end(); ++it) {
144 // Add device information to device vector. 140 // Add device information to device vector.
145 devices->push_back(StreamDeviceInfo( 141 devices->push_back(StreamDeviceInfo(
146 stream_type, it->device_name, it->unique_id)); 142 stream_type, it->device_name, it->unique_id));
147 } 143 }
148 144
149 // If the |use_fake_device_| flag is on, inject the fake device if there is
150 // no available device on the OS.
151 if (use_fake_device_ && devices->empty()) { 145 if (use_fake_device_ && devices->empty()) {
152 devices->push_back(StreamDeviceInfo( 146 // Some unittests can mock the AudioManager enumeration APIs to inject
153 stream_type, media::AudioManagerBase::kDefaultDeviceName, 147 // their own fake devices, so we only inject the fake device if
154 media::AudioManagerBase::kDefaultDeviceId)); 148 // |use_fake_device_| flag is on and there is no enumerated device.
149 devices->push_back(StreamDeviceInfo(stream_type, kFakeDeviceName,
DaleCurtis 2014/05/02 20:20:09 Won't this now put the fake device at the back of
no longer working on chromium 2014/05/06 14:10:56 That has been the change before this CL, and the w
150 kFakeDeviceId));
155 } 151 }
156 152
157 // Return the device list through the listener by posting a task on 153 // Return the device list through the listener by posting a task on
158 // IO thread since MediaStreamManager handles the callback asynchronously. 154 // IO thread since MediaStreamManager handles the callback asynchronously.
159 BrowserThread::PostTask( 155 BrowserThread::PostTask(
160 BrowserThread::IO, 156 BrowserThread::IO,
161 FROM_HERE, 157 FROM_HERE,
162 base::Bind(&AudioInputDeviceManager::DevicesEnumeratedOnIOThread, 158 base::Bind(&AudioInputDeviceManager::DevicesEnumeratedOnIOThread,
163 this, stream_type, base::Passed(&devices))); 159 this, stream_type, base::Passed(&devices)));
164 } 160 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 for (StreamDeviceList::iterator i(devices_.begin()); i != devices_.end(); 245 for (StreamDeviceList::iterator i(devices_.begin()); i != devices_.end();
250 ++i) { 246 ++i) {
251 if (i->session_id == session_id) 247 if (i->session_id == session_id)
252 return i; 248 return i;
253 } 249 }
254 250
255 return devices_.end(); 251 return devices_.end();
256 } 252 }
257 253
258 } // namespace content 254 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | media/audio/fake_audio_input_stream.h » ('j') | media/audio/fake_audio_input_stream.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698