| 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 <limits> | 9 #include <limits> |
| 10 | 10 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 void AudioOutputController::DoPlay() { | 157 void AudioOutputController::DoPlay() { |
| 158 DCHECK(message_loop_->BelongsToCurrentThread()); | 158 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 159 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioOutputController.PlayTime"); | 159 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioOutputController.PlayTime"); |
| 160 TRACE_EVENT0("audio", "AudioOutputController::DoPlay"); | 160 TRACE_EVENT0("audio", "AudioOutputController::DoPlay"); |
| 161 | 161 |
| 162 // We can start from created or paused state. | 162 // We can start from created or paused state. |
| 163 if (state_ != kCreated && state_ != kPaused) | 163 if (state_ != kCreated && state_ != kPaused) |
| 164 return; | 164 return; |
| 165 | 165 |
| 166 // Ask for first packet. | 166 // Ask for first packet. |
| 167 sync_reader_->UpdatePendingBytes(0); | 167 sync_reader_->UpdatePendingBytes(0, 0); |
| 168 | 168 |
| 169 state_ = kPlaying; | 169 state_ = kPlaying; |
| 170 | 170 |
| 171 stream_->Start(this); | 171 stream_->Start(this); |
| 172 | 172 |
| 173 // For UMA tracking purposes, start the wedge detection timer. This allows us | 173 // For UMA tracking purposes, start the wedge detection timer. This allows us |
| 174 // to record statistics about the number of wedged playbacks in the field. | 174 // to record statistics about the number of wedged playbacks in the field. |
| 175 // | 175 // |
| 176 // WedgeCheck() will look to see if |on_more_io_data_called_| is true after | 176 // WedgeCheck() will look to see if |on_more_io_data_called_| is true after |
| 177 // the timeout expires. Care must be taken to ensure the wedge check delay is | 177 // the timeout expires. Care must be taken to ensure the wedge check delay is |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 TRACE_EVENT0("audio", "AudioOutputController::DoPause"); | 210 TRACE_EVENT0("audio", "AudioOutputController::DoPause"); |
| 211 | 211 |
| 212 StopStream(); | 212 StopStream(); |
| 213 | 213 |
| 214 if (state_ != kPaused) | 214 if (state_ != kPaused) |
| 215 return; | 215 return; |
| 216 | 216 |
| 217 // Let the renderer know we've stopped. Necessary to let PPAPI clients know | 217 // Let the renderer know we've stopped. Necessary to let PPAPI clients know |
| 218 // audio has been shutdown. TODO(dalecurtis): This stinks. PPAPI should have | 218 // audio has been shutdown. TODO(dalecurtis): This stinks. PPAPI should have |
| 219 // a better way to know when it should exit PPB_Audio_Shared::Run(). | 219 // a better way to know when it should exit PPB_Audio_Shared::Run(). |
| 220 sync_reader_->UpdatePendingBytes(std::numeric_limits<uint32_t>::max()); | 220 sync_reader_->UpdatePendingBytes(std::numeric_limits<uint32_t>::max(), 0); |
| 221 | 221 |
| 222 handler_->OnPaused(); | 222 handler_->OnPaused(); |
| 223 } | 223 } |
| 224 | 224 |
| 225 void AudioOutputController::DoClose() { | 225 void AudioOutputController::DoClose() { |
| 226 DCHECK(message_loop_->BelongsToCurrentThread()); | 226 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 227 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioOutputController.CloseTime"); | 227 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioOutputController.CloseTime"); |
| 228 TRACE_EVENT0("audio", "AudioOutputController::DoClose"); | 228 TRACE_EVENT0("audio", "AudioOutputController::DoClose"); |
| 229 | 229 |
| 230 if (state_ != kClosed) { | 230 if (state_ != kClosed) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 OnDeviceChange(); | 277 OnDeviceChange(); |
| 278 } | 278 } |
| 279 | 279 |
| 280 void AudioOutputController::DoReportError() { | 280 void AudioOutputController::DoReportError() { |
| 281 DCHECK(message_loop_->BelongsToCurrentThread()); | 281 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 282 if (state_ != kClosed) | 282 if (state_ != kClosed) |
| 283 handler_->OnError(); | 283 handler_->OnError(); |
| 284 } | 284 } |
| 285 | 285 |
| 286 int AudioOutputController::OnMoreData(AudioBus* dest, | 286 int AudioOutputController::OnMoreData(AudioBus* dest, |
| 287 uint32_t total_bytes_delay) { | 287 uint32_t total_bytes_delay, |
| 288 uint32_t frames_skipped) { |
| 288 TRACE_EVENT0("audio", "AudioOutputController::OnMoreData"); | 289 TRACE_EVENT0("audio", "AudioOutputController::OnMoreData"); |
| 289 | 290 |
| 290 // Indicate that we haven't wedged (at least not indefinitely, WedgeCheck() | 291 // Indicate that we haven't wedged (at least not indefinitely, WedgeCheck() |
| 291 // may have already fired if OnMoreData() took an abnormal amount of time). | 292 // may have already fired if OnMoreData() took an abnormal amount of time). |
| 292 // Since this thread is the only writer of |on_more_io_data_called_| once the | 293 // Since this thread is the only writer of |on_more_io_data_called_| once the |
| 293 // thread starts, its safe to compare and then increment. | 294 // thread starts, its safe to compare and then increment. |
| 294 if (base::AtomicRefCountIsZero(&on_more_io_data_called_)) | 295 if (base::AtomicRefCountIsZero(&on_more_io_data_called_)) |
| 295 base::AtomicRefCountInc(&on_more_io_data_called_); | 296 base::AtomicRefCountInc(&on_more_io_data_called_); |
| 296 | 297 |
| 297 sync_reader_->Read(dest); | 298 sync_reader_->Read(dest); |
| 298 | 299 |
| 299 const int frames = dest->frames(); | 300 const int frames = dest->frames(); |
| 300 sync_reader_->UpdatePendingBytes(base::saturated_cast<uint32_t>( | 301 sync_reader_->UpdatePendingBytes( |
| 301 total_bytes_delay + frames * params_.GetBytesPerFrame())); | 302 total_bytes_delay + frames * params_.GetBytesPerFrame(), frames_skipped); |
| 302 | 303 |
| 303 if (will_monitor_audio_levels()) | 304 if (will_monitor_audio_levels()) |
| 304 power_monitor_.Scan(*dest, frames); | 305 power_monitor_.Scan(*dest, frames); |
| 305 | 306 |
| 306 return frames; | 307 return frames; |
| 307 } | 308 } |
| 308 | 309 |
| 309 void AudioOutputController::OnError(AudioOutputStream* stream) { | 310 void AudioOutputController::OnError(AudioOutputStream* stream) { |
| 310 { | 311 { |
| 311 base::AutoLock auto_lock(error_lock_); | 312 base::AutoLock auto_lock(error_lock_); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 DCHECK(message_loop_->BelongsToCurrentThread()); | 428 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 428 | 429 |
| 429 // If we should be playing and we haven't, that's a wedge. | 430 // If we should be playing and we haven't, that's a wedge. |
| 430 if (state_ == kPlaying) { | 431 if (state_ == kPlaying) { |
| 431 UMA_HISTOGRAM_BOOLEAN("Media.AudioOutputControllerPlaybackStartupSuccess", | 432 UMA_HISTOGRAM_BOOLEAN("Media.AudioOutputControllerPlaybackStartupSuccess", |
| 432 base::AtomicRefCountIsOne(&on_more_io_data_called_)); | 433 base::AtomicRefCountIsOne(&on_more_io_data_called_)); |
| 433 } | 434 } |
| 434 } | 435 } |
| 435 | 436 |
| 436 } // namespace media | 437 } // namespace media |
| OLD | NEW |