| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_renderer_host.h" | 5 #include "content/browser/renderer_host/media/audio_input_renderer_host.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/process.h" | 9 #include "base/process.h" |
| 10 #include "base/shared_memory.h" | 10 #include "base/shared_memory.h" |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 | 195 |
| 196 // Add the session entry to the map. | 196 // Add the session entry to the map. |
| 197 session_entries_[session_id] = stream_id; | 197 session_entries_[session_id] = stream_id; |
| 198 | 198 |
| 199 // Start the device with the session_id. If the device is started | 199 // Start the device with the session_id. If the device is started |
| 200 // successfully, OnDeviceStarted() callback will be triggered. | 200 // successfully, OnDeviceStarted() callback will be triggered. |
| 201 audio_input_man->Start(session_id, this); | 201 audio_input_man->Start(session_id, this); |
| 202 } | 202 } |
| 203 | 203 |
| 204 void AudioInputRendererHost::OnCreateStream( | 204 void AudioInputRendererHost::OnCreateStream( |
| 205 int stream_id, const AudioParameters& params, bool low_latency) { | 205 int stream_id, const AudioParameters& params, bool low_latency, |
| 206 const std::string& device_uid) { |
| 206 VLOG(1) << "AudioInputRendererHost::OnCreateStream(stream_id=" | 207 VLOG(1) << "AudioInputRendererHost::OnCreateStream(stream_id=" |
| 207 << stream_id << ")"; | 208 << stream_id << ")"; |
| 208 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 209 DCHECK(LookupById(stream_id) == NULL); | 210 DCHECK(LookupById(stream_id) == NULL); |
| 210 | 211 |
| 211 // Prevent the renderer process from asking for a normal-latency | 212 // Prevent the renderer process from asking for a normal-latency |
| 212 // input stream. | 213 // input stream. |
| 213 if (!low_latency) { | 214 if (!low_latency) { |
| 214 NOTREACHED() << "Current implementation only supports low-latency mode."; | 215 NOTREACHED() << "Current implementation only supports low-latency mode."; |
| 215 return; | 216 return; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 237 | 238 |
| 238 // Then try to initialize the sync writer. | 239 // Then try to initialize the sync writer. |
| 239 if (!writer->Init()) { | 240 if (!writer->Init()) { |
| 240 SendErrorMessage(stream_id); | 241 SendErrorMessage(stream_id); |
| 241 return; | 242 return; |
| 242 } | 243 } |
| 243 | 244 |
| 244 // If we have successfully created the SyncWriter then assign it to the | 245 // If we have successfully created the SyncWriter then assign it to the |
| 245 // entry and construct an AudioInputController. | 246 // entry and construct an AudioInputController. |
| 246 entry->writer.reset(writer.release()); | 247 entry->writer.reset(writer.release()); |
| 247 entry->controller = | 248 entry->controller = media::AudioInputController::CreateLowLatency( |
| 248 media::AudioInputController::CreateLowLatency(this, | 249 this, |
| 249 audio_params, | 250 audio_params, |
| 250 entry->writer.get()); | 251 device_uid, |
| 252 entry->writer.get()); |
| 251 | 253 |
| 252 if (!entry->controller) { | 254 if (!entry->controller) { |
| 253 SendErrorMessage(stream_id); | 255 SendErrorMessage(stream_id); |
| 254 return; | 256 return; |
| 255 } | 257 } |
| 256 | 258 |
| 257 // If we have created the controller successfully create a entry and add it | 259 // If we have created the controller successfully create a entry and add it |
| 258 // to the map. | 260 // to the map. |
| 259 entry->stream_id = stream_id; | 261 entry->stream_id = stream_id; |
| 260 | 262 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 | 323 |
| 322 void AudioInputRendererHost::DeleteEntries() { | 324 void AudioInputRendererHost::DeleteEntries() { |
| 323 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 325 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 324 | 326 |
| 325 for (AudioEntryMap::iterator i = audio_entries_.begin(); | 327 for (AudioEntryMap::iterator i = audio_entries_.begin(); |
| 326 i != audio_entries_.end(); ++i) { | 328 i != audio_entries_.end(); ++i) { |
| 327 CloseAndDeleteStream(i->second); | 329 CloseAndDeleteStream(i->second); |
| 328 } | 330 } |
| 329 } | 331 } |
| 330 | 332 |
| 331 void AudioInputRendererHost::OnDeviceStarted(int session_id, int index) { | 333 void AudioInputRendererHost::OnDeviceStarted( |
| 334 int session_id, const std::string& device_uid) { |
| 332 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 335 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 333 SessionEntryMap::iterator it = session_entries_.find(session_id); | 336 SessionEntryMap::iterator it = session_entries_.find(session_id); |
| 334 if (it == session_entries_.end()) { | 337 if (it == session_entries_.end()) { |
| 335 DLOG(WARNING) << "AudioInputRendererHost::OnDeviceStarted()" | 338 DLOG(WARNING) << "AudioInputRendererHost::OnDeviceStarted()" |
| 336 " session does not exist."; | 339 " session does not exist."; |
| 337 return; | 340 return; |
| 338 } | 341 } |
| 339 | 342 |
| 340 // Notify the renderer that the device has been started. | 343 // Notify the renderer that the device has been started. |
| 341 Send(new AudioInputMsg_NotifyDeviceStarted(it->second, index)); | 344 Send(new AudioInputMsg_NotifyDeviceStarted(it->second, device_uid)); |
| 342 } | 345 } |
| 343 | 346 |
| 344 void AudioInputRendererHost::OnDeviceStopped(int session_id) { | 347 void AudioInputRendererHost::OnDeviceStopped(int session_id) { |
| 345 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 348 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 346 | 349 |
| 347 SessionEntryMap::iterator it = session_entries_.find(session_id); | 350 SessionEntryMap::iterator it = session_entries_.find(session_id); |
| 348 // Return if the stream has been closed. | 351 // Return if the stream has been closed. |
| 349 if (it == session_entries_.end()) | 352 if (it == session_entries_.end()) |
| 350 return; | 353 return; |
| 351 | 354 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 443 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 441 | 444 |
| 442 for (SessionEntryMap::iterator it = session_entries_.begin(); | 445 for (SessionEntryMap::iterator it = session_entries_.begin(); |
| 443 it != session_entries_.end(); ++it) { | 446 it != session_entries_.end(); ++it) { |
| 444 if (stream_id == it->second) { | 447 if (stream_id == it->second) { |
| 445 return it->first; | 448 return it->first; |
| 446 } | 449 } |
| 447 } | 450 } |
| 448 return 0; | 451 return 0; |
| 449 } | 452 } |
| OLD | NEW |