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_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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 | 89 |
90 void AudioOutputController::Flush() { | 90 void AudioOutputController::Flush() { |
91 DCHECK(message_loop_); | 91 DCHECK(message_loop_); |
92 message_loop_->PostTask(FROM_HERE, base::Bind( | 92 message_loop_->PostTask(FROM_HERE, base::Bind( |
93 &AudioOutputController::DoFlush, base::Unretained(this))); | 93 &AudioOutputController::DoFlush, base::Unretained(this))); |
94 } | 94 } |
95 | 95 |
96 void AudioOutputController::Close(const base::Closure& closed_task) { | 96 void AudioOutputController::Close(const base::Closure& closed_task) { |
97 DCHECK(!closed_task.is_null()); | 97 DCHECK(!closed_task.is_null()); |
98 DCHECK(message_loop_); | 98 DCHECK(message_loop_); |
99 message_loop_->PostTask(FROM_HERE, base::Bind( | 99 message_loop_->PostTaskAndReply(FROM_HERE, base::Bind( |
100 &AudioOutputController::DoClose, base::Unretained(this), closed_task)); | 100 &AudioOutputController::DoClose, base::Unretained(this)), closed_task); |
101 } | 101 } |
102 | 102 |
103 void AudioOutputController::SetVolume(double volume) { | 103 void AudioOutputController::SetVolume(double volume) { |
104 DCHECK(message_loop_); | 104 DCHECK(message_loop_); |
105 message_loop_->PostTask(FROM_HERE, base::Bind( | 105 message_loop_->PostTask(FROM_HERE, base::Bind( |
106 &AudioOutputController::DoSetVolume, base::Unretained(this), volume)); | 106 &AudioOutputController::DoSetVolume, base::Unretained(this), volume)); |
107 } | 107 } |
108 | 108 |
109 void AudioOutputController::DoCreate(AudioManager* audio_manager, | 109 void AudioOutputController::DoCreate(AudioManager* audio_manager, |
110 const AudioParameters& params) { | 110 const AudioParameters& params) { |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 return; | 233 return; |
234 } | 234 } |
235 } | 235 } |
236 | 236 |
237 void AudioOutputController::DoFlush() { | 237 void AudioOutputController::DoFlush() { |
238 DCHECK(message_loop_->BelongsToCurrentThread()); | 238 DCHECK(message_loop_->BelongsToCurrentThread()); |
239 | 239 |
240 // TODO(hclam): Actually flush the audio device. | 240 // TODO(hclam): Actually flush the audio device. |
241 } | 241 } |
242 | 242 |
243 void AudioOutputController::DoClose(const base::Closure& closed_task) { | 243 void AudioOutputController::DoClose() { |
244 DCHECK(message_loop_->BelongsToCurrentThread()); | 244 DCHECK(message_loop_->BelongsToCurrentThread()); |
245 | 245 |
246 if (state_ != kClosed) { | 246 if (state_ != kClosed) { |
247 DoStopCloseAndClearStream(NULL); | 247 DoStopCloseAndClearStream(NULL); |
248 sync_reader_->Close(); | 248 sync_reader_->Close(); |
249 state_ = kClosed; | 249 state_ = kClosed; |
250 } | 250 } |
251 | |
252 closed_task.Run(); | |
253 } | 251 } |
254 | 252 |
255 void AudioOutputController::DoSetVolume(double volume) { | 253 void AudioOutputController::DoSetVolume(double volume) { |
256 DCHECK(message_loop_->BelongsToCurrentThread()); | 254 DCHECK(message_loop_->BelongsToCurrentThread()); |
257 | 255 |
258 // Saves the volume to a member first. We may not be able to set the volume | 256 // Saves the volume to a member first. We may not be able to set the volume |
259 // right away but when the stream is created we'll set the volume. | 257 // right away but when the stream is created we'll set the volume. |
260 volume_ = volume; | 258 volume_ = volume; |
261 | 259 |
262 switch (state_) { | 260 switch (state_) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 stream_ = NULL; | 324 stream_ = NULL; |
327 weak_this_.InvalidateWeakPtrs(); | 325 weak_this_.InvalidateWeakPtrs(); |
328 } | 326 } |
329 | 327 |
330 // Should be last in the method, do not touch "this" from here on. | 328 // Should be last in the method, do not touch "this" from here on. |
331 if (done != NULL) | 329 if (done != NULL) |
332 done->Signal(); | 330 done->Signal(); |
333 } | 331 } |
334 | 332 |
335 } // namespace media | 333 } // namespace media |
OLD | NEW |