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_proxy.h" | 5 #include "media/audio/audio_output_proxy.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "media/audio/audio_manager.h" | 9 #include "media/audio/audio_manager.h" |
| 10 #include "media/audio/audio_output_dispatcher.h" | 10 #include "media/audio/audio_output_dispatcher.h" |
| 11 | 11 |
| 12 AudioOutputProxy::AudioOutputProxy(AudioOutputDispatcher* dispatcher) | 12 AudioOutputProxy::AudioOutputProxy(AudioOutputDispatcher* dispatcher) |
| 13 : dispatcher_(dispatcher), | 13 : dispatcher_(dispatcher), |
| 14 state_(kCreated), | 14 state_(kCreated), |
| 15 physical_stream_(NULL), | 15 volume_(1.0), |
| 16 volume_(1.0) { | 16 audio_source_callback_(NULL) { |
| 17 } | 17 } |
| 18 | 18 |
| 19 AudioOutputProxy::~AudioOutputProxy() { | 19 AudioOutputProxy::~AudioOutputProxy() { |
| 20 DCHECK(CalledOnValidThread()); | 20 DCHECK(CalledOnValidThread()); |
| 21 DCHECK(state_ == kCreated || state_ == kClosed); | 21 DCHECK(state_ == kCreated || state_ == kClosed); |
| 22 DCHECK(!physical_stream_); | 22 DCHECK(!audio_source_callback_); |
| 23 } | 23 } |
| 24 | 24 |
| 25 bool AudioOutputProxy::Open() { | 25 bool AudioOutputProxy::Open() { |
| 26 DCHECK(CalledOnValidThread()); | 26 DCHECK(CalledOnValidThread()); |
| 27 DCHECK_EQ(state_, kCreated); | 27 DCHECK_EQ(state_, kCreated); |
| 28 | 28 |
| 29 if (!dispatcher_->StreamOpened()) { | 29 if (!dispatcher_->OpenStream()) { |
| 30 state_ = kError; | 30 state_ = kError; |
| 31 return false; | 31 return false; |
| 32 } | 32 } |
| 33 | 33 |
| 34 state_ = kOpened; | 34 state_ = kOpened; |
| 35 return true; | 35 return true; |
| 36 } | 36 } |
| 37 | 37 |
| 38 void AudioOutputProxy::Start(AudioSourceCallback* callback) { | 38 void AudioOutputProxy::Start(AudioSourceCallback* callback) { |
| 39 DCHECK(CalledOnValidThread()); | 39 DCHECK(CalledOnValidThread()); |
| 40 DCHECK(physical_stream_ == NULL); | |
| 41 DCHECK_EQ(state_, kOpened); | 40 DCHECK_EQ(state_, kOpened); |
| 41 DCHECK(!audio_source_callback_); | |
| 42 | 42 |
| 43 physical_stream_= dispatcher_->StreamStarted(); | 43 audio_source_callback_ = callback; |
| 44 if (!physical_stream_) { | 44 if (!dispatcher_->StartStream(callback, this)) { |
| 45 state_ = kError; | 45 state_ = kError; |
| 46 callback->OnError(this, 0); | 46 callback->OnError(this, 0); |
| 47 audio_source_callback_ = NULL; | |
| 47 return; | 48 return; |
| 48 } | 49 } |
| 49 | |
| 50 physical_stream_->SetVolume(volume_); | |
| 51 physical_stream_->Start(callback); | |
| 52 state_ = kPlaying; | 50 state_ = kPlaying; |
| 53 } | 51 } |
| 54 | 52 |
| 55 void AudioOutputProxy::Stop() { | 53 void AudioOutputProxy::Stop() { |
| 56 DCHECK(CalledOnValidThread()); | 54 DCHECK(CalledOnValidThread()); |
| 57 if (state_ != kPlaying) | 55 if (state_ != kPlaying) |
| 58 return; | 56 return; |
| 59 | 57 |
| 60 DCHECK(physical_stream_); | 58 dispatcher_->StopStream(this); |
| 61 physical_stream_->Stop(); | 59 audio_source_callback_ = NULL; |
| 62 dispatcher_->StreamStopped(physical_stream_); | |
| 63 physical_stream_ = NULL; | |
| 64 state_ = kOpened; | 60 state_ = kOpened; |
| 65 } | 61 } |
| 66 | 62 |
| 67 void AudioOutputProxy::SetVolume(double volume) { | 63 void AudioOutputProxy::SetVolume(double volume) { |
| 68 DCHECK(CalledOnValidThread()); | 64 DCHECK(CalledOnValidThread()); |
| 69 volume_ = volume; | 65 { |
| 70 if (physical_stream_) { | 66 base::AutoLock lock(lock_); |
|
vrk (LEFT CHROMIUM)
2012/04/06 23:37:05
See suggestion in audio_output_mixer.h, and remove
enal1
2012/04/16 22:01:35
Done.
| |
| 71 physical_stream_->SetVolume(volume); | 67 volume_ = volume; |
| 72 } | 68 } |
| 69 dispatcher_->StreamVolumeSet(this, volume); | |
| 73 } | 70 } |
| 74 | 71 |
| 75 void AudioOutputProxy::GetVolume(double* volume) { | 72 void AudioOutputProxy::GetVolume(double* volume) { |
| 76 DCHECK(CalledOnValidThread()); | 73 base::AutoLock lock(lock_); |
| 77 *volume = volume_; | 74 *volume = volume_; |
| 78 } | 75 } |
| 79 | 76 |
| 80 void AudioOutputProxy::Close() { | 77 void AudioOutputProxy::Close() { |
| 81 DCHECK(CalledOnValidThread()); | 78 DCHECK(CalledOnValidThread()); |
| 82 DCHECK(state_ == kCreated || state_ == kError || state_ == kOpened); | 79 DCHECK(state_ == kCreated || state_ == kError || state_ == kOpened); |
| 83 DCHECK(!physical_stream_); | 80 DCHECK(!audio_source_callback_); |
| 84 | 81 |
| 85 if (state_ != kCreated) | 82 if (state_ != kCreated) |
| 86 dispatcher_->StreamClosed(); | 83 dispatcher_->CloseStream(this); |
| 87 | 84 |
| 88 state_ = kClosed; | 85 state_ = kClosed; |
| 89 | 86 |
| 90 // Delete the object now like is done in the Close() implementation of | 87 // Delete the object now like is done in the Close() implementation of |
| 91 // physical stream objects. If we delete the object via DeleteSoon, we | 88 // physical stream objects. If we delete the object via DeleteSoon, we |
| 92 // unnecessarily complicate the Shutdown procedure of the | 89 // unnecessarily complicate the Shutdown procedure of the |
| 93 // dispatcher+audio manager. | 90 // dispatcher+audio manager. |
| 94 delete this; | 91 delete this; |
| 95 } | 92 } |
| 93 | |
| 94 uint32 AudioOutputProxy::OnMoreData(AudioOutputStream* stream, | |
|
vrk (LEFT CHROMIUM)
2012/04/06 23:37:05
See suggestion in audio_output_mixer.h, and remove
enal1
2012/04/16 22:01:35
Done.
| |
| 95 uint8* dest, | |
| 96 uint32 max_size, | |
| 97 AudioBuffersState buffers_state) { | |
| 98 DCHECK(stream == this); | |
| 99 return audio_source_callback_->OnMoreData(stream, | |
| 100 dest, | |
| 101 max_size, | |
| 102 buffers_state); | |
| 103 } | |
| 104 | |
| 105 void AudioOutputProxy::OnError(AudioOutputStream* stream, int code) { | |
| 106 DCHECK(stream == this); | |
| 107 audio_source_callback_->OnError(stream, code); | |
| 108 } | |
| 109 | |
| 110 void AudioOutputProxy::WaitTillDataReady() { | |
| 111 audio_source_callback_->WaitTillDataReady(); | |
| 112 } | |
| OLD | NEW |