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

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: Renamed MEDIA_USER_*_CAPTURE to MEDIA_*_DEVICE_CAPTURE, as suggested by wjia@. 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
19 namespace {
20 const char kStubTabAudioDeviceId[] = "<<tab audio id here>>";
21 }
22
18 const int AudioInputDeviceManager::kFakeOpenSessionId = 1; 23 const int AudioInputDeviceManager::kFakeOpenSessionId = 1;
19 24
20 // Starting id for the first capture session. 25 // Starting id for the first capture session.
21 const int kFirstSessionId = AudioInputDeviceManager::kFakeOpenSessionId + 1; 26 const int kFirstSessionId = AudioInputDeviceManager::kFakeOpenSessionId + 1;
22 27
23 AudioInputDeviceManager::AudioInputDeviceManager( 28 AudioInputDeviceManager::AudioInputDeviceManager(
24 media::AudioManager* audio_manager) 29 media::AudioManager* audio_manager,
30 media_stream::MediaStreamType device_type)
25 : listener_(NULL), 31 : listener_(NULL),
26 next_capture_session_id_(kFirstSessionId), 32 next_capture_session_id_(kFirstSessionId),
27 audio_manager_(audio_manager) { 33 audio_manager_(audio_manager),
34 device_type_(device_type) {
35 DCHECK(content::IsAudioMediaType(device_type_));
28 } 36 }
29 37
30 AudioInputDeviceManager::~AudioInputDeviceManager() { 38 AudioInputDeviceManager::~AudioInputDeviceManager() {
31 } 39 }
32 40
33 void AudioInputDeviceManager::Register( 41 void AudioInputDeviceManager::Register(
34 MediaStreamProviderListener* listener, 42 MediaStreamProviderListener* listener,
35 base::MessageLoopProxy* device_thread_loop) { 43 base::MessageLoopProxy* device_thread_loop) {
36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
37 DCHECK(!listener_); 45 DCHECK(!listener_);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 } 85 }
78 86
79 device_loop_->PostTask( 87 device_loop_->PostTask(
80 FROM_HERE, 88 FROM_HERE,
81 base::Bind(&AudioInputDeviceManager::CloseOnDeviceThread, 89 base::Bind(&AudioInputDeviceManager::CloseOnDeviceThread,
82 this, session_id)); 90 this, session_id));
83 } 91 }
84 92
85 void AudioInputDeviceManager::EnumerateOnDeviceThread() { 93 void AudioInputDeviceManager::EnumerateOnDeviceThread() {
86 DCHECK(IsOnDeviceThread()); 94 DCHECK(IsOnDeviceThread());
87 // AudioManager is guaranteed to outlive MediaStreamManager in
88 // BrowserMainloop.
89 media::AudioDeviceNames device_names;
90 audio_manager_->GetAudioInputDeviceNames(&device_names);
91 95
92 StreamDeviceInfoArray* devices = new StreamDeviceInfoArray; 96 StreamDeviceInfoArray* devices = new StreamDeviceInfoArray;
93 for (media::AudioDeviceNames::iterator it = device_names.begin(); 97 switch (device_type_) {
94 it != device_names.end(); 98 case content::MEDIA_AUDIO_DEVICE_CAPTURE: {
95 ++it) { 99 // AudioManager is guaranteed to outlive MediaStreamManager in
96 devices->push_back(StreamDeviceInfo( 100 // BrowserMainloop.
97 content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, it->device_name, 101 media::AudioDeviceNames device_names;
98 it->unique_id, false)); 102 audio_manager_->GetAudioInputDeviceNames(&device_names);
103 for (media::AudioDeviceNames::iterator it = device_names.begin();
104 it != device_names.end(); ++it) {
105 devices->push_back(StreamDeviceInfo(
106 device_type_, it->device_name, it->unique_id, false));
107 }
108 break;
109 }
110 case content::MEDIA_TAB_AUDIO_CAPTURE:
111 // TODO(miu): Replace this stub with the actual implementation.
112 devices->push_back(StreamDeviceInfo(
113 device_type_, "Stub Tab Audio Capture", kStubTabAudioDeviceId,
114 false));
115 break;
116 default:
117 NOTIMPLEMENTED();
118 break;
99 } 119 }
100 120
101 // Returns the device list through the listener by posting a task on 121 // Returns the device list through the listener by posting a task on
102 // IO thread since MediaStreamManager handles the callback asynchronously. 122 // IO thread since MediaStreamManager handles the callback asynchronously.
103 BrowserThread::PostTask( 123 BrowserThread::PostTask(
104 BrowserThread::IO, 124 BrowserThread::IO,
105 FROM_HERE, 125 FROM_HERE,
106 base::Bind(&AudioInputDeviceManager::DevicesEnumeratedOnIOThread, 126 base::Bind(&AudioInputDeviceManager::DevicesEnumeratedOnIOThread,
107 this, 127 this,
108 devices)); 128 devices));
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 // Erases the event handler referenced by the session_id. 198 // Erases the event handler referenced by the session_id.
179 event_handlers_.erase(session_id); 199 event_handlers_.erase(session_id);
180 } 200 }
181 201
182 void AudioInputDeviceManager::DevicesEnumeratedOnIOThread( 202 void AudioInputDeviceManager::DevicesEnumeratedOnIOThread(
183 StreamDeviceInfoArray* devices) { 203 StreamDeviceInfoArray* devices) {
184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
185 // Ensures that |devices| gets deleted on exit. 205 // Ensures that |devices| gets deleted on exit.
186 scoped_ptr<StreamDeviceInfoArray> devices_array(devices); 206 scoped_ptr<StreamDeviceInfoArray> devices_array(devices);
187 if (listener_) { 207 if (listener_) {
188 listener_->DevicesEnumerated( 208 listener_->DevicesEnumerated(device_type_, *devices_array);
189 content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
190 *devices_array);
191 } 209 }
192 } 210 }
193 211
194 void AudioInputDeviceManager::OpenedOnIOThread(int session_id) { 212 void AudioInputDeviceManager::OpenedOnIOThread(int session_id) {
195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 213 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
196 if (listener_) 214 if (listener_)
197 listener_->Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 215 listener_->Opened(device_type_, session_id);
198 session_id);
199 } 216 }
200 217
201 void AudioInputDeviceManager::ClosedOnIOThread(int session_id) { 218 void AudioInputDeviceManager::ClosedOnIOThread(int session_id) {
202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 219 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
203 if (listener_) 220 if (listener_)
204 listener_->Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 221 listener_->Closed(device_type_, session_id);
205 session_id);
206 } 222 }
207 223
208 bool AudioInputDeviceManager::IsOnDeviceThread() const { 224 bool AudioInputDeviceManager::IsOnDeviceThread() const {
209 return device_loop_->BelongsToCurrentThread(); 225 return device_loop_->BelongsToCurrentThread();
210 } 226 }
211 227
212 } // namespace media_stream 228 } // namespace media_stream
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698