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_t pending_data) override; | 31 void Process(uint32 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 | |
38 DISALLOW_COPY_AND_ASSIGN(AudioThreadCallback); | 37 DISALLOW_COPY_AND_ASSIGN(AudioThreadCallback); |
39 }; | 38 }; |
40 | 39 |
41 AudioOutputDevice::AudioOutputDevice( | 40 AudioOutputDevice::AudioOutputDevice( |
42 scoped_ptr<AudioOutputIPC> ipc, | 41 scoped_ptr<AudioOutputIPC> ipc, |
43 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, | 42 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, |
44 int session_id, | 43 int session_id, |
45 const std::string& device_id, | 44 const std::string& device_id, |
46 const url::Origin& security_origin) | 45 const url::Origin& security_origin) |
47 : ScopedTaskRunnerObserver(io_task_runner), | 46 : ScopedTaskRunnerObserver(io_task_runner), |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 : AudioDeviceThread::Callback(audio_parameters, memory, memory_length, 1), | 388 : AudioDeviceThread::Callback(audio_parameters, memory, memory_length, 1), |
390 render_callback_(render_callback), | 389 render_callback_(render_callback), |
391 callback_num_(0) {} | 390 callback_num_(0) {} |
392 | 391 |
393 AudioOutputDevice::AudioThreadCallback::~AudioThreadCallback() { | 392 AudioOutputDevice::AudioThreadCallback::~AudioThreadCallback() { |
394 } | 393 } |
395 | 394 |
396 void AudioOutputDevice::AudioThreadCallback::MapSharedMemory() { | 395 void AudioOutputDevice::AudioThreadCallback::MapSharedMemory() { |
397 CHECK_EQ(total_segments_, 1); | 396 CHECK_EQ(total_segments_, 1); |
398 CHECK(shared_memory_.Map(memory_length_)); | 397 CHECK(shared_memory_.Map(memory_length_)); |
399 DCHECK_EQ(static_cast<size_t>(memory_length_), | 398 DCHECK_EQ(memory_length_, AudioBus::CalculateMemorySize(audio_parameters_)); |
400 sizeof(AudioOutputBufferParameters) + | |
401 AudioBus::CalculateMemorySize(audio_parameters_)); | |
402 | 399 |
403 AudioOutputBuffer* buffer = | 400 output_bus_ = |
404 reinterpret_cast<AudioOutputBuffer*>(shared_memory_.memory()); | 401 AudioBus::WrapMemory(audio_parameters_, shared_memory_.memory()); |
405 output_bus_ = AudioBus::WrapMemory(audio_parameters_, buffer->audio); | |
406 } | 402 } |
407 | 403 |
408 // Called whenever we receive notifications about pending data. | 404 // Called whenever we receive notifications about pending data. |
409 void AudioOutputDevice::AudioThreadCallback::Process(uint32_t pending_data) { | 405 void AudioOutputDevice::AudioThreadCallback::Process(uint32 pending_data) { |
410 // Convert the number of pending bytes in the render buffer into milliseconds. | 406 // Convert the number of pending bytes in the render buffer into milliseconds. |
411 uint32_t audio_delay_milliseconds = pending_data / bytes_per_ms_; | 407 int audio_delay_milliseconds = pending_data / bytes_per_ms_; |
412 | 408 |
413 callback_num_++; | 409 callback_num_++; |
414 TRACE_EVENT1("audio", "AudioOutputDevice::FireRenderCallback", | 410 TRACE_EVENT1("audio", "AudioOutputDevice::FireRenderCallback", |
415 "callback_num", callback_num_); | 411 "callback_num", callback_num_); |
416 | 412 |
417 // When playback starts, we get an immediate callback to Process to make sure | 413 // When playback starts, we get an immediate callback to Process to make sure |
418 // that we have some data, we'll get another one after the device is awake and | 414 // that we have some data, we'll get another one after the device is awake and |
419 // ingesting data, which is what we want to track with this trace. | 415 // ingesting data, which is what we want to track with this trace. |
420 if (callback_num_ == 2) { | 416 if (callback_num_ == 2) { |
421 TRACE_EVENT_ASYNC_END0("audio", "StartingPlayback", this); | 417 TRACE_EVENT_ASYNC_END0("audio", "StartingPlayback", this); |
422 } | 418 } |
423 | 419 |
424 // Read and reset the number of frames skipped. | 420 // Update the audio-delay measurement then ask client to render audio. Since |
425 AudioOutputBuffer* buffer = | 421 // |output_bus_| is wrapping the shared memory the Render() call is writing |
426 reinterpret_cast<AudioOutputBuffer*>(shared_memory_.memory()); | 422 // directly into the shared memory. |
427 uint32_t frames_skipped = buffer->params.frames_skipped; | 423 render_callback_->Render(output_bus_.get(), audio_delay_milliseconds); |
428 buffer->params.frames_skipped = 0; | |
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); | |
436 } | 424 } |
437 | 425 |
438 } // namespace media | 426 } // namespace media. |
OLD | NEW |