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). |
Henrik Grunell
2016/02/17 08:13:47
Did you have a bug for this?
chcunningham
2016/02/17 18:32:37
Done. http://crbug.com/587522. Updated the comment
| |
139 base::TimeDelta audio_delay = base::TimeDelta::FromMicroseconds( | |
140 std::round(frames_delayed * output_params_.GetMicrosecondsPerFrame())); | |
141 | |
142 master_converter_.ConvertWithDelay(audio_delay, audio_bus); | |
137 return audio_bus->frames(); | 143 return audio_bus->frames(); |
138 } | 144 } |
139 | 145 |
140 void AudioRendererMixer::OnRenderError() { | 146 void AudioRendererMixer::OnRenderError() { |
141 // Call each mixer input and signal an error. | 147 // Call each mixer input and signal an error. |
142 base::AutoLock auto_lock(lock_); | 148 base::AutoLock auto_lock(lock_); |
143 for (const auto& cb : error_callbacks_) | 149 for (const auto& cb : error_callbacks_) |
144 cb.Run(); | 150 cb.Run(); |
145 } | 151 } |
146 | 152 |
147 } // namespace media | 153 } // namespace media |
OLD | NEW |