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