| Index: media/audio/audio_output_device.cc
|
| diff --git a/media/audio/audio_output_device.cc b/media/audio/audio_output_device.cc
|
| index 2518f950e74df9d5ac149ec2cbefafea28c5c96c..692603c75d6a32ac13b94efcdaaa07bcaeada319 100644
|
| --- a/media/audio/audio_output_device.cc
|
| +++ b/media/audio/audio_output_device.cc
|
| @@ -4,6 +4,8 @@
|
|
|
| #include "media/audio/audio_output_device.h"
|
|
|
| +#include <string>
|
| +
|
| #include "base/threading/thread_restrictions.h"
|
| #include "base/time/time.h"
|
| #include "base/trace_event/trace_event.h"
|
| @@ -45,7 +47,8 @@ AudioOutputDevice::AudioOutputDevice(
|
| state_(IDLE),
|
| play_on_start_(true),
|
| session_id_(-1),
|
| - stopping_hack_(false) {
|
| + stopping_hack_(false),
|
| + current_switch_request_id_(0) {
|
| CHECK(ipc_);
|
|
|
| // The correctness of the code depends on the relative values assigned in the
|
| @@ -117,6 +120,17 @@ bool AudioOutputDevice::SetVolume(double volume) {
|
| return true;
|
| }
|
|
|
| +void AudioOutputDevice::SwitchOutputDevice(
|
| + const std::string& device_id,
|
| + const GURL& security_origin,
|
| + scoped_ptr<SwitchOutputDeviceCallbackRunner> callback_runner) {
|
| + DVLOG(1) << __FUNCTION__ << "(" << device_id << ")";
|
| + task_runner()->PostTask(
|
| + FROM_HERE, base::Bind(&AudioOutputDevice::SwitchOutputDeviceOnIOThread,
|
| + this, device_id, security_origin,
|
| + base::Passed(callback_runner.Pass())));
|
| +}
|
| +
|
| void AudioOutputDevice::CreateStreamOnIOThread(const AudioParameters& params) {
|
| DCHECK(task_runner()->BelongsToCurrentThread());
|
| if (state_ == IDLE) {
|
| @@ -179,6 +193,21 @@ void AudioOutputDevice::SetVolumeOnIOThread(double volume) {
|
| ipc_->SetVolume(volume);
|
| }
|
|
|
| +void AudioOutputDevice::SwitchOutputDeviceOnIOThread(
|
| + const std::string& device_id,
|
| + const GURL& security_origin,
|
| + scoped_ptr<SwitchOutputDeviceCallbackRunner> callback_runner) {
|
| + DCHECK(task_runner()->BelongsToCurrentThread());
|
| + DVLOG(1) << __FUNCTION__ << "(" << device_id << "," << security_origin << ")";
|
| + if (state_ >= CREATING_STREAM) {
|
| + SetCurrentSwitchRequest(callback_runner.Pass());
|
| + ipc_->SwitchOutputDevice(device_id, security_origin,
|
| + current_switch_request_id_);
|
| + } else {
|
| + callback_runner->Run(SWITCH_OUTPUT_DEVICE_RESULT_ERROR_NOT_SUPPORTED);
|
| + }
|
| +}
|
| +
|
| void AudioOutputDevice::OnStateChanged(AudioOutputIPCDelegate::State state) {
|
| DCHECK(task_runner()->BelongsToCurrentThread());
|
|
|
| @@ -254,6 +283,32 @@ void AudioOutputDevice::OnStreamCreated(
|
| PlayOnIOThread();
|
| }
|
|
|
| +void AudioOutputDevice::SetCurrentSwitchRequest(
|
| + scoped_ptr<SwitchOutputDeviceCallbackRunner> callback_runner) {
|
| + DCHECK(task_runner()->BelongsToCurrentThread());
|
| + DVLOG(1) << __FUNCTION__;
|
| + // If there is a previous unresolved request, resolve it as obsolete
|
| + if (current_switch_callback_runner_) {
|
| + current_switch_callback_runner_->Run(
|
| + SWITCH_OUTPUT_DEVICE_RESULT_ERROR_OBSOLETE);
|
| + }
|
| + current_switch_callback_runner_ = callback_runner.Pass();
|
| + current_switch_request_id_++;
|
| +}
|
| +
|
| +void AudioOutputDevice::OnOutputDeviceSwitched(
|
| + int request_id, SwitchOutputDeviceResult result) {
|
| + DCHECK(task_runner()->BelongsToCurrentThread());
|
| + DCHECK(request_id <= current_switch_request_id_);
|
| + DVLOG(1) << __FUNCTION__
|
| + << "(" << request_id << ", " << result << ")";
|
| + if (request_id != current_switch_request_id_) {
|
| + return;
|
| + }
|
| + current_switch_callback_runner_->Run(result);
|
| + current_switch_callback_runner_ = NULL;
|
| +}
|
| +
|
| void AudioOutputDevice::OnIPCClosed() {
|
| DCHECK(task_runner()->BelongsToCurrentThread());
|
| state_ = IPC_CLOSED;
|
|
|