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 "media/audio/audio_output_device.h" | 5 #include "media/audio/audio_output_device.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <cmath> | 10 #include <cmath> |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 286 callback_->OnRenderError(); | 286 callback_->OnRenderError(); |
| 287 break; | 287 break; |
| 288 default: | 288 default: |
| 289 NOTREACHED(); | 289 NOTREACHED(); |
| 290 break; | 290 break; |
| 291 } | 291 } |
| 292 } | 292 } |
| 293 | 293 |
| 294 void AudioOutputDevice::OnDeviceAuthorized( | 294 void AudioOutputDevice::OnDeviceAuthorized( |
| 295 OutputDeviceStatus device_status, | 295 OutputDeviceStatus device_status, |
| 296 const media::AudioParameters& output_params) { | 296 const media::AudioParameters& output_params, |
| 297 const std::string& matched_device_id) { | |
| 297 DCHECK(task_runner()->BelongsToCurrentThread()); | 298 DCHECK(task_runner()->BelongsToCurrentThread()); |
| 298 DCHECK_EQ(state_, AUTHORIZING); | 299 DCHECK_EQ(state_, AUTHORIZING); |
| 299 | 300 |
| 300 // It may happen that a second authorization is received as a result to a | 301 // It may happen that a second authorization is received as a result to a |
| 301 // call to Start() after Stop(). If the status for the second authorization | 302 // call to Start() after Stop(). If the status for the second authorization |
| 302 // differs from the first, it will not be reflected in |device_status_| | 303 // differs from the first, it will not be reflected in |device_status_| |
| 303 // to avoid a race. | 304 // to avoid a race. |
| 304 // This scenario is unlikely. If it occurs, the new value will be | 305 // This scenario is unlikely. If it occurs, the new value will be |
| 305 // different from OUTPUT_DEVICE_STATUS_OK, so the AudioOutputDevice | 306 // different from OUTPUT_DEVICE_STATUS_OK, so the AudioOutputDevice |
| 306 // will enter the IPC_CLOSED state anyway, which is the safe thing to do. | 307 // will enter the IPC_CLOSED state anyway, which is the safe thing to do. |
| 307 // This is preferable to holding a lock. | 308 // This is preferable to holding a lock. |
| 308 if (!did_receive_auth_.IsSignaled()) | 309 if (!did_receive_auth_.IsSignaled()) |
| 309 device_status_ = device_status; | 310 device_status_ = device_status; |
| 310 | 311 |
| 311 if (device_status == OUTPUT_DEVICE_STATUS_OK) { | 312 if (device_status == OUTPUT_DEVICE_STATUS_OK) { |
| 312 state_ = AUTHORIZED; | 313 state_ = AUTHORIZED; |
| 313 if (!did_receive_auth_.IsSignaled()) { | 314 if (!did_receive_auth_.IsSignaled()) { |
| 314 output_params_ = output_params; | 315 output_params_ = output_params; |
| 315 did_receive_auth_.Signal(); | 316 did_receive_auth_.Signal(); |
| 316 } | 317 } |
| 317 if (start_on_authorized_) | 318 if (start_on_authorized_) |
| 318 CreateStreamOnIOThread(audio_parameters_); | 319 CreateStreamOnIOThread(audio_parameters_); |
| 320 | |
| 321 // Matching can take place only if |session_id_| is specified and | |
| 322 // |device_id_| is not, however, it's possible not to have a matched device | |
| 323 // even in this case. It means |session_id_| failed and the default device | |
|
Henrik Grunell
2016/03/08 21:09:57
What does "|session_id_| failed" mean?
o1ka
2016/04/05 15:13:38
Done.
| |
| 324 // is used. | |
| 325 DCHECK((session_id_ && device_id_.empty()) ? true | |
| 326 : matched_device_id_.empty()); | |
| 327 matched_device_id_ = matched_device_id; | |
|
o1ka
2016/04/05 15:13:38
This races with a getter: |matched_device_id_| sho
| |
| 319 } else { | 328 } else { |
| 320 // Closing IPC forces a Signal(), so no clients are locked waiting | 329 // Closing IPC forces a Signal(), so no clients are locked waiting |
| 321 // indefinitely after this method returns. | 330 // indefinitely after this method returns. |
| 322 ipc_->CloseStream(); | 331 ipc_->CloseStream(); |
| 323 OnIPCClosed(); | 332 OnIPCClosed(); |
| 324 if (callback_) | 333 if (callback_) |
| 325 callback_->OnRenderError(); | 334 callback_->OnRenderError(); |
| 326 } | 335 } |
| 327 } | 336 } |
| 328 | 337 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 380 | 389 |
| 381 // Signal to unblock any blocked threads waiting for parameters | 390 // Signal to unblock any blocked threads waiting for parameters |
| 382 did_receive_auth_.Signal(); | 391 did_receive_auth_.Signal(); |
| 383 } | 392 } |
| 384 | 393 |
| 385 void AudioOutputDevice::WillDestroyCurrentMessageLoop() { | 394 void AudioOutputDevice::WillDestroyCurrentMessageLoop() { |
| 386 LOG(ERROR) << "IO loop going away before the audio device has been stopped"; | 395 LOG(ERROR) << "IO loop going away before the audio device has been stopped"; |
| 387 ShutDownOnIOThread(); | 396 ShutDownOnIOThread(); |
| 388 } | 397 } |
| 389 | 398 |
| 399 std::string AudioOutputDevice::GetDeviceId() { | |
| 400 CHECK(!task_runner()->BelongsToCurrentThread()); | |
| 401 did_receive_auth_.Wait(); | |
| 402 return (device_id_.empty() && session_id_) ? matched_device_id_ : device_id_; | |
| 403 } | |
| 404 | |
| 390 // AudioOutputDevice::AudioThreadCallback | 405 // AudioOutputDevice::AudioThreadCallback |
| 391 | 406 |
| 392 AudioOutputDevice::AudioThreadCallback::AudioThreadCallback( | 407 AudioOutputDevice::AudioThreadCallback::AudioThreadCallback( |
| 393 const AudioParameters& audio_parameters, | 408 const AudioParameters& audio_parameters, |
| 394 base::SharedMemoryHandle memory, | 409 base::SharedMemoryHandle memory, |
| 395 int memory_length, | 410 int memory_length, |
| 396 AudioRendererSink::RenderCallback* render_callback) | 411 AudioRendererSink::RenderCallback* render_callback) |
| 397 : AudioDeviceThread::Callback(audio_parameters, memory, memory_length, 1), | 412 : AudioDeviceThread::Callback(audio_parameters, memory, memory_length, 1), |
| 398 render_callback_(render_callback), | 413 render_callback_(render_callback), |
| 399 callback_num_(0) {} | 414 callback_num_(0) {} |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 441 | 456 |
| 442 // Update the audio-delay measurement, inform about the number of skipped | 457 // Update the audio-delay measurement, inform about the number of skipped |
| 443 // frames, and ask client to render audio. Since |output_bus_| is wrapping | 458 // frames, and ask client to render audio. Since |output_bus_| is wrapping |
| 444 // the shared memory the Render() call is writing directly into the shared | 459 // the shared memory the Render() call is writing directly into the shared |
| 445 // memory. | 460 // memory. |
| 446 render_callback_->Render(output_bus_.get(), std::round(frames_delayed), | 461 render_callback_->Render(output_bus_.get(), std::round(frames_delayed), |
| 447 frames_skipped); | 462 frames_skipped); |
| 448 } | 463 } |
| 449 | 464 |
| 450 } // namespace media | 465 } // namespace media |
| OLD | NEW |