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

Side by Side Diff: content/browser/renderer_host/media/audio_input_device_manager.cc

Issue 10790121: First step towards moving AudioDevice from content/ to media/audio. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update comments after closing ppapi bug Created 8 years, 5 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 "media/audio/audio_input_ipc.h"
11 #include "media/audio/audio_manager_base.h" 12 #include "media/audio/audio_manager_base.h"
12 13
13 using content::BrowserThread; 14 using content::BrowserThread;
14 15
15 namespace media_stream { 16 namespace media_stream {
16 17
17 const int AudioInputDeviceManager::kFakeOpenSessionId = 1; 18 const int AudioInputDeviceManager::kFakeOpenSessionId = 1;
18 const int AudioInputDeviceManager::kInvalidSessionId = 0;
19 const char AudioInputDeviceManager::kInvalidDeviceId[] = "";
20 19
21 // Starting id for the first capture session. 20 // Starting id for the first capture session.
22 const int kFirstSessionId = AudioInputDeviceManager::kFakeOpenSessionId + 1; 21 const int kFirstSessionId = AudioInputDeviceManager::kFakeOpenSessionId + 1;
23 22
24 AudioInputDeviceManager::AudioInputDeviceManager( 23 AudioInputDeviceManager::AudioInputDeviceManager(
25 media::AudioManager* audio_manager) 24 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 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 // called without using Open(), we post default device for test purpose. 150 // called without using Open(), we post default device for test purpose.
152 // And we do not store the info for the kFakeOpenSessionId but return 151 // And we do not store the info for the kFakeOpenSessionId but return
153 // the callback immediately. 152 // the callback immediately.
154 if (session_id == kFakeOpenSessionId) { 153 if (session_id == kFakeOpenSessionId) {
155 event_handler->OnDeviceStarted(session_id, 154 event_handler->OnDeviceStarted(session_id,
156 media::AudioManagerBase::kDefaultDeviceId); 155 media::AudioManagerBase::kDefaultDeviceId);
157 return; 156 return;
158 } 157 }
159 158
160 // Checks if the device has been opened or not. 159 // Checks if the device has been opened or not.
161 std::string device_id = (devices_.find(session_id) == devices_.end()) ? 160 std::string device_id;
162 kInvalidDeviceId : devices_[session_id].unique_id;
163 161
164 // Adds the event handler to the session if the session has not been started, 162 // Adds the event handler to the session if the session has not been started,
165 // otherwise post a |kInvalidDeviceId| to indicate that Start() fails. 163 // otherwise post an empty |device_id| to indicate that Start() fails.
166 if (event_handlers_.find(session_id) == event_handlers_.end()) 164 if (event_handlers_.find(session_id) == event_handlers_.end()) {
167 event_handlers_.insert(std::make_pair(session_id, event_handler)); 165 event_handlers_.insert(std::make_pair(session_id, event_handler));
168 else 166 if (devices_.find(session_id) != devices_.end())
169 device_id = kInvalidDeviceId; 167 device_id = devices_[session_id].unique_id;
168 }
170 169
171 // Posts a callback through the AudioInputRendererHost to notify the renderer 170 // Posts a callback through the AudioInputRendererHost to notify the renderer
172 // that the device has started. 171 // that the device has started.
173 event_handler->OnDeviceStarted(session_id, device_id); 172 event_handler->OnDeviceStarted(session_id, device_id);
174 } 173 }
175 174
176 void AudioInputDeviceManager::Stop(int session_id) { 175 void AudioInputDeviceManager::Stop(int session_id) {
177 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 176 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
178 177
179 // Erases the event handler referenced by the session_id. 178 // Erases the event handler referenced by the session_id.
(...skipping 24 matching lines...) Expand all
204 if (listener_) 203 if (listener_)
205 listener_->Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 204 listener_->Closed(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
206 session_id); 205 session_id);
207 } 206 }
208 207
209 bool AudioInputDeviceManager::IsOnDeviceThread() const { 208 bool AudioInputDeviceManager::IsOnDeviceThread() const {
210 return device_loop_->BelongsToCurrentThread(); 209 return device_loop_->BelongsToCurrentThread();
211 } 210 }
212 211
213 } // namespace media_stream 212 } // namespace media_stream
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698