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 "media/audio/audio_manager_base.h" | 11 #include "media/audio/audio_manager_base.h" |
12 | 12 |
13 using content::BrowserThread; | 13 using content::BrowserThread; |
14 | 14 |
15 namespace media_stream { | 15 namespace media_stream { |
16 | 16 |
17 const int AudioInputDeviceManager::kFakeOpenSessionId = 1; | 17 const int AudioInputDeviceManager::kFakeOpenSessionId = 1; |
18 const int AudioInputDeviceManager::kInvalidSessionId = 0; | 18 const int AudioInputDeviceManager::kInvalidSessionId = 0; |
19 const char AudioInputDeviceManager::kInvalidDeviceId[] = ""; | 19 const char AudioInputDeviceManager::kInvalidDeviceId[] = ""; |
20 | 20 |
21 // Starting id for the first capture session. | 21 // Starting id for the first capture session. |
22 const int kFirstSessionId = AudioInputDeviceManager::kFakeOpenSessionId + 1; | 22 const int kFirstSessionId = AudioInputDeviceManager::kFakeOpenSessionId + 1; |
23 | 23 |
24 AudioInputDeviceManager::AudioInputDeviceManager( | 24 AudioInputDeviceManager::AudioInputDeviceManager(AudioManager* audio_manager) |
25 media::AudioManager* audio_manager) | |
26 : listener_(NULL), | 25 : listener_(NULL), |
27 next_capture_session_id_(kFirstSessionId), | 26 next_capture_session_id_(kFirstSessionId), |
28 audio_manager_(audio_manager) { | 27 audio_manager_(audio_manager) { |
29 } | 28 } |
30 | 29 |
31 AudioInputDeviceManager::~AudioInputDeviceManager() { | 30 AudioInputDeviceManager::~AudioInputDeviceManager() { |
32 } | 31 } |
33 | 32 |
34 void AudioInputDeviceManager::Register(MediaStreamProviderListener* listener) { | 33 void AudioInputDeviceManager::Register(MediaStreamProviderListener* listener) { |
35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 int session_id, AudioInputDeviceManagerEventHandler* event_handler) { | 120 int session_id, AudioInputDeviceManagerEventHandler* event_handler) { |
122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
123 DCHECK(event_handler); | 122 DCHECK(event_handler); |
124 | 123 |
125 // Solution for not using MediaStreamManager. This is needed when Start() is | 124 // Solution for not using MediaStreamManager. This is needed when Start() is |
126 // called without using Open(), we post default device for test purpose. | 125 // called without using Open(), we post default device for test purpose. |
127 // And we do not store the info for the kFakeOpenSessionId but return | 126 // And we do not store the info for the kFakeOpenSessionId but return |
128 // the callback immediately. | 127 // the callback immediately. |
129 if (session_id == kFakeOpenSessionId) { | 128 if (session_id == kFakeOpenSessionId) { |
130 event_handler->OnDeviceStarted(session_id, | 129 event_handler->OnDeviceStarted(session_id, |
131 media::AudioManagerBase::kDefaultDeviceId); | 130 AudioManagerBase::kDefaultDeviceId); |
132 return; | 131 return; |
133 } | 132 } |
134 | 133 |
135 // Checks if the device has been opened or not. | 134 // Checks if the device has been opened or not. |
136 std::string device_id = (devices_.find(session_id) == devices_.end()) ? | 135 std::string device_id = (devices_.find(session_id) == devices_.end()) ? |
137 kInvalidDeviceId : devices_[session_id].unique_id; | 136 kInvalidDeviceId : devices_[session_id].unique_id; |
138 | 137 |
139 // Adds the event handler to the session if the session has not been started, | 138 // Adds the event handler to the session if the session has not been started, |
140 // otherwise post a |kInvalidDeviceId| to indicate that Start() fails. | 139 // otherwise post a |kInvalidDeviceId| to indicate that Start() fails. |
141 if (event_handlers_.find(session_id) == event_handlers_.end()) | 140 if (event_handlers_.find(session_id) == event_handlers_.end()) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 } | 174 } |
176 | 175 |
177 void AudioInputDeviceManager::ClosedOnIOThread(int session_id) { | 176 void AudioInputDeviceManager::ClosedOnIOThread(int session_id) { |
178 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 177 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
179 if (listener_) | 178 if (listener_) |
180 listener_->Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, | 179 listener_->Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, |
181 session_id); | 180 session_id); |
182 } | 181 } |
183 | 182 |
184 } // namespace media_stream | 183 } // namespace media_stream |
OLD | NEW |