| 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_device.h" | 5 #include "media/audio/audio_output_device.h" |
| 6 | 6 |
| 7 #include <cmath> |
| 7 #include <stddef.h> | 8 #include <stddef.h> |
| 8 #include <stdint.h> | 9 #include <stdint.h> |
| 9 #include <utility> | 10 #include <utility> |
| 10 | 11 |
| 11 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/threading/thread_restrictions.h" | 14 #include "base/threading/thread_restrictions.h" |
| 14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 15 #include "base/trace_event/trace_event.h" | 16 #include "base/trace_event/trace_event.h" |
| 16 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 sizeof(AudioOutputBufferParameters) + | 407 sizeof(AudioOutputBufferParameters) + |
| 407 AudioBus::CalculateMemorySize(audio_parameters_)); | 408 AudioBus::CalculateMemorySize(audio_parameters_)); |
| 408 | 409 |
| 409 AudioOutputBuffer* buffer = | 410 AudioOutputBuffer* buffer = |
| 410 reinterpret_cast<AudioOutputBuffer*>(shared_memory_.memory()); | 411 reinterpret_cast<AudioOutputBuffer*>(shared_memory_.memory()); |
| 411 output_bus_ = AudioBus::WrapMemory(audio_parameters_, buffer->audio); | 412 output_bus_ = AudioBus::WrapMemory(audio_parameters_, buffer->audio); |
| 412 } | 413 } |
| 413 | 414 |
| 414 // Called whenever we receive notifications about pending data. | 415 // Called whenever we receive notifications about pending data. |
| 415 void AudioOutputDevice::AudioThreadCallback::Process(uint32_t pending_data) { | 416 void AudioOutputDevice::AudioThreadCallback::Process(uint32_t pending_data) { |
| 416 // Convert the number of pending bytes in the render buffer into milliseconds. | 417 // Convert the number of pending bytes in the render buffer into frames. |
| 417 uint32_t audio_delay_milliseconds = pending_data / bytes_per_ms_; | 418 double frames_delayed = static_cast<double>(pending_data) / bytes_per_frame_; |
| 418 | 419 |
| 419 callback_num_++; | 420 callback_num_++; |
| 420 TRACE_EVENT1("audio", "AudioOutputDevice::FireRenderCallback", | 421 TRACE_EVENT1("audio", "AudioOutputDevice::FireRenderCallback", |
| 421 "callback_num", callback_num_); | 422 "callback_num", callback_num_); |
| 422 | 423 |
| 423 // When playback starts, we get an immediate callback to Process to make sure | 424 // When playback starts, we get an immediate callback to Process to make sure |
| 424 // that we have some data, we'll get another one after the device is awake and | 425 // that we have some data, we'll get another one after the device is awake and |
| 425 // ingesting data, which is what we want to track with this trace. | 426 // ingesting data, which is what we want to track with this trace. |
| 426 if (callback_num_ == 2) { | 427 if (callback_num_ == 2) { |
| 427 TRACE_EVENT_ASYNC_END0("audio", "StartingPlayback", this); | 428 TRACE_EVENT_ASYNC_END0("audio", "StartingPlayback", this); |
| 428 } | 429 } |
| 429 | 430 |
| 430 // Read and reset the number of frames skipped. | 431 // Read and reset the number of frames skipped. |
| 431 AudioOutputBuffer* buffer = | 432 AudioOutputBuffer* buffer = |
| 432 reinterpret_cast<AudioOutputBuffer*>(shared_memory_.memory()); | 433 reinterpret_cast<AudioOutputBuffer*>(shared_memory_.memory()); |
| 433 uint32_t frames_skipped = buffer->params.frames_skipped; | 434 uint32_t frames_skipped = buffer->params.frames_skipped; |
| 434 buffer->params.frames_skipped = 0; | 435 buffer->params.frames_skipped = 0; |
| 435 | 436 |
| 437 DVLOG(4) << __FUNCTION__ << " pending_data:" << pending_data |
| 438 << " frames_delayed(pre-round):" << frames_delayed |
| 439 << " frames_skipped:" << frames_skipped; |
| 440 |
| 436 // Update the audio-delay measurement, inform about the number of skipped | 441 // Update the audio-delay measurement, inform about the number of skipped |
| 437 // frames, and ask client to render audio. Since |output_bus_| is wrapping | 442 // frames, and ask client to render audio. Since |output_bus_| is wrapping |
| 438 // the shared memory the Render() call is writing directly into the shared | 443 // the shared memory the Render() call is writing directly into the shared |
| 439 // memory. | 444 // memory. |
| 440 render_callback_->Render(output_bus_.get(), audio_delay_milliseconds, | 445 render_callback_->Render(output_bus_.get(), std::round(frames_delayed), |
| 441 frames_skipped); | 446 frames_skipped); |
| 442 } | 447 } |
| 443 | 448 |
| 444 } // namespace media | 449 } // namespace media |
| OLD | NEW |