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

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: Simplify: Use only one AudioInputDeviceManager and VideoCaptureManager, like before. 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"
12 #include "media/audio/audio_device_name.h"
11 #include "media/audio/audio_input_ipc.h" 13 #include "media/audio/audio_input_ipc.h"
12 #include "media/audio/audio_manager_base.h" 14 #include "media/audio/audio_manager_base.h"
13 15
14 using content::BrowserThread; 16 using content::BrowserThread;
15 17
16 namespace media_stream { 18 namespace media_stream {
17 19
18 const int AudioInputDeviceManager::kFakeOpenSessionId = 1; 20 const int AudioInputDeviceManager::kFakeOpenSessionId = 1;
19 21
20 // Starting id for the first capture session. 22 // Starting id for the first capture session.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 DCHECK(IsOnDeviceThread()); 88 DCHECK(IsOnDeviceThread());
87 // AudioManager is guaranteed to outlive MediaStreamManager in 89 // AudioManager is guaranteed to outlive MediaStreamManager in
88 // BrowserMainloop. 90 // BrowserMainloop.
89 media::AudioDeviceNames device_names; 91 media::AudioDeviceNames device_names;
90 audio_manager_->GetAudioInputDeviceNames(&device_names); 92 audio_manager_->GetAudioInputDeviceNames(&device_names);
91 93
92 StreamDeviceInfoArray* devices = new StreamDeviceInfoArray; 94 StreamDeviceInfoArray* devices = new StreamDeviceInfoArray;
93 for (media::AudioDeviceNames::iterator it = device_names.begin(); 95 for (media::AudioDeviceNames::iterator it = device_names.begin();
94 it != device_names.end(); 96 it != device_names.end();
95 ++it) { 97 ++it) {
96 devices->push_back(StreamDeviceInfo( 98 // NOTE: Only support enumeration of the MEDIA_DEVICE_AUDIO_CAPTURE type.
97 content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, it->device_name, 99 devices->push_back(StreamDeviceInfo(
98 it->unique_id, false)); 100 content::MEDIA_DEVICE_AUDIO_CAPTURE, it->device_name,
101 it->unique_id, false));
99 } 102 }
100 103
101 // Returns the device list through the listener by posting a task on 104 // Returns the device list through the listener by posting a task on
102 // IO thread since MediaStreamManager handles the callback asynchronously. 105 // IO thread since MediaStreamManager handles the callback asynchronously.
103 BrowserThread::PostTask( 106 BrowserThread::PostTask(
104 BrowserThread::IO, 107 BrowserThread::IO,
105 FROM_HERE, 108 FROM_HERE,
106 base::Bind(&AudioInputDeviceManager::DevicesEnumeratedOnIOThread, 109 base::Bind(&AudioInputDeviceManager::DevicesEnumeratedOnIOThread,
107 this, 110 this,
108 devices)); 111 devices));
109 } 112 }
110 113
111 void AudioInputDeviceManager::OpenOnDeviceThread( 114 void AudioInputDeviceManager::OpenOnDeviceThread(
112 int session_id, const StreamDeviceInfo& device) { 115 int session_id, const StreamDeviceInfo& device) {
113 DCHECK(IsOnDeviceThread()); 116 DCHECK(IsOnDeviceThread());
114 DCHECK(devices_.find(session_id) == devices_.end()); 117 DCHECK(devices_.find(session_id) == devices_.end());
115 118
116 // Adds the session_id and device to the list. 119 // Adds the session_id and device to the map.
117 media::AudioDeviceName target_device(device.name, device.device_id); 120 devices_[session_id] = device;
118 devices_[session_id] = target_device;
119 121
120 // Returns the |session_id| through the listener by posting a task on 122 // Returns the |session_id| through the listener by posting a task on
121 // IO thread since MediaStreamManager handles the callback asynchronously. 123 // IO thread since MediaStreamManager handles the callback asynchronously.
122 BrowserThread::PostTask(BrowserThread::IO, 124 BrowserThread::PostTask(BrowserThread::IO,
123 FROM_HERE, 125 FROM_HERE,
124 base::Bind(&AudioInputDeviceManager::OpenedOnIOThread, 126 base::Bind(&AudioInputDeviceManager::OpenedOnIOThread,
125 this, 127 this,
126 session_id)); 128 device.stream_type, session_id));
127 } 129 }
128 130
129 void AudioInputDeviceManager::CloseOnDeviceThread(int session_id) { 131 void AudioInputDeviceManager::CloseOnDeviceThread(int session_id) {
130 DCHECK(IsOnDeviceThread()); 132 DCHECK(IsOnDeviceThread());
131 133
132 if (devices_.find(session_id) != devices_.end()) 134 StreamDeviceMap::iterator it = devices_.find(session_id);
133 devices_.erase(session_id); 135 if (it == devices_.end()) {
tommi (sloooow) - chröme 2012/09/10 09:17:25 no {} for cases like this. See how this is done e
miu 2012/09/10 21:24:38 Done.
136 return;
137 }
138 const content::MediaStreamDeviceType stream_type = it->second.stream_type;
139 devices_.erase(it);
134 140
135 // Posts a callback through the listener on IO thread since 141 // Posts a callback through the listener on IO thread since
136 // MediaStreamManager handles the callback asynchronously. 142 // MediaStreamManager handles the callback asynchronously.
137 BrowserThread::PostTask(BrowserThread::IO, 143 BrowserThread::PostTask(BrowserThread::IO,
138 FROM_HERE, 144 FROM_HERE,
139 base::Bind(&AudioInputDeviceManager::ClosedOnIOThread, 145 base::Bind(&AudioInputDeviceManager::ClosedOnIOThread,
140 this, 146 this,
141 session_id)); 147 stream_type, session_id));
142 } 148 }
143 149
144 void AudioInputDeviceManager::Start( 150 void AudioInputDeviceManager::Start(
145 int session_id, AudioInputDeviceManagerEventHandler* event_handler) { 151 int session_id, AudioInputDeviceManagerEventHandler* event_handler) {
146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 152 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
147 DCHECK(event_handler); 153 DCHECK(event_handler);
148 154
149 // Solution for not using MediaStreamManager. This is needed when Start() is 155 // Solution for not using MediaStreamManager. This is needed when Start() is
150 // called without using Open(), we post default device for test purpose. 156 // called without using Open(), we post default device for test purpose.
151 // And we do not store the info for the kFakeOpenSessionId but return 157 // And we do not store the info for the kFakeOpenSessionId but return
152 // the callback immediately. 158 // the callback immediately.
153 if (session_id == kFakeOpenSessionId) { 159 if (session_id == kFakeOpenSessionId) {
154 event_handler->OnDeviceStarted(session_id, 160 event_handler->OnDeviceStarted(session_id,
155 media::AudioManagerBase::kDefaultDeviceId); 161 media::AudioManagerBase::kDefaultDeviceId);
156 return; 162 return;
157 } 163 }
158 164
159 // Checks if the device has been opened or not. 165 // Checks if the device has been opened or not.
160 std::string device_id; 166 std::string device_id;
161 167
162 // Adds the event handler to the session if the session has not been started, 168 // Adds the event handler to the session if the session has not been started,
163 // otherwise post an empty |device_id| to indicate that Start() fails. 169 // otherwise post an empty |device_id| to indicate that Start() fails.
164 if (event_handlers_.find(session_id) == event_handlers_.end()) { 170 if (event_handlers_.find(session_id) == event_handlers_.end()) {
165 event_handlers_.insert(std::make_pair(session_id, event_handler)); 171 event_handlers_.insert(std::make_pair(session_id, event_handler));
166 if (devices_.find(session_id) != devices_.end()) 172 if (devices_.find(session_id) != devices_.end())
167 device_id = devices_[session_id].unique_id; 173 device_id = devices_[session_id].device_id;
168 } 174 }
169 175
170 // Posts a callback through the AudioInputRendererHost to notify the renderer 176 // Posts a callback through the AudioInputRendererHost to notify the renderer
171 // that the device has started. 177 // that the device has started.
172 event_handler->OnDeviceStarted(session_id, device_id); 178 event_handler->OnDeviceStarted(session_id, device_id);
173 } 179 }
174 180
175 void AudioInputDeviceManager::Stop(int session_id) { 181 void AudioInputDeviceManager::Stop(int session_id) {
176 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 182 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
177 183
178 // Erases the event handler referenced by the session_id. 184 // Erases the event handler referenced by the session_id.
179 event_handlers_.erase(session_id); 185 event_handlers_.erase(session_id);
180 } 186 }
181 187
182 void AudioInputDeviceManager::DevicesEnumeratedOnIOThread( 188 void AudioInputDeviceManager::DevicesEnumeratedOnIOThread(
183 StreamDeviceInfoArray* devices) { 189 StreamDeviceInfoArray* devices) {
184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 190 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
185 // Ensures that |devices| gets deleted on exit. 191 // Ensures that |devices| gets deleted on exit.
186 scoped_ptr<StreamDeviceInfoArray> devices_array(devices); 192 scoped_ptr<StreamDeviceInfoArray> devices_array(devices);
187 if (listener_) { 193 if (listener_) {
188 listener_->DevicesEnumerated( 194 // NOTE: Only support enumeration of the MEDIA_DEVICE_AUDIO_CAPTURE type.
189 content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 195 listener_->DevicesEnumerated(content::MEDIA_DEVICE_AUDIO_CAPTURE,
190 *devices_array); 196 *devices_array);
191 } 197 }
192 } 198 }
193 199
194 void AudioInputDeviceManager::OpenedOnIOThread(int session_id) { 200 void AudioInputDeviceManager::OpenedOnIOThread(
201 content::MediaStreamDeviceType stream_type, int session_id) {
195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
196 if (listener_) 203 if (listener_)
197 listener_->Opened(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 204 listener_->Opened(stream_type, session_id);
198 session_id);
199 } 205 }
200 206
201 void AudioInputDeviceManager::ClosedOnIOThread(int session_id) { 207 void AudioInputDeviceManager::ClosedOnIOThread(
208 content::MediaStreamDeviceType stream_type, int session_id) {
202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
203 if (listener_) 210 if (listener_)
204 listener_->Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 211 listener_->Closed(stream_type, session_id);
205 session_id);
206 } 212 }
207 213
208 bool AudioInputDeviceManager::IsOnDeviceThread() const { 214 bool AudioInputDeviceManager::IsOnDeviceThread() const {
209 return device_loop_->BelongsToCurrentThread(); 215 return device_loop_->BelongsToCurrentThread();
210 } 216 }
211 217
212 } // namespace media_stream 218 } // namespace media_stream
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698