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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 message_loop_->PostTaskAndReply(FROM_HERE, base::Bind( | 94 message_loop_->PostTaskAndReply(FROM_HERE, base::Bind( |
95 &AudioOutputController::DoClose, this), closed_task); | 95 &AudioOutputController::DoClose, this), closed_task); |
96 } | 96 } |
97 | 97 |
98 void AudioOutputController::SetVolume(double volume) { | 98 void AudioOutputController::SetVolume(double volume) { |
99 CHECK_EQ(AudioManager::Get(), audio_manager_); | 99 CHECK_EQ(AudioManager::Get(), audio_manager_); |
100 message_loop_->PostTask(FROM_HERE, base::Bind( | 100 message_loop_->PostTask(FROM_HERE, base::Bind( |
101 &AudioOutputController::DoSetVolume, this, volume)); | 101 &AudioOutputController::DoSetVolume, this, volume)); |
102 } | 102 } |
103 | 103 |
104 void AudioOutputController::GetOutputDeviceId( | |
105 base::Callback<void(const std::string&)> callback) const { | |
106 CHECK_EQ(AudioManager::Get(), audio_manager_); | |
107 base::PostTaskAndReplyWithResult( | |
108 message_loop_.get(), | |
109 FROM_HERE, | |
110 base::Bind(&AudioOutputController::DoGetOutputDeviceId, this), | |
111 callback); | |
112 } | |
113 | |
114 void AudioOutputController::SwitchOutputDevice( | |
115 const std::string& output_device_id, const base::Closure& callback) { | |
116 CHECK_EQ(AudioManager::Get(), audio_manager_); | |
117 message_loop_->PostTaskAndReply( | |
118 FROM_HERE, | |
119 base::Bind(&AudioOutputController::DoSwitchOutputDevice, this, | |
120 output_device_id), | |
121 callback); | |
122 } | |
123 | |
124 void AudioOutputController::DoCreate(bool is_for_device_change) { | 104 void AudioOutputController::DoCreate(bool is_for_device_change) { |
125 DCHECK(message_loop_->BelongsToCurrentThread()); | 105 DCHECK(message_loop_->BelongsToCurrentThread()); |
126 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioOutputController.CreateTime"); | 106 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioOutputController.CreateTime"); |
127 TRACE_EVENT0("audio", "AudioOutputController::DoCreate"); | 107 TRACE_EVENT0("audio", "AudioOutputController::DoCreate"); |
128 | 108 |
129 // Close() can be called before DoCreate() is executed. | 109 // Close() can be called before DoCreate() is executed. |
130 if (state_ == kClosed) | 110 if (state_ == kClosed) |
131 return; | 111 return; |
132 | 112 |
133 DoStopCloseAndClearStream(); // Calls RemoveOutputDeviceChangeListener(). | 113 DoStopCloseAndClearStream(); // Calls RemoveOutputDeviceChangeListener(). |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 case kCreated: | 236 case kCreated: |
257 case kPlaying: | 237 case kPlaying: |
258 case kPaused: | 238 case kPaused: |
259 stream_->SetVolume(volume_); | 239 stream_->SetVolume(volume_); |
260 break; | 240 break; |
261 default: | 241 default: |
262 return; | 242 return; |
263 } | 243 } |
264 } | 244 } |
265 | 245 |
266 std::string AudioOutputController::DoGetOutputDeviceId() const { | |
267 DCHECK(message_loop_->BelongsToCurrentThread()); | |
268 return output_device_id_; | |
269 } | |
270 | |
271 void AudioOutputController::DoSwitchOutputDevice( | |
272 const std::string& output_device_id) { | |
273 DCHECK(message_loop_->BelongsToCurrentThread()); | |
274 | |
275 if (state_ == kClosed) | |
276 return; | |
277 | |
278 if (output_device_id == output_device_id_) | |
279 return; | |
280 | |
281 output_device_id_ = output_device_id; | |
282 | |
283 // If output is currently diverted, we must not call OnDeviceChange | |
284 // since it would break the diverted setup. Once diversion is | |
285 // finished using StopDiverting() the output will switch to the new | |
286 // device ID. | |
287 if (stream_ != diverting_to_stream_) | |
288 OnDeviceChange(); | |
289 } | |
290 | |
291 void AudioOutputController::DoReportError() { | 246 void AudioOutputController::DoReportError() { |
292 DCHECK(message_loop_->BelongsToCurrentThread()); | 247 DCHECK(message_loop_->BelongsToCurrentThread()); |
293 if (state_ != kClosed) | 248 if (state_ != kClosed) |
294 handler_->OnControllerError(); | 249 handler_->OnControllerError(); |
295 } | 250 } |
296 | 251 |
297 int AudioOutputController::OnMoreData(base::TimeDelta delay, | 252 int AudioOutputController::OnMoreData(base::TimeDelta delay, |
298 base::TimeTicks delay_timestamp, | 253 base::TimeTicks delay_timestamp, |
299 int prior_frames_skipped, | 254 int prior_frames_skipped, |
300 AudioBus* dest) { | 255 AudioBus* dest) { |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 DCHECK(message_loop_->BelongsToCurrentThread()); | 460 DCHECK(message_loop_->BelongsToCurrentThread()); |
506 | 461 |
507 // If we should be playing and we haven't, that's a wedge. | 462 // If we should be playing and we haven't, that's a wedge. |
508 if (state_ == kPlaying) { | 463 if (state_ == kPlaying) { |
509 UMA_HISTOGRAM_BOOLEAN("Media.AudioOutputControllerPlaybackStartupSuccess", | 464 UMA_HISTOGRAM_BOOLEAN("Media.AudioOutputControllerPlaybackStartupSuccess", |
510 base::AtomicRefCountIsOne(&on_more_io_data_called_)); | 465 base::AtomicRefCountIsOne(&on_more_io_data_called_)); |
511 } | 466 } |
512 } | 467 } |
513 | 468 |
514 } // namespace media | 469 } // namespace media |
OLD | NEW |