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 | |
| 33 void FramesSkipped(uint32_t frames_skipped) override; | |
| 32 | 34 |
| 33 private: | 35 private: |
| 34 AudioRendererSink::RenderCallback* render_callback_; | 36 AudioRendererSink::RenderCallback* render_callback_; |
| 35 scoped_ptr<AudioBus> output_bus_; | 37 scoped_ptr<AudioBus> output_bus_; |
| 36 uint64 callback_num_; | 38 uint64 callback_num_; |
| 39 | |
| 40 // Stores the number of frames skipped by the consumer. Used and cleared in | |
| 41 // Process(). | |
|
tommi (sloooow) - chröme
2015/12/01 13:34:26
nit: and modified in FramesSkipped
Henrik Grunell
2015/12/03 17:01:07
Done.
| |
| 42 uint32_t frames_skipped_; | |
| 43 | |
| 37 DISALLOW_COPY_AND_ASSIGN(AudioThreadCallback); | 44 DISALLOW_COPY_AND_ASSIGN(AudioThreadCallback); |
| 38 }; | 45 }; |
| 39 | 46 |
| 40 AudioOutputDevice::AudioOutputDevice( | 47 AudioOutputDevice::AudioOutputDevice( |
| 41 scoped_ptr<AudioOutputIPC> ipc, | 48 scoped_ptr<AudioOutputIPC> ipc, |
| 42 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, | 49 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, |
| 43 int session_id, | 50 int session_id, |
| 44 const std::string& device_id, | 51 const std::string& device_id, |
| 45 const url::Origin& security_origin) | 52 const url::Origin& security_origin) |
| 46 : ScopedTaskRunnerObserver(io_task_runner), | 53 : ScopedTaskRunnerObserver(io_task_runner), |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 347 // details. | 354 // details. |
| 348 { | 355 { |
| 349 base::AutoLock auto_lock(audio_thread_lock_); | 356 base::AutoLock auto_lock(audio_thread_lock_); |
| 350 if (stopping_hack_) | 357 if (stopping_hack_) |
| 351 return; | 358 return; |
| 352 | 359 |
| 353 DCHECK(audio_thread_.IsStopped()); | 360 DCHECK(audio_thread_.IsStopped()); |
| 354 audio_callback_.reset(new AudioOutputDevice::AudioThreadCallback( | 361 audio_callback_.reset(new AudioOutputDevice::AudioThreadCallback( |
| 355 audio_parameters_, handle, length, callback_)); | 362 audio_parameters_, handle, length, callback_)); |
| 356 audio_thread_.Start(audio_callback_.get(), socket_handle, | 363 audio_thread_.Start(audio_callback_.get(), socket_handle, |
| 357 "AudioOutputDevice", true); | 364 "AudioOutputDevice", true, false); |
| 358 state_ = PAUSED; | 365 state_ = PAUSED; |
| 359 | 366 |
| 360 // We handle the case where Play() and/or Pause() may have been called | 367 // We handle the case where Play() and/or Pause() may have been called |
| 361 // multiple times before OnStreamCreated() gets called. | 368 // multiple times before OnStreamCreated() gets called. |
| 362 if (play_on_start_) | 369 if (play_on_start_) |
| 363 PlayOnIOThread(); | 370 PlayOnIOThread(); |
| 364 } | 371 } |
| 365 } | 372 } |
| 366 | 373 |
| 367 void AudioOutputDevice::OnIPCClosed() { | 374 void AudioOutputDevice::OnIPCClosed() { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 380 | 387 |
| 381 // AudioOutputDevice::AudioThreadCallback | 388 // AudioOutputDevice::AudioThreadCallback |
| 382 | 389 |
| 383 AudioOutputDevice::AudioThreadCallback::AudioThreadCallback( | 390 AudioOutputDevice::AudioThreadCallback::AudioThreadCallback( |
| 384 const AudioParameters& audio_parameters, | 391 const AudioParameters& audio_parameters, |
| 385 base::SharedMemoryHandle memory, | 392 base::SharedMemoryHandle memory, |
| 386 int memory_length, | 393 int memory_length, |
| 387 AudioRendererSink::RenderCallback* render_callback) | 394 AudioRendererSink::RenderCallback* render_callback) |
| 388 : AudioDeviceThread::Callback(audio_parameters, memory, memory_length, 1), | 395 : AudioDeviceThread::Callback(audio_parameters, memory, memory_length, 1), |
| 389 render_callback_(render_callback), | 396 render_callback_(render_callback), |
| 390 callback_num_(0) {} | 397 callback_num_(0), |
| 398 frames_skipped_(0) {} | |
| 391 | 399 |
| 392 AudioOutputDevice::AudioThreadCallback::~AudioThreadCallback() { | 400 AudioOutputDevice::AudioThreadCallback::~AudioThreadCallback() { |
| 393 } | 401 } |
| 394 | 402 |
| 395 void AudioOutputDevice::AudioThreadCallback::MapSharedMemory() { | 403 void AudioOutputDevice::AudioThreadCallback::MapSharedMemory() { |
| 396 CHECK_EQ(total_segments_, 1); | 404 CHECK_EQ(total_segments_, 1); |
| 397 CHECK(shared_memory_.Map(memory_length_)); | 405 CHECK(shared_memory_.Map(memory_length_)); |
| 398 DCHECK_EQ(memory_length_, AudioBus::CalculateMemorySize(audio_parameters_)); | 406 DCHECK_EQ(memory_length_, AudioBus::CalculateMemorySize(audio_parameters_)); |
| 399 | 407 |
| 400 output_bus_ = | 408 output_bus_ = |
| 401 AudioBus::WrapMemory(audio_parameters_, shared_memory_.memory()); | 409 AudioBus::WrapMemory(audio_parameters_, shared_memory_.memory()); |
| 402 } | 410 } |
| 403 | 411 |
| 404 // Called whenever we receive notifications about pending data. | 412 // Called whenever we receive notifications about pending data. |
| 405 void AudioOutputDevice::AudioThreadCallback::Process(uint32 pending_data) { | 413 void AudioOutputDevice::AudioThreadCallback::Process(uint32_t pending_data) { |
| 406 // Convert the number of pending bytes in the render buffer into milliseconds. | 414 // Convert the number of pending bytes in the render buffer into milliseconds. |
| 407 int audio_delay_milliseconds = pending_data / bytes_per_ms_; | 415 int audio_delay_milliseconds = pending_data / bytes_per_ms_; |
| 408 | 416 |
| 409 callback_num_++; | 417 callback_num_++; |
| 410 TRACE_EVENT1("audio", "AudioOutputDevice::FireRenderCallback", | 418 TRACE_EVENT1("audio", "AudioOutputDevice::FireRenderCallback", |
| 411 "callback_num", callback_num_); | 419 "callback_num", callback_num_); |
| 412 | 420 |
| 413 // When playback starts, we get an immediate callback to Process to make sure | 421 // 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 | 422 // 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. | 423 // ingesting data, which is what we want to track with this trace. |
| 416 if (callback_num_ == 2) { | 424 if (callback_num_ == 2) { |
| 417 TRACE_EVENT_ASYNC_END0("audio", "StartingPlayback", this); | 425 TRACE_EVENT_ASYNC_END0("audio", "StartingPlayback", this); |
| 418 } | 426 } |
| 419 | 427 |
| 428 // Inform about skipped frames if any. | |
| 429 if (frames_skipped_ > 0) { | |
| 430 render_callback_->OnFramesSkipped(frames_skipped_); | |
| 431 frames_skipped_ = 0; | |
| 432 } | |
| 433 | |
| 420 // Update the audio-delay measurement then ask client to render audio. Since | 434 // Update the audio-delay measurement then ask client to render audio. Since |
| 421 // |output_bus_| is wrapping the shared memory the Render() call is writing | 435 // |output_bus_| is wrapping the shared memory the Render() call is writing |
| 422 // directly into the shared memory. | 436 // directly into the shared memory. |
| 423 render_callback_->Render(output_bus_.get(), audio_delay_milliseconds); | 437 render_callback_->Render(output_bus_.get(), audio_delay_milliseconds); |
| 424 } | 438 } |
| 425 | 439 |
| 440 void AudioOutputDevice::AudioThreadCallback::FramesSkipped( | |
|
tommi (sloooow) - chröme
2015/12/01 13:34:25
thread check (must be on the same thread as Proces
Henrik Grunell
2015/12/03 17:01:07
The contract with AudioDeviceThread is that all ca
| |
| 441 uint32_t frames_skipped) { | |
| 442 frames_skipped_ += frames_skipped; | |
| 443 } | |
| 444 | |
| 426 } // namespace media. | 445 } // namespace media. |
| OLD | NEW |