diff options
author | fischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-24 22:40:25 +0000 |
---|---|---|
committer | fischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-24 22:40:25 +0000 |
commit | 570eff9b06a32fe16ac4ecf72f2f4e06202238e5 (patch) | |
tree | 9e17e8bef3776d94447588f0e18c23cdb5cd6c56 /media | |
parent | f8bf599c20fe17b4e8c6105ee00c554dd2fde6ff (diff) | |
download | chromium_src-570eff9b06a32fe16ac4ecf72f2f4e06202238e5.zip chromium_src-570eff9b06a32fe16ac4ecf72f2f4e06202238e5.tar.gz chromium_src-570eff9b06a32fe16ac4ecf72f2f4e06202238e5.tar.bz2 |
Stop audio streams in all codepaths that need it.
Before we were leaving dangling streams un-Stop()'d, causing delayed messages to
eventually crash the browser when their source_callback_ was followed but
already invalid.
BUG=101228
TEST=trybots, manual testing.
Review URL: http://codereview.chromium.org/8385001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107000 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r-- | media/audio/audio_output_controller.cc | 26 | ||||
-rw-r--r-- | media/audio/audio_output_controller.h | 3 |
2 files changed, 19 insertions, 10 deletions
diff --git a/media/audio/audio_output_controller.cc b/media/audio/audio_output_controller.cc index cd57bed..adad10a 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); @@ -234,6 +235,9 @@ void AudioOutputController::StartStream() { void AudioOutputController::DoPause() { DCHECK_EQ(message_loop_, MessageLoop::current()); + if (stream_) + stream_->Stop(); + switch (state_) { case kStarting: // We were asked to pause while starting. There is delayed task that will @@ -280,14 +284,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(); @@ -388,4 +385,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 diff --git a/media/audio/audio_output_controller.h b/media/audio/audio_output_controller.h index e359d27c..ea8f27a 100644 --- a/media/audio/audio_output_controller.h +++ b/media/audio/audio_output_controller.h @@ -202,6 +202,9 @@ class MEDIA_EXPORT AudioOutputController // Helper method that starts physical stream. void StartStream(); + // Helper method that stops, closes, and NULLs |*stream_|. + void StopCloseAndClearStream(); + // |handler_| may be called only if |state_| is not kClosed. EventHandler* handler_; AudioOutputStream* stream_; |