Chromium Code Reviews| 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 "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
| 8 #include "base/threading/thread_restrictions.h" | 8 #include "base/threading/thread_restrictions.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 public: | 21 public: |
| 22 AudioThreadCallback(const AudioParameters& audio_parameters, | 22 AudioThreadCallback(const AudioParameters& audio_parameters, |
| 23 base::SharedMemoryHandle memory, | 23 base::SharedMemoryHandle memory, |
| 24 int memory_length, | 24 int memory_length, |
| 25 AudioRendererSink::RenderCallback* render_callback); | 25 AudioRendererSink::RenderCallback* render_callback); |
| 26 ~AudioThreadCallback() override; | 26 ~AudioThreadCallback() override; |
| 27 | 27 |
| 28 void MapSharedMemory() override; | 28 void MapSharedMemory() override; |
| 29 | 29 |
| 30 // Called whenever we receive notifications about pending data. | 30 // Called whenever we receive notifications about pending data. |
| 31 void Process(uint32 pending_data) override; | 31 void Process(uint32_t pending_data) override; |
| 32 | 32 |
| 33 private: | 33 private: |
| 34 AudioRendererSink::RenderCallback* render_callback_; | 34 AudioRendererSink::RenderCallback* render_callback_; |
| 35 scoped_ptr<AudioBus> output_bus_; | 35 scoped_ptr<AudioBus> output_bus_; |
| 36 uint64 callback_num_; | 36 uint64 callback_num_; |
| 37 | |
| 37 DISALLOW_COPY_AND_ASSIGN(AudioThreadCallback); | 38 DISALLOW_COPY_AND_ASSIGN(AudioThreadCallback); |
| 38 }; | 39 }; |
| 39 | 40 |
| 40 AudioOutputDevice::AudioOutputDevice( | 41 AudioOutputDevice::AudioOutputDevice( |
| 41 scoped_ptr<AudioOutputIPC> ipc, | 42 scoped_ptr<AudioOutputIPC> ipc, |
| 42 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, | 43 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, |
| 43 int session_id, | 44 int session_id, |
| 44 const std::string& device_id, | 45 const std::string& device_id, |
| 45 const url::Origin& security_origin) | 46 const url::Origin& security_origin) |
| 46 : ScopedTaskRunnerObserver(io_task_runner), | 47 : ScopedTaskRunnerObserver(io_task_runner), |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 388 : AudioDeviceThread::Callback(audio_parameters, memory, memory_length, 1), | 389 : AudioDeviceThread::Callback(audio_parameters, memory, memory_length, 1), |
| 389 render_callback_(render_callback), | 390 render_callback_(render_callback), |
| 390 callback_num_(0) {} | 391 callback_num_(0) {} |
| 391 | 392 |
| 392 AudioOutputDevice::AudioThreadCallback::~AudioThreadCallback() { | 393 AudioOutputDevice::AudioThreadCallback::~AudioThreadCallback() { |
| 393 } | 394 } |
| 394 | 395 |
| 395 void AudioOutputDevice::AudioThreadCallback::MapSharedMemory() { | 396 void AudioOutputDevice::AudioThreadCallback::MapSharedMemory() { |
| 396 CHECK_EQ(total_segments_, 1); | 397 CHECK_EQ(total_segments_, 1); |
| 397 CHECK(shared_memory_.Map(memory_length_)); | 398 CHECK(shared_memory_.Map(memory_length_)); |
| 398 DCHECK_EQ(memory_length_, AudioBus::CalculateMemorySize(audio_parameters_)); | 399 DCHECK_EQ(memory_length_, |
| 400 sizeof(AudioOutputBufferParameters) + | |
| 401 AudioBus::CalculateMemorySize(audio_parameters_)); | |
| 399 | 402 |
| 400 output_bus_ = | 403 AudioOutputBuffer* buffer = |
| 401 AudioBus::WrapMemory(audio_parameters_, shared_memory_.memory()); | 404 reinterpret_cast<AudioOutputBuffer*>(shared_memory_.memory()); |
| 405 output_bus_ = AudioBus::WrapMemory(audio_parameters_, buffer->audio); | |
| 402 } | 406 } |
| 403 | 407 |
| 404 // Called whenever we receive notifications about pending data. | 408 // Called whenever we receive notifications about pending data. |
| 405 void AudioOutputDevice::AudioThreadCallback::Process(uint32 pending_data) { | 409 void AudioOutputDevice::AudioThreadCallback::Process(uint32_t pending_data) { |
| 406 // Convert the number of pending bytes in the render buffer into milliseconds. | 410 // Convert the number of pending bytes in the render buffer into milliseconds. |
| 407 int audio_delay_milliseconds = pending_data / bytes_per_ms_; | 411 uint32_t audio_delay_milliseconds = pending_data / bytes_per_ms_; |
| 408 | 412 |
| 409 callback_num_++; | 413 callback_num_++; |
| 410 TRACE_EVENT1("audio", "AudioOutputDevice::FireRenderCallback", | 414 TRACE_EVENT1("audio", "AudioOutputDevice::FireRenderCallback", |
| 411 "callback_num", callback_num_); | 415 "callback_num", callback_num_); |
| 412 | 416 |
| 413 // When playback starts, we get an immediate callback to Process to make sure | 417 // When playback starts, we get an immediate callback to Process to make sure |
| 414 // that we have some data, we'll get another one after the device is awake and | 418 // that we have some data, we'll get another one after the device is awake and |
| 415 // ingesting data, which is what we want to track with this trace. | 419 // ingesting data, which is what we want to track with this trace. |
| 416 if (callback_num_ == 2) { | 420 if (callback_num_ == 2) { |
| 417 TRACE_EVENT_ASYNC_END0("audio", "StartingPlayback", this); | 421 TRACE_EVENT_ASYNC_END0("audio", "StartingPlayback", this); |
| 418 } | 422 } |
| 419 | 423 |
| 420 // Update the audio-delay measurement then ask client to render audio. Since | 424 // Read and reset the number of frames skipped. |
| 421 // |output_bus_| is wrapping the shared memory the Render() call is writing | 425 AudioOutputBuffer* buffer = |
| 422 // directly into the shared memory. | 426 reinterpret_cast<AudioOutputBuffer*>(shared_memory_.memory()); |
| 423 render_callback_->Render(output_bus_.get(), audio_delay_milliseconds); | 427 uint32_t frames_skipped = buffer->params.frames_skipped; |
| 428 buffer->params.frames_skipped = 0; | |
|
tommi (sloooow) - chröme
2015/12/08 08:34:51
ah, so we reset the value here... is there a reaso
Henrik Grunell
2015/12/08 09:30:34
Yes, as my reply to the other comment, we can over
| |
| 429 | |
| 430 // Update the audio-delay measurement, inform about the number of skipped | |
| 431 // frames, and ask client to render audio. Since |output_bus_| is wrapping | |
| 432 // the shared memory the Render() call is writing directly into the shared | |
| 433 // memory. | |
| 434 render_callback_->Render(output_bus_.get(), audio_delay_milliseconds, | |
| 435 frames_skipped); | |
| 424 } | 436 } |
| 425 | 437 |
| 426 } // namespace media. | 438 } // namespace media |
| OLD | NEW |