| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/numerics/safe_conversions.h" |
| 10 #include "base/task_runner_util.h" | 11 #include "base/task_runner_util.h" |
| 11 #include "base/threading/platform_thread.h" | 12 #include "base/threading/platform_thread.h" |
| 12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 13 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 14 #include "media/base/scoped_histogram_timer.h" | 15 #include "media/base/scoped_histogram_timer.h" |
| 15 | 16 |
| 16 using base::TimeDelta; | 17 using base::TimeDelta; |
| 17 | 18 |
| 18 namespace media { | 19 namespace media { |
| 19 | 20 |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 OnDeviceChange(); | 274 OnDeviceChange(); |
| 274 } | 275 } |
| 275 | 276 |
| 276 void AudioOutputController::DoReportError() { | 277 void AudioOutputController::DoReportError() { |
| 277 DCHECK(message_loop_->BelongsToCurrentThread()); | 278 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 278 if (state_ != kClosed) | 279 if (state_ != kClosed) |
| 279 handler_->OnError(); | 280 handler_->OnError(); |
| 280 } | 281 } |
| 281 | 282 |
| 282 int AudioOutputController::OnMoreData(AudioBus* dest, | 283 int AudioOutputController::OnMoreData(AudioBus* dest, |
| 283 AudioBuffersState buffers_state) { | 284 uint32 total_bytes_delay) { |
| 284 TRACE_EVENT0("audio", "AudioOutputController::OnMoreData"); | 285 TRACE_EVENT0("audio", "AudioOutputController::OnMoreData"); |
| 285 | 286 |
| 286 // Indicate that we haven't wedged (at least not indefinitely, WedgeCheck() | 287 // Indicate that we haven't wedged (at least not indefinitely, WedgeCheck() |
| 287 // may have already fired if OnMoreIOData() took an abnormal amount of time). | 288 // may have already fired if OnMoreData() took an abnormal amount of time). |
| 288 // Since this thread is the only writer of |on_more_io_data_called_| once the | 289 // Since this thread is the only writer of |on_more_io_data_called_| once the |
| 289 // thread starts, its safe to compare and then increment. | 290 // thread starts, its safe to compare and then increment. |
| 290 if (base::AtomicRefCountIsZero(&on_more_io_data_called_)) | 291 if (base::AtomicRefCountIsZero(&on_more_io_data_called_)) |
| 291 base::AtomicRefCountInc(&on_more_io_data_called_); | 292 base::AtomicRefCountInc(&on_more_io_data_called_); |
| 292 | 293 |
| 293 sync_reader_->Read(dest); | 294 sync_reader_->Read(dest); |
| 294 | 295 |
| 295 const int frames = dest->frames(); | 296 const int frames = dest->frames(); |
| 296 sync_reader_->UpdatePendingBytes( | 297 sync_reader_->UpdatePendingBytes(base::saturated_cast<uint32>( |
| 297 buffers_state.total_bytes() + frames * params_.GetBytesPerFrame()); | 298 total_bytes_delay + frames * params_.GetBytesPerFrame())); |
| 298 | 299 |
| 299 if (will_monitor_audio_levels()) | 300 if (will_monitor_audio_levels()) |
| 300 power_monitor_.Scan(*dest, frames); | 301 power_monitor_.Scan(*dest, frames); |
| 301 | 302 |
| 302 return frames; | 303 return frames; |
| 303 } | 304 } |
| 304 | 305 |
| 305 void AudioOutputController::OnError(AudioOutputStream* stream) { | 306 void AudioOutputController::OnError(AudioOutputStream* stream) { |
| 306 // Handle error on the audio controller thread. | 307 // Handle error on the audio controller thread. |
| 307 message_loop_->PostTask(FROM_HERE, base::Bind( | 308 message_loop_->PostTask(FROM_HERE, base::Bind( |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 DCHECK(message_loop_->BelongsToCurrentThread()); | 410 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 410 | 411 |
| 411 // If we should be playing and we haven't, that's a wedge. | 412 // If we should be playing and we haven't, that's a wedge. |
| 412 if (state_ == kPlaying) { | 413 if (state_ == kPlaying) { |
| 413 UMA_HISTOGRAM_BOOLEAN("Media.AudioOutputControllerPlaybackStartupSuccess", | 414 UMA_HISTOGRAM_BOOLEAN("Media.AudioOutputControllerPlaybackStartupSuccess", |
| 414 base::AtomicRefCountIsOne(&on_more_io_data_called_)); | 415 base::AtomicRefCountIsOne(&on_more_io_data_called_)); |
| 415 } | 416 } |
| 416 } | 417 } |
| 417 | 418 |
| 418 } // namespace media | 419 } // namespace media |
| OLD | NEW |