| 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 return; | 130 return; |
| 131 | 131 |
| 132 DoStopCloseAndClearStream(); // Calls RemoveOutputDeviceChangeListener(). | 132 DoStopCloseAndClearStream(); // Calls RemoveOutputDeviceChangeListener(). |
| 133 DCHECK_EQ(kEmpty, state_); | 133 DCHECK_EQ(kEmpty, state_); |
| 134 | 134 |
| 135 stream_ = diverting_to_stream_ ? | 135 stream_ = diverting_to_stream_ ? |
| 136 diverting_to_stream_ : | 136 diverting_to_stream_ : |
| 137 audio_manager_->MakeAudioOutputStreamProxy(params_, output_device_id_); | 137 audio_manager_->MakeAudioOutputStreamProxy(params_, output_device_id_); |
| 138 if (!stream_) { | 138 if (!stream_) { |
| 139 state_ = kError; | 139 state_ = kError; |
| 140 handler_->OnError(); | 140 handler_->OnControllerError(); |
| 141 return; | 141 return; |
| 142 } | 142 } |
| 143 | 143 |
| 144 if (!stream_->Open()) { | 144 if (!stream_->Open()) { |
| 145 DoStopCloseAndClearStream(); | 145 DoStopCloseAndClearStream(); |
| 146 state_ = kError; | 146 state_ = kError; |
| 147 handler_->OnError(); | 147 handler_->OnControllerError(); |
| 148 return; | 148 return; |
| 149 } | 149 } |
| 150 | 150 |
| 151 // Everything started okay, so re-register for state change callbacks if | 151 // Everything started okay, so re-register for state change callbacks if |
| 152 // stream_ was created via AudioManager. | 152 // stream_ was created via AudioManager. |
| 153 if (stream_ != diverting_to_stream_) | 153 if (stream_ != diverting_to_stream_) |
| 154 audio_manager_->AddOutputDeviceChangeListener(this); | 154 audio_manager_->AddOutputDeviceChangeListener(this); |
| 155 | 155 |
| 156 // We have successfully opened the stream. Set the initial volume. | 156 // We have successfully opened the stream. Set the initial volume. |
| 157 stream_->SetVolume(volume_); | 157 stream_->SetVolume(volume_); |
| 158 | 158 |
| 159 // Finally set the state to kCreated. | 159 // Finally set the state to kCreated. |
| 160 state_ = kCreated; | 160 state_ = kCreated; |
| 161 | 161 |
| 162 // And then report we have been created if we haven't done so already. | 162 // And then report we have been created if we haven't done so already. |
| 163 if (!is_for_device_change) | 163 if (!is_for_device_change) |
| 164 handler_->OnCreated(); | 164 handler_->OnControllerCreated(); |
| 165 } | 165 } |
| 166 | 166 |
| 167 void AudioOutputController::DoPlay() { | 167 void AudioOutputController::DoPlay() { |
| 168 DCHECK(message_loop_->BelongsToCurrentThread()); | 168 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 169 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioOutputController.PlayTime"); | 169 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioOutputController.PlayTime"); |
| 170 TRACE_EVENT0("audio", "AudioOutputController::DoPlay"); | 170 TRACE_EVENT0("audio", "AudioOutputController::DoPlay"); |
| 171 | 171 |
| 172 // We can start from created or paused state. | 172 // We can start from created or paused state. |
| 173 if (state_ != kCreated && state_ != kPaused) | 173 if (state_ != kCreated && state_ != kPaused) |
| 174 return; | 174 return; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 189 // it. | 189 // it. |
| 190 // | 190 // |
| 191 // Timer self-manages its lifetime and WedgeCheck() will only record the UMA | 191 // Timer self-manages its lifetime and WedgeCheck() will only record the UMA |
| 192 // statistic if state is still kPlaying. Additional Start() calls will | 192 // statistic if state is still kPlaying. Additional Start() calls will |
| 193 // invalidate the previous timer. | 193 // invalidate the previous timer. |
| 194 wedge_timer_.reset(new base::OneShotTimer()); | 194 wedge_timer_.reset(new base::OneShotTimer()); |
| 195 wedge_timer_->Start( | 195 wedge_timer_->Start( |
| 196 FROM_HERE, TimeDelta::FromSeconds(5), this, | 196 FROM_HERE, TimeDelta::FromSeconds(5), this, |
| 197 &AudioOutputController::WedgeCheck); | 197 &AudioOutputController::WedgeCheck); |
| 198 | 198 |
| 199 handler_->OnPlaying(); | 199 handler_->OnControllerPlaying(); |
| 200 } | 200 } |
| 201 | 201 |
| 202 void AudioOutputController::StopStream() { | 202 void AudioOutputController::StopStream() { |
| 203 DCHECK(message_loop_->BelongsToCurrentThread()); | 203 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 204 | 204 |
| 205 if (state_ == kPlaying) { | 205 if (state_ == kPlaying) { |
| 206 wedge_timer_.reset(); | 206 wedge_timer_.reset(); |
| 207 stream_->Stop(); | 207 stream_->Stop(); |
| 208 | 208 |
| 209 // A stopped stream is silent, and power_montior_.Scan() is no longer being | 209 // A stopped stream is silent, and power_montior_.Scan() is no longer being |
| (...skipping 12 matching lines...) Expand all Loading... |
| 222 StopStream(); | 222 StopStream(); |
| 223 | 223 |
| 224 if (state_ != kPaused) | 224 if (state_ != kPaused) |
| 225 return; | 225 return; |
| 226 | 226 |
| 227 // Let the renderer know we've stopped. Necessary to let PPAPI clients know | 227 // Let the renderer know we've stopped. Necessary to let PPAPI clients know |
| 228 // audio has been shutdown. TODO(dalecurtis): This stinks. PPAPI should have | 228 // audio has been shutdown. TODO(dalecurtis): This stinks. PPAPI should have |
| 229 // a better way to know when it should exit PPB_Audio_Shared::Run(). | 229 // a better way to know when it should exit PPB_Audio_Shared::Run(). |
| 230 sync_reader_->UpdatePendingBytes(std::numeric_limits<uint32_t>::max(), 0); | 230 sync_reader_->UpdatePendingBytes(std::numeric_limits<uint32_t>::max(), 0); |
| 231 | 231 |
| 232 handler_->OnPaused(); | 232 handler_->OnControllerPaused(); |
| 233 } | 233 } |
| 234 | 234 |
| 235 void AudioOutputController::DoClose() { | 235 void AudioOutputController::DoClose() { |
| 236 DCHECK(message_loop_->BelongsToCurrentThread()); | 236 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 237 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioOutputController.CloseTime"); | 237 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioOutputController.CloseTime"); |
| 238 TRACE_EVENT0("audio", "AudioOutputController::DoClose"); | 238 TRACE_EVENT0("audio", "AudioOutputController::DoClose"); |
| 239 | 239 |
| 240 if (state_ != kClosed) { | 240 if (state_ != kClosed) { |
| 241 DoStopCloseAndClearStream(); | 241 DoStopCloseAndClearStream(); |
| 242 sync_reader_->Close(); | 242 sync_reader_->Close(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 // since it would break the diverted setup. Once diversion is | 283 // since it would break the diverted setup. Once diversion is |
| 284 // finished using StopDiverting() the output will switch to the new | 284 // finished using StopDiverting() the output will switch to the new |
| 285 // device ID. | 285 // device ID. |
| 286 if (stream_ != diverting_to_stream_) | 286 if (stream_ != diverting_to_stream_) |
| 287 OnDeviceChange(); | 287 OnDeviceChange(); |
| 288 } | 288 } |
| 289 | 289 |
| 290 void AudioOutputController::DoReportError() { | 290 void AudioOutputController::DoReportError() { |
| 291 DCHECK(message_loop_->BelongsToCurrentThread()); | 291 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 292 if (state_ != kClosed) | 292 if (state_ != kClosed) |
| 293 handler_->OnError(); | 293 handler_->OnControllerError(); |
| 294 } | 294 } |
| 295 | 295 |
| 296 int AudioOutputController::OnMoreData(base::TimeDelta delay, | 296 int AudioOutputController::OnMoreData(base::TimeDelta delay, |
| 297 base::TimeTicks delay_timestamp, | 297 base::TimeTicks delay_timestamp, |
| 298 int prior_frames_skipped, | 298 int prior_frames_skipped, |
| 299 AudioBus* dest) { | 299 AudioBus* dest) { |
| 300 TRACE_EVENT0("audio", "AudioOutputController::OnMoreData"); | 300 TRACE_EVENT0("audio", "AudioOutputController::OnMoreData"); |
| 301 | 301 |
| 302 // Indicate that we haven't wedged (at least not indefinitely, WedgeCheck() | 302 // Indicate that we haven't wedged (at least not indefinitely, WedgeCheck() |
| 303 // may have already fired if OnMoreData() took an abnormal amount of time). | 303 // may have already fired if OnMoreData() took an abnormal amount of time). |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 DCHECK(message_loop_->BelongsToCurrentThread()); | 506 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 507 | 507 |
| 508 // If we should be playing and we haven't, that's a wedge. | 508 // If we should be playing and we haven't, that's a wedge. |
| 509 if (state_ == kPlaying) { | 509 if (state_ == kPlaying) { |
| 510 UMA_HISTOGRAM_BOOLEAN("Media.AudioOutputControllerPlaybackStartupSuccess", | 510 UMA_HISTOGRAM_BOOLEAN("Media.AudioOutputControllerPlaybackStartupSuccess", |
| 511 base::AtomicRefCountIsOne(&on_more_io_data_called_)); | 511 base::AtomicRefCountIsOne(&on_more_io_data_called_)); |
| 512 } | 512 } |
| 513 } | 513 } |
| 514 | 514 |
| 515 } // namespace media | 515 } // namespace media |
| OLD | NEW |