Chromium Code Reviews| 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/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
| 10 #include "content/public/common/media_stream_request.h" | 10 #include "content/public/common/media_stream_request.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 49 StreamDeviceList::iterator device = GetDevice(session_id); | 49 StreamDeviceList::iterator device = GetDevice(session_id); |
| 50 if (device == devices_.end()) | 50 if (device == devices_.end()) |
| 51 return NULL; | 51 return NULL; |
| 52 | 52 |
| 53 return &(*device); | 53 return &(*device); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void AudioInputDeviceManager::Register( | 56 void AudioInputDeviceManager::Register( |
| 57 MediaStreamProviderListener* listener, | 57 MediaStreamProviderListener* listener, |
| 58 base::MessageLoopProxy* device_thread_loop) { | 58 const scoped_refptr<base::SingleThreadTaskRunner>& device_task_runner) { |
| 59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 60 DCHECK(!listener_); | 60 DCHECK(!listener_); |
| 61 DCHECK(!device_loop_.get()); | 61 DCHECK(!device_task_runner_); |
| 62 listener_ = listener; | 62 listener_ = listener; |
| 63 device_loop_ = device_thread_loop; | 63 device_task_runner_ = device_task_runner; |
| 64 } | 64 } |
| 65 | 65 |
| 66 void AudioInputDeviceManager::Unregister() { | 66 void AudioInputDeviceManager::Unregister() { |
| 67 DCHECK(listener_); | 67 DCHECK(listener_); |
| 68 listener_ = NULL; | 68 listener_ = NULL; |
| 69 } | 69 } |
| 70 | 70 |
| 71 void AudioInputDeviceManager::EnumerateDevices(MediaStreamType stream_type) { | 71 void AudioInputDeviceManager::EnumerateDevices(MediaStreamType stream_type) { |
| 72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 73 DCHECK(listener_); | 73 DCHECK(listener_); |
| 74 | 74 |
| 75 device_loop_->PostTask( | 75 device_task_runner_->PostTask( |
| 76 FROM_HERE, | 76 FROM_HERE, |
| 77 base::Bind(&AudioInputDeviceManager::EnumerateOnDeviceThread, | 77 base::Bind(&AudioInputDeviceManager::EnumerateOnDeviceThread, |
| 78 this, stream_type)); | 78 this, stream_type)); |
| 79 } | 79 } |
| 80 | 80 |
| 81 int AudioInputDeviceManager::Open(const StreamDeviceInfo& device) { | 81 int AudioInputDeviceManager::Open(const StreamDeviceInfo& device) { |
| 82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 83 // Generate a new id for this device. | 83 // Generate a new id for this device. |
| 84 int session_id = next_capture_session_id_++; | 84 int session_id = next_capture_session_id_++; |
| 85 device_loop_->PostTask( | 85 device_task_runner_->PostTask( |
| 86 FROM_HERE, | 86 FROM_HERE, |
| 87 base::Bind(&AudioInputDeviceManager::OpenOnDeviceThread, | 87 base::Bind(&AudioInputDeviceManager::OpenOnDeviceThread, |
| 88 this, session_id, device)); | 88 this, session_id, device)); |
| 89 | 89 |
| 90 return session_id; | 90 return session_id; |
| 91 } | 91 } |
| 92 | 92 |
| 93 void AudioInputDeviceManager::Close(int session_id) { | 93 void AudioInputDeviceManager::Close(int session_id) { |
| 94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 95 DCHECK(listener_); | 95 DCHECK(listener_); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 listener_->Opened(info.device.type, session_id); | 233 listener_->Opened(info.device.type, session_id); |
| 234 } | 234 } |
| 235 | 235 |
| 236 void AudioInputDeviceManager::ClosedOnIOThread(MediaStreamType stream_type, | 236 void AudioInputDeviceManager::ClosedOnIOThread(MediaStreamType stream_type, |
| 237 int session_id) { | 237 int session_id) { |
| 238 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 238 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 239 if (listener_) | 239 if (listener_) |
| 240 listener_->Closed(stream_type, session_id); | 240 listener_->Closed(stream_type, session_id); |
| 241 } | 241 } |
| 242 | 242 |
| 243 bool AudioInputDeviceManager::IsOnDeviceThread() const { | 243 bool AudioInputDeviceManager::IsOnDeviceThread() const { |
|
henrika (OOO until Aug 14)
2014/02/05 08:42:03
Are we still OK with names like IsOnDeviceThread()
DaleCurtis
2014/02/05 21:47:11
I think it's fine and possibly useful in the conte
| |
| 244 return device_loop_->BelongsToCurrentThread(); | 244 return device_task_runner_->BelongsToCurrentThread(); |
| 245 } | 245 } |
| 246 | 246 |
| 247 AudioInputDeviceManager::StreamDeviceList::iterator | 247 AudioInputDeviceManager::StreamDeviceList::iterator |
| 248 AudioInputDeviceManager::GetDevice(int session_id) { | 248 AudioInputDeviceManager::GetDevice(int session_id) { |
| 249 for (StreamDeviceList::iterator i(devices_.begin()); i != devices_.end(); | 249 for (StreamDeviceList::iterator i(devices_.begin()); i != devices_.end(); |
| 250 ++i) { | 250 ++i) { |
| 251 if (i->session_id == session_id) | 251 if (i->session_id == session_id) |
| 252 return i; | 252 return i; |
| 253 } | 253 } |
| 254 | 254 |
| 255 return devices_.end(); | 255 return devices_.end(); |
| 256 } | 256 } |
| 257 | 257 |
| 258 } // namespace content | 258 } // namespace content |
| OLD | NEW |