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

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: Add MediaStreamDispatcher IPC glue (and unittests) for new GenerateStreamForDevice() API. 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 NOTREACHED() << "enumeration of tab audio devices";
112 break;
113 default:
114 NOTIMPLEMENTED();
115 break;
99 } 116 }
100 117
101 // Returns the device list through the listener by posting a task on 118 // Returns the device list through the listener by posting a task on
102 // IO thread since MediaStreamManager handles the callback asynchronously. 119 // IO thread since MediaStreamManager handles the callback asynchronously.
103 BrowserThread::PostTask( 120 BrowserThread::PostTask(
104 BrowserThread::IO, 121 BrowserThread::IO,
105 FROM_HERE, 122 FROM_HERE,
106 base::Bind(&AudioInputDeviceManager::DevicesEnumeratedOnIOThread, 123 base::Bind(&AudioInputDeviceManager::DevicesEnumeratedOnIOThread,
107 this, 124 this,
108 devices)); 125 devices));
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 // Erases the event handler referenced by the session_id. 195 // Erases the event handler referenced by the session_id.
179 event_handlers_.erase(session_id); 196 event_handlers_.erase(session_id);
180 } 197 }
181 198
182 void AudioInputDeviceManager::DevicesEnumeratedOnIOThread( 199 void AudioInputDeviceManager::DevicesEnumeratedOnIOThread(
183 StreamDeviceInfoArray* devices) { 200 StreamDeviceInfoArray* devices) {
184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 201 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
185 // Ensures that |devices| gets deleted on exit. 202 // Ensures that |devices| gets deleted on exit.
186 scoped_ptr<StreamDeviceInfoArray> devices_array(devices); 203 scoped_ptr<StreamDeviceInfoArray> devices_array(devices);
187 if (listener_) { 204 if (listener_) {
188 listener_->DevicesEnumerated( 205 listener_->DevicesEnumerated(device_type_, *devices_array);
189 content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
190 *devices_array);
191 } 206 }
192 } 207 }
193 208
194 void AudioInputDeviceManager::OpenedOnIOThread(int session_id) { 209 void AudioInputDeviceManager::OpenedOnIOThread(int session_id) {
195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 210 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
196 if (listener_) 211 if (listener_)
197 listener_->Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 212 listener_->Opened(device_type_, session_id);
198 session_id);
199 } 213 }
200 214
201 void AudioInputDeviceManager::ClosedOnIOThread(int session_id) { 215 void AudioInputDeviceManager::ClosedOnIOThread(int session_id) {
202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 216 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
203 if (listener_) 217 if (listener_)
204 listener_->Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 218 listener_->Closed(device_type_, session_id);
205 session_id);
206 } 219 }
207 220
208 bool AudioInputDeviceManager::IsOnDeviceThread() const { 221 bool AudioInputDeviceManager::IsOnDeviceThread() const {
209 return device_loop_->BelongsToCurrentThread(); 222 return device_loop_->BelongsToCurrentThread();
210 } 223 }
211 224
212 } // namespace media_stream 225 } // namespace media_stream
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698