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 | 9 |
10 #include <cmath> | 10 #include <cmath> |
(...skipping 19 matching lines...) Expand all Loading... |
30 public: | 30 public: |
31 AudioThreadCallback(const AudioParameters& audio_parameters, | 31 AudioThreadCallback(const AudioParameters& audio_parameters, |
32 base::SharedMemoryHandle memory, | 32 base::SharedMemoryHandle memory, |
33 int memory_length, | 33 int memory_length, |
34 AudioRendererSink::RenderCallback* render_callback); | 34 AudioRendererSink::RenderCallback* render_callback); |
35 ~AudioThreadCallback() override; | 35 ~AudioThreadCallback() override; |
36 | 36 |
37 void MapSharedMemory() override; | 37 void MapSharedMemory() override; |
38 | 38 |
39 // Called whenever we receive notifications about pending data. | 39 // Called whenever we receive notifications about pending data. |
40 void Process(uint32_t pending_data) override; | 40 void Process(uint32_t pending_data, const AudioTimestamp& timestamp) override; |
41 | 41 |
42 private: | 42 private: |
43 AudioRendererSink::RenderCallback* render_callback_; | 43 AudioRendererSink::RenderCallback* render_callback_; |
44 std::unique_ptr<AudioBus> output_bus_; | 44 std::unique_ptr<AudioBus> output_bus_; |
45 uint64_t callback_num_; | 45 uint64_t callback_num_; |
46 | 46 |
47 DISALLOW_COPY_AND_ASSIGN(AudioThreadCallback); | 47 DISALLOW_COPY_AND_ASSIGN(AudioThreadCallback); |
48 }; | 48 }; |
49 | 49 |
50 AudioOutputDevice::AudioOutputDevice( | 50 AudioOutputDevice::AudioOutputDevice( |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 DCHECK_EQ(static_cast<size_t>(memory_length_), | 410 DCHECK_EQ(static_cast<size_t>(memory_length_), |
411 sizeof(AudioOutputBufferParameters) + | 411 sizeof(AudioOutputBufferParameters) + |
412 AudioBus::CalculateMemorySize(audio_parameters_)); | 412 AudioBus::CalculateMemorySize(audio_parameters_)); |
413 | 413 |
414 AudioOutputBuffer* buffer = | 414 AudioOutputBuffer* buffer = |
415 reinterpret_cast<AudioOutputBuffer*>(shared_memory_.memory()); | 415 reinterpret_cast<AudioOutputBuffer*>(shared_memory_.memory()); |
416 output_bus_ = AudioBus::WrapMemory(audio_parameters_, buffer->audio); | 416 output_bus_ = AudioBus::WrapMemory(audio_parameters_, buffer->audio); |
417 } | 417 } |
418 | 418 |
419 // Called whenever we receive notifications about pending data. | 419 // Called whenever we receive notifications about pending data. |
420 void AudioOutputDevice::AudioThreadCallback::Process(uint32_t pending_data) { | 420 void AudioOutputDevice::AudioThreadCallback::Process( |
| 421 uint32_t pending_data, |
| 422 const AudioTimestamp& timestamp) { |
421 // Convert the number of pending bytes in the render buffer into frames. | 423 // Convert the number of pending bytes in the render buffer into frames. |
422 double frames_delayed = static_cast<double>(pending_data) / bytes_per_frame_; | 424 double frames_delayed = static_cast<double>(pending_data) / bytes_per_frame_; |
423 | 425 |
424 callback_num_++; | 426 callback_num_++; |
425 TRACE_EVENT1("audio", "AudioOutputDevice::FireRenderCallback", | 427 TRACE_EVENT1("audio", "AudioOutputDevice::FireRenderCallback", |
426 "callback_num", callback_num_); | 428 "callback_num", callback_num_); |
427 | 429 |
428 // When playback starts, we get an immediate callback to Process to make sure | 430 // When playback starts, we get an immediate callback to Process to make sure |
429 // that we have some data, we'll get another one after the device is awake and | 431 // that we have some data, we'll get another one after the device is awake and |
430 // ingesting data, which is what we want to track with this trace. | 432 // ingesting data, which is what we want to track with this trace. |
431 if (callback_num_ == 2) { | 433 if (callback_num_ == 2) { |
432 TRACE_EVENT_ASYNC_END0("audio", "StartingPlayback", this); | 434 TRACE_EVENT_ASYNC_END0("audio", "StartingPlayback", this); |
433 } | 435 } |
434 | 436 |
435 // Read and reset the number of frames skipped. | 437 // Read and reset the number of frames skipped. |
436 AudioOutputBuffer* buffer = | 438 AudioOutputBuffer* buffer = |
437 reinterpret_cast<AudioOutputBuffer*>(shared_memory_.memory()); | 439 reinterpret_cast<AudioOutputBuffer*>(shared_memory_.memory()); |
438 uint32_t frames_skipped = buffer->params.frames_skipped; | 440 uint32_t frames_skipped = buffer->params.frames_skipped; |
439 buffer->params.frames_skipped = 0; | 441 buffer->params.frames_skipped = 0; |
440 | 442 |
441 DVLOG(4) << __FUNCTION__ << " pending_data:" << pending_data | 443 DVLOG(4) << __FUNCTION__ << " pending_data:" << pending_data |
442 << " frames_delayed(pre-round):" << frames_delayed | 444 << " frames_delayed(pre-round):" << frames_delayed |
443 << " frames_skipped:" << frames_skipped; | 445 << " frames_skipped:" << frames_skipped; |
444 | 446 |
445 // Update the audio-delay measurement, inform about the number of skipped | 447 // Update the audio-delay measurement, inform about the number of skipped |
446 // frames, and ask client to render audio. Since |output_bus_| is wrapping | 448 // frames, and ask client to render audio. Since |output_bus_| is wrapping |
447 // the shared memory the Render() call is writing directly into the shared | 449 // the shared memory the Render() call is writing directly into the shared |
448 // memory. | 450 // memory. |
449 render_callback_->Render(output_bus_.get(), std::round(frames_delayed), | 451 render_callback_->Render(output_bus_.get(), std::round(frames_delayed), |
450 frames_skipped); | 452 frames_skipped, timestamp); |
451 } | 453 } |
452 | 454 |
453 } // namespace media | 455 } // namespace media |
OLD | NEW |