| Index: media/audio/audio_output_controller.cc
|
| diff --git a/media/audio/audio_output_controller.cc b/media/audio/audio_output_controller.cc
|
| index 7118eaa9b83fe7c1e0b2649ac5163b06bfbf5ce4..dd6a6b4eab60f6ee65b75a42f9dbbe70a76d7257 100644
|
| --- a/media/audio/audio_output_controller.cc
|
| +++ b/media/audio/audio_output_controller.cc
|
| @@ -33,6 +33,7 @@ AudioOutputController::AudioOutputController(EventHandler* handler,
|
|
|
| AudioOutputController::~AudioOutputController() {
|
| DCHECK_EQ(kClosed, state_);
|
| + StopCloseAndClearStream();
|
| }
|
|
|
| // static
|
| @@ -138,6 +139,7 @@ void AudioOutputController::DoCreate(const AudioParameters& params) {
|
| if (!AudioManager::GetAudioManager())
|
| return;
|
|
|
| + StopCloseAndClearStream();
|
| stream_ = AudioManager::GetAudioManager()->MakeAudioOutputStreamProxy(params);
|
| if (!stream_) {
|
| // TODO(hclam): Define error types.
|
| @@ -146,8 +148,7 @@ void AudioOutputController::DoCreate(const AudioParameters& params) {
|
| }
|
|
|
| if (!stream_->Open()) {
|
| - stream_->Close();
|
| - stream_ = NULL;
|
| + StopCloseAndClearStream();
|
|
|
| // TODO(hclam): Define error types.
|
| handler_->OnError(this, 0);
|
| @@ -226,8 +227,11 @@ void AudioOutputController::DoPause() {
|
| DCHECK_EQ(message_loop_, MessageLoop::current());
|
|
|
| // We can pause from started state.
|
| - if (state_ != kPlaying)
|
| + if (state_ != kPlaying) {
|
| + if (stream_)
|
| + stream_->Stop();
|
| return;
|
| + }
|
| state_ = kPaused;
|
|
|
| // Then we stop the audio device. This is not the perfect solution because
|
| @@ -261,14 +265,7 @@ void AudioOutputController::DoClose(const base::Closure& closed_task) {
|
| DCHECK_EQ(message_loop_, MessageLoop::current());
|
|
|
| if (state_ != kClosed) {
|
| - // |stream_| can be null if creating the device failed in DoCreate().
|
| - if (stream_) {
|
| - stream_->Stop();
|
| - stream_->Close();
|
| - // After stream is closed it is destroyed, so don't keep a reference to
|
| - // it.
|
| - stream_ = NULL;
|
| - }
|
| + StopCloseAndClearStream();
|
|
|
| if (LowLatencyMode()) {
|
| sync_reader_->Close();
|
| @@ -362,4 +359,13 @@ void AudioOutputController::SubmitOnMoreData_Locked() {
|
| handler_->OnMoreData(this, buffers_state);
|
| }
|
|
|
| +void AudioOutputController::StopCloseAndClearStream() {
|
| + // Allow calling unconditionally and bail if we don't have a stream_ to close.
|
| + if (!stream_)
|
| + return;
|
| + stream_->Stop();
|
| + stream_->Close();
|
| + stream_ = NULL;
|
| +}
|
| +
|
| } // namespace media
|
|
|