| OLD | NEW |
| 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 "content/public/common/media_stream_request.h" |
| 12 #include "media/audio/audio_device_name.h" | 12 #include "media/audio/audio_device_name.h" |
| 13 #include "media/audio/audio_input_ipc.h" | 13 #include "media/audio/audio_input_ipc.h" |
| 14 #include "media/audio/audio_manager_base.h" | 14 #include "media/audio/audio_manager_base.h" |
| 15 | 15 |
| 16 using content::BrowserThread; | 16 namespace content { |
| 17 | |
| 18 namespace media_stream { | |
| 19 | 17 |
| 20 const int AudioInputDeviceManager::kFakeOpenSessionId = 1; | 18 const int AudioInputDeviceManager::kFakeOpenSessionId = 1; |
| 21 | 19 |
| 22 namespace { | 20 namespace { |
| 23 // Starting id for the first capture session. | 21 // Starting id for the first capture session. |
| 24 const int kFirstSessionId = AudioInputDeviceManager::kFakeOpenSessionId + 1; | 22 const int kFirstSessionId = AudioInputDeviceManager::kFakeOpenSessionId + 1; |
| 25 } | 23 } |
| 26 | 24 |
| 27 AudioInputDeviceManager::AudioInputDeviceManager( | 25 AudioInputDeviceManager::AudioInputDeviceManager( |
| 28 media::AudioManager* audio_manager) | 26 media::AudioManager* audio_manager) |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 // BrowserMainloop. | 127 // BrowserMainloop. |
| 130 media::AudioDeviceNames device_names; | 128 media::AudioDeviceNames device_names; |
| 131 audio_manager_->GetAudioInputDeviceNames(&device_names); | 129 audio_manager_->GetAudioInputDeviceNames(&device_names); |
| 132 | 130 |
| 133 StreamDeviceInfoArray* devices = new StreamDeviceInfoArray; | 131 StreamDeviceInfoArray* devices = new StreamDeviceInfoArray; |
| 134 for (media::AudioDeviceNames::iterator it = device_names.begin(); | 132 for (media::AudioDeviceNames::iterator it = device_names.begin(); |
| 135 it != device_names.end(); | 133 it != device_names.end(); |
| 136 ++it) { | 134 ++it) { |
| 137 // NOTE: Only support enumeration of the MEDIA_DEVICE_AUDIO_CAPTURE type. | 135 // NOTE: Only support enumeration of the MEDIA_DEVICE_AUDIO_CAPTURE type. |
| 138 devices->push_back(StreamDeviceInfo( | 136 devices->push_back(StreamDeviceInfo( |
| 139 content::MEDIA_DEVICE_AUDIO_CAPTURE, it->device_name, | 137 MEDIA_DEVICE_AUDIO_CAPTURE, it->device_name, |
| 140 it->unique_id, false)); | 138 it->unique_id, false)); |
| 141 } | 139 } |
| 142 | 140 |
| 143 // Return the device list through the listener by posting a task on | 141 // Return the device list through the listener by posting a task on |
| 144 // IO thread since MediaStreamManager handles the callback asynchronously. | 142 // IO thread since MediaStreamManager handles the callback asynchronously. |
| 145 BrowserThread::PostTask( | 143 BrowserThread::PostTask( |
| 146 BrowserThread::IO, | 144 BrowserThread::IO, |
| 147 FROM_HERE, | 145 FROM_HERE, |
| 148 base::Bind(&AudioInputDeviceManager::DevicesEnumeratedOnIOThread, | 146 base::Bind(&AudioInputDeviceManager::DevicesEnumeratedOnIOThread, |
| 149 this, | 147 this, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 168 this, | 166 this, |
| 169 device.stream_type, session_id)); | 167 device.stream_type, session_id)); |
| 170 } | 168 } |
| 171 | 169 |
| 172 void AudioInputDeviceManager::CloseOnDeviceThread(int session_id) { | 170 void AudioInputDeviceManager::CloseOnDeviceThread(int session_id) { |
| 173 DCHECK(IsOnDeviceThread()); | 171 DCHECK(IsOnDeviceThread()); |
| 174 | 172 |
| 175 StreamDeviceMap::iterator it = devices_.find(session_id); | 173 StreamDeviceMap::iterator it = devices_.find(session_id); |
| 176 if (it == devices_.end()) | 174 if (it == devices_.end()) |
| 177 return; | 175 return; |
| 178 const content::MediaStreamDeviceType stream_type = it->second.stream_type; | 176 const MediaStreamDeviceType stream_type = it->second.stream_type; |
| 179 devices_.erase(it); | 177 devices_.erase(it); |
| 180 | 178 |
| 181 // Post a callback through the listener on IO thread since | 179 // Post a callback through the listener on IO thread since |
| 182 // MediaStreamManager handles the callback asynchronously. | 180 // MediaStreamManager handles the callback asynchronously. |
| 183 BrowserThread::PostTask(BrowserThread::IO, | 181 BrowserThread::PostTask(BrowserThread::IO, |
| 184 FROM_HERE, | 182 FROM_HERE, |
| 185 base::Bind(&AudioInputDeviceManager::ClosedOnIOThread, | 183 base::Bind(&AudioInputDeviceManager::ClosedOnIOThread, |
| 186 this, | 184 this, |
| 187 stream_type, session_id)); | 185 stream_type, session_id)); |
| 188 } | 186 } |
| 189 | 187 |
| 190 void AudioInputDeviceManager::DevicesEnumeratedOnIOThread( | 188 void AudioInputDeviceManager::DevicesEnumeratedOnIOThread( |
| 191 StreamDeviceInfoArray* devices) { | 189 StreamDeviceInfoArray* devices) { |
| 192 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 190 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 193 // Ensure that |devices| gets deleted on exit. | 191 // Ensure that |devices| gets deleted on exit. |
| 194 scoped_ptr<StreamDeviceInfoArray> devices_array(devices); | 192 scoped_ptr<StreamDeviceInfoArray> devices_array(devices); |
| 195 if (listener_) { | 193 if (listener_) { |
| 196 // NOTE: Only support enumeration of the MEDIA_DEVICE_AUDIO_CAPTURE type. | 194 // NOTE: Only support enumeration of the MEDIA_DEVICE_AUDIO_CAPTURE type. |
| 197 listener_->DevicesEnumerated(content::MEDIA_DEVICE_AUDIO_CAPTURE, | 195 listener_->DevicesEnumerated(MEDIA_DEVICE_AUDIO_CAPTURE, *devices_array); |
| 198 *devices_array); | |
| 199 } | 196 } |
| 200 } | 197 } |
| 201 | 198 |
| 202 void AudioInputDeviceManager::OpenedOnIOThread( | 199 void AudioInputDeviceManager::OpenedOnIOThread( |
| 203 content::MediaStreamDeviceType stream_type, int session_id) { | 200 MediaStreamDeviceType stream_type, int session_id) { |
| 204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 201 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 205 if (listener_) | 202 if (listener_) |
| 206 listener_->Opened(stream_type, session_id); | 203 listener_->Opened(stream_type, session_id); |
| 207 } | 204 } |
| 208 | 205 |
| 209 void AudioInputDeviceManager::ClosedOnIOThread( | 206 void AudioInputDeviceManager::ClosedOnIOThread( |
| 210 content::MediaStreamDeviceType stream_type, int session_id) { | 207 MediaStreamDeviceType stream_type, int session_id) { |
| 211 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 208 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 212 if (listener_) | 209 if (listener_) |
| 213 listener_->Closed(stream_type, session_id); | 210 listener_->Closed(stream_type, session_id); |
| 214 } | 211 } |
| 215 | 212 |
| 216 bool AudioInputDeviceManager::IsOnDeviceThread() const { | 213 bool AudioInputDeviceManager::IsOnDeviceThread() const { |
| 217 return device_loop_->BelongsToCurrentThread(); | 214 return device_loop_->BelongsToCurrentThread(); |
| 218 } | 215 } |
| 219 | 216 |
| 220 } // namespace media_stream | 217 } // namespace content |
| OLD | NEW |