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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <limits> | 10 #include <limits> |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 SyncReader* sync_reader) { | 64 SyncReader* sync_reader) { |
65 CHECK(audio_manager); | 65 CHECK(audio_manager); |
66 CHECK_EQ(AudioManager::Get(), audio_manager); | 66 CHECK_EQ(AudioManager::Get(), audio_manager); |
67 DCHECK(sync_reader); | 67 DCHECK(sync_reader); |
68 | 68 |
69 if (!params.IsValid()) | 69 if (!params.IsValid()) |
70 return NULL; | 70 return NULL; |
71 | 71 |
72 scoped_refptr<AudioOutputController> controller(new AudioOutputController( | 72 scoped_refptr<AudioOutputController> controller(new AudioOutputController( |
73 audio_manager, event_handler, params, output_device_id, sync_reader)); | 73 audio_manager, event_handler, params, output_device_id, sync_reader)); |
74 controller->message_loop_->PostTask(FROM_HERE, base::Bind( | 74 controller->message_loop_->PostTask( |
75 &AudioOutputController::DoCreate, controller, false)); | 75 FROM_HERE, |
| 76 base::BindOnce(&AudioOutputController::DoCreate, controller, false)); |
76 return controller; | 77 return controller; |
77 } | 78 } |
78 | 79 |
79 void AudioOutputController::Play() { | 80 void AudioOutputController::Play() { |
80 CHECK_EQ(AudioManager::Get(), audio_manager_); | 81 CHECK_EQ(AudioManager::Get(), audio_manager_); |
81 message_loop_->PostTask(FROM_HERE, base::Bind( | 82 message_loop_->PostTask(FROM_HERE, |
82 &AudioOutputController::DoPlay, this)); | 83 base::BindOnce(&AudioOutputController::DoPlay, this)); |
83 } | 84 } |
84 | 85 |
85 void AudioOutputController::Pause() { | 86 void AudioOutputController::Pause() { |
86 CHECK_EQ(AudioManager::Get(), audio_manager_); | 87 CHECK_EQ(AudioManager::Get(), audio_manager_); |
87 message_loop_->PostTask(FROM_HERE, base::Bind( | 88 message_loop_->PostTask( |
88 &AudioOutputController::DoPause, this)); | 89 FROM_HERE, base::BindOnce(&AudioOutputController::DoPause, this)); |
89 } | 90 } |
90 | 91 |
91 void AudioOutputController::Close(const base::Closure& closed_task) { | 92 void AudioOutputController::Close(base::OnceClosure closed_task) { |
92 CHECK_EQ(AudioManager::Get(), audio_manager_); | 93 CHECK_EQ(AudioManager::Get(), audio_manager_); |
93 DCHECK(!closed_task.is_null()); | 94 DCHECK(!closed_task.is_null()); |
94 message_loop_->PostTaskAndReply(FROM_HERE, base::Bind( | 95 message_loop_->PostTaskAndReply( |
95 &AudioOutputController::DoClose, this), closed_task); | 96 FROM_HERE, base::BindOnce(&AudioOutputController::DoClose, this), |
| 97 std::move(closed_task)); |
96 } | 98 } |
97 | 99 |
98 void AudioOutputController::SetVolume(double volume) { | 100 void AudioOutputController::SetVolume(double volume) { |
99 CHECK_EQ(AudioManager::Get(), audio_manager_); | 101 CHECK_EQ(AudioManager::Get(), audio_manager_); |
100 message_loop_->PostTask(FROM_HERE, base::Bind( | 102 message_loop_->PostTask( |
101 &AudioOutputController::DoSetVolume, this, volume)); | 103 FROM_HERE, |
| 104 base::BindOnce(&AudioOutputController::DoSetVolume, this, volume)); |
102 } | 105 } |
103 | 106 |
104 void AudioOutputController::DoCreate(bool is_for_device_change) { | 107 void AudioOutputController::DoCreate(bool is_for_device_change) { |
105 DCHECK(message_loop_->BelongsToCurrentThread()); | 108 DCHECK(message_loop_->BelongsToCurrentThread()); |
106 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioOutputController.CreateTime"); | 109 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioOutputController.CreateTime"); |
107 TRACE_EVENT0("audio", "AudioOutputController::DoCreate"); | 110 TRACE_EVENT0("audio", "AudioOutputController::DoCreate"); |
108 | 111 |
109 // Close() can be called before DoCreate() is executed. | 112 // Close() can be called before DoCreate() is executed. |
110 if (state_ == kClosed) | 113 if (state_ == kClosed) |
111 return; | 114 return; |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 { | 276 { |
274 base::AutoLock lock(duplication_targets_lock_); | 277 base::AutoLock lock(duplication_targets_lock_); |
275 need_to_duplicate = !duplication_targets_.empty(); | 278 need_to_duplicate = !duplication_targets_.empty(); |
276 } | 279 } |
277 if (need_to_duplicate) { | 280 if (need_to_duplicate) { |
278 const base::TimeTicks reference_time = delay_timestamp + delay; | 281 const base::TimeTicks reference_time = delay_timestamp + delay; |
279 std::unique_ptr<AudioBus> copy(AudioBus::Create(params_)); | 282 std::unique_ptr<AudioBus> copy(AudioBus::Create(params_)); |
280 dest->CopyTo(copy.get()); | 283 dest->CopyTo(copy.get()); |
281 message_loop_->PostTask( | 284 message_loop_->PostTask( |
282 FROM_HERE, | 285 FROM_HERE, |
283 base::Bind(&AudioOutputController::BroadcastDataToDuplicationTargets, | 286 base::BindOnce( |
284 this, base::Passed(©), reference_time)); | 287 &AudioOutputController::BroadcastDataToDuplicationTargets, this, |
| 288 std::move(copy), reference_time)); |
285 } | 289 } |
286 | 290 |
287 if (will_monitor_audio_levels()) | 291 if (will_monitor_audio_levels()) |
288 power_monitor_.Scan(*dest, frames); | 292 power_monitor_.Scan(*dest, frames); |
289 | 293 |
290 return frames; | 294 return frames; |
291 } | 295 } |
292 | 296 |
293 void AudioOutputController::BroadcastDataToDuplicationTargets( | 297 void AudioOutputController::BroadcastDataToDuplicationTargets( |
294 std::unique_ptr<AudioBus> audio_bus, | 298 std::unique_ptr<AudioBus> audio_bus, |
(...skipping 15 matching lines...) Expand all Loading... |
310 } | 314 } |
311 | 315 |
312 void AudioOutputController::OnError(AudioOutputStream* stream) { | 316 void AudioOutputController::OnError(AudioOutputStream* stream) { |
313 { | 317 { |
314 base::AutoLock auto_lock(error_lock_); | 318 base::AutoLock auto_lock(error_lock_); |
315 if (ignore_errors_during_stop_close_) | 319 if (ignore_errors_during_stop_close_) |
316 return; | 320 return; |
317 } | 321 } |
318 | 322 |
319 // Handle error on the audio controller thread. | 323 // Handle error on the audio controller thread. |
320 message_loop_->PostTask(FROM_HERE, base::Bind( | 324 message_loop_->PostTask( |
321 &AudioOutputController::DoReportError, this)); | 325 FROM_HERE, base::BindOnce(&AudioOutputController::DoReportError, this)); |
322 } | 326 } |
323 | 327 |
324 void AudioOutputController::DoStopCloseAndClearStream() { | 328 void AudioOutputController::DoStopCloseAndClearStream() { |
325 DCHECK(message_loop_->BelongsToCurrentThread()); | 329 DCHECK(message_loop_->BelongsToCurrentThread()); |
326 | 330 |
327 // Allow calling unconditionally and bail if we don't have a stream_ to close. | 331 // Allow calling unconditionally and bail if we don't have a stream_ to close. |
328 if (stream_) { | 332 if (stream_) { |
329 { | 333 { |
330 base::AutoLock auto_lock(error_lock_); | 334 base::AutoLock auto_lock(error_lock_); |
331 ignore_errors_during_stop_close_ = true; | 335 ignore_errors_during_stop_close_ = true; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 NOTREACHED() << "Invalid original state."; | 383 NOTREACHED() << "Invalid original state."; |
380 } | 384 } |
381 } | 385 } |
382 | 386 |
383 const AudioParameters& AudioOutputController::GetAudioParameters() { | 387 const AudioParameters& AudioOutputController::GetAudioParameters() { |
384 return params_; | 388 return params_; |
385 } | 389 } |
386 | 390 |
387 void AudioOutputController::StartDiverting(AudioOutputStream* to_stream) { | 391 void AudioOutputController::StartDiverting(AudioOutputStream* to_stream) { |
388 message_loop_->PostTask( | 392 message_loop_->PostTask( |
389 FROM_HERE, | 393 FROM_HERE, base::BindOnce(&AudioOutputController::DoStartDiverting, this, |
390 base::Bind(&AudioOutputController::DoStartDiverting, this, to_stream)); | 394 to_stream)); |
391 } | 395 } |
392 | 396 |
393 void AudioOutputController::StopDiverting() { | 397 void AudioOutputController::StopDiverting() { |
394 message_loop_->PostTask( | 398 message_loop_->PostTask( |
395 FROM_HERE, base::Bind(&AudioOutputController::DoStopDiverting, this)); | 399 FROM_HERE, base::BindOnce(&AudioOutputController::DoStopDiverting, this)); |
396 } | 400 } |
397 | 401 |
398 void AudioOutputController::StartDuplicating(AudioPushSink* sink) { | 402 void AudioOutputController::StartDuplicating(AudioPushSink* sink) { |
399 message_loop_->PostTask( | 403 message_loop_->PostTask( |
400 FROM_HERE, | 404 FROM_HERE, |
401 base::Bind(&AudioOutputController::DoStartDuplicating, this, sink)); | 405 base::BindOnce(&AudioOutputController::DoStartDuplicating, this, sink)); |
402 } | 406 } |
403 | 407 |
404 void AudioOutputController::StopDuplicating(AudioPushSink* sink) { | 408 void AudioOutputController::StopDuplicating(AudioPushSink* sink) { |
405 message_loop_->PostTask( | 409 message_loop_->PostTask( |
406 FROM_HERE, | 410 FROM_HERE, |
407 base::Bind(&AudioOutputController::DoStopDuplicating, this, sink)); | 411 base::BindOnce(&AudioOutputController::DoStopDuplicating, this, sink)); |
408 } | 412 } |
409 | 413 |
410 void AudioOutputController::DoStartDiverting(AudioOutputStream* to_stream) { | 414 void AudioOutputController::DoStartDiverting(AudioOutputStream* to_stream) { |
411 DCHECK(message_loop_->BelongsToCurrentThread()); | 415 DCHECK(message_loop_->BelongsToCurrentThread()); |
412 | 416 |
413 if (state_ == kClosed) | 417 if (state_ == kClosed) |
414 return; | 418 return; |
415 | 419 |
416 DCHECK(!diverting_to_stream_); | 420 DCHECK(!diverting_to_stream_); |
417 diverting_to_stream_ = to_stream; | 421 diverting_to_stream_ = to_stream; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 DCHECK(message_loop_->BelongsToCurrentThread()); | 464 DCHECK(message_loop_->BelongsToCurrentThread()); |
461 | 465 |
462 // If we should be playing and we haven't, that's a wedge. | 466 // If we should be playing and we haven't, that's a wedge. |
463 if (state_ == kPlaying) { | 467 if (state_ == kPlaying) { |
464 UMA_HISTOGRAM_BOOLEAN("Media.AudioOutputControllerPlaybackStartupSuccess", | 468 UMA_HISTOGRAM_BOOLEAN("Media.AudioOutputControllerPlaybackStartupSuccess", |
465 base::AtomicRefCountIsOne(&on_more_io_data_called_)); | 469 base::AtomicRefCountIsOne(&on_more_io_data_called_)); |
466 } | 470 } |
467 } | 471 } |
468 | 472 |
469 } // namespace media | 473 } // namespace media |
OLD | NEW |