Chromium Code Reviews| Index: media/audio/audio_output_proxy.cc |
| diff --git a/media/audio/audio_output_proxy.cc b/media/audio/audio_output_proxy.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e118cac8cde66496011e0635fec3c7ad533a6b6f |
| --- /dev/null |
| +++ b/media/audio/audio_output_proxy.cc |
| @@ -0,0 +1,93 @@ |
| +// Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "media/audio/audio_output_proxy.h" |
| + |
| +#include "base/logging.h" |
| +#include "base/message_loop.h" |
| +#include "base/task.h" |
| +#include "media/audio/audio_manager.h" |
| +#include "media/audio/audio_output_dispatcher.h" |
| + |
| +AudioOutputProxy::AudioOutputProxy(AudioOutputDispatcher* dispatcher) |
| + : dispatcher_(dispatcher), |
| + state_(kCreated), |
| + physical_stream_(NULL), |
| + volume_(1.0) { |
| + DCHECK_EQ(MessageLoop::current(), dispatcher_->message_loop()); |
| +} |
| + |
| +AudioOutputProxy::~AudioOutputProxy() { |
| + DCHECK_EQ(MessageLoop::current(), dispatcher_->message_loop()); |
| + DCHECK(state_ == kCreated || state_ == kClosed); |
| + DCHECK(!physical_stream_); |
| +} |
| + |
| +bool AudioOutputProxy::Open() { |
| + DCHECK_EQ(MessageLoop::current(), dispatcher_->message_loop()); |
| + DCHECK_EQ(state_, kCreated); |
| + |
| + if (!dispatcher_->StreamOpened()) { |
| + state_ = kError; |
| + return false; |
| + } |
| + |
| + state_ = kOpened; |
| + return true; |
| +} |
| + |
| +void AudioOutputProxy::Start(AudioSourceCallback* callback) { |
| + DCHECK_EQ(MessageLoop::current(), dispatcher_->message_loop()); |
| + DCHECK(physical_stream_ == NULL); |
| + DCHECK_EQ(state_, kOpened); |
| + |
| + physical_stream_= dispatcher_->StreamStarted(); |
| + if (!physical_stream_) { |
| + state_ = kError; |
| + callback->OnError(this, 0); |
| + return; |
| + } |
| + |
| + physical_stream_->SetVolume(volume_); |
| + physical_stream_->Start(callback); |
| + state_ = kPlaying; |
| +} |
| + |
| +void AudioOutputProxy::Stop() { |
| + DCHECK_EQ(MessageLoop::current(), dispatcher_->message_loop()); |
| + if (state_ != kPlaying) |
| + return; |
| + |
| + DCHECK(physical_stream_); |
| + physical_stream_->Stop(); |
| + dispatcher_->StreamStopped(physical_stream_); |
| + physical_stream_ = NULL; |
| + state_ = kOpened; |
| +} |
| + |
| +void AudioOutputProxy::SetVolume(double volume) { |
| + DCHECK_EQ(MessageLoop::current(), dispatcher_->message_loop()); |
| + volume_ = volume; |
| + if (physical_stream_) { |
| + physical_stream_->SetVolume(volume); |
|
scherkus (not reviewing)
2010/11/22 06:43:48
I think I need an explanation of how everything ti
Sergey Ulanov
2010/11/23 19:51:46
On 2010/11/22 06:43:48, scherkus wrote:
> I think
|
| + } |
| +} |
| + |
| +void AudioOutputProxy::GetVolume(double* volume) { |
| + DCHECK_EQ(MessageLoop::current(), dispatcher_->message_loop()); |
| + *volume = volume_; |
| +} |
| + |
| +void AudioOutputProxy::Close() { |
| + DCHECK_EQ(MessageLoop::current(), dispatcher_->message_loop()); |
| + DCHECK(state_ == kCreated || state_ == kError || state_ == kOpened); |
| + DCHECK(!physical_stream_); |
| + |
| + if (state_ != kCreated) { |
| + dispatcher_->StreamClosed(); |
| + } |
| + dispatcher_->message_loop()->PostTask( |
| + FROM_HERE, new DeleteTask<AudioOutputProxy>(this)); |
|
scherkus (not reviewing)
2010/11/22 06:43:15
you can use DeleteSoon(this) instead
Sergey Ulanov
2010/11/23 19:51:46
Done.
|
| + state_ = kClosed; |
| +} |