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

Side by Side Diff: media/audio/audio_output_controller.cc

Issue 10261027: Fix race condition caused by r114084. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 8 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_controller.h" 5 #include "media/audio/audio_output_controller.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 controller->message_loop_ = audio_manager->GetMessageLoop(); 74 controller->message_loop_ = audio_manager->GetMessageLoop();
75 controller->message_loop_->PostTask(FROM_HERE, base::Bind( 75 controller->message_loop_->PostTask(FROM_HERE, base::Bind(
76 &AudioOutputController::DoCreate, controller, 76 &AudioOutputController::DoCreate, controller,
77 base::Unretained(audio_manager), params)); 77 base::Unretained(audio_manager), params));
78 return controller; 78 return controller;
79 } 79 }
80 80
81 void AudioOutputController::Play() { 81 void AudioOutputController::Play() {
82 DCHECK(message_loop_); 82 DCHECK(message_loop_);
83 message_loop_->PostTask(FROM_HERE, base::Bind( 83 message_loop_->PostTask(FROM_HERE, base::Bind(
84 &AudioOutputController::DoPlay, base::Unretained(this))); 84 &AudioOutputController::DoPlay, this));
85 } 85 }
86 86
87 void AudioOutputController::Pause() { 87 void AudioOutputController::Pause() {
88 DCHECK(message_loop_); 88 DCHECK(message_loop_);
89 message_loop_->PostTask(FROM_HERE, base::Bind( 89 message_loop_->PostTask(FROM_HERE, base::Bind(
90 &AudioOutputController::DoPause, base::Unretained(this))); 90 &AudioOutputController::DoPause, this));
91 } 91 }
92 92
93 void AudioOutputController::Flush() { 93 void AudioOutputController::Flush() {
94 DCHECK(message_loop_); 94 DCHECK(message_loop_);
95 message_loop_->PostTask(FROM_HERE, base::Bind( 95 message_loop_->PostTask(FROM_HERE, base::Bind(
96 &AudioOutputController::DoFlush, base::Unretained(this))); 96 &AudioOutputController::DoFlush, this));
97 } 97 }
98 98
99 void AudioOutputController::Close(const base::Closure& closed_task) { 99 void AudioOutputController::Close(const base::Closure& closed_task) {
100 DCHECK(!closed_task.is_null()); 100 DCHECK(!closed_task.is_null());
101 DCHECK(message_loop_); 101 DCHECK(message_loop_);
102 message_loop_->PostTaskAndReply(FROM_HERE, base::Bind( 102 message_loop_->PostTaskAndReply(FROM_HERE, base::Bind(
103 &AudioOutputController::DoClose, base::Unretained(this)), closed_task); 103 &AudioOutputController::DoClose, this), closed_task);
104 } 104 }
105 105
106 void AudioOutputController::SetVolume(double volume) { 106 void AudioOutputController::SetVolume(double volume) {
107 DCHECK(message_loop_); 107 DCHECK(message_loop_);
108 message_loop_->PostTask(FROM_HERE, base::Bind( 108 message_loop_->PostTask(FROM_HERE, base::Bind(
109 &AudioOutputController::DoSetVolume, base::Unretained(this), volume)); 109 &AudioOutputController::DoSetVolume, this, volume));
110 } 110 }
111 111
112 void AudioOutputController::DoCreate(AudioManager* audio_manager, 112 void AudioOutputController::DoCreate(AudioManager* audio_manager,
113 const AudioParameters& params) { 113 const AudioParameters& params) {
114 DCHECK(message_loop_->BelongsToCurrentThread()); 114 DCHECK(message_loop_->BelongsToCurrentThread());
115 115
116 // Close() can be called before DoCreate() is executed. 116 // Close() can be called before DoCreate() is executed.
117 if (state_ == kClosed) 117 if (state_ == kClosed)
118 return; 118 return;
119 DCHECK_EQ(kEmpty, state_); 119 DCHECK_EQ(kEmpty, state_);
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 do { 307 do {
308 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1)); 308 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1));
309 } while (!sync_reader_->DataReady() && 309 } while (!sync_reader_->DataReady() &&
310 Time::Now() - start_time < kMaxPollingDelay); 310 Time::Now() - start_time < kMaxPollingDelay);
311 } 311 }
312 } 312 }
313 313
314 void AudioOutputController::OnError(AudioOutputStream* stream, int code) { 314 void AudioOutputController::OnError(AudioOutputStream* stream, int code) {
315 // Handle error on the audio controller thread. 315 // Handle error on the audio controller thread.
316 message_loop_->PostTask(FROM_HERE, base::Bind( 316 message_loop_->PostTask(FROM_HERE, base::Bind(
317 &AudioOutputController::DoReportError, base::Unretained(this), code)); 317 &AudioOutputController::DoReportError, this, code));
318 } 318 }
319 319
320 void AudioOutputController::DoStopCloseAndClearStream(WaitableEvent *done) { 320 void AudioOutputController::DoStopCloseAndClearStream(WaitableEvent *done) {
321 DCHECK(message_loop_->BelongsToCurrentThread()); 321 DCHECK(message_loop_->BelongsToCurrentThread());
322 322
323 // Allow calling unconditionally and bail if we don't have a stream_ to close. 323 // Allow calling unconditionally and bail if we don't have a stream_ to close.
324 if (stream_ != NULL) { 324 if (stream_ != NULL) {
325 stream_->Stop(); 325 stream_->Stop();
326 stream_->Close(); 326 stream_->Close();
327 stream_ = NULL; 327 stream_ = NULL;
328 weak_this_.InvalidateWeakPtrs(); 328 weak_this_.InvalidateWeakPtrs();
329 } 329 }
330 330
331 // Should be last in the method, do not touch "this" from here on. 331 // Should be last in the method, do not touch "this" from here on.
332 if (done != NULL) 332 if (done != NULL)
333 done->Signal(); 333 done->Signal();
334 } 334 }
335 335
336 } // namespace media 336 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698