Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(302)

Unified Diff: media/audio/audio_output_controller.cc

Issue 8385001: Stop audio streams in all codepaths that need it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: enal CR response. Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/audio/audio_output_controller.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « media/audio/audio_output_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698