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 21 matching lines...) Expand all Loading... |
32 public: | 32 public: |
33 AudioThreadCallback(const AudioParameters& audio_parameters, | 33 AudioThreadCallback(const AudioParameters& audio_parameters, |
34 base::SharedMemoryHandle memory, | 34 base::SharedMemoryHandle memory, |
35 int memory_length, | 35 int memory_length, |
36 AudioRendererSink::RenderCallback* render_callback); | 36 AudioRendererSink::RenderCallback* render_callback); |
37 ~AudioThreadCallback() override; | 37 ~AudioThreadCallback() override; |
38 | 38 |
39 void MapSharedMemory() override; | 39 void MapSharedMemory() override; |
40 | 40 |
41 // Called whenever we receive notifications about pending data. | 41 // Called whenever we receive notifications about pending data. |
42 void Process(uint32_t pending_data) override; | 42 void Process(uint32_t pending_data, const AudioTimestamp& timestamp) override; |
43 | 43 |
44 // Returns whether the current thread is the audio device thread or not. | 44 // Returns whether the current thread is the audio device thread or not. |
45 // Will always return true if DCHECKs are not enabled. | 45 // Will always return true if DCHECKs are not enabled. |
46 bool CurrentThreadIsAudioDeviceThread(); | 46 bool CurrentThreadIsAudioDeviceThread(); |
47 | 47 |
48 private: | 48 private: |
49 const int bytes_per_frame_; | 49 const int bytes_per_frame_; |
50 AudioRendererSink::RenderCallback* render_callback_; | 50 AudioRendererSink::RenderCallback* render_callback_; |
51 std::unique_ptr<AudioBus> output_bus_; | 51 std::unique_ptr<AudioBus> output_bus_; |
52 uint64_t callback_num_; | 52 uint64_t callback_num_; |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 DCHECK_EQ(static_cast<size_t>(memory_length_), | 451 DCHECK_EQ(static_cast<size_t>(memory_length_), |
452 sizeof(AudioOutputBufferParameters) + | 452 sizeof(AudioOutputBufferParameters) + |
453 AudioBus::CalculateMemorySize(audio_parameters_)); | 453 AudioBus::CalculateMemorySize(audio_parameters_)); |
454 | 454 |
455 AudioOutputBuffer* buffer = | 455 AudioOutputBuffer* buffer = |
456 reinterpret_cast<AudioOutputBuffer*>(shared_memory_.memory()); | 456 reinterpret_cast<AudioOutputBuffer*>(shared_memory_.memory()); |
457 output_bus_ = AudioBus::WrapMemory(audio_parameters_, buffer->audio); | 457 output_bus_ = AudioBus::WrapMemory(audio_parameters_, buffer->audio); |
458 } | 458 } |
459 | 459 |
460 // Called whenever we receive notifications about pending data. | 460 // Called whenever we receive notifications about pending data. |
461 void AudioOutputDevice::AudioThreadCallback::Process(uint32_t pending_data) { | 461 void AudioOutputDevice::AudioThreadCallback::Process( |
| 462 uint32_t pending_data, |
| 463 const AudioTimestamp& timestamp) { |
462 // Convert the number of pending bytes in the render buffer into frames. | 464 // Convert the number of pending bytes in the render buffer into frames. |
463 double frames_delayed = static_cast<double>(pending_data) / bytes_per_frame_; | 465 double frames_delayed = static_cast<double>(pending_data) / bytes_per_frame_; |
464 | 466 |
465 callback_num_++; | 467 callback_num_++; |
466 TRACE_EVENT1("audio", "AudioOutputDevice::FireRenderCallback", | 468 TRACE_EVENT1("audio", "AudioOutputDevice::FireRenderCallback", |
467 "callback_num", callback_num_); | 469 "callback_num", callback_num_); |
468 | 470 |
469 // When playback starts, we get an immediate callback to Process to make sure | 471 // When playback starts, we get an immediate callback to Process to make sure |
470 // that we have some data, we'll get another one after the device is awake and | 472 // that we have some data, we'll get another one after the device is awake and |
471 // ingesting data, which is what we want to track with this trace. | 473 // ingesting data, which is what we want to track with this trace. |
472 if (callback_num_ == 2) { | 474 if (callback_num_ == 2) { |
473 TRACE_EVENT_ASYNC_END0("audio", "StartingPlayback", this); | 475 TRACE_EVENT_ASYNC_END0("audio", "StartingPlayback", this); |
474 } | 476 } |
475 | 477 |
476 // Read and reset the number of frames skipped. | 478 // Read and reset the number of frames skipped. |
477 AudioOutputBuffer* buffer = | 479 AudioOutputBuffer* buffer = |
478 reinterpret_cast<AudioOutputBuffer*>(shared_memory_.memory()); | 480 reinterpret_cast<AudioOutputBuffer*>(shared_memory_.memory()); |
479 uint32_t frames_skipped = buffer->params.frames_skipped; | 481 uint32_t frames_skipped = buffer->params.frames_skipped; |
480 buffer->params.frames_skipped = 0; | 482 buffer->params.frames_skipped = 0; |
481 | 483 |
482 DVLOG(4) << __FUNCTION__ << " pending_data:" << pending_data | 484 DVLOG(4) << __FUNCTION__ << " pending_data:" << pending_data |
483 << " frames_delayed(pre-round):" << frames_delayed | 485 << " frames_delayed(pre-round):" << frames_delayed |
484 << " frames_skipped:" << frames_skipped; | 486 << " frames_skipped:" << frames_skipped; |
485 | 487 |
486 // Update the audio-delay measurement, inform about the number of skipped | 488 // Update the audio-delay measurement, inform about the number of skipped |
487 // frames, and ask client to render audio. Since |output_bus_| is wrapping | 489 // frames, and ask client to render audio. Since |output_bus_| is wrapping |
488 // the shared memory the Render() call is writing directly into the shared | 490 // the shared memory the Render() call is writing directly into the shared |
489 // memory. | 491 // memory. |
490 render_callback_->Render(output_bus_.get(), std::round(frames_delayed), | 492 render_callback_->Render(output_bus_.get(), std::round(frames_delayed), |
491 frames_skipped); | 493 frames_skipped, timestamp); |
492 } | 494 } |
493 | 495 |
494 bool AudioOutputDevice::AudioThreadCallback:: | 496 bool AudioOutputDevice::AudioThreadCallback:: |
495 CurrentThreadIsAudioDeviceThread() { | 497 CurrentThreadIsAudioDeviceThread() { |
496 return thread_checker_.CalledOnValidThread(); | 498 return thread_checker_.CalledOnValidThread(); |
497 } | 499 } |
498 | 500 |
499 } // namespace media | 501 } // namespace media |
OLD | NEW |