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