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

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

Issue 10912004: Begin adding support for tab mirroring via the MediaStream audio/video capturing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: AudioManager injection into MediaStreamManager, consistent enum naming; per wjia@ comments. Also, … Created 8 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 | Annotate | Revision Log
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/browser/renderer_host/media/audio_input_device_manager_event_h andler.h" 9 #include "content/browser/renderer_host/media/audio_input_device_manager_event_h andler.h"
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
11 #include "content/public/common/media_stream_request.h"
11 #include "media/audio/audio_input_ipc.h" 12 #include "media/audio/audio_input_ipc.h"
12 #include "media/audio/audio_manager_base.h" 13 #include "media/audio/audio_manager_base.h"
13 14
14 using content::BrowserThread; 15 using content::BrowserThread;
15 16
16 namespace media_stream { 17 namespace media_stream {
17 18
18 const int AudioInputDeviceManager::kFakeOpenSessionId = 1; 19 const int AudioInputDeviceManager::kFakeOpenSessionId = 1;
19 20
20 // Starting id for the first capture session. 21 // Starting id for the first capture session.
21 const int kFirstSessionId = AudioInputDeviceManager::kFakeOpenSessionId + 1; 22 const int kFirstSessionId = AudioInputDeviceManager::kFakeOpenSessionId + 1;
22 23
23 AudioInputDeviceManager::AudioInputDeviceManager( 24 AudioInputDeviceManager::AudioInputDeviceManager(
24 media::AudioManager* audio_manager) 25 media::AudioManager* audio_manager,
26 media_stream::MediaStreamType device_type)
25 : listener_(NULL), 27 : listener_(NULL),
26 next_capture_session_id_(kFirstSessionId), 28 next_capture_session_id_(kFirstSessionId),
27 audio_manager_(audio_manager) { 29 audio_manager_(audio_manager),
30 device_type_(device_type) {
31 DCHECK(content::IsAudioMediaType(device_type_));
28 } 32 }
29 33
30 AudioInputDeviceManager::~AudioInputDeviceManager() { 34 AudioInputDeviceManager::~AudioInputDeviceManager() {
31 } 35 }
32 36
33 void AudioInputDeviceManager::Register( 37 void AudioInputDeviceManager::Register(
34 MediaStreamProviderListener* listener, 38 MediaStreamProviderListener* listener,
35 base::MessageLoopProxy* device_thread_loop) { 39 base::MessageLoopProxy* device_thread_loop) {
36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
37 DCHECK(!listener_); 41 DCHECK(!listener_);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 } 81 }
78 82
79 device_loop_->PostTask( 83 device_loop_->PostTask(
80 FROM_HERE, 84 FROM_HERE,
81 base::Bind(&AudioInputDeviceManager::CloseOnDeviceThread, 85 base::Bind(&AudioInputDeviceManager::CloseOnDeviceThread,
82 this, session_id)); 86 this, session_id));
83 } 87 }
84 88
85 void AudioInputDeviceManager::EnumerateOnDeviceThread() { 89 void AudioInputDeviceManager::EnumerateOnDeviceThread() {
86 DCHECK(IsOnDeviceThread()); 90 DCHECK(IsOnDeviceThread());
87 // AudioManager is guaranteed to outlive MediaStreamManager in
88 // BrowserMainloop.
89 media::AudioDeviceNames device_names;
90 audio_manager_->GetAudioInputDeviceNames(&device_names);
91 91
92 StreamDeviceInfoArray* devices = new StreamDeviceInfoArray; 92 StreamDeviceInfoArray* devices = new StreamDeviceInfoArray;
93 for (media::AudioDeviceNames::iterator it = device_names.begin(); 93 switch (device_type_) {
94 it != device_names.end(); 94 case content::MEDIA_DEVICE_AUDIO_CAPTURE: {
95 ++it) { 95 // AudioManager is guaranteed to outlive MediaStreamManager in
96 devices->push_back(StreamDeviceInfo( 96 // BrowserMainloop.
97 content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, it->device_name, 97 media::AudioDeviceNames device_names;
98 it->unique_id, false)); 98 audio_manager_->GetAudioInputDeviceNames(&device_names);
99 for (media::AudioDeviceNames::iterator it = device_names.begin();
100 it != device_names.end(); ++it) {
101 devices->push_back(StreamDeviceInfo(
102 device_type_, it->device_name, it->unique_id, false));
103 }
104 break;
105 }
106 case content::MEDIA_TAB_AUDIO_CAPTURE:
107 NOTREACHED() << "enumeration of tab audio devices";
108 break;
109 default:
110 NOTIMPLEMENTED();
111 break;
99 } 112 }
100 113
101 // Returns the device list through the listener by posting a task on 114 // Returns the device list through the listener by posting a task on
102 // IO thread since MediaStreamManager handles the callback asynchronously. 115 // IO thread since MediaStreamManager handles the callback asynchronously.
103 BrowserThread::PostTask( 116 BrowserThread::PostTask(
104 BrowserThread::IO, 117 BrowserThread::IO,
105 FROM_HERE, 118 FROM_HERE,
106 base::Bind(&AudioInputDeviceManager::DevicesEnumeratedOnIOThread, 119 base::Bind(&AudioInputDeviceManager::DevicesEnumeratedOnIOThread,
107 this, 120 this,
108 devices)); 121 devices));
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 // Erases the event handler referenced by the session_id. 191 // Erases the event handler referenced by the session_id.
179 event_handlers_.erase(session_id); 192 event_handlers_.erase(session_id);
180 } 193 }
181 194
182 void AudioInputDeviceManager::DevicesEnumeratedOnIOThread( 195 void AudioInputDeviceManager::DevicesEnumeratedOnIOThread(
183 StreamDeviceInfoArray* devices) { 196 StreamDeviceInfoArray* devices) {
184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
185 // Ensures that |devices| gets deleted on exit. 198 // Ensures that |devices| gets deleted on exit.
186 scoped_ptr<StreamDeviceInfoArray> devices_array(devices); 199 scoped_ptr<StreamDeviceInfoArray> devices_array(devices);
187 if (listener_) { 200 if (listener_) {
188 listener_->DevicesEnumerated( 201 listener_->DevicesEnumerated(device_type_, *devices_array);
189 content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
190 *devices_array);
191 } 202 }
192 } 203 }
193 204
194 void AudioInputDeviceManager::OpenedOnIOThread(int session_id) { 205 void AudioInputDeviceManager::OpenedOnIOThread(int session_id) {
195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 206 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
196 if (listener_) 207 if (listener_)
197 listener_->Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 208 listener_->Opened(device_type_, session_id);
198 session_id);
199 } 209 }
200 210
201 void AudioInputDeviceManager::ClosedOnIOThread(int session_id) { 211 void AudioInputDeviceManager::ClosedOnIOThread(int session_id) {
202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 212 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
203 if (listener_) 213 if (listener_)
204 listener_->Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 214 listener_->Closed(device_type_, session_id);
205 session_id);
206 } 215 }
207 216
208 bool AudioInputDeviceManager::IsOnDeviceThread() const { 217 bool AudioInputDeviceManager::IsOnDeviceThread() const {
209 return device_loop_->BelongsToCurrentThread(); 218 return device_loop_->BelongsToCurrentThread();
210 } 219 }
211 220
212 } // namespace media_stream 221 } // namespace media_stream
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698