| 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/base/audio_renderer_mixer.h" | 5 #include "media/base/audio_renderer_mixer.h" |
| 6 | 6 |
| 7 #include <cmath> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 9 #include "base/logging.h" | 11 #include "base/logging.h" |
| 10 | 12 |
| 11 namespace media { | 13 namespace media { |
| 12 | 14 |
| 13 enum { kPauseDelaySeconds = 10 }; | 15 enum { kPauseDelaySeconds = 10 }; |
| 14 | 16 |
| 15 AudioRendererMixer::AudioRendererMixer( | 17 AudioRendererMixer::AudioRendererMixer( |
| 16 const AudioParameters& output_params, | 18 const AudioParameters& output_params, |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 NOTREACHED(); | 112 NOTREACHED(); |
| 111 } | 113 } |
| 112 | 114 |
| 113 OutputDevice* AudioRendererMixer::GetOutputDevice() { | 115 OutputDevice* AudioRendererMixer::GetOutputDevice() { |
| 114 DVLOG(1) << __FUNCTION__; | 116 DVLOG(1) << __FUNCTION__; |
| 115 base::AutoLock auto_lock(lock_); | 117 base::AutoLock auto_lock(lock_); |
| 116 return audio_sink_->GetOutputDevice(); | 118 return audio_sink_->GetOutputDevice(); |
| 117 } | 119 } |
| 118 | 120 |
| 119 int AudioRendererMixer::Render(AudioBus* audio_bus, | 121 int AudioRendererMixer::Render(AudioBus* audio_bus, |
| 120 uint32_t audio_delay_milliseconds, | 122 uint32_t frames_delayed, |
| 121 uint32_t frames_skipped) { | 123 uint32_t frames_skipped) { |
| 122 base::AutoLock auto_lock(lock_); | 124 base::AutoLock auto_lock(lock_); |
| 123 | 125 |
| 124 // If there are no mixer inputs and we haven't seen one for a while, pause the | 126 // If there are no mixer inputs and we haven't seen one for a while, pause the |
| 125 // sink to avoid wasting resources when media elements are present but remain | 127 // sink to avoid wasting resources when media elements are present but remain |
| 126 // in the pause state. | 128 // in the pause state. |
| 127 const base::TimeTicks now = base::TimeTicks::Now(); | 129 const base::TimeTicks now = base::TimeTicks::Now(); |
| 128 if (!master_converter_.empty()) { | 130 if (!master_converter_.empty()) { |
| 129 last_play_time_ = now; | 131 last_play_time_ = now; |
| 130 } else if (now - last_play_time_ >= pause_delay_ && playing_) { | 132 } else if (now - last_play_time_ >= pause_delay_ && playing_) { |
| 131 audio_sink_->Pause(); | 133 audio_sink_->Pause(); |
| 132 playing_ = false; | 134 playing_ = false; |
| 133 } | 135 } |
| 134 | 136 |
| 135 master_converter_.ConvertWithDelay( | 137 // TODO(chcunningham): Delete this conversion and change ConvertWith delay to |
| 136 base::TimeDelta::FromMilliseconds(audio_delay_milliseconds), audio_bus); | 138 // expect a count of frames delayed instead of TimeDelta (less precise). |
| 139 // See http://crbug.com/587522. |
| 140 base::TimeDelta audio_delay = base::TimeDelta::FromMicroseconds( |
| 141 std::round(frames_delayed * output_params_.GetMicrosecondsPerFrame())); |
| 142 |
| 143 master_converter_.ConvertWithDelay(audio_delay, audio_bus); |
| 137 return audio_bus->frames(); | 144 return audio_bus->frames(); |
| 138 } | 145 } |
| 139 | 146 |
| 140 void AudioRendererMixer::OnRenderError() { | 147 void AudioRendererMixer::OnRenderError() { |
| 141 // Call each mixer input and signal an error. | 148 // Call each mixer input and signal an error. |
| 142 base::AutoLock auto_lock(lock_); | 149 base::AutoLock auto_lock(lock_); |
| 143 for (const auto& cb : error_callbacks_) | 150 for (const auto& cb : error_callbacks_) |
| 144 cb.Run(); | 151 cb.Run(); |
| 145 } | 152 } |
| 146 | 153 |
| 147 } // namespace media | 154 } // namespace media |
| OLD | NEW |